Download baseline/pi5_stack_cup/inference/stack_cups_config.py from qshou-coder/SpaceDreamer_Galexea: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/qshou-coder/SpaceDreamer_Galexea/resolve/main/baseline/pi5_stack_cup/inference/stack_cups_config.py
- Command line
-
hf download hf://qshou-coder/SpaceDreamer_Galexea/baseline/pi5_stack_cup/inference/stack_cups_config.py
-
curl -L -o stack_cups_config.py https://huggingface.co/qshou-coder/SpaceDreamer_Galexea/resolve/main/baseline/pi5_stack_cup/inference/stack_cups_config.py
4.9 kB
| """Explicit pi0.5 JAX LoRA recipe and raw-joint-anchor deployment adapter.""" | |
| import dataclasses | |
| import os | |
| from pathlib import Path | |
| import numpy as np | |
| from openpi.models.pi0_config import Pi0Config | |
| from openpi.training import config, optimizer, weight_loaders | |
| from openpi import transforms | |
| ROOT = Path(__file__).resolve().parent.parent | |
| BASE = Path(os.environ.get('OPENPI_PI05_BASE', '/path/to/pi05_base')) | |
| REPO_ID = 'galaxea/stack_cups_all81_20hz' | |
| MASK = np.asarray([True] * 6 + [False] + [True] * 6 + [False]) | |
| class GalaxeaData(config.LeRobotAlohaDataConfig): | |
| raw_anchor_in_adapter: bool = False | |
| def create(self, assets_dirs, model_config): | |
| data = super().create(assets_dirs, model_config) | |
| if self.raw_anchor_in_adapter: | |
| outputs = [x for x in data.data_transforms.outputs if not isinstance(x, transforms.AbsoluteActions)] | |
| data = dataclasses.replace(data, data_transforms=transforms.Group( | |
| inputs=data.data_transforms.inputs, outputs=outputs)) | |
| return data | |
| def make_config(*, smoke=False, raw_anchor_in_adapter=False): | |
| model = Pi0Config(pi05=True, action_dim=32, action_horizon=50, max_token_len=200, | |
| paligemma_variant='gemma_2b_lora', action_expert_variant='gemma_300m_lora') | |
| data = GalaxeaData( | |
| repo_id=REPO_ID, adapt_to_pi=False, default_prompt='Stack the cups.', | |
| raw_anchor_in_adapter=raw_anchor_in_adapter, | |
| assets=config.AssetsConfig(asset_id='galaxea_r1_lite_stack_cups'), | |
| base_config=config.DataConfig(prompt_from_task=True), | |
| repack_transforms=transforms.Group(inputs=[transforms.RepackTransform({ | |
| 'images': {'cam_high': 'observation.images.head_left', | |
| 'cam_left_wrist': 'observation.images.wrist_left', | |
| 'cam_right_wrist': 'observation.images.wrist_right'}, | |
| 'state': 'observation.state', 'actions': 'action', 'prompt': 'prompt', | |
| })]), | |
| ) | |
| return config.TrainConfig( | |
| name='pi05_stack_cups_lora', exp_name='smoke' if smoke else 'stack-cups-all81-jax-lora-h50-10k', | |
| project_name='galaxea-real-baselines', model=model, data=data, | |
| weight_loader=weight_loaders.CheckpointWeightLoader(str(BASE / 'params')), | |
| freeze_filter=model.get_freeze_filter(), ema_decay=None, | |
| batch_size=8 if smoke else 256, num_workers=0 if smoke else 8, | |
| num_train_steps=3 if smoke else 10000, seed=0, | |
| lr_schedule=optimizer.CosineDecaySchedule(warmup_steps=500, peak_lr=5e-5, | |
| decay_steps=10000, decay_lr=5e-6), | |
| optimizer=optimizer.AdamW(b1=.9, b2=.95, weight_decay=1e-10, clip_gradient_norm=1.0), | |
| assets_base_dir=str(ROOT / 'assets'), checkpoint_base_dir=str(ROOT / 'checkpoints'), | |
| save_interval=2000, keep_period=1, log_interval=1 if smoke else 20, | |
| fsdp_devices=1, overwrite=False, resume=False, wandb_enabled=not smoke, | |
| policy_metadata={'robot': 'galaxea_r1_lite', 'task': 'stack_cups', 'fps': 20, | |
| 'physical_action_dim': 14, 'prediction_horizon': 50, | |
| 'joint_order': 'left_arm6,left_gripper,right_arm6,right_gripper', | |
| 'arm_units': 'radians', 'gripper_units': 'recorded high-level position command', | |
| 'output_contract': 'absolute_joint_targets; raw joint feedback anchor added once'}, | |
| ) | |
| class RawJointAnchorPolicy: | |
| """Wrap only a delta-output policy; never wrap already absolute output.""" | |
| def __init__(self, delta_policy): | |
| self.delta_policy = delta_policy | |
| def metadata(self): | |
| return self.delta_policy.metadata | |
| def reset(self): | |
| reset=getattr(self.delta_policy,'reset',None) | |
| if reset is not None: | |
| return reset() | |
| def infer(self, observation): | |
| raw_state = np.asarray(observation['state'], dtype=np.float32).copy() | |
| if raw_state.shape != (14,) or not np.isfinite(raw_state).all(): | |
| raise ValueError('Expected finite physical 14-D state in left6,grip,right6,grip order') | |
| result = self.delta_policy.infer(observation) | |
| actions = np.asarray(result['actions'], dtype=np.float32).copy() | |
| if actions.shape != (50, 14) or not np.isfinite(actions).all(): | |
| raise ValueError(f'Expected finite 50x14 delta/absolute-gripper predictions: {actions.shape}') | |
| actions[:, MASK] += raw_state[None, MASK] | |
| return {**result, 'actions': actions} | |
| def create_galaxea_policy(checkpoint_dir, *, num_steps=10): | |
| from openpi.policies.policy_config import create_trained_policy | |
| cfg = make_config(raw_anchor_in_adapter=True) | |
| delta_policy = create_trained_policy(cfg, checkpoint_dir, sample_kwargs={'num_steps': num_steps}) | |
| return RawJointAnchorPolicy(delta_policy) | |