Fix some things before yet another optimizer rework - #24
Open
Human9000-bit wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 0 of the three-layer optimizer arc: correctness and dead-code
prerequisites, so the layers that follow are measured against a clean
baseline.