Fix assertion error when packed_seq_params is passed without proper qkv_format#109
Fix assertion error when packed_seq_params is passed without proper qkv_format#109tomzw11 wants to merge 1 commit into
Conversation
…kv_format Only set cu_seqlens when all conditions are met: - packed_seq_params is not None - qkv_format is 'thd' - cu_seqlens_q is not None
There was a problem hiding this comment.
Code Review
This pull request modifies the packed sequence handling in gated_delta_net.py to ensure cu_seqlens is only set when qkv_format is 'thd' and cu_seqlens_q is present. The reviewer suggested using getattr to safely and concisely access these attributes on packed_seq_params to prevent potential AttributeError exceptions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # Only use packed sequences when qkv_format is 'thd' and cu_seqlens_q is present | ||
| cu_seqlens = None | ||
| if (packed_seq_params is not None and | ||
| hasattr(packed_seq_params, 'qkv_format') and | ||
| packed_seq_params.qkv_format == 'thd' and | ||
| packed_seq_params.cu_seqlens_q is not None): | ||
| cu_seqlens = packed_seq_params.cu_seqlens_q |
There was a problem hiding this comment.
使用 getattr 可以更安全、更简洁地获取属性。这样不仅能避免多次调用 hasattr 和直接属性访问,还能防止在 packed_seq_params 缺少 cu_seqlens_q 属性时触发 AttributeError 异常。
# Only use packed sequences when qkv_format is 'thd' and cu_seqlens_q is present
cu_seqlens = None
if packed_seq_params is not None and getattr(packed_seq_params, 'qkv_format', None) == 'thd':
cu_seqlens = getattr(packed_seq_params, 'cu_seqlens_q', None)|
没懂,什么场景下 packed_seq_params 为非None值,但是没有 cu_seqlens_q |
问题描述
即使没有配置
--reset-attention-mask,也会有packed_seq_params被传入,但缺少qkv_format或cu_seqlens_q,导致 assertion 错误:AssertionError: Packed sequences are not supported when fla is not available.修复方案
修改
cu_seqlens的初始化逻辑,仅在满足以下所有条件时才设置cu_seqlens:packed_seq_params is not Nonepacked_seq_params有qkv_format属性qkv_format == 'thd'cu_seqlens_q is not None