Skip to main content

LocoFormer (wip)

LocoFormer - Generalist Locomotion via Long-Context Adaptation

The gist is they trained a simple Transformer-XL in simulation on robots with many different bodies (cross-embodiment) and extreme domain randomization. When transferring to the real-world, they noticed the robot now gains the ability to adapt to insults. The XL memories span across multiple trials, which allowed the robot to learn in-context adaptation.

Install

$ pip install locoformer

Usage

import torch
from locoformer.locoformer import Locoformer

# mock robot embodied with some state dimensions and action dimensions

locoformer = Locoformer(
    embedder = dict(
        dim = 512,
        dim_state = [32, 16], # support multiple bodies / robots
    ),
    unembedder = dict(
        num_continuous = 12 + 6,
        selectors = [
            list(range(12)),
            list(range(12, 12 + 6))
        ]
    ),
    transformer = dict(
        dim = 512,
        depth = 6,
        heads = 8,
        window_size = 32
    )
)

# mock state from one of the robots (0th one)

state = torch.randn(1, 1, 32)

# forward to get action logits

action_logits, _ = locoformer(
    state,
    state_embed_kwargs = dict(state_type = 'raw'),
    state_id_kwarg = dict(state_id = 0),
    action_select_kwargs = dict(selector_index = 0)
)

# sample action using the internal distribution

action = locoformer.unembedder.sample(action_logits, selector_index = 0) # (1, 1, 12)

Sim-to-Real Bipedal Locomotion (Microduck)

You can train an adaptive bipedal walking gait for the Microduck biped robot from scratch using Locoformer and PPO

An emergent bipedal walking gait starts emerging before 2M steps

$ uv run train_microduck.py

To render periodic evaluation videos or resume from the saved best checkpoint:

# render periodic evaluation videos to videos/
$ uv run train_microduck.py --eval_video True --eval_every 20

# resume training from best checkpoint
$ uv run train_microduck.py --resume True

Special thanks to Pollen Robotics 🤗 for their open sourcing of this sim2real env!

Sponsors

This open sourced work is sponsored by Safe Sentinel

Citations

@article{liu2025locoformer,
    title   = {LocoFormer: Generalist Locomotion via Long-Context Adaptation},
    author  = {Liu, Min and Pathak, Deepak and Agarwal, Ananye},
    journal = {Conference on Robot Learning ({CoRL})},
    year    = {2025}
}
@inproceedings{anonymous2025flow,
    title   = {Flow Policy Gradients for Legged Robots},
    author  = {Anonymous},
    booktitle = {Submitted to The Fourteenth International Conference on Learning Representations},
    year    = {2025},
    url     = {https://openreview.net/forum?id=BA6n0nmagi},
    note    = {under review}
}
@misc{ashlag2025stateentropyregularizationrobust,
    title   = {State Entropy Regularization for Robust Reinforcement Learning},
    author  = {Yonatan Ashlag and Uri Koren and Mirco Mutti and Esther Derman and Pierre-Luc Bacon and Shie Mannor},
    year    = {2025},
    eprint  = {2506.07085},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2506.07085},
}
@misc{osband2026delightfulpolicygradient,
    title   = {Delightful Policy Gradient},
    author  = {Ian Osband},
    year    = {2026},
    eprint  = {2603.14608},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2603.14608},
}
@misc{schwarzer2021dataefficientreinforcementlearningselfpredictive,
    title   = {Data-Efficient Reinforcement Learning with Self-Predictive Representations},
    author  = {Max Schwarzer and Ankesh Anand and Rishab Goel and R Devon Hjelm and Aaron Courville and Philip Bachman},
    year    = {2021},
    eprint  = {2007.05929},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2007.05929},
}
@misc{teoh2026nextlatentpredictiontransformerslearn,
    title   = {Next-Latent Prediction Transformers Learn Compact World Models},
    author  = {Jayden Teoh and Manan Tomar and Kwangjun Ahn and Edward S. Hu and Tim Pearce and Pratyusha Sharma and Akshay Krishnamurthy and Riashat Islam and Alex Lamb and John Langford},
    year    = {2026},
    eprint  = {2511.05963},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2511.05963},
}

Metadata

Release files for locoformer 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for locoformer 0.3.3
File Size Uploaded Provenance Actions
locoformer-0.3.3.tar.gz 28.4 kB Without provenance Details for locoformer-0.3.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for locoformer 0.3.3
File Interpreter ABI Platform Actions
locoformer-0.3.3-py3-none-any.whl Python 3 none any Details for locoformer-0.3.3-py3-none-any.whl

Total release size: 56.0 kB

Release files / locoformer-0.3.3.tar.gz

Download URL locoformer-0.3.3.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
900148a494b14b7dde80144df00412876b0bd2fd866ab08ece5a887c71fd50aa
BLAKE2b-256 checksum
How to use checksums
ec37e77b13f8397aa46434f851b9a3a6eaba635895b5cb9bbabc6d0ecff25ebc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / locoformer-0.3.3-py3-none-any.whl

Download URL locoformer-0.3.3-py3-none-any.whl
Size 27.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
381a7a4e7354d3e8865936251985649b89fdec41039d479c975a7c6e30c25cda
BLAKE2b-256 checksum
How to use checksums
53b29241b2d605cfb8daed198a47b8343b3307349f5d6e696b090f61abde8e4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Security for locoformer 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page