Skip to content

Commit 284f145

Browse files
committed
training-platform core: apply pre-commit formatting (yapf/isort/clang-format)
1 parent cc1f68b commit 284f145

19 files changed

Lines changed: 537 additions & 470 deletions

Deeploy/Targets/Generic/TypeCheckers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ class SoftmaxCrossEntropyLossChecker(SignPropTypeChecker):
574574
def __init__(self, input_types: Sequence[Type[Pointer]], output_types: Sequence[Type[Pointer]]):
575575
super().__init__(input_types, output_types)
576576

577-
def checkOutputType(self, inputs: List[VariableBuffer],
578-
operatorRepresentation: OperatorRepresentation) -> bool:
577+
def checkOutputType(self, inputs: List[VariableBuffer], operatorRepresentation: OperatorRepresentation) -> bool:
579578
# The parser sets 'loss' to a non-empty string for 2-output nodes, '' for 1-output.
580579
# Use this to determine the actual output count and match it against this binding.
581580
actual_num_outputs = 2 if operatorRepresentation.get('loss', '') != '' else 1

Deeploy/Targets/PULPOpen/Bindings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,16 @@
379379
PULPInPlaceAccumulatorV2Bindings = [
380380
NodeBinding(
381381
InPlaceAccumulatorV2Checker(
382-
[PointerClass(float32_t), PointerClass(float32_t), PointerClass(uint8_t)], [PointerClass(float32_t)]),
383-
FloatInPlaceAccumulatorV2Template.referenceTemplate, ForkTransformer)
382+
[PointerClass(float32_t), PointerClass(float32_t),
383+
PointerClass(uint8_t)], [PointerClass(float32_t)]), FloatInPlaceAccumulatorV2Template.referenceTemplate,
384+
ForkTransformer)
384385
]
385386

386387
PULPInPlaceAccumulatorV2TiledBindings = [
387388
NodeBinding(
388389
InPlaceAccumulatorV2Checker(
389-
[PointerClass(float32_t), PointerClass(float32_t), PointerClass(uint8_t)], [PointerClass(float32_t)]),
390+
[PointerClass(float32_t), PointerClass(float32_t),
391+
PointerClass(uint8_t)], [PointerClass(float32_t)]),
390392
FloatInPlaceAccumulatorV2Template.tiledReferenceTemplate, ForkTransformer)
391393
]
392394

Deeploy/Targets/PULPOpen/Platform.py

Lines changed: 82 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
SoftmaxCrossEntropyLossLayer, SoftmaxGradLayer, SoftmaxLayer, TransposeLayer, iHardswishLayer, iRMSNormLayer
2121
from Deeploy.Targets.Generic.Parsers import AddParser, ConcatParser, DequantParser, FlattenParser, GatherParser, \
2222
GELUGradParser, GELUParser, GEMMParser, InPlaceAccumulatorV2Parser, LayerNormGradParser, LayerNormParser, \
23-
MatMulParser, MaxPool1DParser, MaxPool2DParser, MulParser, Pad1DParser, Pad2DParser, QuantParser, \
24-
ReduceSumParser, ReluParser, RequantShiftParser, ReshapeParser, RQAddParser, RQIntegerDivParser, RQSiGELUParser, \
23+
MatMulParser, MaxPool1DParser, MaxPool2DParser, MulParser, Pad1DParser, Pad2DParser, QuantParser, ReduceSumParser, \
24+
ReluParser, RequantShiftParser, ReshapeParser, RQAddParser, RQIntegerDivParser, RQSiGELUParser, \
2525
RQSiHardswishParser, SGDParser, SliceParser, SoftmaxCrossEntropyLossGradParser, SoftmaxCrossEntropyLossParser, \
2626
SoftmaxGradParser, SoftmaxParser, TransposeParser, UniformRequantShiftParser, UnsqueezeParser, iHardswishParser, \
2727
iRMSNormParser, iSoftmaxParser
@@ -116,48 +116,88 @@
116116
DequantMapper = NodeMapper(DequantParser(), BasicDequantBindings)
117117
GEMMDequantMapper = NodeMapper(PULPGEMMParser(), BasicGEMMBindings)
118118
PULPMapping = {
119-
'Conv': ConvLayer([FPConv2DMapper, FPDWConv2DMapper]),
120-
'RequantizedConv': PULPRQSConvLayer([Conv2DMapper, DWConv2DMapper, Conv1DMapper, DWConv1DMapper]),
121-
'RequantizedGemm': PULPRQSGEMMLayer([MatrixVecMapper, TallGEMMMapper, GEMMMapper]),
122-
'Gemm': GEMMLayer([FloatGEMMMapper, GEMMDequantMapper]),
123-
'Gelu': GELULayer([GELUMapper]),
124-
'GeluGrad': GELUGradLayer([GELUGradMapper]),
125-
'LayerNormalization': LayerNormLayer([LayerNormMapper]),
126-
'LayerNormalizationGrad': LayerNormGradLayer([LayerNormGradMapper]),
127-
'MaxPool': MaxPoolLayer([MaxPool1DMapper, MaxPool2DMapper]),
128-
'RequantizediGELU': RQSiGELULayer([RQGELU_int8_Mapper]),
129-
'RQIntegerDiv': RQIntegerDivLayer([RQIntegerDivMapper]),
130-
'MatMul': MatMulLayer([MatMulMapper]),
131-
'IntegerMean': ReduceMeanLayer([ReduceMeanMapper]),
132-
'iSoftmax': SoftmaxLayer([Softmax_int8_Mapper]),
133-
'Softmax': SoftmaxLayer([SoftmaxMapper]),
134-
'ReduceMean': ReduceMeanLayer([ReduceMeanMapper]),
135-
'ReduceSum': ReduceSumLayer([ReduceSumMapper]),
136-
'RequantShift': RequantShiftLayer([UniformRequantShiftMapper, RequantShiftMapper]),
137-
'Add': AddLayer([AddMapper]),
138-
'Flatten': ReshapeLayer([FlattenMapper]),
139-
'Gather': GatherLayer([GatherMapper]),
140-
'Mul': MulLayer([MulMapper]),
141-
'Pad': PadLayer([Pad1DMapper, Pad2DMapper]),
142-
'Relu': ReluLayer([ReluMapper]),
143-
'Reshape': ReshapeLayer([ReshapeMapper]),
144-
'Squeeze': ReshapeLayer([UnsqueezeMapper]),
145-
'Transpose': TransposeLayer([TransposeMapper]),
146-
'Unsqueeze': ReshapeLayer([UnsqueezeMapper]),
147-
'Slice': SliceLayer([SliceMapper, DMASliceMapper]),
148-
'RequantizedAdd': AddLayer([RQAddMapper]),
149-
'Concat': ConcatLayer([ConcatMapper]),
150-
'iRMSNorm': iRMSNormLayer([iRMSNormMapper]),
151-
'iHardswish': iHardswishLayer([iHardswishMapper]),
152-
'RequantizediHardswish': RQSiHardswishLayer([RQSiHardswishMapper]),
153-
'Quant': QuantLayer([QuantMapper]),
154-
'Dequant': QuantLayer([DequantMapper]),
155-
'SoftmaxGrad': SoftmaxGradLayer([SoftmaxGradMapper]),
119+
'Conv':
120+
ConvLayer([FPConv2DMapper, FPDWConv2DMapper]),
121+
'RequantizedConv':
122+
PULPRQSConvLayer([Conv2DMapper, DWConv2DMapper, Conv1DMapper, DWConv1DMapper]),
123+
'RequantizedGemm':
124+
PULPRQSGEMMLayer([MatrixVecMapper, TallGEMMMapper, GEMMMapper]),
125+
'Gemm':
126+
GEMMLayer([FloatGEMMMapper, GEMMDequantMapper]),
127+
'Gelu':
128+
GELULayer([GELUMapper]),
129+
'GeluGrad':
130+
GELUGradLayer([GELUGradMapper]),
131+
'LayerNormalization':
132+
LayerNormLayer([LayerNormMapper]),
133+
'LayerNormalizationGrad':
134+
LayerNormGradLayer([LayerNormGradMapper]),
135+
'MaxPool':
136+
MaxPoolLayer([MaxPool1DMapper, MaxPool2DMapper]),
137+
'RequantizediGELU':
138+
RQSiGELULayer([RQGELU_int8_Mapper]),
139+
'RQIntegerDiv':
140+
RQIntegerDivLayer([RQIntegerDivMapper]),
141+
'MatMul':
142+
MatMulLayer([MatMulMapper]),
143+
'IntegerMean':
144+
ReduceMeanLayer([ReduceMeanMapper]),
145+
'iSoftmax':
146+
SoftmaxLayer([Softmax_int8_Mapper]),
147+
'Softmax':
148+
SoftmaxLayer([SoftmaxMapper]),
149+
'ReduceMean':
150+
ReduceMeanLayer([ReduceMeanMapper]),
151+
'ReduceSum':
152+
ReduceSumLayer([ReduceSumMapper]),
153+
'RequantShift':
154+
RequantShiftLayer([UniformRequantShiftMapper, RequantShiftMapper]),
155+
'Add':
156+
AddLayer([AddMapper]),
157+
'Flatten':
158+
ReshapeLayer([FlattenMapper]),
159+
'Gather':
160+
GatherLayer([GatherMapper]),
161+
'Mul':
162+
MulLayer([MulMapper]),
163+
'Pad':
164+
PadLayer([Pad1DMapper, Pad2DMapper]),
165+
'Relu':
166+
ReluLayer([ReluMapper]),
167+
'Reshape':
168+
ReshapeLayer([ReshapeMapper]),
169+
'Squeeze':
170+
ReshapeLayer([UnsqueezeMapper]),
171+
'Transpose':
172+
TransposeLayer([TransposeMapper]),
173+
'Unsqueeze':
174+
ReshapeLayer([UnsqueezeMapper]),
175+
'Slice':
176+
SliceLayer([SliceMapper, DMASliceMapper]),
177+
'RequantizedAdd':
178+
AddLayer([RQAddMapper]),
179+
'Concat':
180+
ConcatLayer([ConcatMapper]),
181+
'iRMSNorm':
182+
iRMSNormLayer([iRMSNormMapper]),
183+
'iHardswish':
184+
iHardswishLayer([iHardswishMapper]),
185+
'RequantizediHardswish':
186+
RQSiHardswishLayer([RQSiHardswishMapper]),
187+
'Quant':
188+
QuantLayer([QuantMapper]),
189+
'Dequant':
190+
QuantLayer([DequantMapper]),
191+
'SoftmaxGrad':
192+
SoftmaxGradLayer([SoftmaxGradMapper]),
156193
'SoftmaxCrossEntropyLoss':
157194
SoftmaxCrossEntropyLossLayer([SoftmaxCrossEntropyLossDualOutputMapper, SoftmaxCrossEntropyLossMapper]),
158-
'SoftmaxCrossEntropyLossGrad': SoftmaxCrossEntropyLossGradLayer([SoftmaxCrossEntropyLossGradMapper]),
159-
'SGD': SGDLayer([SGDMapper]),
160-
'InPlaceAccumulatorV2': InPlaceAccumulatorV2Layer([InPlaceAccumulatorV2Mapper]),
195+
'SoftmaxCrossEntropyLossGrad':
196+
SoftmaxCrossEntropyLossGradLayer([SoftmaxCrossEntropyLossGradMapper]),
197+
'SGD':
198+
SGDLayer([SGDMapper]),
199+
'InPlaceAccumulatorV2':
200+
InPlaceAccumulatorV2Layer([InPlaceAccumulatorV2Mapper]),
161201
}
162202

163203

Deeploy/Targets/PULPOpen/Templates/FloatInPlaceAccumulatorV2Template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
from typing import Dict, List, Tuple
5+
from typing import List, Tuple
66

7-
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer
7+
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation
88

99

1010
class _PULPInPlaceAccumulatorV2Template(NodeTemplate):

Deeploy/Targets/PULPOpen/Templates/SGDTemplate.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import List, Tuple
66

7-
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation, VariableBuffer
7+
from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation
88

99

1010
class _PULPSGDTemplate(NodeTemplate):
@@ -31,8 +31,7 @@ def alignToContext(
3131

3232
# Make weight_updated share weight's L2 allocation (no separate malloc).
3333
# The egress DMA then writes updated weights back to weight's L2 address.
34-
weight_updated.allocTemplate = NodeTemplate(
35-
" ${name} = (${type.typeName}) " + str(weight._instance) + ";")
34+
weight_updated.allocTemplate = NodeTemplate(" ${name} = (${type.typeName}) " + str(weight._instance) + ";")
3635
weight_updated.deallocTemplate = NodeTemplate("")
3736
return ctxt, operatorRepresentation, []
3837

Deeploy/Targets/PULPOpen/TileConstraints/SGDTileConstraint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SGDTileConstraint(BOPTileConstraint):
1111
dataIn2Name = 'grad'
1212
dataOutName = 'weight_updated'
1313

14+
1415
class ReluGradTileConstraint(BOPTileConstraint):
1516

1617
dataIn1Name = 'grad_out'

Deeploy/Targets/PULPOpen/TileConstraints/SoftmaxCrossEntropyLossDualOutputTileConstraint.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import copy
6-
from typing import Dict, List, Tuple, Union
6+
from typing import List, Tuple
77

88
from Deeploy.DeeployTypes import NetworkContext, OperatorRepresentation
9+
from Deeploy.Targets.PULPOpen.TileConstraints.SoftmaxCrossEntropyTileConstraint import SoftmaxCrossEntropyTileConstraint
910
from Deeploy.TilingExtension.MemoryConstraints import NodeMemoryConstraint
1011
from Deeploy.TilingExtension.TileConstraint import TileConstraint
11-
from Deeploy.TilingExtension.TilerModel import TilerModel
12-
from Deeploy.TilingExtension.TilingCodegen import AbsoluteHyperRectangle, HyperRectangle, TilingSchedule, \
13-
VariableReplacementScheme
14-
from Deeploy.Targets.PULPOpen.TileConstraints.SoftmaxCrossEntropyTileConstraint import \
15-
SoftmaxCrossEntropyTileConstraint
12+
from Deeploy.TilingExtension.TilingCodegen import HyperRectangle, TilingSchedule, VariableReplacementScheme
1613

1714

1815
class SoftmaxCrossEntropyLossDualOutputTileConstraint(SoftmaxCrossEntropyTileConstraint):
@@ -35,8 +32,8 @@ def wrapTilingSolution(
3532
cls, tilingSolution: NodeMemoryConstraint, targetMemLevel: str, ctxt: NetworkContext,
3633
operatorRepresentation: OperatorRepresentation) -> Tuple[VariableReplacementScheme, List[TilingSchedule]]:
3734

38-
logProbVar = operatorRepresentation[cls.dataOutName] # e.g. "onnx::log_prob::3"
39-
lossVar = operatorRepresentation.get(cls.dataLossName, '')
35+
logProbVar = operatorRepresentation[cls.dataOutName] # e.g. "onnx::log_prob::3"
36+
lossVar = operatorRepresentation.get(cls.dataLossName, '')
4037

4138
# If loss is absent (empty string — single-output fallback) or not in the
4239
# memory constraint dict, delegate straight to the parent unchanged.
@@ -52,8 +49,8 @@ def wrapTilingSolution(
5249

5350
# Call the base-class wrapTilingSolution, which runs cube computation and
5451
# calls serializeTilingSolution for log_prob.
55-
varReplacement, tilingSchedules = super().wrapTilingSolution(
56-
singleOutputSolution, targetMemLevel, ctxt, operatorRepresentation)
52+
varReplacement, tilingSchedules = super().wrapTilingSolution(singleOutputSolution, targetMemLevel, ctxt,
53+
operatorRepresentation)
5754

5855
# Extend each TilingSchedule to include the scalar loss output.
5956
# The loss tensor is always 1 element (0-d scalar represented as [1] for DMA).

Deeploy/Targets/PULPOpen/Tiler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from Deeploy.Targets.Generic.TileConstraints.UnaryTileConstraint import UnaryTileConstraint
1717
from Deeploy.Targets.PULPOpen.Bindings import PULPAddBindings, PULPConcatBindings, PULPFloatConv2DBindings, \
1818
PULPFloatDWConv2DBindings, PULPFloatGELUBinding, PULPFloatGELUGradBinding, PULPFloatGEMMBindings, \
19-
PULPGatherBindings, PULPiHardswishBindings, PULPiRMSNormBindings, PULPiRQSGELUBindings, PULPLayernormBinding, \
20-
PULPLayernormGradBinding, PULPMatMulBindings, PULPMaxPool1DBindings, PULPMaxPool2DBindings, PULPMulBindings, \
21-
PULPReduceMeanBindings, PULPReduceSumBindings, PULPReluBinding, PULPReshapeBindings, PULPRQAddBindings, \
22-
PULPInPlaceAccumulatorV2Bindings, PULPInPlaceAccumulatorV2TiledBindings, PULPRQSBindings, \
23-
PULPRQSConv1DBindings, PULPRQSConv2DBindings, PULPRQSDWConv2DBindings, PULPRQSGEMMBindings, \
24-
PULPRQSiHardswishBindings, PULPRQSMatrixVecBindings, PULPRQSTallGEMMBindings, PULPSGDBindings, PULPSliceBindings, \
25-
PULPSoftmaxBindings, PULPSoftmaxCrossEntropyLossBindings, PULPSoftmaxCrossEntropyLossDualOutputBindings, \
19+
PULPGatherBindings, PULPiHardswishBindings, PULPInPlaceAccumulatorV2TiledBindings, PULPiRMSNormBindings, \
20+
PULPiRQSGELUBindings, PULPLayernormBinding, PULPLayernormGradBinding, PULPMatMulBindings, PULPMaxPool1DBindings, \
21+
PULPMaxPool2DBindings, PULPMulBindings, PULPReduceMeanBindings, PULPReduceSumBindings, PULPReluBinding, \
22+
PULPReshapeBindings, PULPRQAddBindings, PULPRQSBindings, PULPRQSConv1DBindings, PULPRQSConv2DBindings, \
23+
PULPRQSDWConv2DBindings, PULPRQSGEMMBindings, PULPRQSiHardswishBindings, PULPRQSMatrixVecBindings, \
24+
PULPRQSTallGEMMBindings, PULPSGDBindings, PULPSliceBindings, PULPSoftmaxBindings, \
25+
PULPSoftmaxCrossEntropyLossBindings, PULPSoftmaxCrossEntropyLossDualOutputBindings, \
2626
PULPSoftmaxCrossEntropyLossGradBindings, PULPSoftmaxGradBindings, PULPTransposeBindings, PULPUniformRQSBindings
2727
from Deeploy.Targets.PULPOpen.TileConstraints.ConvTileConstraint import Conv2DTileConstraint, RQConv1DTileConstraint, \
2828
RQConv2DTileConstraint

Deeploy/TilingExtension/TilerExtension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ def _convertCtxtToStaticSchedule(self, ctxt: NetworkContext,
333333
if _buffer._memoryLevel != memoryLevel:
334334
continue
335335

336-
if hasattr(_buffer, "_alias") and ctxt.is_global(_buffer._alias) and _buffer._alias not in blockNames:
336+
if hasattr(_buffer, "_alias") and ctxt.is_global(
337+
_buffer._alias) and _buffer._alias not in blockNames:
337338
continue
338339

339340
if hasattr(_buffer, "_alias") and _buffer._alias in blockNames:

0 commit comments

Comments
 (0)