Repository: open-compass/opencompass
Issue: [Bug] 使用多卡推理验证Lawbench时，2-1子任务某缓存文件丢失导致最后无法正确evaluation
Root cause: Resource Mishandling

### 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

```python
{'CUDA available': True,
 'CUDA_HOME': '/usr/local/cuda',
 'GCC': 'gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0',
 'GPU 0,1,2,3': 'NVIDIA GeForce RTX 3090',
 'MMEngine': '0.10.4',
 'MUSA available': False,
 'NVCC': 'Cuda compilation tools, release 12.1, V12.1.105',
 'OpenCV': '4.10.0',
 'PyTorch': '2.1.2+cu121',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 9.3\n'
                              '  - C++ Version: 201703\n'
                              '  - Intel(R) oneAPI Math Kernel Library Version '
                              '2022.2-Product Build 20220804 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v3.1.1 (Git Hash '
                              '64f6bcbcbab628e96f33a62c3e975f8535a7bde4)\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.1\n'
                              '  - 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\n'
                              '  - CuDNN 8.9.2\n'
                              '  - Magma 2.6.1\n'
                              '  - 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 -Wno-psabi '
                              '-Wno-error=pedantic -Wno-error=old-style-cast '
                              '-Wno-invalid-partial-specialization '
                              '-Wno-unused-private-field '
                              '-Wno-aligned-allocation-unavailable '
                              '-Wno-missing-braces -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_DISABLE_GPU_ASSERTS=ON, '
                              'TORCH_VERSION=2.1.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, \n',
 'Python': '3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0]',
 'TorchVision': '0.16.2+cu121',
 'lmdeploy': "not installed:No module named 'lmdeploy'",
 'numpy_random_seed': 2147483648,
 'opencompass': '0.3.1+',
 'sys.platform': 'linux',
 'transformers': '4.39.3'}
```

### Reproduces the problem - code/configuration sample

```python
None
```

### Reproduces the problem - command or script

```shell
model_name="../qwen/Qwen2-7B-Instruct "
CUDA_VISIBLE_DEVICES=0,1,2,3 python run.py  --hf-path  $model_name  --datasets  lawbench_zero_shot_gen_002588 -w ./outputs/$model_name --max-num-workers 4    --mode all  -a vllm 
```

### Reproduces the problem - error message

```
详细结果下面放出
```

### Other information

希望能正常输出所有子任务结果

错误的地方
```
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/parallel_to_m2.py", line 2, in <module>
    from modules.annotator import Annotator
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/modules/annotator.py", line 4, in <module>
    from modules.classifier import Classifier
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/modules/classifier.py", line 13, in <module>
    char_smi = CharFuncs(os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "..", "data", "lawbench", "eval_assets", "char_meta.txt"))
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/char_smi.py", line 100, in __init__
    self.data = self.load_char_meta(char_meta_fname)
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/char_smi.py", line 120, in load_char_meta
    f = open(fname, 'r', encoding='utf-8')
FileNotFoundError: [Errno 2] No such file or directory: '/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/modules/../../../../../data/lawbench/eval_assets/char_meta.txt'
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/compare_m2_for_evaluation.py", line 433, in <module>
    main()
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/utils/compare_m2_for_evaluation.py", line 8, in main
    hyp_m2 = open(args.hyp).read().strip().split("\n\n")[args.start:args.end] if args.start is not None and args.end is not None else open(args.hyp).read().strip().split("\n\n")
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpf8i3a78z.m2'
Traceback (most recent call last):
  File "/root/autodl-tmp/opencompass-0.3.1/opencompass/tasks/openicl_eval.py", line 397, in <module>
    inferencer.run()
  File "/root/autodl-tmp/opencompass-0.3.1/opencompass/tasks/openicl_eval.py", line 114, in run
    self._score()
  File "/root/autodl-tmp/opencompass-0.3.1/opencompass/tasks/openicl_eval.py", line 230, in _score
    result = icl_evaluator.score(**preds)
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/lawbench.py", line 71, in score
    scores = funct_dict[self.index](data_dict)
  File "/root/miniconda3/lib/python3.10/site-packages/opencompass/datasets/lawbench/evaluation_functions/wsjd.py", line 43, in compute_wsjd
    output = subprocess.check_output(
  File "/root/miniconda3/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/root/miniconda3/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'python3 compare_m2_for_evaluation.py -hyp /tmp/tmpf8i3a78z.m2 -ref /tmp/tmphl8ddq1_.m2' returned non-zero exit status 1.
```

输出结果
```
00%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:58<00:00,  2.94s/it]
08/30 14:36:39 - OpenCompass - ERROR - /root/autodl-tmp/opencompass-0.3.1/opencompass/runners/base.py - summarize - 64 - OpenICLEval[Qwen2-7B-Instruct_hf-vllm/lawbench-2-1-document_proofreading-0-shot] failed with code 1
dataset                                                version    metric           mode    Qwen2-7B-Instruct_hf-vllm
-----------------------------------------------------  ---------  ---------------  ------  ---------------------------
lawbench-1-1-article_recitation-0-shot                 056a7f     score            gen     20.26
lawbench-1-2-knowledge_question_answering-0-shot       056a7f     score            gen     70.80
lawbench-1-2-knowledge_question_answering-0-shot       056a7f     abstention_rate  gen     0.00
lawbench-2-1-document_proofreading-0-shot              -          -                -       -
lawbench-2-2-dispute_focus_identification-0-shot       056a7f     score            gen     29.40
lawbench-2-2-dispute_focus_identification-0-shot       056a7f     abstention_rate  gen     0.40
lawbench-2-3-marital_disputes_identification-0-shot    056a7f     score            gen     52.47
lawbench-2-3-marital_disputes_identification-0-shot    056a7f     abstention_rate  gen     0.60
lawbench-2-4-issue_topic_identification-0-shot         056a7f     score            gen     38.00
lawbench-2-4-issue_topic_identification-0-shot         056a7f     abstention_rate  gen     4.80
lawbench-2-5-reading_comprehension-0-shot              056a7f     score            gen     50.09
lawbench-2-6-named_entity_recognition-0-shot           056a7f     score            gen     50.30
lawbench-2-6-named_entity_recognition-0-shot           056a7f     anstention_rate  gen     18.40
lawbench-2-7-opinion_summarization-0-shot              056a7f     score            gen     36.22
lawbench-2-8-argument_mining-0-shot                    056a7f     score            gen     45.00
lawbench-2-8-argument_mining-0-shot                    056a7f     abstention_rate  gen     0.00
lawbench-2-9-event_detection-0-shot                    056a7f     score            gen     65.75
lawbench-2-9-event_detection-0-shot                    056a7f     abstention_rate  gen     6.40
lawbench-2-10-trigger_word_extraction-0-shot           056a7f     score            gen     34.14
lawbench-3-1-fact_based_article_prediction-0-shot      056a7f     score            gen     76.83
lawbench-3-1-fact_based_article_prediction-0-shot      056a7f     abstention_rate  gen     2.20
lawbench-3-2-scene_based_article_prediction-0-shot     056a7f     score            gen     30.50
lawbench-3-3-charge_prediction-0-shot                  056a7f     score            gen     50.71
lawbench-3-3-charge_prediction-0-shot                  056a7f     abstention_rate  gen     14.80
lawbench-3-4-prison_term_prediction_wo_article-0-shot  056a7f     score            gen     83.19
lawbench-3-4-prison_term_prediction_wo_article-0-shot  056a7f     abstention_rate  gen     3.00
lawbench-3-5-prison_term_prediction_w_article-0-shot   056a7f     score            gen     80.38
lawbench-3-5-prison_term_prediction_w_article-0-shot   056a7f     abstention_rate  gen     4.20
lawbench-3-6-case_analysis-0-shot                      056a7f     score            gen     63.40
lawbench-3-6-case_analysis-0-shot                      056a7f     abstention_rate  gen     0.00
lawbench-3-7-criminal_damages_calculation-0-shot       056a7f     score            gen     66.80
lawbench-3-7-criminal_damages_calculation-0-shot       056a7f     abstention_rate  gen     0.00
lawbench-3-8-consultation-0-shot                       056a7f     score            gen     18.82
08/30 14:36:39 - OpenCompass - INFO - write summary to /root/autodl-tmp/opencompass-0.3.1/qwen/Qwen2-7B-Instruct/20240830_142447/summary/summary_20240830_142447.txt
08/30 14:36:39 - OpenCompass - INFO - write csv to /root/autodl-tmp/opencompass-0.3.1/qwen/Qwen2-7B-Instruct/202408
30_142447/summary/summary_20240830_142447.csv
```

Rerun your comman with --reuse  to rerun the unfinished task

Closed. Feel free to re-open.