Skip to main content

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.

Metadata

Release files for keras-matmulless 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 keras-matmulless 0.1.2
File Size Uploaded Provenance Actions
keras_matmulless-0.1.2.tar.gz 28.6 kB Without provenance Details for keras_matmulless-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 73.6 kB

Release files / keras_matmulless-0.1.2.tar.gz

Download URL keras_matmulless-0.1.2.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ef5eec3b5b20f94b7a0a68240534c3b169bf393ef67a5f12bfbcbc01dc178751
BLAKE2b-256 checksum
How to use checksums
f9a96614752f3f6f8cb7df364bc9c69030603913388a34ed22768cf67c79ad9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

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

Download URL keras_matmulless-0.1.2-py3-none-any.whl
Size 45.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54223c69c5b728a98f2a4587abf3ab69064be3afcd3861297a54ef5a4d431907
BLAKE2b-256 checksum
How to use checksums
32955a451974fd6a408f09ab8b927dbadae6a5775aa284e4c99dc63d8b07336e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for keras-matmulless 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