Laser Attention from Mind-IE support#379
Laser Attention from Mind-IE support#379OrangeRedeng wants to merge 45 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @OrangeRedeng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates a novel 'Laser Attention' mechanism into the Mind-IE framework, specifically optimized for the Ascend AI processor. It introduces a preprocessing operator to handle tensor reshaping and padding, and a main attention operator for the core computation. The implementation includes comprehensive host-side definitions for shape and data type inference, along with dynamic tiling logic and optimized device-side kernels to maximize performance on Ascend hardware. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces new operators for Laser Attention preprocessing and the Laser Attention mechanism itself. The changes include defining operator shapes, data types, tiling functions, and kernel implementations. Several areas for improvement have been identified, primarily concerning maintainability, correctness, and potential runtime issues. These include inconsistent attribute access, use of magic numbers, redundant comments, and critical type handling issues in the kernel code.
| AscendC::Cast<float, T>( | ||
| castLocal.template ReinterpretCast<float>(), castLocal[bufLen_], |
There was a problem hiding this comment.
| AscendC::DataCopyExtParams inCopyParams{ | ||
| 1, seqLen * headNum_ * HEAD_DIM * static_cast<uint32_t>(sizeof(T)), 0, 0, 0}; | ||
| AscendC::DataCopyPadExtParams<T> inPadParams{false, 0, 0, 0}; | ||
| AscendC::DataCopyPad(srcLocal[bufLen_], src, inCopyParams, inPadParams); |
There was a problem hiding this comment.
The expression srcLocal[bufLen_] appears to be an out-of-bounds access if bufLen_ represents the size of the buffer. Typically, srcLocal itself should be passed as the destination for DataCopyPad when copying into the local tensor. This is a critical issue that could lead to memory corruption or crashes.
AscendC::DataCopyPad(srcLocal, src, inCopyParams, inPadParams);| .DataType({ge::DT_FLOAT, ge::DT_FLOAT}) | ||
| .Format({ge::FORMAT_ND, ge::FORMAT_ND}); |
There was a problem hiding this comment.
| for (uint32_t i = 0; i < seqLen; ++i) { | ||
| AscendC::DataCopyExtParams outCopyParams{ | ||
| static_cast<uint16_t>(headNum_), HEAD_DIM * sizeof(T), 0, dstStride, 0}; | ||
| AscendC::DataCopyPad(dst[i * HEAD_DIM], dstLocal[i * headNum_ * HEAD_DIM], outCopyParams); |
There was a problem hiding this comment.
The outCopyParams uses HEAD_DIM * sizeof(T) for the copy size, but the destination dst is GlobalTensor<DST>. This is a type mismatch. It should use HEAD_DIM * sizeof(DST) to correctly specify the size of data being copied to the destination tensor.
AscendC::DataCopyExtParams outCopyParams{
static_cast<uint16_t>(headNum_), HEAD_DIM * sizeof(DST), 0, dstStride, 0};|
|
||
| for (uint32_t i = 0; i < seqLen; ++i) { | ||
| AscendC::DataCopyExtParams outCopyParams{ | ||
| static_cast<uint16_t>(headNum_), HEAD_DIM * sizeof(T), 0, dstStride, 0}; |
| outKShape->SetDim(1, kShape->GetDim(INPUT_HEAD_NUM_DIM)); | ||
| int32_t kPadDim = (kShape->GetDim(1) + alignLen - 1) / alignLen * alignLen; | ||
| outKShape->SetDim(SEQ_LEN_DIM, kPadDim); | ||
| outKShape->SetDim(HEAD_DIM_DIM, kShape->GetDim(INPUT_HEAD_DIM_DIM)); |
| outQShape->SetDim(HEAD_DIM_DIM, qShape->GetDim(INPUT_HEAD_DIM_DIM)); // head_dim | ||
|
|
||
| outKShape->SetDimNum(kShape->GetDimNum()); | ||
| outKShape->SetDim(0, kShape->GetDim(0)); |
| outQShape->SetDim(1, qShape->GetDim(2)); // head_num (从第2维移到第1维) | ||
| int32_t qPadDim = (qShape->GetDim(1) + alignLen - 1) / alignLen * alignLen; // padded seq_len | ||
| outQShape->SetDim(SEQ_LEN_DIM, qPadDim); | ||
| outQShape->SetDim(HEAD_DIM_DIM, qShape->GetDim(INPUT_HEAD_DIM_DIM)); // head_dim |
| outQShape->SetDimNum(qShape->GetDimNum()); | ||
| outQShape->SetDim(0, qShape->GetDim(0)); // batch | ||
| outQShape->SetDim(1, qShape->GetDim(2)); // head_num (从第2维移到第1维) | ||
| int32_t qPadDim = (qShape->GetDim(1) + alignLen - 1) / alignLen * alignLen; // padded seq_len |
| // 输出形状: [batch, head_num, padded_seq_len, head_dim] | ||
| outQShape->SetDimNum(qShape->GetDimNum()); | ||
| outQShape->SetDim(0, qShape->GetDim(0)); // batch | ||
| outQShape->SetDim(1, qShape->GetDim(2)); // head_num (从第2维移到第1维) |
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Moving Mind-IE Laser attention kernels into sgl-kernel-npu repo