Skip to content

Instantly share code, notes, and snippets.

@daskol
Created August 12, 2021 14:26
Show Gist options
  • Save daskol/4d4004af302f6e2234fc7a76da6fde40 to your computer and use it in GitHub Desktop.
Save daskol/4d4004af302f6e2234fc7a76da6fde40 to your computer and use it in GitHub Desktop.
Free JAX/XLA buffers of size exceeded threshold
import jax
def collect(threshold=256 * 1024 ** 2):
backend = jax.lib.xla_bridge.get_backend()
freed = 0
for buf in backend.live_buffers():
if buf.nbytes >= threshold:
buf += buf.nbytes
buf.delete()
return freed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment