Instructions to use ZibinDong/ActionCodec2-2nd-order with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ZibinDong/ActionCodec2-2nd-order with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ZibinDong/ActionCodec2-2nd-order", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download runtime/routing/cache.py from ZibinDong/ActionCodec2-2nd-order: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/ZibinDong/ActionCodec2-2nd-order/resolve/main/runtime/routing/cache.py
- Command line
-
hf download hf://ZibinDong/ActionCodec2-2nd-order/runtime/routing/cache.py
-
curl -L -o cache.py https://huggingface.co/ZibinDong/ActionCodec2-2nd-order/resolve/main/runtime/routing/cache.py
1.3 kB
| """Small per-instance LRU caches; no global references to fitted codecs.""" | |
| from collections import OrderedDict | |
| from collections.abc import MutableMapping | |
| from threading import RLock | |
| class BoundedCache(MutableMapping): | |
| """Evict least-recently-used entries above a fixed capacity. | |
| Args: | |
| capacity: Maximum retained entries (positive integer). | |
| """ | |
| def __init__(self, capacity): | |
| if type(capacity) is not int or capacity < 1: | |
| raise ValueError("cache capacity must be a positive integer") | |
| self.capacity = capacity | |
| self._items = OrderedDict() | |
| self._lock = RLock() | |
| def __getitem__(self, key): | |
| with self._lock: | |
| value = self._items[key] | |
| self._items.move_to_end(key) | |
| return value | |
| def __setitem__(self, key, value): | |
| with self._lock: | |
| self._items[key] = value | |
| self._items.move_to_end(key) | |
| while len(self._items) > self.capacity: | |
| self._items.popitem(last=False) | |
| def __delitem__(self, key): | |
| with self._lock: | |
| del self._items[key] | |
| def __iter__(self): | |
| with self._lock: | |
| return iter(tuple(self._items)) | |
| def __len__(self): | |
| with self._lock: | |
| return len(self._items) | |