Skip to content

Fix assertion error when packed_seq_params is passed without proper qkv_format#109

Open
tomzw11 wants to merge 1 commit into
modelscope:mainfrom
tomzw11:fix-pack-seq-params-assertion
Open

Fix assertion error when packed_seq_params is passed without proper qkv_format#109
tomzw11 wants to merge 1 commit into
modelscope:mainfrom
tomzw11:fix-pack-seq-params-assertion

Conversation

@tomzw11

@tomzw11 tomzw11 commented Jun 4, 2026

Copy link
Copy Markdown

问题描述

即使没有配置 --reset-attention-mask,也会有 packed_seq_params 被传入,但缺少 qkv_formatcu_seqlens_q,导致 assertion 错误:AssertionError: Packed sequences are not supported when fla is not available.

修复方案

修改 cu_seqlens 的初始化逻辑,仅在满足以下所有条件时才设置 cu_seqlens

  1. packed_seq_params is not None
  2. packed_seq_paramsqkv_format 属性
  3. qkv_format == 'thd'
  4. cu_seqlens_q is not None

…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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +187 to +193
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

使用 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)

@Jintao-Huang

Copy link
Copy Markdown
Collaborator

没懂,什么场景下 packed_seq_params 为非None值,但是没有 cu_seqlens_q

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.

2 participants