Repository navigation
Commit db1aff6
[Common] Check that grouped GEMM matrix pointers are 16-byte aligned (#3845)
* [PyTorch][Common] Handle grouped GEMM outputs that are not 16-byte aligned
cuBLASLt grouped GEMM needs 16-byte aligned matrix pointers. Megatron-LM
packs parameters into its gradient buffer without padding when the
distributed optimizer is off, so expert main_grad views can start off a
16-byte boundary, and the grouped wgrad GEMM then faults with a
misaligned address and aborts the process.
- general_grouped_gemm_for_grouped_tensor computes unquantized outputs
that are not 16-byte aligned, discrete or grouped, through aligned
buffers and copies or adds the result. te.ops.GroupedLinear and
te.pytorch.GroupedLinear therefore accept such main_grad views, with
discrete or single grouped weights and with delayed wgrad.
- The grouped GEMM checks matrix pointer alignment on the host and raises
an error that names the operand instead of faulting on the device.
Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
* [PyTorch] Stage a misaligned grouped GEMM output as a copy of the output
Run the same GEMM, with the same accumulate, alpha, beta and bias, on an
aligned copy of the output and copy the result back. Accumulation and bias
then follow the direct path exactly, instead of rounding the product to the
output dtype and adding bias before the old output; an explicit beta is
supported too. Tests compare misaligned outputs with aligned ones bit for bit,
including a grouped output with bias and accumulation.
Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
* [PyTorch] Copy a misaligned output into the staging buffer when beta is given
The GEMM reads the output as C when it accumulates or when an explicit beta
is passed, so the staging buffer must start as a copy of the output in both
cases. Adds a test that compares an explicit beta on a misaligned output
with an aligned one bit for bit.
Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
* [PyTorch] Raise on a misaligned grouped GEMM output instead of staging it
Remove the aligned staging copy: it adds a hidden device-to-device copy for
every misaligned output, and the caller can align its buffers instead (in
Megatron-LM, by padding the gradient buffer that main_grad views point into).
A misaligned output now stops at the host-side pointer check with a clear
error. The tests check that error, that the output is left untouched and
that no CUDA error is left behind.
Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
* GroupedMLP test not needed. Already testing feature via grouped tensor ggemm
Removed the test for unaligned main gradient handling in grouped GEMM.
Signed-off-by: vthumbe1503 <vthumbe@nvidia.com>
---------
Signed-off-by: Siddhant Rajhans <51508945+siddhant-rajhans@users.noreply.github.com>
Signed-off-by: vthumbe1503 <vthumbe@nvidia.com>
Co-authored-by: vthumbe1503 <vthumbe@nvidia.com>1 parent c2b5a32 commit db1aff6
2 files changed
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1286 | 1286 | | |
1287 | 1287 | | |
1288 | 1288 | | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
1289 | 1359 | | |
1290 | 1360 | | |
1291 | 1361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
576 | 589 | | |
577 | 590 | | |
578 | 591 | | |
| |||
600 | 613 | | |
601 | 614 | | |
602 | 615 | | |
| 616 | + | |
603 | 617 | | |
604 | 618 | | |
605 | 619 | | |
| |||
627 | 641 | | |
628 | 642 | | |
629 | 643 | | |
| 644 | + | |
630 | 645 | | |
631 | 646 | | |
632 | 647 | | |
| |||
819 | 834 | | |
820 | 835 | | |
821 | 836 | | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
822 | 841 | | |
823 | 842 | | |
824 | 843 | | |
| |||
1624 | 1643 | | |
1625 | 1644 | | |
1626 | 1645 | | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
1627 | 1650 | | |
1628 | 1651 | | |
1629 | 1652 | | |
| |||
0 commit comments