/efficient-transformers

This library empowers users to seamlessly port pretrained models and checkpoints on the HuggingFace (HF) hub (developed using HF transformers library) into inference-ready formats that run efficiently on Qualcomm Cloud AI 100 accelerators.

Primary LanguagePythonOtherNOASSERTION

alt text


Efficient Transformers Library


Latest news 🔥

  • [coming soon] Support for more popular models and inference optimization techniques like continuous batching and speculative decoding

Overview

Train anywhere, Infer on Qualcomm Cloud AI with a Developer-centric Toolchain

This library provides reimplemented blocks of LLMs which are used to make the models functional and highly performant on Qualcomm Cloud AI 100. There are several models which can be directly transformed from a pre-trained original form to a deployment ready optimized form. For other models, there is comprehensive documentation to inspire upon the changes needed and How-To(s).

Typically for LLMs, the library provides:

  1. Reimplemented blocks from Transformers which enable efficient on-device retention of intermediate states.
  2. Graph transformations to enable execution of key operations in lower precision
  3. Graph transformations to replace some operations to other mathematically equivalent operations
  4. Handling for under-flows and overflows in lower precision
  5. Patcher modules to map weights of original model's operations to updated model's operations
  6. Exporter module to export the model source into a ONNX Graph.
  7. Sample example applications and demo notebooks
  8. Unit test templates.

It is mandatory for each Pull Request to include tests such as:

  1. If the PR is for adding support for a model, the tests should include successful execution of the model post changes (the changes included as part of PR) on Pytorch and ONNXRT. Successful exit criteria is MSE between output of original model and updated model.
  2. If the PR modifies any common utilities, tests need to be included to execute tests of all models included in the library.

Quick Installation

# Create Python virtual env and activate it. (Required Python 3.8)

python3.8 -m venv qeff_env
source qeff_env/bin/activate
pip install -U pip

# Clone and Install the QEfficient Repo.
pip install git+https://github.com/quic/efficient-transformers

# Or build wheel package using the below command.
pip install build wheel
python -m build --wheel --outdir dist
pip install dist/QEfficient-0.0.1.dev0-py3-none-any.whl

For more details about using QEfficient via Cloud AI 100 Apps SDK, visit Linux Installation Guide

Documentation

Note: More details are here: https://quic.github.io/cloud-ai-sdk-pages/latest/Getting-Started/Model-Architecture-Support/Large-Language-Models/llm/

Acknowledgements

Thanks to:

  • HuggingFace transformers for work in LLM GenAI modeling implementation
  • ONNX, Pytorch, ONNXruntime community.

Support

If you run into any problems with the code, please file Github issues directly to this repo.

Contributing

This project welcomes contributions and suggestions. Please check the License. Integration with a CLA Bot is underway.