Skip to content

Commit 18ff6ca

Browse files
committed
split: move llama_tensor_offset to llama_model_loader
1 parent b8feff4 commit 18ff6ca

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

llama.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,17 +1460,6 @@ struct llama_mlock {
14601460
#endif
14611461
};
14621462

1463-
// Holds information on a tensor data source location.
1464-
struct llama_tensor_offset {
1465-
uint16_t idx; // source file index
1466-
size_t offs; // tensor data offset in the original file
1467-
1468-
llama_tensor_offset(uint16_t idx, const char * name, struct gguf_context * gguf_ctx) : idx(idx) {
1469-
const int tensor_idx = gguf_find_tensor(gguf_ctx, name);
1470-
offs = gguf_get_data_offset(gguf_ctx) + gguf_get_tensor_offset(gguf_ctx, tensor_idx);
1471-
}
1472-
};
1473-
14741463
static std::string llama_token_to_piece(const struct llama_context * ctx, llama_token token) {
14751464
std::vector<char> result(8, 0);
14761465
const int n_tokens = llama_token_to_piece(llama_get_model(ctx), token, result.data(), result.size());
@@ -2829,7 +2818,18 @@ struct llama_model_loader {
28292818
llama_fver fver;
28302819

28312820
std::vector<std::unique_ptr<llama_mmap>> mappings;
2832-
std::unordered_map<std::string, struct llama_tensor_offset> tensors_offs; // unified tensor data offset accross files
2821+
2822+
// Holds information on a tensor data source location.
2823+
struct llama_tensor_offset {
2824+
uint16_t idx; // source file index
2825+
size_t offs; // tensor data offset in the original file
2826+
2827+
llama_tensor_offset(uint16_t idx, const char * name, struct gguf_context * gguf_ctx) : idx(idx) {
2828+
const int tensor_idx = gguf_find_tensor(gguf_ctx, name);
2829+
offs = gguf_get_data_offset(gguf_ctx) + gguf_get_tensor_offset(gguf_ctx, tensor_idx);
2830+
}
2831+
};
2832+
std::unordered_map<std::string, struct llama_tensor_offset> tensors_offs; // unified tensor data offset across files
28332833

28342834
std::unordered_map<std::string, struct llama_model_kv_override> kv_overrides;
28352835

@@ -2884,7 +2884,7 @@ struct llama_model_loader {
28842884
}
28852885
get_key(llm_kv(LLM_KV_SPLIT_TENSORS_COUNT), n_tensors);
28862886

2887-
char split_prefix[4096] = {0};
2887+
char split_prefix[PATH_MAX] = {0};
28882888
if (!llama_split_prefix(split_prefix, fname.c_str(), fname.size(), idx, n_split)) {
28892889
throw std::runtime_error(format("invalid split file: %s", fname.c_str()));
28902890
}

0 commit comments

Comments
 (0)