Repository: open-compass/opencompass
Issue: [Bug] Unable to run OpenCompass with an existing VLLM instance.
Root cause: Validation Gap

### Prerequisite

- [X] I have searched [Issues](https://github.com/open-compass/opencompass/issues/) and [Discussions](https://github.com/open-compass/opencompass/discussions) but cannot get the expected help.
- [X] The bug has not been fixed in the [latest version](https://github.com/open-compass/opencompass).

### Type

I'm evaluating with the officially supported tasks/models/datasets.

### Environment

{'CUDA available': True,
 'CUDA_HOME': '/home/yonatan/.local/cuda-12.1',
 'GCC': 'gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0',
 'GPU 0,1,2,3,4,5,6,7': 'NVIDIA H100 80GB HBM3',
 'MMEngine': '0.10.4',
 'MUSA available': False,
 'NVCC': 'Cuda compilation tools, release 12.1, V12.1.66',
 'OpenCV': '4.10.0',
 'PyTorch': '2.4.0',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 9.3\n'
                              '  - C++ Version: 201703\n'
                              '  - Intel(R) oneAPI Math Kernel Library Version '
                              '2023.1-Product Build 20230303 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v3.4.2 (Git Hash '
                              '1137e04ec0b5251ca2b4400a4fd3c667ce843d67)\n'
                              '  - OpenMP 201511 (a.k.a. OpenMP 4.5)\n'
                              '  - LAPACK is enabled (usually provided by '
                              'MKL)\n'
                              '  - NNPACK is enabled\n'
                              '  - CPU capability usage: AVX512\n'
                              '  - CUDA Runtime 12.4\n'
                              '  - NVCC architecture flags: '
                              '-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-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\n'
                              '  - CuDNN 90.1\n'
                              '  - Magma 2.6.1\n'
                              '  - Build settings: BLAS_INFO=mkl, '
                              'BUILD_TYPE=Release, CUDA_VERSION=12.4, '
                              'CUDNN_VERSION=9.1.0, '
                              '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_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.4.0, '
                              'USE_CUDA=ON, USE_CUDNN=ON, USE_CUSPARSELT=1, '
                              'USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, '
                              'USE_GLOG=OFF, USE_GLOO=ON, USE_MKL=ON, '
                              'USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, '
                              'USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, '
                              'USE_ROCM_KERNEL_ASSERT=OFF, \n',
 'Python': '3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0]',
 'TorchVision': '0.19.0',
 'lmdeploy': "not installed:No module named 'lmdeploy'",
 'numpy_random_seed': 2147483648,
 'opencompass': '0.3.0+8e55c9c',
 'sys.platform': 'linux',
 'transformers': '4.44.0'}

### Reproduces the problem - code/configuration sample

I created a new config called `configs/eval_llama3_instruct_vllm.py`:
```
from mmengine.config import read_base

with read_base():
    from .dataset_collections.chat_OC15 import datasets

    from .models.hf_llama.hf_llama3_8b_instruct import models as hf_llama3_8b_instruct_model

    from .summarizers.chat_OC15 import summarizer


work_dir = 'outputs/debug/llama3-instruct'

# models = sum([v for k, v in locals().items() if k.endswith('_model')], [])

from opencompass.models import OpenAI

api_meta_template = dict(
    round=[
        dict(role='HUMAN', api_role='HUMAN'),
        dict(role='BOT', api_role='BOT', generate=True),
    ],
    reserved_roles=[dict(role='SYSTEM', api_role='SYSTEM')],
)

models = [
    dict(
        abbr='Meta-Llama-3-8B-Instruct-vLLM',
        type=OpenAI,
        openai_api_base='http://0.0.0.0:8000/v1/',  # Service address
        path='Meta-Llama-3-8B-Instruct',  # Model name for service request
        key="1234",
        rpm_verbose=True,  # Whether to print request rate
        meta_template=api_meta_template,  # Service request template
        query_per_second=1,  # Service request rate
        max_out_len=1024,  # Maximum output length
        max_seq_len=4096,  # Maximum input length
        temperature=0.01,  # Generation temperature
        batch_size=8,  # Batch size
        retry=3,  # Number of retries
    )
```

### Reproduces the problem - command or script

`python run.py configs/eval_llama3_instruct_vllm.py`

### Reproduces the problem - error message
```
08/19 15:36:25 - OpenCompass - INFO - Start inferencing [Meta-Llama-3-8B-Instruct-vLLM/lukaemon_mmlu_college_biology]
100%|██████████| 144/144 [00:00<00:00, 974160.93it/s]
Traceback (most recent call last):
  File "/home/yonatan/workspace/opencompass/opencompass/tasks/openicl_infer.py", line 161, in <module>
    inferencer.run()
  File "/home/yonatan/workspace/opencompass/opencompass/tasks/openicl_infer.py", line 89, in run
    self._inference()
  File "/home/yonatan/workspace/opencompass/opencompass/tasks/openicl_infer.py", line 128, in _inference
    inferencer.inference(retriever,
  File "/home/yonatan/workspace/opencompass/opencompass/openicl/icl_inferencer/icl_gen_inferencer.py", line 100, in inference
    prompt_list = self.get_generation_prompt_list_from_retriever_indices(
  File "/home/yonatan/workspace/opencompass/opencompass/openicl/icl_inferencer/icl_gen_inferencer.py", line 222, in get_generation_prompt_list_from_retriever_indices
    prompt_token_num = self.model.get_token_len_from_template(
  File "/home/yonatan/workspace/opencompass/opencompass/models/base.py", line 225, in get_token_len_from_template
    token_lens = [self.get_token_len(prompt) for prompt in prompts]
  File "/home/yonatan/workspace/opencompass/opencompass/models/base.py", line 225, in <listcomp>
    token_lens = [self.get_token_len(prompt) for prompt in prompts]
  File "/home/yonatan/workspace/opencompass/opencompass/models/openai_api.py", line 325, in get_token_len
    enc = self.tiktoken.encoding_for_model(self.path)
  File "/home/yonatan/miniconda3/envs/opencompass/lib/python3.10/site-packages/tiktoken/model.py", line 103, in encoding_for_model
    return get_encoding(encoding_name_for_model(model_name))
  File "/home/yonatan/miniconda3/envs/opencompass/lib/python3.10/site-packages/tiktoken/model.py", line 90, in encoding_name_for_model
    raise KeyError(
KeyError: 'Could not automatically map Meta-Llama-3-8B-Instruct to a tokeniser. Please use `tiktoken.get_encoding` to explicitly get the tokeniser you expect.'
```

### Other information

I adapted the config from `eval_llama3_instruct.py` using the LMDeploy example from the docs. My vLLM server is running but there is no activity on it. I've verified that the port is correct.

This is a BUG for the length calculation process in OC, now it's fixed: https://github.com/open-compass/opencompass/pull/1433

Feel free to re-open if needed.