Skip to content

Commit bb2ea6c

Browse files
committed
add api.types and mark py.typed
1 parent e3805c4 commit bb2ea6c

File tree

8 files changed

+146
-12
lines changed

8 files changed

+146
-12
lines changed

mppq/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
Minimized PPQ quantizer package.
88
"""
99

10+
from mppq import api
11+
12+
__all__ = ["api"]
1013
__version__ = "0.7.3"

mppq/api/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
推荐用户仅使用该包内的函数和对象。
1111
"""
1212

13-
from mppq import __version__
14-
from mppq.api.extension import register_operation, register_platform
13+
from mppq.api.extension import (
14+
BaseQuantizer,
15+
GraphBuilder,
16+
GraphDispatcher,
17+
GraphExporter,
18+
register_operation,
19+
register_platform,
20+
)
1521
from mppq.api.interface import (
1622
dispatch_graph,
1723
export_config,
@@ -23,15 +29,11 @@
2329
load_quantizer,
2430
quantize,
2531
)
26-
from mppq.dispatcher.base import GraphDispatcher
27-
from mppq.executor.torch import TorchExecutor
32+
from mppq.api.types import TorchExecutor
2833
from mppq.ffi import ENABLE_CUDA_KERNEL
29-
from mppq.frontend.base import GraphBuilder, GraphExporter
3034
from mppq.logger import set_level as set_log_level
31-
from mppq.quantizer.base import BaseQuantizer
3235

3336
__all__ = [
34-
"__version__",
3537
"TorchExecutor",
3638
"ENABLE_CUDA_KERNEL",
3739
"set_log_level",

mppq/api/extension.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@
1111
from typing import Dict, Optional, Type
1212

1313
from mppq.dispatcher.base import DISPATCHER_TABLE, GraphDispatcher
14-
from mppq.executor.base import OPERATION_FORWARD_TABLE
15-
from mppq.executor.op.base import DEFAULT_BACKEND_TABLE, OperationForwardProtocol
14+
from mppq.executor.base import OPERATION_FORWARD_TABLE, BaseGraphExecutor
15+
from mppq.executor.op.base import (
16+
ASSERT_IS_QUANT_OP,
17+
ASSERT_NUM_OF_INPUT,
18+
DEFAULT_BACKEND_TABLE,
19+
FORCE_CONVERT_DEVICE,
20+
GET_ATTRIBUTE_FROM_OPERATION,
21+
GET_VALUE_FROM_INPUTS,
22+
VALUE_TO_EXECUTING_DEVICE,
23+
OperationForwardProtocol,
24+
)
1625
from mppq.frontend import EXPORTER, PARSER
17-
from mppq.ir.base.graph import GraphBuilder, GraphExporter
26+
from mppq.frontend.onnx.onnx_exporter import OP_CONVERTERS
27+
from mppq.ir.base.graph import GraphBuilder, GraphExporter, OperationExporter
1828
from mppq.logger import error, warning
29+
from mppq.quantization.optim.base import OPTIM_ALGORITHMS, QuantizationOptimizationPass
1930
from mppq.quantizer.base import QUANTIZER, BaseQuantizer
2031

2132
_PLATFORM_TO_PARSER_: Dict[int, str] = {}
@@ -160,3 +171,31 @@ def register_platform(
160171
f"by default the last one is used. Current quantizer is {name}"
161172
)
162173
_PLATFORM_TO_QUANTIZER_[platform_id] = name
174+
175+
176+
__all__ = [
177+
"register_operation",
178+
"register_platform",
179+
# registry
180+
"DISPATCHER_TABLE",
181+
"PARSER",
182+
"EXPORTER",
183+
"QUANTIZER",
184+
"OP_CONVERTERS",
185+
"OPTIM_ALGORITHMS",
186+
# base classes
187+
"GraphDispatcher",
188+
"GraphBuilder",
189+
"GraphExporter",
190+
"OperationExporter",
191+
"BaseQuantizer",
192+
"BaseGraphExecutor",
193+
"QuantizationOptimizationPass",
194+
# extension api
195+
"ASSERT_IS_QUANT_OP",
196+
"ASSERT_NUM_OF_INPUT",
197+
"FORCE_CONVERT_DEVICE",
198+
"GET_ATTRIBUTE_FROM_OPERATION",
199+
"GET_VALUE_FROM_INPUTS",
200+
"VALUE_TO_EXECUTING_DEVICE",
201+
]

mppq/api/interface.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
_PLATFORM_TO_QUANTIZER_,
1919
)
2020
from mppq.common import DEFAULT_QUANTIZE_OP
21+
from mppq.defs import empty_ppq_cache
2122
from mppq.dispatcher import DISPATCHER_TABLE
2223
from mppq.dispatcher.base import GraphDispatcher
2324
from mppq.dispatcher.scope import IgnoredScope
@@ -27,8 +28,11 @@
2728
from mppq.ir.base.graph import BaseGraph, GraphBuilder, GraphExporter
2829
from mppq.ir.morph import GraphFormatter, GraphMerger, GraphReplacer
2930
from mppq.quant import TargetPrecision
31+
from mppq.quantization.analyse import graphwise_error_analyse, layerwise_error_analyse
3032
from mppq.quantizer import QUANTIZER, BaseQuantizer
3133
from mppq.quantizer.base import QuantizationOptimizationPass
34+
from mppq.utils.qfunction import ppq_fake_quant, ppq_quant_toint
35+
from mppq.utils.round import ppq_tensor_round
3236

3337

3438
def load_graph(graph_file: Any, parser: GraphBuilder) -> BaseGraph:
@@ -339,3 +343,22 @@ def quantize(
339343
)
340344
exporter = EXPORTER[_PLATFORM_TO_PARSER_[platform]]()
341345
export_graph(graph, f, exporter=exporter)
346+
347+
348+
__all__ = [
349+
"load_graph",
350+
"load_onnx_graph",
351+
"export_graph",
352+
"export_onnx_graph",
353+
"export_config",
354+
"format_graph",
355+
"dispatch_graph",
356+
"load_quantizer",
357+
"quantize",
358+
"empty_ppq_cache",
359+
"graphwise_error_analyse",
360+
"layerwise_error_analyse",
361+
"ppq_tensor_round",
362+
"ppq_fake_quant",
363+
"ppq_quant_toint",
364+
]

mppq/api/types.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
Copyright Wenyi Tang 2025
3+
4+
:Author: Wenyi Tang
5+
:Email: wenyitang@outlook.com
6+
7+
mPPQ enumerations and data types.
8+
"""
9+
10+
from mppq.data import DataType
11+
from mppq.dispatcher import (
12+
AggressiveDispatcher,
13+
AllinDispatcher,
14+
ConservativeDispatcher,
15+
Perseus,
16+
PointDispatcher,
17+
)
18+
from mppq.dispatcher.scope import IgnoredScope
19+
from mppq.executor import (
20+
BaseGraphExecutor,
21+
GraphInput,
22+
QuantRuntimeHook,
23+
RuntimeHook,
24+
TorchExecutor,
25+
TorchQuantizeDelegator,
26+
)
27+
from mppq.executor.op.base import OperationForwardProtocol, TorchBackendContext
28+
from mppq.ir.base.command import (
29+
GraphCommand,
30+
GraphCommandType,
31+
GraphDeployCommand,
32+
QuantizeOperationCommand,
33+
ReplaceOperationCommand,
34+
ReplaceVariableCommand,
35+
TruncateGraphCommand,
36+
)
37+
from mppq.ir.base.graph import BaseGraph
38+
from mppq.ir.base.opdef import Operation, Opset, OpSocket, Variable
39+
from mppq.ir.base.quantize import (
40+
BaseQuantFunction,
41+
QuantableOperation,
42+
QuantableVariable,
43+
)
44+
from mppq.ir.deploy import QuantableGraph, RunnableGraph
45+
from mppq.ir.morph import GraphFormatter, GraphMerger, GraphReplacer
46+
from mppq.ir.search import OperationSet, SearchableGraph
47+
from mppq.ir.training import TrainableGraph
48+
from mppq.quant import (
49+
OperationQuantizationConfig,
50+
QuantizationPolicy,
51+
QuantizationProperty,
52+
QuantizationStates,
53+
RoundingPolicy,
54+
TargetPrecision,
55+
TensorQuantizationConfig,
56+
)
57+
from mppq.quantization.algorithm.training import BlockBuilder, TrainableBlock
58+
from mppq.quantization.optim.base import (
59+
QuantizationOptimizationPass,
60+
QuantizationOptimizationPipeline,
61+
)

mppq/executor/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
from mppq.executor.base import BaseGraphExecutor, QuantRuntimeHook, RuntimeHook
1+
from mppq.executor.base import (
2+
BaseGraphExecutor,
3+
GraphInput,
4+
QuantRuntimeHook,
5+
RuntimeHook,
6+
)
27
from mppq.executor.torch import TorchExecutor, TorchQuantizeDelegator
38

49
__all__ = [
510
"BaseGraphExecutor",
11+
"GraphInput",
612
"QuantRuntimeHook",
713
"RuntimeHook",
814
"TorchExecutor",

mppq/py.typed

Whitespace-only changes.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ exclude = ["mppq/executor/op/default.py"]
4747

4848
[tool.flake8]
4949
ignore = ['E203', 'E231', 'E241', 'W503']
50-
per-file-ignores = ['__init__.py:F401']
50+
per-file-ignores = ['mppq/api/types.py:F401']
5151
max-line-length = 999
5252
max-complexity = 30
5353
count = true

0 commit comments

Comments
 (0)