Add optional pi0.5 subtask prediction stage#942
Open
taivu1998 wants to merge 1 commit into
Open
Conversation
wadeKeith
reviewed
May 12, 2026
Contributor
wadeKeith
left a comment
There was a problem hiding this comment.
Nice feature! The optional pi0.5 subtask prediction stage is well scoped with clean separation from the main action prediction path. Tokenizer extensions and test coverage look solid. LGTM! Reviewed by Hermes Agent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in pi0.5 subtask prediction support for research workflows that want to reproduce the two-stage inference pattern described in issue #664:
The existing action-only pi0/pi0.5 behavior remains the default.
Motivation
Issue #664 points out that the pi0.5 paper describes an intermediate subtask prediction stage, while openpi currently tokenizes the prompt and directly predicts actions. This PR adds that missing path behind explicit config flags instead of changing default inference or training behavior for released checkpoints.
Changes
Pi0Configflags for pi0.5 subtask workflows:train_subtask_predictionsample_subtask_predictionsubtask_loss_weightmax_subtask_lensubtask_temperaturesubtask_eos_tokenObservationwith optional tokenized action-suffix fields used by staged inference.Subtask:;sample_actions_with_subtask()returning actions plus generated subtask tokens.sample_subtask_prediction=True.NotImplementedErrorif subtask mode is requested there.Compatibility
Pi0Config(pi05=True)behavior is unchanged.sample_actions()remains action-only and keeps the same return type.sample_actions_with_subtask()and policy wiring when enabled.Validation
uvx ruff check src/openpi/models/model.py src/openpi/models/pi0.py src/openpi/models/pi0_config.py src/openpi/models/gemma.py src/openpi/models/tokenizer.py src/openpi/models/tokenizer_test.py src/openpi/models/model_test.py src/openpi/models_pytorch/pi0_pytorch.py src/openpi/policies/policy.py src/openpi/training/config.py src/openpi/transforms.py src/openpi/transforms_test.py.venv/bin/python -m py_compile src/openpi/models/model.py src/openpi/models/pi0.py src/openpi/models/pi0_config.py src/openpi/models/gemma.py src/openpi/models/tokenizer.py src/openpi/models/tokenizer_test.py src/openpi/models/model_test.py src/openpi/models_pytorch/pi0_pytorch.py src/openpi/policies/policy.py src/openpi/training/config.py src/openpi/transforms.py src/openpi/transforms_test.py.venv/bin/python -m pytest src/openpi/models/tokenizer_test.py::test_subtask_tokenize_training src/openpi/models/tokenizer_test.py::test_subtask_tokenize_inference src/openpi/transforms_test.py::test_tokenize_pi05_subtask_training src/openpi/transforms_test.py::test_tokenize_pi05_subtask_inference src/openpi/transforms_test.py::test_tokenize_pi05_subtask_training_requires_subtask src/openpi/models/model_test.py::test_pi05_subtask_model -qgit diff --checkNote: the full
uv run pytest ...path is not runnable on this macOS arm64 machine because the repo pinsjax[cuda12]==0.5.3, whose CUDA plugin wheel is Linux-only. The targeted runtime tests above used a lightweight CPU-JAX environment.