File size: 4,357 Bytes
1e01143 f2300f5 1e01143 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 67dc523 f2300f5 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | ---
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.
|