[Common/PyTorch] Grouped weighted-SwiGLU MXFP8 kernel - #3315
Conversation
Add nvte_group_swiglu_quantize, which fuses the weighted SwiGLU activation with columnwise MXFP8 quantization over grouped (MoE) tensors. Signed-off-by: Cael Ling <caell@nvidia.com>
for more information, see https://pre-commit.ci
Greptile SummaryThe PR adds a grouped weighted-SwiGLU kernel fused with column-wise MXFP8 quantization and exposes it through the C and PyTorch APIs.
Confidence Score: 4/5The PR is not yet safe to merge because the shared metadata-validation change allows existing grouped operations to launch against metadata and outputs on mismatched CUDA devices. Existing grouped bindings such as group_quantize do not install a device guard, so metadata on a non-current GPU now passes validation before offset kernels use the ambient stream and grouped output allocation follows the ambient CUDA device. Files Needing Attention: transformer_engine/pytorch/csrc/quantizer.cpp and transformer_engine/pytorch/csrc/extensions/cast.cpp Important Files Changed
Sequence DiagramsequenceDiagram
participant Py as PyTorch caller
participant Bind as group_scaled_swiglu binding
participant Quant as MXFP8 grouped allocator
participant Core as NVTE dispatch
participant GPU as CUDA kernel
Py->>Bind: input [T,2F], prob [T], metadata
Bind->>Bind: validate layout and devices
Bind->>Bind: guard input CUDA device
Bind->>Quant: allocate grouped [T,F] output
Quant-->>Bind: columnwise MXFP8 buffers
Bind->>Core: nvte_group_scaled_swiglu
Core->>GPU: weighted SwiGLU + columnwise quantize
GPU-->>Py: grouped MXFP8 output
Reviews (5): Last reviewed commit: "[PyTorch] Add a benchmark for group_scal..." | Re-trigger Greptile |
…tize Signed-off-by: Cael Ling <caell@nvidia.com>
Signed-off-by: Cael Ling <caell@nvidia.com>
…ntize Signed-off-by: Cael Ling <caell@nvidia.com>
vthumbe1503
left a comment
There was a problem hiding this comment.
Thanks for the PR @cael-ling. Could you also please publish the perf numbers for this kernel?
| * \param[in,out] output Grouped output tensor [T, F] (columnwise MXFP8). | ||
| * \param[in] stream CUDA stream used for the operation. | ||
| */ | ||
| void nvte_group_swiglu_quantize(const NVTEGroupedTensor input, const NVTETensor prob, |
There was a problem hiding this comment.
Can we rename this? Quantization details are already encoded in GroupedTensor. It ll be consistent with the other API naming convention
| void nvte_group_swiglu_quantize(const NVTEGroupedTensor input, const NVTETensor prob, | |
| void nvte_group_scaled_swiglu(const NVTEGroupedTensor input, const NVTETensor prob, |
| std::optional<at::Tensor> tensor_offsets, | ||
| std::optional<at::Tensor> noop_flag); | ||
|
|
||
| py::object group_swiglu_quantize(const at::Tensor &input_2f, const at::Tensor &prob, |
There was a problem hiding this comment.
Similar comment.
| py::object group_swiglu_quantize(const at::Tensor &input_2f, const at::Tensor &prob, | |
| py::object group_scaled_swiglu(const at::Tensor &input_2f, const at::Tensor &prob, |
lines up with TE's existing ScaledSwiGLU op, so nvte_group_swiglu_quantize becomes nvte_group_scaled_swiglu, and the kernel header, dispatch, bindings and tests follow. Also makes the kernel actually faster than the unfused path it replaces. Per-token scales are staged through shared memory once per chunk, the output buffer is single-buffered to raise occupancy, and SiLU uses an approximate exp and divide. The activation is quantized to MXFP8 immediately, so the approximation stays far below one FP8 ULP. Signed-off-by: Cael Ling <caell@nvidia.com>
Times the fused kernel against the unfused path it replaces, with the activation half computed three ways: eager PyTorch, torch.compile, and TE's existing ScaledSwiGLU op. Signed-off-by: Cael Ling <caell@nvidia.com>
|
Hi @vthumbe1503, thanks for your review, rename work has been performed, benchmark results have been added in the description, please take a look, thanks! |
Description
Add
nvte_group_swiglu_quantize, which fuses the weighted SwiGLU activation with column-wise MXFP8 quantization over grouped (MoE) tensors:Performance (GB200)
T=98304, F=2048/4096, 16 experts, compact scales:ScaledSwiGLU+tex.group_quantize)Reproduce:
python benchmarks/benchmark_group_scaled_swiglu.py --num-groups 16 --scales compact # shape sweep: 16/64 experts x compact/swizzled scales x eager/graph timing python benchmarks/benchmark_group_scaled_swiglu.py --hidden 4096Type of change
Changes
Please list the changes introduced in this PR:
Checklist: