sci-run / tasks /surface-code-decoding /surface-code-decoding-astra-xhigh-1h100-48h-20261020b /finalization /submission /conditional_edge_compiled.py
Download tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_compiled.py from s42chen/sci-run: direct link, hf CLI and curl.
- Browser
- Download file 963 Bytes
-
https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_compiled.py
- Command line
-
hf download hf://datasets/s42chen/sci-run/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_compiled.py
-
curl -L -o conditional_edge_compiled.py https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/finalization/submission/conditional_edge_compiled.py
963 Bytes
| """Retain bounded compiled attention executables across global JAX cache clears.""" | |
| from collections import OrderedDict | |
| import jax | |
| class PersistentCompiled: | |
| def __init__(self,function,max_executables=2): | |
| self.function=jax.jit(function);self.executables=OrderedDict();self.max_executables=max_executables;self.compilations=0 | |
| def __call__(self,*args): | |
| leaves,tree=jax.tree_util.tree_flatten(args) | |
| signatures=[] | |
| for value in leaves: | |
| abstract=jax.core.get_aval(value) | |
| signatures.append((abstract.shape,str(abstract.dtype),bool(abstract.weak_type))) | |
| key=(tree,tuple(signatures)) | |
| if key not in self.executables: | |
| self.executables[key]=self.function.lower(*args).compile();self.compilations+=1 | |
| while len(self.executables)>self.max_executables:self.executables.popitem(last=False) | |
| self.executables.move_to_end(key) | |
| return self.executables[key](*args) | |