PTWM
ptwm

ptwm.sharding

Sharded .ptwm writers/readers.

ptwm.sharding

Sharded .ptwm writers/readers.

pymodule

ptwm.sharding

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

Sharded ``.ptwm`` writers/readers.

pyfunction

ptwm.sharding.compress_ptwm_blob

python/ptwm/sharding/_writer.py:30
def compress_ptwm_blob(tensors: Sequence[tuple[str, bytes, Any, tuple[int, ...]]], chains_per_tensor: list[list[bytes]] | None = None, method_hint: int = 3, emit_payload_hash: bool = True, emit_plane_crc: bool = True, streaming_chunk: int | None = None) -> bytes

Compress ``tensors`` into a single in-memory ``.ptwm`` container blob.

``tensors`` is a sequence of ``(name, raw_bytes, dtype, shape)``. ``chains_per_tensor`` — one list of chain wire-byte blobs per tensor; each blob is produced by ``Chain.to_bytes()``. When ``None``, chains are auto-derived from each tensor's dtype via the STANDARD production table. ``method_hint``: 1=HUFFMAN, 2=ZSTD, 3=MICROSCALE, 4=RANS, 5=IDENTITY.
pyfunction

ptwm.sharding.plan_shards

python/ptwm/sharding/_sharder.py:18
def plan_shards(sized_tensors: Sequence[tuple[str, int]], max_shard_size: int) -> list[list[tuple[str, int]]]

Greedy pack tensors in input order, respecting ``max_shard_size``.

A single tensor larger than ``max_shard_size`` gets its own shard.
pyclass

ptwm.sharding.PtwmIndex

python/ptwm/sharding/_index.py:12
class PtwmIndex:
pymethod

ptwm.sharding.PtwmIndex.__init__

python/ptwm/sharding/_index.py:1
def __init__(self, total_size: int, compressed_total_size: int, weight_map: dict[str, str] = dict()) -> None
pyattribute

ptwm.sharding.PtwmIndex.compressed_total_size

python/ptwm/sharding/_index.py:15
compressed_total_size: int
pymethod

ptwm.sharding.PtwmIndex.read

python/ptwm/sharding/_index.py:30
def read(cls, path: str | Path) -> PtwmIndex
pyattribute

ptwm.sharding.PtwmIndex.total_size

python/ptwm/sharding/_index.py:14
total_size: int
pyattribute

ptwm.sharding.PtwmIndex.weight_map

python/ptwm/sharding/_index.py:16
weight_map: dict[str, str] = field(default_factory=dict)
pymethod

ptwm.sharding.PtwmIndex.write

python/ptwm/sharding/_index.py:18
def write(self, path: str | Path) -> None
pyfunction

ptwm.sharding.read_sharded_ptwm

python/ptwm/sharding/_reader.py:13
def read_sharded_ptwm(model_dir: str | Path) -> dict[str, bytes]

Open every shard listed in ``model.ptwm.index.json``, return the union.

If no index file is present, falls back to a single ``model.ptwm`` in the directory.
NameTypeDescription
model_dirstr | PathDirectory containing ``.ptwm`` shard files and optionally a ``model.ptwm.index.json`` index.
Returns
dict[str, bytes]Flat mapping of tensor name → raw decompressed bytes, merged across all shards.
Raises
  • FileNotFoundError — If neither ``model.ptwm.index.json`` nor ``model.ptwm`` exists.
  • ValueError — If the same tensor name appears in more than one shard.
pyfunction

ptwm.sharding.shard_filename

python/ptwm/sharding/_sharder.py:10
def shard_filename(idx_one_based: int, total: int, suffix: str) -> str

Return ``model-NNNNN-of-MMMMM.<suffix>``.

pyfunction

ptwm.sharding.write_ptwm_shard

python/ptwm/sharding/_writer.py:78
def write_ptwm_shard(out_path: str | Path, tensors: Sequence[tuple[str, bytes, Any, tuple[int, ...]]], chains_per_tensor: list[list[bytes]] | None = None, method_hint: int = 3, emit_payload_hash: bool = True, emit_plane_crc: bool = True, streaming_chunk: int | None = None) -> None

Write a single ``.ptwm`` container holding ``tensors``.

See :func:`compress_ptwm_blob` for the parameter semantics.