Repository: open-compass/opencompass
Issue: [Bug] TypeError when max_out_len is None in HuggingFace model generation methods
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': '/usr/local/cuda',
 'GCC': 'gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0',
 'GPU 0': 'NVIDIA GeForce RTX 4090',
 'MMEngine': '0.10.7',
 'MUSA available': False,
 'NVCC': 'Cuda compilation tools, release 12.8, V12.8.93',
 'OpenCV': '4.11.0',
 'PyTorch': '2.8.0+cu128',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 13.3\n'
                              '  - C++ Version: 201703\n'
                              '  - Intel(R) oneAPI Math Kernel Library Version '
                              '2024.2-Product Build 20240605 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v3.7.1 (Git Hash '
                              '8d263e693366ef8db40acc569cc7d8edf644556d)\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.8\n'
                              '  - NVCC architecture flags: '
                              '-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;-gencode;arch=compute_100,code=sm_100;-gencode;arch=compute_120,code=sm_120\n'
                              '  - CuDNN 91.0.2  (built against CUDA 12.9)\n'
                              '    - Built with CuDNN 90.8\n'
                              '  - Magma 2.6.1\n'
                              '  - Build settings: BLAS_INFO=mkl, '
                              'BUILD_TYPE=Release, '
                              'COMMIT_SHA=a1cb3cc05d46d198467bebbb6e8fba50a325d4e7, '
                              'CUDA_VERSION=12.8, CUDNN_VERSION=9.8.0, '
                              'CXX_COMPILER=/opt/rh/gcc-toolset-13/root/usr/bin/c++, '
                              'CXX_FLAGS= -fvisibility-inlines-hidden '
                              '-DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO '
                              '-DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON '
                              '-DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK '
                              '-DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE '
                              '-O2 -fPIC -DC10_NODEPRECATED -Wall -Wextra '
                              '-Werror=return-type -Werror=non-virtual-dtor '
                              '-Werror=range-loop-construct '
                              '-Werror=bool-operation -Wnarrowing '
                              '-Wno-missing-field-initializers '
                              '-Wno-unknown-pragmas -Wno-unused-parameter '
                              '-Wno-strict-overflow -Wno-strict-aliasing '
                              '-Wno-stringop-overflow -Wsuggest-override '
                              '-Wno-psabi -Wno-error=old-style-cast '
                              '-faligned-new -Wno-maybe-uninitialized '
                              '-fno-math-errno -fno-trapping-math '
                              '-Werror=format -Wno-dangling-reference '
                              '-Wno-error=dangling-reference '
                              '-Wno-stringop-overflow, LAPACK_INFO=mkl, '
                              'PERF_WITH_AVX=1, PERF_WITH_AVX2=1, '
                              'TORCH_VERSION=2.8.0, USE_CUDA=ON, USE_CUDNN=ON, '
                              'USE_CUSPARSELT=1, USE_GFLAGS=OFF, USE_GLOG=OFF, '
                              'USE_GLOO=ON, 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, USE_XCCL=OFF, '
                              'USE_XPU=OFF, \n',
 'Python': '3.10.18 (main, Jun  5 2025, 13:14:17) [GCC 11.2.0]',
 'TorchVision': '0.23.0+cu128',
 'lmdeploy': "not installed:No module named 'lmdeploy'",
 'numpy_random_seed': 2147483648,
 'opencompass': '0.4.2+',
 'sys.platform': 'linux',
 'transformers': '4.56.1'}

### Reproduces the problem - code/configuration sample

```python
# configs/eval_hf_mmlu.py
from mmengine.config import read_base

with read_base():

    from opencompass.configs.datasets.mmlu.mmlu_gen import mmlu_datasets
    from opencompass.configs.summarizers.chat_OC15 import summarizer

from opencompass.models import HuggingFaceCausalLM

models = [
    dict(
        type=HuggingFaceCausalLM,
        abbr="hf-model", 
        path="google/gemma-3-270m-it", 
        tokenizer_path="google/gemma-3-270m-it",
        tokenizer_kwargs=dict(
            padding_side="left", truncation_side="left", use_fast=True
        ),
        max_seq_len=2048,
        batch_size=32,  # 显存不够就调小

        generation_kwargs=dict(
            temperature=0.0, top_p=1.0, do_sample=False, max_new_tokens=32
        ),
        run_cfg=dict(num_gpus=1, num_procs=1),
    )
]

datasets = mmlu_datasets

work_dir = "./outputs/mmlu_hf_model"
```

### Reproduces the problem - command or script

```shell
opencompass /workspace/opencompass-0.5.0/config/eval_hf_mmlu.py
```

### Reproduces the problem - error message

```
Traceback (most recent call last):
  File "/workspace/opencompass-0.4.2/opencompass/tasks/openicl_infer.py", line 161, in <module>
    inferencer.run()
  File "/workspace/opencompass-0.4.2/opencompass/tasks/openicl_infer.py", line 89, in run
    self._inference()
  File "/workspace/opencompass-0.4.2/opencompass/tasks/openicl_infer.py", line 134, in _inference
    inferencer.inference(retriever,
  File "/workspace/opencompass-0.4.2/opencompass/openicl/icl_inferencer/icl_gen_inferencer.py", line 153, in inference
    results = self.model.generate_from_template(
  File "/workspace/opencompass-0.4.2/opencompass/models/base.py", line 201, in generate_from_template
    return self.generate(inputs, max_out_len=max_out_len, **kwargs)
  File "/workspace/opencompass-0.4.2/opencompass/models/huggingface.py", line 258, in generate
    return sum(
  File "/workspace/opencompass-0.4.2/opencompass/models/huggingface.py", line 260, in <genexpr>
    self._single_generate(
  File "/workspace/opencompass-0.4.2/opencompass/models/huggingface.py", line 402, in _single_generate
    inputs, truncation=True, max_length=self.max_seq_len - max_out_len
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
```

### Other information

_No response_