ptwm.preprocessing
ptwm.preprocessing
Dtype-aware preprocessing for lossless weight compression.
ptwm.preprocessing
python/ptwm/preprocessing/__init__.py:1module ptwm.preprocessingDtype-aware preprocessing for lossless weight compression.
ptwm.preprocessing.cache_dir
python/ptwm/preprocessing/_cache.py:67def cache_dir() -> PathReturn the user-local chain cache directory (XDG-aware).
ptwm.preprocessing.cache_info
python/ptwm/preprocessing/_cache.py:176def cache_info() -> dict[str, int]Map cache filename → chain count, for diagnostics.
ptwm.preprocessing.cache_path_for
python/ptwm/preprocessing/_cache.py:74def cache_path_for(dtype_code: int, role: ClassifierRole) -> Pathptwm.preprocessing.CacheEntry
python/ptwm/preprocessing/_cache.py:44class CacheEntry:One cached chain template, identified structurally.
ptwm.preprocessing.CacheEntry.__init__
python/ptwm/preprocessing/_cache.py:1def __init__(self, internal_dtype: int, ops: tuple[int, ...], byte_split_planes: int) -> Noneptwm.preprocessing.CacheEntry.byte_split_planes
python/ptwm/preprocessing/_cache.py:50byte_split_planes: intptwm.preprocessing.CacheEntry.internal_dtype
python/ptwm/preprocessing/_cache.py:48internal_dtype: intptwm.preprocessing.CacheEntry.ops
python/ptwm/preprocessing/_cache.py:49ops: tuple[int, ...]ptwm.preprocessing.CacheEntry.to_builder
python/ptwm/preprocessing/_cache.py:52def to_builder(self) -> ChainBuilderptwm.preprocessing.Chain
python/ptwm/preprocessing/_chains.py:170class Chain:ptwm.preprocessing.CHAIN_BF16_SPLIT
python/ptwm/preprocessing/_chains.py:851CHAIN_BF16_SPLIT: ChainBuilder = _bf16_split_chainBF16 / FP16 standard: BitReorderIeee16 + ByteSplit(n=2).
ptwm.preprocessing.CHAIN_BYTE_PASSTHROUGH_VALUE
python/ptwm/preprocessing/_chains.py:925CHAIN_BYTE_PASSTHROUGH_VALUE: ChainBuilder = _u8_byte_passthrough_value_chainUint8 standard passthrough.
ptwm.preprocessing.CHAIN_F32_GLOBAL_SCALE
python/ptwm/preprocessing/_chains.py:919CHAIN_F32_GLOBAL_SCALE: ChainBuilder = _fp32_global_scale_chainFP32 global-scale passthrough (NVFP4 input_scale tensors).
ptwm.preprocessing.CHAIN_F8E4M3_NIBBLE
python/ptwm/preprocessing/_chains.py:914CHAIN_F8E4M3_NIBBLE: ChainBuilder = _fp8e4m3_nibble_chainptwm.preprocessing.CHAIN_F8E4M3_SCALE_PASSTHROUGH
python/ptwm/preprocessing/_chains.py:910CHAIN_F8E4M3_SCALE_PASSTHROUGH: ChainBuilder = _fp8e4m3_scale_passthrough_chainFP8 E4M3FN scale-block passthrough (enables O1SAC on block-scale tensors).
ptwm.preprocessing.CHAIN_FP32_SPLIT
python/ptwm/preprocessing/_chains.py:863CHAIN_FP32_SPLIT: ChainBuilder = _fp32_split_chainFP32 standard: BitReorderIeee32 + ByteSplit(n=4).
ptwm.preprocessing.CHAIN_FP4_NIBBLE_PASSTHROUGH
python/ptwm/preprocessing/_chains.py:922CHAIN_FP4_NIBBLE_PASSTHROUGH: ChainBuilder = _fp4_passthrough_chainPacked FP4 values passthrough (enables PerGroupCodebook).
ptwm.preprocessing.CHAIN_FP8E4M3_NIBBLE
python/ptwm/preprocessing/_chains.py:904CHAIN_FP8E4M3_NIBBLE: ChainBuilder = _fp8e4m3_nibble_chainFP8 E4M3FN standard: BitReorderFp8E4M3 + NibbleSplit.
ptwm.preprocessing.CHAIN_FP8E5M2_NIBBLE
python/ptwm/preprocessing/_chains.py:907CHAIN_FP8E5M2_NIBBLE: ChainBuilder = _fp8e5m2_nibble_chainFP8 E5M2 standard: BitReorderFp8E5M2 + NibbleSplit.
ptwm.preprocessing.CHAIN_U8_SCALE_PASSTHROUGH
python/ptwm/preprocessing/_chains.py:916CHAIN_U8_SCALE_PASSTHROUGH: ChainBuilder = _u8_scale_passthrough_chainUint8 scale-block passthrough (MXFP4 E8M0 scales).
ptwm.preprocessing.Chain.__init__
python/ptwm/preprocessing/_chains.py:1def __init__(self, nodes: list[ChainNode], edges: list[ChainEdge], terminals: list[TerminalRef]) -> Noneptwm.preprocessing.Chain.edges
python/ptwm/preprocessing/_chains.py:173edges: list[ChainEdge]ptwm.preprocessing.Chain.nodes
python/ptwm/preprocessing/_chains.py:172nodes: list[ChainNode]ptwm.preprocessing.Chain.terminals
python/ptwm/preprocessing/_chains.py:174terminals: list[TerminalRef]ptwm.preprocessing.Chain.to_bytes
python/ptwm/preprocessing/_chains.py:176def to_bytes(self) -> bytesSerialise to the wire format consumed by ``compress_model``.
ptwm.preprocessing.ChainBuilder
python/ptwm/preprocessing/_chains.py:277ChainBuilder = Callable[[list[int]], Chain | None]ptwm.preprocessing.ChainEdge
python/ptwm/preprocessing/_chains.py:153class ChainEdge:ptwm.preprocessing.ChainEdge.__init__
python/ptwm/preprocessing/_chains.py:1def __init__(self, src_node: int, src_output_idx: int, dst_node: int, dst_input_idx: int, role_override: bytes | None = None, vendor_bytes: bytes = b'') -> Noneptwm.preprocessing.ChainEdge.dst_input_idx
python/ptwm/preprocessing/_chains.py:158dst_input_idx: intptwm.preprocessing.ChainEdge.dst_node
python/ptwm/preprocessing/_chains.py:157dst_node: intptwm.preprocessing.ChainEdge.role_override
python/ptwm/preprocessing/_chains.py:159role_override: bytes | None = Noneptwm.preprocessing.ChainEdge.src_node
python/ptwm/preprocessing/_chains.py:155src_node: intptwm.preprocessing.ChainEdge.src_output_idx
python/ptwm/preprocessing/_chains.py:156src_output_idx: intptwm.preprocessing.ChainEdge.vendor_bytes
python/ptwm/preprocessing/_chains.py:160vendor_bytes: bytes = field(default=b'')ptwm.preprocessing.ChainNode
python/ptwm/preprocessing/_chains.py:147class ChainNode:ptwm.preprocessing.ChainNode.__init__
python/ptwm/preprocessing/_chains.py:1def __init__(self, op_id: int, params: bytes = b'') -> Noneptwm.preprocessing.ChainNode.op_id
python/ptwm/preprocessing/_chains.py:149op_id: intptwm.preprocessing.ChainNode.params
python/ptwm/preprocessing/_chains.py:150params: bytes = field(default=b'')ptwm.preprocessing.chains_for
python/ptwm/preprocessing/_chains.py:1029def chains_for(dtype_code: int, role: ClassifierRole) -> list[ChainBuilder]Return the chain builders for ``(dtype_code, role)``.
ptwm.preprocessing.ClassifierRole
python/ptwm/preprocessing/_chains.py:263class ClassifierRole(IntEnum):Tensor role used as the second key in :data:`PRODUCTION_CHAINS`.
ptwm.preprocessing.ClassifierRole.PACKED_VALUES
python/ptwm/preprocessing/_chains.py:269PACKED_VALUES = 3ptwm.preprocessing.ClassifierRole.SCALE_BLOCK
python/ptwm/preprocessing/_chains.py:267SCALE_BLOCK = 1ptwm.preprocessing.ClassifierRole.SCALE_GLOBAL
python/ptwm/preprocessing/_chains.py:268SCALE_GLOBAL = 2ptwm.preprocessing.ClassifierRole.STANDARD
python/ptwm/preprocessing/_chains.py:266STANDARD = 0ptwm.preprocessing.clear_cache
python/ptwm/preprocessing/_cache.py:164def clear_cache() -> intDelete every cache file. Returns the number of files removed.
ptwm.preprocessing.explore_chains
python/ptwm/preprocessing/_explorer.py:281def explore_chains(dtype_code: int, role: ClassifierRole, opts: ExploreOptions | None = None) -> Iterator[ChainBuilder]Enumerate legal chain builders for *(dtype_code, role)*.
ptwm.preprocessing.ExploreOptions
python/ptwm/preprocessing/_explorer.py:75class ExploreOptions:Search-bound configuration for the generative explorer.
ptwm.preprocessing.ExploreOptions.__init__
python/ptwm/preprocessing/_explorer.py:1def __init__(self, max_nodes: int = 8, max_depth: int = 5, max_candidates_per_dtype: int = 32, allow_cross_tensor: bool = False, allow_cross_plane: bool = False, time_budget_ms: int = 5000) -> Noneptwm.preprocessing.ExploreOptions.allow_cross_plane
python/ptwm/preprocessing/_explorer.py:83allow_cross_plane: bool = Falseptwm.preprocessing.ExploreOptions.allow_cross_tensor
python/ptwm/preprocessing/_explorer.py:82allow_cross_tensor: bool = Falseptwm.preprocessing.ExploreOptions.max_candidates_per_dtype
python/ptwm/preprocessing/_explorer.py:81max_candidates_per_dtype: int = 32ptwm.preprocessing.ExploreOptions.max_depth
python/ptwm/preprocessing/_explorer.py:80max_depth: int = 5ptwm.preprocessing.ExploreOptions.max_nodes
python/ptwm/preprocessing/_explorer.py:79max_nodes: int = 8ptwm.preprocessing.ExploreOptions.time_budget_ms
python/ptwm/preprocessing/_explorer.py:84time_budget_ms: int = 5000ptwm.preprocessing.is_legal_chain
python/ptwm/preprocessing/_explorer.py:92def is_legal_chain(chain: Chain, opts: ExploreOptions | None = None) -> boolReturn ``True`` iff *chain* passes all 10 pruning rules.
ptwm.preprocessing.load_cached_builders
python/ptwm/preprocessing/_cache.py:132def load_cached_builders(dtype_code: int, role: ClassifierRole) -> list[ChainBuilder]Return runtime `ChainBuilder`s for cached entries of `(dtype_code, role)`.
ptwm.preprocessing.load_cached_entries
python/ptwm/preprocessing/_cache.py:119def load_cached_entries(dtype_code: int, role: ClassifierRole) -> list[CacheEntry]Return cached entries for `(dtype_code, role)`, or `[]` on miss / corruption.
ptwm.preprocessing.Plane
python/ptwm/preprocessing/_plane.py:8class Plane:One plane produced by the preprocessing pipeline.
ptwm.preprocessing.Plane.__init__
python/ptwm/preprocessing/_plane.py:1def __init__(self, id: int, role: str, data: bytes) -> Noneptwm.preprocessing.Plane.data
python/ptwm/preprocessing/_plane.py:20data: bytesptwm.preprocessing.Plane.id
python/ptwm/preprocessing/_plane.py:18id: intptwm.preprocessing.Plane.role
python/ptwm/preprocessing/_plane.py:19role: strptwm.preprocessing.PRODUCTION_CHAINS
python/ptwm/preprocessing/_chains.py:969PRODUCTION_CHAINS: dict[tuple[int, ClassifierRole], list[ChainBuilder]] = {(_DT.FLOAT8_E4M3FN.code, ClassifierRole.SCALE_BLOCK): [CHAIN_F8E4M3_SCALE_PASSTHROUGH, CHAIN_F8E4M3_NIBBLE], (_DT.UINT8.code, ClassifierRole.SCALE_BLOCK): [CHAIN_U8_SCALE_PASSTHROUGH], (_DT.FLOAT32.code, ClassifierRole.SCALE_GLOBAL): [CHAIN_F32_GLOBAL_SCALE], (_DT.FLOAT4_E2M1FN_X2.code, ClassifierRole.PACKED_VALUES): [CHAIN_FP4_NIBBLE_PASSTHROUGH], (_DT.BFLOAT16.code, ClassifierRole.STANDARD): [CHAIN_BF16_SPLIT, CHAIN_BF16_SPLIT_INTDELTA, CHAIN_BF16_SPLIT_PREDICTOR_XOR, CHAIN_BF16_MICROSCALE_REPACK, CHAIN_BF16_SPLIT_MZS_K1, CHAIN_BF16_SPLIT_MZS_K2, CHAIN_BF16_SPLIT_MZS_K3, CHAIN_BF16_SPLIT_MZS_K4, CHAIN_BF16_SPHERICAL_NORMALIZE, CHAIN_BF16_ALPHA_STABLE_NORMALIZE, CHAIN_BF16_HUFF_LLM_RAW], (_DT.FLOAT16.code, ClassifierRole.STANDARD): [CHAIN_BF16_SPLIT, CHAIN_BF16_SPLIT_INTDELTA, CHAIN_BF16_SPLIT_PREDICTOR_XOR, CHAIN_BF16_SPLIT_MZS_K1, CHAIN_BF16_SPLIT_MZS_K2, CHAIN_BF16_SPLIT_MZS_K3, CHAIN_BF16_SPLIT_MZS_K4, CHAIN_FP16_SPHERICAL_NORMALIZE, CHAIN_FP16_ALPHA_STABLE_NORMALIZE, CHAIN_FP16_HUFF_LLM_RAW], (_DT.FLOAT32.code, ClassifierRole.STANDARD): [CHAIN_FP32_SPLIT, CHAIN_FP32_SPLIT_INTDELTA, CHAIN_FP32_SPLIT_PREDICTOR_XOR, CHAIN_FP32_SPLIT_MZS_K1, CHAIN_FP32_SPLIT_MZS_K2, CHAIN_FP32_SPLIT_MZS_K3, CHAIN_FP32_SPLIT_MZS_K4, CHAIN_FP32_SPHERICAL_NORMALIZE, CHAIN_FP32_ALPHA_STABLE_NORMALIZE], (_DT.FLOAT8_E4M3FN.code, ClassifierRole.STANDARD): [CHAIN_FP8E4M3_NIBBLE], (_DT.FLOAT8_E5M2.code, ClassifierRole.STANDARD): [CHAIN_FP8E5M2_NIBBLE], (_DT.UINT8.code, ClassifierRole.STANDARD): [CHAIN_BYTE_PASSTHROUGH_VALUE]}ptwm.preprocessing.save_cached_entries
python/ptwm/preprocessing/_cache.py:137def save_cached_entries(dtype_code: int, role: ClassifierRole, new_entries: Iterable[CacheEntry]) -> intUnion `new_entries` with the existing cache file. Returns count added.
ptwm.preprocessing.TerminalRef
python/ptwm/preprocessing/_chains.py:163class TerminalRef:ptwm.preprocessing.TerminalRef.__init__
python/ptwm/preprocessing/_chains.py:1def __init__(self, node_idx: int, output_idx: int, role: bytes) -> Noneptwm.preprocessing.TerminalRef.node_idx
python/ptwm/preprocessing/_chains.py:165node_idx: intptwm.preprocessing.TerminalRef.output_idx
python/ptwm/preprocessing/_chains.py:166output_idx: intptwm.preprocessing.TerminalRef.role
python/ptwm/preprocessing/_chains.py:167role: bytes