4.57.3 auto_docstring crashes with AttributeError
Author: ymcki
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.57.3
- Platform: Linux-6.8.0-88-generic-x86_64-with-glibc2.39
- Python version: 3.12.2
- Huggingface_hub version: 0.36.0
- Safetensors version: 0.5.3
- Accelerate version: 1.11.0
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.7.0+cu126 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA GeForce RTX 3090


### Who can help?

@stevhliu 

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

I am getting this crash when trying to make llama.cpp's causal-verify-logits. Can you fix it?

```
(base) user@hpc:~/gguf/llama.cpp/examples/model-conversion$ make causal-verify-logits MODEL_PATH=/home/user/Kimi-Linear-48B-A3B-Instruct/ CONVERTED_MODEL=/home/user/q4km.gguf
Loading model and tokenizer using AutoTokenizer: /home/user/Kimi-Linear-48B-A3B-Instruct/
Model type:        kimi_linear
Vocab size:        163840
Hidden size:       2304
Number of layers:  27
BOS token id:      163584
EOS token id:      163586
Traceback (most recent call last):
  File "/home/user/gguf/llama.cpp/examples/model-conversion/./scripts/causal/run-org-model.py", line 172, in <module>
    model = AutoModelForCausalLM.from_pretrained(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 586, in from_pretrained
    model_class = get_class_from_dynamic_module(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/dynamic_module_utils.py", line 616, in get_class_from_dynamic_module
    return get_class_in_module(class_name, final_module, force_reload=force_download)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/dynamic_module_utils.py", line 311, in get_class_in_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py", line 899, in <module>
    class KimiLinearModel(KimiPreTrainedModel):
  File "/home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py", line 939, in KimiLinearModel
    @auto_docstring
     ^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 2063, in auto_docstring
    return auto_docstring_decorator(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 2056, in auto_docstring_decorator
    return auto_method_docstring(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 1759, in auto_method_docstring
    docstring += _process_parameters_section(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 1589, in _process_parameters_section
    param_docstring, missing_args = _process_regular_parameters(
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 1408, in _process_regular_parameters
    param_type, optional = _process_parameter_type(param, param_name, func)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/auto_docstring.py", line 1311, in _process_parameter_type
    param_type = f"{param_type.__module__.replace('transformers.', '~').replace('builtins', '')}.{param.annotation.__name__}"
                                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'types.UnionType' object has no attribute '__name__'. Did you mean: '__ne__'?
make: *** [Makefile:56: causal-run-original-model] Error 1
```

### Expected behavior

I would expect it not to crash at that place.

Comments:
I think this is related to https://github.com/huggingface/transformers/pull/42431

> I think this is related to [#42431](https://github.com/huggingface/transformers/pull/42431)

Thanks for your reply. I applied the patch. It seems to get past that error but I run into another error:

```
make causal-verify-logits MODEL_PATH=/home/user/Kimi-Linear-48B-A3B-Instruct/ CONVERTED_MODEL=/home/user/gguf/llama.cpp/q4km.gguf
Loading model and tokenizer using AutoTokenizer: /home/user/Kimi-Linear-48B-A3B-Instruct/
Model type:        kimi_linear
Vocab size:        163840
Hidden size:       2304
Number of layers:  27
BOS token id:      163584
EOS token id:      163586
🚨 `generation_mode` is part of KimiLinearForCausalLM.forward's signature, but not documented. Make sure to add it to the docstring of the function in /home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py.
Ignoring the provided attention implementation eager
Using flash_attention_2 backend instead.
Loading checkpoint shards: 100%|███████████████████████████| 20/20 [00:24<00:00,  1.21s/it]
Some parameters are on the meta device because they were offloaded to the cpu and disk.
Model class: KimiLinearForCausalLM
Input tokens: tensor([[19180,    11,  1106,  1530,   387]], device='cuda:0')
Input text: 'Hello, my name is'
Tokenized: ['Hello', ',', 'Ġmy', 'Ġname', 'Ġis']
Traceback (most recent call last):
  File "/home/user/gguf/llama.cpp/examples/model-conversion/./scripts/causal/run-org-model.py", line 199, in <module>
    outputs = model(input_ids.to(model.device))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/accelerate/hooks.py", line 175, in new_forward
    output = module._old_forward(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/generic.py", line 918, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py", line 1072, in forward
    outputs = self.model(
              ^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: check_model_inputs.<locals>.wrapped_fn() got an unexpected keyword argument 'input_ids'
make: *** [Makefile:56: causal-run-original-model] Error 1
```

> > I think this is related to [#42431](https://github.com/huggingface/transformers/pull/42431)
> 
> Thanks for your reply. I applied the patch. It seems to get past that error but I run into another error:
> 
> ```
> make causal-verify-logits MODEL_PATH=/home/user/Kimi-Linear-48B-A3B-Instruct/ CONVERTED_MODEL=/home/user/gguf/llama.cpp/q4km.gguf
> Loading model and tokenizer using AutoTokenizer: /home/user/Kimi-Linear-48B-A3B-Instruct/
> Model type:        kimi_linear
> Vocab size:        163840
> Hidden size:       2304
> Number of layers:  27
> BOS token id:      163584
> EOS token id:      163586
> 🚨 `generation_mode` is part of KimiLinearForCausalLM.forward's signature, but not documented. Make sure to add it to the docstring of the function in /home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py.
> Ignoring the provided attention implementation eager
> Using flash_attention_2 backend instead.
> Loading checkpoint shards: 100%|███████████████████████████| 20/20 [00:24<00:00,  1.21s/it]
> Some parameters are on the meta device because they were offloaded to the cpu and disk.
> Model class: KimiLinearForCausalLM
> Input tokens: tensor([[19180,    11,  1106,  1530,   387]], device='cuda:0')
> Input text: 'Hello, my name is'
> Tokenized: ['Hello', ',', 'Ġmy', 'Ġname', 'Ġis']
> Traceback (most recent call last):
>   File "/home/user/gguf/llama.cpp/examples/model-conversion/./scripts/causal/run-org-model.py", line 199, in <module>
>     outputs = model(input_ids.to(model.device))
>               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
>     return forward_call(*args, **kwargs)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/accelerate/hooks.py", line 175, in new_forward
>     output = module._old_forward(*args, **kwargs)
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/transformers/utils/generic.py", line 918, in wrapper
>     output = func(self, *args, **kwargs)
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/.cache/huggingface/modules/transformers_modules/modeling_kimi.py", line 1072, in forward
>     outputs = self.model(
>               ^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/home/user/anaconda3/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
>     return forward_call(*args, **kwargs)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> TypeError: check_model_inputs.<locals>.wrapped_fn() got an unexpected keyword argument 'input_ids'
> make: *** [Makefile:56: causal-run-original-model] Error 1
> ```
Original PR is not that good. I already updated it. But I am still waiting for his review and approval.


I find that if I downgrade to 4.56.0, then it doesn't crash with this error.