-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[inductor] Stop using x + tl.zeros(...)
in generated triton
#100163
Conversation
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/100163
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 fa372b3: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` ghstack-source-id: 32e07c41ea197d555aca29771fee20fc2068e583 Pull Request resolved: pytorch#100163
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` ghstack-source-id: 933b241a9a3e72a84e09e1cc2569e42de83e504e Pull Request resolved: #100163
@pytorchbot merge |
Merge failedReason: This PR needs a label If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge |
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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
…x + tl.zeros(...)` in generated triton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
torch/_inductor/codegen/triton.py
Outdated
# tl.reduce doesn't support tl.int1 | ||
accumulator = f"{accumulator}.to(tl.int8)" | ||
result_type = triton_compute_type(dtype) | ||
self.suffix.writeline(f"{result_var} = {final_reduction(accumulator)}.to({result_type})") |
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.
This is only really used for aten.any
. It changes the final reduction of a non-persistent reduction from
tmp5 = triton_helpers.max(_tmp5, 1)[:, None]
tmp5 = triton_helpers.max(_tmp5.to(tl.int8), 1)[:, None].to(tl.int1)
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.
This is good to put as a comment in the code!
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` ghstack-source-id: d92be321d693cfc9a0faeafd37dfa423b93b4d64 Pull Request resolved: pytorch#100163
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
@pytorchbot merge -f "Doc build failure is pre-existing" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Revert "[inductor] Stop using `x + tl.zeros(...)` in generated triton (#100163)" This reverts commit 5b98910. Revert "[inductor] Fix argmin/max with duplicate values (#99920)" This reverts commit 659dcc5. Revert "[inductor] Fix nan-handling of max and min reductions (#99881)" This reverts commit f9c3fcd. [ghstack-poisoned]
Revert "[inductor] Stop using `x + tl.zeros(...)` in generated triton (#100163)" This reverts commit 5b98910. Revert "[inductor] Fix argmin/max with duplicate values (#99920)" This reverts commit 659dcc5. Revert "[inductor] Fix nan-handling of max and min reductions (#99881)" This reverts commit f9c3fcd. ghstack-source-id: 85531baedfb245e48512be97c0ed90eba1685664 Pull Request resolved: #100517
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` ghstack-source-id: 3a7b180d4fa58c14afb407ddd453cc29cf819074 Pull Request resolved: pytorch#100163
For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` ghstack-source-id: 3a7b180d4fa58c14afb407ddd453cc29cf819074 Pull Request resolved: pytorch#100163
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
…ton" For reductions, this changes the accumulator ```python _tmp2 = tl.zeros([XBLOCK, RBLOCK], tl.int8) + -128 ``` to ```python _tmp2 = tl.full([XBLOCK, RBLOCK], -128, tl.int32) ``` which is equivalent since addition does type promotion from `int8` to `int32` For constant indexing, this changes ```python tl.store(in_out_ptr0 + (0 + tl.zeros([XBLOCK, 1], tl.int32)), tmp4, None) ``` to ```python tl.store(in_out_ptr0 + (tl.full([XBLOCK, 1], 0, tl.int32)), tmp4, None) ``` For variable indexing, this changes ```python tl.store(out_ptr0 + (0 + tl.zeros([XBLOCK], tl.int32)), tmp1, None) ``` to ```python tl.store(out_ptr0 + (tl.broadcast_to(x0, [XBLOCK])), tmp1, None) ``` cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire [ghstack-poisoned]
Stack from ghstack (oldest at bottom):
x + tl.zeros(...)
in generated triton #100163For reductions, this changes the accumulator
to
which is equivalent since addition does type promotion from
int8
toint32
For constant indexing, this changes
to
For variable indexing, this changes
to
cc @soumith @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire