Skip to content

imatrix: fix division by zero#21727

Open
krampenschiesser wants to merge 1 commit intoggml-org:masterfrom
krampenschiesser:imatrix--fix-division-by-zero
Open

imatrix: fix division by zero#21727
krampenschiesser wants to merge 1 commit intoggml-org:masterfrom
krampenschiesser:imatrix--fix-division-by-zero

Conversation

@krampenschiesser
Copy link
Copy Markdown

@krampenschiesser krampenschiesser commented Apr 10, 2026

Overview

Viewing the imatrix statistics via ./llama-imatrix --in-file imatrix.gguf --show-statistics does not work in recent llama versions.
It segfaults when opening any imatrix files (unsloth, mraderbacher, local) because the context length in m_params is 0 and then hard-coded in the example.
This is a super basic fix to see the statistics again by using the hardcoded context length from the example itself when its stored as 0.

Requirements

@CISC
Copy link
Copy Markdown
Member

CISC commented Apr 10, 2026

It can be much more basic than this (while also supporting legacy imatrix.dat), essentially m_last_chunk is not used anyway when using --show-statistics, so just force params.n_ctx = 512 (hardcode it, as this is legacy default, no need for global) here:

if (!show_statistics(params)) {

@krampenschiesser
Copy link
Copy Markdown
Author

So i can completely remove the m_last_chunk calculation from the imatrix loading?

@CISC
Copy link
Copy Markdown
Member

CISC commented Apr 10, 2026

So i can completely remove the m_last_chunk calculation from the imatrix loading?

No, it's needed when not using --show-statistics, the point is you can just force the legacy default then so it won't break; a simple one-liner.

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.

2 participants