Code2Act / README.md
Kaiwen107's picture
Model card: paper title, links, descriptive folder names
67dc523 verified
|
Raw History Blame Contribute Delete
4.36 kB
---
license: bsd-3-clause
tags:
- reinforcement-learning
- motor-control
- mujoco
- jax
---
# Discrete Actions for Naturalistic Behavior in Embodied Biomechanical Animal Models
Pretrained models for **Code2Act**, a controller that executes an externally
defined discrete behavioral vocabulary on a biomechanical rat in MuJoCo.
NeurIPS 2026 Workshop on Neuro-Symbolic Embodied Intelligence (NEmo), oral.
[Paper](https://openreview.net/forum?id=FBEAYXac4j) ·
[Project page](https://kbian.org/Code2Act-website/) ·
[Code](https://github.com/talmolab/code2act)
The pipeline has three stages:
1. **Stage 1** — MIMIC-MJX imitation VAE (encoder → 16-d intention, decoder → torques).
2. **Stage 2** — a frozen discrete vocabulary, one code per frame (`best_codes.npz`).
3. **Stage 3** — a GRU controller trained with PPO plus a distillation KL to the
frozen Stage-1 encoder.
## Layout
```
controllers/ Stage-3 controllers, one folder per vocabulary
stage1_mimic/ Stage-1 imitation VAEs
vocabularies/ Stage-2 code sequences and the tokenizers that produced them
code_priors/ Autoregressive priors over code sequences (GPT-2, Mamba, S5, HMM)
```
## Controllers
| Folder | Vocabulary | K | Step | Training run |
|---|---|---|---|---|
| `controllers/kpms_k100/` | Keypoint-MoSeq syllables | 100 | 249 | `260611_073323_750085` |
| `controllers/kvae_k25/` | Kinematics VAE + K-means | 25 | 249 | `260603_180852_140475` |
| `controllers/mlb_k9/` | Manually labeled behavior × direction | 9 | 208 | `260629_212713_669229` |
| `controllers/mlb_k9_end_of_training/` | same run, last step | 9 | 499 | `260629_212713_669229` |
The MLB results in the paper use **step 208** (`controllers/mlb_k9/`).
Each folder holds one Orbax step (`MoSeqPPONetwork_<step>/` with `config/`,
`policy/`, `train_state/`).
## Stage-1 checkpoints
| Folder | Role | Step | Training run |
|---|---|---|---|
| `stage1_mimic/distillation_target/` | Distillation target and decoder initialization for all three controllers | 99 | `260413_040706_764936` |
| `stage1_mimic/expert_reference/` | "Expert MIMIC-MJX" reference in the KID and gait comparisons | 47 | `260405_235031_234849` |
## Vocabularies
| Folder | Codes | Tokenizer |
|---|---|---|
| `vocabularies/kpms_k100/` | `best_codes.npz` | AR-HMM fit in `keypoint_arhmm_states100_seed4/`; `sweep_results.json` ranks the full sweep |
| `vocabularies/kvae/` | `vae_sweep/kl_0p001/tokenize_k25/best_codes.npz` (K=25, used in the paper) | VAE checkpoints and K-means tokenizers for the full KL × K sweep |
| `vocabularies/mlb_k9/` | `best_codes.npz` | hand-specified segmenter (see the code repository) |
| `vocabularies/other/` | designed, heading-aligned KPMS, round-trip and earlier vocabularies | — |
## Code priors
Each folder has `params.msgpack`, `meta.json`, its Hydra config and training log.
| Vocabulary | GPT-2 | Mamba |
|---|---|---|
| KPMS K=100 | `code_priors/kpms_k100/gpt2/` | `code_priors/kpms_k100/mamba/` |
| KVAE K=25 | `code_priors/kvae_k25/gpt2/` | `code_priors/kvae_k25/mamba/` |
| MLB K=9 | `code_priors/mlb_k9/gpt2/` | `code_priors/mlb_k9/mamba/` |
`code_priors/other/<architecture>/<run>/` holds the remaining runs (other
vocabularies, S5 and HMM priors); `meta.json` in each records its `code_source`
and `num_codes`.
## Loading
```python
from huggingface_hub import snapshot_download
root = snapshot_download("Kaiwen107/Code2Act")
```
```python
from c2a.experiments.shared.checkpoint_utils import load_moseq_checkpoint
cfg, normalizer_state, policy_params, ppo_networks = load_moseq_checkpoint(
f"{root}/controllers/kpms_k100"
)
```
Notes:
- Restoring the Orbax checkpoints requires a GPU.
- The code repository's configs refer to checkpoints by training-run path
(`model_checkpoints/<run>`, `trained_mimic_ckpts/<run>`,
`outputs/tokenizer/...`, `outputs/ar_codegen/...`). Point those keys at the
folders above, using the "Training run" columns to match them.
- The `config/metadata` stored in each checkpoint records absolute paths from
the training machine. Override the code path with
`checkpoint.codes_path_override` when evaluating elsewhere.
- Code version: `code2act` at `e985c36`, `track-mjx` branch
`kevin/kpms-decoder` at `4d4331f`, `vnl-playground` v0.0.13.
- Reference clips and train/test splits are not part of this repository.