fix: handle None padding_to in get_padding_to() for fused attention#8002
Conversation
When using fused attention with tp=1, padding_to can be None causing: TypeError: '>' not supported between instances of 'int' and 'NoneType' The fix uses 'padding_to or 1' to handle the None case, consistent with the pattern used elsewhere in the same function. Fixes modelscope#8000
Summary of ChangesHello @Mr-Neutr0n, 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 addresses a runtime error in the 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 addresses a TypeError in get_padding_to() that occurs when using fused attention with a tensor model parallel size of 1. The issue arises because padding_to can be None, leading to an invalid comparison in max(). The fix correctly handles the None case by using padding_to or 1, which is consistent with how this variable is handled elsewhere in the function. The change is correct and effectively resolves the bug.
Summary
Fixed
TypeError: '>' not supported between instances of 'int' and 'NoneType'inget_padding_to()when using fused attention withtp=1.Problem
When using megatron training with fused attention (
attention_backend='fused') andtensor_model_parallel_size=1, the functionget_padding_to()raises a TypeError:This occurs because
padding_tocan remainNonewhen:tensor_model_parallel_size == 1orsequence_parallelis Falsecontext_parallel_size <= 1fp8_recipe != 'blockwise'andfp8_format is NoneSolution
Applied the same
or 1pattern used elsewhere in the function:Fixes #8000