InternLM / InternLM/lmdeploy

[Bug] 部署的多模态模型,多轮对话时输出结果异常

Open
#1,612 11 comments 0 reactions 1 assignee Claimed by @irexyc View on GitHub
Dominant language
Python
Stars
8.1k
Forks
748
Avg merge
6d 2h
Merged PRs (30d)
54

Description

### Checklist

- [X] 1. I have searched related issues but cannot get the expected help.
- [X] 2. The bug has not been fixed in the latest version.

### Describe the bug

使用llava-v1.6-34b模型部署OPENAI 服务后,多轮对话过程中模型有一定的概率会返回错误的结果
```
[{'type': 'text', 'text': '图片中有一辆红色的踏板车,它的车身和车座都有明显的磨损和污垢,车座上甚至有一些灰尘。踏板车的后部有一个黑色的篮子,里面可能装了一些东西。'}]
```

### Reproduction

服务运行命令:
```
CUDA_VISIBLE_DEVICES=0,3,4,5 NCCL_SHM_DISABLE=1 lmdeploy serve api_server /data/workspace/models/llava-v1.6-34b --server-port 23333 --tp 4 --cache-max-entry-count 0.5 --chat-template template.json
```
template.json文件内容:
```
{
"model_name": "llava-chatml",
"system": "<|im_start|>system\n",
"meta_instruction": "You are a robot developed by LMDeploy.",
"eosys": "<|im_end|>\n",
"user": "<|im_start|>user\n",
"eoh": "<|im_end|>\n",
"assistant": "<|im_start|>assistant\n",
"eoa": "<|im_end|>",
"separator": "\n",
"capability": "chat",
"stop_words": ["<|im_end|>"]
}
```
程序运行代码:
```
from openai import OpenAI
import sys
from qwen_test import prompts

client = OpenAI(api_key='YOUR_API_KEY', base_url='http://0.0.0.0:23333/v1')
model_name = client.models.list().data[0].id
# print(model_name)
stream = True
messages=[
{
'role': 'user',
'content':
[
{
'type': 'image_url',
'image_url': {'url': 'https://smartfire.jxgh.vip:9009/000000-zg119/upload/20240412/31de9aff2d9a01b0dfaaf5a6b9ad22de.jpeg',},
},
{
'type': 'text',
'text': '描述一下这张图片',
},
],
},
{
'role': 'assistant',
'content':
[
{
'type': 'text',
'text': """
这张图片显示的是一个室内空间,看起来像是一个仓库或储藏室。在地面中间,有一辆红色的踏板车,它的车座和车身都有明显的磨损和污垢,车座上甚至还有一些灰尘。踏板车的后部有一个黑色的篮子,里面可能
装了一些东西。\n\n在踏板车的周围堆放着各种物品,包括包装材料、箱子、工具、还有一些建筑材料,比如梯子、管道等。这些物品看起来有些杂乱,被随意地堆放在地面上。\n\n在踏板车前方,有一个红色的圆环状物体,可能是某种工具或设备
的一部分。\n\n整个空间的背景是白色的墙壁,上面有一些架子,上面也堆放着一些物品。在左上角,有一根黄色的电缆,可能是用于某种电器设备。在右下角,有一块透明的塑料布覆盖着某些物品,可能是为了保护它们免受灰尘或污垢的侵害。\n\n总的来说,这张图片给人一种凌乱、拥挤的感觉,表明这个空间可能是用来存放一些不常使用的物品或工具的。
"""
}
],
},
{
'role': 'user',
'content':
[
{
'type': 'text',
'text': "图片中有什么车辆,车辆的颜色是什么",
},
],
}
]

try:
responses = client.chat.completions.create(
model=model_name,
messages=messages,
# temperature=0.1,
stream=stream,
# top_p=0.8
)
if stream:
for response in responses:
# print(response)
# print(response.choices[0].delta.content)
result = response.choices[0].delta.content
# print(result)
sys.stdout.write(result)
sys.stdout.flush()

else:
print(responses)
# print(responses.choices[0].message.content)
except Exception as e:
print(e)
```

### Environment

```Shell
sys.platform: linux
Python: 3.10.14 (main, May 6 2024, 19:42:50) [GCC 11.2.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0,1,2,3,4,5: NVIDIA A100-PCIE-40GB
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.2, V12.2.140
GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
PyTorch: 2.2.1+cu121
PyTorch compiling details: PyTorch built with:
- GCC 9.3
- C++ Version: 201703
- Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v3.3.2 (Git Hash 2dc95a2ad0841e29db8b22fbccaf3e5da7992b01)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX512
- CUDA Runtime 12.1
- NVCC architecture flags: -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90
- CuDNN 8.9.2
- Magma 2.6.1
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=12.1, CUDNN_VERSION=8.9.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=pedantic -Wno-error=old-style-cast -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=2.2.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF,

TorchVision: 0.17.1+cu121
LMDeploy: 0.4.1+398c2aa
transformers: 4.40.2
gradio: 3.50.2
fastapi: 0.111.0
pydantic: 2.7.1
triton: 2.2.0
```

### Error traceback

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.