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

相关推荐
mzlogin1 小时前
DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI
人工智能
归去_来兮1 小时前
知识图谱技术概述
大数据·人工智能·知识图谱
就是有点傻1 小时前
VM图像处理之图像二值化
图像处理·人工智能·计算机视觉
行云流水剑1 小时前
【学习记录】深入解析 AI 交互中的五大核心概念:Prompt、Agent、MCP、Function Calling 与 Tools
人工智能·学习·交互
love530love2 小时前
【笔记】在 MSYS2(MINGW64)中正确安装 Rust
运维·开发语言·人工智能·windows·笔记·python·rust
A林玖2 小时前
【机器学习】主成分分析 (PCA)
人工智能·机器学习
Jamence2 小时前
多模态大语言模型arxiv论文略读(108)
论文阅读·人工智能·语言模型·自然语言处理·论文笔记
tongxianchao2 小时前
双空间知识蒸馏用于大语言模型
人工智能·语言模型·自然语言处理
苗老大2 小时前
MMRL: Multi-Modal Representation Learning for Vision-Language Models(多模态表示学习)
人工智能·学习·语言模型
中达瑞和-高光谱·多光谱2 小时前
中达瑞和SHIS高光谱相机在黑色水彩笔墨迹鉴定中的应用
人工智能·数码相机