Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/llama.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ extern "C" {
// Get a string describing the model type
LLAMA_API int32_t llama_model_desc(const struct llama_model * model, char * buf, size_t buf_size);

// Get the model file type (quantization) as a string, e.g. "Q8_0" or "Q4_K - Medium"
// Returns nullptr if the model is invalid or the file type is unknown
// The returned pointer is valid as long as the model is not freed
LLAMA_API const char * llama_model_ftype_name(const struct llama_model * model);

// Returns the total size of all the tensors in the model in bytes
LLAMA_API uint64_t llama_model_size(const struct llama_model * model);

Expand Down
16 changes: 16 additions & 0 deletions src/llama-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ struct llama_model::impl {

std::string desc_str;

std::string ftype_str;
Comment thread
angt marked this conversation as resolved.
Outdated

// model memory mapped files
llama_mmaps mappings;

Expand Down Expand Up @@ -1200,6 +1202,8 @@ void llama_model_base::load_hparams(llama_model_loader & ml) {

pimpl->desc_str = arch_name() + " " + type_name() + " " + ml.ftype_name();

pimpl->ftype_str = ml.ftype_name();

if (hparams.f_max_alibi_bias > 0.0f) {
hparams.use_alibi = true;
}
Expand Down Expand Up @@ -1646,6 +1650,10 @@ std::string llama_model::desc() const {
return pimpl->desc_str;
}

const std::string & llama_model::ftype_name() const {
return pimpl->ftype_str;
}

size_t llama_model::size() const {
return pimpl->n_bytes;
}
Expand Down Expand Up @@ -2616,6 +2624,14 @@ int32_t llama_model_desc(const llama_model * model, char * buf, size_t buf_size)
return snprintf(buf, buf_size, "%s", model->desc().c_str());
}

const char * llama_model_ftype_name(const llama_model * model) {
if (!model) {
return nullptr;
}
const auto & ftype = model->ftype_name();
return ftype.empty() ? nullptr : ftype.c_str();
}

Comment thread
angt marked this conversation as resolved.
uint64_t llama_model_size(const llama_model * model) {
return model->size();
}
Expand Down
2 changes: 2 additions & 0 deletions src/llama-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ struct llama_model {

std::string desc() const;

const std::string & ftype_name() const;

size_t size() const; // file size
size_t n_tensors() const;
size_t n_devices() const;
Expand Down
3 changes: 3 additions & 0 deletions tools/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ int llama_cli(int argc, char ** argv) {
console::log("%s\n", LLAMA_ASCII_LOGO);
console::log("build : %s\n", inf.build_info.c_str());
console::log("model : %s\n", inf.model_name.c_str());
if (!inf.model_ftype.empty()) {
console::log("ftype : %s\n", inf.model_ftype.c_str());
}
console::log("modalities : %s\n", modalities.c_str());
if (!params.system_prompt.empty()) {
console::log("using custom system prompt\n");
Expand Down
4 changes: 4 additions & 0 deletions tools/server/server-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,8 @@ server_context_meta server_context::get_meta() const {
auto bos_token_str = bos_id != LLAMA_TOKEN_NULL ? common_token_to_piece(impl->ctx_tgt, bos_id, true) : "";
auto eos_token_str = eos_id != LLAMA_TOKEN_NULL ? common_token_to_piece(impl->ctx_tgt, eos_id, true) : "";

const char * ftype_name = llama_model_ftype_name(impl->model_tgt);

return server_context_meta {
/* build_info */ std::string(llama_build_info()),
/* model_name */ impl->model_name,
Expand Down Expand Up @@ -4023,6 +4025,7 @@ server_context_meta server_context::get_meta() const {
/* model_n_embd_inp */ llama_model_n_embd(impl->model_tgt),
/* model_n_params */ llama_model_n_params(impl->model_tgt),
/* model_size */ llama_model_size(impl->model_tgt),
/* model_ftype */ ftype_name ? std::string(ftype_name) : std::string(),
};
}

Expand Down Expand Up @@ -5118,6 +5121,7 @@ json server_routes::get_model_info() const {
{"n_embd", meta->model_n_embd_inp},
{"n_params", meta->model_n_params},
{"size", meta->model_size},
{"ftype", meta->model_ftype},
}},
};
}
Expand Down
1 change: 1 addition & 0 deletions tools/server/server-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct server_context_meta {
int32_t model_n_embd_inp;
uint64_t model_n_params;
uint64_t model_size;
std::string model_ftype;
};

enum server_state {
Expand Down
Loading