Skip to content

[0-size Tensor No.88] Add 0-size Tensor support for paddle.incubate.nn.functional.variable_length_memory_efficient_attention [fluid_ops] - #74157

Merged
luotao1 merged 4 commits into
PaddlePaddle:developfrom
co63oc:h35
Jul 28, 2025
Merged

luotao1 merged 4 commits into
PaddlePaddle:developfrom
co63oc:h35

Conversation

@co63oc

@co63oc co63oc commented Jul 22, 2025 •

Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

infermeta 增加key_num_head不为0时计算除法,符号推导没有对应代码
out numel为0返回
增加单测

PaddleAPITest 修改后的测试用例通过
image

@paddle-bot

paddle-bot Bot commented Jul 22, 2025

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 22, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jul 22, 2025
@co63oc

co63oc commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@co63oc

co63oc commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

@DanielSun11 CI已完成需要review

Comment thread paddle/phi/infermeta/fusion.cc Outdated
if (mask_dims[1] == 0 && query_num_head != 0) {
query_num_head = 0;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

paddle特有的api,API的描述如下:

    Cutlass Memory Efficient Variable Attention.
    This method requires SM_ARCH in sm70, sm75, sm80.

    Args:
        query (Tensor): The Query Tensor. Its shape is [batchsize, num_head, seq_len, head_size].
        key (Tensor): The Key Tensor. Its shape is [batchsize, num_head, seq_len, head_size].
        value (Tensor): The Value Tensor. Its shape is [batchsize, num_head, seq_len, head_size].
        seq_lens (Tensor): The sequence lengths of the sequences in the batch, used to index query. Its shape is [batchsize, 1].
        kv_seq_lens (Tensor): The sequence lengths of the sequences in the batch, used to index key and value. Its shape is [batchsize, 1].
        mask (Tensor|None, optional): The Mask Tensor. Its shape is [batchsize, 1, query_seq_len, key_seq_len].
        scale (Float|None, optional): The attention matrix's scale. Default is sqrt(1.0 / head_size).
        causal (Bool): Whether causal masking is used or not. Default is False.
        pre_cache_length (Int): The length of the pre-cache. Default is 0.
    Returns:
        Tensor, the output Tensor.“

明确了q k v的shape应该完全一致以及明确了mask的shape要求。因此不需要针对0-size跳过一些检查,应当保证api描述中对shape的要求。不合法的case可以从paddleapitest中删除或者更改为符合shape要求的0-size 测试case。paddleapitest中的一些case是生成的,不需要完全拟合测试case,可根据api的描述删掉/更改一些不合法的case。但是需要至少保留几个有效的测试case,以测试0-size的场景是否报错

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

修改测试用例PR PFCCLab/PaddleAPITest#434

Comment thread paddle/phi/infermeta/fusion.cc Resolved
Comment thread paddle/phi/infermeta/fusion.cc Resolved
@codecov-commenter

codecov-commenter commented Jul 24, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@98204ab). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #74157   +/-   ##
==========================================
  Coverage           ?        0           
==========================================
  Files              ?        0           
  Lines              ?        0           
  Branches           ?        0           
==========================================
  Hits               ?        0           
  Misses             ?        0           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@co63oc co63oc changed the title [0-size Tensor No.88] Add 0-size Tensor support for paddle.incubate.nn.functional.variable_length_memory_efficient_attention [0-size Tensor No.88] Add 0-size Tensor support for paddle.incubate.nn.functional.variable_length_memory_efficient_attention [fluid_ops] Jul 26, 2025
@co63oc

co63oc commented Jul 26, 2025

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@DanielSun11 DanielSun11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@luotao1
luotao1 merged commit bfa8da2 into PaddlePaddle:develop Jul 28, 2025
@co63oc
co63oc deleted the h35 branch July 29, 2025 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 skip-ci: approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants