[https://nvbugs/6633931][fix] Size the SM90 fp8 block-scale MoE workspace for the buffers it actually uses - #18323
Draft
pranav-nvidia wants to merge 3 commits into
Draft
Conversation
…the buffers it uses Under fp8 activation fusion the inputs buffer holds pre-quantized fp8 activations plus their padded 1x128 scales, not the bf16 activations permuted_data_size is sized for, so max()-ing with the bf16 sizes keeps it at twice what is needed. Only the fused path writes FC2 output into the outputs buffer, so the unfused path no longer sizes for it either. DeepSeek-V3.2 at 65536 MoE rows: 14.068 -> 10.679 GiB, outputs bit-identical. Signed-off-by: Pranav Shrestha <254760092+pranav-nvidia@users.noreply.github.com>
…rkspace Signed-off-by: Pranav Shrestha <254760092+pranav-nvidia@users.noreply.github.com>
…zing comments Signed-off-by: Pranav Shrestha <254760092+pranav-nvidia@users.noreply.github.com>
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.
@coderabbitai summary
Description
On SM90,
getWorkspaceDeviceBufferSizesover-sizes the two overlapped MoE buffers for the fp8 block-scale path, and #16849 made it worse.Under fp8 activation fusion (
useFp8BlockScaleActFusion(), SM90 only) the overlapped inputs buffer holds pre-quantized fp8 activations plus their padded 1x128 scales — never the bf16 activations thatpermuted_data_sizeandfc1_result_sizeare sized for. #16849 already computes the correct size withfp8BlockScaleRegionBytes(...), but takes amax()with the stale bf16 sizes instead of replacing them. Sincesizeof(T) == sizeof(UnfusedGemmOutputType) == 2,permuted_data_sizealone pins the buffer atpermuted_elems * 2, roughly twice what the fused path needs. This replaces rather than maxes.The FC2 GEMM output is now reserved in exactly one of the two buffers, selected by the same predicate the forward pass uses to route it (
isActivationPrequantized()/use_fused_block_scale_quant): the fused path writes it into the outputs buffer (glu_inter_result_, because its inputfc1_result_is aliased ontofc2_result_), the unfused path writesfc2_result_in the inputs buffer. It was previously counted in both. This also restoresoutputs = fc1_outputon the unfused path — #16849 widened it tomax(fc1, fc2)unconditionally, so non-SM90 architectures were reserving an FC2-output-sized buffer they never write to.Measured on H100 (SM90) at DeepSeek-V3.2 dimensions (hidden 7168, inter 2048, 256 experts, top_k 8), sweeping MoE rows, reading the workspace size the op logs at DEBUG:
At 65536 rows that is 15,105,925,632 -> 11,467,047,424 bytes, a 24.1% reduction. This is sizing only; no kernel or launch parameter changes.
Context: the 14.02 GiB allocation is what OOMs in NVBug 6633931 on 8xH200. That test also runs MoE unchunked, which is fixed separately in #18322; the two changes are independent and both are needed to give the test real margin.
Test Coverage
tests/unittest/_torch/modules/moe/test_moe_backend.py -k "FP8_BLOCK_SCALES and CUTLASS"— 10 passed on H100, run on the unpatched build as a control.Because that suite only covers small shapes (seq 1-8, hidden 256-2048) where the workspace is negligible, an under-sized buffer that only overflows at large
num_moe_inputswould corrupt FC2's input silently rather than crash. So the change was additionally checked at full DeepSeek-V3.2 dimensions up to 65536 MoE rows (524288 expanded rows) with identical seeds: output fingerprints are bit-identical before and after at every row count (out_sum194420032929792.0,out_absmax14483456.0,out_mean413869.1875, 0 NaN, 0 Inf), andgetWorkspaceSizeno longer needs the removed capacity.PR Checklist
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.