Skip to content

Commit dc89d36

Browse files
committed
handle no-mmap as well
1 parent 25909ca commit dc89d36

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

examples/gguf-hash/gguf-hash.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,14 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
365365

366366
if (hash_params.fnv) {
367367
uint64_t hash = fnv_hash((const uint8_t *)raw_data, n_bytes);
368-
printf("%016lx %s\n", hash, tensor_layer_name.c_str());
368+
char hex_result[17];
369+
for (int offset = 0; offset < 8; offset++) {
370+
unsigned int shift_bits_by = (8 * (8 - offset - 1));
371+
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff);
372+
}
373+
374+
printf("%-8s %-s %s\n", "fnv", hex_result, tensor_layer_name.c_str());
375+
369376
char hash_key[128];
370377
snprintf(hash_key, sizeof(hash_key), "%s_hash", name);
371378
gguf_set_val_u64(ctx_out, hash_key, hash);

ggml/src/ggml-rpc/ggml-rpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ bool rpc_server::set_tensor_hash(const rpc_msg_set_tensor_hash_req & request, rp
11431143
|| request.tensor.data + request.offset >= p1
11441144
|| size > (p1 - request.tensor.data - request.offset)) {
11451145
GGML_LOG_ERROR("[%s] tensor data region (data=0x%" PRIx64 ", offset=%" PRIu64 ", size=%zu, hash=0x%" PRIx64 ") out of buffer bounds [0x%zx, 0x%zx)\n",
1146-
__func__, in_tensor->data, offset, size, *hash, p0, p1);
1146+
__func__, request.tensor.data, request.offset, size, request.hash, p0, p1);
11471147
return false;
11481148
}
11491149
}

src/llama-model-loader.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,14 @@ bool llama_model_loader::load_all_data(
10791079
buffer_idx %= n_buffers;
10801080
}
10811081
} else {
1082-
read_buf.resize(n_size);
1083-
file->seek(weight->offs, SEEK_SET);
1084-
file->read_raw(read_buf.data(), n_size);
1085-
ggml_backend_tensor_set(cur, read_buf.data(), 0, n_size);
1086-
if (check_tensors && !ggml_validate_row_data(cur->type, read_buf.data(), n_size)) {
1087-
throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));
1082+
if (!check_tensors && !rpc_load_tensor(cur)) {
1083+
read_buf.resize(n_size);
1084+
file->seek(weight->offs, SEEK_SET);
1085+
file->read_raw(read_buf.data(), n_size);
1086+
ggml_backend_tensor_set(cur, read_buf.data(), 0, n_size);
1087+
if (check_tensors && !ggml_validate_row_data(cur->type, read_buf.data(), n_size)) {
1088+
throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));
1089+
}
10881090
}
10891091
}
10901092
}

0 commit comments

Comments
 (0)