Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the tests for the compilation cache.
Background
The JAX compilation cache operates through a set of functions defined in
jax/_src/compilation_cache.py
. These functions implement the operations of the compilation cache. A global variable,_cache
, is defined in this file as an instance of the abstract classCacheInterface
. This instance can be eitherGFileCache
or the newLRUCache
added in #21394.There are three levels of abstraction involved:
CacheInterface
abstract classCacheInterface
abstract classThe Problem
The current
compilation_cache_test.py
file is intended to test the compilation cache operations but relies heavily on the implementation details of the underlying cache. For instance, it assumes that the number of files in the cache directory matches the number of items in the cache.Why is This a Problem?
With the intended introduction of the LRU cache eviction policy for the JAX compilation cache, we now require two separate files for each cache item: one for data and one for metadata. Consequently, the assumption that one cache item corresponds to one file in the cache directory is no longer valid.
The Solution
This PR addresses the problem by implementing two functions,
count_cache_items()
andclear_cache()
, at each level of abstraction. This ensures that the tests for the compilation cache do not depend on the specific implementation details of the underlying cache.