-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR] Preserve Encoding During TensorOp Creation #80871
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
Open
manbearian
wants to merge
1
commit into
llvm:main
Choose a base branch
from
manbearian:users/ianb/tensor-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me that the conservative option is that if the interface isn't implemented, the encoding should no be propagated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joker-eph thanks for your response. I think there may be a misunderstanding, as i don't think what you're saying will work, but i'm not sure if its on my part or yours.
From what i read in the code, the previous behavior drops the encoding (not propagated) for all cases when creating a new type. I'm changing this to reuse the encoding on the newly created type. However, the special case test here is that for this particular encoding (the
VerifiabletensorEncoding
), the encoding may not be possible to propagate, since it is dimensionality specific.I believe the best possible approach would be to update the encoding based on the new dimensionality, but as this isn't an area of the compiler i'm familiar with and that we don't use in our code base, i'm instead falling back to the exiting behavior of dropping the encoding.
Does this make sense?
I'm happy to discuss more if this approach is not what folks want to see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general dropping is the "safe" thing to do when we transform code and we don't know if the transformation can preserve the semantics of the encoding.
Now there may be a specific argument here you'd want to make, but it should be made explicit, about why propagating "blindly" an opaque encoding would be correct in the absolute? If my attribute does not implement the "VerifiableTensorEncoding", you can't ensure that it is correct to just propagate it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit, i'm unfamiliar with
VerifiableTensorEncoding
and its intended use. (I think i originally wrote up this code before it existed)My thinking (before this discussion) that the Encoding attribute was opaque, so the code shouldn't know anything about them. The encodings used in my compiler are not specific to the shape of the tensor and i need to propagate them in all cases.
I suppose it comes down to the default behavior desired here. Currently default is: "don't propagate encoding" and the intent of my change was to change the default to: "always propagate if possible".
I think your suggesting two things:
Please let me know if i'm getting this correct. I'm okay with doing one or both or neither of these, so please let me know what you think is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But when something is "opaque" we have two approaches:
This come down to the guarantee we intend to provide with this attribute though.
Yes: basically we could consider that an attribute which implements
VerifiableTensorEncoding
is "opt in" into being propagated as long as it verifies.But even this is sketchy: the "verifier" aspect does not guarantee that the transformation is semantic preserving!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping encodings through operations seems exceedingly dangerous and definitely semantically incorrect, at least for the use cases in my compiler.
First, in the Tensor representation, an operation such as "SliceOp" should be producing a tensor that has the same encoding as the original tensor.
Second, if we allow operations to simply drop encodings, at least in my case, bufferization will either fail (since it cannot reconcile the types) or it will produce suboptimal code to convert the types using copies.
Is it possible that i'm completely misusing the encoding field? For our compiler it contains information on how the Tensor will be laid out in memory when allocated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're basically saying we should do:
I don't disagree, I'm not sure we have a good documentation of the intent with respect to this tensor encoding.
(many folks, including me, were a bit concerned when this was introduced that we may be better introducing new types because this seems incredibly unsafe and it makes the codebase hard to get right: this is where we're at now)