Skip to main content

PolyLoRA

Minimal PyTorch runtime for batched LoRA inference where each row can use a different adapter.

PolyLoRA wraps an existing torch.nn.Module, replaces selected nn.Linear layers, and serves PEFT LoRA adapters from CPU, GPU, and optional disk caches.

Install

pip install .

With PEFT loading support:

pip install '.[peft]'

Usage

from polylora import PolyLoraConfig, PolyLoraModel

model = PolyLoraModel(
    base_model,
    PolyLoraConfig(
        max_gpu_adapters=4,
        max_rank=16,
        target_modules=["query_proj", "key_proj", "value_proj", "dense"],
    ),
).eval()

model.load_adapter_from_disk("legal", "./adapters/legal")
model.load_adapter_from_disk("finance", "./adapters/finance")

outputs = model(**batch, adapter_ids=["legal", "finance"])

Omit adapter_ids to run the base model. Use __base__ for rows that should skip LoRA inside a mixed batch.

Caches

PolyLoRA uses three adapter tiers:

  • GPU cache: fixed-size adapter slots for the active batch. Slot 0 is reserved for __base__, so non-adapter rows share the same execution path.
  • CPU cache: LRU store for loaded adapter weights. GPU evictions can reload from CPU without touching disk.
  • Disk cache: optional bounded PEFT adapter directory cache. CPU misses can reload adapters from this cold layer.

This makes small hot sets fast while still allowing a larger adapter catalog than GPU memory can hold.

Kernels

On CUDA, PolyLoRA uses Triton SGMV kernels for the LoRA A and B projections:

  • Mixed batches can contain different adapter ids, including __base__ rows.
  • Different adapters may use different ranks, up to max_rank.
  • Rank-0 rows skip adapter work, which is how base-only rows and missing layer weights are represented.
  • The B projection fuses scaling and add-back into the base linear output.
  • The implementation falls back to a PyTorch reference path on CPU or when Triton is disabled.

Adapter Layouts

Adapters do not need to cover every wrapped layer. If a model is wrapped with a larger target_modules set and an adapter only contains LoRA weights for some of those layers, missing layers are treated as rank-0 no-ops for that adapter.

PolyLoRA rejects adapters with weights outside the configured module set, which keeps mixed adapters predictable when different adapters target different subsets of the model.

Notes

  • Supports standard PEFT LoRA adapters for inference.
  • Does not support LoRA dropout, DoRA, RS-LoRA, or LoRA bias.
  • Attention masks must be right padded when enforce_right_padding=True.

Development

pip install -e '.[dev]'
pytest tests

Metadata

Release files for polylora 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polylora 0.1.2
File Size Uploaded Provenance Actions
polylora-0.1.2.tar.gz 32.5 kB Without provenance Details for polylora-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polylora 0.1.2
File Interpreter ABI Platform Actions
polylora-0.1.2-py3-none-any.whl Python 3 none any Details for polylora-0.1.2-py3-none-any.whl

Total release size: 55.0 kB

Release files / polylora-0.1.2.tar.gz

Download URL polylora-0.1.2.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
595854cb6bdeba30f3904fd4944b35a4806bf785bcc30465c3e59491992338fb
BLAKE2b-256 checksum
How to use checksums
8903b1894bd6df16ab7f52562e3925b037bfa6005cb61854689fc345adbcccd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / polylora-0.1.2-py3-none-any.whl

Download URL polylora-0.1.2-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b826ad3a7500c52d8413e78a5a36d61509acf8846fbaa106507be26518e4c7c
BLAKE2b-256 checksum
How to use checksums
15a7153b8a2d7a57c54519ea33d31769ed2807009a982e5c4ae5dbedb3c1ae3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for polylora 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page