Skip to content

Reduce CPU overhead in graph-safe GroupedLinear/GroupedMLP - #3752

Merged
timmoon10 merged 4 commits into
NVIDIA:mainfrom
vthumbe1503:grouped-linear-cpu-overhead
Nov 7, 2026
Merged

timmoon10 merged 4 commits into
NVIDIA:mainfrom
vthumbe1503:grouped-linear-cpu-overhead

Conversation

@vthumbe1503

@vthumbe1503 vthumbe1503 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Reduce CPU host overhead in graph-safe GroupedLinear and grouped MLP training steps. The measured CUDA kernels and their total durations are unchanged.

Type of change

  • Code refactoring
  • Performance improvement

Changes

  • Read Python tensor attributes once in the C++ type converters, including grouped tensor metadata. Keep the newly added optional row-scaled NVFP4 field from main.
  • Remove unnecessary flattening when wrapping contiguous grouped input, output, and gradient buffers. Flatten only at the point where split_into_quantized_tensors slices storage; add coverage for multidimensional contiguous buffers.
  • Use the cached device capability and a direct quantizer check in grouped GEMM setup.
  • Remove redundant scale reshapes from the native scaled activation path.

Performance

CPU host step time, forward plus backward, lower is better. main is dd628d3a11; PR is 96dd4c060e. Values are medians of six 400-step blocks across two interleaved passes (main, PR, main, PR) on the same GB200/Grace node, pinned to CPU 16. Each process had 60 warmup steps. The workload uses eight experts, 256 tokens per expert, hidden size 128, discrete expert weights, and no bias. BF16 uses BF16 activations and weights without FP8 autocast; MXFP8 uses BF16 activations with the MXFP8 block-scaling recipe. Timings exclude a per-step CUDA synchronization. The fused MXFP8 MLP uses split alignment 256; the other Sequential cases use 128.

These measurements predate the merge of main into PR head 08008c8445 on 2026-11-02. The merged head has not been remeasured because dlcluster was unreachable.

BF16

Case Hidden Shape main PR Reduction
GroupedLinear module FC1 128 128 → 256 0.467 ms 0.437 ms 6.3%
GroupedLinear op FC1 128 128 → 256 0.476 ms 0.439 ms 7.6%
GroupedLinear module FC2 128 128 → 128 0.466 ms 0.429 ms 8.0%
GroupedLinear op FC2 128 128 → 128 0.478 ms 0.442 ms 7.5%
GroupedMLP, unfused Sequential 128 128 → 256 → 128 → 128 0.875 ms 0.808 ms 7.6%

MXFP8

Case Hidden Shape main PR Reduction
GroupedLinear module FC1 128 128 → 256 0.633 ms 0.595 ms 6.1%
GroupedLinear op FC1 128 128 → 256 0.640 ms 0.589 ms 8.1%
GroupedLinear module FC2 128 128 → 128 0.634 ms 0.588 ms 7.3%
GroupedLinear op FC2 128 128 → 128 0.627 ms 0.592 ms 5.7%
GroupedMLP, unfused Sequential 128 128 → 256 → 128 → 128 1.197 ms 1.098 ms 8.3%
GroupedMLP, CuTe fused Sequential 128 128 → 256 → 128 → 128 1.488 ms 1.475 ms 0.9%

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
@vthumbe1503
vthumbe1503 force-pushed the grouped-linear-cpu-overhead branch from c67067c to 5885336 Compare October 27, 2026 18:02
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

This PR reduces repeated Python work around graph-safe grouped linear and MLP calls.

  • Grouped operations keep contiguous buffers in their existing shapes.
  • C++ tensor wrappers reuse Python tensor attributes.
  • Grouped GEMM setup checks quantization and device details directly.
  • Scaled activation passes scale tensors without extra reshapes.

No actionable issues were found. Review used the full PR changes because the previous and current heads have different merge bases with the supplied target commit. No runtime tests were run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Contiguous input and gradient buffers] --> B[Grouped storage keeps existing shapes]
  B --> C[C++ reads pointers and grouped metadata]
  C --> D[Grouped GEMM]
  B --> E[Split requested]
  E --> F[Flatten shared views]
  F --> G[Slice individual tensors]
Loading

Reviews (4) · Last reviewed commit: "Merge branch 'main' into grouped-linear-..." · Reviewed by Greptile

@vthumbe1503
vthumbe1503 marked this pull request as draft October 27, 2026 18:16
@vthumbe1503
vthumbe1503 marked this pull request as ready for review October 29, 2026 23:56
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

# for all of fprop/dgrad/wgrad, so no user-configurable setting is discarded.
# On Blackwell and newer the binding emulates this GEMM with MXFP8 (as for
# non-grouped GEMM); the setting is passed through unchanged.
use_split_accumulator = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly at this point, I don't think anyone wants to use use_split_accumulator=False even for per-tensor recipe.

Setting use_split_accumulator=False was a legacy toggle used back in the delayed scaling days or per-tensor current scaling, and we sometimes tuned it off and trade GEMM-K accumulation precision for more GEMM perf. But I don't think anyone is gonna do that anymore, plus that everyone using fp8 recipe on Hopper uses blockwise and they expect fp32 accumulation precision.

use_split_accumulator=False is also Hopper-only, it's not applicable for Blackwell anymore.

I would suggest we remove everything about use_split_accumulator=False because it delivers more precision by default.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
@vthumbe1503 vthumbe1503 changed the title Reduce CPU overhead in grouped-tensor GroupedLinear and MLP Reduce CPU overhead in graph-safe GroupedLinear/GroupedMLP Nov 3, 2026
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@timmoon10 timmoon10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@timmoon10
timmoon10 merged commit f0ee13b into NVIDIA:main Nov 7, 2026
20 of 23 checks passed
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.

3 participants