Illustrates the Qwen LoRA fine-tuning process, from data tokenization with ChatML to PEFT LoRA injection and masked loss training for Qwen2.5-1.5B-Instruct
%%{init: {"theme": "base", "themeVariables": {"background": "#ffffff", "primaryColor": "#f0fdf4", "primaryBorderColor": "#22c55e", "primaryTextColor": "#0f172a", "lineColor": "#64748b"}}}%%
flowchart TB
W1["train.jsonl / valid.jsonl"] --> W2["HF AutoTokenizer + ChatML template"]
W2 --> W3["样本转为 chat-format tokens"]
W3 --> W4["构造 loss mask<br>prefix 对比法定位 assistant 区间"]
W4 --> W5["Qwen2.5-1.5B-Instruct"]
W5 --> W6["PEFT LoRA 注入 target modules"]
W6 --> W7["训练循环<br>forward → masked loss → backward → eval"]
W7 --> W8["checkpoint / best adaptor / final adaptor"]
classDef data fill:#eff6ff,stroke:#60a5fa,color:#0f172a;
classDef train fill:#f0fdf4,stroke:#22c55e,color:#0f172a;
classDef loss fill:#fff7ed,stroke:#fb923c,color:#0f172a;
classDef out fill:#fdf4ff,stroke:#d946ef,color:#0f172a;
class W1,W2,W3 data;
class W5,W6,W7 train;
class W4 loss;
class W8 out;
This diagram illustrates the fine-tuning process for the Qwen2.5-1.5B-Instruct model using LoRA. It details the steps from preparing training data with HF AutoTokenizer and ChatML template, tokenizing samples, constructing a loss mask using prefix comparison to identify the assistant section, injecting PEFT LoRA into target modules, and the training loop involving forward pass, masked loss calculation, backward pass, and evaluation, culminating in checkpoints and adaptors.
Use this diagram when explaining or implementing LoRA fine-tuning for large language models, specifically Qwen, using Hugging Face tools and PEFT. It's suitable for understanding the data preparation, tokenization, loss masking, and training loop involved in adapting pre-trained models.
This diagram can be adapted for other LLM fine-tuning scenarios by changing the base model (e.g., Llama, Mistral), adjusting the tokenizer and chat template to match the new model's requirements, and modifying the PEFT configuration for different LoRA parameters or target modules. The loss masking strategy might also need adjustments based on the specific fine-tuning task or model architecture.