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

Don't write atime file if JAX_COMPILATION_CACHE_MAX_SIZE == -1 #26529

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ When releasing, please add the new-release-boilerplate to docs/pallas/CHANGELOG.
JAX-level dead code elimination (DCE). See {jax-issue}`#25956` for more
details.
* Added low-level reduction APIs in {mod}`jax.lax`: {func}`jax.lax.reduce_sum`,
{func}`jax.lax.reduce_prod`, {func}`jax.lax.reduce_max`, {func}`jax.lax.reduce_min`,
{func}`jax.lax.reduce_prod`, {func}`jax.lax.reduce_max`, {func}`jax.lax.reduce_min`,
{func}`jax.lax.reduce_and`, {func}`jax.lax.reduce_or`, and {func}`jax.lax.reduce_xor`.
* {func}`jax.lax.linalg.qr`, and {func}`jax.scipy.linalg.qr`, now support
column-pivoting on CPU and GPU. See {jax-issue}`#20282` and
Expand All @@ -46,6 +46,12 @@ When releasing, please add the new-release-boilerplate to docs/pallas/CHANGELOG.
info. This change does not affect public APIs.
See https://github.com/jax-ml/jax/issues/26480 for more detail.

* Bug fixes
* Persistent compilation cache no longer writes access time file if
JAX_COMPILATION_CACHE_MAX_SIZE is unset or set to -1, i.e. if the LRU
eviction policy isn't enabled. This should improve performance when using
the cache with large-scale network storage.

## jax 0.5.0 (Jan 17, 2025)

As of this release, JAX now uses
Expand Down
14 changes: 8 additions & 6 deletions jax/_src/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def get(self, key: str) -> bytes | None:
raise ValueError("key cannot be empty")

cache_path = self.path / f"{key}{_CACHE_SUFFIX}"
atime_path = self.path / f"{key}{_ATIME_SUFFIX}"
jakevdp marked this conversation as resolved.
Show resolved Hide resolved

if self.eviction_enabled:
self.lock.acquire(timeout=self.lock_timeout_secs)
Expand All @@ -108,8 +107,10 @@ def get(self, key: str) -> bytes | None:

val = cache_path.read_bytes()

timestamp = time.time_ns().to_bytes(8, "little")
atime_path.write_bytes(timestamp)
if self.eviction_enabled:
timestamp = time.time_ns().to_bytes(8, "little")
atime_path = self.path / f"{key}{_ATIME_SUFFIX}"
atime_path.write_bytes(timestamp)

return val

Expand Down Expand Up @@ -138,7 +139,6 @@ def put(self, key: str, val: bytes) -> None:
return

cache_path = self.path / f"{key}{_CACHE_SUFFIX}"
atime_path = self.path / f"{key}{_ATIME_SUFFIX}"

if self.eviction_enabled:
self.lock.acquire(timeout=self.lock_timeout_secs)
Expand All @@ -151,8 +151,10 @@ def put(self, key: str, val: bytes) -> None:

cache_path.write_bytes(val)

timestamp = time.time_ns().to_bytes(8, "little")
atime_path.write_bytes(timestamp)
if self.eviction_enabled:
timestamp = time.time_ns().to_bytes(8, "little")
atime_path = self.path / f"{key}{_ATIME_SUFFIX}"
atime_path.write_bytes(timestamp)

finally:
if self.eviction_enabled:
Expand Down
14 changes: 13 additions & 1 deletion tests/lru_cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from absl.testing import absltest

from jax._src import path as pathlib
from jax._src.lru_cache import _CACHE_SUFFIX, LRUCache
from jax._src.lru_cache import _ATIME_SUFFIX, _CACHE_SUFFIX, LRUCache
import jax._src.test_util as jtu


Expand Down Expand Up @@ -153,6 +153,18 @@ def test_max_size(self):
self.assertIsNone(cache.get("a"))
self.assertEqual(set(self.path.glob(f"*{_CACHE_SUFFIX}")), set())

# Check that we don't write access time file when the eviction policy is
# disabled. Writing this file can be extremely unperformant and cause
# problems on large-scale network storage.
def test_no_atime_file(self):
cache = LRUCache(self.name, max_size=-1)

cache.put("a", b"a")
self.assertEmpty(list(self.path.glob(f"*{_ATIME_SUFFIX}")))

cache.get("a")
self.assertEmpty(list(self.path.glob(f"*{_ATIME_SUFFIX}")))


if __name__ == "__main__":
absltest.main(testLoader=jtu.JaxTestLoader())
Loading