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中。

相关推荐
数据饕餮几秒前
大模型推理引擎选型与应用场景分析:SGLang、Ollama、VLLM 和 LLaMA.cpp
人工智能·语言模型
Likeadust3 分钟前
依靠视频设备轨迹回放平台EasyCVR构建视频监控,为幼教连锁园区安全护航
大数据·网络·人工智能·音视频·实时音视频
掘金一周3 分钟前
高并发场景下,为什么大厂都选择SSE而不是WebSocket?| 掘金一周 4.10
人工智能·openai
Y1nhl8 分钟前
搜广推校招面经七十一
人工智能·深度学习·数学建模·广告算法·推荐算法·搜索算法
人大博士的交易之路21 分钟前
今日行情明日机会——20250409
人工智能·数学建模·分类·数据挖掘·量化交易
努力犯错玩AI26 分钟前
HuggingFace镜像站-AI 快站使用说明文档
人工智能·后端·开源
追逐☞29 分钟前
机器学习(1)—线性回归
人工智能·机器学习·线性回归
王亭_66641 分钟前
大模型Prompt提示词越狱相关知识
人工智能·chatgpt·大模型·prompt·deepseek
蔗理苦1 小时前
2025-04-09 吴恩达机器学习6——神经网络(1):介绍
人工智能·深度学习·神经网络·机器学习
_一条咸鱼_1 小时前
深度剖析 AI 大模型的 Transformer 和 MoE 架构
人工智能·深度学习·神经网络