A collection of tricks to speed up LLMs, see our transformer-tricks papers on arXiv
Project description
Setup
pip3 install transformer-tricks
To run llama and other LLMs that need an agreement (not SmolLM), you first have to type the following, which will ask for your hf_token:
huggingface-cli login
Example
The example below converts SmolLM-135M to FlashNorm and measures perplexity of the original and the modified model.
import transformer_tricks as tt
# convert model and store the new model in ./SmolLM-135M_flashNorm
tt.flashify_repo('HuggingFaceTB/SmolLM-135M')
# run example inference of original and modified model
tt.hello_world('HuggingFaceTB/SmolLM-135M')
tt.hello_world('SmolLM-135M_flashNorm')
# measure perplexity of original and modified model
tt.perplexity('HuggingFaceTB/SmolLM-135M', speedup=16)
tt.perplexity('SmolLM-135M_flashNorm', speedup=16)
Results:
Once upon a time there was a curious little girl
Once upon a time there was a curious little girl
perplexity = 16.083
perplexity = 16.083
You can run the example in your browser by clicking on this notebook: . Hit "cancel" when it says "Notebook does not have secret access", because we don't need an HF_TOKEN for SmolLM.
Test FlashNorm
# setup
git clone https://github.com/OpenMachine-ai/transformer-tricks.git
cd python
pip3 install --quiet -r requirements.txt
# run tests
python3 flashNorm_test.py
Results:
Once upon a time there was a curious little girl
Once upon a time there was a curious little girl
Once upon a time there was a little girl named
Once upon a time there was a little girl named
perplexity = 16.083
perplexity = 16.083
perplexity = 12.086
perplexity = 12.086
Contributing
Before making a change to this repo, please do the following:
- Format your code by typing
autopep8 *.py. It's using the config inpyproject.toml. - Whenever you change
transformer_tricks.py, publish a new version of the package as follows:- First, update the version number in
pyproject.tomland inrequirements.txt - Then, push the package to PyPi by typing
./push_pypi.sh
- First, update the version number in
- Whenever you modify
flashNorm_example.py, generate the corresponding notebook as follows:jupytext --to ipynb flashNorm_example.py -o ../notebooks/flashNorm_example.ipynb sed -i -e 's/import transformer_tricks/%pip install --quiet transformer_tricks\\n", "import transformer_tricks/g' ../notebooks/flashNorm_example.ipynb
Notes on python package
Please give us a ⭐ if you like this repo, thanks!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file transformer_tricks-0.1.16.tar.gz.
File metadata
- Download URL: transformer_tricks-0.1.16.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1880899dbd1a7401b8b8cdc34c7c0559bd57a05df366864ac331bc0c4d6b992a
|
|
| MD5 |
cfcbba1db9f108924bc75721643892c7
|
|
| BLAKE2b-256 |
98ccc84fa91dfa263e969c08f47d125eb8c06e238ca957f84670d627aefe709d
|
File details
Details for the file transformer_tricks-0.1.16-py3-none-any.whl.
File metadata
- Download URL: transformer_tricks-0.1.16-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac4b4e01072a90d3ba5c070dddf96cb122379d7321d842ba17afd62e5dc83121
|
|
| MD5 |
243fdf6f82444a52ac418756c0500245
|
|
| BLAKE2b-256 |
9e806ed2ec6ae495370861632d567d41b23d270a5fa20386c1ea04ea6d60e667
|