Tool for knowledge distillation into conversational LLMs
Project description
Microbrewery
Distill conversational models into any causal LM architecture on HuggingFace!
Installation
From PyPI
python3 -m pip install microbrewery
Manual
- Clone this repository
- Create a new virtualenv and activate it
- (optional) Download PyTorch wheel suited to your needs
pip install -r requirements.txt
You're all set
Done! You can now run microbrewery --help to see a list of available options.
Usage
CLI
Distill knowledge of the Polish language from Bielik v3.0 into GPT-2 (commands tested on RTX 3070).
microbrewery distill \
--teacher-model-path speakleash/Bielik-1.5B-v3.0-Instruct \
--student-model-path openai-community/gpt2 \
--dataset-path "Igorrr0/polish-qa-general" \
--custom-system-prompt "Jesteś ekspertem od udzielania odpowiedzi, dobrze znającym język polski. Odpowiadaj krótko, konwersacyjnie, zgodnie z prawdą." \
--completion-column-name output \
--prompt-column-name instruction \
--output-dir "./microbrewery-distilled-model" \
--max-new-tokens 128 \
--training-max-tokens 256 \
--teacher-batch-size 32 \
--cached-targets-path "./microbrewery-cached" \
--learning-rate 1e-4 \
--num-train-epochs 10 \
--gradient-accumulation-steps 1 \
--per-device-train-batch-size 4
Make sure the models are not too big and the batch size fits your VRAM.
To get a new response from the distilled model, simply run:
microbrewery infer \
--system-prompt "Jesteś ekspertem od udzielania odpowiedzi, dobrze znającym język polski. Odpowiadaj krótko, konwersacyjnie, zgodnie z prawdą." \
--user-prompt "Czy już znasz język polski?" \
--model-path "./microbrewery-distilled-model/checkpoint-740"
Library
You can also run the same functions as a Python library (e.g. in Jupyter notebooks).
Simply put from microbrewery import distill, finetune, infer in your code.
Features
- Hard target distillation
- Easy inference with the distilled weights
- PyTorch support
- Caching of generated targets
- Automatic cloning of teacher architecture's chat template
- Q&A dataset conversion into chat format
License
This project is licensed under the MIT 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
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 microbrewery-0.1.0rc1.tar.gz.
File metadata
- Download URL: microbrewery-0.1.0rc1.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9161c432c8638f2fd0ced82c93b241120c92974c924a5d0427be392eafc9fad0
|
|
| MD5 |
82c6bef770e859aadeebf83be19c2644
|
|
| BLAKE2b-256 |
9ac667a43b4b16ec2856d2a60ef356c249f35e1f5b9f71516b97b7617f825a7a
|
File details
Details for the file microbrewery-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: microbrewery-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a869c3e92afc2e20feedc63279eab7f042fa0eb4754da0c85f2d92bba3ab3d1
|
|
| MD5 |
dccd38fe6efd58fbecfe2e785385c386
|
|
| BLAKE2b-256 |
5da4b6cb30e31bf2f83b0e653b884c153a32a16e21cf37adb41c4bf7fb84990b
|