ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

PaddleNLP 中 BLOOM 大模型配置与微调量化实战指南

PaddleNLP 中 BLOOM 大模型配置与微调量化实战指南 人工智能大模型预训练微调LoRARLHF强化学习分布式训练【免费下载链接】PaddleNLPEasy-to-use and powerful LLM and SLM library with awesome model zoo.项目地址https://gitcode.com/gh_mirrors/pa/PaddleNLP点击查看免费下载导读本文以 PaddleNLP 仓库中 BLOOM 模型配置文档docs/en/llm/config/bloom/README.md为核心骨架系统讲解 BLOOM 系列大语言模型在 PaddleNLP 中的落地方式。你将掌握BLOOM/BloomZ 模型的特性与仓库支持的权重列表、五种开箱即用的训练与量化配置文件SFT、LoRA、Prefix Tuning、PTQ、GPTQ的逐项参数含义以及如何结合 llm/config/bloom/ 目录下的配置与 llm/run_finetune.py、llm/run_quantization.py 启动微调和量化实验。1. BLOOM 模型介绍BLOOM 是一个自回归autoregressive大型语言模型LLM在大量文本数据上训练用于生成目标文本。其核心能力如下多语言支持支持 46 种语言和 13 种编程语言的文本交互核心任务主要基于文本生成任务训练可以很好地完成文本续写text continuation任务BloomZ 变体BloomZ 系列模型在 BLOOM 基础上加入了Instruction Tuning指令微调能够更好地理解并执行以指令形式给出的任务。在 PaddleNLP 中BLOOM 的完整实现位于 paddlenlp/transformers/bloom/包含modeling.py自回归语言模型CausalLM核心实现configuration.py模型配置类定义了vocab_size、hidden_size、n_layer、n_head、hidden_dropout、attention_dropout等关键超参数tokenizer.py 与 tokenizer_fast.py分词器含 Fast 加速版processor.py多模态/多输入处理器。2. 支持的模型权重配置文档中明确列出了 PaddleNLP 支持的 BLOOM / BloomZ 系列预训练权重模型名即 Hugging Face 权重标识可直接作为model_name_or_path使用Modelbigscience/bloom-560mbigscience/bloom-560m-bf16bigscience/bloom-1b1bigscience/bloom-3bbigscience/bloom-7b1bigscience/bloomz-560mbigscience/bloomz-1b1bigscience/bloomz-3bbigscience/bloomz-7b1-mtbigscience/bloomz-7b1-p3bigscience/bloomz-7b1bellegroup/belle-7b-2m其中bloomz-*为经过指令微调的 BloomZ 系列belle-7b-2m为社区中文化微调变体。在仓库的各配置文件中默认使用的权重均为bigscience/bloomz-7b1-mt即支持多语言指令的 7B 级 BloomZ 模型。3. 微调配置SFT 全量微调llm/config/bloom/sft_argument.json 提供了 BLOOM 全量监督微调SFT的标准配置完整内容如下{ model_name_or_path: bigscience/bloomz-7b1-mt, dataset_name_or_path: ./data, output_dir: ./checkpoints/sft_ckpts, per_device_train_batch_size: 4, gradient_accumulation_steps: 4, per_device_eval_batch_size: 8, eval_accumulation_steps:16, num_train_epochs: 3, learning_rate: 3e-05, warmup_steps: 30, logging_steps: 1, evaluation_strategy: epoch, save_strategy: epoch, src_length: 1024, max_length: 2048, fp16: true, fp16_opt_level: O2, do_train: true, do_eval: true, disable_tqdm: true, load_best_model_at_end: true, eval_with_do_generation: false, metric_for_best_model: accuracy, recompute: true, save_total_limit: 1, tensor_parallel_degree: 4, pipeline_parallel_degree: 1, zero_padding: false, unified_checkpoint: true, use_flash_attention: false }关键参数逐项解读参数取值含义与建议model_name_or_pathbigscience/bloomz-7b1-mt预训练权重标识可替换为上表任意支持权重dataset_name_or_path./data训练数据路径本地数据目录output_dir./checkpoints/sft_ckpts模型与检查点输出目录per_device_train_batch_size4单卡训练 batch size7B 模型建议配合梯度累积使用gradient_accumulation_steps4梯度累积步数等效 batch size 4 × 4 16learning_rate3e-05全量微调通常使用较小的学习率num_train_epochs3训练轮数src_length/max_length1024 / 2048输入上下文长度与最大序列长度fp16fp16_opt_leveltrue /O2混合精度训练O2 为保留算子精度等级的优化策略recomputetrue开启重计算activation checkpointing以节省显存tensor_parallel_degree4张量并行度7B 级模型在 SFT 中默认按 4 卡切分pipeline_parallel_degree1流水线并行度unified_checkpointtrue使用统一检查点格式便于跨并行策略复用权重use_flash_attentionfalse是否启用 FlashAttention 加速注意力计算3.1 如何启动 SFT使用 llm/run_finetune.py 入口脚本将上述 JSON 作为--arguments传入即可python -m paddle.distributed.launch \ --gpus 0,1,2,3 \ llm/run_finetune.py \ llm/config/bloom/sft_argument.json从源码看llm/run_finetune.py 通过PdArgumentParser解析 JSON 参数并通过AutoModelForCausalLM/AutoModelForCausalLMPipe自动加载对应规模的 BLOOM 模型当pipeline_parallel_degree 1时会自动切换到AutoModelForCausalLMPipe流水线并行版本。数据侧通过 llm/utils/data.py 的get_convert_example完成 prompt 与 response 的拼接格式化。4. LoRA 高效微调llm/config/bloom/lora_argument.json 提供 LoRA 低秩适配微调配置{ model_name_or_path: bigscience/bloomz-7b1-mt, dataset_name_or_path: ./data, output_dir: ./checkpoints/lora_ckpts, per_device_train_batch_size: 4, gradient_accumulation_steps: 4, per_device_eval_batch_size: 8, eval_accumulation_steps:16, num_train_epochs: 3, learning_rate: 3e-04, warmup_steps: 30, logging_steps: 1, evaluation_strategy: epoch, save_strategy: epoch, src_length: 1024, max_length: 2048, fp16: true, fp16_opt_level: O2, do_train: true, do_eval: true, disable_tqdm: true, load_best_model_at_end: true, eval_with_do_generation: false, metric_for_best_model: accuracy, recompute: true, save_total_limit: 1, tensor_parallel_degree: 1, pipeline_parallel_degree: 1, lora: true, zero_padding: false, unified_checkpoint: true, use_flash_attention: false }与 SFT 配置相比LoRA 配置的关键差异lora: true开启 LoRA 适配仅训练注入的低秩矩阵冻结原模型参数显著降低显存占用与训练成本learning_rate: 3e-04LoRA 训练使用比全量微调3e-05高一个数量级的学习率tensor_parallel_degree: 1LoRA 训练默认单卡即可进行说明该方法对显存需求更友好。LoRA 底层由 paddlenlp/peft/lora/ 中的LoRAConfig/LoRAModel实现llm/run_finetune.py 会依据loraTrue自动调用get_lora_target_modules确定注入目标模块。LoRA 训练产出的检查点可通过 llm/tools/merge_lora_params.py 合并回原模型权重。5. Prefix TuningP-Tuning前缀微调llm/config/bloom/pt_argument.json 提供 Prefix Tuning 前缀微调配置{ model_name_or_path: bigscience/bloomz-7b1-mt, dataset_name_or_path: ./data, output_dir: ./checkpoints/pt_ckpts, per_device_train_batch_size: 4, gradient_accumulation_steps: 4, per_device_eval_batch_size: 8, eval_accumulation_steps:16, num_train_epochs: 3, learning_rate: 3e-02, warmup_steps: 30, logging_steps: 1, evaluation_strategy: epoch, save_strategy: epoch, src_length: 1024, max_length: 2048, fp16: true, fp16_opt_level: O2, do_train: true, do_eval: true, disable_tqdm: true, load_best_model_at_end: true, eval_with_do_generation: false, metric_for_best_model: accuracy, recompute: true, save_total_limit: 1, tensor_parallel_degree: 1, pipeline_parallel_degree: 1, prefix_tuning: true, zero_padding: false, unified_checkpoint: true, use_flash_attention: false }关键差异prefix_tuning: true开启前缀微调在每一 Transformer 层的 KV 前拼接可学习的前缀向量learning_rate: 3e-02前缀向量是可学习的少量新参数因此使用更高的学习率相比 SFT 高三个数量级也能稳定收敛同样保持tensor_parallel_degree: 1单卡即可运行。Prefix Tuning 由 paddlenlp/peft/prefix/ 中的PrefixConfig/PrefixModelForCausalLM实现llm/run_finetune.py 会调用get_prefix_tuning_params构造前缀参数。6. 量化配置PTQ 与 GPTQBLOOM 配置目录还提供了两种后训练量化Post-Training Quantization方案用于降低推理显存与加速部署对应入口脚本为 llm/run_quantization.py。6.1 PTQ含 SmoothQuant 平滑量化llm/config/bloom/ptq_argument.json{ model_name_or_path: bigscience/bloomz-7b1-mt, per_device_train_batch_size: 8, per_device_eval_batch_size: 8, eval_accumulation_steps:16, src_length: 1024, max_length: 2048, fp16: true, fp16_opt_level: O2, dataset_name_or_path: ./data, output_dir: ./checkpoints/ptq_ckpts, do_eval: true, eval_with_do_generation: false, do_ptq: true, ptq_step: 16, smooth: true, smooth_step: 16, smooth_all_linears: true, smooth_piecewise_search: true, smooth_k_piece: 3, unified_checkpoint: true, smooth_search_piece: true }PTQ 参数说明参数取值含义do_ptqtrue开启 PTQ 后训练量化ptq_step16量化校准calibration时使用的样本步数smoothtrue启用 SmoothQuant 激活平滑缓解激活值离群导致的量化误差smooth_step16平滑系数搜索步数smooth_all_linearstrue对所有 Linear 层执行平滑处理smooth_piecewise_search/smooth_search_piecetrue分段搜索平滑策略smooth_k_piece3分段搜索的段数6.2 GPTQllm/config/bloom/gptq_argument.json{ model_name_or_path: bigscience/bloomz-7b1-mt, per_device_train_batch_size: 8, per_device_eval_batch_size: 8, eval_accumulation_steps:16, src_length: 1024, max_length: 2048, fp16: true, fp16_opt_level: O2, dataset_name_or_path: ./data, output_dir: ./checkpoints/gptq_ckpts, do_eval: true, eval_with_do_generation: false, do_gptq: true, unified_checkpoint: true, gptq_step: 8 }GPTQ 参数说明do_gptq: true开启 GPTQ 逐层权重量化gptq_step: 8量化校准步数较 PTQ 的 16 步更少GPTQ 依赖二阶 Hessian 信息补偿量化误差。6.3 启动量化python -m paddle.distributed.launch \ --gpus 0 \ llm/run_quantization.py \ llm/config/bloom/ptq_argument.json # 或 python -m paddle.distributed.launch \ --gpus 0 \ llm/run_quantization.py \ llm/config/bloom/gptq_argument.json量化后的检查点配合 llm/predict/export_model.py 可导出为推理模型。更完整的量化背景可参考 llm/docs/quantization.md 与 llm/docs/quantization_tutorial.md。7. 三种微调方案对比与选择建议结合以上配置可归纳 BLOOM 在 PaddleNLP 中的微调选型参考方案关键开关学习率并行度默认值适用场景SFT 全量微调无默认3e-05TP4, PP1数据充足、追求最优效果、显存充裕LoRAlora: true3e-04TP1, PP1单卡可训、快速迭代、低成本适配Prefix Tuningprefix_tuning: true3e-02TP1, PP1参数量最少适合快速尝试验证启动微调的统一入口为 llm/run_finetune.py只需将--arguments指向对应 JSON训练结束后LoRA/Prefix 检查点可通过 llm/tools/merge_lora_params.py 等合并工具还原为完整权重。数据准备与 SFT 全流程细节可继续阅读 llm/docs/finetune.md 和 llm/docs/peft.md。8. 总结PaddleNLP 为 BLOOM / BloomZ 系列提供了从模型实现paddlenlp/transformers/bloom/到训练llm/run_finetune.py、量化llm/run_quantization.py的完整链路。本文基于 llm/config/bloom/ 下的五份标准配置逐项解读了 SFT、LoRA、Prefix Tuning、PTQ 与 GPTQ 的参数设计思路——其中学习率与并行度的差异化取值正体现了全量微调、参数高效微调与后训练量化在资源占用和收敛特性上的本质区别。读者可直接复用这些配置将任意支持的 BLOOM 权重快速接入自己的微调与部署流程。赞分享人工智能大模型预训练微调LoRARLHF强化学习分布式训练【免费下载链接】PaddleNLPEasy-to-use and powerful LLM and SLM library with awesome model zoo.项目地址https://gitcode.com/gh_mirrors/pa/PaddleNLP点击查看免费下载相关推荐PaddleNLP 中 Qwen 系列模型Qwen / Qwen1.5 / Qwen2的配置与微调实战指南PaddleNLP 中 Qwen 系列模型Qwen / Qwen1.5 / Qwen2的配置与微调实战指南 PaddleNLP 的 LLM 训练套件为阿里云人工智能大模型预训练微调LoRARLHF强化学习分布式训练模型推理服务推理引擎模型量化模型压缩本地部署NLPTaskNotes高级过滤与分组打造个性化任务管理系统的终极指南TaskNotes高级过滤与分组打造个性化任务管理系统的终极指南 在Obsidian中进行任务管理时你是否曾为繁杂的任务列表感到困扰想要快速找到高优先级工PaddleNLP 中的 ChatGLM2-6B模型架构、源码实现与全流程微调配置指南PaddleNLP 中的 ChatGLM2 6B模型架构、源码实现与全流程微调配置指南 导读 本文基于 PaddleNLP 仓库中的 ChatGLM2 配置说人工智能大模型预训练微调LoRARLHF强化学习分布式训练模型推理服务推理引擎模型量化模型压缩本地部署NLP创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表