Transformers 微调时报错:`if v not in ALL_PARALLEL_STYLES` 的解决记录(非 LLaMA-Factory 框架)_微调合并的模型 不能用transformers加载
Transformers 微调时报错:if v not in ALL_PARALLEL_STYLES 的解决记录(非 LLaMA-Factory 框架)
📌 背景说明
在不使用 LLaMA-Factory 框架的情况下,我使用了来自这篇 CSDN 博客的代码进行模型微调:
🔗 原始代码来源:
https://blog.csdn.net/SoulmateY/article/details/139564504
我的本地文件路径为:
/home/fyp/pretrain/finetune_qwen_fudan.py
运行微调时出现如下错误:
❌ 报错详情
TypeError: argument of type \'NoneType\' is not iterable
堆栈信息定位到 HuggingFace Transformers 中的以下位置:
if v not in ALL_PARALLEL_STYLES:
该报错说明模型配置中的 parallelization_style 字段为 None,但 transformers 的判断语句未考虑这种情况。
✅ 解决方法
✅ 在加载模型前加入以下代码:
在 finetune_qwen_fudan.py 中,在加载模型前(如 AutoModel.from_pretrained() 之前)添加以下代码:
from transformers import modeling_utilsif not hasattr(modeling_utils, \"ALL_PARALLEL_STYLES\") or modeling_utils.ALL_PARALLEL_STYLES is None: modeling_utils.ALL_PARALLEL_STYLES = [\"tp\", \"none\", \"colwise\", \"rowwise\"]
这段代码作用是动态补全 HuggingFace Transformers 中的全局变量 ALL_PARALLEL_STYLES,防止其在后续初始化模型时由于空值报错。
📝 总结建议
-
此问题通常出现在使用 本地模型 或第三方微调代码,且 transformers 版本 >= 4.52 时;
-
如果仅为临时测试或兼容旧代码,使用上述补丁代码可以快速修复。
📁 文件信息
- 本地测试脚本路径:
/home/fyp/pretrain/finetune_qwen_fudan.py - 更新时间:2025-06-17
- 关键词:transformers、parallelization_style、NoneType、微调报错、Qwen、huggingface


