Skip to content

Commit e9748e4

Browse files
committed
fix traililng whitespce
1 parent c292bf1 commit e9748e4

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

examples/llava/clip.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -659,19 +659,19 @@ static ggml_cgraph * clip_image_build_graph(clip_ctx * ctx, const clip_image_f32
659659
if (ctx->has_qwen2vl_merger) {
660660
GGML_ASSERT(image_size_width % (patch_size * 2) == 0);
661661
GGML_ASSERT(image_size_height % (patch_size * 2) == 0);
662-
662+
663663
auto inp_1 = ggml_conv_2d(ctx0, model.patch_embeddings_1, inp_raw, patch_size, patch_size, 0, 0, 1, 1);
664664
inp = ggml_add(ctx0, inp, inp_1);
665665
inp = ggml_cont(ctx0, ggml_permute(ctx0, inp, 1, 2, 0, 3)); // [w, h, c, b] -> [c, w, h, b]
666666
inp = ggml_reshape_4d(
667-
ctx0, inp,
667+
ctx0, inp,
668668
hidden_size * 2, patches_w / 2, patches_h, batch_size);
669669
inp = ggml_reshape_4d(
670-
ctx0, inp,
670+
ctx0, inp,
671671
hidden_size * 2, patches_w / 2, 2, batch_size * (patches_h / 2));
672672
inp = ggml_cont(ctx0, ggml_permute(ctx0, inp, 0, 2, 1, 3));
673673
inp = ggml_reshape_3d(
674-
ctx0, inp,
674+
ctx0, inp,
675675
hidden_size, patches_w * patches_h, batch_size);
676676
}
677677
else {
@@ -756,7 +756,7 @@ static ggml_cgraph * clip_image_build_graph(clip_ctx * ctx, const clip_image_f32
756756
Q = ggml_reshape_4d(ctx0, Q, d_head, n_head, num_positions, batch_size);
757757
if (ctx->has_qwen2vl_merger) {
758758
Q = ggml_rope_multi(
759-
ctx0, Q, positions, nullptr,
759+
ctx0, Q, positions, nullptr,
760760
d_head/2, mrope_sections, GGML_ROPE_TYPE_VISION, 32768, 10000, 1, 0, 1, 32, 1);
761761
}
762762
Q = ggml_scale_inplace(ctx0, Q, 1.0f / sqrt((float)d_head));
@@ -769,7 +769,7 @@ static ggml_cgraph * clip_image_build_graph(clip_ctx * ctx, const clip_image_f32
769769
K = ggml_reshape_4d(ctx0, K, d_head, n_head, num_positions, batch_size);
770770
if (ctx->has_qwen2vl_merger) {
771771
K = ggml_rope_multi(
772-
ctx0, K, positions, nullptr,
772+
ctx0, K, positions, nullptr,
773773
d_head/2, mrope_sections, GGML_ROPE_TYPE_VISION, 32768, 10000, 1, 0, 1, 32, 1);
774774
}
775775
K = ggml_cont(ctx0, ggml_permute(ctx0, K, 0, 2, 1, 3));
@@ -1286,7 +1286,7 @@ struct clip_ctx * clip_model_load(const char * fname, const int verbosity = 1) {
12861286

12871287
idx = get_key_idx(ctx, KEY_USE_GELU);
12881288
new_clip->use_gelu = gguf_get_val_bool(ctx, idx);
1289-
1289+
12901290
try {
12911291
idx = get_key_idx(ctx, KEY_USE_SILU);
12921292
new_clip->use_silu = gguf_get_val_bool(ctx, idx);
@@ -2079,14 +2079,14 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, cli
20792079
}
20802080
}
20812081
return true;
2082-
}
2082+
}
20832083
else if (ctx->has_qwen2vl_merger) {
20842084
clip_image_u8 * resized = clip_image_u8_init();
20852085
auto patch_size = clip_patch_size(ctx) * 2;
20862086
int nx = ceil((float)img->nx / patch_size) * patch_size;
20872087
int ny = ceil((float)img->ny / patch_size) * patch_size;
20882088
bicubic_resize(*img, *resized, nx, ny);
2089-
2089+
20902090
res_imgs->data = new clip_image_f32[1];
20912091
// clip_image_f32 * res = clip_image_f32_init();
20922092
normalize_image_u8_to_f32(resized, res_imgs->data, ctx->image_mean, ctx->image_std);
@@ -2573,7 +2573,7 @@ bool clip_image_batch_encode(clip_ctx * ctx, const int n_threads, const clip_ima
25732573
const int pw = image_size_width / patch_size;
25742574
const int ph = image_size_height / patch_size;
25752575
int* positions_data = (int*)malloc(ggml_nbytes(positions));
2576-
2576+
25772577
int ptr = 0;
25782578
for (int y = 0; y < ph; y+=2)
25792579
{
@@ -2590,7 +2590,7 @@ bool clip_image_batch_encode(clip_ctx * ctx, const int n_threads, const clip_ima
25902590
}
25912591
}
25922592
}
2593-
2593+
25942594
ggml_backend_tensor_set(positions, positions_data, 0, ggml_nbytes(positions));
25952595
free(positions_data);
25962596
}

examples/llava/llava.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli
263263
std::vector<float *> image_embd_v;
264264
image_embd_v.resize(img_res_v.size);
265265
struct clip_image_size * load_image_size = clip_image_size_init();
266-
266+
267267
for (size_t i = 0; i < img_res_v.size; i++) {
268268
const int64_t t_img_enc_step_start_us = ggml_time_us();
269269
image_embd_v[i] = (float *)malloc(clip_embd_nbytes_by_img(ctx_clip, img_res_v.data[i].nx, img_res_v.data[i].ny));
270270
int patch_size=14;
271271
load_image_size->width = img_res_v.data[i].nx;
272272
load_image_size->height = img_res_v.data[i].ny;
273273
clip_add_load_image_size(ctx_clip, load_image_size);
274-
274+
275275
bool encoded = false;
276276
if (clip_is_qwen2vl(ctx_clip)) {
277277
encoded = clip_image_encode(ctx_clip, n_threads, &img_res_v.data[i], image_embd_v[i]);
@@ -285,7 +285,7 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli
285285
encoded = clip_image_encode(ctx_clip, n_threads, &img_res_v.data[i], image_embd_v[i]);
286286
}
287287
}
288-
288+
289289
if (!encoded) {
290290
LOG_ERR("Unable to encode image - spatial_unpad - subimage %d of %d\n", (int) i+1, (int) img_res_v.size);
291291
return false;
@@ -299,8 +299,8 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli
299299
int n_img_pos_out = 0;
300300
for (size_t i = 0; i < image_embd_v.size(); i++) {
301301
std::memcpy(
302-
image_embd + n_img_pos_out * clip_n_mmproj_embd(ctx_clip),
303-
image_embd_v[i],
302+
image_embd + n_img_pos_out * clip_n_mmproj_embd(ctx_clip),
303+
image_embd_v[i],
304304
clip_embd_nbytes_by_img(ctx_clip, img_res_v.data[i].nx, img_res_v.data[i].ny));
305305
n_img_pos_out += clip_n_patches_by_img(ctx_clip, &img_res_v.data[i]);
306306
}

examples/llava/qwen2vl-cli.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <fstream>
2626

2727

28-
static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct llava_image_embed * image_embed,
28+
static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct llava_image_embed * image_embed,
2929
int n_batch, int * n_past, int * st_pos_id, struct clip_image_size * image_size) {
3030
int n_embd = llama_n_embd(llama_get_model(ctx_llama));
3131
const int patch_size = 14 * 2;
@@ -35,7 +35,7 @@ static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct lla
3535
// llama_pos mrope_pos[img_tokens * 4];
3636
std::vector<llama_pos> mrope_pos;
3737
mrope_pos.resize(img_tokens * 4);
38-
38+
3939
for (int y = 0; y < ph; y++)
4040
{
4141
for (int x = 0; x < pw; x++)
@@ -45,14 +45,14 @@ static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct lla
4545
mrope_pos[i + img_tokens] = *st_pos_id + y;
4646
mrope_pos[i + img_tokens * 2] = *st_pos_id + x;
4747
mrope_pos[i + img_tokens * 3] = 0;
48-
}
48+
}
4949
}
5050
*st_pos_id += std::max(pw, ph);
5151

5252
int processed = 0;
5353
std::vector<llama_pos> batch_mrope_pos;
5454
batch_mrope_pos.resize(img_tokens * 4);
55-
55+
5656
for (int i = 0; i < img_tokens; i += n_batch) {
5757
int n_eval = img_tokens - i;
5858
if (n_eval > n_batch) {
@@ -65,7 +65,7 @@ static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct lla
6565
memcpy(&batch_mrope_pos[n_eval * 1], &mrope_pos[img_tokens * 1 + processed], n_eval * sizeof(llama_pos));
6666
memcpy(&batch_mrope_pos[n_eval * 2], &mrope_pos[img_tokens * 2 + processed], n_eval * sizeof(llama_pos));
6767
memcpy(&batch_mrope_pos[n_eval * 3], &mrope_pos[img_tokens * 3 + processed], n_eval * sizeof(llama_pos));
68-
68+
6969
llama_batch batch = {
7070
int32_t(n_eval), // n_tokens
7171
nullptr, // token
@@ -75,7 +75,7 @@ static bool qwen2vl_eval_image_embed(llama_context * ctx_llama, const struct lla
7575
nullptr, // seq_id
7676
nullptr, // logits
7777
};
78-
78+
7979
if (llama_decode(ctx_llama, batch)) {
8080
LOG_ERR("%s : failed to eval\n", __func__);
8181
return false;
@@ -103,7 +103,7 @@ static bool eval_tokens(struct llama_context * ctx_llama, std::vector<llama_toke
103103
pos[j] = *st_pos_id + (j % batch.n_tokens);
104104
}
105105
batch.pos = pos.data();
106-
106+
107107
if (llama_decode(ctx_llama, batch)) {
108108
LOG_ERR("%s : failed to eval. token %d/%d (batch size %d, n_past %d)\n", __func__, i, N, n_batch, *n_past);
109109
return false;
@@ -413,7 +413,7 @@ static void debug_test_mrope_2d() {
413413
pos_id[i + 90] = i + 30;
414414
}
415415
int sections[4] = {32, 32, 0, 0};
416-
416+
417417
// 4. Allocate a `ggml_backend_buffer` to store all tensors
418418
ggml_backend_buffer_t buffer = ggml_backend_alloc_ctx_tensors(ctx, backend);
419419

@@ -424,7 +424,7 @@ static void debug_test_mrope_2d() {
424424
// 6. Create a `ggml_cgraph` for mul_mat operation
425425
struct ggml_cgraph * gf = NULL;
426426
struct ggml_context * ctx_cgraph = NULL;
427-
427+
428428
// create a temporally context to build the graph
429429
struct ggml_init_params params0 = {
430430
/*.mem_size =*/ ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead(),
@@ -441,7 +441,7 @@ static void debug_test_mrope_2d() {
441441

442442
// Add "result" tensor and all of its dependencies to the cgraph
443443
ggml_build_forward_expand(gf, result0);
444-
444+
445445
// 7. Create a `ggml_gallocr` for cgraph computation
446446
ggml_gallocr_t allocr = ggml_gallocr_new(ggml_backend_get_default_buffer_type(backend));
447447
ggml_gallocr_alloc_graph(allocr, gf);
@@ -462,7 +462,7 @@ static void debug_test_mrope_2d() {
462462
ggml_backend_tensor_get(result, result_data, 0, ggml_nbytes(result));
463463
const std::string bin_file = "mrope_2d_" + backend_name +".bin";
464464
std::ofstream outFile(bin_file, std::ios::binary);
465-
465+
466466
if (outFile.is_open()) {
467467
outFile.write(reinterpret_cast<const char*>(result_data), ggml_nbytes(result));
468468
outFile.close();
@@ -493,7 +493,7 @@ static void debug_dump_img_embed(struct llava_context * ctx_llava) {
493493
for (int c = 0; c < 3; c++)
494494
vals[i * 3 + c] = (float)(i % (56 * 56)) / (56*56);
495495
}
496-
496+
497497
clip_encode_float_image(ctx_llava->ctx_clip, 16, vals, 56, 56, embd.data());
498498

499499
std::ofstream outFile("img_embed.bin", std::ios::binary);
@@ -547,7 +547,7 @@ int main(int argc, char ** argv) {
547547
#ifndef NDEBUG
548548
} else if (params.image[0].empty()) {
549549
auto ctx_llava = llava_init_context(&params, model);
550-
550+
551551
debug_test_mrope_2d();
552552
debug_dump_img_embed(ctx_llava);
553553

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9146,10 +9146,10 @@ static void ggml_mrope_cache_init(
91469146
int sec_w = sections[1] + sections[0];
91479147
int sec_e = sections[2] + sec_w;
91489148
GGML_ASSERT(sect_dims <= ne0);
9149-
9149+
91509150
for (int64_t i0 = 0; i0 < ne0; i0 += 2) {
91519151
const float ff = freq_factors ? freq_factors[i0/2] : 1.0f;
9152-
9152+
91539153
int sector = (i0 / 2) % sect_dims;
91549154
if (indep_sects) {
91559155
// compute theta independently for each dim sections
@@ -9171,14 +9171,14 @@ static void ggml_mrope_cache_init(
91719171
float theta = theta_t;
91729172
if (sector >= sections[0] && sector < sec_w) {
91739173
theta = theta_h;
9174-
}
9174+
}
91759175
else if (sector >= sec_w && sector < sec_w + sections[2]) {
91769176
theta = theta_w;
91779177
}
91789178
else if (sector >= sec_w + sections[2]) {
91799179
theta = theta_e;
91809180
}
9181-
9181+
91829182
rope_yarn(
91839183
theta/ff, freq_scale, corr_dims, i0, ext_factor, mscale, &cache[i0 + 0], &cache[i0 + 1]
91849184
);

ggml/src/ggml-cuda/rope.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static __global__ void rope_multi(
147147
}
148148
else if (sector >= sections.v[0] && sector < sec_w) {
149149
theta_base = pos[i2 + ne2 * 1]*powf(theta_scale, i0/2.0f);
150-
}
150+
}
151151
else if (sector >= sec_w && sector < sec_w + sections.v[2]) {
152152
theta_base = pos[i2 + ne2 * 2]*powf(theta_scale, i0/2.0f);
153153
}
@@ -196,7 +196,7 @@ static __global__ void rope_vision(
196196
else if (sector >= sections.v[0] && sector < sec_w) {
197197
const int p = sector - sections.v[0];
198198
theta_base = pos[i2 + ne2]*powf(theta_scale, p);
199-
}
199+
}
200200

201201
const float freq_factor = has_ff ? freq_factors[i0/2] : 1.0f;
202202

src/llama.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,7 @@ struct llama_context {
34003400

34013401
// whether we are computing encoder output or decoder output
34023402
bool is_encoding = false;
3403-
3403+
34043404
// TODO: find a better way to accommodate mutli-dimension position encoding methods
34053405
// number of position id each token get, 1 for each token in most cases.
34063406
// when using m-rope, it will be 3 position ids per token to representing 3 dimension coordinate.
@@ -12592,7 +12592,7 @@ struct llm_build_context {
1259212592

1259312593
return gf;
1259412594
}
12595-
12595+
1259612596
struct ggml_cgraph * build_qwen2vl() {
1259712597
struct ggml_cgraph * gf = ggml_new_graph_custom(ctx0, llama_model_max_nodes(model), false);
1259812598
const int64_t n_embd_head = hparams.n_embd_head_v;
@@ -12644,7 +12644,7 @@ struct llm_build_context {
1264412644
cb(Vcur, "Vcur", il);
1264512645

1264612646
Qcur = ggml_rope_multi(
12647-
ctx0,
12647+
ctx0,
1264812648
ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head, n_tokens), inp_pos, nullptr,
1264912649
n_rot, sections, rope_type, n_ctx_orig, freq_base, freq_scale,
1265012650
ext_factor, attn_factor, beta_fast, beta_slow
@@ -20168,7 +20168,7 @@ enum llama_rope_type llama_rope_type(const struct llama_model * model) {
2016820168
case LLM_ARCH_EXAONE:
2016920169
case LLM_ARCH_MINICPM3:
2017020170
return LLAMA_ROPE_TYPE_NEOX;
20171-
20171+
2017220172
case LLM_ARCH_QWEN2VL:
2017320173
return LLAMA_ROPE_TYPE_MROPE;
2017420174

tests/test-backend-ops.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,10 +2200,10 @@ struct test_rope : public test_case {
22002200
ggml_set_param(ctx, a);
22012201
ggml_set_name(a, "a");
22022202
}
2203-
2203+
22042204
const bool is_mrope = mode & GGML_ROPE_TYPE_MROPE;
22052205
const bool is_vision = mode == GGML_ROPE_TYPE_VISION;
2206-
2206+
22072207
ggml_tensor * pos;
22082208
if (is_mrope || is_vision) {
22092209
pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, ne_a[2] * 4);
@@ -3834,7 +3834,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
38343834
test_cases.emplace_back(new test_rope(type, { 80, 32, 2, 1}, 20, 2, 512, fs, ef, af, ff, v)); // neox (stablelm)
38353835
test_cases.emplace_back(new test_rope(type, { 80, 32, 2, 1}, 32, 2, 512, fs, ef, af, ff, v)); // neox (phi-2)
38363836
}
3837-
3837+
38383838
if (all) {
38393839
test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 128, GGML_ROPE_TYPE_MROPE, 512, fs, ef, af, ff, v)); // rope_multi,m-rope (qwen2vl 2B)
38403840
test_cases.emplace_back(new test_rope(type, {128, 28, 2, 1}, 128, GGML_ROPE_TYPE_MROPE, 512, fs, ef, af, ff, v)); // rope_multi,m-rope (qwen2vl 7B)

tests/test-rope.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ int main(int /*argc*/, const char ** /*argv*/) {
178178
struct ggml_tensor * p0 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4);
179179
struct ggml_tensor * p1 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4);
180180
struct ggml_tensor * p2 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4);
181-
181+
182182
int sections[4] = {16, 24, 24, 0};
183183
mode = (m == 3) ? GGML_ROPE_TYPE_MROPE : GGML_ROPE_TYPE_VISION;
184184

@@ -189,7 +189,7 @@ int main(int /*argc*/, const char ** /*argv*/) {
189189
((int32_t *) p2->data)[i + ne[2] * j] = n_past_2 + i + j;
190190
}
191191
}
192-
192+
193193
// [[100, 101, 102, ..., 172],
194194
// [101, 102, 103, ..., 173],
195195
// [102, 103, 104, ..., 174]]

0 commit comments

Comments
 (0)