The df11pack compressor as a Python function, for programs that would otherwise call
the command through subprocess. Same encoder and defaults as the command;
tests/test_binding.py checks that the output equals the command's, file by file, on a
small synthetic Qwen3 model.
import df11pack
# a built-in definition by name (df11pack.architectures() lists them)
df11pack.compress("lumina_2_model_bf16.safetensors", "out/", arch="lumina2-comfyui")
# a pattern_dict given at call time, in the official compressor's form
PD = {r"double_blocks\.\d+": ["img_mod.lin", "img_attn.qkv"], ...}
df11pack.compress("model.safetensors", "out/", pattern_dict=PD, layout="comfyui-native")
# tensors already in memory (e.g. a merged model): written to a temporary safetensors
# file next to `out`, compressed, then removed; needs torch and safetensors
df11pack.compress_state_dict(model.state_dict(), "out/", pattern_dict=PD, layout="comfyui-native")layout is one of transformers, diffusers, diffusers-single, comfyui-native
(docs/DEFINITIONS.md in the repository). Options: safe=True (decode every unit and
check it against the source before writing), ram="16G", workers=N, and for a
pattern_dict file= and keys= as in a TOML definition. A wrong argument type raises
TypeError; a bad definition, option or input raises ValueError.
The call releases the GIL while it runs.
compress_state_dict writes the tensors to disk first (as much space as the BF16
tensors take): the compressor reads safetensors files. Needs torch, safetensors and
numpy (pip install .[torch]). The names must be the ones the
definition expects; tensors that share memory (tied weights) are refused, keep one.
DF11PACK_ARCH_DIR adds or overrides definitions by name, as for the command.
Not on PyPI. From this directory, with Rust and maturin installed:
pip install maturin
maturin build --release # a wheel in target/wheels/
# or, into the current virtual environment:
maturin develop --releaseTests, from the repository root, after cargo build --release (the command is the
reference): python -m unittest discover -s python/tests -v.