Skip to content

[Feature] Add ACTModel and ACTLoss for robot learning#3639

Open
theap06 wants to merge 2 commits intopytorch:mainfrom
theap06:feat/ACTModel
Open

[Feature] Add ACTModel and ACTLoss for robot learning#3639
theap06 wants to merge 2 commits intopytorch:mainfrom
theap06:feat/ACTModel

Conversation

@theap06
Copy link
Copy Markdown
Contributor

@theap06 theap06 commented Apr 17, 2026

Implements Action Chunking with Transformers (Zhao et al., 2023, arxiv.org/abs/2304.13705) as a composable model + loss pair.

Implements - #3636
ACTModel (torchrl/modules/models/act.py):

  • CVAE encoder: [CLS | action_tokens | obs_token] → z_mu, z_log_var
  • DETR-style Transformer decoder: learned action queries attend to [obs_token, z_token] → action chunk of shape (chunk_size, action_dim)
  • Training mode: pass action_chunk to activate encoder and sample z
  • Inference mode: omit action_chunk; defaults to z=0 (prior mean)
  • Sinusoidal positional encoding, configurable hidden_dim / nheads / num_encoder_layers / num_decoder_layers / latent_dim / dropout

ACTLoss (torchrl/objectives/act.py):

  • loss = L1(action_pred, action_chunk) + kl_weight * KL(q(z|o,a)||N(0,I))
  • Returns loss_act (differentiable), loss_reconstruction and loss_kl (detached, for logging)
  • kl_weight defaults to 10.0 per the original paper
  • Follows the LossModule / convert_to_functional / to_module pattern established by DiffusionBCLoss

Also:

  • Registers ACTModel in torchrl.modules.models and ACTLoss in torchrl.objectives
  • Adds 31 tests covering shapes, training/inference modes, KL decomposition, reductions, and gradient flow
  • Adds docs entries in objectives_other.rst and modules_models.rst

Implements Action Chunking with Transformers (Zhao et al., 2023,
arxiv.org/abs/2304.13705) as a composable model + loss pair.

ACTModel (torchrl/modules/models/act.py):
- CVAE encoder: [CLS | action_tokens | obs_token] → z_mu, z_log_var
- DETR-style Transformer decoder: learned action queries attend to
  [obs_token, z_token] → action chunk of shape (chunk_size, action_dim)
- Training mode: pass action_chunk to activate encoder and sample z
- Inference mode: omit action_chunk; defaults to z=0 (prior mean)
- Sinusoidal positional encoding, configurable hidden_dim / nheads /
  num_encoder_layers / num_decoder_layers / latent_dim / dropout

ACTLoss (torchrl/objectives/act.py):
- loss = L1(action_pred, action_chunk) + kl_weight * KL(q(z|o,a)||N(0,I))
- Returns loss_act (differentiable), loss_reconstruction and loss_kl
  (detached, for logging)
- kl_weight defaults to 10.0 per the original paper
- Follows the LossModule / convert_to_functional / to_module pattern
  established by DiffusionBCLoss

Also:
- Registers ACTModel in torchrl.modules.models and ACTLoss in
  torchrl.objectives
- Adds 31 tests covering shapes, training/inference modes, KL
  decomposition, reductions, and gradient flow
- Adds docs entries in objectives_other.rst and modules_models.rst
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 17, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3639

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⚠️ 17 Awaiting Approval

As of commit 92ee098 with merge base eb90c5d (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 17, 2026
@theap06
Copy link
Copy Markdown
Contributor Author

theap06 commented Apr 24, 2026

@vmoens lmk if you need any outputs before mergings.

@theap06
Copy link
Copy Markdown
Contributor Author

theap06 commented Apr 24, 2026

@vmoens lgtm
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Documentation Improvements or additions to documentation Feature New feature Integrations/torch_geometric Integrations Modules Objectives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant