transformers icon indicating copy to clipboard operation
transformers copied to clipboard

LlamaAttention forward function type hint is incorrect

Open nhatkhtn opened this issue 7 months ago • 7 comments

System Info

For the current version (4.52.4), in the LlamaAttention class, the type hint for the forward function

https://github.com/huggingface/transformers/blob/aa798b7ac9ff5018b3578eb927dc438671ab6a3e/src/transformers/models/llama/modeling_llama.py#L231

and what it actually returns

https://github.com/huggingface/transformers/blob/aa798b7ac9ff5018b3578eb927dc438671ab6a3e/src/transformers/models/llama/modeling_llama.py#L264

mismatch. Looking at the git blame, this is probably the result of the attention refactor introduced in #35235.

Who can help?

@ArthurZucker

Information

  • [ ] 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

Look at the code

Expected behavior

The type hint should be correct to avoid confusion

nhatkhtn avatar Jun 10 '25 18:06 nhatkhtn

Hello! I noticed a small mismatch in the return type of the LlamaAttention forward method in Transformers version 4.52.4. It does not match what is actually being returned. This might have happened during the recent attention refactor, possibly in pull request . I just wanted to point it out. I would be happy to open a quick pull request to fix it if that helps. Thank you for all the great work you are doing!

ArkVex avatar Jun 10 '25 19:06 ArkVex

@nhatkhtn ?

ArkVex avatar Jun 11 '25 11:06 ArkVex

Hi @nhatkhtn, yes, this looks like an incorrect type hint. Would you be willing to make a PR to fix it?

Rocketknight1 avatar Jun 11 '25 12:06 Rocketknight1

Yeah sure...

ArkVex avatar Jun 11 '25 14:06 ArkVex

@Rocketknight1 i have done the changes...I am pushing the changes Plz review

ArkVex avatar Jun 11 '25 21:06 ArkVex

Hi @ArkVex can you link the PR?

Rocketknight1 avatar Jun 12 '25 14:06 Rocketknight1

#38795 @Rocketknight1

ArkVex avatar Jun 12 '25 15:06 ArkVex

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 are likely to be ignored.

github-actions[bot] avatar Jul 11 '25 08:07 github-actions[bot]

Fixed with #38998

nhatkhtn avatar Jul 15 '25 20:07 nhatkhtn

Thanks!

ArthurZucker avatar Jul 16 '25 09:07 ArthurZucker