Skip to content

[1/2] [graph_trainer] Save forward dependencies hidden by mutations - #4842

Merged
IvanKobzarev merged 1 commit into
mainfrom
graph-trainer-save-forward-mutation-dependencies
Oct 2, 2026
Merged

IvanKobzarev merged 1 commit into
mainfrom
graph-trainer-save-forward-mutation-dependencies

Conversation

@IvanKobzarev

@IvanKobzarev IvanKobzarev commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
  1. E.g. we have joint graph:
before = sin(x)
mutation = x.copy_(before)  # Mutation return is unused.
forward = cos(x)                    # forward = cos(sin(x0))
backward = before * 2          # backward = 2 * sin(x)

Current partitioner:

saved = find_saved_values(forward_outputs, backward_outputs)
mutations = find_forward_mutations()
  saved = [x]
  mutations = [mutation]

FWD:

before = sin(x)
mutation = x.copy_(before)
forward = cos(x)
return forward, x, mutation # 

BWD:

# x_saved already contains sin(original_x)
before = sin(x_saved)
backward = before * 2

Backward therefore uses sin(sin(original_x)) - WRONG

The Fix:

Add sources of mutations into lookup of values to be saved , to cut the recomputation chains at them.

Then the old logic will check, that it is used by forward and by backward and save it.

In this case sin(x) will not be replayed.

So the main semantic that we add:

We save forward mutation sources if they are used by backward too.
This makes the recompute cat to be after this points, without rereplaying ops on them.

Implementation:

Extracted all mutation related utilities to torchtitan/experiments/graph_trainer/mutation_utils.py

Removed all positional assumptions to use schema based mutation analysis.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 23, 2026
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch 2 times, most recently from d1a8764 to 54d82f1 Compare September 23, 2026 16:02
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from 54d82f1 to 2a3c645 Compare September 23, 2026 16:16
@IvanKobzarev
IvanKobzarev removed this pull request from stack #4843 September 23, 2026 16:17
@IvanKobzarev
IvanKobzarev removed this pull request from stack #4844 September 23, 2026 16:20
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from 2a3c645 to ced3eb7 Compare September 23, 2026 16:22
Base automatically changed from graph-trainer-effectful-op-partitioning to main September 24, 2026 11:44
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from ced3eb7 to 6c2bc41 Compare September 24, 2026 11:44
@IvanKobzarev
IvanKobzarev marked this pull request as ready for review September 24, 2026 18:12
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Sep 24, 2026
@IvanKobzarev IvanKobzarev added the ciflow/h100.8 Trigger H100.8 CI label Sep 24, 2026
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Save forward dependencies hidden by mutations [graph_trainer] Save forward mutation premutation buffers that are used by backward Sep 24, 2026
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch 2 times, most recently from d3d4aaa to 8d6f8a2 Compare September 25, 2026 12:24
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from 8d6f8a2 to cae764e Compare September 29, 2026 16:48
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Save forward mutation premutation buffers that are used by backward [1/2] [graph_trainer] Save forward dependencies hidden by mutations Sep 29, 2026
Discover existing forward mutation outputs before selecting values saved for backward, and include those mutations in forward dependency analysis. This prevents pure forward values used by backward from being recomputed from storage mutated later in forward.

Keep the existing GraphMeta, runtime output, and FSDP split contracts unchanged. Cover the behavior with a CPU regression and an exact SM100 MXFP8 WGrad reproducer.
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from 2ac386c to cae764e Compare October 1, 2026 12:26
@IvanKobzarev
IvanKobzarev force-pushed the graph-trainer-save-forward-mutation-dependencies branch from cae764e to 7c49bcd Compare October 1, 2026 16:02
@IvanKobzarev
IvanKobzarev merged commit bc86435 into main Oct 2, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/h100.8 Trigger H100.8 CI 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.

2 participants