MCPcopy Create free account
hub / github.com/modelscope/modelscope / _load_by_rank

Function _load_by_rank

modelscope/utils/megatron_utils.py:191–198  ·  view source on GitHub ↗
(checkpoint_dir: Union[str, bytes, os.PathLike],
                  rank: int)

Source from the content-addressed store, hash-verified

189
190
191def _load_by_rank(checkpoint_dir: Union[str, bytes, os.PathLike],
192 rank: int) -> Dict[str, torch.Tensor]:
193 checkpoint_name = _CHECKPOINT_FORMAT.replace('XX', f'{rank:02d}')
194 state_dict = torch.load(
195 os.path.join(checkpoint_dir, checkpoint_name),
196 map_location=lambda storage, loc: storage,
197 weights_only=True)
198 return state_dict['module'] if 'module' in state_dict else state_dict
199
200
201def _split_tensor(tensor: torch.Tensor, num_partitions: int,

Callers 2

_split_checkpointFunction · 0.85
_merge_checkpointFunction · 0.85

Calls 2

replaceMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…