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

相关推荐
行然梦实几秒前
TOPSIS(Technique for Order Preference by Similarity to Ideal Solution )简介与简单示例
人工智能·算法·机器学习·数学建模
机器觉醒时代8 分钟前
具身智能VLA困于“数据泥潭”,人类活动视频数据是否是“破局之钥”?
人工智能·具身智能·vla模型
Godspeed Zhao10 分钟前
自动驾驶中的传感器技术14——Camera(5)
人工智能·机器学习·自动驾驶·camera·摄像头
音视频牛哥10 分钟前
智能感知的新入口:AIGC 与低延迟视频通路的深度融合
人工智能·计算机视觉·aigc·音视频·大牛直播sdk·aigc实时·aigc rtsp
Fine姐27 分钟前
数据挖掘2.1&2.2 分类和线性判别器&确定线性可分性
人工智能·分类·数据挖掘
倔强青铜三38 分钟前
GIL竟是Python命中注定的解药?统治AI时代的核心秘密!
人工智能·python·ai编程
倔强青铜三42 分钟前
大揭秘!Python类没有真正私有属性的原因
人工智能·python·ai编程
stars1 小时前
数字人开发02--前端服务配置
前端·人工智能
好多渔鱼好多1 小时前
【语音技术】意图与语料
人工智能·智能家居·智能互联·语音技术·影音开发·意图
无风听海1 小时前
理解梯度在神经网络中的应用
人工智能·深度学习·神经网络·梯度