Skip to content

Comments

add remove_inputs to InputObserver#422

Merged
sdpython merged 11 commits intomainfrom
removi
Feb 24, 2026
Merged

add remove_inputs to InputObserver#422
sdpython merged 11 commits intomainfrom
removi

Conversation

@xadupre
Copy link
Collaborator

@xadupre xadupre commented Feb 23, 2026

No description provided.

@xadupre
Copy link
Collaborator Author

xadupre commented Feb 23, 2026

@copilot can you add unit test for the added code

Copy link
Contributor

Copilot AI commented Feb 23, 2026

@xadupre I've opened a new pull request, #423, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits February 23, 2026 17:08
* Initial plan

* Add unit tests for remove_inputs in InputObserver

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a remove_inputs API to InputObserver to allow dropping specific captured inputs before inferring dynamic shapes/arguments, and updates the ModelBuilder exporter path handling plus related docs/tests.

Changes:

  • Add remove_inputs plumbing across InputCandidate, InputObserverInfo, and InputObserver.
  • Adjust ModelBuilder export to handle empty cache_dir and attempt to rename the produced ONNX file.
  • Add unit tests for removing kwarg inputs and a new sphinx-gallery example demonstrating ModelBuilder export.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
onnx_diagnostic/investigate/input_observer.py Introduces remove_inputs methods to drop captured inputs and recompute internal flattened structures.
onnx_diagnostic/export/api.py Tweaks ModelBuilder exporter cache/output handling and adds a load/save step intended to rename the output ONNX.
_unittests/ut_investigate/test_input_observer.py Adds tests asserting remove_inputs updates inferred dynamic shapes and inferred arguments for kwargs.
_doc/examples/plot_export_with_modelbuilder.py Adds a new sphinx-gallery example for exporting a HF model with ModelBuilder and using remove_inputs.
CHANGELOGS.rst Adds changelog entries referencing the PR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +316 to +323
cache_dir=os.path.dirname(filename) or ".",
**(exporter_kwargs or {}),
)
save_model_builder(onx, os.path.dirname(filename))
temp_filename = os.path.join(os.path.dirname(filename), "model.onnx")
# renaming
onx = onnx.load(temp_filename, load_external_data=True)
onnx.save(onx, filename, save_as_external_data=True)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the modelbuilder exporter, save_model_builder(onx, os.path.dirname(filename)) passes an empty string when filename has no directory, which makes save_model_builder return an in-memory proto without writing a file. The subsequent onnx.load(temp_filename) will then fail. Use a normalized output dir (e.g., out_dir = os.path.dirname(filename) or ".") consistently for cache_dir, save_model_builder, and temp file paths.

Copilot uses AI. Check for mistakes.
xadupre and others added 5 commits February 23, 2026 22:34
@sdpython sdpython merged commit e1f0c88 into main Feb 24, 2026
31 checks passed
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.

3 participants