Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
testFloatMul
Quant
Dequant
QuantizedLinear


generic-models:
Expand Down Expand Up @@ -270,6 +271,7 @@ jobs:
testFloatMul
Quant
Dequant
QuantizedLinear
num-cores: 8

siracusa-models:
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,11 @@ Change main.c to use OUTPUTTYPE instead of float
- Custom `DequantPatternPass` class to replace matched patterns with a single `Dequant` operator
- Parser implementation in `Parsers.py` to extract dequantization parameters
- C template implementation in `DequantTemplate.py` for efficient dequantization
- Type checker implementation in `TypeCheckers.py` to handle bit-width and signedness
- Type checker implementation in `TypeCheckers.py` to handle bit-width and signedness

## Implemented Updates for handling Quantized Linear DNN

### Added
- New `_sanitizeGraphNames` function to sanitize the names of the nodes and tensors of the graph
- Implementation for both Generic and Siracusa targets in the Deeploy framework
- Modified the binding of dequant in `Bindings.py` to handle int32 after GEMM operation
14 changes: 14 additions & 0 deletions Deeploy/DeeployTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3129,6 +3129,18 @@ def _foldConstants(self, graph: gs.Graph):
graph.fold_constants()
graph.cleanup().toposort()

def _sanitizeGraphNames(self, graph: gs.Graph):

def sanitize(name: str) -> str:
# Remove illegal characters: anything not a letter, digit, or underscore.
sanitized_name = re.sub(r'[^a-zA-Z0-9_]', '', name)
return sanitized_name

for node in graph.nodes:
node.name = sanitize(node.name)
for tensor in node.inputs + node.outputs:
tensor.name = sanitize(tensor.name)

# Don't override this
# Duplicate constants with multiple users
def _removeEmptyInputs(self, graph: gs.Graph):
Expand All @@ -3147,6 +3159,8 @@ def frontEnd(self):
for idx, outputNode in enumerate(self.graph.outputs):
outputNode.name = "output_" + str(idx)

self._sanitizeGraphNames(self.graph)

self._removeEmptyInputs(self.graph)

self._duplicateConstants(self.graph)
Expand Down
3 changes: 3 additions & 0 deletions Deeploy/Targets/Generic/Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,7 @@
BasicDequantBindings = [
NodeBinding(DequantChecker([PointerClass(int8_t)], [PointerClass(float32_t)]), DequantTemplate.referenceTemplate,
BasicTransformer),
] + [
NodeBinding(DequantChecker([PointerClass(int32_t)], [PointerClass(float32_t)]), DequantTemplate.referenceTemplate,
BasicTransformer),
]
3 changes: 3 additions & 0 deletions Deeploy/Targets/PULPOpen/Bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,7 @@
BasicDequantBindings = [
NodeBinding(DequantChecker([PointerClass(int8_t)], [PointerClass(float32_t)]), DequantTemplate.referenceTemplate,
ForkTransformer),
] + [
NodeBinding(DequantChecker([PointerClass(int32_t)], [PointerClass(float32_t)]), DequantTemplate.referenceTemplate,
ForkTransformer),
]
6 changes: 4 additions & 2 deletions Deeploy/Targets/PULPOpen/Platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
NodeTemplate, StructBuffer, TopologyOptimizer, TransientBuffer, VariableBuffer
from Deeploy.MemoryLevelExtension.MemoryLevels import MemoryHierarchy, MemoryLevel
from Deeploy.MemoryLevelExtension.NetworkDeployers.MemoryLevelDeployer import MemoryPlatform, MemoryPlatformWrapper
from Deeploy.Targets.Generic.Bindings import BasicPad1DBindings, BasicPad2DBindings, BasicRQIntegerDivBinding
from Deeploy.Targets.Generic.Bindings import BasicGEMMBindings, BasicPad1DBindings, BasicPad2DBindings, \
BasicRQIntegerDivBinding
from Deeploy.Targets.Generic.Layers import AddLayer, ConcatLayer, ConvLayer, DequantLayer, GatherLayer, GELULayer, \
GEMMLayer, LayerNormLayer, MatMulLayer, MaxPoolLayer, MulLayer, PadLayer, QuantLayer, ReduceMeanLayer, ReluLayer, \
RequantShiftLayer, ReshapeLayer, RQIntegerDivLayer, RQSiGELULayer, RQSiHardswishLayer, SliceLayer, SoftmaxLayer, \
Expand Down Expand Up @@ -110,12 +111,13 @@

QuantMapper = NodeMapper(QuantParser(), BasicQuantBindings)
DequantMapper = NodeMapper(DequantParser(), BasicDequantBindings)
GEMMDequantMapper = NodeMapper(PULPGEMMParser(), BasicGEMMBindings)

PULPMapping = {
'Conv': ConvLayer([FPConv2DMapper]),
'RequantizedConv': PULPRQSConvLayer([Conv2DMapper, DWConv2DMapper, Conv1DMapper, DWConv1DMapper]),
'RequantizedGemm': PULPRQSGEMMLayer([MatrixVecMapper, TallGEMMMapper, GEMMMapper]),
'Gemm': GEMMLayer([FloatGEMMMapper]),
'Gemm': GEMMLayer([FloatGEMMMapper, GEMMDequantMapper]),
'Gelu': GELULayer([GELUMapper]),
'LayerNormalization': LayerNormLayer([LayerNormMapper]),
'MaxPool': MaxPoolLayer([MaxPool2DMapper]),
Expand Down
Binary file added DeeployTest/Tests/QuantizedLinear/inputs.npz
Binary file not shown.
Binary file added DeeployTest/Tests/QuantizedLinear/network.onnx
Binary file not shown.
Binary file added DeeployTest/Tests/QuantizedLinear/outputs.npz
Binary file not shown.
Loading