Repository navigation
Conversation
The forward and backward kernels placed rows on CUDA grid dimension 1, which holds at most 65,535 blocks, so more than 65,535 rows failed to launch. Both kernels now use a 1D grid. Widths up to 256 columns process several rows per 4,096-element tile as an autotune dimension, instead of one program per row, which starves the GPU on narrow rows. Wider rows keep one row per program, and the backward kernel runs up to four persistent programs per SM on the row-tiled path. Padded rows are now masked out after the arithmetic in the backward kernel: with infinite alpha, tanh(inf * 0) is NaN and masked loads alone let it poison the parameter gradients. dalpha and dbeta now take their parameters' dtypes, like dgamma already did, instead of rounding float32 parameter gradients through x.dtype. The output keeps the x.dtype contract.
|
Closing this draft for now: the branch remains pushed on my fork, and the PR message has not been decided yet. It can be reopened, or a new PR opened from the same branch, once the message is settled. |
|
Temporary GPU-testing note, kept in sync with GPU TESTING — TEMPORARY, DO NOT MERGE
This branch has not been executed on a GPU yet. The port was reworked Proposed pull request message (draft, not yet posted)Title: ## Summary
Modification to the shape handling in the fused DyT kernels that gives
a major performance gain in my application: a small network with DyT,
as tested on an H100.
- Both kernels placed rows on CUDA grid dimension 1, which holds at most
65,535 blocks, so more than 65,535 rows failed to launch. Both kernels
now use a 1D grid.
- One program per row starves the GPU on narrow rows. Widths up to 256
columns now process several rows per 4,096-element tile, exposed as a
`BLOCK_M` autotune dimension; wider rows keep one row per program, and
the backward kernel runs up to four persistent programs per SM on the
row-tiled path.
- Padded rows are now masked out after the arithmetic in the backward
kernel: with infinite `alpha`, `tanh(inf * 0)` is NaN and masked loads
alone let it poison the parameter gradients.
- `dalpha` and `dbeta` now take their parameters' dtypes, like `dgamma`
already did, instead of rounding float32 parameter gradients through
`x.dtype`. The output keeps the `x.dtype` contract.
Because the autotuned `BLOCK_N` is not known before launch, the backward
buffers are sized for the worst-case config and zeroed, so unused
programs/column blocks contribute nothing to the reductions.
## Testing Done
Hardware: H100.
- `make checkstyle`: passes.
- `make test`: [to be filled in from the rented-box run]
- `make test-convergence`: [to be filled in from the rented-box run]Runbook: rented H100 boxRun this in a disposable copy. git clone --branch dyt-1d-grid-row-tiling \
https://github.com/apullin/Liger-Kernel.git liger-pr
cd liger-pr
git rev-parse HEAD # record this hash with the results
nvidia-smi
python3 --version # 3.10-3.12 preferred
python3 -m venv .venv && source .venv/bin/activate
pip install --upgrade pip
pip install -e ".[dev]"
make checkstyle 2>&1 | tee /tmp/checkstyle.log
# Gate: the DyT tests. The first run per hidden size triggers autotune
# benchmarking across all configs — let it run, do not kill it as hung.
# This includes the 65,537-row case.
python -m pytest test/transformers/test_dyt.py -v 2>&1 | tee /tmp/test_dyt.logIf rental time allows, then the full template set: make test 2>&1 | tee /tmp/make_test.log
make test-convergence 2>&1 | tee /tmp/test_convergence.logNote on convergence: no convergence mini-model uses DyT, so it should Report back
Do not mark the pull request ready for review until these results are |
Summary
Fixes four related problems in the fused DyT kernels:
BLOCK_Mautotune dimension, alongside the existingBLOCK_Nautotune), and the backward kernel runs up to four persistent programs per SM on that path. Wider rows keep one row per program.alpha, a padded zero givestanh(inf * 0) = NaNand poisons the parameter gradients, so padded contributions are now masked after the arithmetic in the backward kernel.dalphaanddbetawere cast tox.dtype, unlikedgamma. They now take their parameters' dtypes, so float32 parameter gradients are not rounded through e.g. bfloat16. The output keeps thex.dtypecontract.Because the autotuned
BLOCK_Nis not known before launch, the backwardda/dg/dbbuffers are sized for the worst-case config (most programs, smallestBLOCK_N) and zeroed, so programs and column blocks a config does not use contribute nothing to the reductions. Thereset_to_zero=["DA"]autotune behaviour is preserved.Testing Done
make checkstyleequivalent:ruff checkandruff format --checkpass on both changed filesmake testto ensure correctnessmake test-convergenceto ensure convergenceThe new and extended tests in
test/transformers/test_dyt.py(small/ragged widths, 65,537 rows, ragged rows with infinitealpha, and bfloat16 input with float32 parameters) still need to run on a GPU, e.g. via CI. This is opened as a draft until those results are in.