Skip to main content

Zenbit

TPU sharding and quantization utilities for PyTorch/XLA training. Built as a companion to ZAdapter, but usable standalone for any PyTorch/XLA training setup.

Install

pip install zenbit[tpu]

The [tpu] extra pulls in torch_xla. Without it, quantization utilities (int8, NF4) still work on CPU/GPU for offline testing — only the sharding/tensor-parallel pieces require an actual TPU runtime.

What's inside

  • zenbit.int8 — uniform int8 weight quantization (~50% memory savings vs fp16)
  • zenbit.nf4 — NF4 blockwise quantization with double quantization, QLoRA-style (~75-89% memory savings vs fp32)
  • zenbit.sharding — data-parallel training loop utilities: device detection, dataset sharding, gradient sync, checkpointing, logging
  • zenbit.tensor_parallel — SPMD tensor parallel sharding (Megatron-style column/row parallel linear layers) for models too large to replicate on a single TPU core

Quick example

from transformers import AutoModelForCausalLM
from zadapter import inject_adapter
from zenbit import quantize_model_nf4, NF4Config, train_loop, TrainConfig

model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-7B")
model = quantize_model_nf4(model, NF4Config(double_quant=True))
model = inject_adapter(model, r=64)

train_loop(model, train_dataset, loss_fn, TrainConfig(lr=1e-4, num_epochs=3))

For models too large for a single TPU core (30B+), combine with tensor parallel:

from zenbit import setup_spmd_mesh, build_tp_zadapter_model, TPConfig

mesh = setup_spmd_mesh(TPConfig(num_shards=8))
model = build_tp_zadapter_model(model, mesh)

Design notes

  • Why data-parallel by default: adapter parameters are small (~0.5-3% of the model), so gradient sync overhead is minimal. Data parallel keeps communication to one all-reduce per step, avoiding the per-layer communication overhead of full model parallelism.
  • Why tensor parallel is opt-in: it's necessary once the base model no longer fits on a single TPU core's HBM (roughly 30B+ params even with NF4 quantization), but comes with real communication overhead per layer. Use it only when the model size requires it.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zenbit-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zenbit-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file zenbit-0.1.0.tar.gz.

File metadata

  • Download URL: zenbit-0.1.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for zenbit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2f45bbbb92552e6557d7a71377fd082c4d2a39606e26274d6c2a38ac45891eec
MD5 f64d8b90145997d34132864ca1d72da7
BLAKE2b-256 30257839597685f9b457a958cb321e4746b2158dc4c641ebbad952e18a96af37

See more details on using hashes here.

File details

Details for the file zenbit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zenbit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for zenbit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3bb6d2b1733a1bd82226ecb03e38a8e33e7e9141780ecdcc295798ea53afa8cd
MD5 278297b6d5b58a59edbefb3151a15aa6
BLAKE2b-256 d7306122f756bc91d621c23a007ef57437153ff4f4c2546cbf897a39399fed34

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.0

2 files

0.4.0

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page