upstream-carry #32740: ggml: compact bias on the existing FLASH_ATTN_EXT for CUDA, ROCm and Vulkan
Temporary carry of the open upstream PR https://github.com/ggml-org/llama.cpp/pull/32740 at head 808fd1c4e, its four commits (1fa93f902, d29f9d489, ff91e4f84, 808fd1c4e) squashed. Inkling's per-query bias table is applied inside flash attention instead of a dense [n_kv, n_tokens, n_head] bias tensor, which cuts Inkling's compute buffers and long-context prefill time on the RX 580. Drop this commit when the PR is merged upstream (FORK.md, "Temporary upstream carries"). One conflict, ggml-vulkan.cpp use_mask_opt: kept the fork's GCN `HSK >= 256 || HSV >= 256` clause and its comment (F2) and upstream's `!use_sparse`, added the PR's `!bias &&`. Original commit trailer: Assisted-by: Codex Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PZz44SLQvTXMyWGio6t9DZ
This commit is contained in:
1 parent
d2143f1e47
commit
66b3c3f72f
32 files changed
+505
-145
No files matched your search
@@ -2009,14 +2009,18 @@ bool llama_kv_cache::has_cell_ext() const {
|
||||
return hparams.n_pos_per_embd() > 1 || hparams.ple_n_heads > 0;
|
||||
}
|
||||
|
||||
void llama_kv_cache::set_input_relative_pos(ggml_tensor * dst, const llama_ubatch * ubatch, uint32_t extent) const {
|
||||
void llama_kv_cache::set_input_relative_pos(ggml_tensor * dst, const ggml_tensor * rows, const llama_ubatch * ubatch, uint32_t extent) const {
|
||||
GGML_ASSERT(dst->type == GGML_TYPE_I32);
|
||||
const int64_t n_kv = dst->ne[0];
|
||||
GGML_ASSERT(!rows || (rows->ne[0] == n_kv && ggml_backend_buffer_is_host(rows->buffer)));
|
||||
const int64_t n_tps = ubatch->n_tokens / (rows ? rows->ne[1] : 1);
|
||||
std::vector<int32_t> data(n_kv * ubatch->n_tokens);
|
||||
for (uint32_t i = 0; i < ubatch->n_tokens; ++i) {
|
||||
const auto & cells = v_cells.at(seq_to_stream.at(ubatch->seq_id[i][0]));
|
||||
const int32_t * list = rows ? (const int32_t *) rows->data + (i/n_tps)*n_kv : nullptr;
|
||||
for (int64_t j = 0; j < n_kv; ++j) {
|
||||
const int64_t distance = cells.is_empty(j) ? -1 : int64_t(ubatch->pos[i]) - cells.pos_get(j);
|
||||
const int64_t cell = list ? list[j] : j;
|
||||
const int64_t distance = cell < 0 || cells.is_empty(cell) ? -1 : int64_t(ubatch->pos[i]) - cells.pos_get(cell);
|
||||
data[i*n_kv + j] = distance >= 0 && distance < extent ? distance : extent;
|
||||
}
|
||||
}
|
||||
@@ -3210,8 +3214,8 @@ void llama_kv_cache_context::set_input_pos_bucket(ggml_tensor * dst, const llama
|
||||
kv->set_input_pos_bucket(dst, ubatch);
|
||||
}
|
||||
|
||||
void llama_kv_cache_context::set_input_relative_pos(ggml_tensor * dst, const llama_ubatch * ubatch, uint32_t extent) const {
|
||||
kv->set_input_relative_pos(dst, ubatch, extent);
|
||||
void llama_kv_cache_context::set_input_relative_pos(ggml_tensor * dst, const ggml_tensor * rows, const llama_ubatch * ubatch, uint32_t extent) const {
|
||||
kv->set_input_relative_pos(dst, rows, ubatch, extent);
|
||||
}
|
||||
|
||||
void llama_kv_cache_context::get_prev_tokens(const llama_ubatch & ubatch, uint32_t n, std::vector<llama_token> & res) const {
|
||||
|
||||
Reference in new issue
Block a user