Skip to content

Fix torch.compile _tree_map recompilations - #30

Merged
mctigger merged 6 commits into
mainfrom
recompiles
Feb 26, 2026
Merged

Fix torch.compile _tree_map recompilations#30
mctigger merged 6 commits into
mainfrom
recompiles

Conversation

@mctigger

Copy link
Copy Markdown
Owner

Summary

This PR includes the commits on recompiles that are not yet in origin/main, focused on resolving Dynamo recompilation behavior around _tree_map and finalizing release metadata.

  • Adds compile-mode fast paths that bypass _tree_map and use pytree.tree_map directly in affected TensorContainer operations, preventing callable-identity guard churn.
  • Retains eager-mode _tree_map behavior so existing error wrapping and diagnostics remain available outside compiled regions.
  • Adds regression coverage for frame-guard/recompilation behavior, including a repro script and compile-specific tests.
  • Expands and refines the investigation document in docs/compile-recompilation-investigation.md with root cause analysis, alternatives considered, and rationale for the selected fix.
  • Bumps project version to 0.9.0 and fixes invalid pyproject.toml author metadata.

Why

Real workloads were hitting torch._dynamo recompile limits due to _tree_map being compiled as a separate frame with changing callable identities. The compile-path bypass removes this failure mode while preserving eager-path diagnostics and keeping behavior stable.

Validation

  • Added/updated tests covering:
    • _tree_map bypass behavior under torch.compile
    • frame-guard/recompile-limit repro scenarios
    • compile/eager behavioral consistency for updated call sites

Tim Joseph added 6 commits February 25, 2026 22:34
Add a compile-time fast path to avoid error-wrapping overhead
and document expected torch.compile behavior with new tests.
Add a detailed investigation write-up for _tree_map
recompilation and a test script that exercises frame
guard behavior across compiled scenarios.
Add is_compiling fast paths to call pytree.tree_map directly and
avoid Dynamo recompile limits, plus tests and docs to verify behavior.
document why `_tree_map_fn()` and `substitute_in_graph` approaches do
not prevent recompiles in real workloads, even when unit tests pass.

clarify the proven fix as a two-layer defense: per-method
`is_compiling()` fast paths as the primary solution, plus module-level
`_tree_map_impl` polyfill support as structural backup.

update the investigation matrix and test strategy section to reflect the
new failure modes and current validation approach.
add author metadata entry in project configuration
Delete the malformed `author` entry in `pyproject.toml` to keep
project metadata valid for packaging tools.

Also reformat long compile-related call sites in shape operations and
test files for readability, with no intended behavior changes.
@mctigger
mctigger merged commit 0e71ba4 into main Feb 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant