mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-11-26 23:29:34 +00:00
Some checks failed
CI (sanitize) / ctest (ubuntu-24.04, THREAD) (push) Has been cancelled
CI (snapdragon) / android-ndk-snapdragon (push) Has been cancelled
CI (snapdragon) / linux-iot-snapdragon (push) Has been cancelled
CI (sanitize) / ctest ([self-hosted X64 Linux], UNDEFINED) (push) Has been cancelled
CI (sanitize) / ctest (ubuntu-24.04, ADDRESS) (push) Has been cancelled
CI (3rd-party) / ubuntu-24-llguidance (push) Has been cancelled
CI (android) / default (push) Has been cancelled
CI (android) / ndk (push) Has been cancelled
CI (android) / arm64 (push) Has been cancelled
CI (apple) / macos-latest-arm64 (push) Has been cancelled
CI (apple) / macos-latest-x64 (push) Has been cancelled
CI (apple) / macos-latest-ios-xcode (push) Has been cancelled
CI (apple) / macos-latest-tvos (push) Has been cancelled
CI (apple) / macos-latest-visionos (push) Has been cancelled
CI (self-hosted WebGPU backend) / gpu-webgpu-nvidia (push) Has been cancelled
CI (cpu) / build-cmake-pkg (push) Has been cancelled
CI (cpu) / ubuntu (arm64, ubuntu-24.04-arm) (push) Has been cancelled
CI (cpu) / ubuntu (x64, ubuntu-22.04) (push) Has been cancelled
CI (cpu) / windows / arm64 (push) Has been cancelled
CI (cpu) / windows / x64-cpu-static (push) Has been cancelled
CI (cpu) / windows / x64-openblas (push) Has been cancelled
CI (CUDA, ubuntu) / cuda (push) Has been cancelled
CI (CUDA, ubuntu) / hip (push) Has been cancelled
CI (CUDA, ubuntu) / musa (push) Has been cancelled
CI (ibm) / ubuntu-24-s390x (VXE OFF) (push) Has been cancelled
CI (ibm) / ubuntu-24-s390x (VXE ON) (push) Has been cancelled
CI (ibm) / ubuntu-26-zdnn-s390x (push) Has been cancelled
CI (ibm) / ubuntu-24-ppc64le (push) Has been cancelled
CI (opencl) / windows-2025-opencl-adreno (push) Has been cancelled
CI (openvino) / ubuntu-24-openvino (push) Has been cancelled
CI (openvino) / openvino-windows-2022 (push) Has been cancelled
CI (riscv) / ubuntu-cpu-riscv64-native (push) Has been cancelled
CI (sycl) / ubuntu-24-sycl (fp16, ON) (push) Has been cancelled
CI (sycl) / ubuntu-24-sycl (fp32, OFF) (push) Has been cancelled
CI (sycl) / windows-latest-sycl (push) Has been cancelled
CI (virtgpu) / ubuntu-24-virtgpu (push) Has been cancelled
CI (vulkan) / ubuntu-arm64 (push) Has been cancelled
CI (vulkan) / ubuntu-llvmpipe (push) Has been cancelled
CI (vulkan) / windows / arm64 (push) Has been cancelled
CI (vulkan) / windows / x64 (push) Has been cancelled
CI (wasi) / ubuntu-webgpu (push) Has been cancelled
CI (wasm) / ubuntu-webgpu (push) Has been cancelled
CI (self-hosted CPU backend) / cpu-x64-high-perf (push) Has been cancelled
CI (self-hosted CPU backend) / cpu-arm64-high-perf-graviton4 (push) Has been cancelled
CI (self-hosted CUDA backend) / gpu-cuda (push) Has been cancelled
CI (self-hosted CUDA backend) / gpu-rocm (push) Has been cancelled
CI (self-hosted KleidiAI backend) / cpu-arm64-graviton4-kleidiai (push) Has been cancelled
CI (self-hosted Metal backend) / gpu-metal (push) Has been cancelled
CI (self-hosted OpenVINO backend) / gpu-openvino-low-perf (push) Has been cancelled
Python Type-Check / python type-check (push) Has been cancelled
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm (push) Has been cancelled
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm2 (push) Has been cancelled
CI (self-hosted Vulkan backend) / gpu-vulkan-apple (push) Has been cancelled
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-linux (push) Has been cancelled
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-windows (push) Has been cancelled
CI (self-hosted WebGPU backend) / gpu-webgpu-apple (push) Has been cancelled
Code Style Checker / model-naming (push) Has been cancelled
EditorConfig Checker / editorconfig (push) Has been cancelled
Models Backend Check / cuda (push) Has been cancelled
Models Backend Check / metal (push) Has been cancelled
Models Backend Check / rocm (push) Has been cancelled
Models Backend Check / vulkan-nvidia (push) Has been cancelled
Models Backend Check / vulkan-amd (push) Has been cancelled
Models Backend Check / webgpu-nvidia (push) Has been cancelled
flake8 Lint / Lint (push) Has been cancelled
Release / check-release (push) Has been cancelled
Server (sanitize) / server (RelWithDebInfo, ADDRESS) (push) Has been cancelled
Server (sanitize) / server (RelWithDebInfo, UNDEFINED) (push) Has been cancelled
Server (self-hosted) / server-metal (push) Has been cancelled
Server (self-hosted) / server-cuda (push) Has been cancelled
Server (self-hosted) / server-kleidiai (push) Has been cancelled
Server / ubuntu (push) Has been cancelled
Server / windows (push) Has been cancelled
Release / windows (arm64, vulkan, -G "Ninja Multi-Config" -DGGML_VULKAN=ON -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake, ggml-vulkan) (push) Has been cancelled
Release / ubuntu-24-sycl (fp16, ON) (push) Has been cancelled
Release / ubuntu-24-sycl (fp32, OFF) (push) Has been cancelled
Release / ubuntu-24-rocm (10.0.0, x64, gfx908;gfx90a;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201) (push) Has been cancelled
CI (snapdragon) / Test on QDC Device (QCS9075M) (push) Has been cancelled
CI (snapdragon) / Test on QDC Device (SM8850) (push) Has been cancelled
CI (apple) / macos-latest-swift (generic/platform=iOS) (push) Has been cancelled
CI (apple) / macos-latest-swift (generic/platform=macOS) (push) Has been cancelled
CI (apple) / macos-latest-swift (generic/platform=tvOS) (push) Has been cancelled
Release / macos-cpu (arm64, arm64, -DGGML_METAL_EMBED_LIBRARY=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-26) (push) Has been cancelled
Release / macos-cpu (x64, x64, -DGGML_METAL=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-15-intel) (push) Has been cancelled
Release / ubuntu-cpu (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Release / ubuntu-cpu (s390x, ubuntu-24.04-s390x) (push) Has been cancelled
Release / ubuntu-cpu (x64, ubuntu-22.04) (push) Has been cancelled
Release / ubuntu-vulkan (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Release / ubuntu-vulkan (x64, ubuntu-22.04) (push) Has been cancelled
Release / ubuntu-cuda (13.4, arm64) (push) Has been cancelled
Release / ubuntu-cuda (12.8, x64) (push) Has been cancelled
Release / ubuntu-cuda (13.4, x64) (push) Has been cancelled
Release / windows-cpu / x64 (push) Has been cancelled
Release / android-arm64 (push) Has been cancelled
Release / android-arm64-snapdragon (push) Has been cancelled
Release / linux-arm64-snapdragon (push) Has been cancelled
Release / ubuntu-24-openvino (push) Has been cancelled
Release / windows-openvino (push) Has been cancelled
Release / windows-cpu / arm64 (push) Has been cancelled
Release / windows-rocm (10.0.0, x64, gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Has been cancelled
Release / windows (arm64, opencl-adreno, -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake -DCMAKE_PREFIX_PATH="$env:RUNNER_TEMP/opencl-arm64-release" -DGGML_OPENCL=ON -DGGML_OPENCL_USE_ADRENO_KERNELS=ON, ggml-opencl) (push) Has been cancelled
Release / windows (x64, vulkan, -DGGML_VULKAN=ON, ggml-vulkan) (push) Has been cancelled
Release / windows-cuda (13.4, arm64) (push) Has been cancelled
Release / windows-cuda (12.4, x64) (push) Has been cancelled
Release / windows-cuda (13.4, x64) (push) Has been cancelled
Release / windows-sycl (push) Has been cancelled
Release / ios-xcode (push) Has been cancelled
Release / ui-build (push) Has been cancelled
* spec : add probabilistic sampling for DFlash2 drafts * spec : apply review suggestions --------- Co-authored-by: Pranesh Gonegandla <pgonegandla@nvidia.com>
125 lines
5.2 KiB
C++
125 lines
5.2 KiB
C++
#pragma once
|
|
|
|
#include "llama.h"
|
|
#include "common.h"
|
|
|
|
struct common_speculative;
|
|
|
|
// comma separated list the provided types
|
|
std::string common_speculative_type_name_str(const std::vector<enum common_speculative_type> & types);
|
|
|
|
// comma separated list of all types
|
|
const char * common_speculative_all_types_str();
|
|
|
|
// parse user provided types
|
|
std::vector<enum common_speculative_type> common_speculative_types_from_names(const std::vector<std::string> & names);
|
|
|
|
// infer the spec types from the GGUF metadata of a draft model; empty if unknown
|
|
std::vector<enum common_speculative_type> common_speculative_types_from_gguf(const std::string & path);
|
|
|
|
// convert string to type
|
|
enum common_speculative_type common_speculative_type_from_name(const std::string & name);
|
|
|
|
// convert type to string
|
|
std::string common_speculative_type_to_str(enum common_speculative_type type);
|
|
|
|
// return the max number of draft tokens based on the speculative parameters
|
|
int32_t common_speculative_n_max(const common_params_speculative * spec);
|
|
|
|
// return the max number of draft tokens from the initialized implementations
|
|
int32_t common_speculative_n_max(const common_speculative * spec);
|
|
|
|
// validate and resolve the unconditional synthetic acceptance rates
|
|
std::vector<double> common_speculative_synth_rates_resolve(const common_params_speculative * spec, int32_t n_max);
|
|
|
|
// return the conditional synthetic acceptance probabilities
|
|
const std::vector<double> & common_speculative_get_synth_probs(const common_speculative * spec);
|
|
|
|
common_params common_base_params_to_speculative(const common_params & params);
|
|
|
|
struct common_speculative_output_limits {
|
|
int32_t total;
|
|
int32_t per_seq;
|
|
};
|
|
|
|
// return the output limits needed for speculative decoding
|
|
common_speculative_output_limits common_speculative_get_output_limits(
|
|
int32_t n_batch, int32_t n_parallel, int32_t n_draft);
|
|
|
|
// return true if the target and draft models have compatible vocabs
|
|
bool common_speculative_are_compatible(const llama_model * model_tgt, const llama_model * model_dft);
|
|
|
|
common_speculative * common_speculative_init(common_params_speculative & params, uint32_t n_seq);
|
|
|
|
void common_speculative_free(common_speculative * spec);
|
|
|
|
struct common_speculative_draft_params {
|
|
// this flag is used to chain the drafts through all the available implementations
|
|
// after the first successful draft from an implementation, we set it
|
|
// to false to prevent further drafts for that sequence
|
|
// at the end of the draft() call, all drafting flags will be reset to false
|
|
bool drafting = false;
|
|
|
|
// overrides individual configurations (-1 disabled)
|
|
// can be used to constraint the max draft based on the remaining context size
|
|
int32_t n_max = -1;
|
|
|
|
llama_pos pos0;
|
|
llama_token id_last;
|
|
|
|
// TODO: remove in the future by keeping track of the prompt from the _begin() call and the consecutive accept calls
|
|
const llama_tokens * prompt;
|
|
|
|
// the generated draft from the last _draft() call
|
|
llama_tokens * result;
|
|
|
|
// candidate distribution per drafted token; set it to make draft-simple, draft-mtp and draft-dflash (DFlash2 only) sample
|
|
std::vector<std::vector<llama_token_data>> * result_q = nullptr;
|
|
|
|
// the target's temp and seed, read only when the drafter samples probabilistically
|
|
float temp = 1.0f;
|
|
uint32_t seed = LLAMA_DEFAULT_SEED;
|
|
};
|
|
|
|
common_speculative_draft_params & common_speculative_get_draft_params(common_speculative * spec, llama_seq_id seq_id);
|
|
|
|
// optionally call once at the beginning of a new generation
|
|
void common_speculative_begin(common_speculative * spec, llama_seq_id seq_id, const llama_tokens & prompt);
|
|
|
|
// process the batch and update the internal state of the speculative context
|
|
bool common_speculative_process(common_speculative * spec, const common_batch & batch);
|
|
|
|
// generate drafts for the sequences specified with `common_speculative_get_draft_params`
|
|
void common_speculative_draft(common_speculative * spec);
|
|
|
|
// informs the speculative context that n_accepted tokens were accepted by the target model
|
|
void common_speculative_accept(common_speculative * spec, llama_seq_id, uint16_t n_accepted);
|
|
|
|
// (optional) get/set internal state
|
|
bool common_speculative_get_state(common_speculative * spec, llama_seq_id seq_id, std::vector<uint8_t> & data);
|
|
void common_speculative_set_state(common_speculative * spec, llama_seq_id seq_id, const std::vector<uint8_t> & data);
|
|
|
|
// print statistics about the speculative decoding
|
|
void common_speculative_print_stats(const common_speculative * spec);
|
|
|
|
struct common_speculative_deleter {
|
|
void operator()(common_speculative * s) { common_speculative_free(s); }
|
|
};
|
|
|
|
typedef std::unique_ptr<common_speculative, common_speculative_deleter> common_speculative_ptr;
|
|
|
|
struct common_speculative_init_result {
|
|
common_speculative_init_result(common_params & params, llama_model * model_tgt, llama_context * ctx_tgt);
|
|
~common_speculative_init_result();
|
|
|
|
llama_model * model();
|
|
llama_context * context();
|
|
|
|
private:
|
|
struct impl;
|
|
std::unique_ptr<impl> pimpl;
|
|
};
|
|
|
|
using common_speculative_init_result_ptr = std::unique_ptr<common_speculative_init_result>;
|
|
|
|
common_speculative_init_result_ptr common_speculative_init_from_params(common_params & params, llama_model * model_tgt, llama_context * ctx_tgt);
|