Merge remote-tracking branch 'origin/master' into jinja
This commit is contained in:
commit
099f983949
39 changed files with 3745 additions and 717 deletions
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
|
@ -87,6 +87,7 @@ jobs:
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
cp LICENSE ./build/bin/
|
cp LICENSE ./build/bin/
|
||||||
|
cp examples/run/linenoise.cpp/LICENSE ./build/bin/LICENSE.linenoise.cpp
|
||||||
zip -r llama-${{ steps.tag.outputs.name }}-bin-macos-arm64.zip ./build/bin/*
|
zip -r llama-${{ steps.tag.outputs.name }}-bin-macos-arm64.zip ./build/bin/*
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
|
@ -149,6 +150,7 @@ jobs:
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
cp LICENSE ./build/bin/
|
cp LICENSE ./build/bin/
|
||||||
|
cp examples/run/linenoise.cpp/LICENSE ./build/bin/LICENSE.linenoise.cpp
|
||||||
zip -r llama-${{ steps.tag.outputs.name }}-bin-macos-x64.zip ./build/bin/*
|
zip -r llama-${{ steps.tag.outputs.name }}-bin-macos-x64.zip ./build/bin/*
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
|
@ -217,6 +219,7 @@ jobs:
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
cp LICENSE ./build/bin/
|
cp LICENSE ./build/bin/
|
||||||
|
cp examples/run/linenoise.cpp/LICENSE ./build/bin/LICENSE.linenoise.cpp
|
||||||
zip -r llama-${{ steps.tag.outputs.name }}-bin-ubuntu-x64.zip ./build/bin/*
|
zip -r llama-${{ steps.tag.outputs.name }}-bin-ubuntu-x64.zip ./build/bin/*
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
|
@ -234,7 +237,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
sanitizer: [ADDRESS, THREAD, UNDEFINED]
|
sanitizer: [ADDRESS, THREAD, UNDEFINED]
|
||||||
build_type: [Debug, Release]
|
build_type: [Debug]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
|
@ -796,6 +799,7 @@ jobs:
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
Copy-Item LICENSE .\build\bin\Release\llama.cpp.txt
|
Copy-Item LICENSE .\build\bin\Release\llama.cpp.txt
|
||||||
|
Copy-Item .\examples\run\linenoise.cpp\LICENSE .\build\bin\Release\linenoise.cpp.txt
|
||||||
7z a llama-${{ steps.tag.outputs.name }}-bin-win-${{ matrix.build }}.zip .\build\bin\Release\*
|
7z a llama-${{ steps.tag.outputs.name }}-bin-win-${{ matrix.build }}.zip .\build\bin\Release\*
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
|
|
25
.github/workflows/server.yml
vendored
25
.github/workflows/server.yml
vendored
|
@ -112,9 +112,9 @@ jobs:
|
||||||
-DGGML_OPENMP=OFF ;
|
-DGGML_OPENMP=OFF ;
|
||||||
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server
|
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server
|
||||||
|
|
||||||
- name: Build
|
- name: Build (sanitizers)
|
||||||
id: cmake_build
|
id: cmake_build_sanitizers
|
||||||
if: ${{ matrix.sanitizer != 'THREAD' }}
|
if: ${{ matrix.sanitizer != '' && matrix.sanitizer != 'THREAD' }}
|
||||||
run: |
|
run: |
|
||||||
cmake -B build \
|
cmake -B build \
|
||||||
-DGGML_NATIVE=OFF \
|
-DGGML_NATIVE=OFF \
|
||||||
|
@ -124,12 +124,31 @@ jobs:
|
||||||
-DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON ;
|
-DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON ;
|
||||||
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server
|
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server
|
||||||
|
|
||||||
|
- name: Build (sanitizers)
|
||||||
|
id: cmake_build
|
||||||
|
if: ${{ matrix.sanitizer == '' }}
|
||||||
|
run: |
|
||||||
|
cmake -B build \
|
||||||
|
-DGGML_NATIVE=OFF \
|
||||||
|
-DLLAMA_BUILD_SERVER=ON \
|
||||||
|
-DLLAMA_CURL=ON \
|
||||||
|
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ;
|
||||||
|
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target llama-server
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
id: server_integration_tests
|
id: server_integration_tests
|
||||||
|
if: ${{ matrix.sanitizer == '' }}
|
||||||
run: |
|
run: |
|
||||||
cd examples/server/tests
|
cd examples/server/tests
|
||||||
./tests.sh
|
./tests.sh
|
||||||
|
|
||||||
|
- name: Tests (sanitizers)
|
||||||
|
id: server_integration_tests_sanitizers
|
||||||
|
if: ${{ matrix.sanitizer != '' }}
|
||||||
|
run: |
|
||||||
|
cd examples/server/tests
|
||||||
|
LLAMA_SANITIZE=1 ./tests.sh
|
||||||
|
|
||||||
- name: Slow tests
|
- name: Slow tests
|
||||||
id: server_integration_tests_slow
|
id: server_integration_tests_slow
|
||||||
if: ${{ (github.event.schedule || github.event.inputs.slow_tests == 'true') && matrix.build_type == 'Release' }}
|
if: ${{ (github.event.schedule || github.event.inputs.slow_tests == 'true') && matrix.build_type == 'Release' }}
|
||||||
|
|
|
@ -83,11 +83,8 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake)
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake)
|
||||||
|
|
||||||
# override ggml options
|
# override ggml options
|
||||||
set(GGML_SANITIZE_THREAD ${LLAMA_SANITIZE_THREAD})
|
set(GGML_ALL_WARNINGS ${LLAMA_ALL_WARNINGS})
|
||||||
set(GGML_SANITIZE_ADDRESS ${LLAMA_SANITIZE_ADDRESS})
|
set(GGML_FATAL_WARNINGS ${LLAMA_FATAL_WARNINGS})
|
||||||
set(GGML_SANITIZE_UNDEFINED ${LLAMA_SANITIZE_UNDEFINED})
|
|
||||||
set(GGML_ALL_WARNINGS ${LLAMA_ALL_WARNINGS})
|
|
||||||
set(GGML_FATAL_WARNINGS ${LLAMA_FATAL_WARNINGS})
|
|
||||||
|
|
||||||
# change the default for these ggml options
|
# change the default for these ggml options
|
||||||
if (NOT DEFINED GGML_LLAMAFILE)
|
if (NOT DEFINED GGML_LLAMAFILE)
|
||||||
|
@ -117,16 +114,62 @@ llama_option_depr(WARNING LLAMA_SYCL GGML_SYCL)
|
||||||
llama_option_depr(WARNING LLAMA_SYCL_F16 GGML_SYCL_F16)
|
llama_option_depr(WARNING LLAMA_SYCL_F16 GGML_SYCL_F16)
|
||||||
llama_option_depr(WARNING LLAMA_CANN GGML_CANN)
|
llama_option_depr(WARNING LLAMA_CANN GGML_CANN)
|
||||||
|
|
||||||
|
if (NOT MSVC)
|
||||||
|
if (LLAMA_SANITIZE_THREAD)
|
||||||
|
message(STATUS "Using -fsanitize=thread")
|
||||||
|
|
||||||
|
add_compile_options(-fsanitize=thread)
|
||||||
|
link_libraries (-fsanitize=thread)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (LLAMA_SANITIZE_ADDRESS)
|
||||||
|
message(STATUS "Using -fsanitize=address")
|
||||||
|
|
||||||
|
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||||
|
link_libraries (-fsanitize=address)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (LLAMA_SANITIZE_UNDEFINED)
|
||||||
|
message(STATUS "Using -fsanitize=undefined")
|
||||||
|
|
||||||
|
add_compile_options(-fsanitize=undefined)
|
||||||
|
link_libraries (-fsanitize=undefined)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
#
|
#
|
||||||
# build the library
|
# 3rd-party
|
||||||
#
|
#
|
||||||
|
|
||||||
if (NOT TARGET ggml)
|
if (NOT TARGET ggml)
|
||||||
add_subdirectory(ggml)
|
add_subdirectory(ggml)
|
||||||
# ... otherwise assume ggml is added by a parent CMakeLists.txt
|
# ... otherwise assume ggml is added by a parent CMakeLists.txt
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# build the library
|
||||||
|
#
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
#
|
||||||
|
# utils, programs, examples and tests
|
||||||
|
#
|
||||||
|
|
||||||
|
if (LLAMA_BUILD_COMMON)
|
||||||
|
add_subdirectory(common)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TESTS AND NOT CMAKE_JS_VERSION)
|
||||||
|
include(CTest)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
add_subdirectory(pocs)
|
||||||
|
endif()
|
||||||
|
|
||||||
#
|
#
|
||||||
# install
|
# install
|
||||||
#
|
#
|
||||||
|
@ -200,21 +243,3 @@ configure_file(cmake/llama.pc.in
|
||||||
|
|
||||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/llama.pc"
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/llama.pc"
|
||||||
DESTINATION lib/pkgconfig)
|
DESTINATION lib/pkgconfig)
|
||||||
|
|
||||||
#
|
|
||||||
# utils, programs, examples and tests
|
|
||||||
#
|
|
||||||
|
|
||||||
if (LLAMA_BUILD_COMMON)
|
|
||||||
add_subdirectory(common)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TESTS AND NOT CMAKE_JS_VERSION)
|
|
||||||
include(CTest)
|
|
||||||
add_subdirectory(tests)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_EXAMPLES)
|
|
||||||
add_subdirectory(examples)
|
|
||||||
add_subdirectory(pocs)
|
|
||||||
endif()
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ if(MSVC)
|
||||||
set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
|
set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
|
||||||
else()
|
else()
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}
|
COMMAND sh -c "\"$@\" --version | head -1" _ ${CMAKE_C_COMPILER}
|
||||||
OUTPUT_VARIABLE OUT
|
OUTPUT_VARIABLE OUT
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
)
|
)
|
||||||
|
|
|
@ -133,7 +133,8 @@ static void common_params_handle_model_default(
|
||||||
const std::string & model_url,
|
const std::string & model_url,
|
||||||
std::string & hf_repo,
|
std::string & hf_repo,
|
||||||
std::string & hf_file,
|
std::string & hf_file,
|
||||||
const std::string & hf_token) {
|
const std::string & hf_token,
|
||||||
|
const std::string & model_default) {
|
||||||
if (!hf_repo.empty()) {
|
if (!hf_repo.empty()) {
|
||||||
// short-hand to avoid specifying --hf-file -> default it to --model
|
// short-hand to avoid specifying --hf-file -> default it to --model
|
||||||
if (hf_file.empty()) {
|
if (hf_file.empty()) {
|
||||||
|
@ -163,7 +164,7 @@ static void common_params_handle_model_default(
|
||||||
model = fs_get_cache_file(string_split<std::string>(f, '/').back());
|
model = fs_get_cache_file(string_split<std::string>(f, '/').back());
|
||||||
}
|
}
|
||||||
} else if (model.empty()) {
|
} else if (model.empty()) {
|
||||||
model = DEFAULT_MODEL_PATH;
|
model = model_default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,8 +300,9 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor model params in a common struct
|
// TODO: refactor model params in a common struct
|
||||||
common_params_handle_model_default(params.model, params.model_url, params.hf_repo, params.hf_file, params.hf_token);
|
common_params_handle_model_default(params.model, params.model_url, params.hf_repo, params.hf_file, params.hf_token, DEFAULT_MODEL_PATH);
|
||||||
common_params_handle_model_default(params.vocoder.model, params.vocoder.model_url, params.vocoder.hf_repo, params.vocoder.hf_file, params.hf_token);
|
common_params_handle_model_default(params.speculative.model, params.speculative.model_url, params.speculative.hf_repo, params.speculative.hf_file, params.hf_token, "");
|
||||||
|
common_params_handle_model_default(params.vocoder.model, params.vocoder.model_url, params.vocoder.hf_repo, params.vocoder.hf_file, params.hf_token, "");
|
||||||
|
|
||||||
if (params.escape) {
|
if (params.escape) {
|
||||||
string_process_escapes(params.prompt);
|
string_process_escapes(params.prompt);
|
||||||
|
@ -1637,6 +1639,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||||
params.hf_repo = value;
|
params.hf_repo = value;
|
||||||
}
|
}
|
||||||
).set_env("LLAMA_ARG_HF_REPO"));
|
).set_env("LLAMA_ARG_HF_REPO"));
|
||||||
|
add_opt(common_arg(
|
||||||
|
{"-hfd", "-hfrd", "--hf-repo-draft"}, "<user>/<model>[:quant]",
|
||||||
|
"Same as --hf-repo, but for the draft model (default: unused)",
|
||||||
|
[](common_params & params, const std::string & value) {
|
||||||
|
params.speculative.hf_repo = value;
|
||||||
|
}
|
||||||
|
).set_env("LLAMA_ARG_HFD_REPO"));
|
||||||
add_opt(common_arg(
|
add_opt(common_arg(
|
||||||
{"-hff", "--hf-file"}, "FILE",
|
{"-hff", "--hf-file"}, "FILE",
|
||||||
"Hugging Face model file. If specified, it will override the quant in --hf-repo (default: unused)",
|
"Hugging Face model file. If specified, it will override the quant in --hf-repo (default: unused)",
|
||||||
|
@ -2282,6 +2291,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||||
params.vocoder.model = value;
|
params.vocoder.model = value;
|
||||||
}
|
}
|
||||||
).set_examples({LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_SERVER}));
|
).set_examples({LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_SERVER}));
|
||||||
|
add_opt(common_arg(
|
||||||
|
{"--tts-use-guide-tokens"},
|
||||||
|
"Use guide tokens to improve TTS word recall",
|
||||||
|
[](common_params & params) {
|
||||||
|
params.vocoder.use_guide_tokens = true;
|
||||||
|
}
|
||||||
|
).set_examples({LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_SERVER}));
|
||||||
|
|
||||||
// model-specific
|
// model-specific
|
||||||
add_opt(common_arg(
|
add_opt(common_arg(
|
||||||
|
|
|
@ -175,7 +175,11 @@ struct common_params_speculative {
|
||||||
struct cpu_params cpuparams;
|
struct cpu_params cpuparams;
|
||||||
struct cpu_params cpuparams_batch;
|
struct cpu_params cpuparams_batch;
|
||||||
|
|
||||||
std::string model = ""; // draft model for speculative decoding // NOLINT
|
std::string hf_repo = ""; // HF repo // NOLINT
|
||||||
|
std::string hf_file = ""; // HF file // NOLINT
|
||||||
|
|
||||||
|
std::string model = ""; // draft model for speculative decoding // NOLINT
|
||||||
|
std::string model_url = ""; // model url to download // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct common_params_vocoder {
|
struct common_params_vocoder {
|
||||||
|
@ -184,6 +188,8 @@ struct common_params_vocoder {
|
||||||
|
|
||||||
std::string model = ""; // model path // NOLINT
|
std::string model = ""; // model path // NOLINT
|
||||||
std::string model_url = ""; // model url to download // NOLINT
|
std::string model_url = ""; // model url to download // NOLINT
|
||||||
|
|
||||||
|
bool use_guide_tokens = false; // enable guide tokens to improve TTS accuracy // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct common_params {
|
struct common_params {
|
||||||
|
@ -507,12 +513,14 @@ struct llama_model * common_load_model_from_url(
|
||||||
const std::string & local_path,
|
const std::string & local_path,
|
||||||
const std::string & hf_token,
|
const std::string & hf_token,
|
||||||
const struct llama_model_params & params);
|
const struct llama_model_params & params);
|
||||||
|
|
||||||
struct llama_model * common_load_model_from_hf(
|
struct llama_model * common_load_model_from_hf(
|
||||||
const std::string & repo,
|
const std::string & repo,
|
||||||
const std::string & remote_path,
|
const std::string & remote_path,
|
||||||
const std::string & local_path,
|
const std::string & local_path,
|
||||||
const std::string & hf_token,
|
const std::string & hf_token,
|
||||||
const struct llama_model_params & params);
|
const struct llama_model_params & params);
|
||||||
|
|
||||||
std::pair<std::string, std::string> common_get_hf_file(
|
std::pair<std::string, std::string> common_get_hf_file(
|
||||||
const std::string & hf_repo_with_tag,
|
const std::string & hf_repo_with_tag,
|
||||||
const std::string & hf_token);
|
const std::string & hf_token);
|
||||||
|
|
|
@ -696,6 +696,9 @@ class Model:
|
||||||
if chkhsh == "877081d19cf6996e2c4ff0e1236341e9b7bde288f5311a56a937f0afbbb3aeb5":
|
if chkhsh == "877081d19cf6996e2c4ff0e1236341e9b7bde288f5311a56a937f0afbbb3aeb5":
|
||||||
# ref: https://huggingface.co/deepseek-ai/DeepSeek-V3
|
# ref: https://huggingface.co/deepseek-ai/DeepSeek-V3
|
||||||
res = "deepseek-v3"
|
res = "deepseek-v3"
|
||||||
|
if chkhsh == "b3f499bb4255f8ca19fccd664443283318f2fd2414d5e0b040fbdd0cc195d6c5":
|
||||||
|
# ref: https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
|
||||||
|
res = "deepseek-r1-qwen"
|
||||||
|
|
||||||
if res is None:
|
if res is None:
|
||||||
logger.warning("\n")
|
logger.warning("\n")
|
||||||
|
|
|
@ -65,49 +65,50 @@ else:
|
||||||
|
|
||||||
# TODO: add models here, base models preferred
|
# TODO: add models here, base models preferred
|
||||||
models = [
|
models = [
|
||||||
{"name": "llama-spm", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/meta-llama/Llama-2-7b-hf", },
|
{"name": "llama-spm", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/meta-llama/Llama-2-7b-hf", },
|
||||||
{"name": "llama-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/meta-llama/Meta-Llama-3-8B", },
|
{"name": "llama-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/meta-llama/Meta-Llama-3-8B", },
|
||||||
{"name": "phi-3", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct", },
|
{"name": "phi-3", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct", },
|
||||||
{"name": "deepseek-llm", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/deepseek-llm-7b-base", },
|
{"name": "deepseek-llm", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/deepseek-llm-7b-base", },
|
||||||
{"name": "deepseek-coder", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base", },
|
{"name": "deepseek-coder", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base", },
|
||||||
{"name": "falcon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/falcon-7b", },
|
{"name": "falcon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/falcon-7b", },
|
||||||
{"name": "bert-bge", "tokt": TOKENIZER_TYPE.WPM, "repo": "https://huggingface.co/BAAI/bge-small-en-v1.5", },
|
{"name": "bert-bge", "tokt": TOKENIZER_TYPE.WPM, "repo": "https://huggingface.co/BAAI/bge-small-en-v1.5", },
|
||||||
{"name": "falcon3", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/Falcon3-7B-Base", },
|
{"name": "falcon3", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/tiiuae/Falcon3-7B-Base", },
|
||||||
{"name": "bert-bge-large", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/BAAI/bge-large-zh-v1.5", },
|
{"name": "bert-bge-large", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/BAAI/bge-large-zh-v1.5", },
|
||||||
{"name": "mpt", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mosaicml/mpt-7b", },
|
{"name": "mpt", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mosaicml/mpt-7b", },
|
||||||
{"name": "starcoder", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/bigcode/starcoder2-3b", },
|
{"name": "starcoder", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/bigcode/starcoder2-3b", },
|
||||||
{"name": "gpt-2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/openai-community/gpt2", },
|
{"name": "gpt-2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/openai-community/gpt2", },
|
||||||
{"name": "stablelm2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/stabilityai/stablelm-2-zephyr-1_6b", },
|
{"name": "stablelm2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/stabilityai/stablelm-2-zephyr-1_6b", },
|
||||||
{"name": "refact", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/smallcloudai/Refact-1_6-base", },
|
{"name": "refact", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/smallcloudai/Refact-1_6-base", },
|
||||||
{"name": "command-r", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/CohereForAI/c4ai-command-r-v01", },
|
{"name": "command-r", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/CohereForAI/c4ai-command-r-v01", },
|
||||||
{"name": "qwen2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Qwen/Qwen1.5-7B", },
|
{"name": "qwen2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Qwen/Qwen1.5-7B", },
|
||||||
{"name": "olmo", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/allenai/OLMo-1.7-7B-hf", },
|
{"name": "olmo", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/allenai/OLMo-1.7-7B-hf", },
|
||||||
{"name": "dbrx", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/databricks/dbrx-base", },
|
{"name": "dbrx", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/databricks/dbrx-base", },
|
||||||
{"name": "jina-v1-en", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-reranker-v1-tiny-en", },
|
{"name": "jina-v1-en", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-reranker-v1-tiny-en", },
|
||||||
{"name": "jina-v2-en", "tokt": TOKENIZER_TYPE.WPM, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-en", }, # WPM!
|
{"name": "jina-v2-en", "tokt": TOKENIZER_TYPE.WPM, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-en", }, # WPM!
|
||||||
{"name": "jina-v2-es", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-es", },
|
{"name": "jina-v2-es", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-es", },
|
||||||
{"name": "jina-v2-de", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-de", },
|
{"name": "jina-v2-de", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-de", },
|
||||||
{"name": "smaug-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/abacusai/Smaug-Llama-3-70B-Instruct", },
|
{"name": "smaug-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/abacusai/Smaug-Llama-3-70B-Instruct", },
|
||||||
{"name": "poro-chat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LumiOpen/Poro-34B-chat", },
|
{"name": "poro-chat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LumiOpen/Poro-34B-chat", },
|
||||||
{"name": "jina-v2-code", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-code", },
|
{"name": "jina-v2-code", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jinaai/jina-embeddings-v2-base-code", },
|
||||||
{"name": "viking", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LumiOpen/Viking-7B", }, # Also used for Viking 13B and 33B
|
{"name": "viking", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LumiOpen/Viking-7B", }, # Also used for Viking 13B and 33B
|
||||||
{"name": "gemma", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/google/gemma-2b", },
|
{"name": "gemma", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/google/gemma-2b", },
|
||||||
{"name": "gemma-2", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/google/gemma-2-9b", },
|
{"name": "gemma-2", "tokt": TOKENIZER_TYPE.SPM, "repo": "https://huggingface.co/google/gemma-2-9b", },
|
||||||
{"name": "jais", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/core42/jais-13b", },
|
{"name": "jais", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/core42/jais-13b", },
|
||||||
{"name": "t5", "tokt": TOKENIZER_TYPE.UGM, "repo": "https://huggingface.co/google-t5/t5-small", },
|
{"name": "t5", "tokt": TOKENIZER_TYPE.UGM, "repo": "https://huggingface.co/google-t5/t5-small", },
|
||||||
{"name": "codeshell", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/WisdomShell/CodeShell-7B", },
|
{"name": "codeshell", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/WisdomShell/CodeShell-7B", },
|
||||||
{"name": "tekken", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mistralai/Mistral-Nemo-Base-2407", },
|
{"name": "tekken", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/mistralai/Mistral-Nemo-Base-2407", },
|
||||||
{"name": "smollm", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/HuggingFaceTB/SmolLM-135M", },
|
{"name": "smollm", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/HuggingFaceTB/SmolLM-135M", },
|
||||||
{'name': "bloom", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/bigscience/bloom", },
|
{'name': "bloom", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/bigscience/bloom", },
|
||||||
{'name': "gpt3-finnish", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/TurkuNLP/gpt3-finnish-small", },
|
{'name': "gpt3-finnish", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/TurkuNLP/gpt3-finnish-small", },
|
||||||
{"name": "exaone", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct", },
|
{"name": "exaone", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct", },
|
||||||
{"name": "phi-2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/microsoft/phi-2", },
|
{"name": "phi-2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/microsoft/phi-2", },
|
||||||
{"name": "chameleon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/facebook/chameleon-7b", },
|
{"name": "chameleon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/facebook/chameleon-7b", },
|
||||||
{"name": "minerva-7b", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/sapienzanlp/Minerva-7B-base-v1.0", },
|
{"name": "minerva-7b", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/sapienzanlp/Minerva-7B-base-v1.0", },
|
||||||
{"name": "roberta-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/sentence-transformers/stsb-roberta-base"},
|
{"name": "roberta-bpe", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/sentence-transformers/stsb-roberta-base"},
|
||||||
{"name": "gigachat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/ai-sage/GigaChat-20B-A3B-instruct"},
|
{"name": "gigachat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/ai-sage/GigaChat-20B-A3B-instruct"},
|
||||||
{"name": "megrez", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Infinigence/Megrez-3B-Instruct"},
|
{"name": "megrez", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/Infinigence/Megrez-3B-Instruct"},
|
||||||
{"name": "deepseek-v3", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/DeepSeek-V3"},
|
{"name": "deepseek-v3", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/DeepSeek-V3"},
|
||||||
|
{"name": "deepseek-r1-qwen", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
set(TARGET llama-run)
|
set(TARGET llama-run)
|
||||||
add_executable(${TARGET} run.cpp)
|
add_executable(${TARGET} run.cpp linenoise.cpp/linenoise.cpp)
|
||||||
install(TARGETS ${TARGET} RUNTIME)
|
install(TARGETS ${TARGET} RUNTIME)
|
||||||
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_compile_features(${TARGET} PRIVATE cxx_std_17)
|
target_compile_features(${TARGET} PRIVATE cxx_std_17)
|
||||||
|
|
26
examples/run/linenoise.cpp/LICENSE
Normal file
26
examples/run/linenoise.cpp/LICENSE
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
|
Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||||
|
Copyright (c) 2025, Eric Curtin <ericcurtin17 at gmail dot com>
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1351
examples/run/linenoise.cpp/linenoise.cpp
Normal file
1351
examples/run/linenoise.cpp/linenoise.cpp
Normal file
File diff suppressed because it is too large
Load diff
114
examples/run/linenoise.cpp/linenoise.h
Normal file
114
examples/run/linenoise.cpp/linenoise.h
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/* linenoise.h -- VERSION 1.0
|
||||||
|
*
|
||||||
|
* Guerrilla line editing library against the idea that a line editing lib
|
||||||
|
* needs to be 20,000 lines of C++ code.
|
||||||
|
*
|
||||||
|
* See linenoise.cpp for more information.
|
||||||
|
*
|
||||||
|
* ------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010-2023, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
|
* Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||||
|
* Copyright (c) 2025, Eric Curtin <ericcurtin17 at gmail dot com>
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LINENOISE_H
|
||||||
|
#define __LINENOISE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stddef.h> /* For size_t. */
|
||||||
|
|
||||||
|
extern const char *linenoiseEditMore;
|
||||||
|
|
||||||
|
/* The linenoiseState structure represents the state during line editing.
|
||||||
|
* We pass this state to functions implementing specific editing
|
||||||
|
* functionalities. */
|
||||||
|
struct linenoiseState {
|
||||||
|
int in_completion; /* The user pressed TAB and we are now in completion
|
||||||
|
* mode, so input is handled by completeLine(). */
|
||||||
|
size_t completion_idx; /* Index of next completion to propose. */
|
||||||
|
int ifd; /* Terminal stdin file descriptor. */
|
||||||
|
int ofd; /* Terminal stdout file descriptor. */
|
||||||
|
char *buf; /* Edited line buffer. */
|
||||||
|
size_t buflen; /* Edited line buffer size. */
|
||||||
|
const char *prompt; /* Prompt to display. */
|
||||||
|
size_t plen; /* Prompt length. */
|
||||||
|
size_t pos; /* Current cursor position. */
|
||||||
|
size_t oldpos; /* Previous refresh cursor position. */
|
||||||
|
size_t len; /* Current edited line length. */
|
||||||
|
size_t cols; /* Number of columns in terminal. */
|
||||||
|
size_t oldrows; /* Rows used by last refrehsed line (multiline mode) */
|
||||||
|
int history_index; /* The history index we are currently editing. */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct linenoiseCompletions {
|
||||||
|
size_t len;
|
||||||
|
char **cvec;
|
||||||
|
} linenoiseCompletions;
|
||||||
|
|
||||||
|
/* Non blocking API. */
|
||||||
|
int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt);
|
||||||
|
const char *linenoiseEditFeed(struct linenoiseState *l);
|
||||||
|
void linenoiseEditStop(struct linenoiseState *l);
|
||||||
|
void linenoiseHide(struct linenoiseState *l);
|
||||||
|
void linenoiseShow(struct linenoiseState *l);
|
||||||
|
|
||||||
|
/* Blocking API. */
|
||||||
|
const char *linenoise(const char *prompt);
|
||||||
|
void linenoiseFree(void *ptr);
|
||||||
|
|
||||||
|
/* Completion API. */
|
||||||
|
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||||
|
typedef const char*(linenoiseHintsCallback)(const char *, int *color, int *bold);
|
||||||
|
typedef void(linenoiseFreeHintsCallback)(const char *);
|
||||||
|
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||||
|
void linenoiseSetHintsCallback(linenoiseHintsCallback *);
|
||||||
|
void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
|
||||||
|
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||||
|
|
||||||
|
/* History API. */
|
||||||
|
int linenoiseHistoryAdd(const char *line);
|
||||||
|
int linenoiseHistorySetMaxLen(int len);
|
||||||
|
int linenoiseHistorySave(const char *filename);
|
||||||
|
int linenoiseHistoryLoad(const char *filename);
|
||||||
|
|
||||||
|
/* Other utilities. */
|
||||||
|
void linenoiseClearScreen(void);
|
||||||
|
void linenoiseSetMultiLine(int ml);
|
||||||
|
void linenoisePrintKeyCodes(void);
|
||||||
|
void linenoiseMaskModeEnable(void);
|
||||||
|
void linenoiseMaskModeDisable(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __LINENOISE_H */
|
|
@ -19,12 +19,14 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
#include "linenoise.cpp/linenoise.h"
|
||||||
#include "llama-cpp.h"
|
#include "llama-cpp.h"
|
||||||
#include "chat-template.hpp"
|
#include "chat-template.hpp"
|
||||||
|
|
||||||
|
@ -540,7 +542,7 @@ class LlamaData {
|
||||||
llama_sampler_ptr sampler;
|
llama_sampler_ptr sampler;
|
||||||
llama_context_ptr context;
|
llama_context_ptr context;
|
||||||
std::vector<llama_chat_message> messages;
|
std::vector<llama_chat_message> messages;
|
||||||
std::vector<std::string> msg_strs;
|
std::list<std::string> msg_strs;
|
||||||
std::vector<char> fmtted;
|
std::vector<char> fmtted;
|
||||||
|
|
||||||
int init(Opt & opt) {
|
int init(Opt & opt) {
|
||||||
|
@ -749,10 +751,12 @@ static int apply_chat_template(const llama_chat_template & tmpl, LlamaData & lla
|
||||||
|
|
||||||
// Function to tokenize the prompt
|
// Function to tokenize the prompt
|
||||||
static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt,
|
static int tokenize_prompt(const llama_vocab * vocab, const std::string & prompt,
|
||||||
std::vector<llama_token> & prompt_tokens) {
|
std::vector<llama_token> & prompt_tokens, const LlamaData & llama_data) {
|
||||||
const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true);
|
const bool is_first = llama_get_kv_cache_used_cells(llama_data.context.get()) == 0;
|
||||||
|
|
||||||
|
const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, is_first, true);
|
||||||
prompt_tokens.resize(n_prompt_tokens);
|
prompt_tokens.resize(n_prompt_tokens);
|
||||||
if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), true,
|
if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), is_first,
|
||||||
true) < 0) {
|
true) < 0) {
|
||||||
printe("failed to tokenize the prompt\n");
|
printe("failed to tokenize the prompt\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -798,7 +802,7 @@ static int generate(LlamaData & llama_data, const std::string & prompt, std::str
|
||||||
const llama_vocab * vocab = llama_model_get_vocab(llama_data.model.get());
|
const llama_vocab * vocab = llama_model_get_vocab(llama_data.model.get());
|
||||||
|
|
||||||
std::vector<llama_token> tokens;
|
std::vector<llama_token> tokens;
|
||||||
if (tokenize_prompt(vocab, prompt, tokens) < 0) {
|
if (tokenize_prompt(vocab, prompt, tokens, llama_data) < 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,24 +833,44 @@ static int generate(LlamaData & llama_data, const std::string & prompt, std::str
|
||||||
batch = llama_batch_get_one(&new_token_id, 1);
|
batch = llama_batch_get_one(&new_token_id, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\033[0m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_user_input(std::string & user) {
|
static int read_user_input(std::string & user_input) {
|
||||||
std::getline(std::cin, user);
|
static const char * prompt_prefix = "> ";
|
||||||
|
#ifdef WIN32
|
||||||
|
printf(
|
||||||
|
"\r%*s"
|
||||||
|
"\r\033[0m%s",
|
||||||
|
get_terminal_width(), " ", prompt_prefix);
|
||||||
|
|
||||||
|
std::getline(std::cin, user_input);
|
||||||
if (std::cin.eof()) {
|
if (std::cin.eof()) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
if (user == "/bye") {
|
std::unique_ptr<char, decltype(&std::free)> line(const_cast<char *>(linenoise(prompt_prefix)), free);
|
||||||
|
if (!line) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.empty()) {
|
user_input = line.get();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (user_input == "/bye") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user_input.empty()) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
linenoiseHistoryAdd(line.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0; // Should have data in happy path
|
return 0; // Should have data in happy path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,10 +911,6 @@ static int handle_user_input(std::string & user_input, const std::string & user)
|
||||||
return 0; // No need for interactive input
|
return 0; // No need for interactive input
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(
|
|
||||||
"\r%*s"
|
|
||||||
"\r\033[32m> \033[0m",
|
|
||||||
get_terminal_width(), " ");
|
|
||||||
return read_user_input(user_input); // Returns true if input ends the loop
|
return read_user_input(user_input); // Returns true if input ends the loop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,6 +19,7 @@
|
||||||
#include "loading.html.hpp"
|
#include "loading.html.hpp"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
@ -33,6 +34,8 @@
|
||||||
|
|
||||||
using json = nlohmann::ordered_json;
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
|
constexpr int HTTP_POLLING_SECONDS = 1;
|
||||||
|
|
||||||
enum stop_type {
|
enum stop_type {
|
||||||
STOP_TYPE_NONE,
|
STOP_TYPE_NONE,
|
||||||
STOP_TYPE_EOS,
|
STOP_TYPE_EOS,
|
||||||
|
@ -1603,6 +1606,30 @@ struct server_response {
|
||||||
// should never reach here
|
// should never reach here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same as recv(), but have timeout in seconds
|
||||||
|
// if timeout is reached, nullptr is returned
|
||||||
|
server_task_result_ptr recv_with_timeout(const std::unordered_set<int> & id_tasks, int timeout) {
|
||||||
|
while (true) {
|
||||||
|
std::unique_lock<std::mutex> lock(mutex_results);
|
||||||
|
bool cr_res = condition_results.wait_for(lock, std::chrono::seconds(timeout), [&]{
|
||||||
|
return !queue_results.empty();
|
||||||
|
});
|
||||||
|
if (!cr_res) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (int) queue_results.size(); i++) {
|
||||||
|
if (id_tasks.find(queue_results[i]->id) != id_tasks.end()) {
|
||||||
|
server_task_result_ptr res = std::move(queue_results[i]);
|
||||||
|
queue_results.erase(queue_results.begin() + i);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// should never reach here
|
||||||
|
}
|
||||||
|
|
||||||
// single-task version of recv()
|
// single-task version of recv()
|
||||||
server_task_result_ptr recv(int id_task) {
|
server_task_result_ptr recv(int id_task) {
|
||||||
std::unordered_set<int> id_tasks = {id_task};
|
std::unordered_set<int> id_tasks = {id_task};
|
||||||
|
@ -1704,13 +1731,16 @@ struct server_context {
|
||||||
add_bos_token = llama_vocab_get_add_bos(vocab);
|
add_bos_token = llama_vocab_get_add_bos(vocab);
|
||||||
has_eos_token = llama_vocab_eos(vocab) != LLAMA_TOKEN_NULL;
|
has_eos_token = llama_vocab_eos(vocab) != LLAMA_TOKEN_NULL;
|
||||||
|
|
||||||
if (!params_base.speculative.model.empty()) {
|
if (!params_base.speculative.model.empty() || !params_base.speculative.hf_repo.empty()) {
|
||||||
SRV_INF("loading draft model '%s'\n", params_base.speculative.model.c_str());
|
SRV_INF("loading draft model '%s'\n", params_base.speculative.model.c_str());
|
||||||
|
|
||||||
auto params_dft = params_base;
|
auto params_dft = params_base;
|
||||||
|
|
||||||
params_dft.devices = params_base.speculative.devices;
|
params_dft.devices = params_base.speculative.devices;
|
||||||
|
params_dft.hf_file = params_base.speculative.hf_file;
|
||||||
|
params_dft.hf_repo = params_base.speculative.hf_repo;
|
||||||
params_dft.model = params_base.speculative.model;
|
params_dft.model = params_base.speculative.model;
|
||||||
|
params_dft.model_url = params_base.speculative.model_url;
|
||||||
params_dft.n_ctx = params_base.speculative.n_ctx == 0 ? params_base.n_ctx / params_base.n_parallel : params_base.speculative.n_ctx;
|
params_dft.n_ctx = params_base.speculative.n_ctx == 0 ? params_base.n_ctx / params_base.n_parallel : params_base.speculative.n_ctx;
|
||||||
params_dft.n_gpu_layers = params_base.speculative.n_gpu_layers;
|
params_dft.n_gpu_layers = params_base.speculative.n_gpu_layers;
|
||||||
params_dft.n_parallel = 1;
|
params_dft.n_parallel = 1;
|
||||||
|
@ -2349,10 +2379,21 @@ struct server_context {
|
||||||
void receive_multi_results(
|
void receive_multi_results(
|
||||||
const std::unordered_set<int> & id_tasks,
|
const std::unordered_set<int> & id_tasks,
|
||||||
const std::function<void(std::vector<server_task_result_ptr>&)> & result_handler,
|
const std::function<void(std::vector<server_task_result_ptr>&)> & result_handler,
|
||||||
const std::function<void(json)> & error_handler) {
|
const std::function<void(json)> & error_handler,
|
||||||
|
const std::function<bool()> & is_connection_closed) {
|
||||||
std::vector<server_task_result_ptr> results(id_tasks.size());
|
std::vector<server_task_result_ptr> results(id_tasks.size());
|
||||||
for (size_t i = 0; i < id_tasks.size(); i++) {
|
for (int i = 0; i < (int)id_tasks.size(); i++) {
|
||||||
server_task_result_ptr result = queue_results.recv(id_tasks);
|
server_task_result_ptr result = queue_results.recv_with_timeout(id_tasks, HTTP_POLLING_SECONDS);
|
||||||
|
|
||||||
|
if (is_connection_closed()) {
|
||||||
|
cancel_tasks(id_tasks);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == nullptr) {
|
||||||
|
i--; // retry
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (result->is_error()) {
|
if (result->is_error()) {
|
||||||
error_handler(result->to_json());
|
error_handler(result->to_json());
|
||||||
|
@ -2376,10 +2417,20 @@ struct server_context {
|
||||||
void receive_cmpl_results_stream(
|
void receive_cmpl_results_stream(
|
||||||
const std::unordered_set<int> & id_tasks,
|
const std::unordered_set<int> & id_tasks,
|
||||||
const std::function<bool(server_task_result_ptr&)> & result_handler,
|
const std::function<bool(server_task_result_ptr&)> & result_handler,
|
||||||
const std::function<void(json)> & error_handler) {
|
const std::function<void(json)> & error_handler,
|
||||||
|
const std::function<bool()> & is_connection_closed) {
|
||||||
size_t n_finished = 0;
|
size_t n_finished = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
server_task_result_ptr result = queue_results.recv(id_tasks);
|
server_task_result_ptr result = queue_results.recv_with_timeout(id_tasks, HTTP_POLLING_SECONDS);
|
||||||
|
|
||||||
|
if (is_connection_closed()) {
|
||||||
|
cancel_tasks(id_tasks);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == nullptr) {
|
||||||
|
continue; // retry
|
||||||
|
}
|
||||||
|
|
||||||
if (result->is_error()) {
|
if (result->is_error()) {
|
||||||
error_handler(result->to_json());
|
error_handler(result->to_json());
|
||||||
|
@ -3663,6 +3714,7 @@ int main(int argc, char ** argv) {
|
||||||
const auto handle_completions_impl = [&ctx_server, &res_error, &res_ok](
|
const auto handle_completions_impl = [&ctx_server, &res_error, &res_ok](
|
||||||
server_task_type type,
|
server_task_type type,
|
||||||
json & data,
|
json & data,
|
||||||
|
std::function<bool()> is_connection_closed,
|
||||||
httplib::Response & res,
|
httplib::Response & res,
|
||||||
oaicompat_type oaicompat) {
|
oaicompat_type oaicompat) {
|
||||||
GGML_ASSERT(type == SERVER_TASK_TYPE_COMPLETION || type == SERVER_TASK_TYPE_INFILL);
|
GGML_ASSERT(type == SERVER_TASK_TYPE_COMPLETION || type == SERVER_TASK_TYPE_INFILL);
|
||||||
|
@ -3724,7 +3776,7 @@ int main(int argc, char ** argv) {
|
||||||
}
|
}
|
||||||
}, [&](const json & error_data) {
|
}, [&](const json & error_data) {
|
||||||
res_error(res, error_data);
|
res_error(res, error_data);
|
||||||
});
|
}, is_connection_closed);
|
||||||
|
|
||||||
ctx_server.queue_results.remove_waiting_task_ids(task_ids);
|
ctx_server.queue_results.remove_waiting_task_ids(task_ids);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3734,6 +3786,7 @@ int main(int argc, char ** argv) {
|
||||||
if (res_json.is_array()) {
|
if (res_json.is_array()) {
|
||||||
for (const auto & res : res_json) {
|
for (const auto & res : res_json) {
|
||||||
if (!server_sent_event(sink, "data", res)) {
|
if (!server_sent_event(sink, "data", res)) {
|
||||||
|
// sending failed (HTTP connection closed), cancel the generation
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3743,6 +3796,9 @@ int main(int argc, char ** argv) {
|
||||||
}
|
}
|
||||||
}, [&](const json & error_data) {
|
}, [&](const json & error_data) {
|
||||||
server_sent_event(sink, "error", error_data);
|
server_sent_event(sink, "error", error_data);
|
||||||
|
}, [&sink]() {
|
||||||
|
// note: do not use req.is_connection_closed here because req is already destroyed
|
||||||
|
return !sink.is_writable();
|
||||||
});
|
});
|
||||||
if (oaicompat != OAICOMPAT_TYPE_NONE) {
|
if (oaicompat != OAICOMPAT_TYPE_NONE) {
|
||||||
static const std::string ev_done = "data: [DONE]\n\n";
|
static const std::string ev_done = "data: [DONE]\n\n";
|
||||||
|
@ -3765,6 +3821,7 @@ int main(int argc, char ** argv) {
|
||||||
return handle_completions_impl(
|
return handle_completions_impl(
|
||||||
SERVER_TASK_TYPE_COMPLETION,
|
SERVER_TASK_TYPE_COMPLETION,
|
||||||
data,
|
data,
|
||||||
|
req.is_connection_closed,
|
||||||
res,
|
res,
|
||||||
OAICOMPAT_TYPE_NONE);
|
OAICOMPAT_TYPE_NONE);
|
||||||
};
|
};
|
||||||
|
@ -3774,6 +3831,7 @@ int main(int argc, char ** argv) {
|
||||||
return handle_completions_impl(
|
return handle_completions_impl(
|
||||||
SERVER_TASK_TYPE_COMPLETION,
|
SERVER_TASK_TYPE_COMPLETION,
|
||||||
data,
|
data,
|
||||||
|
req.is_connection_closed,
|
||||||
res,
|
res,
|
||||||
OAICOMPAT_TYPE_COMPLETION);
|
OAICOMPAT_TYPE_COMPLETION);
|
||||||
};
|
};
|
||||||
|
@ -3850,6 +3908,7 @@ int main(int argc, char ** argv) {
|
||||||
return handle_completions_impl(
|
return handle_completions_impl(
|
||||||
SERVER_TASK_TYPE_INFILL,
|
SERVER_TASK_TYPE_INFILL,
|
||||||
data,
|
data,
|
||||||
|
req.is_connection_closed,
|
||||||
res,
|
res,
|
||||||
OAICOMPAT_TYPE_NONE); // infill is not OAI compatible
|
OAICOMPAT_TYPE_NONE); // infill is not OAI compatible
|
||||||
};
|
};
|
||||||
|
@ -3867,6 +3926,7 @@ int main(int argc, char ** argv) {
|
||||||
return handle_completions_impl(
|
return handle_completions_impl(
|
||||||
SERVER_TASK_TYPE_COMPLETION,
|
SERVER_TASK_TYPE_COMPLETION,
|
||||||
data,
|
data,
|
||||||
|
req.is_connection_closed,
|
||||||
res,
|
res,
|
||||||
OAICOMPAT_TYPE_CHAT);
|
OAICOMPAT_TYPE_CHAT);
|
||||||
};
|
};
|
||||||
|
@ -4013,7 +4073,7 @@ int main(int argc, char ** argv) {
|
||||||
}, [&](const json & error_data) {
|
}, [&](const json & error_data) {
|
||||||
res_error(res, error_data);
|
res_error(res, error_data);
|
||||||
error = true;
|
error = true;
|
||||||
});
|
}, req.is_connection_closed);
|
||||||
|
|
||||||
ctx_server.queue_results.remove_waiting_task_ids(task_ids);
|
ctx_server.queue_results.remove_waiting_task_ids(task_ids);
|
||||||
}
|
}
|
||||||
|
@ -4103,7 +4163,7 @@ int main(int argc, char ** argv) {
|
||||||
}, [&](const json & error_data) {
|
}, [&](const json & error_data) {
|
||||||
res_error(res, error_data);
|
res_error(res, error_data);
|
||||||
error = true;
|
error = true;
|
||||||
});
|
}, req.is_connection_closed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
import requests
|
||||||
import time
|
import time
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from utils import *
|
from utils import *
|
||||||
|
@ -405,3 +406,23 @@ def test_n_probs_post_sampling():
|
||||||
assert "bytes" in prob and type(prob["bytes"]) == list
|
assert "bytes" in prob and type(prob["bytes"]) == list
|
||||||
# because the test model usually output token with either 100% or 0% probability, we need to check all the top_probs
|
# because the test model usually output token with either 100% or 0% probability, we need to check all the top_probs
|
||||||
assert any(prob["prob"] == 1.0 for prob in tok["top_probs"])
|
assert any(prob["prob"] == 1.0 for prob in tok["top_probs"])
|
||||||
|
|
||||||
|
|
||||||
|
def test_cancel_request():
|
||||||
|
global server
|
||||||
|
server.n_ctx = 4096
|
||||||
|
server.n_predict = -1
|
||||||
|
server.n_slots = 1
|
||||||
|
server.server_slots = True
|
||||||
|
server.start()
|
||||||
|
# send a request that will take a long time, but cancel it before it finishes
|
||||||
|
try:
|
||||||
|
server.make_request("POST", "/completion", data={
|
||||||
|
"prompt": "I believe the meaning of life is",
|
||||||
|
}, timeout=0.1)
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
pass # expected
|
||||||
|
# make sure the slot is free
|
||||||
|
time.sleep(1) # wait for HTTP_POLLING_SECONDS
|
||||||
|
res = server.make_request("GET", "/slots")
|
||||||
|
assert res.body[0]["is_processing"] == False
|
||||||
|
|
|
@ -26,6 +26,9 @@ from re import RegexFlag
|
||||||
import wget
|
import wget
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_HTTP_TIMEOUT = 10 if "LLAMA_SANITIZE" not in os.environ else 30
|
||||||
|
|
||||||
|
|
||||||
class ServerResponse:
|
class ServerResponse:
|
||||||
headers: dict
|
headers: dict
|
||||||
status_code: int
|
status_code: int
|
||||||
|
@ -89,7 +92,7 @@ class ServerProcess:
|
||||||
if "PORT" in os.environ:
|
if "PORT" in os.environ:
|
||||||
self.server_port = int(os.environ["PORT"])
|
self.server_port = int(os.environ["PORT"])
|
||||||
|
|
||||||
def start(self, timeout_seconds: int = 10) -> None:
|
def start(self, timeout_seconds: int | None = DEFAULT_HTTP_TIMEOUT) -> None:
|
||||||
if "LLAMA_SERVER_BIN_PATH" in os.environ:
|
if "LLAMA_SERVER_BIN_PATH" in os.environ:
|
||||||
server_path = os.environ["LLAMA_SERVER_BIN_PATH"]
|
server_path = os.environ["LLAMA_SERVER_BIN_PATH"]
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
|
@ -224,17 +227,18 @@ class ServerProcess:
|
||||||
path: str,
|
path: str,
|
||||||
data: dict | Any | None = None,
|
data: dict | Any | None = None,
|
||||||
headers: dict | None = None,
|
headers: dict | None = None,
|
||||||
|
timeout: float | None = None,
|
||||||
) -> ServerResponse:
|
) -> ServerResponse:
|
||||||
url = f"http://{self.server_host}:{self.server_port}{path}"
|
url = f"http://{self.server_host}:{self.server_port}{path}"
|
||||||
parse_body = False
|
parse_body = False
|
||||||
if method == "GET":
|
if method == "GET":
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers, timeout=timeout)
|
||||||
parse_body = True
|
parse_body = True
|
||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
response = requests.post(url, headers=headers, json=data)
|
response = requests.post(url, headers=headers, json=data, timeout=timeout)
|
||||||
parse_body = True
|
parse_body = True
|
||||||
elif method == "OPTIONS":
|
elif method == "OPTIONS":
|
||||||
response = requests.options(url, headers=headers)
|
response = requests.options(url, headers=headers, timeout=timeout)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unimplemented method: {method}")
|
raise ValueError(f"Unimplemented method: {method}")
|
||||||
result = ServerResponse()
|
result = ServerResponse()
|
||||||
|
|
|
@ -98,10 +98,12 @@ int main(int argc, char ** argv) {
|
||||||
auto generate = [&](const std::string & prompt) {
|
auto generate = [&](const std::string & prompt) {
|
||||||
std::string response;
|
std::string response;
|
||||||
|
|
||||||
|
const bool is_first = llama_get_kv_cache_used_cells(ctx) == 0;
|
||||||
|
|
||||||
// tokenize the prompt
|
// tokenize the prompt
|
||||||
const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, true, true);
|
const int n_prompt_tokens = -llama_tokenize(vocab, prompt.c_str(), prompt.size(), NULL, 0, is_first, true);
|
||||||
std::vector<llama_token> prompt_tokens(n_prompt_tokens);
|
std::vector<llama_token> prompt_tokens(n_prompt_tokens);
|
||||||
if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), llama_get_kv_cache_used_cells(ctx) == 0, true) < 0) {
|
if (llama_tokenize(vocab, prompt.c_str(), prompt.size(), prompt_tokens.data(), prompt_tokens.size(), is_first, true) < 0) {
|
||||||
GGML_ABORT("failed to tokenize the prompt\n");
|
GGML_ABORT("failed to tokenize the prompt\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,6 +425,33 @@ static void prompt_init(llama_tokens & prompt, const llama_vocab * vocab) {
|
||||||
prompt_add(prompt, vocab, "<|im_start|>\n", true, true);
|
prompt_add(prompt, vocab, "<|im_start|>\n", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<llama_token> prepare_guide_tokens(const llama_vocab * vocab, const std::string & str) {
|
||||||
|
const std::string& delimiter = "<|text_sep|>";
|
||||||
|
|
||||||
|
std::vector<llama_token> result;
|
||||||
|
size_t start = 0;
|
||||||
|
size_t end = str.find(delimiter);
|
||||||
|
|
||||||
|
//first token is always a newline, as it was not previously added
|
||||||
|
result.push_back(common_tokenize(vocab, "\n", false, true)[0]);
|
||||||
|
|
||||||
|
while (end != std::string::npos) {
|
||||||
|
std::string current_word = str.substr(start, end - start);
|
||||||
|
auto tmp = common_tokenize(vocab, current_word, false, true);
|
||||||
|
result.push_back(tmp[0]);
|
||||||
|
start = end + delimiter.length();
|
||||||
|
end = str.find(delimiter, start);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the last part
|
||||||
|
std::string current_word = str.substr(start);
|
||||||
|
auto tmp = common_tokenize(vocab, current_word, false, true);
|
||||||
|
if (tmp.size() > 0) {
|
||||||
|
result.push_back(tmp[0]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
common_params params;
|
common_params params;
|
||||||
|
|
||||||
|
@ -494,6 +521,7 @@ int main(int argc, char ** argv) {
|
||||||
const auto t_main_start = ggml_time_us();
|
const auto t_main_start = ggml_time_us();
|
||||||
|
|
||||||
std::vector<llama_token> codes;
|
std::vector<llama_token> codes;
|
||||||
|
std::vector<llama_token> guide_tokens;
|
||||||
|
|
||||||
// process prompt and generate voice codes
|
// process prompt and generate voice codes
|
||||||
{
|
{
|
||||||
|
@ -508,6 +536,9 @@ int main(int argc, char ** argv) {
|
||||||
// convert the input text into the necessary format expected by OuteTTS
|
// convert the input text into the necessary format expected by OuteTTS
|
||||||
{
|
{
|
||||||
std::string prompt_clean = process_text(params.prompt);
|
std::string prompt_clean = process_text(params.prompt);
|
||||||
|
if (params.vocoder.use_guide_tokens) {
|
||||||
|
guide_tokens = prepare_guide_tokens(vocab, prompt_clean);
|
||||||
|
}
|
||||||
|
|
||||||
LOG_INF("%s: prompt: '%s'\n", __func__, prompt_clean.c_str());
|
LOG_INF("%s: prompt: '%s'\n", __func__, prompt_clean.c_str());
|
||||||
|
|
||||||
|
@ -717,6 +748,8 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
|
||||||
int n_past = batch.n_tokens;
|
int n_past = batch.n_tokens;
|
||||||
int n_decode = 0;
|
int n_decode = 0;
|
||||||
|
|
||||||
|
bool next_token_uses_guide_token = true;
|
||||||
|
|
||||||
while (n_decode <= n_predict) {
|
while (n_decode <= n_predict) {
|
||||||
// prepare the next batch
|
// prepare the next batch
|
||||||
common_batch_clear(batch);
|
common_batch_clear(batch);
|
||||||
|
@ -728,7 +761,17 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const llama_token new_token_id = common_sampler_sample(smpl[i], ctx_ttc, i_batch[i]);
|
llama_token new_token_id = common_sampler_sample(smpl[i], ctx_ttc, i_batch[i]);
|
||||||
|
|
||||||
|
//guide tokens help prevent hallucinations by forcing the TTS to use the correct word
|
||||||
|
if (!guide_tokens.empty() && next_token_uses_guide_token && !llama_vocab_is_control(vocab, new_token_id) && !llama_vocab_is_eog(vocab, new_token_id)) {
|
||||||
|
llama_token guide_token = guide_tokens[0];
|
||||||
|
guide_tokens.erase(guide_tokens.begin());
|
||||||
|
new_token_id = guide_token; //ensure correct word fragment is used
|
||||||
|
}
|
||||||
|
|
||||||
|
//this is the token id that always precedes a new word
|
||||||
|
next_token_uses_guide_token = (new_token_id == 198);
|
||||||
|
|
||||||
common_sampler_accept(smpl[i], new_token_id, true);
|
common_sampler_accept(smpl[i], new_token_id, true);
|
||||||
|
|
||||||
|
|
|
@ -333,8 +333,12 @@ struct ggml_backend_sycl_context {
|
||||||
// pool
|
// pool
|
||||||
std::unique_ptr<ggml_sycl_pool> pools[GGML_SYCL_MAX_DEVICES];
|
std::unique_ptr<ggml_sycl_pool> pools[GGML_SYCL_MAX_DEVICES];
|
||||||
|
|
||||||
|
std::unique_ptr<ggml_sycl_pool> host_pools[GGML_SYCL_MAX_DEVICES];
|
||||||
|
|
||||||
static std::unique_ptr<ggml_sycl_pool> new_pool_for_device(queue_ptr qptr, int device);
|
static std::unique_ptr<ggml_sycl_pool> new_pool_for_device(queue_ptr qptr, int device);
|
||||||
|
|
||||||
|
static std::unique_ptr<ggml_sycl_pool> new_pool_for_host(queue_ptr qptr, int device);
|
||||||
|
|
||||||
ggml_sycl_pool & pool(int device) {
|
ggml_sycl_pool & pool(int device) {
|
||||||
if (pools[device] == nullptr) {
|
if (pools[device] == nullptr) {
|
||||||
pools[device] = new_pool_for_device(stream(device,0), device);
|
pools[device] = new_pool_for_device(stream(device,0), device);
|
||||||
|
@ -345,6 +349,15 @@ struct ggml_backend_sycl_context {
|
||||||
ggml_sycl_pool & pool() {
|
ggml_sycl_pool & pool() {
|
||||||
return pool(device);
|
return pool(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ggml_sycl_pool & host_pool(int device) {
|
||||||
|
if (host_pools[device] == nullptr) {
|
||||||
|
host_pools[device] = new_pool_for_host(stream(device, 0), device);
|
||||||
|
}
|
||||||
|
return *host_pools[device];
|
||||||
|
}
|
||||||
|
|
||||||
|
ggml_sycl_pool & host_pool() { return host_pool(device); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// common device functions
|
// common device functions
|
||||||
|
|
|
@ -82,6 +82,14 @@ inline std::string get_device_backend_and_type(const sycl::device &device) {
|
||||||
return device_type.str();
|
return device_type.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Ts> struct matrix_info_t {
|
||||||
|
oneapi::mkl::transpose transpose_info[2];
|
||||||
|
Ts value_info[2];
|
||||||
|
std::int64_t size_info[3];
|
||||||
|
std::int64_t ld_info[3];
|
||||||
|
std::int64_t groupsize_info;
|
||||||
|
};
|
||||||
|
|
||||||
namespace dpct
|
namespace dpct
|
||||||
{
|
{
|
||||||
typedef sycl::queue *queue_ptr;
|
typedef sycl::queue *queue_ptr;
|
||||||
|
@ -1727,26 +1735,13 @@ namespace dpct
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Ta, class Tb, class Tc, class Ts>
|
template <class Ta, class Tb, class Tc, class Ts>
|
||||||
inline void gemm_batch_impl(sycl::queue &q, oneapi::mkl::transpose a_trans,
|
inline void gemm_batch_impl(sycl::queue & q, oneapi::mkl::transpose a_trans, oneapi::mkl::transpose b_trans,
|
||||||
oneapi::mkl::transpose b_trans, int m, int n, int k,
|
int m, int n, int k, const void * alpha, const void ** a, int lda, const void ** b,
|
||||||
const void *alpha, const void **a, int lda,
|
int ldb, const void * beta, void ** c, int ldc, int batch_size,
|
||||||
const void **b, int ldb, const void *beta, void **c,
|
matrix_info_t<float> * matrix_info) {
|
||||||
int ldc, int batch_size)
|
|
||||||
{
|
|
||||||
struct matrix_info_t
|
|
||||||
{
|
|
||||||
oneapi::mkl::transpose transpose_info[2];
|
|
||||||
Ts value_info[2];
|
|
||||||
std::int64_t size_info[3];
|
|
||||||
std::int64_t ld_info[3];
|
|
||||||
std::int64_t groupsize_info;
|
|
||||||
};
|
|
||||||
|
|
||||||
Ts alpha_value = dpct::get_value(reinterpret_cast<const Ts *>(alpha), q);
|
Ts alpha_value = dpct::get_value(reinterpret_cast<const Ts *>(alpha), q);
|
||||||
Ts beta_value = dpct::get_value(reinterpret_cast<const Ts *>(beta), q);
|
Ts beta_value = dpct::get_value(reinterpret_cast<const Ts *>(beta), q);
|
||||||
|
|
||||||
matrix_info_t *matrix_info =
|
|
||||||
(matrix_info_t *)std::malloc(sizeof(matrix_info_t));
|
|
||||||
matrix_info->transpose_info[0] = a_trans;
|
matrix_info->transpose_info[0] = a_trans;
|
||||||
matrix_info->transpose_info[1] = b_trans;
|
matrix_info->transpose_info[1] = b_trans;
|
||||||
matrix_info->value_info[0] = alpha_value;
|
matrix_info->value_info[0] = alpha_value;
|
||||||
|
@ -1763,23 +1758,18 @@ namespace dpct
|
||||||
sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
|
sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
|
||||||
oneapi::mkl::backend_selector<oneapi::mkl::backend::cublas>{ q }, matrix_info->transpose_info,
|
oneapi::mkl::backend_selector<oneapi::mkl::backend::cublas>{ q }, matrix_info->transpose_info,
|
||||||
matrix_info->transpose_info + 1, matrix_info->size_info, matrix_info->size_info + 1,
|
matrix_info->transpose_info + 1, matrix_info->size_info, matrix_info->size_info + 1,
|
||||||
matrix_info->size_info + 2, matrix_info->value_info, reinterpret_cast<const Ta **>(a),
|
matrix_info->size_info + 2, reinterpret_cast<Ts *>(matrix_info->value_info),
|
||||||
matrix_info->ld_info, reinterpret_cast<const Tb **>(b), matrix_info->ld_info + 1,
|
reinterpret_cast<const Ta **>(a), matrix_info->ld_info, reinterpret_cast<const Tb **>(b),
|
||||||
matrix_info->value_info + 1, reinterpret_cast<Tc **>(c), matrix_info->ld_info + 2, 1,
|
matrix_info->ld_info + 1, reinterpret_cast<Ts *>(matrix_info->value_info + 1),
|
||||||
&(matrix_info->groupsize_info));
|
reinterpret_cast<Tc **>(c), matrix_info->ld_info + 2, 1, &(matrix_info->groupsize_info));
|
||||||
#else
|
#else
|
||||||
sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
|
sycl::event e = oneapi::mkl::blas::column_major::gemm_batch(
|
||||||
q, matrix_info->transpose_info, matrix_info->transpose_info + 1, matrix_info->size_info,
|
q, matrix_info->transpose_info, matrix_info->transpose_info + 1, matrix_info->size_info,
|
||||||
matrix_info->size_info + 1, matrix_info->size_info + 2, matrix_info->value_info,
|
matrix_info->size_info + 1, matrix_info->size_info + 2, reinterpret_cast<Ts *>(matrix_info->value_info),
|
||||||
reinterpret_cast<const Ta **>(a), matrix_info->ld_info, reinterpret_cast<const Tb **>(b),
|
reinterpret_cast<const Ta **>(a), matrix_info->ld_info, reinterpret_cast<const Tb **>(b),
|
||||||
matrix_info->ld_info + 1, matrix_info->value_info + 1, reinterpret_cast<Tc **>(c),
|
matrix_info->ld_info + 1, reinterpret_cast<Ts *>(matrix_info->value_info + 1),
|
||||||
matrix_info->ld_info + 2, 1, &(matrix_info->groupsize_info));
|
reinterpret_cast<Tc **>(c), matrix_info->ld_info + 2, 1, &(matrix_info->groupsize_info));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
q.submit([&](sycl::handler &cgh)
|
|
||||||
{
|
|
||||||
cgh.depends_on(e);
|
|
||||||
cgh.host_task([=] { std::free(matrix_info); }); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Ta, class Tb, class Tc, class Ts>
|
template <class Ta, class Tb, class Tc, class Ts>
|
||||||
|
@ -2422,25 +2412,11 @@ namespace dpct
|
||||||
/// \param [in] ldc Leading dimension of C.
|
/// \param [in] ldc Leading dimension of C.
|
||||||
/// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
|
/// \param [in] batch_size Specifies the number of matrix multiply operations to perform.
|
||||||
/// \param [in] scaling_type Data type of the scaling factors.
|
/// \param [in] scaling_type Data type of the scaling factors.
|
||||||
inline void gemm_batch(sycl::queue &q, oneapi::mkl::transpose a_trans,
|
inline void gemm_batch(sycl::queue & q, oneapi::mkl::transpose a_trans, oneapi::mkl::transpose b_trans, int m,
|
||||||
oneapi::mkl::transpose b_trans, int m, int n, int k,
|
int n, int k, const void * alpha, const void * a[], library_data_t a_type, int lda,
|
||||||
const void *alpha, const void *a[],
|
const void * b[], library_data_t b_type, int ldb, const void * beta, void * c[],
|
||||||
library_data_t a_type, int lda, const void *b[],
|
library_data_t c_type, int ldc, int batch_size, library_data_t scaling_type,
|
||||||
library_data_t b_type, int ldb, const void *beta,
|
matrix_info_t<float> * matrix_info) {
|
||||||
void *c[], library_data_t c_type, int ldc,
|
|
||||||
int batch_size, library_data_t scaling_type)
|
|
||||||
{
|
|
||||||
if (scaling_type == library_data_t::real_float &&
|
|
||||||
c_type == library_data_t::complex_float)
|
|
||||||
{
|
|
||||||
scaling_type = library_data_t::complex_float;
|
|
||||||
}
|
|
||||||
else if (scaling_type == library_data_t::real_double &&
|
|
||||||
c_type == library_data_t::complex_double)
|
|
||||||
{
|
|
||||||
scaling_type = library_data_t::complex_double;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint64_t key =
|
std::uint64_t key =
|
||||||
detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
|
detail::get_type_combination_id(a_type, b_type, c_type, scaling_type);
|
||||||
switch (key)
|
switch (key)
|
||||||
|
@ -2449,48 +2425,24 @@ namespace dpct
|
||||||
library_data_t::real_float, library_data_t::real_float,
|
library_data_t::real_float, library_data_t::real_float,
|
||||||
library_data_t::real_float, library_data_t::real_float):
|
library_data_t::real_float, library_data_t::real_float):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<float, float, float, float>(
|
detail::gemm_batch_impl<float, float, float, float>(q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb,
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
beta, c, ldc, batch_size, matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
library_data_t::real_double, library_data_t::real_double,
|
library_data_t::real_double, library_data_t::real_double,
|
||||||
library_data_t::real_double, library_data_t::real_double):
|
library_data_t::real_double, library_data_t::real_double):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<double, double, double, double>(
|
detail::gemm_batch_impl<double, double, double, double>(q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb,
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
beta, c, ldc, batch_size, matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case detail::get_type_combination_id(
|
|
||||||
library_data_t::complex_float, library_data_t::complex_float,
|
|
||||||
library_data_t::complex_float, library_data_t::complex_float):
|
|
||||||
{
|
|
||||||
detail::gemm_batch_impl<std::complex<float>, std::complex<float>,
|
|
||||||
std::complex<float>, std::complex<float>>(
|
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
|
||||||
batch_size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case detail::get_type_combination_id(
|
|
||||||
library_data_t::complex_double, library_data_t::complex_double,
|
|
||||||
library_data_t::complex_double, library_data_t::complex_double):
|
|
||||||
{
|
|
||||||
detail::gemm_batch_impl<std::complex<double>, std::complex<double>,
|
|
||||||
std::complex<double>, std::complex<double>>(
|
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
library_data_t::real_half, library_data_t::real_half,
|
library_data_t::real_half, library_data_t::real_half,
|
||||||
library_data_t::real_half, library_data_t::real_half):
|
library_data_t::real_half, library_data_t::real_half):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<sycl::half, sycl::half, sycl::half,
|
detail::gemm_batch_impl<sycl::half, sycl::half, sycl::half, sycl::half>(
|
||||||
sycl::half>(q, a_trans, b_trans, m, n, k, alpha,
|
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, batch_size, matrix_info);
|
||||||
a, lda, b, ldb, beta, c, ldc,
|
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef __INTEL_MKL__
|
#ifdef __INTEL_MKL__
|
||||||
|
@ -2498,19 +2450,16 @@ namespace dpct
|
||||||
library_data_t::real_bfloat16, library_data_t::real_bfloat16,
|
library_data_t::real_bfloat16, library_data_t::real_bfloat16,
|
||||||
library_data_t::real_bfloat16, library_data_t::real_float):
|
library_data_t::real_bfloat16, library_data_t::real_float):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<oneapi::mkl::bfloat16, oneapi::mkl::bfloat16,
|
detail::gemm_batch_impl<oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, float>(
|
||||||
oneapi::mkl::bfloat16, float>(
|
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, batch_size, matrix_info);
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
library_data_t::real_bfloat16, library_data_t::real_bfloat16,
|
library_data_t::real_bfloat16, library_data_t::real_bfloat16,
|
||||||
library_data_t::real_float, library_data_t::real_float):
|
library_data_t::real_float, library_data_t::real_float):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, float,
|
detail::gemm_batch_impl<oneapi::mkl::bfloat16, oneapi::mkl::bfloat16, float, float>(
|
||||||
float>(q, a_trans, b_trans, m, n, k, alpha, a, lda,
|
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, batch_size, matrix_info);
|
||||||
b, ldb, beta, c, ldc, batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2522,10 +2471,9 @@ namespace dpct
|
||||||
dpct::get_value(reinterpret_cast<const std::int32_t *>(alpha), q);
|
dpct::get_value(reinterpret_cast<const std::int32_t *>(alpha), q);
|
||||||
float beta_float =
|
float beta_float =
|
||||||
dpct::get_value(reinterpret_cast<const std::int32_t *>(beta), q);
|
dpct::get_value(reinterpret_cast<const std::int32_t *>(beta), q);
|
||||||
detail::gemm_batch_impl<std::int8_t, std::int8_t, std::int32_t,
|
detail::gemm_batch_impl<std::int8_t, std::int8_t, std::int32_t, float>(
|
||||||
float>(q, a_trans, b_trans, m, n, k, &alpha_float,
|
q, a_trans, b_trans, m, n, k, &alpha_float, a, lda, b, ldb, &beta_float, c, ldc, batch_size,
|
||||||
a, lda, b, ldb, &beta_float, c, ldc,
|
matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
|
@ -2533,8 +2481,7 @@ namespace dpct
|
||||||
library_data_t::real_float, library_data_t::real_float):
|
library_data_t::real_float, library_data_t::real_float):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<std::int8_t, std::int8_t, float, float>(
|
detail::gemm_batch_impl<std::int8_t, std::int8_t, float, float>(
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, batch_size, matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
|
@ -2542,8 +2489,7 @@ namespace dpct
|
||||||
library_data_t::real_float, library_data_t::real_float):
|
library_data_t::real_float, library_data_t::real_float):
|
||||||
{
|
{
|
||||||
detail::gemm_batch_impl<sycl::half, sycl::half, float, float>(
|
detail::gemm_batch_impl<sycl::half, sycl::half, float, float>(
|
||||||
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc,
|
q, a_trans, b_trans, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc, batch_size, matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case detail::get_type_combination_id(
|
case detail::get_type_combination_id(
|
||||||
|
@ -2557,8 +2503,7 @@ namespace dpct
|
||||||
sycl::half alpha_half(alpha_value);
|
sycl::half alpha_half(alpha_value);
|
||||||
sycl::half beta_half(beta_value);
|
sycl::half beta_half(beta_value);
|
||||||
detail::gemm_batch_impl<sycl::half, sycl::half, sycl::half, sycl::half>(
|
detail::gemm_batch_impl<sycl::half, sycl::half, sycl::half, sycl::half>(
|
||||||
q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, b, ldb, &beta_half, c, ldc,
|
q, a_trans, b_trans, m, n, k, &alpha_half, a, lda, b, ldb, &beta_half, c, ldc, batch_size, matrix_info);
|
||||||
batch_size);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1173,6 +1173,85 @@ struct ggml_sycl_pool_leg : public ggml_sycl_pool {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ggml_sycl_pool_host : public ggml_sycl_pool {
|
||||||
|
queue_ptr qptr;
|
||||||
|
int device;
|
||||||
|
|
||||||
|
inline static int counter{ 0 };
|
||||||
|
|
||||||
|
struct ggml_sycl_buffer {
|
||||||
|
void * ptr = nullptr;
|
||||||
|
size_t size = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set arbitrarly to 64
|
||||||
|
static constexpr int MAX_POOL_SIZE{ 64 };
|
||||||
|
std::vector<ggml_sycl_buffer> buffer_pool = std::vector<ggml_sycl_buffer>(MAX_POOL_SIZE);
|
||||||
|
size_t pool_size = 0;
|
||||||
|
|
||||||
|
explicit ggml_sycl_pool_host(queue_ptr qptr_, int device_) : qptr(qptr_), device(device_) {}
|
||||||
|
|
||||||
|
~ggml_sycl_pool_host() {
|
||||||
|
for (int i = 0; i < MAX_POOL_SIZE; ++i) {
|
||||||
|
ggml_sycl_buffer & b = buffer_pool[i];
|
||||||
|
if (b.ptr != nullptr) {
|
||||||
|
SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(b.ptr, *qptr)));
|
||||||
|
b.ptr = nullptr;
|
||||||
|
pool_size -= b.size;
|
||||||
|
b.size = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * alloc(size_t size, size_t * actual_size) override {
|
||||||
|
if (counter == MAX_POOL_SIZE) {
|
||||||
|
ggml_sycl_buffer b = buffer_pool[0];
|
||||||
|
void * ptr = b.ptr;
|
||||||
|
*actual_size = b.size;
|
||||||
|
counter = 1;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
ggml_sycl_buffer & b = buffer_pool[counter];
|
||||||
|
|
||||||
|
if (b.ptr == nullptr) {
|
||||||
|
void * ptr;
|
||||||
|
|
||||||
|
SYCL_CHECK(CHECK_TRY_ERROR(ptr = (void *) sycl::malloc_host(size, *qptr)));
|
||||||
|
if (!ptr) {
|
||||||
|
GGML_LOG_ERROR("%s: can't allocate %lu Bytes of memory on host\n", __func__, size);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
pool_size += size;
|
||||||
|
*actual_size = size;
|
||||||
|
counter = counter + 1;
|
||||||
|
return ptr;
|
||||||
|
} else {
|
||||||
|
++counter;
|
||||||
|
b.size = size;
|
||||||
|
return b.ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free(void * ptr, size_t size) override {
|
||||||
|
// if the pool is not completed add the pointer to it in place of the first nullptr found.
|
||||||
|
// Otherwise do nothing, pointers will be freed once the pool is deallocated.
|
||||||
|
for (int i = 0; i < MAX_POOL_SIZE; ++i) {
|
||||||
|
ggml_sycl_buffer & b = buffer_pool[i];
|
||||||
|
if (b.ptr == nullptr) {
|
||||||
|
b.ptr = ptr;
|
||||||
|
b.size = size;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<ggml_sycl_pool> ggml_backend_sycl_context::new_pool_for_host(queue_ptr qptr, int device) {
|
||||||
|
// return pool for the host to speed up memory management
|
||||||
|
return std::unique_ptr<ggml_sycl_pool>(new ggml_sycl_pool_host(qptr, device));
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<ggml_sycl_pool> ggml_backend_sycl_context::new_pool_for_device(queue_ptr qptr, int device) {
|
std::unique_ptr<ggml_sycl_pool> ggml_backend_sycl_context::new_pool_for_device(queue_ptr qptr, int device) {
|
||||||
// TBD: NO VMM support
|
// TBD: NO VMM support
|
||||||
// if (ggml_sycl_info().devices[device].vmm) {
|
// if (ggml_sycl_info().devices[device].vmm) {
|
||||||
|
@ -3363,6 +3442,7 @@ static void ggml_sycl_mul_mat_batched_sycl(ggml_backend_sycl_context & ctx,
|
||||||
|
|
||||||
ggml_sycl_pool_alloc<const void *> ptrs_src(ctx.pool(), 2*ne23);
|
ggml_sycl_pool_alloc<const void *> ptrs_src(ctx.pool(), 2*ne23);
|
||||||
ggml_sycl_pool_alloc< void *> ptrs_dst(ctx.pool(), 1*ne23);
|
ggml_sycl_pool_alloc< void *> ptrs_dst(ctx.pool(), 1*ne23);
|
||||||
|
ggml_sycl_pool_alloc<matrix_info_t<float>> matrix_info(ctx.host_pool(), 1);
|
||||||
|
|
||||||
sycl::range<3> block_dims(1, ne12, ne13);
|
sycl::range<3> block_dims(1, ne12, ne13);
|
||||||
/*
|
/*
|
||||||
|
@ -3391,14 +3471,10 @@ static void ggml_sycl_mul_mat_batched_sycl(ggml_backend_sycl_context & ctx,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
SYCL_CHECK(CHECK_TRY_ERROR(dpct::gemm_batch(
|
SYCL_CHECK(CHECK_TRY_ERROR(dpct::gemm_batch(
|
||||||
*main_stream, oneapi::mkl::transpose::trans,
|
*main_stream, oneapi::mkl::transpose::trans, oneapi::mkl::transpose::nontrans, ne01, ne11, ne10, alpha,
|
||||||
oneapi::mkl::transpose::nontrans, ne01, ne11, ne10, alpha,
|
(const void **) (ptrs_src.get() + 0 * ne23), dpct::library_data_t::real_half, nb01 / nb00,
|
||||||
(const void **)(ptrs_src.get() + 0 * ne23),
|
(const void **) (ptrs_src.get() + 1 * ne23), dpct::library_data_t::real_half, nb11 / nb10, beta,
|
||||||
dpct::library_data_t::real_half, nb01 / nb00,
|
(void **) (ptrs_dst.get() + 0 * ne23), cu_data_type, ne01, ne23, cu_compute_type, matrix_info.get())));
|
||||||
(const void **)(ptrs_src.get() + 1 * ne23),
|
|
||||||
dpct::library_data_t::real_half, nb11 / nb10, beta,
|
|
||||||
(void **)(ptrs_dst.get() + 0 * ne23), cu_data_type, ne01, ne23,
|
|
||||||
cu_compute_type)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (sycl::exception const &exc) {
|
catch (sycl::exception const &exc) {
|
||||||
|
|
|
@ -29,8 +29,6 @@
|
||||||
|
|
||||||
#include "ggml-vulkan-shaders.hpp"
|
#include "ggml-vulkan-shaders.hpp"
|
||||||
|
|
||||||
#define VK_API_VERSION VK_API_VERSION_1_2
|
|
||||||
|
|
||||||
#define CEIL_DIV(M, N) (((M) + (N)-1) / (N))
|
#define CEIL_DIV(M, N) (((M) + (N)-1) / (N))
|
||||||
|
|
||||||
#define VK_VENDOR_ID_AMD 0x1002
|
#define VK_VENDOR_ID_AMD 0x1002
|
||||||
|
@ -386,10 +384,13 @@ struct vk_flash_attn_push_constants {
|
||||||
uint32_t nev3;
|
uint32_t nev3;
|
||||||
uint32_t nem1;
|
uint32_t nem1;
|
||||||
|
|
||||||
|
uint32_t nb01;
|
||||||
uint32_t nb02;
|
uint32_t nb02;
|
||||||
uint32_t nb03;
|
uint32_t nb03;
|
||||||
|
uint32_t nb11;
|
||||||
uint32_t nb12;
|
uint32_t nb12;
|
||||||
uint32_t nb13;
|
uint32_t nb13;
|
||||||
|
uint32_t nb21;
|
||||||
uint32_t nb22;
|
uint32_t nb22;
|
||||||
uint32_t nb23;
|
uint32_t nb23;
|
||||||
uint32_t nb31;
|
uint32_t nb31;
|
||||||
|
@ -1611,11 +1612,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
|
||||||
CREATE_MM(PIPELINE_NAME . f16acc, NAMELC, _f16acc, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT) \
|
CREATE_MM(PIPELINE_NAME . f16acc, NAMELC, _f16acc, WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT) \
|
||||||
CREATE_MM(PIPELINE_NAME . f32acc, NAMELC, , WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT) \
|
CREATE_MM(PIPELINE_NAME . f32acc, NAMELC, , WG_DENOMS, WARPTILE, PUSHCONST, PARAMCOUNT) \
|
||||||
|
|
||||||
CREATE_MM(pipeline_matmul_f32, matmul_f32_f32, , wg_denoms, warptile, vk_mat_mat_push_constants, 3)
|
|
||||||
CREATE_MM(pipeline_matmul_f32_f16, matmul_f32_f16, , wg_denoms, warptile, vk_mat_mat_push_constants, 3)
|
|
||||||
|
|
||||||
CREATE_MM2(pipeline_matmul_f16, matmul_f16, wg_denoms, warptile, vk_mat_mat_push_constants, 3)
|
CREATE_MM2(pipeline_matmul_f16, matmul_f16, wg_denoms, warptile, vk_mat_mat_push_constants, 3)
|
||||||
CREATE_MM2(pipeline_matmul_f16_f32, matmul_f16_f32, wg_denoms, warptile, vk_mat_mat_push_constants, 3)
|
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q4_0].f16acc, matmul_q4_0_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q4_0].f16acc, matmul_q4_0_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q4_1].f16acc, matmul_q4_1_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q4_1].f16acc, matmul_q4_1_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q5_0].f16acc, matmul_q5_0_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q5_0].f16acc, matmul_q5_0_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
||||||
|
@ -1628,21 +1625,18 @@ static void ggml_vk_load_shaders(vk_device& device) {
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q6_K].f16acc, matmul_q6_k_f16, _f16acc, mmq_wg_denoms_k, warptile_mmq_k, vk_mat_mat_push_constants, 3)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_Q6_K].f16acc, matmul_q6_k_f16, _f16acc, mmq_wg_denoms_k, warptile_mmq_k, vk_mat_mat_push_constants, 3)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_IQ4_NL].f16acc, matmul_iq4_nl_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_IQ4_NL].f16acc, matmul_iq4_nl_f16, _f16acc, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
||||||
|
|
||||||
CREATE_MM(pipeline_matmul_id_f32, matmul_id_f32_f32, , wg_denoms, warptile, vk_mat_mat_id_push_constants, 4)
|
|
||||||
CREATE_MM2(pipeline_matmul_id_f16, matmul_id_f16, wg_denoms, warptile, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM2(pipeline_matmul_id_f16, matmul_id_f16, wg_denoms, warptile, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM2(pipeline_matmul_id_f16_f32, matmul_id_f16_f32, wg_denoms, warptile, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_0].f16acc, matmul_id_q4_0_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_1].f16acc, matmul_id_q4_1_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_0].f16acc, matmul_id_q4_0_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_0].f16acc, matmul_id_q5_0_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_1].f16acc, matmul_id_q4_1_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_1].f16acc, matmul_id_q5_1_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_0].f16acc, matmul_id_q5_0_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q8_0].f16acc, matmul_id_q8_0_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_1].f16acc, matmul_id_q5_1_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q2_K].f16acc, matmul_id_q2_k_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q8_0].f16acc, matmul_id_q8_0_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q3_K].f16acc, matmul_id_q3_k_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q2_K].f16acc, matmul_id_q2_k_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_K].f16acc, matmul_id_q4_k_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q3_K].f16acc, matmul_id_q3_k_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_K].f16acc, matmul_id_q5_k_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q4_K].f16acc, matmul_id_q4_k_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q6_K].f16acc, matmul_id_q6_k_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q5_K].f16acc, matmul_id_q5_k_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL].f16acc, matmul_id_iq4_nl_f16, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_Q6_K].f16acc, matmul_id_q6_k_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
|
||||||
CREATE_MM(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL].f16acc, matmul_id_iq4_nl_f32, , mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 4)
|
|
||||||
#undef CREATE_MM
|
#undef CREATE_MM
|
||||||
#undef CREATE_MM2
|
#undef CREATE_MM2
|
||||||
} else
|
} else
|
||||||
|
@ -2284,6 +2278,14 @@ static vk_device ggml_vk_get_device(size_t idx) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
VkPhysicalDeviceMaintenance4Features maint4_features {};
|
||||||
|
maint4_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_4_FEATURES;
|
||||||
|
if (maintenance4_support) {
|
||||||
|
last_struct->pNext = (VkBaseOutStructure *)&maint4_features;
|
||||||
|
last_struct = (VkBaseOutStructure *)&maint4_features;
|
||||||
|
device_extensions.push_back("VK_KHR_maintenance4");
|
||||||
|
}
|
||||||
|
|
||||||
vkGetPhysicalDeviceFeatures2(device->physical_device, &device_features2);
|
vkGetPhysicalDeviceFeatures2(device->physical_device, &device_features2);
|
||||||
|
|
||||||
device->fp16 = device->fp16 && vk12_features.shaderFloat16;
|
device->fp16 = device->fp16 && vk12_features.shaderFloat16;
|
||||||
|
@ -2659,7 +2661,14 @@ void ggml_vk_instance_init() {
|
||||||
|
|
||||||
vk_instance_initialized = true;
|
vk_instance_initialized = true;
|
||||||
|
|
||||||
vk::ApplicationInfo app_info{ "ggml-vulkan", 1, nullptr, 0, VK_API_VERSION };
|
uint32_t api_version = vk::enumerateInstanceVersion();
|
||||||
|
|
||||||
|
if (api_version < VK_API_VERSION_1_2) {
|
||||||
|
std::cerr << "ggml_vulkan: Error: Vulkan 1.2 required." << std::endl;
|
||||||
|
GGML_ABORT("fatal error");
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::ApplicationInfo app_info{ "ggml-vulkan", 1, nullptr, 0, api_version };
|
||||||
|
|
||||||
const std::vector<vk::ExtensionProperties> instance_extensions = vk::enumerateInstanceExtensionProperties();
|
const std::vector<vk::ExtensionProperties> instance_extensions = vk::enumerateInstanceExtensionProperties();
|
||||||
const bool validation_ext = ggml_vk_instance_validation_ext_available(instance_extensions);
|
const bool validation_ext = ggml_vk_instance_validation_ext_available(instance_extensions);
|
||||||
|
@ -2969,7 +2978,7 @@ static vk_matmul_pipeline ggml_vk_get_mul_mat_mat_id_pipeline(ggml_backend_vk_co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GGML_ASSERT(src1_type == GGML_TYPE_F32);
|
GGML_ASSERT(src1_type == GGML_TYPE_F32 || (ctx->device->coopmat2 && src1_type == GGML_TYPE_F16));
|
||||||
|
|
||||||
switch (src0_type) {
|
switch (src0_type) {
|
||||||
case GGML_TYPE_Q4_0:
|
case GGML_TYPE_Q4_0:
|
||||||
|
@ -3809,8 +3818,9 @@ static void ggml_vk_mul_mat_q_f16(ggml_backend_vk_context * ctx, vk_context& sub
|
||||||
src1_uma = d_Qy != nullptr;
|
src1_uma = d_Qy != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool x_non_contig = !ggml_vk_dim01_contiguous(src0);
|
// Reformat and convert to fp16 if non-contiguous, or for coopmat2 for better perf
|
||||||
// Reformat and convert to fp16 if src1 is non-contiguous, or for coopmat2 for better perf
|
const bool x_non_contig = (ctx->device->coopmat2 && src0->type == GGML_TYPE_F32) ||
|
||||||
|
!ggml_vk_dim01_contiguous(src0);
|
||||||
const bool y_non_contig = (ctx->device->coopmat2 && src1->type == GGML_TYPE_F32) ||
|
const bool y_non_contig = (ctx->device->coopmat2 && src1->type == GGML_TYPE_F32) ||
|
||||||
!ggml_vk_dim01_contiguous(src1);
|
!ggml_vk_dim01_contiguous(src1);
|
||||||
|
|
||||||
|
@ -4390,8 +4400,11 @@ static void ggml_vk_mul_mat_id_q_f16(ggml_backend_vk_context * ctx, vk_context&
|
||||||
ids_uma = d_ids != nullptr;
|
ids_uma = d_ids != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool x_non_contig = !ggml_vk_dim01_contiguous(src0);
|
// Reformat and convert to fp16 if non-contiguous, or for coopmat2 for better perf
|
||||||
const bool y_non_contig = !ggml_vk_dim01_contiguous(src1);
|
const bool x_non_contig = (ctx->device->coopmat2 && src0->type == GGML_TYPE_F32) ||
|
||||||
|
!ggml_vk_dim01_contiguous(src0);
|
||||||
|
const bool y_non_contig = (ctx->device->coopmat2 && src1->type == GGML_TYPE_F32) ||
|
||||||
|
!ggml_vk_dim01_contiguous(src1);
|
||||||
|
|
||||||
const bool y_f32_kernel = src1->type == GGML_TYPE_F32 && !y_non_contig;
|
const bool y_f32_kernel = src1->type == GGML_TYPE_F32 && !y_non_contig;
|
||||||
|
|
||||||
|
@ -4401,7 +4414,8 @@ static void ggml_vk_mul_mat_id_q_f16(ggml_backend_vk_context * ctx, vk_context&
|
||||||
const bool qy_needs_dequant = (src1->type != GGML_TYPE_F16 && !y_f32_kernel) || y_non_contig;
|
const bool qy_needs_dequant = (src1->type != GGML_TYPE_F16 && !y_f32_kernel) || y_non_contig;
|
||||||
|
|
||||||
if (qx_needs_dequant) {
|
if (qx_needs_dequant) {
|
||||||
GGML_ABORT("fatal error");
|
// Fall back to dequant + f16 mulmat
|
||||||
|
mmp = ggml_vk_get_mul_mat_mat_id_pipeline(ctx, GGML_TYPE_F16, y_f32_kernel ? GGML_TYPE_F32 : GGML_TYPE_F16, (ggml_prec)dst->op_params[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not implemented
|
// Not implemented
|
||||||
|
@ -4809,7 +4823,14 @@ static void ggml_vk_flash_attn(ggml_backend_vk_context * ctx, vk_context& subctx
|
||||||
}
|
}
|
||||||
assert(pipelines);
|
assert(pipelines);
|
||||||
|
|
||||||
bool aligned = (KV % pipelines[1]->align) == 0;
|
const uint32_t q_stride = (uint32_t)(nbq1 / ggml_type_size(q->type));
|
||||||
|
const uint32_t k_stride = (uint32_t)(nbk1 / ggml_type_size(k->type));
|
||||||
|
const uint32_t v_stride = (uint32_t)(nbv1 / ggml_type_size(v->type));
|
||||||
|
|
||||||
|
bool aligned = (KV % pipelines[1]->align) == 0 &&
|
||||||
|
// the "aligned" shader variant will forcibly align strides, for performance
|
||||||
|
(q_stride & 7) == 0 && (k_stride & 7) == 0 && (v_stride & 7) == 0;
|
||||||
|
|
||||||
vk_pipeline pipeline = pipelines[aligned];
|
vk_pipeline pipeline = pipelines[aligned];
|
||||||
assert(pipeline);
|
assert(pipeline);
|
||||||
|
|
||||||
|
@ -4845,15 +4866,15 @@ static void ggml_vk_flash_attn(ggml_backend_vk_context * ctx, vk_context& subctx
|
||||||
|
|
||||||
if (ctx->device->uma) {
|
if (ctx->device->uma) {
|
||||||
ggml_vk_host_get(ctx->device, q->data, d_Q, q_buf_offset);
|
ggml_vk_host_get(ctx->device, q->data, d_Q, q_buf_offset);
|
||||||
ggml_vk_host_get(ctx->device, k->data, d_K, q_buf_offset);
|
ggml_vk_host_get(ctx->device, k->data, d_K, k_buf_offset);
|
||||||
ggml_vk_host_get(ctx->device, v->data, d_V, q_buf_offset);
|
ggml_vk_host_get(ctx->device, v->data, d_V, v_buf_offset);
|
||||||
ggml_vk_host_get(ctx->device, dst->data, d_D, q_buf_offset);
|
ggml_vk_host_get(ctx->device, dst->data, d_D, d_buf_offset);
|
||||||
Q_uma = d_Q != nullptr;
|
Q_uma = d_Q != nullptr;
|
||||||
K_uma = d_K != nullptr;
|
K_uma = d_K != nullptr;
|
||||||
V_uma = d_V != nullptr;
|
V_uma = d_V != nullptr;
|
||||||
D_uma = d_D != nullptr;
|
D_uma = d_D != nullptr;
|
||||||
if (mask) {
|
if (mask) {
|
||||||
ggml_vk_host_get(ctx->device, mask->data, d_M, q_buf_offset);
|
ggml_vk_host_get(ctx->device, mask->data, d_M, m_buf_offset);
|
||||||
M_uma = d_M != nullptr;
|
M_uma = d_M != nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4891,7 +4912,18 @@ static void ggml_vk_flash_attn(ggml_backend_vk_context * ctx, vk_context& subctx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const vk_flash_attn_push_constants pc = { N, KV, (uint32_t)ne1, (uint32_t)ne2, (uint32_t)ne3, (uint32_t)neq2, (uint32_t)neq3, (uint32_t)nek2, (uint32_t)nek3, (uint32_t)nev2, (uint32_t)nev3, nem1, (uint32_t)nbq2, (uint32_t)nbq3, (uint32_t)nbk2, (uint32_t)nbk3, (uint32_t)nbv2, (uint32_t)nbv3, nbm1, scale, max_bias, logit_softcap, mask != nullptr, n_head_log2, m0, m1 };
|
const vk_flash_attn_push_constants pc = { N, KV,
|
||||||
|
(uint32_t)ne1, (uint32_t)ne2, (uint32_t)ne3,
|
||||||
|
(uint32_t)neq2, (uint32_t)neq3,
|
||||||
|
(uint32_t)nek2, (uint32_t)nek3,
|
||||||
|
(uint32_t)nev2, (uint32_t)nev3,
|
||||||
|
nem1,
|
||||||
|
q_stride, (uint32_t)nbq2, (uint32_t)nbq3,
|
||||||
|
k_stride, (uint32_t)nbk2, (uint32_t)nbk3,
|
||||||
|
v_stride, (uint32_t)nbv2, (uint32_t)nbv3,
|
||||||
|
nbm1,
|
||||||
|
scale, max_bias, logit_softcap,
|
||||||
|
mask != nullptr, n_head_log2, m0, m1 };
|
||||||
ggml_vk_dispatch_pipeline(ctx, subctx, pipeline,
|
ggml_vk_dispatch_pipeline(ctx, subctx, pipeline,
|
||||||
{
|
{
|
||||||
vk_subbuffer{d_Q, q_buf_offset, VK_WHOLE_SIZE},
|
vk_subbuffer{d_Q, q_buf_offset, VK_WHOLE_SIZE},
|
||||||
|
@ -8668,6 +8700,7 @@ static void ggml_vk_check_results_1(ggml_tensor * tensor) {
|
||||||
ggml_tensor * src0 = tensor->src[0];
|
ggml_tensor * src0 = tensor->src[0];
|
||||||
ggml_tensor * src1 = tensor->src[1];
|
ggml_tensor * src1 = tensor->src[1];
|
||||||
ggml_tensor * src2 = tensor->src[2];
|
ggml_tensor * src2 = tensor->src[2];
|
||||||
|
ggml_tensor * src3 = tensor->src[3];
|
||||||
|
|
||||||
void * tensor_data = tensor->data;
|
void * tensor_data = tensor->data;
|
||||||
|
|
||||||
|
@ -8730,6 +8763,9 @@ static void ggml_vk_check_results_1(ggml_tensor * tensor) {
|
||||||
if (src2 != nullptr) {
|
if (src2 != nullptr) {
|
||||||
std::cerr << "src2=" << src2 << " src2->name=" << src2->name << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
std::cerr << "src2=" << src2 << " src2->name=" << src2->name << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
||||||
}
|
}
|
||||||
|
if (src3 != nullptr) {
|
||||||
|
std::cerr << "src3=" << src3 << " src3->name=" << src3->name << " op=" << ggml_op_name(src3->op) << " type=" << ggml_type_name(src3->type) << " ne0=" << src3->ne[0] << " nb0=" << src3->nb[0] << " ne1=" << src3->ne[1] << " nb1=" << src3->nb[1] << " ne2=" << src3->ne[2] << " nb2=" << src3->nb[2] << " ne3=" << src3->ne[3] << " nb3=" << src3->nb[3] << " offset=" << src3->view_offs << std::endl;
|
||||||
|
}
|
||||||
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
||||||
std::cerr << std::endl << "Result:" << std::endl;
|
std::cerr << std::endl << "Result:" << std::endl;
|
||||||
ggml_vk_print_tensor_area(tensor, tensor_data, i0, i1, i2, i3);
|
ggml_vk_print_tensor_area(tensor, tensor_data, i0, i1, i2, i3);
|
||||||
|
@ -8774,6 +8810,9 @@ static void ggml_vk_check_results_1(ggml_tensor * tensor) {
|
||||||
if (src2 != nullptr) {
|
if (src2 != nullptr) {
|
||||||
std::cerr << "src2=" << src2 << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
std::cerr << "src2=" << src2 << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
||||||
}
|
}
|
||||||
|
if (src3 != nullptr) {
|
||||||
|
std::cerr << "src3=" << src3 << " op=" << ggml_op_name(src3->op) << " type=" << ggml_type_name(src3->type) << " ne0=" << src3->ne[0] << " nb0=" << src3->nb[0] << " ne1=" << src3->ne[1] << " nb1=" << src3->nb[1] << " ne2=" << src3->ne[2] << " nb2=" << src3->nb[2] << " ne3=" << src3->ne[3] << " nb3=" << src3->nb[3] << " offset=" << src3->view_offs << std::endl;
|
||||||
|
}
|
||||||
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
||||||
std::cerr << std::endl << "Result:" << std::endl;
|
std::cerr << std::endl << "Result:" << std::endl;
|
||||||
ggml_vk_print_tensor_area(tensor, tensor_data, 5, 5, 0, 0);
|
ggml_vk_print_tensor_area(tensor, tensor_data, 5, 5, 0, 0);
|
||||||
|
@ -8796,6 +8835,9 @@ static void ggml_vk_check_results_1(ggml_tensor * tensor) {
|
||||||
if (src2 != nullptr) {
|
if (src2 != nullptr) {
|
||||||
std::cerr << "src2=" << src2 << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
std::cerr << "src2=" << src2 << " op=" << ggml_op_name(src2->op) << " type=" << ggml_type_name(src2->type) << " ne0=" << src2->ne[0] << " nb0=" << src2->nb[0] << " ne1=" << src2->ne[1] << " nb1=" << src2->nb[1] << " ne2=" << src2->ne[2] << " nb2=" << src2->nb[2] << " ne3=" << src2->ne[3] << " nb3=" << src2->nb[3] << " offset=" << src2->view_offs << std::endl;
|
||||||
}
|
}
|
||||||
|
if (src3 != nullptr) {
|
||||||
|
std::cerr << "src3=" << src3 << " op=" << ggml_op_name(src3->op) << " type=" << ggml_type_name(src3->type) << " ne0=" << src3->ne[0] << " nb0=" << src3->nb[0] << " ne1=" << src3->ne[1] << " nb1=" << src3->nb[1] << " ne2=" << src3->ne[2] << " nb2=" << src3->nb[2] << " ne3=" << src3->ne[3] << " nb3=" << src3->nb[3] << " offset=" << src3->view_offs << std::endl;
|
||||||
|
}
|
||||||
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
std::cerr << "First error: result=" << first_error_result << " correct=" << first_error_correct << " i3=" << first_error[3] << " i2=" << first_error[2] << " i1=" << first_error[1] << " i0=" << first_error[0] << std::endl;
|
||||||
std::cerr << std::endl << "Result:" << std::endl;
|
std::cerr << std::endl << "Result:" << std::endl;
|
||||||
ggml_vk_print_tensor_area(tensor, tensor_data, first_error[0], first_error[1], first_error[2], first_error[3]);
|
ggml_vk_print_tensor_area(tensor, tensor_data, first_error[0], first_error[1], first_error[2], first_error[3]);
|
||||||
|
|
|
@ -42,10 +42,13 @@ layout (push_constant) uniform parameter {
|
||||||
uint32_t nev3;
|
uint32_t nev3;
|
||||||
uint32_t nem1;
|
uint32_t nem1;
|
||||||
|
|
||||||
|
uint32_t nb01;
|
||||||
uint32_t nb02;
|
uint32_t nb02;
|
||||||
uint32_t nb03;
|
uint32_t nb03;
|
||||||
|
uint32_t nb11;
|
||||||
uint32_t nb12;
|
uint32_t nb12;
|
||||||
uint32_t nb13;
|
uint32_t nb13;
|
||||||
|
uint32_t nb21;
|
||||||
uint32_t nb22;
|
uint32_t nb22;
|
||||||
uint32_t nb23;
|
uint32_t nb23;
|
||||||
uint32_t nb31;
|
uint32_t nb31;
|
||||||
|
@ -146,7 +149,24 @@ void main() {
|
||||||
tensorLayoutK = setTensorLayoutDimensionNV(tensorLayoutK, KV, D);
|
tensorLayoutK = setTensorLayoutDimensionNV(tensorLayoutK, KV, D);
|
||||||
tensorLayoutV = setTensorLayoutDimensionNV(tensorLayoutV, KV, D);
|
tensorLayoutV = setTensorLayoutDimensionNV(tensorLayoutV, KV, D);
|
||||||
|
|
||||||
coopmat<Q_TYPE, gl_ScopeWorkgroup, Br, D, gl_MatrixUseA> Q;
|
// nb?1 are already divided by the type size and are in units of elements
|
||||||
|
uint32_t q_stride = p.nb01;
|
||||||
|
uint32_t k_stride = p.nb11;
|
||||||
|
uint32_t v_stride = p.nb21;
|
||||||
|
// hint to the compiler that strides are aligned for the aligned variant of the shader
|
||||||
|
if (Clamp != gl_CooperativeMatrixClampModeConstantNV)
|
||||||
|
{
|
||||||
|
q_stride &= ~7;
|
||||||
|
#if !defined(BLOCK_SIZE)
|
||||||
|
k_stride &= ~7;
|
||||||
|
v_stride &= ~7;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
tensorLayoutQ = setTensorLayoutStrideNV(tensorLayoutQ, q_stride, 1);
|
||||||
|
tensorLayoutK = setTensorLayoutStrideNV(tensorLayoutK, k_stride, 1);
|
||||||
|
tensorLayoutV = setTensorLayoutStrideNV(tensorLayoutV, v_stride, 1);
|
||||||
|
|
||||||
|
coopmat<Q_TYPE, gl_ScopeWorkgroup, Br, D, gl_MatrixUseAccumulator> Q;
|
||||||
coopmat<float16_t, gl_ScopeWorkgroup, Br, D, gl_MatrixUseA> Qf16;
|
coopmat<float16_t, gl_ScopeWorkgroup, Br, D, gl_MatrixUseA> Qf16;
|
||||||
|
|
||||||
uint32_t q_offset = iq2*p.nb02+iq3*p.nb03;
|
uint32_t q_offset = iq2*p.nb02+iq3*p.nb03;
|
||||||
|
|
|
@ -57,17 +57,13 @@ layout (binding = 2) writeonly buffer D {D_TYPE data_d[];};
|
||||||
|
|
||||||
#if QUANT_K > 1
|
#if QUANT_K > 1
|
||||||
#define DECODEFUNCA , dequantFuncA
|
#define DECODEFUNCA , dequantFuncA
|
||||||
#define MAT_A_TYPE float16_t
|
|
||||||
|
|
||||||
#include "dequant_funcs_cm2.comp"
|
#include "dequant_funcs_cm2.comp"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define DECODEFUNCA
|
#define DECODEFUNCA
|
||||||
#define MAT_A_TYPE A_TYPE
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAT_B_TYPE B_TYPE
|
|
||||||
|
|
||||||
#ifdef MUL_MAT_ID
|
#ifdef MUL_MAT_ID
|
||||||
layout (binding = 3) readonly buffer IDS {int data_ids[];};
|
layout (binding = 3) readonly buffer IDS {int data_ids[];};
|
||||||
|
|
||||||
|
@ -236,16 +232,13 @@ void main() {
|
||||||
|
|
||||||
for (uint block_k = start_k, i = 0; i < k_iters; block_k += BK, ++i) {
|
for (uint block_k = start_k, i = 0; i < k_iters; block_k += BK, ++i) {
|
||||||
|
|
||||||
coopmat<MAT_A_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a;
|
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a;
|
||||||
coopmat<MAT_B_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b;
|
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b;
|
||||||
|
|
||||||
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutA, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutA, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
||||||
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA>(mat_a);
|
|
||||||
|
|
||||||
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
||||||
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB>(mat_b);
|
|
||||||
|
|
||||||
sum = coopMatMulAdd(mat_a_ft, mat_b_ft, sum);
|
sum = coopMatMulAdd(mat_a, mat_b, sum);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // !defined(MUL_MAT_ID)
|
#endif // !defined(MUL_MAT_ID)
|
||||||
|
@ -261,10 +254,8 @@ void main() {
|
||||||
[[dont_unroll]]
|
[[dont_unroll]]
|
||||||
for (uint block_k = start_k; block_k < end_k; block_k += BK) {
|
for (uint block_k = start_k; block_k < end_k; block_k += BK) {
|
||||||
|
|
||||||
coopmat<MAT_A_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a;
|
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a;
|
||||||
coopmat<MAT_B_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b;
|
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b;
|
||||||
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA> mat_a_ft;
|
|
||||||
coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB> mat_b_ft;
|
|
||||||
|
|
||||||
// Clamping is expensive, so detect different code paths for each combination
|
// Clamping is expensive, so detect different code paths for each combination
|
||||||
// of A and B needing clamping.
|
// of A and B needing clamping.
|
||||||
|
@ -281,16 +272,12 @@ void main() {
|
||||||
#else
|
#else
|
||||||
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, (block_k & ~7), BK), tensorViewTranspose);
|
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, (block_k & ~7), BK), tensorViewTranspose);
|
||||||
#endif
|
#endif
|
||||||
mat_a_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA>(mat_a);
|
sum = coopMatMulAdd(mat_a, mat_b, sum);
|
||||||
mat_b_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB>(mat_b);
|
|
||||||
sum = coopMatMulAdd(mat_a_ft, mat_b_ft, sum);
|
|
||||||
} else if (unclampedA && !unclampedB) {
|
} else if (unclampedA && !unclampedB) {
|
||||||
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutA, ir * BM, BM, (block_k & ~7), BK) DECODEFUNCA);
|
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutA, ir * BM, BM, (block_k & ~7), BK) DECODEFUNCA);
|
||||||
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutBClamp, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutBClamp, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
||||||
|
|
||||||
mat_a_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA>(mat_a);
|
sum = coopMatMulAdd(mat_a, mat_b, sum);
|
||||||
mat_b_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB>(mat_b);
|
|
||||||
sum = coopMatMulAdd(mat_a_ft, mat_b_ft, sum);
|
|
||||||
} else if (!unclampedA && unclampedB) {
|
} else if (!unclampedA && unclampedB) {
|
||||||
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutAClamp, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutAClamp, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
||||||
#ifdef MUL_MAT_ID
|
#ifdef MUL_MAT_ID
|
||||||
|
@ -298,16 +285,12 @@ void main() {
|
||||||
#else
|
#else
|
||||||
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, (block_k & ~7), BK), tensorViewTranspose);
|
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutB, ic * BN, BN, (block_k & ~7), BK), tensorViewTranspose);
|
||||||
#endif
|
#endif
|
||||||
mat_a_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA>(mat_a);
|
sum = coopMatMulAdd(mat_a, mat_b, sum);
|
||||||
mat_b_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB>(mat_b);
|
|
||||||
sum = coopMatMulAdd(mat_a_ft, mat_b_ft, sum);
|
|
||||||
} else if (!unclampedA && !unclampedB) {
|
} else if (!unclampedA && !unclampedB) {
|
||||||
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutAClamp, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
coopMatLoadTensorNV(mat_a, data_a, pos_a, sliceTensorLayoutNV(tensorLayoutAClamp, ir * BM, BM, block_k, BK) DECODEFUNCA);
|
||||||
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutBClamp, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
coopMatLoadTensorNV(mat_b, data_b, pos_b, sliceTensorLayoutNV(tensorLayoutBClamp, ic * BN, BN, block_k, BK), tensorViewTranspose);
|
||||||
|
|
||||||
mat_a_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BM, BK, gl_MatrixUseA>(mat_a);
|
sum = coopMatMulAdd(mat_a, mat_b, sum);
|
||||||
mat_b_ft = coopmat<FLOAT_TYPE, gl_ScopeWorkgroup, BK, BN, gl_MatrixUseB>(mat_b);
|
|
||||||
sum = coopMatMulAdd(mat_a_ft, mat_b_ft, sum);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,8 +316,11 @@ void matmul_shaders(bool fp16, bool matmul_id, bool coopmat, bool coopmat2, bool
|
||||||
// For aligned matmul loads
|
// For aligned matmul loads
|
||||||
std::string load_vec_a = (coopmat2 || tname == "f32" || tname == "f16") ? load_vec : "2";
|
std::string load_vec_a = (coopmat2 || tname == "f32" || tname == "f16") ? load_vec : "2";
|
||||||
|
|
||||||
string_to_spv(shader_name + "_" + tname + "_f32", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a_unaligned}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
// don't generate f32 variants for coopmat2
|
||||||
string_to_spv(shader_name + "_" + tname + "_f32_aligned", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a}, {"LOAD_VEC_B", load_vec}, {"B_TYPE", aligned_b_type_f32}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}, {"ALIGNED", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
if (!coopmat2) {
|
||||||
|
string_to_spv(shader_name + "_" + tname + "_f32", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a_unaligned}, {"B_TYPE", "float"}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
||||||
|
string_to_spv(shader_name + "_" + tname + "_f32_aligned", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a}, {"LOAD_VEC_B", load_vec}, {"B_TYPE", aligned_b_type_f32}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}, {"ALIGNED", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
||||||
|
}
|
||||||
|
|
||||||
if (tname != "f16" && tname != "f32") {
|
if (tname != "f16" && tname != "f32") {
|
||||||
string_to_spv(shader_name + "_" + tname + "_f16", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a_unaligned}, {"B_TYPE", "float16_t"}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
string_to_spv(shader_name + "_" + tname + "_f16", source_name, merge_maps(base_dict, {{data_a_key, "1"}, {"LOAD_VEC_A", load_vec_a_unaligned}, {"B_TYPE", "float16_t"}, {"D_TYPE", "float"}, {"B_IS_FLOAT", "1"}}), fp16, coopmat, coopmat2, f16acc);
|
||||||
|
|
|
@ -648,6 +648,10 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par
|
||||||
|
|
||||||
ok = ok && data != nullptr;
|
ok = ok && data != nullptr;
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ggml_set_name(data, "GGUF tensor data binary blob");
|
||||||
|
}
|
||||||
|
|
||||||
// read the binary blob with the tensor data
|
// read the binary blob with the tensor data
|
||||||
ok = ok && gr.read(data->data, ctx->size);
|
ok = ok && gr.read(data->data, ctx->size);
|
||||||
|
|
||||||
|
|
112
models/ggml-vocab-deepseek-r1-qwen.gguf.inp
Normal file
112
models/ggml-vocab-deepseek-r1-qwen.gguf.inp
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
ied 4 ½ months
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Führer
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello world
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello world
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello World
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello World
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello World!
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello, world!
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello, world!
|
||||||
|
__ggml_vocab_test__
|
||||||
|
this is 🦙.cpp
|
||||||
|
__ggml_vocab_test__
|
||||||
|
w048 7tuijk dsdfhu
|
||||||
|
__ggml_vocab_test__
|
||||||
|
нещо на Български
|
||||||
|
__ggml_vocab_test__
|
||||||
|
កាន់តែពិសេសអាចខលចេញ
|
||||||
|
__ggml_vocab_test__
|
||||||
|
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello
|
||||||
|
Hello
|
||||||
|
__ggml_vocab_test__
|
||||||
|
(
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
=
|
||||||
|
__ggml_vocab_test__
|
||||||
|
' era
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
||||||
|
__ggml_vocab_test__
|
||||||
|
!!!!!!
|
||||||
|
__ggml_vocab_test__
|
||||||
|
3
|
||||||
|
__ggml_vocab_test__
|
||||||
|
33
|
||||||
|
__ggml_vocab_test__
|
||||||
|
333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
3333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
33333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
333333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
3333333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
33333333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
333333333
|
||||||
|
__ggml_vocab_test__
|
||||||
|
Cửa Việt
|
||||||
|
__ggml_vocab_test__
|
||||||
|
discards
|
||||||
|
__ggml_vocab_test__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
||||||
|
__ggml_vocab_test__
|
46
models/ggml-vocab-deepseek-r1-qwen.gguf.out
Normal file
46
models/ggml-vocab-deepseek-r1-qwen.gguf.out
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
1122 220 19 220 26062 3951
|
||||||
|
37 50753 261
|
||||||
|
|
||||||
|
220
|
||||||
|
256
|
||||||
|
262
|
||||||
|
197
|
||||||
|
198
|
||||||
|
271
|
||||||
|
1406
|
||||||
|
1572
|
||||||
|
9707 1879
|
||||||
|
21927 1879
|
||||||
|
9707 4337
|
||||||
|
21927 4337
|
||||||
|
21927 4337 0
|
||||||
|
9707 11 1879 0
|
||||||
|
21927 11 1879 0
|
||||||
|
419 374 11162 99 247 13 10821
|
||||||
|
86 15 19 23 220 22 83 1963 41808 11472 2940 16739
|
||||||
|
78762 14144 1456 13073 63471 33594 3038 133178 79012
|
||||||
|
146394 97529 241 44258 233 146568 44258 224 147603 20879 115 146280 44258 223 146280 147272 97529 227 147805 148301 147270 44258 223 146848
|
||||||
|
145836 320 8252 8 26525 114 378 235 149921 30543 320 35673 99066 97534 8 25521 227 320 3243 42365 429 702 1181 1828 3950 8
|
||||||
|
9707
|
||||||
|
21927
|
||||||
|
220 21927
|
||||||
|
256 21927
|
||||||
|
262 21927
|
||||||
|
262 21927 198 262 21927
|
||||||
|
320
|
||||||
|
198 284
|
||||||
|
6 11385
|
||||||
|
9707 11 379 64848 0 2585 525 498 26525 223 937 104100 18493 22377 99257 16 18 16 19 16 20 16 35727 21216
|
||||||
|
17085 2928
|
||||||
|
18
|
||||||
|
18 18
|
||||||
|
18 18 18
|
||||||
|
18 18 18 18
|
||||||
|
18 18 18 18 18
|
||||||
|
18 18 18 18 18 18
|
||||||
|
18 18 18 18 18 18 18
|
||||||
|
18 18 18 18 18 18 18 18
|
||||||
|
18 18 18 18 18 18 18 18 18
|
||||||
|
34 90063 128324
|
||||||
|
2560 2347
|
||||||
|
198 4710 14731 65497 7847 1572 2303 78672 10947 145836 320 8252 8 26525 114 378 235 149921 30543 320 35673 99066 97534 8 25521 227 11162 99 247 149955 220 18 220 18 18 220 18 18 18 220 18 18 18 18 220 18 18 18 18 18 220 18 18 18 18 18 18 220 18 18 18 18 18 18 18 220 18 18 18 18 18 18 18 18 220 18 13 18 220 18 496 18 220 18 1112 18 220 146394 97529 241 44258 233 146568 44258 224 147603 20879 115 146280 44258 223 146280 147272 97529 227 144534 937 104100 18493 22377 99257 16 18 16 19 16 20 16 35727 21216 55460 53237 18658 14144 1456 13073 63471 33594 3038 133178 79012 3355 4605 4605 13874 13874 73594 3014 3014 28149 17085 2928 26610 7646 358 3003 1012 364 83 813 566 594 1052 11 364 787 498 2704 30 364 44 537 2704 358 3278 1281 432 11 364 35 498 1075 1045 15243 30 1205 6 42612 264 63866 43
|
112
scripts/hf.sh
Executable file
112
scripts/hf.sh
Executable file
|
@ -0,0 +1,112 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Shortcut for downloading HF models
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# ./llama-cli -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)
|
||||||
|
# ./llama-cli -m $(./scripts/hf.sh --url https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/blob/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)
|
||||||
|
# ./llama-cli -m $(./scripts/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf)
|
||||||
|
#
|
||||||
|
|
||||||
|
# all logs go to stderr
|
||||||
|
function log {
|
||||||
|
echo "$@" 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
function usage {
|
||||||
|
log "Usage: $0 [[--url] <url>] [--repo <repo>] [--file <file>] [--outdir <dir> [-h|--help]"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# check for curl or wget
|
||||||
|
function has_cmd {
|
||||||
|
if ! [ -x "$(command -v $1)" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if has_cmd wget; then
|
||||||
|
cmd="wget -q -c -O %s/%s %s"
|
||||||
|
elif has_cmd curl; then
|
||||||
|
cmd="curl -C - -f --output-dir %s -o %s -L %s"
|
||||||
|
else
|
||||||
|
log "[E] curl or wget not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
url=""
|
||||||
|
repo=""
|
||||||
|
file=""
|
||||||
|
outdir="."
|
||||||
|
|
||||||
|
# parse args
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--url)
|
||||||
|
url="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--repo)
|
||||||
|
repo="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--file)
|
||||||
|
file="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--outdir)
|
||||||
|
outdir="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
url="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$repo" ] && [ -n "$file" ]; then
|
||||||
|
url="https://huggingface.co/$repo/resolve/main/$file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$url" ]; then
|
||||||
|
log "[E] missing --url"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check if the URL is a HuggingFace model, and if so, try to download it
|
||||||
|
is_url=false
|
||||||
|
|
||||||
|
if [[ ${#url} -gt 22 ]]; then
|
||||||
|
if [[ ${url:0:22} == "https://huggingface.co" ]]; then
|
||||||
|
is_url=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$is_url" = false ]; then
|
||||||
|
log "[E] invalid URL, must start with https://huggingface.co"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# replace "blob/main" with "resolve/main"
|
||||||
|
url=${url/blob\/main/resolve\/main}
|
||||||
|
|
||||||
|
basename=$(basename $url)
|
||||||
|
|
||||||
|
log "[+] attempting to download $basename"
|
||||||
|
|
||||||
|
if [ -n "$cmd" ]; then
|
||||||
|
cmd=$(printf "$cmd" "$outdir" "$basename" "$url")
|
||||||
|
log "[+] $cmd"
|
||||||
|
if $cmd; then
|
||||||
|
echo $outdir/$basename
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "[-] failed to download"
|
||||||
|
|
||||||
|
exit 1
|
|
@ -152,7 +152,7 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
|
||||||
return LLM_CHAT_TEMPLATE_MINICPM;
|
return LLM_CHAT_TEMPLATE_MINICPM;
|
||||||
} else if (tmpl_contains("'Assistant: ' + message['content'] + eos_token")) {
|
} else if (tmpl_contains("'Assistant: ' + message['content'] + eos_token")) {
|
||||||
return LLM_CHAT_TEMPLATE_DEEPSEEK_2;
|
return LLM_CHAT_TEMPLATE_DEEPSEEK_2;
|
||||||
} else if (tmpl_contains(LU8("'<|Assistant|>' + message['content'] + '<|end▁of▁sentence|>'"))) {
|
} else if (tmpl_contains(LU8("<|Assistant|>")) && tmpl_contains(LU8("<|User|>")) && tmpl_contains(LU8("<|end▁of▁sentence|>"))) {
|
||||||
return LLM_CHAT_TEMPLATE_DEEPSEEK_3;
|
return LLM_CHAT_TEMPLATE_DEEPSEEK_3;
|
||||||
} else if (tmpl_contains("[|system|]") && tmpl_contains("[|assistant|]") && tmpl_contains("[|endofturn|]")) {
|
} else if (tmpl_contains("[|system|]") && tmpl_contains("[|assistant|]") && tmpl_contains("[|endofturn|]")) {
|
||||||
// ref: https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct/discussions/8#66bae61b1893d14ee8ed85bb
|
// ref: https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct/discussions/8#66bae61b1893d14ee8ed85bb
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
#ifdef __has_include
|
#ifdef __has_include
|
||||||
#if __has_include(<unistd.h>)
|
#if __has_include(<unistd.h>)
|
||||||
|
|
|
@ -2203,6 +2203,50 @@ bool llama_model::load_tensors(llama_model_loader & ml) {
|
||||||
layer.rope_short = create_tensor(tn(LLM_TENSOR_ROPE_FACTORS_SHORT, "weight", i), { n_embd_head/2 }, TENSOR_NOT_REQUIRED | (i != 0 ? TENSOR_DUPLICATED : 0));
|
layer.rope_short = create_tensor(tn(LLM_TENSOR_ROPE_FACTORS_SHORT, "weight", i), { n_embd_head/2 }, TENSOR_NOT_REQUIRED | (i != 0 ? TENSOR_DUPLICATED : 0));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case LLM_ARCH_PHIMOE:
|
||||||
|
{
|
||||||
|
const int64_t n_embd_head = n_embd / n_head;
|
||||||
|
|
||||||
|
tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), { n_embd, n_vocab }, 0);
|
||||||
|
|
||||||
|
// output
|
||||||
|
output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), { n_embd }, 0);
|
||||||
|
output_norm_b = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "bias"), {n_embd}, 0);
|
||||||
|
output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), { n_embd, n_vocab }, 0);
|
||||||
|
output_b = create_tensor(tn(LLM_TENSOR_OUTPUT, "bias"), { n_vocab }, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < n_layer; ++i) {
|
||||||
|
auto & layer = layers[i];
|
||||||
|
|
||||||
|
layer.attn_norm = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "weight", i), { n_embd }, 0);
|
||||||
|
layer.attn_norm_b = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "bias", i), { n_embd }, 0);
|
||||||
|
|
||||||
|
layer.wqkv = create_tensor(tn(LLM_TENSOR_ATTN_QKV, "weight", i), { n_embd, n_embd + 2 * n_embd_gqa }, llama_model_loader::TENSOR_NOT_REQUIRED);
|
||||||
|
if (layer.wqkv == nullptr) {
|
||||||
|
layer.wq = create_tensor(tn(LLM_TENSOR_ATTN_Q, "weight", i), {n_embd, n_embd}, 0);
|
||||||
|
layer.bq = create_tensor(tn(LLM_TENSOR_ATTN_Q, "bias", i), {n_embd}, 0);
|
||||||
|
|
||||||
|
layer.wk = create_tensor(tn(LLM_TENSOR_ATTN_K, "weight", i), {n_embd, n_embd_gqa}, 0);
|
||||||
|
layer.bk = create_tensor(tn(LLM_TENSOR_ATTN_K, "bias", i), {n_embd_gqa}, 0);
|
||||||
|
|
||||||
|
layer.wv = create_tensor(tn(LLM_TENSOR_ATTN_V, "weight", i), {n_embd, n_embd_gqa}, 0);
|
||||||
|
layer.bv = create_tensor(tn(LLM_TENSOR_ATTN_V, "bias", i), {n_embd_gqa}, 0);
|
||||||
|
}
|
||||||
|
layer.wo = create_tensor(tn(LLM_TENSOR_ATTN_OUT, "weight", i), { n_embd, n_embd }, 0);
|
||||||
|
layer.bo = create_tensor(tn(LLM_TENSOR_ATTN_OUT, "bias", i), { n_embd }, 0);
|
||||||
|
|
||||||
|
layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), { n_embd }, 0);
|
||||||
|
layer.ffn_norm_b = create_tensor(tn(LLM_TENSOR_FFN_NORM, "bias", i), { n_embd }, 0);
|
||||||
|
|
||||||
|
layer.ffn_gate_inp = create_tensor(tn(LLM_TENSOR_FFN_GATE_INP, "weight", i), {n_embd, n_expert}, 0);
|
||||||
|
layer.ffn_gate_exps = create_tensor(tn(LLM_TENSOR_FFN_GATE_EXPS, "weight", i), {n_embd, n_ff, n_expert}, 0);
|
||||||
|
layer.ffn_down_exps = create_tensor(tn(LLM_TENSOR_FFN_DOWN_EXPS, "weight", i), {n_ff, n_embd, n_expert}, 0);
|
||||||
|
layer.ffn_up_exps = create_tensor(tn(LLM_TENSOR_FFN_UP_EXPS, "weight", i), {n_embd, n_ff, n_expert}, 0);
|
||||||
|
|
||||||
|
layer.rope_long = create_tensor(tn(LLM_TENSOR_ROPE_FACTORS_LONG, "weight", i), { n_embd_head/2 }, TENSOR_NOT_REQUIRED | (i != 0 ? TENSOR_DUPLICATED : 0));
|
||||||
|
layer.rope_short = create_tensor(tn(LLM_TENSOR_ROPE_FACTORS_SHORT, "weight", i), { n_embd_head/2 }, TENSOR_NOT_REQUIRED | (i != 0 ? TENSOR_DUPLICATED : 0));
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case LLM_ARCH_PLAMO:
|
case LLM_ARCH_PLAMO:
|
||||||
{
|
{
|
||||||
tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
|
tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
|
||||||
|
|
|
@ -1523,7 +1523,8 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
|
||||||
pre_type = LLAMA_VOCAB_PRE_TYPE_COMMAND_R;
|
pre_type = LLAMA_VOCAB_PRE_TYPE_COMMAND_R;
|
||||||
clean_spaces = false;
|
clean_spaces = false;
|
||||||
} else if (
|
} else if (
|
||||||
tokenizer_pre == "qwen2") {
|
tokenizer_pre == "qwen2" ||
|
||||||
|
tokenizer_pre == "deepseek-r1-qwen") {
|
||||||
pre_type = LLAMA_VOCAB_PRE_TYPE_QWEN2;
|
pre_type = LLAMA_VOCAB_PRE_TYPE_QWEN2;
|
||||||
clean_spaces = false;
|
clean_spaces = false;
|
||||||
} else if (
|
} else if (
|
||||||
|
|
|
@ -7,18 +7,17 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <codecvt>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <locale>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <locale>
|
|
||||||
#include <codecvt>
|
|
||||||
|
|
||||||
size_t unicode_len_utf8(char src) {
|
size_t unicode_len_utf8(char src) {
|
||||||
const size_t lookup[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4 };
|
const size_t lookup[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4 };
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
llama_add_compile_flags()
|
||||||
|
|
||||||
function(llama_test target)
|
function(llama_test target)
|
||||||
include(CMakeParseArguments)
|
include(CMakeParseArguments)
|
||||||
set(options)
|
set(options)
|
||||||
|
|
|
@ -3046,9 +3046,10 @@ struct test_flash_attn_ext : public test_case {
|
||||||
const float logit_softcap; // Gemma 2
|
const float logit_softcap; // Gemma 2
|
||||||
|
|
||||||
const ggml_type type_KV;
|
const ggml_type type_KV;
|
||||||
|
std::array<int32_t, 4> permute;
|
||||||
|
|
||||||
std::string vars() override {
|
std::string vars() override {
|
||||||
return VARS_TO_STR8(hs, nh, kv, nb, mask, max_bias, logit_softcap, type_KV);
|
return VARS_TO_STR9(hs, nh, kv, nb, mask, max_bias, logit_softcap, type_KV, permute);
|
||||||
}
|
}
|
||||||
|
|
||||||
double max_nmse_err() override {
|
double max_nmse_err() override {
|
||||||
|
@ -3063,19 +3064,33 @@ struct test_flash_attn_ext : public test_case {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_flash_attn_ext(int64_t hs = 128, int64_t nh = 32, int64_t kv = 96, int64_t nb = 8,
|
test_flash_attn_ext(int64_t hs = 128, int64_t nh = 32, int64_t kv = 96, int64_t nb = 8,
|
||||||
bool mask = true, float max_bias = 0.0f, float logit_softcap = 0.0f, ggml_type type_KV = GGML_TYPE_F16)
|
bool mask = true, float max_bias = 0.0f, float logit_softcap = 0.0f, ggml_type type_KV = GGML_TYPE_F16,
|
||||||
: hs(hs), nh(nh), kv(kv), nb(nb), mask(mask), max_bias(max_bias), logit_softcap(logit_softcap), type_KV(type_KV) {}
|
std::array<int32_t, 4> permute = {0, 1, 2, 3})
|
||||||
|
: hs(hs), nh(nh), kv(kv), nb(nb), mask(mask), max_bias(max_bias), logit_softcap(logit_softcap), type_KV(type_KV), permute(permute) {}
|
||||||
|
|
||||||
ggml_tensor * build_graph(ggml_context * ctx) override {
|
ggml_tensor * build_graph(ggml_context * ctx) override {
|
||||||
const int64_t hs_padded = GGML_PAD(hs, ggml_blck_size(type_KV));
|
const int64_t hs_padded = GGML_PAD(hs, ggml_blck_size(type_KV));
|
||||||
|
|
||||||
ggml_tensor * q = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, hs_padded, nb, nh, 1);
|
auto const &create_permuted = [&](ggml_type type, int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3) -> ggml_tensor * {
|
||||||
|
int64_t ne[4] = {ne0, ne1, ne2, ne3};
|
||||||
|
int64_t ne_perm[4];
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
ne_perm[permute[i]] = ne[i];
|
||||||
|
}
|
||||||
|
ggml_tensor * t = ggml_new_tensor_4d(ctx, type, ne_perm[0], ne_perm[1], ne_perm[2], ne_perm[3]);
|
||||||
|
if (permute != std::array<int32_t, 4>{0, 1, 2, 3}) {
|
||||||
|
t = ggml_permute(ctx, t, permute[0], permute[1], permute[2], permute[3]);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
|
||||||
|
ggml_tensor * q = create_permuted(GGML_TYPE_F32, hs_padded, nb, nh, 1);
|
||||||
ggml_set_name(q, "q");
|
ggml_set_name(q, "q");
|
||||||
|
|
||||||
ggml_tensor * k = ggml_new_tensor_4d(ctx, type_KV, hs_padded, kv, nh, 1);
|
ggml_tensor * k = create_permuted(type_KV, hs_padded, kv, nh, 1);
|
||||||
ggml_set_name(k, "k");
|
ggml_set_name(k, "k");
|
||||||
|
|
||||||
ggml_tensor * v = ggml_new_tensor_4d(ctx, type_KV, hs_padded, kv, nh, 1);
|
ggml_tensor * v = create_permuted(type_KV, hs_padded, kv, nh, 1);
|
||||||
ggml_set_name(v, "v");
|
ggml_set_name(v, "v");
|
||||||
|
|
||||||
ggml_tensor * m = nullptr;
|
ggml_tensor * m = nullptr;
|
||||||
|
@ -4167,6 +4182,10 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
|
||||||
for (int nb : { 1, 3, 32, 35, }) {
|
for (int nb : { 1, 3, 32, 35, }) {
|
||||||
for (ggml_type type_KV : {GGML_TYPE_F16, GGML_TYPE_BF16, GGML_TYPE_Q8_0, GGML_TYPE_Q4_0}) {
|
for (ggml_type type_KV : {GGML_TYPE_F16, GGML_TYPE_BF16, GGML_TYPE_Q8_0, GGML_TYPE_Q4_0}) {
|
||||||
test_cases.emplace_back(new test_flash_attn_ext(hs, nh, kv, nb, mask, max_bias, logit_softcap, type_KV));
|
test_cases.emplace_back(new test_flash_attn_ext(hs, nh, kv, nb, mask, max_bias, logit_softcap, type_KV));
|
||||||
|
// run fewer test cases permuted
|
||||||
|
if (mask == true && max_bias == 0.0f && logit_softcap == 0 && kv == 512) {
|
||||||
|
test_cases.emplace_back(new test_flash_attn_ext(hs, nh, kv, nb, mask, max_bias, logit_softcap, type_KV, {0, 2, 1, 3}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ enum handcrafted_file_type {
|
||||||
HANDCRAFTED_DATA_CUSTOM_ALIGN = 810 + offset_has_data,
|
HANDCRAFTED_DATA_CUSTOM_ALIGN = 810 + offset_has_data,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string handcrafted_file_type_name(const enum handcrafted_file_type hft) {
|
static std::string handcrafted_file_type_name(const enum handcrafted_file_type hft) {
|
||||||
switch (hft) {
|
switch (hft) {
|
||||||
case HANDCRAFTED_HEADER_BAD_MAGIC: return "HEADER_BAD_MAGIC";
|
case HANDCRAFTED_HEADER_BAD_MAGIC: return "HEADER_BAD_MAGIC";
|
||||||
case HANDCRAFTED_HEADER_BAD_VERSION_1: return "HEADER_BAD_VERSION_1";
|
case HANDCRAFTED_HEADER_BAD_VERSION_1: return "HEADER_BAD_VERSION_1";
|
||||||
|
@ -99,7 +99,7 @@ static bool expect_context_not_null(const enum handcrafted_file_type hft) {
|
||||||
|
|
||||||
typedef std::pair<enum ggml_type, std::array<int64_t, GGML_MAX_DIMS>> tensor_config_t;
|
typedef std::pair<enum ggml_type, std::array<int64_t, GGML_MAX_DIMS>> tensor_config_t;
|
||||||
|
|
||||||
std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) {
|
static std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) {
|
||||||
std::vector<tensor_config_t> tensor_configs;
|
std::vector<tensor_config_t> tensor_configs;
|
||||||
tensor_configs.reserve(100);
|
tensor_configs.reserve(100);
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ std::vector<tensor_config_t> get_tensor_configs(std::mt19937 & rng) {
|
||||||
return tensor_configs;
|
return tensor_configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<enum gguf_type, enum gguf_type>> get_kv_types(std::mt19937 rng) {
|
static std::vector<std::pair<enum gguf_type, enum gguf_type>> get_kv_types(std::mt19937 rng) {
|
||||||
std::vector<std::pair<enum gguf_type, enum gguf_type>> kv_types;
|
std::vector<std::pair<enum gguf_type, enum gguf_type>> kv_types;
|
||||||
kv_types.reserve(100);
|
kv_types.reserve(100);
|
||||||
|
|
||||||
|
@ -626,8 +626,6 @@ static bool handcrafted_check_tensor_data(const gguf_context * gguf_ctx, const u
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
const uint32_t alignment = GGUF_DEFAULT_ALIGNMENT;
|
|
||||||
|
|
||||||
for (int i = 0; i < int(tensor_configs.size()); ++i) {
|
for (int i = 0; i < int(tensor_configs.size()); ++i) {
|
||||||
const ggml_type type = tensor_configs[i].first;
|
const ggml_type type = tensor_configs[i].first;
|
||||||
const std::array<int64_t, GGML_MAX_DIMS> shape = tensor_configs[i].second;
|
const std::array<int64_t, GGML_MAX_DIMS> shape = tensor_configs[i].second;
|
||||||
|
@ -866,13 +864,13 @@ static struct random_gguf_context_result get_random_gguf_context(ggml_backend_t
|
||||||
case GGUF_TYPE_COUNT:
|
case GGUF_TYPE_COUNT:
|
||||||
default: {
|
default: {
|
||||||
GGML_ABORT("fatal error");
|
GGML_ABORT("fatal error");
|
||||||
} break;
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case GGUF_TYPE_COUNT:
|
case GGUF_TYPE_COUNT:
|
||||||
default: {
|
default: {
|
||||||
GGML_ABORT("fatal error");
|
GGML_ABORT("fatal error");
|
||||||
} break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -938,7 +936,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == GGUF_TYPE_ARRAY) {
|
if (type == GGUF_TYPE_ARRAY) {
|
||||||
const int arr_n = gguf_get_arr_n(ctx, id);
|
const size_t arr_n = gguf_get_arr_n(ctx, id);
|
||||||
if (arr_n != gguf_get_arr_n(other, idx_other)) {
|
if (arr_n != gguf_get_arr_n(other, idx_other)) {
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
|
@ -953,7 +951,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other
|
||||||
if (type_arr == GGUF_TYPE_BOOL) {
|
if (type_arr == GGUF_TYPE_BOOL) {
|
||||||
const int8_t * data = reinterpret_cast<const int8_t *>(gguf_get_arr_data(ctx, id));
|
const int8_t * data = reinterpret_cast<const int8_t *>(gguf_get_arr_data(ctx, id));
|
||||||
const int8_t * data_other = reinterpret_cast<const int8_t *>(gguf_get_arr_data(other, idx_other));
|
const int8_t * data_other = reinterpret_cast<const int8_t *>(gguf_get_arr_data(other, idx_other));
|
||||||
for (int arr_i = 0; arr_i < arr_n; ++arr_i) {
|
for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) {
|
||||||
if (bool(data[arr_i]) != bool(data_other[arr_i])) {
|
if (bool(data[arr_i]) != bool(data_other[arr_i])) {
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
@ -962,7 +960,7 @@ static bool all_kv_in_other(const gguf_context * ctx, const gguf_context * other
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type_arr == GGUF_TYPE_STRING) {
|
if (type_arr == GGUF_TYPE_STRING) {
|
||||||
for (int arr_i = 0; arr_i < arr_n; ++arr_i) {
|
for (size_t arr_i = 0; arr_i < arr_n; ++arr_i) {
|
||||||
const std::string str = gguf_get_arr_str(ctx, id, arr_i);
|
const std::string str = gguf_get_arr_str(ctx, id, arr_i);
|
||||||
const std::string str_other = gguf_get_arr_str(other, idx_other, arr_i);
|
const std::string str_other = gguf_get_arr_str(other, idx_other, arr_i);
|
||||||
if (str != str_other) {
|
if (str != str_other) {
|
||||||
|
@ -1033,6 +1031,12 @@ static bool same_tensor_data(const struct ggml_context * orig, const struct ggml
|
||||||
|
|
||||||
struct ggml_tensor * t_orig = ggml_get_first_tensor(orig);
|
struct ggml_tensor * t_orig = ggml_get_first_tensor(orig);
|
||||||
struct ggml_tensor * t_read = ggml_get_first_tensor(read);
|
struct ggml_tensor * t_read = ggml_get_first_tensor(read);
|
||||||
|
|
||||||
|
if (std::string(t_read->name) != "GGUF tensor data binary blob") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
t_read = ggml_get_next_tensor(read, t_read);
|
||||||
|
|
||||||
while (t_orig) {
|
while (t_orig) {
|
||||||
if (!t_read) {
|
if (!t_read) {
|
||||||
ok = false;
|
ok = false;
|
||||||
|
@ -1051,13 +1055,13 @@ static bool same_tensor_data(const struct ggml_context * orig, const struct ggml
|
||||||
}
|
}
|
||||||
|
|
||||||
t_orig = ggml_get_next_tensor(orig, t_orig);
|
t_orig = ggml_get_next_tensor(orig, t_orig);
|
||||||
t_read = ggml_get_next_tensor(orig, t_read);
|
t_read = ggml_get_next_tensor(read, t_read);
|
||||||
}
|
}
|
||||||
if (t_read) {
|
if (t_read) {
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::pair<int, int> test_roundtrip(ggml_backend_dev_t dev, const unsigned int seed, const bool only_meta) {
|
static std::pair<int, int> test_roundtrip(ggml_backend_dev_t dev, const unsigned int seed, const bool only_meta) {
|
||||||
|
|
|
@ -144,7 +144,6 @@ static void test_penalties(
|
||||||
|
|
||||||
sampler_tester tester(probs, probs_expected);
|
sampler_tester tester(probs, probs_expected);
|
||||||
|
|
||||||
const size_t n_vocab = probs.size();
|
|
||||||
auto * sampler = llama_sampler_init_penalties(last_tokens.size(), repeat_penalty, alpha_frequency, alpha_presence);
|
auto * sampler = llama_sampler_init_penalties(last_tokens.size(), repeat_penalty, alpha_frequency, alpha_presence);
|
||||||
|
|
||||||
for (size_t i = 0; i < last_tokens.size(); i++) {
|
for (size_t i = 0; i < last_tokens.size(); i++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue