Skip to content

Fix some things before yet another optimizer rework - #24

Open
Human9000-bit wants to merge 1 commit into
enthropy7:mainfrom
Human9000-bit:onnx-optimizer-stage0
Open

Fix some things before yet another optimizer rework#24
Human9000-bit wants to merge 1 commit into
enthropy7:mainfrom
Human9000-bit:onnx-optimizer-stage0

Conversation

@Human9000-bit

Copy link
Copy Markdown
Collaborator

Stage 0 of the three-layer optimizer arc: correctness and dead-code
prerequisites, so the layers that follow are measured against a clean
baseline.

Stage 0 of the three-layer optimizer arc: correctness and dead-code
prerequisites, so the layers that follow are measured against a clean
baseline. No perf win is claimed.

remove_dropout_nodes deleted nodes by NodeProto.name, which ONNX makes
optional. A single unnamed Dropout put the empty string into the delete
set, and `retain(|n| !dropout_names.contains(&n.name))` then removed
every unnamed node in the graph — the new fixture
remove_dropout_keeps_unnamed_siblings drops from three nodes to zero
against the old code. The same block also deleted malformed Dropout
nodes that the rewiring loop above had skipped, orphaning their
consumers. It now records the indices it actually rewired and removes
those, matching the reverse-removal idiom the other passes use.

eliminate_squeeze_unsqueeze_pairs accepted overlapping inverse pairs.
A Squeeze -> Unsqueeze -> Squeeze chain with matching axes satisfies the
predicate at both i and i+1, and the reverse-removal loop then deleted
already-shifted indices — in the new
eliminate_squeeze_unsqueeze_handles_overlapping_chain fixture the
downstream Relu disappears entirely. A next_free cursor now skips
matches that overlap an accepted pair.

Nine of the twelve passes called rebuild_runtime_index() on exit, so one
optimize_onnx_graph re-ran execution-plan construction and weight
prepacking about ten times over. Each pass now exposes a `run` that
mutates without rebuilding and reports whether it changed anything; the
driver calls those and rebuilds once at the end. The public per-pass
entry points keep rebuilding, because a stale plan holds node indices
and yscv-quantize-cli and llm-bench call several passes standalone.
fold_conv_mul and fold_conv_add_const lose their public wrappers — the
driver was their only caller and they were never re-exported from lib.rs.

run_onnx_model_sequential is gone: ~600 lines re-deriving Conv+BN+Relu,
Conv+SiLU and Conv+Add patterns on every inference. It was reachable
only when the load-time execution plan was empty, which no graph with
nodes produces; confirmed by panicking in that branch and running the
workspace suite (53 binaries, zero hits). Its orphaned helpers went with
it — find_relu_after_identity_chain, mark_skip_indices,
exec_reshape_zerocopy, and the use_counts-taking
try_reshape_nhwc_passthrough. The plan path's _inner variant and the
NHWC-passthrough optimization are untouched. TensorEnv::get_mut survives
behind #[cfg(feature = "gpu")], its only remaining callers.

Validation: cargo fmt, clippy --workspace --all-targets --all-features
-D warnings, clippy with `gpu` and with `gpu rknn native-camera`,
cargo test --workspace (2305 passed), check-doc-counts.sh (all 14 rows
match; onnx-cpu-ops still 122). The Windows cross-check could not run
locally — x86_64-pc-windows-msvc std is not installed; nothing here is
platform-specific and CI covers it.
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.

1 participant