Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ONNX): replaces getValueList helper with createScalarSublist #3987

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

bjacobgordon
Copy link
Contributor

@bjacobgordon bjacobgordon commented Jan 28, 2025

A preliminary refactor to support #3945

  • extracts several new helper functions
  • removes cruft

@bjacobgordon
Copy link
Contributor Author

Hey, @AmosLewis, could you review this since @zjgarvey is out? Zach reviewed a lot of it under #3945, but wanted to split into two stacked PRs to make each final diff smaller.

@zjgarvey
Copy link
Collaborator

I'll get a chance to review today, too. But it would be good to get Chi's review too.

Copy link
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

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

Thanks, Jacob. The helper function getValueList would certainly benefit from some cleanup.

lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

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

Adding a few more comments, mostly pertaining to the other function I didn't review earlier.

lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
@bjacobgordon bjacobgordon force-pushed the refactor-onnx-replaces-getValueList-helper-with-createScalarSublist branch from 2e2300b to 9e57557 Compare January 30, 2025 17:24
@bjacobgordon bjacobgordon requested a review from zjgarvey January 30, 2025 17:25
Copy link
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

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

Nice! This looks good. Just a few changes and we should merge this. Ping me when you're done and I'll approve.

Thanks!

lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp Outdated Show resolved Hide resolved
@bjacobgordon bjacobgordon force-pushed the refactor-onnx-replaces-getValueList-helper-with-createScalarSublist branch from 9e57557 to 1580393 Compare January 31, 2025 23:16
@bjacobgordon
Copy link
Contributor Author

@zjgarvey All the tweaks were super quick, and one of them sparked a few ideas! It took some time, but I think it'll be worth it:

  • Was able to extract out two more helpers that I think you'll like
  • standardized the way I named their signatures so it'd be easier to modify for use with ImplicitLocOpBuilder
    • kept rewriter (and givenLoc) as the first param(s) each time
    • kept the convention of rewriter methods starting with "get"/"create" for types/values (while still ensuring it was obvious what the method does)

I think there's a ton of opportunity for subsequent PRs to leverage these new helpers to gradually distill the implementation for these conversions!

Hoping that it leaves you nitless, but we'll see! Just let me know haha.

@bjacobgordon bjacobgordon requested a review from zjgarvey January 31, 2025 23:27
@bjacobgordon bjacobgordon changed the title refactor(ONNX): replaces getValueList helper with createScalarSublist refactor(ONNX): replaces getValueList helper with createTorchScalarSublist Jan 31, 2025
Copy link
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

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

Hey, Jacob.

The PR was in a great state to merge before you made the undiscussed changes. To make this process more efficient, would you please revert those changes so that we can merge the PR as discussed earlier?

This PR is blocking your progress on another PR, so I don't want to spend another day or two going back and forth on these new changes.

@bjacobgordon bjacobgordon force-pushed the refactor-onnx-replaces-getValueList-helper-with-createScalarSublist branch 2 times, most recently from f61b1e8 to a751f8c Compare February 6, 2025 14:47
…` helper

- `operand`: helper isn't concerned with how the call site things about this
- `input`: tells us that it's a parameter passed into this scope, but the implementation eventually tells us that we're treating it like a tensor
- `inputTensor`: but not just _any_ tensor, it's a 1D tensor
- `input1DTensor`: "input" has been used elsewhere to mean "first operand for an operation", and this function isn't a full-blown op, so we gotta use something else
- `given1DTensor`: bingo
…lueList` helper

- `operandType`: "operand" is the given tensor
- `castedGiven1DTensorType`: can be renamed as validated generic
- `some1DTensorType`: meaning "type of some 1D tensor"
- Before:
  - "get": implies retrieval of some private property
  - "Value": restatement of the return type `Value`
  - "List": assumed result of casting the returned instance
- After:
  - "create": contextualizes the need to pass in `rewriter`
  - "Scalar": contextualizes the opaque return type
  - "Sublist": the relationship between the first parameter and the returned result
@bjacobgordon bjacobgordon force-pushed the refactor-onnx-replaces-getValueList-helper-with-createScalarSublist branch from a751f8c to db12b36 Compare February 6, 2025 15:47
@bjacobgordon bjacobgordon changed the title refactor(ONNX): replaces getValueList helper with createTorchScalarSublist refactor(ONNX): replaces getValueList helper with createScalarSublist Feb 6, 2025
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