Skip to content

Issue/867: adjust paged_attention_prefill interface naming - #883

Merged
whjthu merged 2 commits into
mainfrom
issue/867
Jan 9, 2026
Merged

Issue/867: adjust paged_attention_prefill interface naming#883
whjthu merged 2 commits into
mainfrom
issue/867

Conversation

@spike-zhu

@spike-zhuspike-zhu commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

python 测试:
image

image

@spike-zhu
spike-zhu requested a review from a teamJanuary 5, 2026 12:34
@spike-zhuspike-zhu changed the title Issue/867: add pagedIssue/867: update paged attention prefill var nameJan 5, 2026
@spike-zhu
spike-zhuforce-pushed the issue/867 branch 4 times, most recently from b8c4b54 to a236f24CompareJanuary 8, 2026 03:26
@spike-zhuspike-zhu self-assigned this Jan 8, 2026
@spike-zhuspike-zhu changed the title Issue/867: update paged attention prefill var nameIssue/867: adjust paged_attention_prefill interface namingJan 8, 2026

// --- 该 token 在当前序列中的相对位置
size_t q_token_idx = global_token_idx - offset_[seq_idx];
const int64_t total_kv_len = total_kv_lens_[seq_idx];

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.

为什么用 int64_t 而不是 size_t?size_t 和 int64_t 一个是有符号,一个是无符号,应该是有明确的功能区分的,且 size_t 严格定义的话并不一定是 64bit。 size_t 和 int64_t 肯定不能混用, size_t 和 uint64_t 应该也是尽量不混用的

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

total_kv_lens是从python端传进来的,所以和pytorch默认int64的行为保持了一致。目前这几个跟index相关的参数只支持了int64类型,在创建的时候也做了限制。如果传入类型需要支持更多类型,可以增加模板参数。
在kernel内部如果需要规范可以强转:“size_t total_kv_len = size_t(total_kv_lens_[seq_idx]); ”,需要这么改吗?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已修改

const int64_t causal_limit = history_len + q_token_idx;

const Tdata *q_ptr_base = q_ + global_token_idx * num_heads * head_size + head_idx * head_size;
// 4. 计算指针偏移

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.

注释改英文,新加代码的注释全用英文,老的遗留问题现在不用改,后面集中改

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已删除

}
return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
}
} No newline at end of file

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.

文件结尾空行

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已修改

if (!alibi_slopes.is_none()) {
alibi_slopes_tensor = alibi_slopes.cast<Tensor>();
}
op::paged_attention_prefill_(out, q, k_cache, v_cache, block_tables, history_lens, cu_seqlens_q, alibi_slopes_tensor, scale);

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.

单行80字符控制?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

现在没这个强制要求了,因为有些强行换行会影响阅读。现在写代码的人可以决定是否换行,这个需要换行吗?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已修改

@whjthu
whjthu merged commit 3883f32 into mainJan 9, 2026
10 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@spike-zhu@whjthu@PanZezhong1725