-
Notifications
You must be signed in to change notification settings - Fork 4.9k
whisper : add support for backends with multiple ggml_backend_buffer_type #2863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ggerganov
merged 3 commits into
ggml-org:master
from
eddnjjn:feature/ggml_backend_buffer_type
Mar 26, 2025
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ endif() | |
|
||
add_library(whisper | ||
../include/whisper.h | ||
whisper-arch.h | ||
whisper.cpp | ||
) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
#pragma once | ||
|
||
#include "ggml.h" | ||
|
||
#include <map> | ||
|
||
enum asr_tensor { | ||
ASR_TENSOR_ENC_POS_EMBD, | ||
ASR_TENSOR_DEC_POS_EMBD, | ||
ASR_TENSOR_DEC_TOKEN_EMBD_WEIGHT, | ||
ASR_TENSOR_LN_WEIGHT, | ||
ASR_TENSOR_LN_BIAS, | ||
ASR_TENSOR_CONV1_WEIGHT, | ||
ASR_TENSOR_CONV1_BIAS, | ||
ASR_TENSOR_CONV2_WEIGHT, | ||
ASR_TENSOR_CONV2_BIAS, | ||
ASR_TENSOR_LN_POST_WEIGHT, | ||
ASR_TENSOR_LN_POST_BIAS, | ||
ASR_TENSOR_MLP_LN_WEIGHT, | ||
ASR_TENSOR_MLP_LN_BIAS, | ||
ASR_TENSOR_MLP_0_WEIGHT, | ||
ASR_TENSOR_MLP_0_BIAS, | ||
ASR_TENSOR_MLP_2_WEIGHT, | ||
ASR_TENSOR_MLP_2_BIAS, | ||
ASR_TENSOR_ATTN_LN_WEIGHT, | ||
ASR_TENSOR_ATTN_LN_BIAS, | ||
ASR_TENSOR_ATTN_QUERY_WEIGHT, | ||
ASR_TENSOR_ATTN_QUERY_BIAS, | ||
ASR_TENSOR_ATTN_KEY_WEIGHT, | ||
ASR_TENSOR_ATTN_VALUE_WEIGHT, | ||
ASR_TENSOR_ATTN_VALUE_BIAS, | ||
ASR_TENSOR_ATTN_OUT_WEIGHT, | ||
ASR_TENSOR_ATTN_OUT_BIAS, | ||
}; | ||
|
||
enum asr_system { | ||
ASR_SYSTEM_ENCODER, | ||
ASR_SYSTEM_DECODER, | ||
ASR_SYSTEM_CROSS | ||
}; | ||
|
||
static const std::map<asr_system, std::map<asr_tensor, const char *>> ASR_TENSOR_NAMES = { | ||
{ | ||
ASR_SYSTEM_ENCODER, | ||
{ | ||
{ASR_TENSOR_ENC_POS_EMBD, "encoder.positional_embedding"}, | ||
{ASR_TENSOR_CONV1_WEIGHT, "encoder.conv1.weight"}, | ||
{ASR_TENSOR_CONV1_BIAS, "encoder.conv1.bias"}, | ||
{ASR_TENSOR_CONV2_WEIGHT, "encoder.conv2.weight"}, | ||
{ASR_TENSOR_CONV2_BIAS, "encoder.conv2.bias"}, | ||
{ASR_TENSOR_LN_WEIGHT, "encoder.ln_post.weight"}, | ||
{ASR_TENSOR_LN_POST_BIAS, "encoder.ln_post.bias"}, | ||
{ASR_TENSOR_MLP_LN_WEIGHT, "encoder.blocks.%d.mlp_ln.weight"}, | ||
{ASR_TENSOR_MLP_LN_BIAS, "encoder.blocks.%d.mlp_ln.bias"}, | ||
{ASR_TENSOR_MLP_0_WEIGHT, "encoder.blocks.%d.mlp.0.weight"}, | ||
{ASR_TENSOR_MLP_0_BIAS, "encoder.blocks.%d.mlp.0.bias"}, | ||
{ASR_TENSOR_MLP_2_WEIGHT, "encoder.blocks.%d.mlp.2.weight"}, | ||
{ASR_TENSOR_MLP_2_BIAS, "encoder.blocks.%d.mlp.2.bias"}, | ||
{ASR_TENSOR_ATTN_LN_WEIGHT, "encoder.blocks.%d.attn_ln.weight"}, | ||
{ASR_TENSOR_ATTN_LN_BIAS, "encoder.blocks.%d.attn_ln.bias"}, | ||
{ASR_TENSOR_ATTN_QUERY_WEIGHT, "encoder.blocks.%d.attn.query.weight"}, | ||
{ASR_TENSOR_ATTN_QUERY_BIAS, "encoder.blocks.%d.attn.query.bias"}, | ||
{ASR_TENSOR_ATTN_KEY_WEIGHT, "encoder.blocks.%d.attn.key.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_WEIGHT, "encoder.blocks.%d.attn.value.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_BIAS, "encoder.blocks.%d.attn.value.bias"}, | ||
{ASR_TENSOR_ATTN_OUT_WEIGHT, "encoder.blocks.%d.attn.out.weight"}, | ||
{ASR_TENSOR_ATTN_OUT_BIAS, "encoder.blocks.%d.attn.out.bias"}, | ||
}, | ||
}, | ||
{ | ||
ASR_SYSTEM_DECODER, | ||
{ | ||
{ASR_TENSOR_DEC_POS_EMBD, "decoder.positional_embedding"}, | ||
{ASR_TENSOR_DEC_TOKEN_EMBD_WEIGHT, "decoder.token_embedding.weight"}, | ||
{ASR_TENSOR_LN_WEIGHT, "decoder.ln.weight"}, | ||
{ASR_TENSOR_LN_BIAS, "decoder.ln.bias"}, | ||
|
||
{ASR_TENSOR_MLP_LN_WEIGHT, "decoder.blocks.%d.mlp_ln.weight"}, | ||
{ASR_TENSOR_MLP_LN_BIAS, "decoder.blocks.%d.mlp_ln.bias"}, | ||
{ASR_TENSOR_MLP_0_WEIGHT, "decoder.blocks.%d.mlp.0.weight"}, | ||
{ASR_TENSOR_MLP_0_BIAS, "decoder.blocks.%d.mlp.0.bias"}, | ||
{ASR_TENSOR_MLP_2_WEIGHT, "decoder.blocks.%d.mlp.2.weight"}, | ||
{ASR_TENSOR_MLP_2_BIAS, "decoder.blocks.%d.mlp.2.bias"}, | ||
{ASR_TENSOR_ATTN_LN_WEIGHT, "decoder.blocks.%d.attn_ln.weight"}, | ||
{ASR_TENSOR_ATTN_LN_BIAS, "decoder.blocks.%d.attn_ln.bias"}, | ||
{ASR_TENSOR_ATTN_QUERY_WEIGHT, "decoder.blocks.%d.attn.query.weight"}, | ||
{ASR_TENSOR_ATTN_QUERY_BIAS, "decoder.blocks.%d.attn.query.bias"}, | ||
{ASR_TENSOR_ATTN_KEY_WEIGHT, "decoder.blocks.%d.attn.key.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_WEIGHT, "decoder.blocks.%d.attn.value.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_BIAS, "decoder.blocks.%d.attn.value.bias"}, | ||
{ASR_TENSOR_ATTN_OUT_WEIGHT, "decoder.blocks.%d.attn.out.weight"}, | ||
{ASR_TENSOR_ATTN_OUT_BIAS, "decoder.blocks.%d.attn.out.bias"}, | ||
}, | ||
}, | ||
{ | ||
ASR_SYSTEM_CROSS, | ||
{ | ||
{ASR_TENSOR_ATTN_LN_WEIGHT, "decoder.blocks.%d.cross_attn_ln.weight"}, | ||
{ASR_TENSOR_ATTN_LN_BIAS, "decoder.blocks.%d.cross_attn_ln.bias"}, | ||
{ASR_TENSOR_ATTN_QUERY_WEIGHT, "decoder.blocks.%d.cross_attn.query.weight"}, | ||
{ASR_TENSOR_ATTN_QUERY_BIAS, "decoder.blocks.%d.cross_attn.query.bias"}, | ||
{ASR_TENSOR_ATTN_KEY_WEIGHT, "decoder.blocks.%d.cross_attn.key.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_WEIGHT, "decoder.blocks.%d.cross_attn.value.weight"}, | ||
{ASR_TENSOR_ATTN_VALUE_BIAS, "decoder.blocks.%d.cross_attn.value.bias"}, | ||
{ASR_TENSOR_ATTN_OUT_WEIGHT, "decoder.blocks.%d.cross_attn.out.weight"}, | ||
{ASR_TENSOR_ATTN_OUT_BIAS, "decoder.blocks.%d.cross_attn.out.bias"}, | ||
}, | ||
}, | ||
}; | ||
|
||
static const std::map<asr_tensor, ggml_op> ASR_TENSOR_INFO = { | ||
{ASR_TENSOR_ENC_POS_EMBD, GGML_OP_ADD}, | ||
{ASR_TENSOR_DEC_POS_EMBD, GGML_OP_GET_ROWS}, | ||
// Note: ASR_TENSOR_DEC_TOKEN_EMBD_WEIGHT is also used by GGML_OP_MAT_MUL. Need to figure out a way how to handle | ||
// weight tensors that are used by multiple different operators when extra_buffer_type implementations accelerate | ||
// more than just GGML_OP_MUL_MAT. | ||
{ASR_TENSOR_DEC_TOKEN_EMBD_WEIGHT, GGML_OP_GET_ROWS}, | ||
{ASR_TENSOR_LN_WEIGHT, GGML_OP_MUL}, | ||
{ASR_TENSOR_LN_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_CONV1_WEIGHT, GGML_OP_IM2COL}, | ||
{ASR_TENSOR_CONV1_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_CONV2_WEIGHT, GGML_OP_IM2COL}, | ||
{ASR_TENSOR_CONV2_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_LN_POST_WEIGHT, GGML_OP_MUL}, | ||
{ASR_TENSOR_LN_POST_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_MLP_LN_WEIGHT, GGML_OP_MUL}, | ||
{ASR_TENSOR_MLP_LN_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_MLP_0_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_MLP_0_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_MLP_2_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_MLP_2_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_ATTN_LN_WEIGHT, GGML_OP_MUL}, | ||
{ASR_TENSOR_ATTN_LN_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_ATTN_QUERY_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_ATTN_QUERY_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_ATTN_KEY_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_ATTN_VALUE_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_ATTN_VALUE_BIAS, GGML_OP_ADD}, | ||
{ASR_TENSOR_ATTN_OUT_WEIGHT, GGML_OP_MUL_MAT}, | ||
{ASR_TENSOR_ATTN_OUT_BIAS, GGML_OP_ADD}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this copyright notice.