MCPcopy
hub / github.com/InternLM/lmdeploy / __init__

Method __init__

lmdeploy/turbomind/checkpoint.py:229–239  ·  view source on GitHub ↗
(self, model_path: str, *,
                 mappings=(),
                 index_name: str | None = None,
                 file_pattern: str | None = None)

Source from the content-addressed store, hash-verified

227 """torch.load-backed checkpoint over ``*.bin`` / ``*.pt`` shards."""
228
229 def __init__(self, model_path: str, *,
230 mappings=(),
231 index_name: str | None = None,
232 file_pattern: str | None = None):
233 self._mappings = list(mappings)
234 shards, _ = _gather_shards(model_path, index_name, file_pattern)
235 self._data: dict[str, torch.Tensor] = {}
236 for shard in shards:
237 tmp = torch.load(shard, map_location='cpu', weights_only=True)
238 for k, v in tmp.items():
239 self._data[_apply_mappings(k, self._mappings)] = v
240
241 def get(self, key: str, index=None):
242 t = self._data[key]

Callers

nothing calls this directly

Calls 4

_gather_shardsFunction · 0.85
_apply_mappingsFunction · 0.85
itemsMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected