ptwm.stores
ptwm.stores
Pluggable weight-storage backends behind a shared :class:WeightStore API.
ptwm.stores
python/ptwm/stores/__init__.py:1module ptwm.storesPluggable weight-storage backends behind a shared :class:`WeightStore` API.
ptwm.stores.decode_member_tensor
python/ptwm/stores/_common.py:131def decode_member_tensor(registry_json: str, tensor_json: str, members: dict[str, bytes]) -> torch.TensorReconstruct a single tensor (as a :class:`torch.Tensor`) from members.
ptwm.stores.detect_format
python/ptwm/stores/__init__.py:49def detect_format(path: str | Path) -> str | NoneReturn ``"ptwm"`` / ``"lmdb"`` / ``"webdataset"`` for ``path`` or ``None``.
ptwm.stores.explode_model
python/ptwm/stores/_common.py:96def explode_model(blob: bytes) -> ExplodedModelExplode a multi-tensor ``.ptwm`` container blob into an exploded model.
ptwm.stores.ExplodedModel
python/ptwm/stores/_common.py:60class ExplodedModel:A compressed model projected to its canonical PTWM-JSON form.
ptwm.stores.ExplodedModel.__init__
python/ptwm/stores/_common.py:69def __init__(self, registry_json: str, tensors: list[tuple[str, str, str]], members: dict[str, bytes]) -> Noneptwm.stores.ExplodedModel.key
python/ptwm/stores/_common.py:86def key(self, name: str) -> strptwm.stores.ExplodedModel.member_size
python/ptwm/stores/_common.py:89def member_size(self, name: str) -> intTotal compressed bytes owned by ``name`` (planes + per-tensor state).
ptwm.stores.ExplodedModel.members
python/ptwm/stores/_common.py:77members = membersptwm.stores.ExplodedModel.names
python/ptwm/stores/_common.py:80def names(self) -> list[str]ptwm.stores.ExplodedModel.registry_json
python/ptwm/stores/_common.py:75registry_json = registry_jsonptwm.stores.ExplodedModel.tensor_json
python/ptwm/stores/_common.py:83def tensor_json(self, name: str) -> strptwm.stores.ExplodedModel.tensors
python/ptwm/stores/_common.py:76tensors = tensorsptwm.stores.jcs_canonicalize
python/ptwm/stores/_common.py:149def jcs_canonicalize(obj: Any) -> strSerialize ``obj`` to a canonical (RFC 8785) JSON string.
ptwm.stores.LmdbWeightStore
python/ptwm/stores/_lmdb.py:187class LmdbWeightStore:Read/update API over an LMDB-backed PTWM model (both layouts).
ptwm.stores.LmdbWeightStore.__enter__
python/ptwm/stores/_lmdb.py:238def __enter__(self) -> Selfptwm.stores.LmdbWeightStore.__exit__
python/ptwm/stores/_lmdb.py:241def __exit__(self, *exc: object = ()) -> Noneptwm.stores.LmdbWeightStore.__init__
python/ptwm/stores/_lmdb.py:190def __init__(self, path: str | Path, map_size: int = _DEFAULT_MAP_SIZE, readonly: bool = True) -> Noneptwm.stores.LmdbWeightStore.close
python/ptwm/stores/_lmdb.py:234def close(self) -> NoneClose the underlying LMDB environment.
ptwm.stores.LmdbWeightStore.get_bytes
python/ptwm/stores/_lmdb.py:309def get_bytes(self, name: str) -> bytesReturn the raw decompressed bytes for ``name``.
ptwm.stores.LmdbWeightStore.get_tensor
python/ptwm/stores/_lmdb.py:323def get_tensor(self, name: str) -> torch.TensorDecompress ``name`` and return a :class:`torch.Tensor`.
ptwm.stores.LmdbWeightStore.layout
python/ptwm/stores/_lmdb.py:245layout: strEither ``"blob"`` or ``"exploded"``.
ptwm.stores.LmdbWeightStore.names
python/ptwm/stores/_lmdb.py:305def names(self) -> list[str]Return tensor names in storage order.
ptwm.stores.LmdbWeightStore.open
python/ptwm/stores/_lmdb.py:229def open(cls, path: str | Path, readonly: bool = True) -> LmdbWeightStoreOpen an LMDB PTWM environment for reading (or updating).
ptwm.stores.LmdbWeightStore.put_tensor
python/ptwm/stores/_lmdb.py:353def put_tensor(self, name: str, raw: bytes, dtype: Any, shape: tuple[int, ...], delta_reference: str | None = None, method_hint: int = 3) -> NoneAtomically insert or replace tensor ``name`` (blob layout only).
ptwm.stores.LmdbWeightStore.stream_tensors
python/ptwm/stores/_lmdb.py:343def stream_tensors(self, names: Iterable[str] | None = None) -> Iterator[tuple[str, torch.Tensor]]Yield ``(name, tensor)`` pairs.
ptwm.stores.open_store
python/ptwm/stores/__init__.py:88def open_store(path: str | Path) -> WeightStoreOpen ``path`` as a :class:`WeightStore`, auto-detecting the format.
ptwm.stores.raw_from_members
python/ptwm/stores/_common.py:116def raw_from_members(registry_json: str, tensor_json: str, members: dict[str, bytes]) -> bytesReconstruct a one-tensor container and return its raw decompressed bytes.
ptwm.stores.SHARDMETA_MEMBER
python/ptwm/stores/_webdataset.py:46SHARDMETA_MEMBER = '__shardmeta__.json'ptwm.stores.WDS_FORMAT
python/ptwm/stores/_webdataset.py:45WDS_FORMAT = 'ptwm-wds'ptwm.stores.WebDatasetWeightStore
python/ptwm/stores/_webdataset.py:132class WebDatasetWeightStore:Read API over a WebDataset shard set (or a single shard for streaming).
ptwm.stores.WebDatasetWeightStore.__enter__
python/ptwm/stores/_webdataset.py:186def __enter__(self) -> Selfptwm.stores.WebDatasetWeightStore.__exit__
python/ptwm/stores/_webdataset.py:189def __exit__(self, *exc: object = ()) -> Noneptwm.stores.WebDatasetWeightStore.__init__
python/ptwm/stores/_webdataset.py:135def __init__(self, path: str | Path) -> Noneptwm.stores.WebDatasetWeightStore.close
python/ptwm/stores/_webdataset.py:179def close(self) -> NoneClose any open shard tar handles.
ptwm.stores.WebDatasetWeightStore.get_bytes
python/ptwm/stores/_webdataset.py:239def get_bytes(self, name: str) -> bytesReturn the raw decompressed bytes for ``name``.
ptwm.stores.WebDatasetWeightStore.get_tensor
python/ptwm/stores/_webdataset.py:246def get_tensor(self, name: str) -> torch.TensorDecompress ``name`` and return a :class:`torch.Tensor`.
ptwm.stores.WebDatasetWeightStore.names
python/ptwm/stores/_webdataset.py:235def names(self) -> list[str]Return tensor names in storage order.
ptwm.stores.WebDatasetWeightStore.open
python/ptwm/stores/_webdataset.py:174def open(cls, path: str | Path) -> WebDatasetWeightStoreOpen a WebDataset store directory (or a single shard).
ptwm.stores.WebDatasetWeightStore.stream_tensors
python/ptwm/stores/_webdataset.py:253def stream_tensors(self, names: Iterable[str] | None = None) -> Iterator[tuple[str, torch.Tensor]]Yield ``(name, tensor)`` pairs, reading shards sequentially.
ptwm.stores.WebDatasetWeightStore.webdataset_pipeline
python/ptwm/stores/_webdataset.py:296def webdataset_pipeline(self) -> AnyReturn a ``webdataset.WebDataset`` over the shard URLs.
ptwm.stores.WeightStore
python/ptwm/stores/_common.py:33class WeightStore(Protocol):Read API shared by every PTWM storage backend.
ptwm.stores.WeightStore.get_bytes
python/ptwm/stores/_common.py:45def get_bytes(self, name: str) -> bytesReturn the raw decompressed bytes for ``name``.
ptwm.stores.WeightStore.get_tensor
python/ptwm/stores/_common.py:48def get_tensor(self, name: str) -> torch.TensorDecompress ``name`` and return a :class:`torch.Tensor`.
ptwm.stores.WeightStore.names
python/ptwm/stores/_common.py:42def names(self) -> list[str]Return tensor names in storage order.
ptwm.stores.WeightStore.stream_tensors
python/ptwm/stores/_common.py:51def stream_tensors(self, names: Iterable[str] | None = None) -> Iterator[tuple[str, torch.Tensor]]Yield ``(name, tensor)`` pairs.
ptwm.stores.write_lmdb
python/ptwm/stores/_lmdb.py:71def write_lmdb(path: str | Path, tensors: Sequence[tuple[str, bytes, Any, tuple[int, ...]]], layout: str = 'blob', map_size: int = _DEFAULT_MAP_SIZE, method_hint: int = 3, chains_per_tensor: list[list[bytes]] | None = None) -> PathWrite ``tensors`` into an LMDB environment at ``path``.
ptwm.stores.write_webdataset
python/ptwm/stores/_webdataset.py:66def write_webdataset(out_dir: str | Path, tensors: Sequence[tuple[str, bytes, Any, tuple[int, ...]]], max_shard_size: int = _DEFAULT_MAX_SHARD_SIZE, method_hint: int = 3, chains_per_tensor: list[list[bytes]] | None = None) -> PathWrite ``tensors`` as a WebDataset shard set rooted at ``out_dir``.