Skip to main content

ZAdapter

TPU-native bottleneck FFN adapter for parameter-efficient fine-tuning.

Unlike LoRA (parallel low-rank matrices merged into existing weights), ZAdapter injects a small bottleneck feed-forward block serially after attention and MLP in each transformer layer. This keeps the computation graph static — no merge/unmerge step, no dynamic branching — which plays well with XLA compilation on TPU.

input -> down_proj [d_model -> r] -> activation -> up_proj [r -> d_model] -> output
output = input + adapter(input)

Install

pip install zadapter

Usage

from transformers import AutoModelForCausalLM
from zadapter import inject_adapter, get_trainable_params

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

trainable_params = get_trainable_params(model)
optimizer = torch.optim.AdamW(trainable_params, lr=1e-4)

Why not LoRA

LoRA ZAdapter
Injection Parallel to existing weight Serial FFN block
Mergeable Yes (zero inference overhead after merge) No
Graph Dynamic (merge/unmerge) Static, XLA-friendly
Trainable params ~0.1-1% ~0.5-3%

ZAdapter trades a slightly larger parameter count and a small inference overhead for a simpler, more XLA-friendly training graph — useful when targeting TPU where static graphs compile more predictably.

Companion library

For TPU sharding (data-parallel, tensor-parallel) and quantization (int8, NF4) to use alongside ZAdapter, see zenbit.

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

zadapter-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

zadapter-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for zadapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e57fec9b77cfe81460b08c9bb3d2d5d9ae9f49abef34e73571594f8ad583dbf1
MD5 5cb24d0ff2047515d6117c436db157b6
BLAKE2b-256 2adecc29be5c421f85889883287e8cf74b9d26157df389bae92ff94729549748

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for zadapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de7f1d2a7f659bc3a1cf3752ce47cc202e6d3474f4e3b5c544982022c2f65e53
MD5 5ccaba2ff82caac737ec20c25ba80578
BLAKE2b-256 5509d65cd3cf98e769a7ce7d57f72624ed39ee646e6dc94229bf1e555aec108c

See more details on using hashes here.

Release history Release notifications | RSS feed

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