Skip to content

[graph_trainer] Add CooR precompile support for rank-agnostic compilation - #2713

Merged
bobrenjc93 merged 20 commits into
mainfrom
gh/bobrenjc93/34/head
Apr 3, 2026
Merged

bobrenjc93 merged 20 commits into
mainfrom
gh/bobrenjc93/34/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:

  • precompile.py: Artifact serialization/loading with config fingerprint
    validation. DeviceMesh objects flow as opaque graph inputs (via
    DTensor.tensor_flatten -> OpaqueObjectState), so no post-load
    patching or PG aliasing is needed.
  • precompile_main.py: Single-process entry point using fake PG backend
  • graph_utils.py: Enable CooR in export_joint() when precompile is on,
    so PG names are opaque graph inputs (not hardcoded string constants)
  • compile.py: Precompile save/load integration with AOT compilation
  • passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
Model: graph_trainer_llama3_8b
Parallelism: TP=8, SimpleFSDP=2
Compile: AOT, full_inductor_compilation + inductor_decomposition
Training: 100 steps, local_batch_size=1, seq_len=2048
Determinism: --debug.seed=42 --debug.deterministic

CooR precompile (1 node, 1 GPU, fake PG backend)
-> train (2 nodes, 16 GPUs) vs baseline (no precompile)
Result: bitwise identical loss and grad_norm for all 100 steps

image

[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Mar 26, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN


ghstack-source-id: b6b4816
Pull-Request: #2713
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 26, 2026
@bobrenjc93
bobrenjc93 requested review from SherlockNoMad, aorenste, ezyang and zhxchen17 and removed request for SherlockNoMad March 26, 2026 05:31
@bobrenjc93
bobrenjc93 marked this pull request as ready for review March 26, 2026 05:34
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Mar 26, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 1c7c950
Pull-Request: #2713
@bobrenjc93
bobrenjc93 marked this pull request as draft March 26, 2026 14:57
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Mar 26, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 6100357
Pull-Request: #2713
--training.seq_len 2048

# Step 2: load and train with torchrun (uses all GPUs)
torchrun --nproc_per_node=8 --virtual-local-rank \

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 did consider deriving these flags from the precompiled artifact but decided against it for the following reasons:

  1. The additional fingerprint check seems useful in the case when the CLI args at runtime are different than the ones used at precompile time.
  2. Since some configs come from the artifact (model, parallelism, compile passes) but others come from the user (training steps, batch size, etc), we'd have to implement some sort of partial load + merge config system which makes the interface harder to reason about from a user POV.

@yiming0416

Copy link
Copy Markdown
Contributor

@claude review this PR

@claude

claude Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @yiming0416's task in 4m 16s —— View job


Review of PR #2713: [graph_trainer] Add CooR precompile support

  • Read the full diff and all changed files
  • Review precompile_main.py (new file, main entry point)
  • Review precompile.py (artifact serialization/loading)
  • Review compile.py (precompile save/load integration)
  • Review graph_utils.py (CooR export changes)
  • Review passes.py (inductor decomposition fix)
  • Review configs.py (config changes)
  • Review README.md (documentation)
  • Review test files
  • Post comprehensive review

Summary

This PR adds single-process precompilation using compile-on-one-rank (CooR). The key idea is that a single GPU can trace through distributed ops with a fake backend, producing a rank-agnostic artifact that all ranks can load during torchrun training. The bitwise-identical verification across 100 steps (Llama3-8B, 16 GPUs) is strong evidence of correctness.

The architecture is clean: precompile_main.py → fake PG → trace → serialize, then at training time: load → deserialize → run. The fingerprinting system to catch stale artifacts is well-thought-out.

Issues

1. Integration tests will fail — no precompile pre-step mechanism (Bug)

The two new integration tests (aot_llama3_precompile_full_inductor and aot_llama3_precompile_regional_inductor) at tests/integration_tests.py:287-321 pass --compile.precompile to the training command, but compile.py:146-151 now hard-errors if the artifact doesn't exist:

if not storage.exists(artifact_key):
    raise ValueError(
        f"Precompiled artifact not found at ..."
    )

The test infrastructure (run_tests.py:run_single_test()) has no mechanism to run precompile_main.py as a pre-step before the training command. OverrideDefinitions only supports sequences of training commands — there's no hook for arbitrary pre-test commands. These tests will fail at runtime with a ValueError.

The previous behavior had a fallback (compile-on-the-fly if no artifact exists, then save). This PR removed that fallback in favor of the two-step workflow, but the integration tests weren't updated to accommodate the new two-step requirement.

Suggestion: Either extend OverrideDefinitions with a pre_commands field, or structure the precompile tests as a two-element override_args list where the first entry runs precompile_main (would need run_single_test modifications), or add a custom test runner for precompile tests.

2. CooR flag toggling is not exception-safe during init_weights (precompile_main.py:166-169)

dist_config.compile_on_one_rank = False
with torch.no_grad():
    model.init_weights(buffer_device=None)
dist_config.compile_on_one_rank = True

If init_weights raises, compile_on_one_rank stays False for the rest of the process. This should use a try/finally pattern, consistent with how export_joint in graph_utils.py:76-98 properly uses try/finally for the same flag.

Fix this →

Nits / Minor

3. Implicit string concatenation instead of single string (precompile_main.py:64-65)

raise ValueError(
    "precompile_main requires --compile.precompile_artifact_dir " "to be set."
)

This is an implicit string concatenation. It works, but should be a single string for clarity. Same pattern appears at precompile_main.py:92-93:

f"Initializing single-process precompile with " f"world_size={world_size}"

Two f-strings implicitly concatenated — just use one.

4. README Pre-compile section says artifacts are "detected automatically... and trigger a recompilation with a warning" (README.md:82-83)

Stale artifacts are detected automatically via config fingerprinting and trigger a recompilation with a warning

But the code no longer auto-recompiles. After this PR, stale artifacts trigger a hard ValueError (or a warning if TORCHTITAN_SKIP_FINGERPRINT_CHECK=1). The README text should be updated to match the new behavior.

5. precompile_artifact_dir default is empty string, not something more Pythonic (configs.py:46)

The config field precompile_artifact_dir: str = "" with a separate validation check works, but this is a case where the repo's CLAUDE.md says "No None defaults for required fields." An empty string is arguably the same anti-pattern as None — it's a sentinel that requires a separate check. That said, since precompile_artifact_dir is only required when precompile=True, the empty-string default is reasonable. Just noting the tradeoff.

6. _make_precompile_callback type hint says str | None but the actual type is ConfigFingerprint (compile.py:93)

def _make_precompile_callback(
    ...
    config_fingerprint: str | None = None,

The precompile.py module defines ConfigFingerprint = NewType("ConfigFingerprint", str). The type hint here should be ConfigFingerprint | None for consistency with the precompile module.

Design Observations

  • Removal of auto-compile fallback: The previous code would compile-and-save if no artifact existed, then load on subsequent runs. This PR requires precompile_main to be run explicitly first. This is a cleaner separation of concerns (precompile step vs. training step), but does make the workflow more manual. The tradeoff seems reasonable given that CooR precompile is fundamentally a different code path (fake PG backend, single process) than multi-rank compilation.

  • Pickle security: The pickle.loads at precompile.py:163 has an appropriate safety comment noting that storage backends are assumed trusted. This is fine for the local-disk use case, but if shared-filesystem storage is used in multi-tenant environments, this could be a concern. The existing comment adequately documents this.

  • Thread safety: The lazy deserialization in precompile_load at precompile.py:222-223 has a comment noting it's "not thread-safe — assumes single-threaded forward calls." This is appropriate for the current use case.

Overall Assessment

The core CooR integration is solid — the approach of using a fake PG backend for single-process tracing, then loading rank-agnostic artifacts, is well-designed. The bitwise verification is convincing. The main concern is the integration tests that will fail due to the missing precompile pre-step mechanism, and the minor README inconsistency about auto-recompilation behavior.


…tic compilation"


Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

<img width="2383" height="887" alt="image" src="https://github.com/user-attachments/assets/27b9ac3d-2b51-4bba-948c-befdb35dd846" />

[ghstack-poisoned]
…t for rank-agnostic compilation"


Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

<img width="2383" height="887" alt="image" src="https://github.com/user-attachments/assets/27b9ac3d-2b51-4bba-948c-befdb35dd846" />

[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Mar 30, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 8234101
Pull-Request: #2713
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Mar 31, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 9930518
Pull-Request: #2713
--parallelism.tensor_parallel_degree 2

# Step 2: load and train with torchrun (uses all GPUs)
torchrun --nproc_per_node=8 --virtual-local-rank \

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.

Do you actually want --virtual-local-rank in the README here

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 worry if we don't it will be a footgun since our graphs aren't actually device normalized without it. We could consider maybe turning the flag on by default in the torchtitan trainer? cc @aorenste

--compile.joint_passes inductor_decomposition \
--compile.precompile_artifact_dir /tmp/precompile_artifacts \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2

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.

It is difficult to tell which of these flags are load bearing versus which ones can be dropped / changed.

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.

All of these flags are load bearing since they all feed into the config fingerprint.

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.

See #2713 (comment) for more details

@bobrenjc93
bobrenjc93 changed the base branch from gh/bobrenjc93/34/base to main April 2, 2026 15:56
--parallelism.tensor_parallel_degree 2

# Step 2: load and train with torchrun (uses all GPUs)
torchrun --nproc_per_node=8 --virtual-local-rank \

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.

what does this flag do? It's hard to tell from its pytorch docstring.

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.

It makes it so each rank sees cuda:0 by using CUDA_VISIBLE_DEVICES under the hood. We need this since torch.compile by default specializes on device id.

Comment thread tests/integration_tests/__init__.py Resolved
Comment thread run_train.sh Resolved
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Apr 3, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 7c23061
Pull-Request: #2713
@bobrenjc93
bobrenjc93 changed the base branch from main to gh/bobrenjc93/34/base April 3, 2026 01:03
bobrenjc93 added a commit that referenced this pull request Apr 3, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 7c23061
Pull-Request: #2713
@bobrenjc93
bobrenjc93 changed the base branch from gh/bobrenjc93/34/base to main April 3, 2026 01:05

@tianyu-l tianyu-l left a comment

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.

lgtm, may need to rebase before merge

[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Apr 3, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 506cd3e
Pull-Request: #2713
@bobrenjc93
bobrenjc93 changed the base branch from main to gh/bobrenjc93/34/base April 3, 2026 02:00
bobrenjc93 added a commit that referenced this pull request Apr 3, 2026
…tion

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

  20-step plot: https://pxl.cl/9c0Tv
  100-step plot: https://pxl.cl/9c2FN

ghstack-source-id: 506cd3e
Pull-Request: #2713
@bobrenjc93
bobrenjc93 changed the base branch from gh/bobrenjc93/34/base to main April 3, 2026 02:00
@bobrenjc93
bobrenjc93 merged commit fbdc4c9 into main Apr 3, 2026
17 of 25 checks passed
yiming0416 added a commit that referenced this pull request Apr 3, 2026
Update `test_precompile.py` to align with the API changes from #2713
(CooR precompile support), which removed the explicit key parameter from
`precompile_save` and `precompile_load`

``` 
pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py 
```
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
…tion (pytorch#2713)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* __->__ pytorch#2713

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

<img width="2383" height="887" alt="image"
src="https://github.com/user-attachments/assets/27b9ac3d-2b51-4bba-948c-befdb35dd846"
/>
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
Update `test_precompile.py` to align with the API changes from pytorch#2713
(CooR precompile support), which removed the explicit key parameter from
`precompile_save` and `precompile_load`

``` 
pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py 
```
jemitche1 pushed a commit to jemitche1/torchtitan that referenced this pull request Apr 14, 2026
…tion (pytorch#2713)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* __->__ pytorch#2713

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

<img width="2383" height="887" alt="image"
src="https://github.com/user-attachments/assets/27b9ac3d-2b51-4bba-948c-befdb35dd846"
/>
jemitche1 pushed a commit to jemitche1/torchtitan that referenced this pull request Apr 14, 2026
Update `test_precompile.py` to align with the API changes from pytorch#2713
(CooR precompile support), which removed the explicit key parameter from
`precompile_save` and `precompile_load`

``` 
pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py 
```
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
…tion (pytorch#2713)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* __->__ pytorch#2713

Adds single-process precompilation using compile-on-one-rank (CooR) to
generate rank-agnostic compiled artifacts. A single GPU traces through
distributed ops with a fake backend, producing an artifact loadable by
all ranks during torchrun training.

Key changes:
- precompile.py: Artifact serialization/loading with config fingerprint
  validation. DeviceMesh objects flow as opaque graph inputs (via
  DTensor.__tensor_flatten__ -> OpaqueObjectState), so no post-load
  patching or PG aliasing is needed.
- precompile_main.py: Single-process entry point using fake PG backend
- graph_utils.py: Enable CooR in export_joint() when precompile is on,
  so PG names are opaque graph inputs (not hardcoded string constants)
- compile.py: Precompile save/load integration with AOT compilation
- passes.py: Fix inductor_decomposition_pass for CooR opaque inputs

Verification (Llama3-8B, MAST, 2 nodes / 16 GPUs):
  Model: graph_trainer_llama3_8b
  Parallelism: TP=8, SimpleFSDP=2
  Compile: AOT, full_inductor_compilation + inductor_decomposition
  Training: 100 steps, local_batch_size=1, seq_len=2048
  Determinism: --debug.seed=42 --debug.deterministic

  CooR precompile (1 node, 1 GPU, fake PG backend)
    -> train (2 nodes, 16 GPUs) vs baseline (no precompile)
  Result: bitwise identical loss and grad_norm for all 100 steps

<img width="2383" height="887" alt="image"
src="https://github.com/user-attachments/assets/27b9ac3d-2b51-4bba-948c-befdb35dd846"
/>
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
Update `test_precompile.py` to align with the API changes from pytorch#2713
(CooR precompile support), which removed the explicit key parameter from
`precompile_save` and `precompile_load`

``` 
pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py 
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

6 participants