Repository navigation
[AMD] Fix kwidth printing and parsing - #3676
Conversation
|
FYI @oplavsic |
| auto mmaParent = parent.dyn_cast<NvidiaMmaEncodingAttr>(); | ||
| printer << "<{" | ||
| << "opIdx = " << getOpIdx() << ", parent = " << getParent(); | ||
| if (mmaParent && mmaParent.isAmpere()) |
There was a problem hiding this comment.
I have a question related to Nvidia.
This part mismatches parsing:
- Parse for Ampere and Hopper
- Print only for Ampere
Can anyone clarify, which behavior is correct?
There was a problem hiding this comment.
I'm 60% sure that printing for Hopper is correct, but also in the 40% case that it's incorrect then printing it will make it obvious to someone else that it shouldn't be there. :) Thanks for noticing this.
There was a problem hiding this comment.
Also this whole thing seems unnecessarily confusing. It seems to me that we shouldn't need any of this custom parsing logic. Instead:
- Make kWidth an optional attribute with a default of 0 or -1.
- Use a regular MLIR parser and printer, no need for the custom C++ at all. It will not print kWidth when it's 0, because that's the default.
- Add a verifier that checks that kWidth is 0 for those encodings that don't support kWidth. Also check that the kWidth is explicitly equal to
AMDWmmaEncodingAttr::getMNKDimPerWMMAInstr()[2]for AMDWmma.
Not your sin, I guess you don't need to change it.
There was a problem hiding this comment.
I can try to rework this with default value approach without custom parsing.
I suspect this will change formatting, but we can experiment and see if this make sense
There was a problem hiding this comment.
It is OK to change formatting. You'll have to fix the tests, but I've done it, it's not too bad.
There was a problem hiding this comment.
Turned out declarative format can express same formatting 🙂
There was a problem hiding this comment.
Yup. Great to see this getting cleaned up. Thanks @binarman!
jlebar
left a comment
There was a problem hiding this comment.
Requesting changes because I think this needs a unit test.
| << "opIdx = " << getOpIdx() << ", parent = " << getParent(); | ||
| if (mmaParent && mmaParent.isAmpere()) | ||
| bool isAmdWithKWidth = | ||
| parent.isa<AMDMfmaEncodingAttr>() || parent.isa<AMDWmmaEncodingAttr>(); |
There was a problem hiding this comment.
This seems like a similar inconsistency to Ampere/Hopper. Here we're printing kWidth if AMDWmma, but if AMDWmma we ignore any parsed value and unconditionally do kWidth = AMDWmmaEncodingAttr::getMNKDimPerWMMAInstr()[2];
| auto mmaParent = parent.dyn_cast<NvidiaMmaEncodingAttr>(); | ||
| printer << "<{" | ||
| << "opIdx = " << getOpIdx() << ", parent = " << getParent(); | ||
| if (mmaParent && mmaParent.isAmpere()) |
There was a problem hiding this comment.
Also this whole thing seems unnecessarily confusing. It seems to me that we shouldn't need any of this custom parsing logic. Instead:
- Make kWidth an optional attribute with a default of 0 or -1.
- Use a regular MLIR parser and printer, no need for the custom C++ at all. It will not print kWidth when it's 0, because that's the default.
- Add a verifier that checks that kWidth is 0 for those encodings that don't support kWidth. Also check that the kWidth is explicitly equal to
AMDWmmaEncodingAttr::getMNKDimPerWMMAInstr()[2]for AMDWmma.
Not your sin, I guess you don't need to change it.
| Attribute _kWidth = attrs.get("kWidth"); | ||
| if (_kWidth) { | ||
| if (!mmaParent || mmaParent.isVolta()) { | ||
| bool isAmdWithKWidth = |
| Attribute _kWidth = attrs.get("kWidth"); | ||
| if (_kWidth) { | ||
| if (!mmaParent || mmaParent.isVolta()) { | ||
| bool isAmdWithKWidth = |
|
Also, @binarman, please make sure all tests pass before marking pull requests as ready for review. As addressing bots happy needs changing the impl. (You can ping me if you need to trigger CI runs.) |
c936414 to
5017d00
Compare
|
@antiagainst @jlebar |
794e451 to
dff9246
Compare
antiagainst
left a comment
There was a problem hiding this comment.
Cool, looks better. I still have a few comments. Major one is actuall the tests.
| auto mmaParent = parent.dyn_cast<NvidiaMmaEncodingAttr>(); | ||
| printer << "<{" | ||
| << "opIdx = " << getOpIdx() << ", parent = " << getParent(); | ||
| if (mmaParent && mmaParent.isAmpere()) |
There was a problem hiding this comment.
Yup. Great to see this getting cleaned up. Thanks @binarman!
|
(converting to draft as we said internally. will mark it open after approval from me) |
This PR fixes: - parsing and printing of kWidth attribute for MFMA and WMMA layouts - comment in 06-fused-attention.p tutorial
dff9246 to
09680cf
Compare
antiagainst
left a comment
There was a problem hiding this comment.
Awesome, thanks for bearing with my nitpicking! :)
This PR fixes: