Skip to content

Commit 348a54e

Browse files
authored
feat: use pretty-progress for tensor loading (#516)
1 parent d50473d commit 348a54e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

model.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1748,9 +1748,11 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
17481748
}
17491749
return true;
17501750
};
1751-
1751+
int tensor_count = 0;
1752+
int64_t t1 = ggml_time_ms();
17521753
for (auto& tensor_storage : processed_tensor_storages) {
17531754
if (tensor_storage.file_index != file_index) {
1755+
++tensor_count;
17541756
continue;
17551757
}
17561758
ggml_tensor* dst_tensor = NULL;
@@ -1762,6 +1764,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
17621764
}
17631765

17641766
if (dst_tensor == NULL) {
1767+
++tensor_count;
17651768
continue;
17661769
}
17671770

@@ -1828,6 +1831,9 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
18281831
ggml_backend_tensor_set(dst_tensor, convert_buffer.data(), 0, ggml_nbytes(dst_tensor));
18291832
}
18301833
}
1834+
int64_t t2 = ggml_time_ms();
1835+
pretty_progress(++tensor_count, processed_tensor_storages.size(), (t2 - t1) / 1000.0f);
1836+
t1 = t2;
18311837
}
18321838

18331839
if (zip != NULL) {

util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void pretty_progress(int step, int steps, float time) {
348348
}
349349
}
350350
progress += "|";
351-
printf(time > 1.0f ? "\r%s %i/%i - %.2fs/it" : "\r%s %i/%i - %.2fit/s",
351+
printf(time > 1.0f ? "\r%s %i/%i - %.2fs/it" : "\r%s %i/%i - %.2fit/s\033[K",
352352
progress.c_str(), step, steps,
353353
time > 1.0f || time == 0 ? time : (1.0f / time));
354354
fflush(stdout); // for linux

0 commit comments

Comments
 (0)