Skip to content

Commit 9d3445c

Browse files
committed
training-platform core: drop unused loop var and populate zero-sized input defaults
Two fixes to the inputTypes / inputOffsets build loop in both generateTrainingNetwork.py and testMVPTraining.py (the two files share this pattern verbatim). 1. The `name` loop variable in `for graph_idx, name in enumerate(...)` was dead — switched to `for graph_idx in range(len(...))` so the intent is explicit and the lint warning goes away. 2. The zero-sized-input branch (`np.prod(arr.shape) == 0`) previously `pass`ed without populating inputTypes[f"input_{idx}"] or inputOffsets[f"input_{idx}"]. ONNX permits optional placeholder inputs with shape like (0,) and the downstream deployer looks up every input by key, so a zero-sized input would later raise a confusing KeyError far from the cause. Populate the entries with a trivial default (float32 pointer, offset 0) — the type does not matter for codegen since the buffer has no elements, but the key must exist. Verified on Siracusa: simplemlp_train passes 0/4 (diff=0.000000 at every step) in both non-tiled and tiled runs.
1 parent ac4df5b commit 9d3445c

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

DeeployTest/generateTrainingNetwork.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def generateTrainingNetwork(args):
8484
inputOffsets = {}
8585

8686
npz_idx = 0
87-
for graph_idx, name in enumerate(graph_input_names):
87+
for graph_idx in range(len(graph_input_names)):
8888
if graph_idx in grad_acc_set:
8989
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
9090
inputOffsets[f"input_{graph_idx}"] = 0
@@ -102,7 +102,11 @@ def generateTrainingNetwork(args):
102102
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
103103
inputOffsets[f"input_{graph_idx}"] = 0
104104
elif np.prod(arr.shape) == 0:
105-
pass
105+
# Zero-sized input (ONNX allows shape (0, ...) for optional
106+
# placeholders). No data to infer from, but downstream still
107+
# looks up input_{idx} by key, so populate with a trivial default.
108+
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
109+
inputOffsets[f"input_{graph_idx}"] = 0
106110
else:
107111
values = arr.reshape(-1).astype(np.float32)
108112
_type, offset = inferTypeAndOffset(values, signProp = False)

DeeployTest/testMVPTraining.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def generateTiledTrainingNetwork(args) -> None:
7979
inputOffsets = {}
8080

8181
npz_idx = 0
82-
for graph_idx, name in enumerate(graph_input_names):
82+
for graph_idx in range(len(graph_input_names)):
8383
if graph_idx in grad_acc_set:
8484
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
8585
inputOffsets[f"input_{graph_idx}"] = 0
@@ -93,7 +93,11 @@ def generateTiledTrainingNetwork(args) -> None:
9393
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
9494
inputOffsets[f"input_{graph_idx}"] = 0
9595
elif np.prod(arr.shape) == 0:
96-
pass
96+
# Zero-sized input (ONNX allows shape (0, ...) for optional
97+
# placeholders). No data to infer from, but downstream still
98+
# looks up input_{idx} by key, so populate with a trivial default.
99+
inputTypes[f"input_{graph_idx}"] = PointerClass(float32_t)
100+
inputOffsets[f"input_{graph_idx}"] = 0
97101
else:
98102
values = arr.reshape(-1).astype(np.float32)
99103
_type, offset = inferTypeAndOffset(values, signProp = False)

0 commit comments

Comments
 (0)