Skip to content

[PyTorch] BF16 fused grouped MLP: N-major dgrad weights and direct weight-gradient allocation - #4

Open
hwanseoc wants to merge 2 commits into
hwanseoc/te3646-basefrom
hwanseoc/bf16-grouped-mlp-host
Open

hwanseoc wants to merge 2 commits into
hwanseoc/te3646-basefrom
hwanseoc/bf16-grouped-mlp-host

Conversation

@hwanseoc

Copy link
Copy Markdown
Owner

Staging PR in the fork, stacked on @tingyangk's BF16 fused grouped MLP (NVIDIA#3646). hwanseoc/te3646-base is that PR's commit.

  • N-major dgrad weights (7f47508): when the cuDNN frontend advertises supports_bf16_canonical_layouts (Accept canonical layouts in the BF16 grouped GEMM backends and stop reading offsets to the host NVIDIA/cudnn-frontend#1602, merged), a packed weight goes to cuDNN as the stored (experts, out, in) buffer with b_major="n". FC1 dgrad no longer transposes the whole weight every step, and FC2 dGLU no longer builds a pointer array.
  • Weight-gradient allocation (46f5919): the buffer is allocated directly with make_grouped_tensor_from_rowwise_data instead of make_grouped_tensor_with_shapes, which cost about 217 µs per call. This function is shared, so the MXFP8 and NVFP4 paths get it too.

Measured on B200 against NVIDIA#3646 with cuDNN FE develop:

  • Outputs and all gradients are bitwise identical.
  • At 64 experts, hidden 4096, FFN 1024, 16384 tokens, fwd+bwd goes from 4540 to 853 µs host and from 4752 to 2098 µs end to end. Unfused is 2294 µs end to end.

@coderabbitai ignore

With cuDNN frontend canonical BF16 layouts (supports_bf16_canonical_layouts),
the FC1 dgrad grouped GEMM and the FC2 dGLU take the stored (experts, out, in)
weight directly with b_major="n": no per-backward transpose copy for FC1 and
no pointer array for FC2.

Signed-off-by: Hwanseo Choi <hwanseoc@nvidia.com>
make_grouped_tensor_with_shapes builds per-tensor split metadata on every
backward (about 217 us per call); the uniform-shape unquantized buffer only
needs make_grouped_tensor_from_rowwise_data over one allocation.

Signed-off-by: Hwanseo Choi <hwanseoc@nvidia.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant