You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1aaede2
Browse filesBrowse the repository at this point in the historyBrowse files
Reuse cuBLASMp's all-gathered grad_output in the wgrad GEMM (#3629)
* [PyTorch] Reuse cuBLASMp's all-gathered grad_output for wgrad
With the cuBLASMp comm+GEMM overlap backend, the dgrad AllGather + GEMM gathers grad_output and the wgrad GEMM
gathered it a second time, while Userbuffers wgrad reads the tensor that its dgrad all-gather left in the
communication buffer. cuBLASMp 0.11.0 leaves the gathered B at the start of its workspace (a documented
cublasMpMatmul workspace property), so wgrad now reuses it the same way:
- nvte_comm_gemm_workspace() (comm_gemm.h, TE-internal) returns the comm-gemm context's workspace.
- With the cuBLASMp backend, CommOverlap/CommOverlapP2P::get_buffer() returns a view of that workspace with the
communicator's buffer shape and dtype, like the Userbuffers buffer view.
- get_cublasmp_all_gather_output() builds the gathered tensor from it for unquantized and per-tensor FP8 data.
Linear, LayerNormLinear, LayerNormMLP (fc2) and the fused te.ops backward use it instead of
gather_along_first_dim; MXFP8 and other formats, a delayed wgrad and a skipped dgrad GEMM still gather.
This needs cuBLASMp 0.11.0 or newer, since older versions keep the gathered B elsewhere in the workspace; the next
commit checks the version.
Tested on 4x H100 with cuBLASMp 0.11.0: the layer and multi-layer tests of test_comm_gemm_overlap.py with the
cuBLASMp backend pass (39 passed, 13 MXFP8 cases skipped on H100), and test_fusible_ops_with_userbuffers.py
--use-cublasmp passes in BF16 and FP8 delayed and current scaling. All-gathers per backward: row-parallel Linear
1 -> 0, LayerNormMLP 2 -> 1 (fc1 still re-gathers its input, as with Userbuffers).
Signed-off-by: Almog Segal <asegal@nvidia.com>
* [PyTorch] Fall back to the all-gather with cuBLASMp before 0.11.0
Reusing the gathered grad_output relies on cuBLASMp 0.11.0 leaving the gathered B at the start of its workspace.
Earlier versions keep it after their cuBLASLt workspaces, so the view held other data. nvte_comm_gemm_workspace() now
checks the loaded library with cublasMpGetVersion() and returns nullptr before 0.11.0; get_buffer() then reports that
no gathered input is available, and get_cublasmp_all_gather_output() returns None, so the callers all-gather as before.
Tested on 4x H100: with cuBLASMp 0.11.0, the row-parallel Linear backward issues no all-gather and the Linear and
LayerNormMLP overlap tests with the cuBLASMp backend pass (9 passed). With cuBLASMp 0.10.0 it all-gathers once per
backward and the same tests pass, as they do on TE main.
Signed-off-by: Almog Segal <asegal@nvidia.com>
* [PyTorch] Check the cuBLASMp version instead of catching the get_buffer() error
get_cublasmp_all_gather_output() fell back to the all-gather for cuBLASMp versions before 0.11.0 by catching the
error that get_buffer() raises and matching its message. That breaks silently if the message changes, and with an
older cuBLASMp it raises and catches an exception in every backward pass of every layer that overlaps an all-gather.
nvte_cublasmp_version() now returns the version of the loaded cuBLASMp library, read once with cublasMpGetVersion()
(0 without cuBLASMp), and Python exposes it as tex.nvte_cublasmp_version(). get_cublasmp_all_gather_output() checks a
cached version >= 0.11.0 before calling get_buffer(), so get_buffer() errors are no longer caught.
nvte_comm_gemm_workspace() uses the same function.
Signed-off-by: Almog Segal <asegal@nvidia.com>
* [PyTorch] Test the fused te.ops comm+GEMM overlap with cuBLASMp
test_fuser_ops_with_userbuffers only ran the Userbuffers backend, although the script supports --use-cublasmp and the
fused te.ops backward reuses cuBLASMp's gathered grad_output. It is now parametrized over both backends and skips the
cuBLASMp cases when Transformer Engine is built without cuBLASMp.
Signed-off-by: Almog Segal <asegal@nvidia.com>
---------
Signed-off-by: Almog Segal <asegal@nvidia.com>
0 commit comments