perf(fp8): Remove redundant clone calls from FP8 Linear Kernel - #841
perf(fp8): Remove redundant clone calls from FP8 Linear Kernel#841R3hankhan123 wants to merge 1 commit into
Conversation
|
👋 Hi! Thank you for contributing. We also recommend installing prek and configuring it to check your code before every local commit. |
|
/caude-review |
tdoublep
left a comment
There was a problem hiding this comment.
Posted by Claude Code on behalf of @tdoublep.
I ran this on the device. The removed clones really are redundant: output is bitwise identical to main across 9 shape/M combinations, still contiguous at offset 0, and nothing reuses the buffer. Looks good.
Two notes:
- It also fixes a bug. On main, 3-D input that needs M padding comes back with wrong numbers (off by ~2-3 vs. the same rows passed as 2-D). Trimming before the reshape is what fixes it. Worth saying so in the description.
- Nothing tests this.
test_scaled_mm_applyusesnum_tokens1/4/128, which all skip M padding, and it only checks dtype and shape — so the branch added here never runs in CI. Please add 5 or 130 and compare values.
6aac65b to
0de5162
Compare
Signed-off-by: Rehan Khan <Rehan.Khan7@ibm.com>
0de5162 to
8b7bc81
Compare
|
/claude-review |
| """apply_weights runs aten._scaled_mm on Spyre. | ||
|
|
||
| num_tokens=5 and 130 exercise M-padding (not in _SMALL_M, not aligned | ||
| to _M_ALIGN=128), verifying the trim-before-reshape path. |
There was a problem hiding this comment.
These two cases (5, 130) do add M-padding, but the test still only asserts dtype and shape and only ever passes 2-D x. The bug this PR fixes is 3-D input that needs M-padding: the pre-clone() reshape reads the padded storage and returns wrong numbers. On device I confirmed it — feeding the same 130 rows as (13, 10, 128) gives max|out3d - out2d| = 2.999 on main and 0.0 on this branch. Neither of those facts is checked here: no 3-D shape is exercised (so the reshape branch never runs in CI), and no value comparison is done (so even a 2-D numeric regression would pass). The docstring's claim that these cases are "verifying the trim-before-reshape path" is therefore not accurate. Please add a 3-D case and compare apply_weights output against a reference (e.g. the 2-D result reshaped, or a dequantized fp16 matmul), as tdoublep asked in the review.
There was a problem hiding this comment.
@R3hankhan123 looks like this might need one more pass then we should be good to go
|
Reviewed on Spyre hardware. The clone removals in One issue worth blocking on: the fix is untested. The new |
Description
Remove Redundant clone calls from FP8 Linear Kernel
Related Issues
Fixes #840
Test Plan
curl request
output
Checklist
bash format.sh)Signed-off-by:line (DCO compliance)