Skip to content

Commit 7e1289a

Browse files
committed
fixes for sdcpp
1 parent a0ae187 commit 7e1289a

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

examples/llava/clip.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,26 @@ struct clip_ctx {
363363
if(enable_gpu_clip)
364364
{
365365
#ifdef GGML_USE_CUDA
366-
backend = ggml_backend_cuda_init(0);
366+
backend = ggml_backend_ptr(ggml_backend_cuda_init(0));
367367
LOG_INF("%s: CLIP using CUDA backend\n", __func__);
368368
#endif
369369
#ifdef GGML_USE_METAL
370-
backend = ggml_backend_metal_init();
370+
backend = ggml_backend_ptr(ggml_backend_metal_init());
371371
LOG_INF("%s: CLIP using Metal backend\n", __func__);
372372
#endif
373373
#ifdef GGML_USE_VULKAN
374-
backend = ggml_backend_vk_init(0);
374+
backend = ggml_backend_ptr(ggml_backend_vk_init(0));
375375
LOG_INF("%s: CLIP using Vulkan backend\n", __func__);
376376
#endif
377377
}
378378

379379
if (!backend) {
380-
backend = ggml_backend_cpu_init();
380+
backend = ggml_backend_ptr(ggml_backend_cpu_init());
381381
LOG_INF("%s: CLIP using CPU backend\n", __func__);
382382
}
383383

384-
backend_ptrs.push_back(backend);
385-
backend_buft.push_back(ggml_backend_get_default_buffer_type(backend));
384+
backend_ptrs.push_back(backend.get());
385+
backend_buft.push_back(ggml_backend_get_default_buffer_type(backend.get()));
386386

387387
sched.reset(
388388
ggml_backend_sched_new(backend_ptrs.data(), backend_buft.data(), backend_ptrs.size(), 8192, false)
@@ -1228,7 +1228,7 @@ struct clip_model_loader {
12281228

12291229
// print gguf info
12301230
try {
1231-
1231+
12321232
std::string name;
12331233
get_string(KEY_NAME, name, false);
12341234
std::string description;
@@ -2950,8 +2950,8 @@ bool clip_image_batch_encode(clip_ctx * ctx, const int n_threads, const clip_ima
29502950
if (window_mask) ggml_backend_tensor_set(window_mask, mask.data(), 0, ggml_nbytes(window_mask));
29512951
}
29522952

2953-
if (ggml_backend_is_cpu(ctx->backend)) {
2954-
ggml_backend_cpu_set_n_threads(ctx->backend, n_threads);
2953+
if (ggml_backend_is_cpu(ctx->backend.get())) {
2954+
ggml_backend_cpu_set_n_threads(ctx->backend.get(), n_threads);
29552955
}
29562956

29572957
auto status = ggml_backend_sched_graph_compute(ctx->sched.get(), gf);

otherarch/sdcpp/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class UpSampleBlock : public GGMLBlock {
5656
// x: [N, channels, h, w]
5757
auto conv = std::dynamic_pointer_cast<Conv2d>(blocks["conv"]);
5858

59-
x = ggml_upscale(ctx, x, 2); // [N, channels, h*2, w*2]
59+
x = ggml_upscale(ctx, x, 2, ggml_scale_mode::GGML_SCALE_MODE_NEAREST); // [N, channels, h*2, w*2]
6060
x = conv->forward(ctx, x); // [N, out_channels, h*2, w*2]
6161
return x;
6262
}

otherarch/sdcpp/esrgan.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class RRDBNet : public GGMLBlock {
130130
body_feat = conv_body->forward(ctx, body_feat);
131131
feat = ggml_add(ctx, feat, body_feat);
132132
// upsample
133-
feat = lrelu(ctx, conv_up1->forward(ctx, ggml_upscale(ctx, feat, 2)));
134-
feat = lrelu(ctx, conv_up2->forward(ctx, ggml_upscale(ctx, feat, 2)));
133+
feat = lrelu(ctx, conv_up1->forward(ctx, ggml_upscale(ctx, feat, 2, ggml_scale_mode::GGML_SCALE_MODE_NEAREST)));
134+
feat = lrelu(ctx, conv_up2->forward(ctx, ggml_upscale(ctx, feat, 2, ggml_scale_mode::GGML_SCALE_MODE_NEAREST)));
135135
auto out = conv_last->forward(ctx, lrelu(ctx, conv_hr->forward(ctx, feat)));
136136
return out;
137137
}

otherarch/sdcpp/ggml_extend.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ __STATIC_INLINE__ struct ggml_tensor* ggml_kronecker(ggml_context* ctx, struct g
113113
a->ne[0] * b->ne[0],
114114
a->ne[1] * b->ne[1],
115115
a->ne[2] * b->ne[2],
116-
a->ne[3] * b->ne[3]),
116+
a->ne[3] * b->ne[3],
117+
ggml_scale_mode::GGML_SCALE_MODE_NEAREST),
117118
b);
118119
}
119120

otherarch/sdcpp/model.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
17491749
bool success = true;
17501750
for (size_t file_index = 0; file_index < file_paths_.size(); file_index++) {
17511751
std::string file_path = file_paths_[file_index];
1752-
LOG_DEBUG("loading tensors from %s", file_path.c_str());
1752+
LOG_DEBUG("loading tensors from %s\n", file_path.c_str());
17531753

17541754
std::ifstream file(file_path, std::ios::binary);
17551755
if (!file.is_open()) {
@@ -1886,7 +1886,12 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
18861886
}
18871887
}
18881888
int64_t t2 = ggml_time_ms();
1889-
pretty_progress(++tensor_count, processed_tensor_storages.size(), (t2 - t1) / 1000.0f);
1889+
++tensor_count;
1890+
if(tensor_count<2 || tensor_count%5==0 || (tensor_count+10) > processed_tensor_storages.size())
1891+
{
1892+
//throttle progress printing
1893+
pretty_progress(tensor_count, processed_tensor_storages.size(), (t2 - t1) / 1000.0f);
1894+
}
18901895
t1 = t2;
18911896
}
18921897

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) {
160160
{
161161
printf("With Custom Clip-G Model: %s\n",clipg_filename.c_str());
162162
}
163+
if(inputs.quant)
164+
{
165+
printf("Note: Loading a pre-quantized model is always faster than using compress weights!\n");
166+
}
163167

164168
//duplicated from expose.cpp
165169
int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices

otherarch/sdcpp/tae.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class TinyDecoder : public UnaryBlock {
149149
if (i == 1) {
150150
h = ggml_relu_inplace(ctx, h);
151151
} else {
152-
h = ggml_upscale(ctx, h, 2);
152+
h = ggml_upscale(ctx, h, 2, ggml_scale_mode::GGML_SCALE_MODE_NEAREST);
153153
}
154154
continue;
155155
}

0 commit comments

Comments
 (0)