question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add mechanism to clear full compilation cache

See original GitHub issue

There is currently no way to clear the full compilation class in JAX — something like f._clear_cache(), but which applies to all JIT-ted functions that have been compiled so far. This would be useful in situations where multiple high-memory-usage tasks need to be done sequentially. See discussion in https://github.com/google/jax/discussions/10826

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
patrick-kidgercommented, May 26, 2022

Whilst we’re at it – JAX caches a lot of things (e.g. jaxprs) and I’ve found that this can also contribute to OOM on limited memory machines. (Such as GitHub Actions runners, for running tests.) Ways to clean these up would also be desirable.

FWIW my hugely hacky approach so far has been

def clear_caches():
    process = psutil.Process()
    if process.memory_info().vms > 4 * 2**30:  # >4GB memory usage
        for module_name, module in sys.modules.items():
            if module_name.startswith("jax"):
                for obj_name in dir(module):
                    obj = getattr(module, obj_name)
                    if hasattr(obj, "cache_clear"):
                        obj.cache_clear()
        gc.collect()

(which in the context of tests is wrapped in a @pytest.fixture(autouse=True).)

2reactions
simitiicommented, Oct 25, 2022

I think the need for manually cleaning the cache once in a while is not natural. It would be nice to have an internal garbage collector inside Jax that cleans the least recently used objects in the cache (depending on the memory usage by the cache at the time).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct Method of Flushing Caches & Managing the Compiler
This is the “safer” way to clear the cache, as it does not clear absolutely everything. If you are using any secondary cache...
Read more >
11.4 Cache time-consuming code chunks - Bookdown
One way to do it is to add another chunk option cache.extra = file.mtime('my-precious.csv') or more rigorously, cache.extra = tools::md5sum('my-precious.
Read more >
Cache clear option - Arduino IDE 2.0
I use a build_opt.h file in the sketch to set options in the processor core and or/library. The problem is that swapping between...
Read more >
Build Cache - Gradle User Manual
The Gradle build cache is a cache mechanism that aims to save time by reusing outputs produced by other builds. The build cache...
Read more >
20 Performing Basic Cache Operations - Oracle Help Center
Basic cache put operations are performed using the put method as defined by the Map interface. The put method adds an entry to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found