Code Monkey home page Code Monkey logo

bitlinear's Introduction

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

bitlinear's People

Contributors

peter-sk avatar

Stargazers

 avatar Simon Opsahl avatar Xin Li avatar  avatar Sunny Gonnabathula avatar Chris Taylor avatar 152334H avatar Wei avatar Lukas Galke avatar  avatar  avatar Julian Harris avatar Nicolai van der Smagt avatar

Watchers

Lukas Galke avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.