Skip to content

[CI] Cache torch.compile artifacts for the pytorch unit tests - #2170

Merged
felixdittrich92 merged 1 commit into
mindee:mainfrom
quotentiroler:ci/cache-torchinductor
Oct 16, 2026
Merged

felixdittrich92 merged 1 commit into
mindee:mainfrom
quotentiroler:ci/cache-torchinductor

Conversation

@quotentiroler

Copy link
Copy Markdown
Contributor

The pytorch test job compiles 23 models with torch.compile and starts every run with an empty TorchInductor cache. So each graph goes through Inductor lowering, C++ codegen and a gcc build again. On CPU this is the largest part of the job: test_torch_compiled_models[tablecenternet] alone takes over 10 minutes cold.

This adds an opt-in cache-compile input to the setup-env action. It points TORCHINDUCTOR_CACHE_DIR at ~/.cache/torchinductor and persists it with actions/cache. Only pytest-torch enables it.

The key includes the runner image, the Python and torch versions, the vector ISA Inductor generates code for, and a hash of doctr/**/*.py. A prefix restore-key lets a commit reuse the previous entries. Inductor looks entries up by the traced graph, the torch build and its config, so models a change does not touch are reused and changed ones are compiled again.

Measured in a Linux container (python:3.11, 4 CPUs, torch 2.14.1+cpu) with the CI command:

  • 23 compile tests: 2315s with an empty cache, 535s with a restored cache. The cache is 96 MB.
  • tablecenternet compile test: 665s to 52s.
  • Full suite with the cache restored into a fresh container: same 452 test ids, same outcomes (447 passed, 5 skipped), same coverage totals (8711/10741 lines).

The tests and assertions are unchanged. The first run on main fills the cache.

Prepared with Claude Code; I reviewed and tested the change.

The pytorch test job compiles 23 models with torch.compile, and every run
starts from an empty TorchInductor cache, so each graph goes through the
full Inductor lowering, C++ codegen and gcc build again. On CPU this is
the largest block of the job: the tablecenternet compile test alone
takes over 10 minutes cold.

setup-env gets an opt-in cache-compile input that points
TORCHINDUCTOR_CACHE_DIR at ~/.cache/torchinductor and persists it with
actions/cache. Only pytest-torch enables it. The key carries the runner
image, Python version, torch version and the vector ISA Inductor picks
for code generation, plus a hash of doctr/**/*.py. A prefix restore-key
lets a run reuse the entries of a previous commit: Inductor looks entries
up by the traced graph, torch build and its config, so graphs a change
does not touch are reused and changed ones are compiled again.

Measured in a Linux container (python:3.11, 4 CPUs, torch 2.14.1+cpu),
with the CI command (pytest tests/pytorch/ -rs --cov):
- the 23 compile tests: 2315s with an empty cache, 535s with a cache
  restored from a previous run (-77%); the cache is 96 MB
- tablecenternet compile test: 665s -> 52s
- full suite with the cache restored into a fresh container: same 452
  test ids, same outcomes (447 passed, 5 skipped) and same coverage
  totals (8711/10741 lines) as the cold baseline run
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.61%. Comparing base (7b91803) to head (b106c46).

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2170       +/-   ##
=========================================
+ Coverage      0   97.61%   +97.61%     
=========================================
  Files         0      170      +170     
  Lines         0    10740    +10740     
=========================================
+ Hits          0    10484    +10484     
- Misses        0      256      +256     
Flag Coverage Δ
unittests 97.61% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 self-assigned this Oct 16, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Oct 16, 2026
@felixdittrich92 felixdittrich92 added type: enhancement Improvement topic: ci Related to CI labels Oct 16, 2026

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @quotentiroler 👍

@felixdittrich92
felixdittrich92 merged commit a2efb6e into mindee:main Oct 16, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: ci Related to CI type: enhancement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants