Repository: open-compass/opencompass
Issue: [Bug] Is tokenizer.json a necessary file for scoring?
Root cause: External Dependency Breakage

### Prerequisite

- [X] I have searched [Issues](https://github.com/InternLM/opencompass/issues/) and [Discussions](https://github.com/InternLM/opencompass/discussions) but cannot get the expected help.
- [X] The bug has not been fixed in the [latest version](https://github.com/InternLM/opencompass).

### Type

I'm evaluating with the officially supported tasks/models/datasets.

### Environment

```bash
/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: '/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torchvision/image.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
{'CUDA available': True,
 'CUDA_HOME': '/data/cuda',
 'GCC': 'gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0',
 'GPU 0,1,2,3,4,5,6,7': 'A100-SXM4-40GB',
 'MMEngine': '0.8.4',
 'NVCC': 'Cuda compilation tools, release 11.0, V11.0.221',
 'OpenCV': '4.8.0',
 'PyTorch': '1.13.1+cu117',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 9.3\n'
                              '  - C++ Version: 201402\n'
                              '  - Intel(R) Math Kernel Library Version '
                              '2020.0.0 Product Build 20191122 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v2.6.0 (Git Hash '
                              '52b5f107dd9cf10910aaa19cb47f3abf9b349815)\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: AVX2\n'
                              '  - CUDA Runtime 11.7\n'
                              '  - NVCC architecture flags: '
                              '-gencode;arch=compute_37,code=sm_37;-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\n'
                              '  - CuDNN 8.5\n'
                              '  - Magma 2.6.1\n'
                              '  - Build settings: BLAS_INFO=mkl, '
                              'BUILD_TYPE=Release, CUDA_VERSION=11.7, '
                              'CUDNN_VERSION=8.5.0, '
                              'CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, '
                              'CXX_FLAGS= -fabi-version=11 -Wno-deprecated '
                              '-fvisibility-inlines-hidden -DUSE_PTHREADPOOL '
                              '-fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM '
                              '-DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK '
                              '-DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE '
                              '-DEDGE_PROFILER_USE_KINETO -O2 -fPIC '
                              '-Wno-narrowing -Wall -Wextra '
                              '-Werror=return-type -Werror=non-virtual-dtor '
                              '-Wno-missing-field-initializers '
                              '-Wno-type-limits -Wno-array-bounds '
                              '-Wno-unknown-pragmas -Wunused-local-typedefs '
                              '-Wno-unused-parameter -Wno-unused-function '
                              '-Wno-unused-result -Wno-strict-overflow '
                              '-Wno-strict-aliasing '
                              '-Wno-error=deprecated-declarations '
                              '-Wno-stringop-overflow -Wno-psabi '
                              '-Wno-error=pedantic -Wno-error=redundant-decls '
                              '-Wno-error=old-style-cast '
                              '-fdiagnostics-color=always -faligned-new '
                              '-Wno-unused-but-set-variable '
                              '-Wno-maybe-uninitialized -fno-math-errno '
                              '-fno-trapping-math -Werror=format '
                              '-Werror=cast-function-type '
                              '-Wno-stringop-overflow, LAPACK_INFO=mkl, '
                              'PERF_WITH_AVX=1, PERF_WITH_AVX2=1, '
                              'PERF_WITH_AVX512=1, TORCH_VERSION=1.13.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=ON, '
                              'USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, \n',
 'Python': '3.10.12 (main, Jul  5 2023, 18:54:27) [GCC 11.2.0]',
 'TorchVision': '0.15.2',
 'numpy_random_seed': 2147483648,
 'opencompass': '0.1.2+b2d602f',
 'sys.platform': 'linux'}
```

### Reproduces the problem - code/configuration sample

```python
# configs/eval_hf_llama2_7b.py
from mmengine.config import read_base

with read_base():
    from .datasets.ceval.ceval_ppl import ceval_datasets
    from .models.hf_llama2_7b import models


datasets = [*ceval_datasets]

# configs/models/hf_llama2_7b.py
from opencompass.models import HuggingFaceCausalLM

model_name_or_paths = '/data/home/xxx/model/llama2/7b/origin/hf'

models = [
    dict(
        type=HuggingFaceCausalLM,
        abbr='llama-2-7b-hf',
        path=model_name_or_paths,
        tokenizer_path=model_name_or_paths,
        tokenizer_kwargs=dict(padding_side='left',
                              truncation_side='left',
                            #   use_fast=False,
                              ),
        max_out_len=100,
        max_seq_len=2048,
        batch_size=8,
        model_kwargs=dict(device_map='auto'),
        batch_padding=False, # if false, inference with for-loop without batch padding
        run_cfg=dict(num_gpus=1, num_procs=1),
    )
]

#  eval.sh

#bin/bash
CUDA_VISIBLE_DEVICES=0 python run.py configs/eval_hf_llama2_7b.py -w outputs/llama2_7b_with_ceval --debug
```

### Reproduces the problem - command or script

```shell
sh eval.sh
```

### Reproduces the problem - error message

```shell
/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/mmengine/utils/manager.py:113: UserWarning: <class 'mmengine.logging.logger.MMLogger'> instance named of OpenCompass has been created, the method `get_instance` should not accept any other arguments
  warnings.warn(
09/01 14:53:53 - OpenCompass - INFO - Partitioned into 3 tasks.
09/01 14:53:53 - OpenCompass - DEBUG - Task 0: [llama-2-7b-hf/ceval-college_economics,llama-2-7b-hf/ceval-accountant,llama-2-7b-hf/ceval-tax_accountant,llama-2-7b-hf/ceval-physician,llama-2-7b-hf/ceval-civil_servant,llama-2-7b-hf/ceval-urban_and_rural_planner,llama-2-7b-hf/ceval-teacher_qualification,llama-2-7b-hf/ceval-college_programming,llama-2-7b-hf/ceval-electrical_engineer,llama-2-7b-hf/ceval-business_administration,llama-2-7b-hf/ceval-art_studies]
09/01 14:53:53 - OpenCompass - DEBUG - Task 1: [llama-2-7b-hf/ceval-fire_engineer,llama-2-7b-hf/ceval-environmental_impact_assessment_engineer,llama-2-7b-hf/ceval-education_science,llama-2-7b-hf/ceval-professional_tour_guide,llama-2-7b-hf/ceval-college_chemistry,llama-2-7b-hf/ceval-metrology_engineer,llama-2-7b-hf/ceval-mao_zedong_thought,llama-2-7b-hf/ceval-law,llama-2-7b-hf/ceval-veterinary_medicine,llama-2-7b-hf/ceval-modern_chinese_history,llama-2-7b-hf/ceval-chinese_language_and_literature,llama-2-7b-hf/ceval-legal_professional,llama-2-7b-hf/ceval-logic,llama-2-7b-hf/ceval-middle_school_history,llama-2-7b-hf/ceval-plant_protection,llama-2-7b-hf/ceval-clinical_medicine,llama-2-7b-hf/ceval-computer_architecture,llama-2-7b-hf/ceval-middle_school_biology,llama-2-7b-hf/ceval-middle_school_politics,llama-2-7b-hf/ceval-middle_school_chemistry,llama-2-7b-hf/ceval-high_school_history]
09/01 14:53:53 - OpenCompass - DEBUG - Task 2: [llama-2-7b-hf/ceval-computer_network,llama-2-7b-hf/ceval-operating_system,llama-2-7b-hf/ceval-college_physics,llama-2-7b-hf/ceval-advanced_mathematics,llama-2-7b-hf/ceval-high_school_physics,llama-2-7b-hf/ceval-high_school_chemistry,llama-2-7b-hf/ceval-high_school_biology,llama-2-7b-hf/ceval-middle_school_mathematics,llama-2-7b-hf/ceval-middle_school_physics,llama-2-7b-hf/ceval-marxism,llama-2-7b-hf/ceval-high_school_politics,llama-2-7b-hf/ceval-high_school_geography,llama-2-7b-hf/ceval-ideological_and_moral_cultivation,llama-2-7b-hf/ceval-high_school_chinese,llama-2-7b-hf/ceval-sports_science,llama-2-7b-hf/ceval-basic_medicine,llama-2-7b-hf/ceval-probability_and_statistics,llama-2-7b-hf/ceval-high_school_mathematics,llama-2-7b-hf/ceval-discrete_mathematics,llama-2-7b-hf/ceval-middle_school_geography]
09/01 14:53:53 - OpenCompass - DEBUG - Modules of opencompass's task registry have been automatically imported from opencompass.tasks
09/01 14:53:53 - OpenCompass - DEBUG - Get class `OpenICLInferTask` from "task" registry in "opencompass"
09/01 14:53:53 - OpenCompass - DEBUG - An `OpenICLInferTask` instance is built from registry, and its implementation can be found in opencompass.tasks.openicl_infer
09/01 14:53:59 - OpenCompass - INFO - Task [llama-2-7b-hf/ceval-college_economics,llama-2-7b-hf/ceval-accountant,llama-2-7b-hf/ceval-tax_accountant,llama-2-7b-hf/ceval-physician,llama-2-7b-hf/ceval-civil_servant,llama-2-7b-hf/ceval-urban_and_rural_planner,llama-2-7b-hf/ceval-teacher_qualification,llama-2-7b-hf/ceval-college_programming,llama-2-7b-hf/ceval-electrical_engineer,llama-2-7b-hf/ceval-business_administration,llama-2-7b-hf/ceval-art_studies]
/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/mmengine/utils/manager.py:113: UserWarning: <class 'mmengine.logging.logger.MMLogger'> instance named of OpenCompass has been created, the method `get_instance` should not accept any other arguments
  warnings.warn(
Traceback (most recent call last):
  File "/data/home/xxx/examples/opencompass/opencompass/tasks/openicl_infer.py", line 147, in <module>
    inferencer.run()
  File "/data/home/xxx/examples/opencompass/opencompass/tasks/openicl_infer.py", line 60, in run
    self.model = build_model_from_cfg(model_cfg)
  File "/data/home/xxx/examples/opencompass/opencompass/utils/build.py", line 23, in build_model_from_cfg
    return MODELS.build(model_cfg)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/mmengine/registry/registry.py", line 570, in build
    return self.build_func(cfg, *args, **kwargs, registry=self)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
    obj = obj_cls(**args)  # type: ignore
  File "/data/home/xxx/examples/opencompass/opencompass/models/huggingface.py", line 72, in __init__
    self._load_tokenizer(path=path,
  File "/data/home/xxx/examples/opencompass/opencompass/models/huggingface.py", line 85, in _load_tokenizer
    self.tokenizer = AutoTokenizer.from_pretrained(
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 727, in from_pretrained
    return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1854, in from_pretrained
    return cls._from_pretrained(
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1886, in _from_pretrained
    slow_tokenizer = (cls.slow_tokenizer_class)._from_pretrained(
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2017, in _from_pretrained
    tokenizer = cls(*init_inputs, **init_kwargs)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/models/llama/tokenization_llama.py", line 156, in __init__
    self.sp_model = self.get_spm_processor()
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/models/llama/tokenization_llama.py", line 164, in get_spm_processor
    model_pb2 = import_protobuf()
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/transformers/convert_slow_tokenizer.py", line 40, in import_protobuf
    return sentencepiece_model_pb2
UnboundLocalError: local variable 'sentencepiece_model_pb2' referenced before assignment
^CWARNING:torch.distributed.elastic.agent.server.api:Received 2 death signal, shutting down workers
Traceback (most recent call last):
  File "/data/home/xxx/.conda/envs/opencompass/bin/torchrun", line 8, in <module>
    sys.exit(main())
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 346, in wrapper
    return f(*args, **kwargs)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/run.py", line 762, in main
    run(args)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/run.py", line 753, in run
    elastic_launch(
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 132, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 237, in launch_agent
    result = agent.run()
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/elastic/metrics/api.py", line 129, in wrapper
    result = f(*args, **kwargs)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/elastic/agent/server/api.py", line 709, in run
    result = self._invoke_run(role)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/elastic/agent/server/api.py", line 850, in _invoke_run
    time.sleep(monitor_interval)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/site-packages/torch/distributed/elastic/multiprocessing/api.py", line 62, in _terminate_process_handler
    raise SignalException(f"Process {os.getpid()} got signal: {sigval}", sigval=sigval)
torch.distributed.elastic.multiprocessing.api.SignalException: Process 562641 got signal: 2
Traceback (most recent call last):
  File "/data/home/xxx/examples/opencompass/run.py", line 330, in <module>
    main()
  File "/data/home/xxx/examples/opencompass/run.py", line 257, in main
    exec_infer_runner(tasks, args, cfg)
  File "/data/home/xxx/examples/opencompass/opencompass/utils/run.py", line 144, in exec_infer_runner
    runner(tasks)
  File "/data/home/xxx/examples/opencompass/opencompass/runners/base.py", line 38, in __call__
    status = self.launch(tasks)
  File "/data/home/xxx/examples/opencompass/opencompass/runners/local.py", line 72, in launch
    subprocess.run(cmd, shell=True, text=True)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/subprocess.py", line 505, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/subprocess.py", line 1146, in communicate
    self.wait()
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/subprocess.py", line 1209, in wait
    return self._wait(timeout=timeout)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/subprocess.py", line 1959, in _wait
    (pid, sts) = self._try_wait(0)
  File "/data/home/xxx/.conda/envs/opencompass/lib/python3.10/subprocess.py", line 1917, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
```

### Other information

But when I save the tokenizer to json, the error is missing.
```
model = AutoTokenizer.from_pretrained(from_path)
model.backend_tokenizer.save(to_path)
```

What's the reason of it? The origin hugging face model has no tokenizer.json file.

I believe there IS a `tokenizer.json` in the huggingface repo: 

https://huggingface.co/meta-llama/Llama-2-7b-hf/blob/main/tokenizer.json

I am not sure about the `sentencepiece_model_pb2` error, which looks like a huggingface internal bug?

Feel free to re-open if needed.