Keras layers without using matrix multiplications.
Project description
Keras-MatMulLess (Keras-MML)
We offer no explanation as to why these architectures seem to work; we attribute their success, as all else, to divine benevolence.
— Noam Shazeer, in GLU Variants Improve Transformer
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.
- 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.
- The memory use for storing full precision weights is very high.
- 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
- Python 3.9 (or above);
- Keras; and
- the Keras backend (either Tensorflow, PyTorch, or Jax).
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; andjax
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file keras_matmulless-0.1.1.tar.gz
.
File metadata
- Download URL: keras_matmulless-0.1.1.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cc6407975766ce2f3083bbf7dd746dcf0997abc3a110f7662a76b85b6763f5b |
|
MD5 | 70932fbe69d50e0f5ad405af6a006641 |
|
BLAKE2b-256 | c2225a4777f60532a420273c0336b0981071d1e669f64b3e2c51846bc0fe7a2a |
File details
Details for the file keras_matmulless-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: keras_matmulless-0.1.1-py3-none-any.whl
- Upload date:
- Size: 44.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce63ff38c62bb508c4f0e995a10d18e9d67451aa4383f735b1e0e81ba8e8a2e8 |
|
MD5 | 3147445cca3c9d5248a96662cd4db2a3 |
|
BLAKE2b-256 | a51cfd84cb81629d0d9ef1744808b349f1aea6a41e268646e1168c40e2afd4a4 |