InternLM / lmdeploy

LMDeploy is a toolkit for compressing, deploying, and serving LLMs.
https://lmdeploy.readthedocs.io/en/latest/
Apache License 2.0
4.19k stars 377 forks source link

Internvl2 api 使用没法正常返回结果,用transforms的推理方式可以 #1959

Closed day9011 closed 2 months ago

day9011 commented 2 months ago

Checklist

Describe the bug

Internvl2 api 使用没法正常返回结果,用transforms的推理方式可以, lmdeploy==0.4.3部署的internvl1.5也可以。 internvl2 api: {'id': '1', 'object': 'chat.completion', 'created': 1720492891, 'model': '/storage210_new/models/huggingface/internvl/InternVL2-26B/', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': ''}, 'logprobs': None, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 2466, 'total_tokens': 2466, 'completion_tokens': 0}}

internvl1.5 api: {"id":"103929","object":"chat.completion","created":1720494142,"model":"internvl-internlm2","choices":[{"index":0,"message":{"role":"assistant","content":"json\n{\n \"felled_tree\": false,\n \"landslide\": false,\n \"flooded_shop\": false\n}\n"},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":915,"total_tokens":948,"completion_tokens":33}}

transforms: User: Observe the image for the following three conditions. If any of them exist, return true; otherwise, return false. The results must be returned in a JSON format, including the following keys:

Assistant: ```json { "felled_tree": false, "landslide": false, "flooded_shop": false }


### Reproduction

[flooding.zip](https://github.com/user-attachments/files/16136811/flooding.zip)

### 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,6,7: NVIDIA A800-SXM4-80GB
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.3, V12.3.103
GCC: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
PyTorch: 2.2.2+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.2, 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.2+cu121
LMDeploy: 0.5.0+0424a25
transformers: 4.42.3
gradio: Not Found
fastapi: 0.111.0
pydantic: 2.8.2
triton: 2.2.0
NVIDIA Topology:
        GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      NV8     NV8     NV8     NV8     NV8     NV8     NV8     0-23,48-71      0               N/A
GPU1    NV8      X      NV8     NV8     NV8     NV8     NV8     NV8     0-23,48-71      0               N/A
GPU2    NV8     NV8      X      NV8     NV8     NV8     NV8     NV8     0-23,48-71      0               N/A
GPU3    NV8     NV8     NV8      X      NV8     NV8     NV8     NV8     0-23,48-71      0               N/A
GPU4    NV8     NV8     NV8     NV8      X      NV8     NV8     NV8     24-47,72-95     1               N/A
GPU5    NV8     NV8     NV8     NV8     NV8      X      NV8     NV8     24-47,72-95     1               N/A
GPU6    NV8     NV8     NV8     NV8     NV8     NV8      X      NV8     24-47,72-95     1               N/A
GPU7    NV8     NV8     NV8     NV8     NV8     NV8     NV8      X      24-47,72-95     1               N/A

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

Error traceback

No response

zhyncs commented 2 months ago

May you provide the test code for the client?

zhyncs commented 2 months ago

May you provide the test code for the client?

ref https://github.com/user-attachments/files/16136811/flooding.zip

zhyncs commented 2 months ago

I use InternVL2 2B to verify locally and it works well. cc @irexyc

I suspect it's an environmental issue. I haven't been able to reproduce your problem on my end. @day9011

# server
# https://github.com/zhyncs/lmdeploy-build/releases/download/3030ae4/lmdeploy-0.5.0+cu121+3030ae4-cp39-cp39-manylinux2014_x86_64.whl
python3 -m lmdeploy serve api_server InternVL2-2B

# client
python3 internvl_test.py --image tiger.jpeg

# result
{"id":"1","object":"chat.completion","created":1720505284,"model":"InternVL2-2B","choices":[{"index":0,"message":{"role":"assistant","content":"```json\n{\n  \"felled_tree\": false,\n  \"landslide\": false,\n  \"flooded_shop\": false\n}\n```"},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":1954,"total_tokens":1987,"completion_tokens":33}}
zhyncs commented 2 months ago

By the way, I used the Google Colab.

day9011 commented 2 months ago

By the way, I used the Google Colab.

InternVL2 2B在我的环境里也可以,26B的返回结果为空。

irexyc commented 2 months ago

@day9011

图片可以提供么?是所有的图片都不行么?

我看了你的 transformers (internvl2.py) 代码,里面的 do_sample 是关闭的,对应到 internvl_test.py 里面的代码,temperature 要设置成 0.

day9011 commented 2 months ago

安装flash-attn后测试 internvl2,发生CUDA error: an illegal memory access was encountered image

day9011 commented 2 months ago

@day9011

图片可以提供么?是所有的图片都不行么?

我看了你的 transformers (internvl2.py) 代码,里面的 do_sample 是关闭的,对应到 internvl_test.py 里面的代码,temperature 要设置成 0.

level_0_1

day9011 commented 2 months ago

@day9011

图片可以提供么?是所有的图片都不行么?

我看了你的 transformers (internvl2.py) 代码,里面的 do_sample 是关闭的,对应到 internvl_test.py 里面的代码,temperature 要设置成 0.

image 我尝试了三张图片,返回的prompt_tokens数量都一样

day9011 commented 2 months ago

@day9011

图片可以提供么?是所有的图片都不行么?

我看了你的 transformers (internvl2.py) 代码,里面的 do_sample 是关闭的,对应到 internvl_test.py 里面的代码,temperature 要设置成 0.

我尝试了--tp 2,是正常了 image

irexyc commented 2 months ago

temperature 0 和 0.7 我这里都是正常的。

如果 messages 如果只有文本,把图片去掉,对话有返回么 ?

day9011 commented 2 months ago

temperature 0 和 0.7 我这里都是正常的。

如果 messages 如果只有文本,把图片去掉,对话有返回么 ?

只有文本是正常的 image

day9011 commented 2 months ago

重新git pull模型后,能够正常显示了

Expert68 commented 2 months ago

重新git pull模型后,能够正常显示了

使用--tp 2是正常的,使用--tp 4也是无法输出,使用单卡也是不能正常输出,重新pull模型还是没有效果

Expert68 commented 2 months ago

重新git pull模型后,能够正常显示了

使用--tp 2是正常的,使用--tp 4也是无法输出,使用单卡也是不能正常输出,重新pull模型还是没有效果

单卡使用--tp 1也可以正常使用,应该是api接口有一点问题

irexyc commented 2 months ago

@Expert68

单卡不行,单卡加 --tp 1可以?

两者都只会用一块卡把,我觉得是别的什么原因。