Skip to main content

Keras layers without using matrix multiplications.

Project description

Keras-MatMulLess (Keras-MML)

PyPI - Python Version PyPI - Version PyPI - Downloads PyPI - License

Read the Docs - Stable Read the Docs - Latest

CodeCov Code Style - Black Linting - Ruff

Contributor Covenant

We offer no explanation as to why these architectures seem to work; we attribute their success, as all else, to divine benevolence.

Keras layers without using matrix multiplications.

This is a Keras based implementation of some layers mentioned in the papers The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits and Scalable MatMul-free Language Modeling. Find the documentation here.

Rationale

Traditional, matrix multiplication based layers suffer from a few issues.

  1. They have high inference and computational costs due to the use of matrix multiplications. This hinders the speed at which inference is performed on GPU-less machines.
  2. The memory use for storing full precision weights is very high.
  3. The energy costs of running matrix multiplications is very high.

Matrix multiplication free layers addresses these pain points by removing the key source of costs — matrix multiplications.

Installation

Requirements

Keras-MML has a few requirements, namely

Instructions on how to install Keras can be found here.

Installation Instructions

PyPi

If you use pip, you can install Keras-MML using the command

pip install keras-matmulless
Pre-Release Versions

To install pre-release versions, use the command

pip install --pre keras-matmulless
Nightly Versions

Nightly releases for Keras-MML are primarily found on the TestPyPi page. To install them, use the command

pip install -i https://test.pypi.org/simple/ keras-matmulless

Building From Scratch

First, clone the repository using

git clone https://github.com/PhotonicGluon/Keras-MatMulLess.git
cd Keras-MatMulLess

We recommend to create a virtual environment to install Poetry and the other dependencies into.

python -m venv venv  # If `python` doesn't work, try `python3`

Activate the virtual environment using

source venv/bin/activate

or, if you are on Windows,

venv/Scripts/activate

Now we install Poetry.

pip install poetry

Finally, install the development dependencies. The development dependencies are split into several groups.

  • The test group contains dependencies that are used to perform testing.
  • The docs group contains dependencies that are used to generate the documentation.
  • The build group contains dependencies that are used to create a distributable.
  • The notebook group is required to run the Jupyter notebooks in the documentation folder.

Simply include the desired groups in the install.py call. For example, to install test, docs, and build (the main development dependencies), run the following command.

python install.py test docs build

If you have not installed a backend (i.e., Tensorflow, PyTorch, or Jax) you can do so here.

python install.py test docs build --backend BACKEND_NAME

Note that the BACKEND_NAME to be specified here is

  • tensorflow for the Tensorflow backend;
  • torch for the PyTorch backend; and
  • jax for the Jax backend.

If you need to install with CUDA support, run

python install.py test docs build --backend BACKEND_NAME --with-cuda

That's it! You should now have access to the keras_mml package.

Quickstart

Read the tutorial.

Contributing

We welcome contributions! Please read more about contributing to Keras-MML in the contribution guidelines.

License

Keras-MML is licensed under the Apache 2.0 license.

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

keras_matmulless-0.1.2.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

keras_matmulless-0.1.2-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file keras_matmulless-0.1.2.tar.gz.

File metadata

  • Download URL: keras_matmulless-0.1.2.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for keras_matmulless-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ef5eec3b5b20f94b7a0a68240534c3b169bf393ef67a5f12bfbcbc01dc178751
MD5 3e3d28dd187289ac7a53882a61d302d5
BLAKE2b-256 f9a96614752f3f6f8cb7df364bc9c69030603913388a34ed22768cf67c79ad9f

See more details on using hashes here.

File details

Details for the file keras_matmulless-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for keras_matmulless-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54223c69c5b728a98f2a4587abf3ab69064be3afcd3861297a54ef5a4d431907
MD5 f9cfe93c692fed08acef9e2f186989fb
BLAKE2b-256 32955a451974fd6a408f09ab8b927dbadae6a5775aa284e4c99dc63d8b07336e

See more details on using hashes here.

Supported by

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