Skip to content

Commit e729ace

Browse files
authored
Merge branch 'ggml-org:master' into glm45v-2
2 parents deb1399 + a5c07dc commit e729ace

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4638
-4690
lines changed

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ ggml:
7676
- changed-files:
7777
- any-glob-to-any-file:
7878
- ggml/**
79+
model:
80+
- changed-files:
81+
- any-glob-to-any-file:
82+
- src/models/**
7983
nix:
8084
- changed-files:
8185
- any-glob-to-any-file:

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ LLM inference in C/C++
1717

1818
## Hot topics
1919

20-
- **[guide : running gpt-oss with llama.cpp](https://github.com/ggml-org/llama.cpp/discussions/15396)**
21-
- **[[FEEDBACK] Better packaging for llama.cpp to support downstream consumers 🤗](https://github.com/ggml-org/llama.cpp/discussions/15313)**
20+
- **[guide : using the new WebUI of llama.cpp](https://github.com/ggml-org/llama.cpp/discussions/16938)**
21+
- [guide : running gpt-oss with llama.cpp](https://github.com/ggml-org/llama.cpp/discussions/15396)
22+
- [[FEEDBACK] Better packaging for llama.cpp to support downstream consumers 🤗](https://github.com/ggml-org/llama.cpp/discussions/15313)
2223
- Support for the `gpt-oss` model with native MXFP4 format has been added | [PR](https://github.com/ggml-org/llama.cpp/pull/15091) | [Collaboration with NVIDIA](https://blogs.nvidia.com/blog/rtx-ai-garage-openai-oss) | [Comment](https://github.com/ggml-org/llama.cpp/discussions/15095)
23-
- Hot PRs: [All](https://github.com/ggml-org/llama.cpp/pulls?q=is%3Apr+label%3Ahot+) | [Open](https://github.com/ggml-org/llama.cpp/pulls?q=is%3Apr+label%3Ahot+is%3Aopen)
2424
- Multimodal support arrived in `llama-server`: [#12898](https://github.com/ggml-org/llama.cpp/pull/12898) | [documentation](./docs/multimodal.md)
2525
- VS Code extension for FIM completions: https://github.com/ggml-org/llama.vscode
2626
- Vim/Neovim plugin for FIM completions: https://github.com/ggml-org/llama.vim
27-
- Introducing GGUF-my-LoRA https://github.com/ggml-org/llama.cpp/discussions/10123
2827
- Hugging Face Inference Endpoints now support GGUF out of the box! https://github.com/ggml-org/llama.cpp/discussions/9669
2928
- Hugging Face GGUF editor: [discussion](https://github.com/ggml-org/llama.cpp/discussions/9268) | [tool](https://huggingface.co/spaces/CISCai/gguf-editor)
3029

ggml/include/ggml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ extern "C" {
21082108
enum ggml_scale_mode {
21092109
GGML_SCALE_MODE_NEAREST = 0,
21102110
GGML_SCALE_MODE_BILINEAR = 1,
2111+
GGML_SCALE_MODE_BICUBIC = 2,
21112112

21122113
GGML_SCALE_MODE_COUNT
21132114
};

ggml/src/ggml-cpu/ops.cpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7507,10 +7507,17 @@ static void ggml_compute_forward_upscale_f32(
75077507
float sf1 = (float)ne1/src0->ne[1];
75087508
float sf2 = (float)ne2/src0->ne[2];
75097509
float sf3 = (float)ne3/src0->ne[3];
7510+
float pixel_offset = 0.5f;
75107511

75117512
const int32_t mode_flags = ggml_get_op_params_i32(dst, 0);
75127513
const ggml_scale_mode mode = (ggml_scale_mode) (mode_flags & 0xFF);
75137514

7515+
if (mode_flags & GGML_SCALE_FLAG_ALIGN_CORNERS) {
7516+
pixel_offset = 0.0f;
7517+
sf0 = ne0 > 1 && ne00 > 1 ? (float)(ne0 - 1) / (ne00 - 1) : sf0;
7518+
sf1 = ne1 > 1 && ne01 > 1 ? (float)(ne1 - 1) / (ne01 - 1) : sf1;
7519+
}
7520+
75147521
if (mode == GGML_SCALE_MODE_NEAREST) {
75157522
for (int64_t i3 = 0; i3 < ne3; i3++) {
75167523
const int64_t i03 = i3 / sf3;
@@ -7530,13 +7537,6 @@ static void ggml_compute_forward_upscale_f32(
75307537
}
75317538
}
75327539
} else if (mode == GGML_SCALE_MODE_BILINEAR) {
7533-
float pixel_offset = 0.5f;
7534-
if (mode_flags & GGML_SCALE_FLAG_ALIGN_CORNERS) {
7535-
pixel_offset = 0.0f;
7536-
sf0 = ne0 > 1 && ne00 > 1 ? (float)(ne0 - 1) / (ne00 - 1) : sf0;
7537-
sf1 = ne1 > 1 && ne01 > 1 ? (float)(ne1 - 1) / (ne01 - 1) : sf1;
7538-
}
7539-
75407540
for (int64_t i3 = 0; i3 < ne3; i3++) {
75417541
const int64_t i03 = i3 / sf3;
75427542
for (int64_t i2 = ith; i2 < ne2; i2 += nth) {
@@ -7571,6 +7571,51 @@ static void ggml_compute_forward_upscale_f32(
75717571

75727572
const float val = a*(1 - dx)*(1 - dy) + b*dx*(1 - dy) + c*(1 - dx)*dy + d*dx*dy;
75737573

7574+
float * y_dst = (float *)((char *)dst->data + i0*nb0 + i1*nb1 + i2*nb2 + i3*nb3);
7575+
*y_dst = val;
7576+
}
7577+
}
7578+
}
7579+
}
7580+
} else if (mode == GGML_SCALE_MODE_BICUBIC) {
7581+
// https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm
7582+
const float a = -0.75f; // use alpha = -0.75 (same as PyTorch)
7583+
auto weight1 = [a](float x) { return ((a + 2) * x - (a + 3)) * x * x + 1; };
7584+
auto weight2 = [a](float x) { return ((a * x - 5 * a) * x + 8 * a) * x - 4 * a; };
7585+
auto bicubic = [=](float p0, float p1, float p2, float p3, float x) {
7586+
const float w0 = weight2(x + 1);
7587+
const float w1 = weight1(x + 0);
7588+
const float w2 = weight1(1 - x);
7589+
const float w3 = weight2(2 - x);
7590+
return p0*w0 + p1*w1 + p2*w2 + p3*w3;
7591+
};
7592+
7593+
for (int64_t i3 = 0; i3 < ne3; i3++) {
7594+
const int64_t i03 = i3 / sf3;
7595+
for (int64_t i2 = ith; i2 < ne2; i2 += nth) {
7596+
const int64_t i02 = i2 / sf2;
7597+
for (int64_t i1 = 0; i1 < ne1; i1++) {
7598+
const float y = ((float)i1 + pixel_offset) / sf1 - pixel_offset;
7599+
const int64_t y0 = (int64_t)floorf(y);
7600+
const float dy = y - (float)y0;
7601+
7602+
for (int64_t i0 = 0; i0 < ne0; i0++) {
7603+
const float x = ((float)i0 + pixel_offset) / sf0 - pixel_offset;
7604+
const int64_t x0 = (int64_t)floorf(x);
7605+
const float dx = x - (float)x0;
7606+
7607+
auto p = [=](int64_t x_off, int64_t y_off) -> float {
7608+
int64_t i00 = std::max(int64_t(0), std::min(x0 + x_off, ne00 - 1));
7609+
int64_t i01 = std::max(int64_t(0), std::min(y0 + y_off, ne01 - 1));
7610+
return *(const float *)((const char *)src0->data + i00*nb00 + i01*nb01 + i02*nb02 + i03*nb03);
7611+
};
7612+
7613+
const float val = bicubic(
7614+
bicubic(p(-1,-1), p(0,-1), p(1,-1), p(2,-1), dx),
7615+
bicubic(p(-1, 0), p(0, 0), p(1, 0), p(2, 0), dx),
7616+
bicubic(p(-1, 1), p(0, 1), p(1, 1), p(2, 1), dx),
7617+
bicubic(p(-1, 2), p(0, 2), p(1, 2), p(2, 2), dx), dy);
7618+
75747619
float * y_dst = (float *)((char *)dst->data + i0*nb0 + i1*nb1 + i2*nb2 + i3*nb3);
75757620
*y_dst = val;
75767621
}

ggml/src/ggml-cpu/repack.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,10 +1678,24 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS, ggml_type PAR
16781678
int64_t chunk_size = (nr + nth_scaled - 1) / nth_scaled;
16791679
int64_t nchunk = (nr + chunk_size - 1) / chunk_size;
16801680

1681+
// Ensure minimum chunk size to avoid alignment issues with high thread counts
1682+
// Minimum chunk size should be at least NB_COLS to prevent overlapping chunks after alignment
1683+
const int64_t min_chunk_size = NB_COLS;
1684+
if (nchunk > 0 && (nr / nchunk) < min_chunk_size && nr >= min_chunk_size) {
1685+
nchunk = (nr + min_chunk_size - 1) / min_chunk_size;
1686+
}
1687+
16811688
if (nth == 1 || nchunk < nth || disable_chunking) {
16821689
nchunk = nth;
16831690
}
16841691

1692+
// Ensure nchunk doesn't exceed the number of rows divided by minimum chunk size
1693+
// This prevents creating too many tiny chunks that could overlap after alignment
1694+
const int64_t max_nchunk = (nr + min_chunk_size - 1) / min_chunk_size;
1695+
if (nchunk > max_nchunk) {
1696+
nchunk = max_nchunk;
1697+
}
1698+
16851699
if (ith == 0) {
16861700
// Every thread starts at ith, so the first unprocessed chunk is nth. This save a bit of coordination right at the start.
16871701
ggml_threadpool_chunk_set(params->threadpool, nth);
@@ -1695,8 +1709,15 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS, ggml_type PAR
16951709
while (current_chunk < nchunk) {
16961710
int64_t src0_start = (current_chunk * ne01) / nchunk;
16971711
int64_t src0_end = ((current_chunk + 1) * ne01) / nchunk;
1712+
1713+
// Align boundaries to NB_COLS - round up to ensure all data is included
1714+
// The chunk size limiting above ensures chunks are large enough to prevent overlaps
16981715
src0_start = (src0_start % NB_COLS) ? src0_start + NB_COLS - (src0_start % NB_COLS) : src0_start;
16991716
src0_end = (src0_end % NB_COLS) ? src0_end + NB_COLS - (src0_end % NB_COLS) : src0_end;
1717+
if (src0_end > ne01) {
1718+
src0_end = ne01;
1719+
}
1720+
17001721
if (src0_start >= src0_end) {
17011722
break;
17021723
}
@@ -1808,8 +1829,12 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS, ggml_type PAR
18081829
int64_t src0_cur_start = (ith * ne01) / nth;
18091830
int64_t src0_cur_end = ((ith + 1) * ne01) / nth;
18101831

1832+
// Align boundaries to NB_COLS - round up to ensure all data is included
18111833
src0_cur_start = (src0_cur_start % NB_COLS) ? src0_cur_start + NB_COLS - (src0_cur_start % NB_COLS) : src0_cur_start;
18121834
src0_cur_end = (src0_cur_end % NB_COLS) ? src0_cur_end + NB_COLS - (src0_cur_end % NB_COLS) : src0_cur_end;
1835+
if (src0_cur_end > ne01) {
1836+
src0_cur_end = ne01;
1837+
}
18131838

18141839
if (src0_cur_start >= src0_cur_end) {
18151840
return;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,14 @@ static bool ggml_cuda_should_fuse_mul_mat_vec_f(const ggml_tensor * tensor) {
21152115
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
21162116
use_mul_mat_vec_f = use_mul_mat_vec_f && ggml_cuda_should_use_mmvf(src0->type, cc, src0->ne, is_mul_mat_id ? src1->ne[2] : src1->ne[1]);
21172117

2118+
const bool split = ggml_backend_buft_is_cuda_split(src0->buffer->buft) ||
2119+
ggml_backend_buft_is_cuda_split(src1->buffer->buft);
2120+
2121+
//TODO: add support for fusion for split buffers
2122+
if (split) {
2123+
return false;
2124+
}
2125+
21182126
//we only support fusion for ncols_dst = 1
21192127
if (tensor->op == GGML_OP_MUL_MAT && dst->ne[1] != 1) {
21202128
return false;
@@ -2154,6 +2162,15 @@ static bool ggml_cuda_should_fuse_mul_mat_vec_q(const ggml_tensor * tensor) {
21542162
return false;
21552163
}
21562164

2165+
2166+
const bool split = ggml_backend_buft_is_cuda_split(src0->buffer->buft) ||
2167+
ggml_backend_buft_is_cuda_split(src1->buffer->buft);
2168+
2169+
//TODO: add support for fusion for split buffers
2170+
if (split) {
2171+
return false;
2172+
}
2173+
21572174
return use_mul_mat_vec_q;
21582175
}
21592176

ggml/src/ggml-hexagon/htp/ops-utils.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,46 +43,46 @@ static inline int32_t htp_is_one_chunk(void * addr, uint32_t n, uint32_t chunk_s
4343
}
4444

4545
static inline void htp_dump_int8_line(char * pref, const int8_t * x, int n) {
46-
char str[1024], *p = str;
47-
p += sprintf(p, "%s: ", pref);
48-
for (int i = 0; i < 16; i++) {
49-
p += sprintf(p, "%d, ", x[i]);
46+
char str[1024], *p = str, *p_end = str + sizeof(str);
47+
p += snprintf(p, p_end - p, "%s: ", pref);
48+
for (int i = 0; i < n && p < p_end; i++) {
49+
p += snprintf(p, p_end - p, "%d, ", x[i]);
5050
}
5151
FARF(HIGH, "%s\n", str);
5252
}
5353

5454
static inline void htp_dump_uint8_line(char * pref, const uint8_t * x, uint32_t n) {
55-
char str[1024], *p = str;
56-
p += sprintf(p, "%s: ", pref);
57-
for (int i = 0; i < n; i++) {
58-
p += sprintf(p, "%d, ", x[i]);
55+
char str[1024], *p = str, *p_end = str + sizeof(str);
56+
p += snprintf(p, p_end - p, "%s: ", pref);
57+
for (int i = 0; i < n && p < p_end; i++) {
58+
p += snprintf(p, p_end - p, "%d, ", x[i]);
5959
}
6060
FARF(HIGH, "%s\n", str);
6161
}
6262

6363
static inline void htp_dump_int32_line(char * pref, const int32_t * x, uint32_t n) {
64-
char str[1024], *p = str;
65-
p += sprintf(p, "%s: ", pref);
64+
char str[1024], *p = str, *p_end = str + sizeof(str);
65+
p += snprintf(p, p_end - p, "%s: ", pref);
6666
for (int i = 0; i < n; i++) {
67-
p += sprintf(p, "%d, ", (int) x[i]);
67+
p += snprintf(p, p_end - p, "%d, ", (int) x[i]);
6868
}
6969
FARF(HIGH, "%s\n", str);
7070
}
7171

7272
static inline void htp_dump_fp16_line(char * pref, const __fp16 * x, uint32_t n) {
73-
char str[1024], *p = str;
74-
p += sprintf(p, "%s: ", pref);
73+
char str[1024], *p = str, *p_end = str + sizeof(str);
74+
p += snprintf(p, p_end - p, "%s: ", pref);
7575
for (int i = 0; i < n; i++) {
76-
p += sprintf(p, "%.6f, ", (float) x[i]);
76+
p += snprintf(p, p_end - p, "%.6f, ", (float) x[i]);
7777
}
7878
FARF(HIGH, "%s\n", str);
7979
}
8080

8181
static inline void htp_dump_fp32_line(char * pref, const float * x, uint32_t n) {
82-
char str[1024], *p = str;
83-
p += sprintf(p, "%s: ", pref);
82+
char str[1024], *p = str, *p_end = str + sizeof(str);
83+
p += snprintf(p, p_end - p, "%s: ", pref);
8484
for (int i = 0; i < n; i++) {
85-
p += sprintf(p, "%.6f, ", x[i]);
85+
p += snprintf(p, p_end - p, "%.6f, ", x[i]);
8686
}
8787
FARF(HIGH, "%s\n", str);
8888
}

0 commit comments

Comments
 (0)