Respect PyTorch precision when loading checkpoints#940
Open
taivu1998 wants to merge 1 commit into
Open
Conversation
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
Fixes #788.
This PR makes PyTorch checkpoint loading respect
TrainConfig.pytorch_training_precisioninstead of silently falling back to the nested model config's default dtype.Root Cause
scripts/train_pytorch.pyalready updates the model config dtype before constructingPI0Pytorch, butBaseModelConfig.load_pytorchdid not do the same. That meant a config requesting float32 PyTorch precision could still instantiate and load a PyTorch checkpoint through a bfloat16-configured module. The policy-loading path also unconditionally re-applied"bfloat16"after loading, which would keep float32 policy loading broken even if the loader was fixed.Changes
load_pytorchwithdtype=train_config.pytorch_training_precisionbefore loading safetensors.PI0Pytorch."bfloat16".Validation
.venv/bin/python -m pytest src/openpi/models/model_test.py -k pytorch.venv/bin/python -m pytest src/openpi/policies/policy_test.py -k pytorchuvx ruff check src/openpi/models/model.py src/openpi/policies/policy_config.py src/openpi/models/model_test.py src/openpi/policies/policy_test.pyuvx ruff format --check src/openpi/models/model.py src/openpi/policies/policy_config.py src/openpi/models/model_test.py src/openpi/policies/policy_test.pygit diff --checkNote: on macOS arm64, the normal
uv runpath attempts to install Linux-only CUDA JAX wheels from the project lockfile. I validated using a temporary environment synced with the CUDA-only packages skipped, then removed the generated environment and caches.