Skip to main content

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

  1. Clone this repository
  2. Create a new virtualenv and activate it
  3. (optional) Download PyTorch wheel suited to your needs
  4. 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

Bielik teaching GPT-2 Polish grammar

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"

Sample response after 10 training epochs (740 steps)

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

  1. Hard target distillation
  2. Easy inference with the distilled weights
  3. PyTorch support
  4. Caching of generated targets
  5. Automatic cloning of teacher architecture's chat template
  6. Q&A dataset conversion into chat format

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microbrewery-0.1.0rc1.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

microbrewery-0.1.0rc1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for microbrewery-0.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 9161c432c8638f2fd0ced82c93b241120c92974c924a5d0427be392eafc9fad0
MD5 82c6bef770e859aadeebf83be19c2644
BLAKE2b-256 9ac667a43b4b16ec2856d2a60ef356c249f35e1f5b9f71516b97b7617f825a7a

See more details on using hashes here.

File details

Details for the file microbrewery-0.1.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for microbrewery-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a869c3e92afc2e20feedc63279eab7f042fa0eb4754da0c85f2d92bba3ab3d1
MD5 dccd38fe6efd58fbecfe2e785385c386
BLAKE2b-256 5da4b6cb30e31bf2f83b0e653b884c153a32a16e21cf37adb41c4bf7fb84990b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page