Step 7: Action Chunking
Replaces single-action prediction with a sequence of actions (chunk) to capture temporal structure, with configurable execution modes.
What this file does
Replaces single-action prediction with a sequence of actions (chunk) to capture temporal structure, with configurable execution modes.
When to use it
- You need a policy that predicts multiple future actions at once
- You want to smooth out jittery behavior from single-step policies
- Your task has temporal dependencies that benefit from open-loop execution
- You are implementing Action Chunking with Transformers (ACT) or Pi0
Assumes this stack
Step 7: Action Chunking
Goal
Instead of predicting one action at a time, predict a sequence of actions (chunk). This captures temporal structure and is a key idea from ACT (Action Chunking with Transformers) that carries into Pi0.
Concept
Before (single action):
- Input: observation
- Output: action (2D)
- Execute, get new obs, repeat
After (action chunk):
- Input: observation
- Output: action sequence [a₁, a₂, ..., aₖ] (k×2D)
- Execute all k actions (open-loop), then get new obs and predict again
Implementation
- Same CNN encoder as BC
- Output layer predicts
chunk_size * action_dimvalues - Reshape to
(chunk_size, 2)for execution - Dataset pairs each observation with next
chunk_sizeactions
Execution Modes
Controlled via actions_per_inference parameter:
Open-loop: actions_per_inference=8 (default)
- Execute entire chunk blindly, then re-observe
- Simple, but errors compound over k steps
Receding horizon: actions_per_inference=1
- Predict chunk every step, only use first action
- More reactive, more compute
Partial: actions_per_inference=4
- Middle ground - predict 8, execute 4, then re-predict
- Good balance of reactivity and efficiency
Episode Boundary Handling
Problem: Original data collection flattened all episodes into one array. Action chunks near episode boundaries would include actions from the next episode.
Solution:
- Data collection now saves
episode_endsarray marking where each episode ends - Dataset pads chunks with zeros at episode boundaries instead of crossing into next episode
- This teaches the model to predict "do nothing" near success states
Training Setup
- chunk_size: 8
- Same hyperparameters as BC (lr=1e-3, batch_size=64)
- Data: expert + dagger (10k samples)
- Train/val split: 0.7
- Best checkpoint: epoch 6 (val_loss=3.25)
- Observed overfitting after epoch 6 (train kept dropping, val plateaued ~3.5)
Results
Without episode_ends (v1):
- Policy works but shows jittering/overshooting
- Open-loop errors compound, expert data noise amplified
With episode_ends + receding horizon (v2):
actions_per_inference=4smooths out jitter- Cleaner data + more frequent re-prediction helps
Honest assessment:
- Episode ends training improved data quality
- Receding horizon (4) made execution noticeably smoother
- But overall performance is not dramatically better than BC + DAgger for this simple task
- Action chunking likely shines more on complex tasks with temporal structure (multi-step manipulation, longer horizons) rather than this simple ball-catching task
Videos
| Description | Video |
|---|---|
| Initial open-loop, some jitter | 07_action_chunking_policy.mp4 |
| Receding horizon (4), smoother | 07_action_chunking_policy_rh4.mp4 |
| With episode ends | 07_action_chunking_policy_episode_ends.mp4 |
| Episode ends + RH4 | 07_action_chunking_policy_rh4_episode_ends.mp4 |
| Episode ends + zero padding | 07_action_chunking_policy_episode_ends_padded.mp4 |
| Episode ends + zero padding + RH4 | 07_action_chunking_policy_rh4_episode_ends_padded.mp4 |
Status
Complete
Location: policy/action_chunking_policy.py, data/dataset.py
What's inside
Goal, concept, implementation, 3 execution modes, episode boundary handling, training setup, results, 6 video references, status
Change this for your project
- Replace
chunk_size: 8with your desired chunk length - Replace
actions_per_inference=8with your execution mode - Replace
episode_endsarray handling indata/dataset.pyfor your data format
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Pad action chunks with zeros at episode boundaries to avoid cross-episode contamination
- Use a receding horizon (predict chunk, execute subset, re-predict) to balance reactivity and smoothness
Related Documents
基于命题分块以增强RAG
Implements proposition chunking for RAG: decomposes documents into atomic facts, evaluates quality, and compares retrieval against standard chunking.
TileMap Chunk Manager
Divides a large tilemap into fixed-size chunks, loading and rendering only those visible to reduce memory and draw calls by over 99%.
Message Chunking for MCP stdio Transport
Explains macOS 64KB pipe write limit and provides a chunking layer for MCP stdio transport that splits and reassembles large messages transparently.
🤖 n8n AI Agent Mastery Course 2025
Serves as the main README for an n8n course repository, listing 10+ AI agent workflow projects with links to YouTube tutorials and Docker setup instructions.