Skip to main content

An production-ready implementation of 1.58 bit quantization-aware training and inference.

Project description

bitlinear

This project aims to provide a production-ready implementation of 1.58-bit layers for quantization-aware training and time-, memory-, and energy-efficient inference. It builds on the ideas from The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits.

installation

Installation from PyPI:

pip install bitlinear

Installation from source:

git clone https://github.com/schneiderkamplab/bitlinear
cd bitlinear
pip install .

usage

The usage is best explained by a short example:

from bitlinear import replace_modules
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("HuggingFaceM4/tiny-random-LlamaForCausalLM")
replace_modules(model)

More elaborate examples are available under examples/classifier, including training and evaluating a binary classifer:

pip install -r examples/classifier/requirements.txt
python examples/classifier/train.py
python examples/classifier/eval.py

There is also an MNIST classifier:

pip install -r examples/classifier/requirements.txt
python examples/mnist/train.py

comparison to other work

There are other implementations of bit-linear layers, most of which get at least some of the details wrong at the time of this writing (April 2024).

The focus of this implementation is to develop:

  • a flexible production-ready drop-in replacemenbt for torch.nn.LinearLayer,
  • efficient fused kernels for training, and
  • efficient fused kernels for inference with 2-bit weights and 8-bit activations.

Furthermore, this implementation is meant to serve as a testbed for research on low-bit quantization aware training and inference.

future work

  • further examples (vision, llm)
  • efficient fused kernels for GPU/AVX/CPU training
  • efficient fused kernels for GPU/AVX/CPU inferenc

Project details


Download files

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

Source Distribution

bitlinear-2.0.1.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file bitlinear-2.0.1.tar.gz.

File metadata

  • Download URL: bitlinear-2.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for bitlinear-2.0.1.tar.gz
Algorithm Hash digest
SHA256 c97a6c6f932f0b39b4e3ddabd1e36ed2fc545835ff116914980825c51cdb08be
MD5 f56b6908d9f5579a6e5e6e6b67613159
BLAKE2b-256 2aafc6bdcb6e53571077f2d39ac99aee23b3d799ed8bb2895adf489e91bf6c73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page