[TIR] Refactor BF16Legalize#14405
Merged
junrushao merged 1 commit intoapache:mainfrom Mar 28, 2023
Merged
Conversation
Collaborator
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
Member
Author
5d9440a to
d2011c4
Compare
This PR refactors BF16Legalize to enable more f32 computations. We also split the BF16Legalize into two steps. - BF16ComputeLegalize changes all computation to f32 while keeping the external BF16 storages. - BF16StorageLegalize changes all storage to u16. Now BF16 kernels accept tvm.nd.array that are created as bfloat16 type.
Member
Author
|
note: the android failure is not related to this PR. |
Member
Author
|
cc @vinx13 |
Member
|
Retriggering failed Android tests |
junrushao
reviewed
Mar 28, 2023
Comment on lines
+831
to
+834
| // TODO(tvm-team): consider add native support | ||
| ICHECK(!from.is_bfloat16()) << "BF16 needs to be storaged lowered first"; | ||
| ICHECK(!to.is_bfloat16()) << "BF16 needs to be storaged lowered first"; | ||
|
|
Member
There was a problem hiding this comment.
seems possible to support software BF16 in upstream LLVM/MLIR world. leaving it to future work
Member
Author
There was a problem hiding this comment.
Good point, already left as a todo
junrushao
reviewed
Mar 28, 2023
Comment on lines
+102
to
+108
| # handle the bfloat16 so we explicitly allocate | ||
| # bfloat16 arrays as input | ||
| for i, param in enumerate(mod["main"].params): | ||
| if param.type_annotation.dtype == "bfloat16": | ||
| input_data[i] = tvm.nd.empty(input_data[i].shape, "bfloat16").copyfrom( | ||
| input_data[i] | ||
| ) |
Member
There was a problem hiding this comment.
why are we adding ONNX tests in this PR though?
Member
Author
There was a problem hiding this comment.
This is needed to patch up onnx converting bf16 to uint16
junrushao
approved these changes
Mar 28, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors BF16Legalize to enable more f32 computations.
We also split the BF16Legalize into two steps.
the external BF16 storages.
Now BF16 kernels accept tvm.nd.array that are created as bfloat16 type.