Skip to content
Open
Changes from all commits
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
11 changes: 8 additions & 3 deletions src/llama-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
// llama_context
//

class llama_exception : public std::runtime_error {
using std::runtime_error::runtime_error;
};
Comment on lines +25 to +27

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can update to a struct or move to src\llama-impl.h if preferred


static llm_graph_type ctx_type_to_graph_type(llama_context_type ctx_type) {
switch (ctx_type) {
case LLAMA_CONTEXT_TYPE_DEFAULT: return LLM_GRAPH_TYPE_DEFAULT;
Expand Down Expand Up @@ -93,8 +97,7 @@ llama_context::llama_context(
// TODO: more generic
if (model.arch == LLM_ARCH_GEMMA4_ASSISTANT) {
if (params.ctx_other == nullptr) {
// TODO: change from runtime_error to llama_exception to avoid printing error message
throw std::runtime_error("Gemma4Assistant requires ctx_other to be set (this warning is normal during memory fitting)");
throw llama_exception("Gemma4Assistant requires ctx_other to be set (this warning is normal during memory fitting)");
}

cparams.ctx_other = params.ctx_other;
Expand All @@ -103,7 +106,7 @@ llama_context::llama_context(
if (model.arch == LLM_ARCH_EAGLE3) {
if (model.tok_embd == nullptr || model.output == nullptr) {
if (params.ctx_other == nullptr) {
throw std::runtime_error("EAGLE3 requires ctx_other to be set (this warning is normal during memory fitting)");
throw llama_exception("EAGLE3 requires ctx_other to be set (this warning is normal during memory fitting)");
}
cparams.ctx_other = params.ctx_other;
}
Expand Down Expand Up @@ -3560,6 +3563,8 @@ llama_context * llama_init_from_model(
try {
auto * ctx = new llama_context(*model, params);
return ctx;
Comment on lines 3563 to 3565

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add e.g. LLAMA_LOG_INFO("%s: successfully initialized the context: %s\n", __func__); if preferred

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*LLAMA_LOG_DEBUG

} catch (const llama_exception & err) {
LLAMA_LOG_WARN("%s: failed to initialize the context: %s\n", __func__, err.what());
} catch (const std::exception & err) {
Comment on lines +3566 to 3568

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can rename err vars to e if preferred (seems the more common convention)

LLAMA_LOG_ERROR("%s: failed to initialize the context: %s\n", __func__, err.what());
}
Expand Down