启用 Flash Attention 2 需额外安装 flash-attn 并加 --no-build-isolation;模型默认从 Hugging Face 拉取,需提前准备权重与网络;README 中自定义配置示例用 python toolkit.py --config-path,与 pip 安装后的 llmtune 命令不一致。

LLM-Finetuning-Toolkit
georgian-ioApache-2.0活跃维护开源大模型微调工具箱,支持 LoRA 等参数高效微调,还能做消融实验和单元测试,方便快速验证 Llama2、Mistral、Falcon 等模型在分类任务上的效果。
Toolkit for fine-tuning, ablating and unit-testing open-source LLMs.
pipx install llm-toolkit
llmtune generate config
llmtune run ./config.ymlREADME 未说明具体显存要求;示例使用 Llama-2-7B、Mistral-7B、Falcon-7B 等模型,并支持 4bit 量化与 Flash Attention 2(需较新 GPU,旧卡用 float16)。
用一份 YAML 配置批量跑开源 LLM 微调、消融与测试实验的 CLI 工具
开源大模型微调工具箱,支持 LoRA 等参数高效微调,还能做消融实验和单元测试,方便快速验证 Llama2、Mistral、Falcon 等模型在分类任务上的效果。
核心能力
- 用单个 YAML 配置控制提示词、模型、优化策略与测试
- 支持在配置中列出多组提示词、模型和 LoRA 参数做消融
- 集成 LoRA 与 bitsandbytes 4bit 量化微调
- 内置 QA 指标如长度测试与词重叠测试
- 按配置哈希生成实验目录,中断后可续跑
容易踩的坑
- v0.2.3最新正式版2024-07-25 · 2024-07-25 15:15 UTC
What's Changed
- Bump requests from 2.31.0 to 2.32.0 by @dependabot in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/173
- fixing docker build command by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/177
- Adding JSON validity test by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/178
- Fixed issue where Rich cannot display non-str types by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/172
- renaming metrics from tests to metrics by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/180
- pytest CI github action by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/184
- Version bump 20240620 by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/183
- Ampere+ Comment for Older GPUs by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/185
- Moving metrics to metrics and adding pass/fail LLM tests by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/186
- pyproject.toml: bump BNB dependency by @Titus-von-Koeller in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/190
New Contributors
- @dependabot made their first contribution in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/173
- @Titus-von-Koeller made their first contribution in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/190
Full Changelog: https://github.com/georgian-io/LLM-Finetuning-Toolkit/compare/v0.2.2...v0.2.3
- v0.2.22024-05-13 · 2024-05-13 17:01 UTC
查看更新说明
What's Changed
- Update README.md by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/149
- Integrate main qa by @viveksingh-ctrl in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/131
- README edits and refactoring into contributing.md by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/156
- [Unit Tests] Introducing Unit Tests by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/162
- [Version Bumps] May 7, 2024 by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/165
- Smaller Model for Default Config by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/166
- Fix LLM QA by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/167
- bumping requirements.txt to match poetry.lock by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/168
- Update issue template to include information on GPU configuration/runtime by @SinclairHudson in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/171
New Contributors
- @viveksingh-ctrl made their first contribution in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/131
- @SinclairHudson made their first contribution in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/156
Full Changelog: https://github.com/georgian-io/LLM-Finetuning-Toolkit/compare/v0.2.1...v0.2.2
- v0.2.12024-04-10 · 2024-04-10 14:52 UTC
查看更新说明
What's Changed
- Bug Fix -
llmtune generate confignot finding the yml file by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/150
Full Changelog: https://github.com/georgian-io/LLM-Finetuning-Toolkit/compare/v0.2.0...v0.2.1
- Bug Fix -
- v0.2.02024-04-10 · 2024-04-10 14:13 UTC
查看更新说明
What's Changed
- DOCS(README.md): Fix typo by @akashsaravanan-georgian in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/138
jsonlformat support by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/136- [CLI] Generate Example
config.ymlanywhere viallmtune generate configby @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/137 - Flash Attention Implementation & Fuller Config Options by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/139
- Remove unused
acceleratecode by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/145 - Better Starter Config by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/146
- Better Handling of Logs and Warnings for UI by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/148
Full Changelog: https://github.com/georgian-io/LLM-Finetuning-Toolkit/compare/v0.1.4...v0.2.0
- v0.1.42024-04-05 · 2024-04-05 21:22 UTC
查看更新说明
This release attempts to resolve issue where README images are not showing up in PyPI
What's Changed
- README image reference update by @benjaminye in https://github.com/georgian-io/LLM-Finetuning-Toolkit/pull/128
Full Changelog: https://github.com/georgian-io/LLM-Finetuning-Toolkit/compare/v0.1.3...v0.1.4
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
LLM Finetuning Toolkit
Overview
LLM Finetuning toolkit is a config-based CLI tool for launching a series of LLM fine-tuning experiments on your data and gathering their results. From one single yaml config file, control all elements of a typical experimentation pipeline - prompts, open-source LLMs, optimization strategy and LLM testing.
Installation
pipx (recommended)
pipx installs the package and dependencies in a separate virtual environment
pipx install llm-toolkit
pip
pip install llm-toolkit
Quick Start
This guide contains 3 stages that will enable you to get the most out of this toolkit!
- Basic: Run your first LLM fine-tuning experiment
- Intermediate: Run a custom experiment by changing the components of the YAML configuration file
- Advanced: Launch series of fine-tuning experiments across different prompt templates, LLMs, optimization techniques -- all through one YAML configuration file
Basic
llmtune generate config
llmtune run ./config.yml
The first command generates a helpful starter config.yml file and saves in the current working directory. This is provided to users to quickly get started and as a base for further modification.
Then the second command initiates the fine-tuning process using the settings specified in the default YAML configuration file config.yaml.
Intermediate
The configuration file is the central piece that defines the behavior of the toolkit. It is written in YAML format and consists of several sections that control different aspects of the process, such as data ingestion, model definition, training, inference, and quality assurance. We highlight some of the critical sections.
Flash Attention 2
To enable Flash-attention for supported models. First install flash-attn:
pipx
pipx inject llm-toolkit flash-attn --pip-args=--no-build-isolation
pip
pip install flash-attn --no-build-isolation
Then, add to config file.
model:
torch_dtype: "bfloat16" # or "float16" if using older GPU
attn_implementation: "flash_attention_2"
Data Ingestion
An example of what the data ingestion may look like:
data:
file_type: "huggingface"
path: "yahma/alpaca-cleaned"
prompt:
### Instruction: {instruction}
### Input: {input}
### Output:
prompt_stub: { output }
test_size: 0.1 # Proportion of test as % of total; if integer then # of samples
train_size: 0.9 # Proportion of train as % of total; if integer then # of samples
train_test_split_seed: 42
- While the above example illustrates using a public dataset from Hugging Face, the config file can also ingest your own data.
file_type: "json"
path: "<path to your data file>
file_type: "csv"
path: "<path to your data file>
-
The prompt fields help create instructions to fine-tune the LLM on. It reads data from specific columns, mentioned in {} brackets, that are present in your dataset. In the example provided, it is expected for the data file to have column names:
instruction,inputandoutput. -
The prompt fields use both
promptandprompt_stubduring fine-tuning. However, during testing, only thepromptsection is used as input to the fine-tuned LLM.
LLM Definition
model:
hf_model_ckpt: "NousResearch/Llama-2-7b-hf"
quantize: true
bitsandbytes:
load_in_4bit: true
bnb_4bit_compute_dtype: "bf16"
bnb_4bit_quant_type: "nf4"
# LoRA Params -------------------
lora:
task_type: "CAUSAL_LM"
r: 32
lora_dropout: 0.1
target_modules:
- q_proj
- v_proj
- k_proj
- o_proj
- up_proj
- down_proj
- gate_proj
- While the above example showcases using Llama2 7B, in theory, any open-source LLM supported by Hugging Face can be used in this toolkit.
hf_model_ckpt: "mistralai/Mistral-7B-v0.1"
hf_model_ckpt: "tiiuae/falcon-7b"
- The parameters for LoRA, such as the rank
rand dropout, can be altered.
lora:
r: 64
lora_dropout: 0.25
Quality Assurance
qa:
llm_metrics:
- length_test
- word_overlap_test
- To ensure that the fine-tuned LLM behaves as expected, you can add tests that check if the desired behaviour is being attained. Example: for an LLM fine-tuned for a summarization task, we may want to check if the generated summary is indeed smaller in length than the input text. We would also like to learn the overlap between words in the original text and generated summary.
Artifact Outputs
This config will run fine-tuning and save the results under directory ./experiment/[unique_hash]. Each unique configuration will generate a unique hash, so that our tool can automatically pick up where it left off. For example, if you need to exit in the middle of the training, by relaunching the script, the program will automatically load the existing dataset that has been generated under the directory, instead of doing it all over again.
After the script finishes running you will see these distinct artifacts:
/dataset # generated pkl file in hf datasets format
/model # peft model weights in hf format
/results # csv of prompt, ground truth, and predicted values
/qa # csv of test results: e.g. vector similarity between ground truth and prediction
Once all the changes have been incorporated in the YAML file, you can simply use it to run a custom fine-tuning experiment!
python toolkit.py --config-path <path to custom YAML file>
Advanced
Fine-tuning workflows typically involve running ablation studies across various LLMs, prompt designs and optimization techniques. The configuration file can be altered to support running ablation studies.
- Specify different prompt templates to experiment with while fine-tuning.
data:
file_type: "huggingface"
path: "yahma/alpaca-cleaned"
prompt:
- >-
This is the first prompt template to iterate over
### Input: {input}
### Output:
- >-
This is the second prompt template
### Instruction: {instruction}
### Input: {input}
### Output:
prompt_stub: { output }
test_size: 0.1 # Proportion of test as % of total; if integer then # of samples
train_size: 0.9 # Proportion of train as % of total; if integer then # of samples
train_test_split_seed: 42
- Specify various LLMs that you would like to experiment with.
model:
hf_model_ckpt:
[
"NousResearch/Llama-2-7b-hf",
mistralai/Mistral-7B-v0.1",
"tiiuae/falcon-7b",
]
quantize: true
bitsandbytes:
load_in_4bit: true
bnb_4bit_compute_dtype: "bf16"
bnb_4bit_quant_type: "nf4"
- Specify different configurations of LoRA that you would like to ablate over.
lora:
r: [16, 32, 64]
lora_dropout: [0.25, 0.50]
Extending
The toolkit provides a modular and extensible architecture that allows developers to customize and enhance its functionality to suit their specific needs. Each component of the toolkit, such as data ingestion, fine-tuning, inference, and quality assurance testing, is designed to be easily extendable.
Contributing
Open-source contributions to this toolkit are welcome and encouraged. If you would like to contribute, please see CONTRIBUTING.md.