Skip to content

Disable dynamo LRU cache when AC is enabled - #2204

Merged
fegin merged 1 commit into
mainfrom
disable-lru-when-ac
Jan 14, 2026
Merged

fegin merged 1 commit into
mainfrom
disable-lru-when-ac

Conversation

@soulitzer

@soulitzer soulitzer commented Jan 6, 2026 •

Copy link
Copy Markdown
Contributor

Previously this config is flipped whenever compile is enabled. This PR updates it so that the config is flipped whenever AC is applied, so that the only flex compiled case is also covered.

Code comment:

# Disable dynamo LRU cache to workaround an interaction between SAC, PP, and Flex:
#
# When forward runs with a second PP microbatch, it triggers recompilation with dynamic
# shapes enabled. Now there are two valid compiled graphs. By default, dynamo selects
# the latest one (the dynamic shapes version), so the runtime wrapper expects an extra
# symint output. When SAC caches the inductor HOP output from the static graph for
# batch_idx=0, it would miss that symint and cause an assertion failure. The workaround
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: https://github.com/pytorch/pytorch/issues/166926

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 6, 2026
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: https://github.com/pytorch/pytorch/issues/166926
torch._C._dynamo.eval_frame._set_lru_cache(False)

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's the downside of always setting this to False?

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.

hmm from the original issue pytorch/pytorch#166926 it is mentioned that it would increase cache look up time, but I don't understand the details completely
maybe @williamwen42 @xmfan have more context

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.

When there's recompiles, there are many valid graphs for one compiled function. Each time the function is called, dynamo needs to evaluate each graph's guards in order. If you evaluate them in LRU order, you might be more likely to get an early cache hit.

@xmfan xmfan Jan 6, 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.

In the original report, this issue affected MoEs only (as dense was static shaped). In the FlexAttention case, would it also only for MoE? If so, you probably want a centralized apply_ac function inside of torchtitan similar to apply_compile to group MoE logic.

Alternatively, we can consider making flex's compile explicit in the config system: compile.components

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.

Not sure it is MoEs only, the dynamism is coming from mask_mod closing over the PP batch idx so it should happen whenever we are using PP and Flex? pytorch/pytorch#164111

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.

Sounds like it doesn't only affect DSv3, so you'll need to add it to the other models

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.

TorchTitan already has a centralized apply_ac.

@xmfan

xmfan commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Why does the setting need to be applied when compiled is not turned on?

If compiled is enabled, then it should be covered by: https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/llama4/infra/parallelize.py#L597

@fegin

fegin commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

@xmfan Compile is not turned one. But FlexAttention is already compiled regardless the compile flag.

@soulitzer
soulitzer force-pushed the disable-lru-when-ac branch from 70c5157 to e2f2420 Compare January 14, 2026 16:47
@soulitzer soulitzer changed the title Disable dynamo LRU cache when AC is enabled for DSV3 Disable dynamo LRU cache when AC is enabled Jan 14, 2026
@soulitzer
soulitzer requested review from fegin and xmfan January 14, 2026 16:52
@fegin
fegin merged commit c26ea60 into main Jan 14, 2026
@fegin
fegin deleted the disable-lru-when-ac branch January 14, 2026 23:32
wwwjn pushed a commit to wwwjn/torchtitan that referenced this pull request Jan 15, 2026
Previously this config is flipped whenever compile is enabled. This PR
updates it so that the config is flipped whenever AC is applied, so that
the only flex compiled case is also covered.

Code comment:
```
# Disable dynamo LRU cache to workaround an interaction between SAC, PP, and Flex:
#
# When forward runs with a second PP microbatch, it triggers recompilation with dynamic
# shapes enabled. Now there are two valid compiled graphs. By default, dynamo selects
# the latest one (the dynamic shapes version), so the runtime wrapper expects an extra
# symint output. When SAC caches the inductor HOP output from the static graph for
# batch_idx=0, it would miss that symint and cause an assertion failure. The workaround
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: pytorch/pytorch#166926
```
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
Previously this config is flipped whenever compile is enabled. This PR
updates it so that the config is flipped whenever AC is applied, so that
the only flex compiled case is also covered.

Code comment:
```
# Disable dynamo LRU cache to workaround an interaction between SAC, PP, and Flex:
#
# When forward runs with a second PP microbatch, it triggers recompilation with dynamic
# shapes enabled. Now there are two valid compiled graphs. By default, dynamo selects
# the latest one (the dynamic shapes version), so the runtime wrapper expects an extra
# symint output. When SAC caches the inductor HOP output from the static graph for
# batch_idx=0, it would miss that symint and cause an assertion failure. The workaround
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: pytorch/pytorch#166926
```
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
Previously this config is flipped whenever compile is enabled. This PR
updates it so that the config is flipped whenever AC is applied, so that
the only flex compiled case is also covered.

Code comment:
```
# Disable dynamo LRU cache to workaround an interaction between SAC, PP, and Flex:
#
# When forward runs with a second PP microbatch, it triggers recompilation with dynamic
# shapes enabled. Now there are two valid compiled graphs. By default, dynamo selects
# the latest one (the dynamic shapes version), so the runtime wrapper expects an extra
# symint output. When SAC caches the inductor HOP output from the static graph for
# batch_idx=0, it would miss that symint and cause an assertion failure. The workaround
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: pytorch/pytorch#166926
```
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
Previously this config is flipped whenever compile is enabled. This PR
updates it so that the config is flipped whenever AC is applied, so that
the only flex compiled case is also covered.

Code comment:
```
# Disable dynamo LRU cache to workaround an interaction between SAC, PP, and Flex:
#
# When forward runs with a second PP microbatch, it triggers recompilation with dynamic
# shapes enabled. Now there are two valid compiled graphs. By default, dynamo selects
# the latest one (the dynamic shapes version), so the runtime wrapper expects an extra
# symint output. When SAC caches the inductor HOP output from the static graph for
# batch_idx=0, it would miss that symint and cause an assertion failure. The workaround
# here is to disable the LRU cache, and select graphs in insertion order instead.
#
# Also see: pytorch/pytorch#166926
```
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. high priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants