Skip to content

Check if ctx or model is null before calling sampler#19101

Open
gagankonana wants to merge 2 commits intoggml-org:masterfrom
gagankonana:check-sampler-size-before-access
Open

Check if ctx or model is null before calling sampler#19101
gagankonana wants to merge 2 commits intoggml-org:masterfrom
gagankonana:check-sampler-size-before-access

Conversation

@gagankonana
Copy link

@gagankonana gagankonana commented Jan 26, 2026

Add a check in main in completion.cpp to check if ctx or model is null before calling sampler. This validates that common_init_from_params was successful
Resolves #19065

@gagankonana gagankonana changed the title check if samplers size > seq id before access Return nullptr if samplers size less than seq id Jan 26, 2026
@ggerganov
Copy link
Member

This seems to hide some other problem - it's not a valid solution

@danbev
Copy link
Member

danbev commented Jan 26, 2026

This seems to hide some other problem - it's not a valid solution

Ah yes, it looks like this is because the model is failing to load but we are calling llama_init->sampler(0) without checking the context here:

ctx = llama_init->context();
model = llama_init->model();
smpl = llama_init->sampler(0);

We should move check of the ctx before this call.

@gagankonana
Copy link
Author

Updated the PR. I followed the pattern from other files. Let me know wdyt

@gagankonana gagankonana changed the title Return nullptr if samplers size less than seq id Check if ctx or model is null before calling sampler Jan 28, 2026
@danbev
Copy link
Member

danbev commented Jan 29, 2026

Updated the PR. I followed the pattern from other files. Let me know wdyt

Thanks! This looks good to me. Can you also take a look at the EditorConfig Checker CI failure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Segmentfault When Using llama-completion For Inference

3 participants