PTWM
ptwm

ptwm.random_access

Random-access loader for .ptwm containers.

ptwm.random_access

Random-access loader for .ptwm containers.

pymodule

ptwm.random_access

python/ptwm/random_access/__init__.py:1
module ptwm.random_access

Random-access loader for ``.ptwm`` containers.

:class:`TensorIndex` opens a compressed bundle and decompresses individual tensors on demand. The index is tiny (a manifest of name → offset/length records), so opening a bundle and fetching one tensor touches only that tensor's bytes. idx = TensorIndex.open("model.safetensors.ptwm") weight = idx.get_tensor("layer_5.weight") for name, tensor in idx.stream_tensors(names_of_interest): ...
pyclass

ptwm.random_access.TensorEntry

python/ptwm/random_access/__init__.py:29
class TensorEntry:

One entry from a ``.ptwm`` tensor index.

pymethod

ptwm.random_access.TensorEntry.__init__

python/ptwm/random_access/__init__.py:1
def __init__(self, name: str) -> None
pyattribute

ptwm.random_access.TensorEntry.name

python/ptwm/random_access/__init__.py:33
name: str
pyclass

ptwm.random_access.TensorIndex

python/ptwm/random_access/__init__.py:36
class TensorIndex:

Name-indexed random-access loader over a ``.ptwm`` container.

pymethod

ptwm.random_access.TensorIndex.__init__

python/ptwm/random_access/__init__.py:39
def __init__(self, path: str | Path) -> None
pymethod

ptwm.random_access.TensorIndex.__iter__

python/ptwm/random_access/__init__.py:125
def __iter__(self) -> Iterator[str]
pymethod

ptwm.random_access.TensorIndex.entries

python/ptwm/random_access/__init__.py:66
def entries(self) -> list[TensorEntry]

Return every :class:`TensorEntry` in manifest order.

pymethod

ptwm.random_access.TensorIndex.entry

python/ptwm/random_access/__init__.py:70
def entry(self, name: str) -> TensorEntry

Return the :class:`TensorEntry` for ``name`` or raise ``KeyError``.

pymethod

ptwm.random_access.TensorIndex.get_bytes

python/ptwm/random_access/__init__.py:79
def get_bytes(self, name: str) -> bytes

Return the raw decompressed bytes for ``name``.

pymethod

ptwm.random_access.TensorIndex.get_tensor

python/ptwm/random_access/__init__.py:88
def get_tensor(self, name: str) -> torch.Tensor

Decompress ``name`` and return a :class:`torch.Tensor`.

Shape/dtype come from the CBOR shape metadata written at compression time; tensors without metadata raise :class:`TypeError`.
pymethod

ptwm.random_access.TensorIndex.names

python/ptwm/random_access/__init__.py:62
def names(self) -> list[str]

Return tensor names in manifest (write) order.

pymethod

ptwm.random_access.TensorIndex.open

python/ptwm/random_access/__init__.py:50
def open(cls, path: str | Path) -> Self

Open ``path`` for random-access tensor lookup.

pyattribute

ptwm.random_access.TensorIndex.path

python/ptwm/random_access/__init__.py:58
path: Path

Filesystem path this index was opened from.

pymethod

ptwm.random_access.TensorIndex.stream_tensors

python/ptwm/random_access/__init__.py:108
def stream_tensors(self, names: Iterable[str] | None = None) -> Iterator[tuple[str, torch.Tensor]]

Yield ``(name, tensor)`` pairs.