Skip to content

[GraphTrainer] Unified framework for activation memory management - #3118

Merged
SherlockNoMad merged 1 commit into
mainfrom
graph_trainer/memory-policy
Apr 28, 2026
Merged

SherlockNoMad merged 1 commit into
mainfrom
graph_trainer/memory-policy

Conversation

@SherlockNoMad

Copy link
Copy Markdown
Contributor

Summary

  • Add tag_with_memory_policy_pass that unifies SAC and CPU offload tagging into a single pass, dispatching based on config.compile.memory_policy
  • Add cpu_offload_all memory policy that tags all eligible activations for CPU offload (WIP, for dev/testing)
  • Restructure pass pipeline: apply_cpu_offload_pass and selective_activation_remat_pass always run after tagging (no-ops when no nodes are tagged)

Test plan

  • Pre-commit passes
  • CPU offload unit tests pass (test_cpu_offload.py)
  • Passes unit tests pass (test_passes.py)
  • Bitwise deterministic tests pass (default policy unchanged)
  • Manual 8-GPU run with --compile.memory_policy cpu_offload_all completes successfully, logs show 40 activations offloaded (222.81 MB)
  • CI integration test aot_fx_trace_llama3_fsdp_tp_cpu_offload_all

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 27, 2026
@SherlockNoMad SherlockNoMad changed the title [GraphTrainer] Add cpu_offload_all memory policy [GraphTrainer] Unified framework for activation memory management Apr 27, 2026
@SherlockNoMad
SherlockNoMad force-pushed the graph_trainer/memory-policy branch from 888ce61 to 97aeb9f Compare April 27, 2026 21:28
"""Log timing, op-count diffs, and before/after graphs for each pass to tlparse."""

memory_policy: Literal["default", "eager"] = "default"
memory_policy: Literal["default", "eager", "cpu_offload_all"] = "default"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how should a user express a combination of offload + SAC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I expect user to implement a policy_fn, and register it. The framework doesn't exist yet, but I expect something like this to work

@register_policy
def my_tagging_pass(gm)
    ... 

We should provide our own, e.g. based on Sanket's ILP solver.

_NOT_IN_LAYERS,
)
from torchtitan.experiments.graph_trainer.cpu_offload import cpu_offload_pass
from torchtitan.experiments.graph_trainer.cpu_offload import (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIUC, cpu_offload_pass = tag_all_offloadable_activations + apply_cpu_offload_pass

In the current code, we didn't call cpu_offload_pass anymore. Shall we remove it? And we can also clean up the APIs in cpu_offload.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed.

"""Log timing, op-count diffs, and before/after graphs for each pass to tlparse."""

memory_policy: Literal["default", "eager"] = "default"
memory_policy: Literal["default", "eager", "cpu_offload_all"] = "default"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same question: if user use "default", tag_all_offloadable_activations won't be called, then apply_cpu_offload_pass is a no-op?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, it's ok to run a no-op pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

annotate_flex_attention_for_regional_inductor_pass is also an no-op pass for model not using flex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so right now we can't have SAC and CPU offloading at the same time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yea, we don't have a policy_fn that would use SAC and CPU offload at the same time yet...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added comment.

…policy_pass

Introduce a unified tag_with_memory_policy_pass that tags forward nodes
with MUST_SAVE, PREFER_RECOMPUTE, or MUST_CPU_OFFLOAD based on the
configured memory policy. The pass pipeline now always runs
apply_cpu_offload_pass and selective_activation_remat_pass after
tagging (both are no-ops when no nodes are tagged).

Add cpu_offload_all memory policy that offloads all eligible activations
to CPU. This is a work-in-progress policy for development and testing.

Add integration test for aot_fx_trace with cpu_offload_all.
@SherlockNoMad
SherlockNoMad force-pushed the graph_trainer/memory-policy branch from 97aeb9f to c5a5e9d Compare April 27, 2026 23:03
@SherlockNoMad SherlockNoMad added the ciflow/h100.8 Trigger H100.8 CI label Apr 27, 2026
@SherlockNoMad
SherlockNoMad merged commit 6179e65 into main Apr 28, 2026
11 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants