Repository navigation
fix(dyt): put the row count on grid dimension 0 in the forward launch - #1607
Open
bhargavchintam wants to merge 1 commit into
Open
bhargavchintam wants to merge 1 commit into
bhargavchintam wants to merge 1 commit into
Conversation
…d kernel CUDA limits grid dimensions 1 and 2 to 65535 programs. The forward kernel put the row count (batch * sequence length) on dimension 1, so any input with more than 65535 rows failed at launch with "Triton Error [CUDA]: invalid argument". A batch of 128 sequences of 1024 tokens is 131072 rows. Swap the two dimensions, as the tiled SwiGLU kernel already does. The column tile count stays on dimension 1, and the backward kernel keeps its grid because it uses the SM count there.
Author
|
I ran None of the 22 is in |
1 of 3 tasks
This branch has not been deployed
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.
Fixes #1605
Summary
liger_dyt_fwdlaunches_dyt_fwd_kernelwithgrid = (cdiv(N, BLOCK_N), M), which puts the row countM(batch × sequence length) on grid dimension 1. CUDA limits that dimension to 65535 (the B200 I ran this on reports that limit), so any input with more than 65535 rows fails at launch withTriton Error [CUDA]: invalid argument. A batch of 128 sequences of 1024 tokens is 131072 rows.This PR swaps the two grid dimensions in the forward launch and the two
tl.program_idcalls in_dyt_fwd_kernel, so the rows are on dimension 0 and the column tiles on dimension 1. The tiled SwiGLU kernel already orders its grid this way (grid = (n_rows, triton.cdiv(n_cols, BLOCK_SIZE))inops/swiglu.py). The backward kernel is unchanged because its dimension 1 is the SM count.Details
CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X/Y/Zon the B200 are 2147483647, 65535 and 65535.ops/backends/_ascend/ops/dyt.pyis not changed, and I did not run anything on Ascend.liger_dyt_fwdlaunched 300 times after a warmup, withtorch.cuda.synchronize()around the loop, mean in µs):Testing Done
make testto ensure correctnessmake checkstyleto ensure code style (I ran its two check-only steps, shown at the end, because the other two steps rewrite files)make test-convergenceto ensure convergenceI did not run
make testormake test-convergence. The B200 was rented for this run, and on it I ran only the changed kernel's test file,test/transformers/test_dyt.py, as below.New test
test_liger_dyt_more_rows_than_grid_dimension_limituses 2 × 32769 = 65538 rows, with and without beta, and compares the output and all gradients with torch.The snippet from the issue, run on this branch (on main the second line is
RuntimeError: Triton Error [CUDA]: invalid argument):