mindie推理大语言模型问题及解决方法汇总

问题说明

使用功能mindie 1.0 RC2推理大语言模型,遇到不少问题,记录下解决思路。

我的硬件是910B4。

问题及解决

问题1

在docker内启动mindie时终端报错

shell 复制代码
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)

查看logs/pythonlog.log.xxxx

复制代码
File "/usr/local/Ascend/atb-models/atb_llm/utils/file_utils.py", line 110, in check_owner
raise argparse.ArgumentTypeError("The path is not owned by current user or root")
argparse.ArgumentTypeError: The path is not owned by current user or root

问题分析:模型目录是我从外部映射进去的,目录的所有者是一个叫guest的用户,而docker内的用户是root。

解决方法:将日志目录所有者和组改为root

复制代码
chown root:root /path/to/directory -R

问题2

在docker内启动mindie时终端报错

shell 复制代码
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x0000ffff8401d570)

查看logs/pythonlog.log.xxxx

shell 复制代码
File "/root/.cache/huggingface/modules/transformers_modules/Baichuan2-13B-Base/tokenization_baichuan.py", line 7, in <module>
import sentencepiece as spm
ModuleNotFoundError: No module named 'sentencepiece'

问题分析:我加载的事baichuan2-13b模型,该模型依赖sentencepiece这个组件

解决方法:

shell 复制代码
pip install sentencepiece

问题3

在docker内启动mindie时终端报错

shell 复制代码
Exception:unsupported type: torch.bfloat16

问题分析:我加载的模型是bfloat16的,而mindie貌似不支持,只能支持fp16.具体类型可以从模型下的config.json中看到

解决办法:将模型转换为fp16类型

python 复制代码
import argparse
import os
import torch


def convert_bin2st_from_pretrained(model_path, out_path):
    from transformers import AutoModelForCausalLM, AutoTokenizer
    tokenizer = AutoTokenizer.from_pretrained(model_path,
        revision="v2.0",
        use_fast=False,
        trust_remote_code=True)
    model = AutoModelForCausalLM.from_pretrained(
        pretrained_model_name_or_path=model_path,
        low_cpu_mem_usage=True,
        trust_remote_code=True,
        torch_dtype=torch.float16)  #这里指定float16格式
    print(f"Saving the target model to {out_path}")
    model.save_pretrained(out_path, safe_serialization=True)
    print(f"Saving the tokenizer to {out_path}")
    tokenizer.save_pretrained(out_path)

if __name__ == '__main__':
    print(f"covert  model  into safetensor")
    convert_bin2st_from_pretrained("./Qwen2-72B-Instruct", "./Qwen2-72B-Instruct_fp16")

转换完毕,将./Qwen2-72B-Instruct/tokenizer.json手动复制到./Qwen2-72B-Instruct_fp16。其它文件都全了。

问题4

在docker内启动mindie时终端报错

shell 复制代码
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x0000ffffac01d570)

查看logs/pythonlog.log.xxxx

复制代码
File "/usr/local/Ascend/atb-models/atb_llm/models/qwen2/router_qwen2.py", line 39, in checkout_config_qwen
if value < min_val or value > max_val:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

跟踪发现是router_qwen2.py中获取的sliding_window为None.这个问题是我用上一步的方法转换模型引起的。

解决方法:在转换后的模型目录中config.json中将sliding_window字段设置为131072。

总结

很多问题表现为GIL相关的问题,实际都是业务进程出错了,真实原因往往在logs/pythonlog.log.xxxx中。

相关推荐
杨小扩5 小时前
第4章:实战项目一 打造你的第一个AI知识库问答机器人 (RAG)
人工智能·机器人
whaosoft-1435 小时前
51c~目标检测~合集4
人工智能
雪兽软件5 小时前
2025 年网络安全与人工智能发展趋势
人工智能·安全·web安全
元宇宙时间6 小时前
全球发展币GDEV:从中国出发,走向全球的数字发展合作蓝图
大数据·人工智能·去中心化·区块链
小黄人20256 小时前
自动驾驶安全技术的演进与NVIDIA的创新实践
人工智能·安全·自动驾驶
ZStack开发者社区7 小时前
首批 | 云轴科技ZStack加入施耐德电气技术本地化创新生态
人工智能·科技·云计算
X Y O8 小时前
神经网络初步学习3——数据与损失
人工智能·神经网络·学习
唯创知音8 小时前
玩具语音方案选型决策OTP vs Flash 的成本功耗与灵活性
人工智能·语音识别
Jamence8 小时前
多模态大语言模型arxiv论文略读(151)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
tongxianchao8 小时前
LaCo: Large Language Model Pruning via Layer Collapse
人工智能·语言模型·剪枝