Instructions to use ZibinDong/ActionCodec2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ZibinDong/ActionCodec2 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ZibinDong/ActionCodec2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 2,769 Bytes
7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 7c09a0c 1bfc3f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | """Numerical primitive parameters stored in ``primitives.npz``."""
from __future__ import annotations
from collections.abc import Sequence
from pathlib import Path
import numpy as np
from .configuration import ConfigError
PRIMITIVES_NAME = "primitives.npz"
def _key(dimension: int) -> str:
return f"dimension_{dimension:04d}"
class PrimitiveStore:
"""Immutable numerical primitive axes in global action-dimension order."""
def __init__(self, values: Sequence[np.ndarray | Sequence[float]]) -> None:
if not values:
raise ConfigError("primitives must contain at least one dimension")
arrays = []
for dimension, raw in enumerate(values):
array = np.asarray(raw)
if array.dtype.hasobject:
raise ConfigError(f"primitive dimension {dimension} must not use object dtype")
if array.ndim != 1 or not len(array):
raise ConfigError(f"primitive dimension {dimension} must be a non-empty vector")
real_numeric = np.issubdtype(array.dtype, np.integer) or np.issubdtype(
array.dtype, np.floating
)
if not real_numeric or not np.all(np.isfinite(array)):
raise ConfigError(f"primitive dimension {dimension} must contain finite numbers")
arrays.append(np.array(array, copy=True))
self.values = tuple(arrays)
self.bins = tuple(len(array) for array in arrays)
@property
def dimension(self) -> int:
return len(self.values)
@classmethod
def from_pretrained(cls, directory: str | Path, *, input_dim: int) -> PrimitiveStore:
"""Load exactly one safe numeric vector per expected global dimension."""
path = Path(directory) / PRIMITIVES_NAME
with np.load(path, allow_pickle=False) as payload:
expected = {_key(index) for index in range(input_dim)}
actual = set(payload.files)
missing = sorted(expected - actual)
unknown = sorted(actual - expected)
if missing:
raise ConfigError(f"{PRIMITIVES_NAME} is missing array(s): {', '.join(missing)}")
if unknown:
raise ConfigError(
f"{PRIMITIVES_NAME} contains unknown array(s): {', '.join(unknown)}"
)
values = [payload[_key(index)] for index in range(input_dim)]
return cls(values)
def save_pretrained(self, directory: str | Path) -> None:
"""Write ``primitives.npz`` without pickled objects or path metadata."""
path = Path(directory) / PRIMITIVES_NAME
path.parent.mkdir(parents=True, exist_ok=True)
np.savez(path, **{_key(index): value for index, value in enumerate(self.values)})
|