Skip to content

Reduce Grouped MLP Fuser CPU Overhead - #3410

Open
zhongbozhu wants to merge 3 commits into
NVIDIA:mainfrom
zhongbozhu:opfuser_group_mlp_cpu_optim
Open

Reduce Grouped MLP Fuser CPU Overhead#3410
zhongbozhu wants to merge 3 commits into
NVIDIA:mainfrom
zhongbozhu:opfuser_group_mlp_cpu_optim

Conversation

@zhongbozhu

@zhongbozhu zhongbozhu commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Description

Reuse fused operation plans when full activation recompute changes grad mode, and avoid redundant CUDA current-device discovery for grouped MLP stream lookups.

Fixes # (issue)

#2897

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 20, 2026
@zhongbozhu
zhongbozhu marked this pull request as ready for review August 20, 2026 18:39
@zhongbozhu
zhongbozhu requested a review from timmoon10 as a code owner August 20, 2026 18:39
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR caches operation-fusion plans across alternating gradient requirements and avoids redundant CUDA current-device discovery.

  • Adds separate reusable plans for checkpoint forward and grad-enabled recomputation.
  • Uses the grouped-MLP tensor device directly when obtaining the CUDA stream.
  • Adds a focused test for alternating no-grad and grad-enabled cache reuse.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/pytorch/ops/fuser.py Separates recipe-state reset from backward-boundary selection and caches forward/backward plans for reuse.
transformer_engine/pytorch/ops/fused/grouped_mlp.py Obtains each grouped-MLP CUDA stream using the operation tensor's explicit device index.
tests/pytorch/test_fusible_ops.py Verifies that alternating grad requirements build exactly two plans and subsequently restore the corresponding cached lists.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[OperationFuser invocation] --> B[Compute backward boundary]
  B --> C{Recipe state changed?}
  C -->|yes| D[Reset basic-op recipe state]
  C -->|no| E[Build fusion key]
  D --> E
  E --> F{Cached plan exists?}
  F -->|yes| G[Restore forward and backward plans]
  F -->|no| H[Apply fusion rules]
  H --> I[Cache generated plans]
  G --> J[Execute]
  I --> J
Loading

Reviews (6): Last reviewed commit: "fix cutedsl wgrad crash" | Re-trigger Greptile

Comment thread transformer_engine/pytorch/ops/fuser.py
# backward boundary in the key, but pay construction cost only once for
# each configuration. Full recompute therefore builds at most one
# no-grad plan and one grad-enabled plan for a stable recipe.
fusion_params = (recipe_type, first_op_requiring_backward, backward_override)

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.

I think we should use recipe object instead of recipe_type as fusion_param key And implement hash function for it. Since that governs the fusion and not just the recipe type

cc: @timmoon10

@vthumbe1503 vthumbe1503 Aug 25, 2026

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.

@zhongbozhu commenting here so we dont miss out on our discussions related to this PR. The main issue we need to take care of here is the CPU overheads of the additional recipe object as a key in fusion params.

There are two options to deal with this

  1. We can cache the recipe representation so that the later iterations using the same recipe object dont have to deal with recomputing the representation/hash needed to be maintained in a fusion params dict. However it turns out recipe object can be recreated on every iteration (for eg, in Megatron).
  2. So @timmoon10 had the idea of exposing a representation of recipe object, call it options_key. Different objects will have the same options_key(). And so fuser will take the responsibility of caching the options_key instead of Recipe class itself taking that responsibility. And so if recipe is unchanged in terms of options_key, we wont face any new CPU overheads for the fusion_params_key computation

@tingyangk
tingyangk force-pushed the opfuser_group_mlp_cpu_optim branch 2 times, most recently from ff86f24 to 97850a4 Compare August 22, 2026 02:00
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@zhongbozhu
zhongbozhu force-pushed the opfuser_group_mlp_cpu_optim branch from 97850a4 to 866c6f1 Compare August 27, 2026 20:38
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

zhongbozhu and others added 3 commits August 31, 2026 10:29
Reuse fused operation plans when full activation recompute changes grad mode, and avoid redundant CUDA current-device discovery for grouped MLP stream lookups.

Co-authored-by: Ting-Yang Kao <tingyangk@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
Signed-off-by: tingyangk <tingyangk@nvidia.com>
@zhongbozhu
zhongbozhu force-pushed the opfuser_group_mlp_cpu_optim branch from 866c6f1 to 2fb926f Compare August 31, 2026 17:29
@zhongbozhu

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch L1

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

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants