Skip to content

Commit bb0c139

Browse files
authored
llama : check LLAMA_TRACE env for extra logging (#4929)
* llama : minor fix indent * llama : check LLAMA_TRACE env for extra logging ggml-ci
1 parent 9408cfd commit bb0c139

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

llama.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,11 @@ struct llama_model_loader {
21902190
LLM_KV llm_kv = LLM_KV(LLM_ARCH_UNKNOWN);
21912191

21922192
llama_model_loader(const std::string & fname, bool use_mmap, const struct llama_model_kv_override * param_overrides_p) : file(fname.c_str(), "rb") {
2193+
int trace = 0;
2194+
if (getenv("LLAMA_TRACE")) {
2195+
trace = atoi(getenv("LLAMA_TRACE"));
2196+
}
2197+
21932198
struct gguf_init_params params = {
21942199
/*.no_alloc = */ true,
21952200
/*.ctx = */ &ctx_meta,
@@ -2242,11 +2247,10 @@ struct llama_model_loader {
22422247
type_max = type;
22432248
}
22442249

2245-
// TODO: make runtime configurable
2246-
#if 0
2247-
struct ggml_tensor * meta = ggml_get_tensor(ctx_meta, gguf_get_tensor_name(ctx_gguf, i));
2248-
LLAMA_LOG_INFO("%s: - tensor %4d: %32s %-8s [ %s ]\n", __func__, i, ggml_get_name(meta), ggml_type_name(type), llama_format_tensor_shape(meta).c_str());
2249-
#endif
2250+
if (trace > 0) {
2251+
struct ggml_tensor * meta = ggml_get_tensor(ctx_meta, gguf_get_tensor_name(ctx_gguf, i));
2252+
LLAMA_LOG_INFO("%s: - tensor %4d: %32s %-8s [ %s ]\n", __func__, i, ggml_get_name(meta), ggml_type_name(type), llama_format_tensor_shape(meta).c_str());
2253+
}
22502254
}
22512255

22522256
switch (type_max) {
@@ -6451,15 +6455,15 @@ static uint8_t llama_token_to_byte(const llama_vocab& vocab, llama_token id) {
64516455
static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) {
64526456
static const char * hex = "0123456789ABCDEF";
64536457
switch (llama_vocab_get_type(vocab)) {
6454-
case LLAMA_VOCAB_TYPE_SPM: {
6455-
const char buf[7] = { '<', '0', 'x', hex[ch >> 4], hex[ch & 15], '>', 0 };
6456-
return vocab.token_to_id.at(buf);
6457-
}
6458-
case LLAMA_VOCAB_TYPE_BPE: {
6459-
return vocab.token_to_id.at(bytes_to_unicode_bpe(ch));
6460-
}
6461-
default:
6462-
GGML_ASSERT(false);
6458+
case LLAMA_VOCAB_TYPE_SPM: {
6459+
const char buf[7] = { '<', '0', 'x', hex[ch >> 4], hex[ch & 15], '>', 0 };
6460+
return vocab.token_to_id.at(buf);
6461+
}
6462+
case LLAMA_VOCAB_TYPE_BPE: {
6463+
return vocab.token_to_id.at(bytes_to_unicode_bpe(ch));
6464+
}
6465+
default:
6466+
GGML_ASSERT(false);
64636467
}
64646468
}
64656469

0 commit comments

Comments
 (0)