Skip to content

Test RegionAC context-parallel boundaries - #4614

Merged
anijain2305 merged 34 commits into
mainfrom
gh/anijain2305/18/head
Sep 15, 2026
Merged

anijain2305 merged 34 commits into
mainfrom
gh/anijain2305/18/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

self.inner_attention is already a RegionAC region. Add a real two-rank test for KV-all-gather and Ulysses under TorchTitan's single-threaded autograd execution, verifying that saved regions do not replay communication.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305 anijain2305 changed the title [DONT REVIEW YET] Validate RegionAC context-parallel boundaries Validate RegionAC context-parallel boundaries Sep 13, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305 anijain2305 changed the title Validate RegionAC context-parallel boundaries Test RegionAC context-parallel boundaries Sep 14, 2026
[ghstack-poisoned]
@anijain2305 anijain2305 changed the title Test RegionAC context-parallel boundaries Preserve SPMD mesh during RegionAC replay Sep 14, 2026
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305
anijain2305 marked this pull request as ready for review September 14, 2026 05:30
region_name=checkpoint_region_name,
determinism_check=config.determinism_check,
preserve_rng_state=False,
recompute_state_hooks=(_SpmdMeshRecomputeStateHook(),),

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.

@anijain2305
anijain2305 marked this pull request as draft September 14, 2026 05:36

active_context = set_current_spmd_mesh(mesh)
active_context.__enter__()
self._thread_state.active_context = active_context

@pianpwk pianpwk Sep 14, 2026 •

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.

I thought it was enough to put the mesh context over BWD

with self.train_context():
pred = self.model_parts[0](inputs, **extra_kwargs)
loss_kwargs = {}
if "positions" in extra_kwargs:
loss_kwargs["positions"] = extra_kwargs["positions"]
loss, _ = self.loss_fn(
pred,
labels, # pyrefly: ignore[bad-argument-type]
global_valid_tokens,
**loss_kwargs,
)
del pred
with spmd.no_typecheck():
# this propagates types through BWD, causing unnecessary conflicts
# between torch_function and internals (e.g. AC). FWD is sufficient.
loss.backward()
, and disable autograd multithreading
# disable autograd multithreading, to enable TLS DeviceMesh stack for spmd_types backend.
# this is needed for AC functionality; multi-threaded autograd means BWD threads performing recompute,
# cannot access PGs, e.g. current_spmd_mesh().get_group("tp") to perform the collectives they need.
torch.autograd.set_multithreading_enabled(False)
, is this not the case ?

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.

You are right. The test I wrote did not mirror the set_multithreading_enabled(False) variant. I was trying to solve a non-existent problem.

I will just update the test.

[ghstack-poisoned]
@anijain2305 anijain2305 changed the title Preserve SPMD mesh during RegionAC replay Test RegionAC context-parallel boundaries Sep 14, 2026
@anijain2305
anijain2305 marked this pull request as ready for review September 14, 2026 17:24
@anijain2305
anijain2305 requested a review from pianpwk September 14, 2026 17:24
@anijain2305
anijain2305 changed the base branch from gh/anijain2305/18/base to main September 15, 2026 16:30
@anijain2305
anijain2305 merged commit 4fe0139 into main Sep 15, 2026
9 checks passed
anijain2305 added a commit that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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