Download real_robot/source/retime/checkpoint.py from mmmmmcyaaa/ReTime: direct link, hf CLI and curl.
- Browser
- Download file 864 Bytes
-
https://huggingface.co/mmmmmcyaaa/ReTime/resolve/main/real_robot/source/retime/checkpoint.py
- Command line
-
hf download hf://mmmmmcyaaa/ReTime/real_robot/source/retime/checkpoint.py
-
curl -L -o checkpoint.py https://huggingface.co/mmmmmcyaaa/ReTime/resolve/main/real_robot/source/retime/checkpoint.py
864 Bytes
| """Load full policy weights before or after DeepSpeed partitions parameters.""" | |
| def load_policy_state_dict(model, state_dict, *, strict=True): | |
| """Every distributed rank must call this with the same state dictionary. | |
| ZeRO-3 initialization replaces parameter storage with empty shards. Gather | |
| those parameters while copying weights, then broadcast and repartition on | |
| context exit. Loading on every rank also initializes replicated buffers. | |
| Ordinary models do not need DeepSpeed installed. | |
| """ | |
| partitioned = [parameter for parameter in model.parameters() if hasattr(parameter, "ds_id")] | |
| if not partitioned: | |
| return model.load_state_dict(state_dict, strict=strict) | |
| from deepspeed import zero | |
| with zero.GatheredParameters(partitioned, modifier_rank=0): | |
| return model.load_state_dict(state_dict, strict=strict) | |