Skip to content

Fix immediate output getattr#2541

Merged
TobyRoseman merged 3 commits into
apple:mainfrom
tritolol:fix-immediate-output-getattr
May 19, 2026
Merged

Fix immediate output getattr#2541
TobyRoseman merged 3 commits into
apple:mainfrom
tritolol:fix-immediate-output-getattr

Conversation

@tritolol
Copy link
Copy Markdown
Contributor

Fixes #2538.

Changed remove_getattr_nodes() such that it adds a new constant op if it encounters a getattr op that is part of the graph's output. Before it raised an error wich caused some networks not to convert.

Added a unit test for the scenario.

@tritolol tritolol force-pushed the fix-immediate-output-getattr branch from 092ebff to 7eee9a9 Compare June 12, 2025 06:45
@TobyRoseman
Copy link
Copy Markdown
Collaborator

@tritolol thanks for the pull request. I apologize that no one seems to have looked at this. Please rebase this change on top of tip of main. Then I will kick off a CI run.

@tritolol tritolol force-pushed the fix-immediate-output-getattr branch from 600f0d8 to 5d51d4f Compare August 7, 2025 07:46
@tritolol
Copy link
Copy Markdown
Contributor Author

@TobyRoseman I'm not sure if you are automatically notified, so just in case you are not: The rebase is done.

@TobyRoseman
Copy link
Copy Markdown
Collaborator

@tritolol
Copy link
Copy Markdown
Contributor Author

@TobyRoseman are any of the failing tests related to this PR? There is no indication of that for me.

@TobyRoseman
Copy link
Copy Markdown
Collaborator

@tritolol - I don't think those failures are related to this change. Please rebase this change on top the latest main.

@tritolol tritolol force-pushed the fix-immediate-output-getattr branch from 5d51d4f to d0c66b1 Compare May 3, 2026 11:46
@tritolol
Copy link
Copy Markdown
Contributor Author

tritolol commented May 3, 2026

@TobyRoseman rebased onto the latest main.

@TobyRoseman
Copy link
Copy Markdown
Collaborator

Sorry @tritolol, we just updated our CI. I'm going to need you to rebase one more time on top of latest main in order to kick off a CI run for you.

@tritolol tritolol force-pushed the fix-immediate-output-getattr branch from d0c66b1 to 01918ad Compare May 7, 2026 18:49
@tritolol
Copy link
Copy Markdown
Contributor Author

tritolol commented May 7, 2026

@TobyRoseman rebased once more onto the latest main.

else:
new_nodes.append(node)

# check the getattr nodes not in the outputs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The removed code raised a RuntimeError whenever a getattr node appeared in the graph outputs, treating that as an invalid state. But that assumption is wrong — a model can legitimately return a parameter/attribute directly (e.g., return self.weight), which produces exactly this pattern. The fix replaces the hard error with correct handling: converting the output getattr node into a constant node. The getattr_nodes list was removed since it was only used to feed that error check.

@TobyRoseman
Copy link
Copy Markdown
Collaborator

@TobyRoseman TobyRoseman merged commit e81c213 into apple:main May 19, 2026
@TobyRoseman
Copy link
Copy Markdown
Collaborator

thanks @tritolol

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.

remove_getattr_nodes torchIR pass fails with constant model outputs

2 participants