LLM Finetuning Toolkit 使用教程

LLM Finetuning Toolkit 使用教程

LLM-Finetuning-Hub Repository that contains LLM fine-tuning and deployment scripts along with our research findings. LLM-Finetuning-Hub 项目地址: https://gitcode.com/gh_mirrors/ll/LLM-Finetuning-Hub

1. 项目目录结构及介绍

LLM Finetuning Toolkit 是一个用于启动一系列语言模型微调实验的开源工具。以下是项目的目录结构及各部分的简要介绍:

  • assets/: 存储项目所需的静态资源文件。
  • examples/: 包含了一些示例配置文件,用于演示如何设置和运行微调实验。
  • llama2/: 与 Llama-2 模型相关的代码和配置。
  • llmtune/: 包含了微调工具的核心代码。
  • mistral/: 与 Mistral 模型相关的代码和配置。
  • test_utils/: 用于测试微调后的模型的工具。
  • tests/: 包含了项目的单元测试代码。
  • .github/: 包含了 GitHub Actions 工作流文件。
  • .gitignore: 定义了 Git 忽略的文件和目录。
  • CONTRIBUTING.md: 指导如何为项目贡献代码的文档。
  • Dockerfile: 用于构建项目 Docker 容器的文件。
  • LICENSE: 项目的许可文件。
  • Makefile: 定义了构建和测试项目的命令。
  • README.md: 项目的自述文件。
  • poetry.lock: PyPoetry 锁定文件,确保依赖的稳定性。
  • pyproject.toml: 定义了项目的依赖和构建系统。
  • requirements.txt: 项目依赖文件。

2. 项目的启动文件介绍

项目的启动文件是 llmtune.py,它负责解析命令行参数,加载配置文件,并运行微调实验。以下是如何使用该文件的基本步骤:

python llmtune.py --config-path path_to_config.yml

其中 path_to_config.yml 是指定配置文件的路径。

3. 项目的配置文件介绍

配置文件是 YAML 格式的文件,它定义了微调实验的各个方面,包括数据输入、模型定义、训练、推断和质量保证。以下是配置文件的一些关键部分:

  • data: 定义了数据源的类型和路径,以及用于生成提示的模板。
  • model: 指定了用于微调的模型类型和参数,例如模型检查点、量化设置和 LoRA 参数。
  • qa: 定义了质量保证测试,用于验证微调后的模型是否达到预期的性能。
  • train_sizetest_size: 定义了训练集和测试集的大小。
  • train_test_split_seed: 定义了训练和测试数据集分割的随机种子。

以下是一个配置文件的示例:

data:
  file_type: "huggingface"
  path: "yahma/alpaca-cleaned"
  prompt: |
    ### Instruction: {instruction}
    ### Input: {input}
    ### Output:
  prompt_stub: "{ output }"
  test_size: 0.1
  train_size: 0.9
  train_test_split_seed: 42

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:
    task_type: "CAUSAL_LM"
    r: 32
    lora_dropout: 0.1
    target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "up_proj", "down_proj", "gate_proj"]

qa:
  llm_metrics: ["length_test", "word_overlap_test"]

确保配置文件正确无误,然后可以通过指定配置文件的路径来启动微调实验。

LLM-Finetuning-Hub Repository that contains LLM fine-tuning and deployment scripts along with our research findings. LLM-Finetuning-Hub 项目地址: https://gitcode.com/gh_mirrors/ll/LLM-Finetuning-Hub