Remove redundant config_name arg from JAX->Pytorch model conversion script#915
Open
tahsinkose wants to merge 1 commit intoPhysical-Intelligence:mainfrom
Conversation
…cript by inferring required fields from the checkpoint.
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.
Fixes #781.
Background
convert_jax_model_to_pytorch.pypreviously required a--config_nameargument (e.g.pi05_base,pi05_droid) to look up aTrainConfigand extract aPi0Config. This was unnecessary because all the information the conversion actually needs is either inferable from the checkpoint contents or irrelevant to the weight conversion entirely.Approach
Each field of
Pi0Configconsumed by the script was audited:1.
pi05(bool)Determines the model architecture: which projection keys exist (
time_mlp_in/time_mlp_outvsstate_proj/action_time_mlp_in/action_time_mlp_out) and whether expert normalization layers use adaptiveDenselayers or standardRMSNormscale.Resolution: reliably detectable from checkpoint contents —
"time_mlp_in"is present in the projection params if and only if the checkpoint is pi05. No path-name heuristics needed.2.
action_dimUsed in
PI0Pytorch.__init__to size the projection layers:Must be correct for
load_state_dictto succeed.Resolution: inferred from the checkpoint —
action_in_proj/kernel.shape[0]givesaction_dimdirectly.3.
action_horizonOnly referenced in forward/sample methods (
embed_suffix,forward,sample_actions,denoise_step) for attention maskconstruction and output slicing. Never used in
__init__, so it has no effect on layer sizes or the weight conversion. Notably it also varies across checkpoints (pi05_droid: 15,pi05_libero: 10, default: 50), so using a hardcoded default would silently be wrong — but since it does not affect the conversion at all, it is simply not needed here. Theconfig.jsonwritten alongside the converted weights is a human-readable reference only — nothing in the codebase reads it back. So omittingaction_horizonfrom it has no functional impact on inference or finetuning; callers must constructPI0Pytorch(config)with the correct config themselves regardless.#### 4.
paligemma_variant/action_expert_variantAlready hardcoded elsewhere in the script — the
PaliGemmaConfiginline class for the vision/language side andopenpi.models.gemma.get_config("gemma_300m")for the expert. Not needed by the config.Changes
config_nameparameter frommainandconvert_pi0_checkpointpi05from checkpoint contents:"time_mlp_in" in initial_params["projection_params"]action_dimfrom checkpoint:action_in_proj_kernel.shape[0]