RWKV6-Finch-7B-HF crashes during inference
Author: assafbk
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.50.3
- Platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.35
- Python version: 3.10.16
- Huggingface_hub version: 0.30.1
- Safetensors version: 0.5.3
- Accelerate version: 1.6.0
- Accelerate config:    not found
- DeepSpeed version: not installed
- PyTorch version (GPU?): 2.5.1+cu118 (True)
- 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?: no
- Using GPU in script?: yes
- GPU type: NVIDIA RTX A6000

### Who can help?

@ArthurZucker, @gante 

### Information

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

### Tasks

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

### Reproduction

Code snippet for reproduction:
```
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

def generate_prompt(instruction, input=""):
    instruction = instruction.strip().replace('\r\n','\n').replace('\n\n','\n')
    input = input.strip().replace('\r\n','\n').replace('\n\n','\n')
    if input:
        return f"""Instruction: {instruction}

Input: {input}

Response:"""
    else:
        return f"""User: hi

Assistant: Hi. I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.

User: {instruction}

Assistant:"""


model = AutoModelForCausalLM.from_pretrained("RWKV/v6-Finch-7B-HF", trust_remote_code=True, torch_dtype=torch.float16).to('cuda')
tokenizer = AutoTokenizer.from_pretrained("RWKV/v6-Finch-7B-HF", trust_remote_code=True)

text = "Hello how are you?"
prompt = generate_prompt(text)

inputs = tokenizer(prompt, return_tensors="pt").to('cuda')
output = model.generate(inputs["input_ids"], max_new_tokens=128, do_sample=False)
print(tokenizer.decode(output[0].tolist(), skip_special_tokens=True))
```

Error message:

> Traceback (most recent call last):
>   File "/data2/assaf/tmp/rwkv_test.py", line 30, in <module>
>     output = model.generate(inputs["input_ids"], max_new_tokens=128, do_sample=False)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
>     return func(*args, **kwargs)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/transformers/generation/utils.py", line 2326, in generate
>     result = self._sample(
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/transformers/generation/utils.py", line 3286, in _sample
>     outputs = self(**model_inputs, return_dict=True)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
>     return forward_call(*args, **kwargs)
>   File "/home/assaf/.cache/huggingface/modules/transformers_modules/RWKV/v6-Finch-7B-HF/02946e470978a56fc96bc8c47cb942c50bc9c71a/modeling_rwkv6.py", line 716, in forward
>     outputs = self.rwkv(
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
>     return forward_call(*args, **kwargs)
>   File "/home/assaf/.cache/huggingface/modules/transformers_modules/RWKV/v6-Finch-7B-HF/02946e470978a56fc96bc8c47cb942c50bc9c71a/modeling_rwkv6.py", line 574, in forward
>     hidden_states, state, attentions = block(
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
>     return forward_call(*args, **kwargs)
>   File "/home/assaf/.cache/huggingface/modules/transformers_modules/RWKV/v6-Finch-7B-HF/02946e470978a56fc96bc8c47cb942c50bc9c71a/modeling_rwkv6.py", line 275, in forward
>     attention, state = self.attention(self.ln1(hidden), state=state, use_cache=use_cache, seq_mode=seq_mode)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
>     return self._call_impl(*args, **kwargs)
>   File "/data2/assaf/conda_envs/recurrent_gemma_tmp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
>     return forward_call(*args, **kwargs)
>   File "/home/assaf/.cache/huggingface/modules/transformers_modules/RWKV/v6-Finch-7B-HF/02946e470978a56fc96bc8c47cb942c50bc9c71a/modeling_rwkv6.py", line 192, in forward
>     receptance, key, value, gate, time_decay, state = self.extract_key_value(hidden, state=state)
>   File "/home/assaf/.cache/huggingface/modules/transformers_modules/RWKV/v6-Finch-7B-HF/02946e470978a56fc96bc8c47cb942c50bc9c71a/modeling_rwkv6.py", line 183, in extract_key_value
>     time_decay = torch.tanh(time_decay @ self.time_decay_w1) @ self.time_decay_w2
> RuntimeError: expected mat1 and mat2 to have the same dtype, but got: c10::Half != float


### Expected behavior

Regular inference is expected, yet the script crashes with the error message above. 

The bug was seen in transformers version v4.50.3
It does not reproduce on earlier transformers versions, such as v4.42.4

Comments:
Hi @assafbk, same comment as on your other issue - can you use `git bisect` to find the commit where this error started occuring?

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.