Skip to content

Conversation

@justinchuby
Copy link
Member

@justinchuby justinchuby commented Apr 24, 2025

Improve Extractor to handle the case where user requests a graph output, that is simultaneously an intermediate value, to be extracted as an input of the new graph.

Previously the value info of the graph i/o are not added to the mapping, causing _collect_new_io_core to fail with KeyError.

Improve Extractor to handle the case where user requests a graph output, that is simultaneously a intermediate value, to be extracted as an input of the new graph.

Previously the value info of the graph i/o are not added to the mapping, causing _collect_new_io_core to fail with key error

Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby justinchuby requested a review from a team as a code owner April 24, 2025 14:52
@github-project-automation github-project-automation bot moved this to In progress in PR Tracker Apr 24, 2025
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 improves the Extractor to correctly map intermediate graph I/O values when a graph output that is also an intermediate value is requested, preventing KeyError failures.

  • Removed the previous vimap and wmap in favor of initializers and value_infos, which are updated with input and output values.
  • Consolidated the collection of new I/O into a single method (_collect_new_io) and updated tensor collection accordingly.

@justinchuby justinchuby requested a review from zhenhuaw-me April 24, 2025 14:53
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby justinchuby force-pushed the justinchu/extractor branch from 92e4c22 to d00ffa0 Compare April 24, 2025 14:54
@justinchuby justinchuby requested a review from Copilot April 24, 2025 14:54
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 improves the Extractor in onnx/utils.py to correctly handle cases in which a graph output (acting as an intermediate value) is also requested as an input, preventing a KeyError.

  • Replaces the separate _collect_new_inputs/_outputs methods with a unified _collect_new_io method that validates io names against value_infos.
  • Updates mapping references from vimap/wmap to value_infos/initializers throughout the extraction process.
Comments suppressed due to low confidence (1)

onnx/utils.py:42

  • [nitpick] Consider renaming _collect_new_io to a more descriptive name, such as _collect_valid_io, to clearly indicate that it validates and collects tensor info for both inputs and outputs.
def _collect_new_io(self, io_names_to_extract: list[str]) -> list[ValueInfoProto]:

@justinchuby justinchuby changed the title Improve Extractor Improve model Extractor Apr 25, 2025
@codecov
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 56.30%. Comparing base (9e379bd) to head (27f4ed1).
Report is 5 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnx/utils.py 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6920      +/-   ##
==========================================
- Coverage   56.31%   56.30%   -0.02%     
==========================================
  Files         509      509              
  Lines       32590    32582       -8     
  Branches     3097     3095       -2     
==========================================
- Hits        18354    18346       -8     
  Misses      13378    13378              
  Partials      858      858              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@zhenhuaw-me zhenhuaw-me left a comment

Choose a reason for hiding this comment

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

LGTM. Better to have some tolerance about the ONNX spec.

FYI: our TensorRT project has a improved version (and many more powerful features) baked in polygraphy: https://github.com/NVIDIA/TensorRT/tree/main/tools/Polygraphy/examples/cli/surgeon/01_isolating_subgraphs

Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby justinchuby requested a review from andife April 27, 2025 15:36
@justinchuby justinchuby enabled auto-merge April 27, 2025 15:36
@justinchuby justinchuby added this to the 1.19 milestone Apr 27, 2025
@justinchuby justinchuby added this pull request to the merge queue Apr 29, 2025
@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in PR Tracker Apr 29, 2025
Merged via the queue into main with commit 94e8207 Apr 29, 2025
67 checks passed
@justinchuby justinchuby deleted the justinchu/extractor branch April 29, 2025 18:24
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in PR Tracker Apr 29, 2025
gramalingam pushed a commit to gramalingam/onnx that referenced this pull request May 19, 2025
Improve Extractor to handle the case where user requests a graph output,
that is simultaneously an intermediate value, to be extracted as an
input of the new graph.

Previously the value info of the graph i/o are not added to the mapping,
causing _collect_new_io_core to fail with KeyError.

---------

Signed-off-by: Justin Chu <justinchu@microsoft.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: gramalingam <grama@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants