[Pytorch] Improve conversion from bf16 on aarch64/NEON#166880
Closed
Nicoshev wants to merge 1 commit intopytorch:mainfrom
Closed
[Pytorch] Improve conversion from bf16 on aarch64/NEON#166880Nicoshev wants to merge 1 commit intopytorch:mainfrom
Nicoshev wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/166880
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 98734d2 with merge base 3a38ec7 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
9a25755 to
485e2de
Compare
Nicoshev
added a commit
to Nicoshev/pytorch
that referenced
this pull request
Nov 3, 2025
Summary: Conversion from/to bfloat16 was not getting covered by conversion templates, because these used bfloat16_t as data type instead of the custom c10::BFloat16 Conversion by casting from/to bfloat16_t is broken in clang-[17, 20], fixed in clang-21. Because Pytorch does not currently have CI running binaries compiled using clang-21, we won't implement this approach for now. We are currently only adding conversion from bfloat16, as it can be implementing by zero-extending into 4 bytes. We've observed the following performance improvements, when compiling with clang-19 and targeting armv9a+sve2: Before: bfloat16_t->uint8 ===> 423.583us bfloat16_t->int8 ===> 424.090us bfloat16_t->int16 ===> 430.817us bfloat16_t->int64 ===> 571.547us bfloat16_t->double ===> 459.089us After: bfloat16_t->uint8 ===> 142.698us ----> 297% higher throughput bfloat16_t->int8 ===> 134.837us -----> 315% higher throughput bfloat16_t->int16 ===> 136.794us ----> 315% higher throughput bfloat16_t->int64 ===> 200.364us ----> 285% higher throughput bfloat16_t->double ===> 137.103us ---> 335% higher throughput Test Plan: Correctness: buck2 test mode/opt //caffe2/test:test_ops buck2 test mode/opt //caffe2/test:torch Performance: buck2 run mode/opt //caffe2/benchmarks/operator_benchmark/fb:operator_benchmark_test Reviewed By: mcfi Differential Revision: D86119613
mcfi
approved these changes
Nov 3, 2025
Summary: Conversion from/to bfloat16 was not getting covered by conversion templates, because these used bfloat16_t as data type instead of the custom c10::BFloat16 Conversion by casting from/to bfloat16_t is broken in clang-[17, 20], fixed in clang-21. Because Pytorch does not currently have CI running binaries compiled using clang-21, we won't implement this approach for now. We are currently only adding conversion from bfloat16, as it can be implementing by zero-extending into 4 bytes. We've observed the following performance improvements, when compiling with clang-19 and targeting armv9a+sve2: Before: bfloat16_t->uint8 ===> 423.583us bfloat16_t->int8 ===> 424.090us bfloat16_t->int16 ===> 430.817us bfloat16_t->int64 ===> 571.547us bfloat16_t->double ===> 459.089us After: bfloat16_t->uint8 ===> 142.698us ----> 297% higher throughput bfloat16_t->int8 ===> 134.837us -----> 315% higher throughput bfloat16_t->int16 ===> 136.794us ----> 315% higher throughput bfloat16_t->int64 ===> 200.364us ----> 285% higher throughput bfloat16_t->double ===> 137.103us ---> 335% higher throughput Test Plan: Correctness: buck2 test mode/opt //caffe2/test:test_ops buck2 test mode/opt //caffe2/test:torch Performance: buck2 run mode/opt //caffe2/benchmarks/operator_benchmark/fb:operator_benchmark_test Reviewed By: mcfi Differential Revision: D86119613
485e2de to
98734d2
Compare
aditew01
approved these changes
Nov 3, 2025
Contributor
|
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
pytorch-bot bot
pushed a commit
that referenced
this pull request
Nov 4, 2025
Summary: Conversion from/to bfloat16 was not getting covered by conversion templates, because these used bfloat16_t as data type instead of the custom c10::BFloat16 Conversion by casting from/to bfloat16_t is broken in clang-[17, 20], fixed in clang-21. Because Pytorch does not currently have CI running binaries compiled using clang-21, we won't implement this approach for now. We are currently only adding conversion from bfloat16, as it can be implementing by zero-extending into a 4-byte float. We've observed the following performance improvements, when compiling with clang-19 and targeting armv9a+sve2: Before: bfloat16_t->uint8 ===> 423.583us bfloat16_t->int8 ===> 424.090us bfloat16_t->int16 ===> 430.817us bfloat16_t->int64 ===> 571.547us bfloat16_t->double ===> 459.089us After: bfloat16_t->uint8 ===> 123.783us ----> 342% higher throughput bfloat16_t->int8 ===> 131.575us -----> 322% higher throughput bfloat16_t->int16 ===> 136.794us ----> 315% higher throughput bfloat16_t->int64 ===> 177.699us ----> 322% higher throughput bfloat16_t->double ===> 165.556us ---> 277% higher throughput Test Plan: Correctness: buck2 test mode/opt //caffe2/test:test_ops buck2 test mode/opt //caffe2/test:torch Performance: buck2 run mode/opt //caffe2/benchmarks/operator_benchmark/fb:operator_benchmark_test Differential Revision: D86119613 Pull Request resolved: #166880 Approved by: https://github.com/mcfi, https://github.com/aditew01
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.
Summary:
Conversion from/to bfloat16 was not getting covered by conversion templates, because these used bfloat16_t as data type instead of the custom c10::BFloat16
Conversion by casting from/to bfloat16_t is broken in clang-[17, 20], fixed in clang-21.
Because Pytorch does not currently have CI running binaries compiled using clang-21, we won't implement this approach for now.
We are currently only adding conversion from bfloat16, as it can be implementing by zero-extending into a 4-byte float.
We've observed the following performance improvements, when compiling with clang-19 and targeting armv9a+sve2:
Before:
bfloat16_t->uint8 ===> 423.583us
bfloat16_t->int8 ===> 424.090us
bfloat16_t->int16 ===> 430.817us
bfloat16_t->int64 ===> 571.547us
bfloat16_t->double ===> 459.089us
After:
bfloat16_t->uint8 ===> 123.783us ----> 342% higher throughput
bfloat16_t->int8 ===> 131.575us -----> 322% higher throughput
bfloat16_t->int16 ===> 136.794us ----> 315% higher throughput
bfloat16_t->int64 ===> 177.699us ----> 322% higher throughput
bfloat16_t->double ===> 165.556us ---> 277% higher throughput
Test Plan:
Correctness:
buck2 test mode/opt //caffe2/test:test_ops
buck2 test mode/opt //caffe2/test:torch
Performance:
buck2 run mode/opt //caffe2/benchmarks/operator_benchmark/fb:operator_benchmark_test
Differential Revision: D86119613
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @jerryzh168 @aditew01 @snadampal @milpuz01 @nikhil-arm @fadara01