Repository navigation
Disable dynamo LRU cache when AC is enabled - #2204
Conversation
| # 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) |
There was a problem hiding this comment.
What's the downside of always setting this to False?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Sounds like it doesn't only affect DSv3, so you'll need to add it to the other models
There was a problem hiding this comment.
TorchTitan already has a centralized apply_ac.
|
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 |
|
@xmfan Compile is not turned one. But FlexAttention is already compiled regardless the compile flag. |
70c5157 to
e2f2420
Compare
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 ```
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 ```
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 ```
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 ```
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: