Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compilation cache tests #21982

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Conversation

ayaka14732
Copy link
Member

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 class CacheInterface. This instance can be either GFileCache or the new LRUCache added in #21394.

There are three levels of abstraction involved:

  1. Compilation cache operations
  2. The CacheInterface abstract class
  3. Implementations of the CacheInterface abstract class

The 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() and clear_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.

tests/compilation_cache_test.py Outdated Show resolved Hide resolved
@google-ml-butler google-ml-butler bot added kokoro:force-run pull ready Ready for copybara import and testing labels Jun 26, 2024
@hawkinsp
Copy link
Member

Please squash your commits.

@copybara-service copybara-service bot merged commit 81fcc97 into google:main Jul 2, 2024
14 checks passed
@ayaka14732 ayaka14732 deleted the main branch July 2, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull ready Ready for copybara import and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants