Skip to content

Fix stale value_info on ONNX export and IndexError in powermetrics - #12

Open
alisajil wants to merge 1 commit into
microsoft:mainfrom
alisajil:fix/onnx-export-pipeline-bugs
Open

Fix stale value_info on ONNX export and IndexError in powermetrics#12
alisajil wants to merge 1 commit into
microsoft:mainfrom
alisajil:fix/onnx-export-pipeline-bugs

Conversation

@alisajil

@alisajil alisajil commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Two small, independent bug fixes found while exporting a model through the Qualcomm ONNX path and benchmarking on macOS:

  • conversion/_exporter/_onnx_utils.py: OnnxOptimizer's Gather-squeeze QNN workaround (_qc_workaround_squeeze_gather_4d) hand-crafts a value_info entry for an intermediate tensor without refreshing the rest of the graph's shape info afterward. onnxruntime tolerates the resulting inconsistency, but Qualcomm AI Hub's strict onnx.checker.check_model(..., full_check=True) rejects it with ShapeInferenceError: Inferred shape and existing shape differ in rank. Fix: clear value_info and re-run onnx.shape_inference.infer_shapes() at the end of every optimization pass, so the saved model is always internally consistent regardless of which passes ran.
  • conversion/_powermetrics.py: PowerMetricsCollector._run_apple indexes into an empty readline() result (if line[0] == 0), which throws IndexError in a background thread whenever the powermetrics subprocess emits a blank line. Fix: guard with if line and line[0] == 0.

Test plan

  • Reproduced the value_info failure on a 1080p (1920x1088) export through convert.py export --model-type onnx --target-device qualcomm; confirmed onnx.checker.check_model(full_check=True) now passes on all exported graphs (encoder part 1/2, decoder) with no manual post-processing.
  • Reproduced the IndexError via convert.py export --benchmark on macOS; confirmed the guard prevents the crash.

…trics line

OnnxOptimizer's Gather-squeeze QNN workaround hand-crafts a value_info
entry without keeping the rest of the graph's shape info in sync.
onnxruntime tolerates the resulting inconsistency but AI Hub's strict
onnx.checker rejects it (ShapeInferenceError: rank mismatch). Refresh
value_info from scratch at the end of every optimization pass instead
of patching individual exported artifacts by hand each time this comes up.

Also guard PowerMetricsCollector._run_apple against an empty stdout line
from the powermetrics subprocess, which crashed a background thread with
an IndexError.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@alisajil

alisajil commented Aug 2, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

1 similar comment
@alisajil

alisajil commented Aug 2, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@alisajil

alisajil commented Aug 2, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="ecogo.ai"

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