Skip to content

fix(export): preserve graph order for input encoding assignment - #4153

Open
Santosh Todkar (todkarsant) wants to merge 1 commit into
qualcomm:developfrom
todkarsant:fix/export-input-encoding-order
Open

Santosh Todkar (todkarsant) wants to merge 1 commit into
qualcomm:developfrom
todkarsant:fix/export-input-encoding-order

Conversation

@todkarsant

Copy link
Copy Markdown

Summary

  • Replace set() with ordered list + dedup set for start_op_names in _get_layer_input_tensors, fixing non-deterministic input encoding assignment during ONNX export

Problem

When EXPORT_TO_ONNX_DIRECT = True, _get_layer_input_tensors builds start_op_names as a Python set(). Since set iteration order depends on PYTHONHASHSEED, the resulting input_tensors list has non-deterministic order. When this list is later zip'd with input_encodings by index, encodings get assigned to the wrong ONNX tensors.

For modules that expand to many ONNX ops (e.g. ScatterND with ~40 ops), the encoding for input 0 (data) can land on the updates path, an integer Shape output, or the indices input.

Fix

Use list + set for dedup (preserving graph order from op_names), matching the pattern already used on the output side in find_op_names_for_layer (lines 1527-1546).

Fixes #4141

Replace set() with ordered list + dedup set for start_op_names in
_get_layer_input_tensors, matching the pattern already used on the
output side in find_op_names_for_layer.

set() iteration order depends on PYTHONHASHSEED, so when a module
expands to many ONNX ops (e.g. ScatterND ~40 ops), input encodings
get zip'd to wrong tensors — data encoding can land on the updates
path, an integer Shape output, or the indices input.

Fixes qualcomm#4141

Signed-off-by: Santosh Todkar <todkarsant@gmail.com>
@todkarsant

Copy link
Copy Markdown
Author

michaelgtuttle Could you review? This fixes the non-deterministic input encoding assignment during ONNX export reported in #4141.

@todkarsant

Copy link
Copy Markdown
Author

Abhi Khobare (@abhikhobare) Could you review this PR? It preserves graph order for input encoding assignment during ONNX export. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sim.export: input encodings of a module exported as several ONNX nodes land on tensors chosen by set order (ScatterND data encoding on the updates path)

1 participant