Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat:support any num_heads for get_alibi_slope #200

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/flashinfer/pos_enc.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ inline std::string PosEncodingModeToString(const PosEncodingMode& pos_encoding_m
}

__device__ __forceinline__ float get_alibi_slope(uint32_t head_idx, uint32_t num_heads) {
// NOTE(Zihao): here we assume that num_heads is a power of 2
return math::ptx_exp2(-8. * float(head_idx + 1) / float(num_heads));
int n = math::ptx_exp2((int)math::ptx_log2(num_heads));
return head_idx < n ? math::ptx_exp2(-8. * float(head_idx + 1) / float(n))
: math::ptx_exp2(-4. * float((head_idx + 1 - n) * 2 - 1) / float(n));
}

/*!
Expand Down