本文涉及到的测试步骤和相关代码已经放置在:
https://github.com/davidsajare/david-share.git
下的Deep-Learning/Fine-tuning-with-Axolotl
欢迎点亮github星星。
第一步,使用Axolotl调用DeepSpeed针对phi-3-mini-4k进行QLoRA量化(bnb),生成量化后的权重文件。
第二步,针对第一步生成的参数和权重进行反量化,与原始的phi-3-mini-4k进行合并,生成一个完整的模型。
接下来进行四种场景的测试。
四种场景:
1.Merge adapter and original model together, then do inference with FP/BF16 on vLLM. 使用vLLM针对合并后的模型进行推理,使用16位。目前vLLM还不支持bnb。
2.Merge adapter and original model together, then do inference with FP/BF16 on HF transformer. 使用HF transformer针对合并后的模型进行推理,使用16位。
3.Based on merged model #1, use bnb to quantization and inference on HF transformer. 使用HF transformer针对合并后的模型,进行bnb动态量化加载推理。
4.Use bnb to dynamically load the phi-3 base model, load the post-FT checkpoints as adapter, and then use the INFERENCE on HF transformer. 使用bnb动态加载phi-3-mini-4k基础模型,使用adapter加载QLoRA后的权重文件,然后使用HF transformer进行推理。
推理测试结果对比如下:
场景1:
描述:Merge adapter and original model together, then do inference with FP/BF16 on vLLM.
推理结果:
Generation time: 11.48 seconds
Tokens per second: 219.90
Prompt: 'Who is the current president of United States?'
Generated text: Detailed and accurate response about Joe Biden being the current president.
分析:模型合并:适配器和原始模型合并。
推理框架:vLLM。
精度:FP/BF16。
性能:生成时间较短,tokens per second较高,推理速度快。
输出质量:生成的文本详细且准确。
场景2:
描述:Merge adapter and original model together, then do inference with FP/BF16 on HF transformer.
推理结果:
Generation time: 45.78 seconds
Tokens per second: 43.47
Prompt: 'Who is the current president of United States?'
Generated text:Accurate response about Joe Biden being the current president, but with additional context and examples.
分析:模型合并:适配器和原始模型合并。
推理框架:HF transformer。
精度:FP/BF16。
性能:生成时间较长,tokens per second较低,推理速度较慢。
输出质量:生成的文本准确,但包含更多上下文和示例,可能更适合需要详细解释的场景。
场景3:
描述:Based on merged model #1, use bnb to quantization and inference on HF transformer.
推理结果:
Generation time: 21.50 seconds
Tokens per second: 24.93
Prompt: 'Who is the current president of United States?'
Generated text:Accurate response about Joe Biden being the current president, with brief context.
分析:模型合并:基于合并的模型#1。
推理框架:HF transformer。
量化方法:bnb量化。
性能:生成时间适中,tokens per second较低,推理速度适中。
输出质量:生成的文本准确,包含简短的上下文,适合需要简洁回答的场景。
场景4:
描述:Use bnb to dynamically load the phi-3 base model, load the post-FT checkpoints as adapter, and then use the INFERENCE on HF transformer.
推理结果:
Model loading time: 1.92 seconds
Generation time: 95.35 seconds
Tokens per second: 20.87
Prompt: 'Who is the current president of United States?'
Generated text:Accurate response about Joe Biden being the current president, with repetitive context.
分析:模型加载:动态加载phi-3基础模型,加载后FT检查点作为适配器。
推理框架:HF transformer。
量化方法:bnb量化。
性能:模型加载时间较短,但生成时间最长,tokens per second最低,推理速度最慢。
输出质量:生成的文本准确,但包含重复的上下文,可能需要进一步优化以减少冗余。
总结:
性能:场景1的推理速度最快,场景4的推理速度最慢。
输出质量:场景1和场景2的输出质量较高,场景3的输出简洁,场景4的输出有重复内容。
适用场景:场景1适合需要快速响应的应用,场景2适合需要详细解释的应用,场景3适合需要简洁回答的应用,场景4可能需要进一步优化以减少冗余。