Download code/scripts/prepare_legacy_l18_protocol.py from jisue/robottt-pi05-base-comparison: direct link, hf CLI and curl.
- Browser
- Download file 4.69 kB
-
https://huggingface.co/jisue/robottt-pi05-base-comparison/resolve/main/code/scripts/prepare_legacy_l18_protocol.py
- Command line
-
hf download hf://jisue/robottt-pi05-base-comparison/code/scripts/prepare_legacy_l18_protocol.py
-
curl -L -o prepare_legacy_l18_protocol.py https://huggingface.co/jisue/robottt-pi05-base-comparison/resolve/main/code/scripts/prepare_legacy_l18_protocol.py
4.69 kB
| """Extend the actual L4 initial state to L18 and retain its exact training inputs.""" | |
| import json | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import numpy as np | |
| import torch | |
| ROOT = Path(__file__).resolve().parents[1] | |
| LOCAL = ROOT / '.release_local' | |
| sys.path.insert(0, str(ROOT / 'src')) | |
| from robottt_pi05.config import ExperimentConfig | |
| from robottt_pi05.core import TTTLayer, TTTConfig | |
| from robottt_pi05.modeling import extension | |
| from robottt_pi05.eval_io import atomic_json, atomic_tensor, sha, parameter_hash | |
| def main(): | |
| bundle = LOCAL / 'legacy-l4-handoff/bundle' | |
| original = bundle / 'learned_inner_lr_v1/protocol/initial.pt' | |
| assert sha(original) == '2e59f08afdd6bc863ffc89ecd29ff7ba25e861bdccfba6ae44f9b63eb210830b' | |
| saved = torch.load(original, map_location='cpu', weights_only=True) | |
| cfg_path = ROOT / 'configs/l18_learned_s4.json' | |
| config = ExperimentConfig.load(cfg_path) | |
| slow = extension(config) | |
| shared = {'4', '8', '12', '17'} | |
| seeds = {} | |
| for key, layer in slow.ttt.items(): | |
| if key not in shared: | |
| seed = int(np.random.SeedSequence([281004, int(key)]).generate_state(1, dtype=np.uint32)[0]) | |
| seeds[key] = seed | |
| with torch.random.fork_rng(devices=[]): | |
| torch.manual_seed(seed) | |
| initialized = TTTLayer(TTTConfig(dim=1024, memory_dim=32, hidden_dim=64, base_lr=1e-4)) | |
| layer.load_state_dict(initialized.state_dict(), strict=True) | |
| state = slow.state_dict() | |
| for key, value in saved['slow'].items(): | |
| state[key].copy_(value) | |
| for key, value in saved['slow'].items(): | |
| assert torch.equal(state[key], value), key | |
| assert len({p.data_ptr() for p in slow.parameters()}) == len(list(slow.parameters())) | |
| protocol = LOCAL / 'protocol-legacy-ft-l18' | |
| protocol.mkdir(exist_ok=True) | |
| initial = protocol / 'initial.pt' | |
| initial_record = dict(slow=state, rng=saved['rng'], parameter_names=[n for n, p in slow.named_parameters() if p.requires_grad], | |
| source_initial=str(original), source_step0=str(original), source_step0_sha256=sha(original), not_smoke=True) | |
| atomic_tensor(initial, initial_record) | |
| for filename, source_name in [('schedule.json', 'schedule.json'), ('bank.pt', 'banks.pt')]: | |
| source = bundle / 'sequence_training_v1/protocol' / source_name | |
| target = protocol / filename | |
| if not target.exists(): | |
| os.link(source, target) | |
| data = LOCAL / 'legacy-ft-data' | |
| index = LOCAL / 'legacy-ft-prefix/asset-index.json' | |
| paths = dict(openpi_source=str(ROOT.parent / 'openpi'), | |
| model_checkpoint=str(LOCAL / 'ft-base-reproduction/converted/pi05_libero_pytorch/model.safetensors'), | |
| normalization=str(data / 'normalization.json'), tokenizer=str(LOCAL / 'assets/paligemma_tokenizer.model'), | |
| data_root=str(data), prefix_root=str(LOCAL / 'legacy-ft-prefix'), asset_index=str(index), | |
| initial_extension=str(initial), schedule=str(protocol / 'schedule.json'), bank=str(protocol / 'bank.pt'), | |
| output=str(LOCAL / 'runs/legacy-ft-l18-learned'), experiment_config=str(cfg_path)) | |
| hashes = {name: sha(Path(paths[name])) for name in ('model_checkpoint', 'normalization', 'tokenizer', 'asset_index', 'initial_extension', 'schedule', 'bank')} | |
| uuid = subprocess.check_output(['nvidia-smi', '--query-gpu=uuid', '--format=csv,noheader'], text=True).strip() | |
| run = dict(paths=paths, hashes=hashes, gpu_uuid=uuid, updates=1024, milestones=[256, 512, 1024], checkpoint_every=25, | |
| runtime_profile='minimal', model_profile='legacy_pi05_libero', optimizer_profile='legacy', original=False, | |
| limits=dict(model_load=4, expert=16384, inner=294912, backward=4096, optimizer_update=1024, rollout=0)) | |
| atomic_json(LOCAL / 'legacy-ft-l18-learned.json', run) | |
| atomic_json(protocol / 'initialization-audit.json', dict(shared_tensors_verified=len(saved['slow']), shared_layers=[4,8,12,17], | |
| register_initial_exact=True, original_initial_sha256=sha(original), added_layer_seeds=seeds, | |
| trainable_parameters=sum(p.numel() for p in slow.parameters() if p.requires_grad), | |
| trainable_tensors=sum(p.requires_grad for p in slow.parameters()), initial_parameter_hash=parameter_hash(state), | |
| optimizer='legacy AdamW 3e-4, betas .9/.999, clip 1, fixed outer LR', | |
| runtime='sequential S4 graph with reduced diagnostic bookkeeping; no timestep batching')) | |
| print('L18_PROTOCOL_READY', str(LOCAL / 'legacy-ft-l18-learned.json'), flush=True) | |
| if __name__ == '__main__': | |
| main() | |