Add JAX compilation cache clear fixture to prevent XLA memory accumulation - #4784
Add JAX compilation cache clear fixture to prevent XLA memory accumulation#4784SurbhiJainUSC wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a global autouse pytest fixture in tests/conftest.py to clear JAX compilation caches and force garbage collection, while removing redundant manual cache clearing and garbage collection calls from individual integration tests. The feedback points out that running this cleanup before and after every single test (including CPU-only tests) will severely degrade test suite performance due to constant recompilation. It is recommended to restrict this cleanup to run only after tests, and only when executing on TPU or GPU accelerators.
1071ff9 to
8f9920f
Compare
|
🤖 Hi @SurbhiJainUSC, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This pull request introduces an autouse pytest fixture (clear_jax_compilation_cache) to automatically clear JAX compilation caches and force garbage collection after each test on hardware accelerators (TPU, GPU, and proxy platforms). The objective is to prevent memory accumulation and fragmentation in CI/CD environments, and the overall quality and cleanliness of the implementation is excellent.
🔍 General Feedback
- Simplifies Test Codebase: Removing manual
jax.clear_caches()andgc.collect()calls from individual test files (likeestimator_test.pyanddeepseek_scan_engram_test.py) significantly reduces boilerplate and improves maintenance. - Accelerator-Scoped Cleanups: Correctly restricts the automatic cache clearing to hardware accelerator environments, ensuring CPU-only tests or local CPU runs are unaffected.
- Compilation/Performance Overhead: Note that clearing JAX caches after every test can lead to increased compilation times if multiple test cases within the same session or module compile identical functions. However, this is a very reasonable trade-off for CI stability and memory reliability in resource-constrained TPU/Pathways environments.
8f9920f to
5680ab3
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
300ab0a to
da0e7aa
Compare
da0e7aa to
f5b9c10
Compare
Description
This PR an autouse pytest fixture (
clear_jax_compilation_cache) intests/conftest.pythat invokesjax.clear_caches()andgc.collect()after every test module execution to prevent XLA memory accumulation.Key benefits:
jax.clear_caches()andgc.collect()calls intests/integration/estimator_test.pyandtests/integration/deepseek_scan_engram_test.py.Tests
CI tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.