[Bug]: AI调用模型速度极慢
问题描述
AI调用模型时要花费很长的时间,通常有70秒以上
相关日志输出
[WARNING] 2025.02.10更新:由于配置文件格式变更,如果先前你拉取过本 Repo 并在 02.10 后执行过fetch操作,请您重新设置模型配置,由此带来的不便我们深表歉意
[INFO] 启动Muice-Chatbot中🚀...
[INFO] 加载配置文件...
[INFO] 配置文件存在,正在读取
[INFO] 加载模型:llmtuner
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,981 >> loading file vocab.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,981 >> loading file merges.txt
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,983 >> loading file tokenizer.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,983 >> loading file added_tokens.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,983 >> loading file special_tokens_map.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:13,983 >> loading file tokenizer_config.json
[INFO|tokenization_utils_base.py:2475] 2025-02-21 17:49:14,208 >> Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
02/21/2025 17:49:14 - INFO - llmtuner.data.template - Replace eos token: <|im_end|>
[INFO|configuration_utils.py:677] 2025-02-21 17:49:14,209 >> loading configuration file E:\Muice-Chatbot-main\model\Qwen2.5-7B-Instruct-GPTQ-Int4\config.json
[INFO|configuration_utils.py:746] 2025-02-21 17:49:14,211 >> Model config Qwen2Config {
"_name_or_path": "E:\\Muice-Chatbot-main\\model\\Qwen2.5-7B-Instruct-GPTQ-Int4",
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151645,
"hidden_act": "silu",
"hidden_size": 3584,
"initializer_range": 0.02,
"intermediate_size": 18944,
"max_position_embeddings": 32768,
"max_window_layers": 28,
"model_type": "qwen2",
"num_attention_heads": 28,
"num_hidden_layers": 28,
"num_key_value_heads": 4,
"quantization_config": {
"batch_size": 1,
"bits": 4,
"block_name_to_quantize": null,
"cache_block_outputs": true,
"damp_percent": 0.01,
"dataset": null,
"desc_act": false,
"exllama_config": {
"version": 1
},
"group_size": 128,
"max_input_length": null,
"model_seqlen": null,
"module_name_preceding_first_block": null,
"modules_in_block_to_quantize": null,
"pad_token_id": null,
"quant_method": "gptq",
"sym": true,
"tokenizer": null,
"true_sequential": true,
"use_cuda_fp16": false,
"use_exllama": true
},
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000.0,
"sliding_window": null,
"tie_word_embeddings": false,
"torch_dtype": "float16",
"transformers_version": "4.46.3",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 152064
}
02/21/2025 17:49:14 - INFO - llmtuner.model.utils.quantization - Loading 4-bit GPTQ-quantized model.
02/21/2025 17:49:14 - INFO - llmtuner.model.patcher - Using KV cache for faster generation.
CUDA extension not installed.
CUDA extension not installed.
[INFO|quantizer_gptq.py:68] 2025-02-21 17:49:14,353 >> We suggest you to set `torch_dtype=torch.float16` for better efficiency with GPTQ.
[INFO|modeling_utils.py:3934] 2025-02-21 17:49:14,353 >> loading weights file E:\Muice-Chatbot-main\model\Qwen2.5-7B-Instruct-GPTQ-Int4\model.safetensors.index.json
[INFO|modeling_utils.py:1670] 2025-02-21 17:49:14,354 >> Instantiating Qwen2ForCausalLM model under default dtype torch.float32.
[INFO|configuration_utils.py:1096] 2025-02-21 17:49:14,355 >> Generate config GenerationConfig {
"bos_token_id": 151643,
"eos_token_id": 151645
}
C:\Users\123\miniconda3\lib\site-packages\transformers\modeling_utils.py:5006: FutureWarning: `_is_quantized_training_enabled` is going to be deprecated in transformers 4.39.0. Please use `model.hf_quantizer.is_trainable` instead
warnings.warn(
[WARNING|logging.py:328] 2025-02-21 17:49:14,374 >> `loss_type=None` was set in the config but it is unrecognised.Using the default loss: `ForCausalLMLoss`.
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 2.25it/s]
[INFO|modeling_utils.py:4800] 2025-02-21 17:49:15,691 >> All model checkpoint weights were used when initializing Qwen2ForCausalLM.
[INFO|modeling_utils.py:4808] 2025-02-21 17:49:15,692 >> All the weights of Qwen2ForCausalLM were initialized from the model checkpoint at E:\Muice-Chatbot-main\model\Qwen2.5-7B-Instruct-GPTQ-Int4.
If your task is similar to the task the model of the checkpoint was trained on, you can already use Qwen2ForCausalLM for predictions without further training.
[INFO|configuration_utils.py:1049] 2025-02-21 17:49:15,694 >> loading configuration file E:\Muice-Chatbot-main\model\Qwen2.5-7B-Instruct-GPTQ-Int4\generation_config.json
[INFO|configuration_utils.py:1096] 2025-02-21 17:49:15,695 >> Generate config GenerationConfig {
"bos_token_id": 151643,
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"pad_token_id": 151643,
"repetition_penalty": 1.05,
"temperature": 0.7,
"top_k": 20,
"top_p": 0.8
}
02/21/2025 17:49:15 - INFO - llmtuner.model.utils.attention - Using torch SDPA for faster training and inference.
02/21/2025 17:49:15 - INFO - llmtuner.model.adapter - Upcasting trainable params to float32.
02/21/2025 17:49:15 - INFO - llmtuner.model.adapter - Fine-tuning method: LoRA
02/21/2025 17:49:16 - INFO - llmtuner.model.adapter - Loaded adapter(s): E:\Muice-Chatbot-main\model\Muice-2.7.1-Qwen2.5-7B-Instruct-GPTQ-Int4-8e-4
02/21/2025 17:49:16 - INFO - llmtuner.model.loader - all params: 1110384128
[INFO] 加载OFA图像模型...
2025-02-21 17:49:17,693 - modelscope - INFO - initiate model from E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh
2025-02-21 17:49:17,693 - modelscope - INFO - initiate model from location E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh.
2025-02-21 17:49:17,696 - modelscope - INFO - initialize model from E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh
[INFO|configuration_utils.py:677] 2025-02-21 17:49:17,705 >> loading configuration file E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh\config.json
[INFO|configuration_utils.py:746] 2025-02-21 17:49:17,705 >> Model config OFAConfig {
"activation_dropout": 0.0,
"activation_function": "gelu",
"add_type_embedding": true,
"architectures": [
"OFAModel"
],
"attention_dropout": 0.0,
"attn_scale_factor": 2.0,
"bos_token_id": 0,
"classifier_dropout": 0.0,
"code_image_size": 128,
"code_layernorm_embedding": true,
"d_model": 1024,
"decoder_attention_heads": 16,
"decoder_drop_path_rate": 0.0,
"decoder_ffn_dim": 4096,
"decoder_layerdrop": 0.0,
"decoder_layers": 12,
"decoder_normalize_before": true,
"decoder_start_token_id": 0,
"disable_entangle": false,
"dropout": 0.1,
"encoder_attention_heads": 16,
"encoder_drop_path_rate": 0.0,
"encoder_ffn_dim": 4096,
"encoder_layerdrop": 0.0,
"encoder_layers": 12,
"encoder_normalize_before": true,
"entangle_position_embedding": false,
"eos_token_id": 2,
"exclude_mlp": true,
"forced_eos_token_id": 2,
"gamma": 1.0,
"image_bucket_size": 42,
"init_std": 0.02,
"interpolate_position": true,
"is_encoder_decoder": true,
"layernorm_embedding": true,
"max_position_embeddings": 1024,
"mlp_dim": 512,
"model_type": "ofa",
"normformer": true,
"num_hidden_layers": 12,
"orig_patch_image_size": 224,
"pad_token_id": 1,
"patch_layernorm_embedding": true,
"remove_decoder_type_embedding": false,
"resnet_drop_path_rate": 0.0,
"resnet_model_path": null,
"resnet_type": "resnet152",
"scale_embedding": false,
"share_attn_bias": false,
"share_decoder_input_output_embed": true,
"temperature_init_value": null,
"token_bucket_size": 256,
"torch_dtype": "float32",
"transformers_version": "4.46.3",
"use_cache": true,
"use_gamma_feature": false,
"use_image_feature": true,
"use_ofasys": false,
"vit_drop_path_rate": 0.0,
"vit_type": "vit_base",
"vocab_size": 30325
}
[INFO|modeling_utils.py:3934] 2025-02-21 17:49:17,706 >> loading weights file E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh\pytorch_model.bin
[WARNING|logging.py:328] 2025-02-21 17:49:17,845 >> OFAModel has generative capabilities, as `prepare_inputs_for_generation` is explicitly overwritten. However, it doesn't directly inherit from `GenerationMixin`. From 👉v4.50👈 onwards, `PreTrainedModel` will NOT inherit from `GenerationMixin`, and this model will lose the ability to call `generate` and other related functions.
- If you're using `trust_remote_code=True`, you can get rid of this warning by loading the model with an auto class. See https://huggingface.co/docs/transformers/en/model_doc/auto#auto-classes
- If you are the owner of the model architecture code, please modify your model class such that it inherits from `GenerationMixin` (after `PreTrainedModel`, otherwise you'll get an exception).
- If you are not the owner of the model architecture class, please contact the model code owner to update it.
[INFO|configuration_utils.py:1096] 2025-02-21 17:49:17,845 >> Generate config GenerationConfig {
"bos_token_id": 0,
"decoder_start_token_id": 0,
"eos_token_id": 2,
"forced_eos_token_id": 2,
"pad_token_id": 1
}
[INFO|modeling_utils.py:4800] 2025-02-21 17:49:18,554 >> All model checkpoint weights were used when initializing OFAModel.
[INFO|modeling_utils.py:4808] 2025-02-21 17:49:18,554 >> All the weights of OFAModel were initialized from the model checkpoint at E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh.
If your task is similar to the task the model of the checkpoint was trained on, you can already use OFAModel for predictions without further training.
[INFO|modeling_utils.py:4272] 2025-02-21 17:49:18,568 >> Generation config file not found, using a generation config created from the model config.
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,570 >> loading file vocab.txt
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,570 >> loading file added_tokens.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,570 >> loading file special_tokens_map.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,571 >> loading file tokenizer_config.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,571 >> loading file tokenizer.json
[INFO|configuration_utils.py:677] 2025-02-21 17:49:18,571 >> loading configuration file E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh\config.json
2025-02-21 17:49:18,732 - modelscope - WARNING - No preprocessor field found in cfg.
2025-02-21 17:49:18,732 - modelscope - WARNING - No val key and type key found in preprocessor domain of configuration.json file.
2025-02-21 17:49:18,732 - modelscope - WARNING - Cannot find available config to build preprocessor at mode inference, current config: {'model_dir': 'E:\\Muice-Chatbot-main\\model\\ofa_image-caption_meme_large_zh'}. trying to build by task and model information.
2025-02-21 17:49:18,733 - modelscope - WARNING - No preprocessor key ('ofa', 'image-captioning') found in PREPROCESSOR_MAP, skip building preprocessor.
2025-02-21 17:49:18,735 - modelscope - INFO - cuda is not available, using cpu instead.
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,743 >> loading file vocab.txt
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,743 >> loading file added_tokens.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,743 >> loading file special_tokens_map.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,743 >> loading file tokenizer_config.json
[INFO|tokenization_utils_base.py:2209] 2025-02-21 17:49:18,743 >> loading file tokenizer.json
[INFO|configuration_utils.py:677] 2025-02-21 17:49:18,744 >> loading configuration file E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh\config.json
[INFO] 初始化Bot服务...
[INFO] 尝试与适配器建立WebSocket连接...
[INFO] WebSocket运行地址:http://127.0.0.1:21050
>>>[INFO] 沐雪Chatbot已在运行中✨
[INFO] 收到来自QQ171***的消息:有人吗?
[INFO] 正在调用模型...
[INFO] 模型调用时长: 125.62448859214783 s
Building prefix dict from the default dictionary ...
DEBUG:jieba:Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\123\AppData\Local\Temp\jieba.cache
DEBUG:jieba:Loading model from cache C:\Users\123\AppData\Local\Temp\jieba.cache
Loading model cost 0.505 seconds.
DEBUG:jieba:Loading model cost 0.505 seconds.
Prefix dict has been built successfully.
DEBUG:jieba:Prefix dict has been built successfully.
[INFO] 找到相似图片:file:///E:\Muice-Chatbot-main\image_data\storge\1740130715.7040842.jpg,相似度为0.6328125
[INFO] 回复列表:['[CQ:image,url=file:///E:\\Muice-Chatbot-main\\image_data\\storge\\1740130715.7040842.jpg]']
配置文件
# 模型相关
model:
loader: llmtuner # 使用 llmtuner 加载器
model_path: E:\Muice-Chatbot-main\model\Qwen2.5-7B-Instruct-GPTQ-Int4 # 原始模型路径(必填)
adapter_path: E:\Muice-Chatbot-main\model\Muice-2.7.1-Qwen2.5-7B-Instruct-GPTQ-Int4-8e-4 # 微调模型路径(可选)
template: qwen # LLaMA-Factory 中模型的模板(必填)
system_prompt: '现在开始你是一个名为的“沐雪”的AI女孩子' # 系统提示(可选)
auto_system_prompt: false # 自动配置沐雪的系统提示(默认为 false)
max_tokens: 1024 # 模型生成的最大 token 数(可选,默认为 1024)
temperature: 0.75 # 模型生成的温度参数(可选)
top_k: 0.95 # 模型生成的 Top_k 参数(可选)
multimodal:
enable: false # 是否启用多模态
loader: dashscope # 使用 dashscope 加载器
model_name: qwen-vl-plus # 多模态模型名称
api_key: sk-xxxxxxx # API 密钥(必须)
# Bot相关
bot:
platform: qq # 聊天平台 qq/telegram
id: 395*** # 机器人QQ号
port: 21050 # LLOneBot反向WebSocket服务端口
wait_reply: true # 拟人化回复(回复前等待一段时间)
cq_code: false # 是否解析CQ码
anyone: true # 是否回复所有人
trusted: # 可信QQ号(当anyone为false时生效)
- 171***
group:
enable: true # 是否启用群聊回复
only_at: true # 是否只回复at自己的消息
rate: 0.5 # 群聊回复概率(only_at为false时生效)
anyone: false # 是否回复所有群组
trusted: # 可信群组(当anyone为false时生效)
- 102***
only_trusted: false # 是否只回复可信QQ号
cmd_only_trusted: true # 是否只执行可信QQ号的命令
nonreply_prefix: # 不回复消息的前缀
- '!'
- '!'
- '#'
nickname: '观众大大' # 用户昵称(当输出中包含 <USERNAME> 时生效)
# 主动对话相关
active:
enable: false # 是否启用主动对话
rate: 0.05 # 主动对话概率(每分钟)
active_prompts:
- '<生成推文: 胡思乱想>'
- '<生成推文: AI生活>'
- '<生成推文: AI思考>'
- '<生成推文: 表达爱意>'
- '<生成推文: 情感建议>'
not_disturb: true # 是否开启免打扰模式
shecdule:
enable: true # 是否启用定时任务
rate: 0.75 # 定时任务概率(每次)
tasks:
- hour: 8
prompt: '<日常问候: 早上>'
- hour: 12
prompt: '<日常问候: 中午>'
- hour: 18
prompt: '<日常问候: 傍晚>'
- hour: 22
prompt: '<日常问候: 深夜>'
targets: # 主动对话目标QQ号
- 171***
- 23456789
# 其他可选服务
# OFA 图像识别
ofa_image:
enable: true # 是否启用OFA图像服务
path: E:\Muice-Chatbot-main\model\ofa_image-caption_meme_large_zh # OFA模型路径
# 语音回复
voice_reply:
enable: false # 是否启用语音回复
rate: 0.75 # 语音回复概率
# 实时语音对话(realtime_refence.py)
realtime_voice:
path: ./model/SenseVoice # 实时语音模型路径
# Faiss长期记忆(Beta)
faiss:
enable: false # 是否启用Faiss长期记忆
path: ./model/distiluse-base-multilingual-cased-v1 # Faiss模型路径
是的我换版本了(
复现步骤
1.运行muice-chatbot程序 2.成功运行后向AI发送消息 3.AI能够正常发送消息,但调用模型所花费的时间很长
其他信息
我的网络正常,而且auto_gptq是有本地项目位置的,所以应该不是这个情况(吧)
我在进行#68的修复操作之前,模型调用速度都是正常的(10秒内)
你好,感谢你的反馈
在你的报错信息中,我们发现了2025-02-21 17:49:18,735 - modelscope - INFO - cuda is not available, using cpu instead.,这可能是由于torch安装了cpu版本,或是未安装cuda/不在path变量中。
要检查cuda环境是否正常,打开命令提示符(不要以管理员身份运行),输入nvcc --version,若出现nvcc: NVIDIA (R) Cuda compiler driver......则说明cuda环境正常。
要检查torch是否正常,打开命令提示符,在激活虚拟环境(如果有的话)后输入pip show torch,检查版本Version是否为2.x.x+cuxxx,同时cu版本与cuda环境对齐。
根据 #68 的反馈,你提到了fairseq安装问题,fairseq需要在本地编译(需求完整的C环境),如果安装不上可以搜索编译好的文件安装/复制到site-packages文件夹里。需要注意的是,fairseq必定会与某包冲突,属于正常情况,程序可以正常运行的。
cuda有的,torch也正常
你的torch未安装cuda版本,正确版本号应为2.x.x+cu126
就是不知道torch的2.x.x+cu126的版本要怎么下啊...
在激活虚拟环境后,使用命令:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
或
pip install torch==2.5.1+cu126 torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://download.pytorch.org/whl/cu126
如果提示已存在torch,则先卸载原包:
pip uninstall torch
好的,解决了~
不过话说在发送图片信息后回复速度整体变慢(包括发送图片后再发送文字信息)是正常现象吗
@v191949v 不正常,可能是由于之前的更新导致的,具体我要抽空看一下代码。
不过话说在发送图片信息后回复速度整体变慢(包括发送图片后再发送文字信息)是正常现象吗
目前我也有这样的情况启用了语音回复就会让模型输出变慢,目前来看好像是好像是显存如果用到了共享gpu显存即使占用了共享gpu显存0.5gb都会变得及其的慢3-5分钟处理一句话,在处理的过程中gpu典型不断的100%到90%占用3-5分钟左右,如果正常状态来说gpu只有一瞬间会这样 我的gpu是4080
还有就是这个问题有可能是关于显存,目前就是单运行程序没有问题如果这个显存超出到显卡以外的共享显存才会这样