Skip to content

Add zero dim tensor check when using flash_attention#38280

Merged
ArthurZucker merged 2 commits into
huggingface:mainfrom
ranzhejiang:zhejiang_fix_flash_attn
Jun 25, 2025
Merged

Add zero dim tensor check when using flash_attention#38280
ArthurZucker merged 2 commits into
huggingface:mainfrom
ranzhejiang:zhejiang_fix_flash_attn

Conversation

@ranzhejiang

Copy link
Copy Markdown
Contributor

The cuda or triton kernel can not support this case: dimensions of size is 0, but traditional SDPA is implemented using PyTorch's tensor operations, which have robust support for tensors with dimensions of size 0. We need to add this check and error tips for developers when using flash_attention. Related issue is in deepspeedai/DeepSpeed#7275

@Rocketknight1

Copy link
Copy Markdown
Member

cc @ArthurZucker for FA2

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'd rather we write 3 explicit checks as only query, key and value need this check. Maybe even just testing key?

@ranzhejiang

ranzhejiang commented May 23, 2025

Copy link
Copy Markdown
Contributor Author

Thanks, I'd rather we write 3 explicit checks as only query, key and value need this check. Maybe even just testing key?

Do you mean we don't need write a function to do this check, just call explicit check directly? if so, I agree with you, I can write 3 explicit checks for query, key and value, or only for key, and give users info which shape is wrong.

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Yeah, I mean only checking q should be enough as well no?

@ranzhejiang ranzhejiang force-pushed the zhejiang_fix_flash_attn branch 3 times, most recently from 3d36772 to 8365960 Compare May 30, 2025 09:37
Signed-off-by: ranzhejiang <zhejiang.ran@intel.com>
@ranzhejiang

Copy link
Copy Markdown
Contributor Author

Yeah, I mean only checking q should be enough as well no?

Yes, I agree with you and have change my code, thanks for review

Signed-off-by: ranzhejiang <zhejiang.ran@intel.com>
@ranzhejiang

Copy link
Copy Markdown
Contributor Author

@ArthurZucker Hi ArthurZucker, I have changed my code following your advice, can you help review this PR ? Thanks

@ArthurZucker ArthurZucker merged commit ae32f1a into huggingface:main Jun 25, 2025
18 checks passed
@ArthurZucker

Copy link
Copy Markdown
Collaborator

sorry I was out for holidays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants