Skip to content

Commit 41baa7b

Browse files
authored
Disallow shape inference (#128)
The current status quo did shape inference on _some_ layers but not all. This was done through the `computeShapes` method of the ONNXLayer and by examining the implementations of that method, we can see that some calculate the output shape out of the input shapes, but some just blindly copy the tensor's shape. I propose we disallow shape inference and if we want to properly support this feature we can revert this change and implement it properly or depend on another tool to do it for us (e.g. [ONNX's shape inference module](https://onnx.ai/onnx/api/shape_inference.html)). Now, I have disallowed shape inference after lowering because some lowerings actually consumed shapeless tensors and produced correct replacements, but some lowerings produced shapeless tensors themeselves, specifically, the MHSA pass in MemPool. I have disabled all tests that used those lowerings which can be re-enabled once the offending lowerings get fixed. I will create an issue following this if this PR gets accepted. ## Added - Added assertion that all the graph tensors after lowering have a shape annotated ## Changed - Disabled ICCT_ITA_8 MemPool test because it was using a lowering that created shapeless tensors - Added missing shape annotation to the testTypeInferenceDifferentTypes
1 parent 5db6de3 commit 41baa7b

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

.github/workflows/ci-platform-mempool.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,5 @@ jobs:
6969
ICCT
7070
ICCT_ITA
7171
ICCT_8
72-
ICCT_ITA_8
7372
miniMobileNet
7473
miniMobileNetv2

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid
44
## Unreleased (Planned Release Target: v0.2.1)
55

66
### List of Pull Requests
7+
- Disallow shape inference [#128](https://github.com/pulp-platform/Deeploy/pull/128)
78
- Remove memory-aware node bindings [#123](https://github.com/pulp-platform/Deeploy/pull/123)
89
- Fix missing const's layout transformation and refactor NCHWtoNHWC passes [#122](https://github.com/pulp-platform/Deeploy/pull/122)
910
- Fix aliasing [#125](https://github.com/pulp-platform/Deeploy/pull/125)
@@ -51,6 +52,7 @@ This file contains the changelog for the Deeploy project. The changelog is divid
5152
- Per–memory-level usage tracking and worst-case reporting in `NetworkContext`
5253
- Memory/I/O summaries and input/output logging in deployers
5354
- RequantHelpers.py for Neureka's TileConstraints
55+
- Added assertion that all the graph tensors after lowering have a shape annotated
5456

5557
### Changed
5658
- Replaced platform-specific tags (`*-amd64`, `*-arm64`) with direct digest references in `Noelware/docker-manifest-action`.
@@ -85,6 +87,8 @@ This file contains the changelog for the Deeploy project. The changelog is divid
8587
- Removed NodeMemoryLevelChecker, MemoryAwareNodeBinding
8688
- Removed _parseNode from MemoryNetworkDeployer since we don't need the annotations before typeChecking anymore
8789
- Removed Wmem variants of bindings and tile constraints from Neureka
90+
- Disabled ICCT_ITA_8 MemPool test because it was using a lowering that created shapeless tensors
91+
- Added missing shape annotation to the testTypeInferenceDifferentTypes
8892

8993
### Fixed
9094
- Prevent node duplication for graphs generated via GraphSurgeon

Deeploy/DeeployTypes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,6 +3372,11 @@ def _removeIdentityNodes(self):
33723372
for node in filter(lambda x: x.op == "Identity", self.graph.nodes):
33733373
self.graph.deleteNode(node)
33743374

3375+
def _assertTensorsHaveShape(self) -> None:
3376+
missingShapes = [name for name, tensor in self.graph.tensors().items() if tensor.shape is None]
3377+
assert len(missingShapes) == 0, \
3378+
f"Shape inference is not supported.\nFound tensors with missing shape annotation: {missingShapes}"
3379+
33753380
def frontEnd(self):
33763381
"""API hook to prepare the graph to be deployed and build the initial NetworkContext
33773382
@@ -3419,6 +3424,9 @@ def frontEnd(self):
34193424
log.info(f"> Export State {_middlewarePostLoweringFilename}[.onnx|.pkl]")
34203425
self.exportDeeployState(self.deeployStateDir, _middlewarePostLoweringFilename)
34213426

3427+
log.info(" - Assert all tensors have a shape annotation")
3428+
self._assertTensorsHaveShape()
3429+
34223430
log.info("- Perform Graph Parsing")
34233431
try:
34243432
self.parse(self.default_channels_first) # This reparses the lowered graph
27 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)