Skip to content

Commit 9d74fdc

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dev-upstream-master-gemma4-local-20260607
2 parents eb7dd0b + 8f83d6c commit 9d74fdc

35 files changed

Lines changed: 1166 additions & 190 deletions

.devops/intel.Dockerfile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ LABEL org.opencontainers.image.created=$BUILD_DATE \
5757
org.opencontainers.image.url=$IMAGE_URL \
5858
org.opencontainers.image.source=$IMAGE_SOURCE
5959

60-
ARG IGC_VERSION=v2.20.5
61-
ARG IGC_VERSION_FULL=2_2.20.5+19972
62-
ARG COMPUTE_RUNTIME_VERSION=25.40.35563.10
63-
ARG COMPUTE_RUNTIME_VERSION_FULL=25.40.35563.10-0
64-
ARG IGDGMM_VERSION=22.8.2
60+
#Following versions are for multiple GPUs, since 26.x has known issue:
61+
# https://github.com/ggml-org/llama.cpp/issues/21747,
62+
# https://github.com/intel/compute-runtime/issues/921.
63+
#ARG IGC_VERSION=v2.20.5
64+
#ARG IGC_VERSION_FULL=2_2.20.5+19972
65+
#ARG COMPUTE_RUNTIME_VERSION=25.40.35563.10
66+
#ARG COMPUTE_RUNTIME_VERSION_FULL=25.40.35563.10-0
67+
#ARG IGDGMM_VERSION=22.8.2
68+
69+
70+
ARG IGC_VERSION=v2.34.4
71+
ARG IGC_VERSION_FULL=2_2.34.4+21428
72+
ARG COMPUTE_RUNTIME_VERSION=26.18.38308.1
73+
ARG COMPUTE_RUNTIME_VERSION_FULL=26.18.38308.1-0
74+
ARG IGDGMM_VERSION=22.10.0
6575
RUN mkdir /tmp/neo/ && cd /tmp/neo/ \
6676
&& wget https://github.com/intel/intel-graphics-compiler/releases/download/$IGC_VERSION/intel-igc-core-${IGC_VERSION_FULL}_amd64.deb \
6777
&& wget https://github.com/intel/intel-graphics-compiler/releases/download/$IGC_VERSION/intel-igc-opencl-${IGC_VERSION_FULL}_amd64.deb \

common/arg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
16151615
string_format("samplers that will be used for generation in the order, separated by \';\'\n(default: %s)", sampler_type_names.c_str()),
16161616
[](common_params & params, const std::string & value) {
16171617
const auto sampler_names = string_split<std::string>(value, ';');
1618-
params.sampling.samplers = common_sampler_types_from_names(sampler_names, true);
1618+
params.sampling.samplers = common_sampler_types_from_names(sampler_names);
16191619
params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_SAMPLERS;
16201620
}
16211621
).set_sampling());
@@ -2221,8 +2221,8 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
22212221
}
22222222
).set_examples(mmproj_examples).set_env("LLAMA_ARG_MMPROJ_OFFLOAD"));
22232223
add_opt(common_arg(
2224-
{"--image", "--audio"}, "FILE",
2225-
"path to an image or audio file. use with multimodal models, use comma-separated values for multiple files\n",
2224+
{"--image", "--audio", "--video"}, "FILE",
2225+
"path to an image, audio, or video file. use with multimodal models, use comma-separated values for multiple files\n",
22262226
[](common_params & params, const std::string & value) {
22272227
for (const auto & item : parse_csv_row(value)) {
22282228
params.image.emplace_back(item);

common/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ static void common_init_sampler_from_model(
11481148
if (llama_model_meta_val_str(model, llama_model_meta_key_str(LLAMA_MODEL_META_KEY_SAMPLING_SEQUENCE), buf, sizeof(buf)) > 0) {
11491149
const std::vector<std::string> sampler_names = string_split<std::string>(std::string(buf), ';');
11501150
if (!sampler_names.empty()) {
1151-
sparams.samplers = common_sampler_types_from_names(sampler_names, true);
1151+
sparams.samplers = common_sampler_types_from_names(sampler_names);
11521152
}
11531153
}
11541154
}

common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ struct common_params {
571571
struct common_params_model mmproj;
572572
bool mmproj_use_gpu = true; // use GPU for multimodal model
573573
bool no_mmproj = false; // explicitly disable multimodal model
574-
std::vector<std::string> image; // path to image file(s)
574+
std::vector<std::string> image; // path to image file(s) ; TODO: change the name to "media"
575575
int image_min_tokens = -1;
576576
int image_max_tokens = -1;
577577

common/sampling.cpp

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -769,54 +769,63 @@ std::string common_sampler_type_to_str(enum common_sampler_type cnstr) {
769769
}
770770
}
771771

772-
std::vector<common_sampler_type> common_sampler_types_from_names(const std::vector<std::string> & names, bool allow_alt_names) {
773-
std::unordered_map<std::string, common_sampler_type> sampler_canonical_name_map {
774-
{ "dry", COMMON_SAMPLER_TYPE_DRY },
775-
{ "top_k", COMMON_SAMPLER_TYPE_TOP_K },
776-
{ "top_p", COMMON_SAMPLER_TYPE_TOP_P },
777-
{ "top_n_sigma", COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
778-
{ "typ_p", COMMON_SAMPLER_TYPE_TYPICAL_P },
779-
{ "min_p", COMMON_SAMPLER_TYPE_MIN_P },
780-
{ "temperature", COMMON_SAMPLER_TYPE_TEMPERATURE },
781-
{ "xtc", COMMON_SAMPLER_TYPE_XTC },
782-
{ "infill", COMMON_SAMPLER_TYPE_INFILL },
783-
{ "penalties", COMMON_SAMPLER_TYPE_PENALTIES },
784-
{ "adaptive_p", COMMON_SAMPLER_TYPE_ADAPTIVE_P },
785-
};
786-
787-
// since samplers names are written multiple ways
788-
// make it ready for both system names and input names
789-
std::unordered_map<std::string, common_sampler_type> sampler_alt_name_map {
790-
{ "top-k", COMMON_SAMPLER_TYPE_TOP_K },
791-
{ "top-p", COMMON_SAMPLER_TYPE_TOP_P },
792-
{ "top-n-sigma", COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
793-
{ "nucleus", COMMON_SAMPLER_TYPE_TOP_P },
794-
{ "typical-p", COMMON_SAMPLER_TYPE_TYPICAL_P },
795-
{ "typical", COMMON_SAMPLER_TYPE_TYPICAL_P },
796-
{ "typ-p", COMMON_SAMPLER_TYPE_TYPICAL_P },
797-
{ "typ", COMMON_SAMPLER_TYPE_TYPICAL_P },
798-
{ "min-p", COMMON_SAMPLER_TYPE_MIN_P },
799-
{ "temp", COMMON_SAMPLER_TYPE_TEMPERATURE },
800-
{ "adaptive-p", COMMON_SAMPLER_TYPE_ADAPTIVE_P },
801-
};
772+
std::vector<common_sampler_type> common_sampler_types_from_names(const std::vector<std::string> & names) {
773+
// sampler names can be written multiple ways; generate aliases from canonical names
774+
static const auto sampler_name_map = []{
775+
// canonical sampler name mapping
776+
std::unordered_map<std::string, common_sampler_type> canonical_name_map {
777+
{ "dry", COMMON_SAMPLER_TYPE_DRY },
778+
{ "top_k", COMMON_SAMPLER_TYPE_TOP_K },
779+
{ "top_p", COMMON_SAMPLER_TYPE_TOP_P },
780+
{ "top_n_sigma", COMMON_SAMPLER_TYPE_TOP_N_SIGMA },
781+
{ "typ_p", COMMON_SAMPLER_TYPE_TYPICAL_P },
782+
{ "min_p", COMMON_SAMPLER_TYPE_MIN_P },
783+
{ "temperature", COMMON_SAMPLER_TYPE_TEMPERATURE },
784+
{ "xtc", COMMON_SAMPLER_TYPE_XTC },
785+
{ "infill", COMMON_SAMPLER_TYPE_INFILL },
786+
{ "penalties", COMMON_SAMPLER_TYPE_PENALTIES },
787+
{ "adaptive_p", COMMON_SAMPLER_TYPE_ADAPTIVE_P }
788+
};
789+
std::unordered_map<std::string, common_sampler_type> alias_name_map;
790+
for (const auto & entry : canonical_name_map) {
791+
const std::string & canonical = entry.first;
792+
if (canonical.find('_') == std::string::npos) {
793+
continue;
794+
}
795+
// kebab-case: "top-k", "min-p", etc.
796+
{
797+
std::string kebab_case = canonical;
798+
std::replace(kebab_case.begin(), kebab_case.end(), '_', '-');
799+
alias_name_map.insert({kebab_case, entry.second});
800+
}
801+
// no dash: "topk", "minp", etc.
802+
{
803+
std::string no_dash = canonical;
804+
no_dash.erase(std::remove(no_dash.begin(), no_dash.end(), '_'), no_dash.end());
805+
alias_name_map.insert({no_dash, entry.second});
806+
}
807+
}
808+
// misc. aliases
809+
alias_name_map.insert({"nucleus", COMMON_SAMPLER_TYPE_TOP_P});
810+
alias_name_map.insert({"temp", COMMON_SAMPLER_TYPE_TEMPERATURE});
811+
alias_name_map.insert({"typ", COMMON_SAMPLER_TYPE_TYPICAL_P});
812+
// include aliases + canonical names in the complete mapping
813+
alias_name_map.merge(canonical_name_map);
814+
return alias_name_map;
815+
}();
802816

803817
std::vector<common_sampler_type> samplers;
804818
samplers.reserve(names.size());
805819

806820
for (const auto & name : names) {
807-
auto sampler = sampler_canonical_name_map.find(name);
808-
if (sampler != sampler_canonical_name_map.end()) {
821+
std::string name_lower = name;
822+
std::transform(name_lower.begin(), name_lower.end(), name_lower.begin(), ::tolower);
823+
auto sampler = sampler_name_map.find(name_lower);
824+
if (sampler != sampler_name_map.end()) {
809825
samplers.push_back(sampler->second);
810826
continue;
811827
}
812-
if (allow_alt_names) {
813-
sampler = sampler_alt_name_map.find(name);
814-
if (sampler != sampler_alt_name_map.end()) {
815-
samplers.push_back(sampler->second);
816-
continue;
817-
}
818-
}
819-
LOG_WRN("%s: unable to match sampler by name '%s'\n", __func__, name.c_str());
828+
LOG_WRN("%s: unable to match sampler by name '%s'\n", __func__, name_lower.c_str());
820829
}
821830

822831
return samplers;

common/sampling.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::string common_sampler_prev_str(common_sampler * gsmpl, llama_context * ctx,
109109
char common_sampler_type_to_chr(enum common_sampler_type cnstr);
110110
std::string common_sampler_type_to_str(enum common_sampler_type cnstr);
111111

112-
std::vector<enum common_sampler_type> common_sampler_types_from_names(const std::vector<std::string> & names, bool allow_alt_names);
112+
std::vector<enum common_sampler_type> common_sampler_types_from_names(const std::vector<std::string> & names);
113113
std::vector<enum common_sampler_type> common_sampler_types_from_chars(const std::string & chars);
114114

115115
llama_sampler * llama_sampler_init_llg(const llama_vocab * vocab,

conversion/mistral.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ def set_mistral_config(gguf_writer: gguf.GGUFWriter, hparams: dict):
105105
gguf_writer.add_rope_scaling_yarn_log_mul(mscale_all_dim)
106106
gguf_writer.add_rope_scaling_orig_ctx_len(yarn_params["original_max_position_embeddings"])
107107

108-
if "llama_4_scaling" in hparams:
109-
gguf_writer.add_attn_temperature_scale(hparams["llama_4_scaling"]["beta"])
108+
llama_4_scaling = hparams.get("llama_4_scaling")
109+
if llama_4_scaling is not None:
110+
gguf_writer.add_attn_temperature_scale(llama_4_scaling["beta"])
110111

111112

112113
class MistralMoeModel(DeepseekV2Model):

convert_hf_to_gguf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def main() -> None:
238238
assert hparams.get("vision_encoder") is not None, "This model does not support multimodal"
239239
from conversion.pixtral import PixtralModel
240240
model_class = PixtralModel
241-
elif "moe" in hparams:
241+
elif hparams.get("moe") is not None:
242242
from conversion.mistral import MistralMoeModel
243243
model_class = MistralMoeModel
244244
else:

ggml/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ project("ggml" C CXX ASM)
44

55
### GGML Version
66
set(GGML_VERSION_MAJOR 0)
7-
set(GGML_VERSION_MINOR 13)
8-
set(GGML_VERSION_PATCH 1)
7+
set(GGML_VERSION_MINOR 14)
8+
set(GGML_VERSION_PATCH 0)
99
set(GGML_VERSION_BASE "${GGML_VERSION_MAJOR}.${GGML_VERSION_MINOR}.${GGML_VERSION_PATCH}")
1010

1111
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

ggml/src/ggml-cuda/ggml-cuda.cu

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,18 @@ ggml_backend_cuda_context::~ggml_backend_cuda_context() {
622622

623623
// cuda buffer
624624

625+
struct ggml_backend_cuda_device_context {
626+
int device;
627+
std::string name;
628+
std::string description;
629+
std::string pci_bus_id;
630+
int op_offload_min_batch_size;
631+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
632+
std::mutex device_mutex;
633+
int active_count = 0;
634+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
635+
};
636+
625637
struct ggml_backend_cuda_buffer_context {
626638
int device;
627639
void * dev_ptr = nullptr;
@@ -639,6 +651,13 @@ struct ggml_backend_cuda_buffer_context {
639651

640652
static void ggml_backend_cuda_buffer_free_buffer(ggml_backend_buffer_t buffer) {
641653
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;
654+
655+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
656+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) buffer->buft->device->context;
657+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
658+
dev_ctx->active_count--;
659+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
660+
642661
delete ctx;
643662
}
644663

@@ -791,6 +810,12 @@ static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_bac
791810

792811
ggml_backend_cuda_buffer_context * ctx = new ggml_backend_cuda_buffer_context(buft_ctx->device, dev_ptr);
793812

813+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
814+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) buft->device->context;
815+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
816+
dev_ctx->active_count++;
817+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
818+
794819
return ggml_backend_buffer_init(buft, ggml_backend_cuda_buffer_interface, ctx, size);
795820
}
796821

@@ -1490,6 +1515,12 @@ static bool ggml_backend_buft_is_cuda_host(ggml_backend_buffer_type_t buft) {
14901515
}
14911516

14921517
static void ggml_backend_cuda_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
1518+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
1519+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) buffer->buft->device->context;
1520+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
1521+
dev_ctx->active_count--;
1522+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
1523+
14931524
CUDA_CHECK(cudaFreeHost(buffer->context));
14941525
}
14951526

@@ -1498,6 +1529,8 @@ static void * ggml_cuda_host_malloc(size_t size) {
14981529
return nullptr;
14991530
}
15001531

1532+
ggml_cuda_set_device(0); // cudaMallocHost can create the implicit CUDA device context, make sure that this is consistently done on device 0.
1533+
15011534
void * ptr = nullptr;
15021535
cudaError_t err = cudaMallocHost((void **) &ptr, size);
15031536
if (err != cudaSuccess) {
@@ -1523,6 +1556,12 @@ static ggml_backend_buffer_t ggml_backend_cuda_host_buffer_type_alloc_buffer(ggm
15231556
buffer->buft = buft;
15241557
buffer->iface.free_buffer = ggml_backend_cuda_host_buffer_free_buffer;
15251558

1559+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
1560+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) buft->device->context;
1561+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
1562+
dev_ctx->active_count++;
1563+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
1564+
15261565
return buffer;
15271566
}
15281567

@@ -3140,6 +3179,12 @@ static const char * ggml_backend_cuda_get_name(ggml_backend_t backend) {
31403179
static void ggml_backend_cuda_free(ggml_backend_t backend) {
31413180
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context;
31423181

3182+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
3183+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) backend->device->context;
3184+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
3185+
dev_ctx->active_count--;
3186+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
3187+
31433188
delete cuda_ctx;
31443189
delete backend;
31453190
}
@@ -4871,14 +4916,6 @@ void ggml_backend_cuda_unregister_host_buffer(void * buffer) {
48714916

48724917
// backend device
48734918

4874-
struct ggml_backend_cuda_device_context {
4875-
int device;
4876-
std::string name;
4877-
std::string description;
4878-
std::string pci_bus_id;
4879-
int op_offload_min_batch_size;
4880-
};
4881-
48824919
static const char * ggml_backend_cuda_device_get_name(ggml_backend_dev_t dev) {
48834920
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
48844921
return ctx->name.c_str();
@@ -4967,6 +5004,11 @@ static bool ggml_backend_cuda_get_available_uma_memory(long * available_memory_k
49675004

49685005
static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
49695006
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
5007+
5008+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
5009+
std::lock_guard<std::mutex> lock(ctx->device_mutex);
5010+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
5011+
49705012
ggml_cuda_set_device(ctx->device);
49715013
CUDA_CHECK(cudaMemGetInfo(free, total));
49725014

@@ -4993,6 +5035,13 @@ static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t *
49935035
}
49945036
#endif // defined(__linux__)
49955037

5038+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
5039+
// If no backends or buffers are active, the cudaMemGetInfo call above lazily created a CUDA
5040+
// context that permanently consumes VRAM. Reset the device to free it.
5041+
if (ctx->active_count == 0) {
5042+
CUDA_CHECK(cudaDeviceReset());
5043+
}
5044+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
49965045
}
49975046

49985047
static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend_dev_t dev) {
@@ -5687,13 +5736,21 @@ ggml_backend_t ggml_backend_cuda_init(int device) {
56875736
return nullptr;
56885737
}
56895738

5739+
ggml_backend_dev_t dev = ggml_backend_reg_dev_get(ggml_backend_cuda_reg(), device);
5740+
56905741
ggml_backend_t cuda_backend = new ggml_backend {
56915742
/* .guid = */ ggml_backend_cuda_guid(),
56925743
/* .iface = */ ggml_backend_cuda_interface,
5693-
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cuda_reg(), device),
5744+
/* .device = */ dev,
56945745
/* .context = */ ctx,
56955746
};
56965747

5748+
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
5749+
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) dev->context;
5750+
std::lock_guard<std::mutex> lock(dev_ctx->device_mutex);
5751+
dev_ctx->active_count++;
5752+
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
5753+
56975754
return cuda_backend;
56985755
}
56995756

0 commit comments

Comments
 (0)