-
Notifications
You must be signed in to change notification settings - Fork 46
Add 2D Autoencoder and GMM Integration on Siracusa Target #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
745bf7b
4ccd827
36bcd9b
7a798ce
313c0c6
e6fea61
b602497
d7768a9
3914648
f2dbfa2
39ebb53
a7f58df
25cc340
a44f1dd
812db25
2710d0d
3a7fbec
a614fe1
e3d478a
f090df1
01ad221
0a95b20
b879205
bbe8732
ed9a2b5
112bb12
d674d0a
47d756b
4994588
89fc4e7
3075c8a
e2da705
1993f19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only changes to this file are blank lines. Please revert them completely. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,37 @@ class CodeGenVerbosity: | |
| _backendPostParsingFilename = 'backend_post_parsing' | ||
| _backendPostBindingFilename = 'backend_post_binding' | ||
|
|
||
|
|
||
| def _deeployTypeToNpType(ty: Type[BaseType]): | ||
|
|
||
| def _broadcastInteger(ty: Type[IntegerImmediate]): | ||
| if ty.signed: | ||
| return np.dtype(getattr(np, "int" + str(ty.typeWidth))) | ||
| else: | ||
| return np.dtype(getattr(np, "uint" + str(ty.typeWidth))) | ||
|
|
||
| def _broadcastFloat(ty: Type[FloatImmediate]): | ||
| if ty.typeWidth == 16: | ||
| return np.dtype(np.float16) | ||
| if ty.typeWidth == 32: | ||
| return np.dtype(np.float32) | ||
| if ty.typeWidth == 64: | ||
| return np.dtype(np.float64) | ||
| return np.dtype(np.float32) | ||
|
|
||
| if issubclass(ty, Pointer) and hasattr(ty, "referencedType"): | ||
| if issubclass(ty.referencedType, IntegerImmediate): | ||
| return _broadcastInteger(ty.referencedType) | ||
| if issubclass(ty.referencedType, FloatImmediate): | ||
| return _broadcastFloat(ty.referencedType) | ||
| elif issubclass(ty, IntegerImmediate): | ||
| return _broadcastInteger(ty) | ||
| elif issubclass(ty, FloatImmediate): | ||
| return _broadcastFloat(ty) | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| _ctxtExtension = '.pkl' | ||
| _graphExtension = '.onnx' | ||
| _dataExtension = '.data' | ||
|
|
@@ -415,7 +446,12 @@ def __eq__(self, other): | |
| def _valueString(self) -> str: | ||
| values = list(self.values.reshape(-1)) | ||
| if self._type.typeName == 'float32_t*': | ||
| strValues = [f'{value}f' for value in values] | ||
| strValues = [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this fix? |
||
| for value in values: | ||
| literal = f"{float(value):.9g}" | ||
| if "e" not in literal and "." not in literal: | ||
| literal += ".0" | ||
| strValues.append(literal + "f") | ||
| elif self._type.typeName == 'int8_t*': | ||
| strValues = [f'{int(value)}' for value in values] | ||
| else: | ||
|
|
@@ -977,8 +1013,6 @@ def hoistConstant(self, | |
| Returns the name of the newly registed ConstantBuffer | ||
|
|
||
| """ | ||
| assert len(constant.outputs) <= 1, f"Constant {constant.name} has more than one output" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this assert been removed just for a test to pass? :) |
||
|
|
||
| name = name if name is not None else constant.name | ||
|
|
||
| # LMACAN: The shape needs to be copied into a tuple for pickling to work. Don't ask me why.. | ||
|
|
@@ -2027,25 +2061,7 @@ def parse(self, ctxt: NetworkContext, default_channels_first: bool) -> Tuple[Net | |
| return ctxt, False | ||
|
|
||
| def _broadcastToNpType(self, ty: Type[BaseType]): | ||
|
|
||
| def _broadcastInteger(ty: Type[IntegerImmediate]): | ||
| if ty.signed: | ||
| return np.dtype(getattr(np, "int" + str(ty.typeWidth))) | ||
| else: | ||
| return np.dtype(getattr(np, "uint" + str(ty.typeWidth))) | ||
|
|
||
| def _broadcastFloat(ty: Type[FloatImmediate]): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that you just moved the entire content (with some modifications) from here into _deeployTypeToNpType that then gets called here. I don't see the reason for this, I think it's better to just apply the changes directly here, no need for a separate function |
||
| return np.dtype(getattr(np, "double")) | ||
|
|
||
| if issubclass(ty, Pointer) and hasattr(ty, "referencedType"): | ||
| if issubclass(ty.referencedType, IntegerImmediate): | ||
| return _broadcastInteger(ty.referencedType) | ||
| elif issubclass(ty, IntegerImmediate): | ||
| return _broadcastInteger(ty) | ||
| elif issubclass(ty, FloatImmediate): | ||
| return _broadcastFloat(ty) | ||
|
|
||
| return None | ||
| return _deeployTypeToNpType(ty) | ||
|
|
||
| def typeCheck(self, ctxt: NetworkContext) -> Tuple[NetworkContext, bool]: | ||
| """Invokes the mapper's typeCheck method | ||
|
|
@@ -2106,8 +2122,9 @@ def bind(self, ctxt: NetworkContext) -> Tuple[NetworkContext, bool]: | |
| elif ctxt.is_global(node.name): | ||
| npType = self._broadcastToNpType(ctxt.globalObjects[node.name]._type) | ||
| if isinstance(ctxt.globalObjects[node.name], ConstantBuffer): | ||
| if isinstance(node, gs.Constant): | ||
| if isinstance(node, gs.Constant) and npType is not None: | ||
| node.values = node.values.astype(npType) | ||
| node.export_dtype = npType | ||
| else: | ||
| node.shape = ctxt.globalObjects[node.name].shape | ||
| if npType is not None: | ||
|
|
@@ -2856,7 +2873,17 @@ def generateInferenceInitializationCode(self) -> str: | |
|
|
||
| name = node.name | ||
| node.name = self.ctxt._mangle(node.name) | ||
| callStack += node.init() | ||
|
|
||
| if ("TILING_CODEGEN" not in node.name and isinstance(node, VariableBuffer) and hasattr(node, "_type") | ||
| and issubclass(node._type, Pointer)): | ||
| # Local inference buffers are late-bound by the generated layer code. Initializing them to NULL keeps | ||
| # clang from flagging false-positive uninitialized reads on paths where the assignment is emitted in a | ||
| # separate closure, and marking them unused avoids noise for scratch buffers that are reserved | ||
| # generically but optimized away for a specific layer instance. | ||
| typeName = node._instance.typeName if hasattr(node, "_instance") else node._type.typeName | ||
| callStack += f"{typeName} {node.name} __attribute__((unused)) = NULL;\n" | ||
| else: | ||
| callStack += node.init() | ||
| node.name = name | ||
|
|
||
| return callStack | ||
|
|
@@ -3121,6 +3148,15 @@ def _exportGraph(self, folderPath, fileName): | |
| # VJUNG: ONNX-Graphsurgeon needs tensors to be in their export types | ||
| constTensors = [tensor for tensor in self.graph.tensors().values() if isinstance(tensor, gs.Constant)] | ||
| for tensor in constTensors: | ||
| if tensor.name in self.ctxt.globalObjects: | ||
| ctxtTensor = self.ctxt.globalObjects[tensor.name] | ||
| if isinstance(ctxtTensor, ConstantBuffer) and hasattr(ctxtTensor, "_type"): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? |
||
| npType = _deeployTypeToNpType(ctxtTensor._type) | ||
| if npType is not None: | ||
| tensor.values = tensor.values.astype(npType) | ||
| tensor.export_dtype = npType | ||
| continue | ||
|
|
||
| if tensor.dtype != tensor.export_dtype: | ||
| tensor.values = tensor.values.astype(tensor.export_dtype) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,8 @@ def apply(self, graph: gs.Graph) -> Tuple[gs.Graph]: | |
| engine = self.engineMapper.mapNodeToEngine(node, graph) | ||
| if engine is not None: | ||
| node.attrs["engine"] = engine.name | ||
| if hasattr(engine, "n_cores"): | ||
| node.attrs["n_cores"] = engine.n_cores | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good approach IMO. The number of cores is not a node attribute (conceptually, the node attributes should follow the ones that exist in the real ONNX nodes). Plus, this issue of passing the information about the number of cores should already be solved, and the value should already exist in the operator representation, it's passed here. If this value doesn't get passed in your case, we should identify the root cause.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking a little more into it, maybe you need to add NeurekaEngine in the list here. |
||
| return graph | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,6 +340,12 @@ def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorReprese | |
| if inputShapes[1] == () or inputShapes[1] == []: | ||
| inputShapes[1] = (1,) | ||
|
|
||
| # Scalars and singletons should broadcast to the tensor operand, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
| # not shrink the tensor shape to (1,). | ||
| if tuple(inputShapes[1]) == (1,): | ||
| inputShapes[1] = inputShapes[0] | ||
| return (inputShapes, outputShapes) | ||
|
|
||
| if len(inputShapes[0]) > len(inputShapes[1]): | ||
| inputShapes[1] = inputShapes[0] | ||
| else: | ||
|
|
@@ -435,8 +441,34 @@ def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorReprese | |
| return (inputShapes, outputShapes) | ||
|
|
||
|
|
||
| class ReluLayer(SingleOperationPerElementLayer): | ||
| pass | ||
| class ReduceLogSumExpLayer(ONNXLayer): | ||
|
|
||
| def __init__(self, maps: List[NodeMapper]): | ||
| super().__init__(maps) | ||
|
|
||
| def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorRepresentation, | ||
| channels_first) -> Tuple[Shape, Shape]: | ||
| axis = operatorRepresentation['axes'][0] | ||
| inputShape = list(copy.deepcopy(inputShapes[0])) | ||
|
|
||
| if operatorRepresentation['keepdims']: | ||
| outputShape = inputShape | ||
| outputShape[axis] = 1 | ||
| else: | ||
| outputShape = inputShape[:axis] + inputShape[axis + 1:] | ||
| if len(outputShape) == 0: | ||
| outputShape = [1] | ||
|
|
||
| return (inputShapes, [outputShape]) | ||
|
|
||
|
|
||
| class ReluLayer(ONNXLayer): | ||
|
|
||
| def __init__(self, maps: List[NodeMapper]): | ||
| super().__init__(maps) | ||
|
|
||
| def computeOps(self): | ||
| return self.mapper.parser.operatorRepresentation['size'] | ||
|
|
||
|
|
||
| class LayerNormLayer(ONNXLayer): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that these changes were made to adjust your local work env, and should not be pushed to main. Please revert them.