Skip to content

Fix conversion for models inherit from LlamaModel calling super().modify_tensors() - #19064

Merged
CISC merged 6 commits into
ggml-org:masterfrom
bartowski1182:master
Jan 25, 2026
Merged

CISC merged 6 commits into
ggml-org:masterfrom
bartowski1182:master

Conversation

@bartowski1182

@bartowski1182 bartowski1182 commented Jan 24, 2026 •

Copy link
Copy Markdown
Contributor

After #18866 modify_tensors was altered to call the super function

Previously, Afmoe and CogVLM both returned the tensors directly, bypassing the super().modify_tensors() function

LlamaModel causes undo_permute to be set to True, which breaks the model by applying the Q/K permutation when the super function is called, as well as other potential side effects

This change replaces super() with ModelBase in order to bypass inheritance

@bartowski1182

Copy link
Copy Markdown
Contributor Author

Get another issue with CogVLM presumably also because of the change

KeyError: "could not find any of: ['n_kv_heads', 'num_key_value_heads']"

Can't figure out what it should be..

@am17an

am17an commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

I think the problem is with models with multiple inheritance (e.g. CogVLM inherits from LlamaModel). So I think instead of yield from super(), it should be yield from ModelBase.modify_tensors()

@bartowski1182

Copy link
Copy Markdown
Contributor Author

@am17an Currently there are other models that inherent from LlamaModel (Mistral, SmolLM3, Apertus)

Mistral currently includes the same undo_permute = False

Are you suggesting no models should inherit from LlamaModel or that Afmoe specifically should not have?

Just want to be clear on what's the "best" solution at this time

@am17an

am17an commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

No I mean currently we're calling the immediate super class's modify_tensors, I was suggesting that we call the ModelBase's modify_tensors to bypass all inheritance

@bartowski1182

Copy link
Copy Markdown
Contributor Author

Oh I understand what you're saying, that was clear in your original comment too I just blanked on understanding it (I'll blame it on being up at 1am)

Yes that seems reasonable! Avoid any side effects from Llama for models that weren't originally calling it

@am17an

am17an commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

@CISC what do you think?

@bartowski1182

Copy link
Copy Markdown
Contributor Author

For the record I tested your proposed fix and it seems to work, PPL is normal again

@CISC

CISC commented Jan 24, 2026

Copy link
Copy Markdown
Member

I think the problem is with models with multiple inheritance (e.g. CogVLM inherits from LlamaModel). So I think instead of yield from super(), it should be yield from ModelBase.modify_tensors()

Yes, if the model always returned directly before it should yield from base.

@am17an

am17an commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

So, s/yield from super()/yield from ModelBase/g?

@CISC

CISC commented Jan 24, 2026

Copy link
Copy Markdown
Member

So, s/yield from super()/yield from ModelBase/g?

Yes, in the following models:

  • AfmoeModel
  • CogVLMModel
  • GraniteHybridModel
  • NemotronHModel (the final super() is ok)

@bartowski1182

Copy link
Copy Markdown
Contributor Author

@am17an do you want to make the change in a new PR or should I update this one

@am17an

am17an commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

@bartowski1182 you can update this PR. Thank you for fixing!

@bartowski1182 bartowski1182 changed the title Fix conversion for models that needed undo_permute = False but never declared it Fix conversion for models inherit from LlamaModel calling super().modify_tensors() Jan 24, 2026
@bartowski1182

Copy link
Copy Markdown
Contributor Author

@am17an updated

Comment thread convert_hf_to_gguf.py Resolved
Comment thread convert_hf_to_gguf.py Resolved
Comment thread convert_hf_to_gguf.py Resolved
bartowski1182 and others added 3 commits January 24, 2026 19:27
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
@bartowski1182

Copy link
Copy Markdown
Contributor Author

Merged your fixes in the laziest way possible, sorry about that lol

@CISC

CISC commented Jan 25, 2026

Copy link
Copy Markdown
Member

Merged your fixes in the laziest way possible, sorry about that lol

No worries. :)

@CISC
CISC merged commit 9981c30 into ggml-org:master Jan 25, 2026
6 checks passed
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
…dify_tensors (ggml-org#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
…dify_tensors (ggml-org#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
…dify_tensors (ggml-org#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
MrLordCat referenced this pull request in MrLordCat/llama.cpp-rdna-lab Jul 16, 2026
…dify_tensors (#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
…dify_tensors (ggml-org#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
…dify_tensors (ggml-org#19064)

* Add undo_permute = False where needed

* Replace super().modify_tensors with ModelBase

* Add one more ModelBase.modify_tensors

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

* Update convert_hf_to_gguf.py

Co-authored-by: Sigbjørn Skjæret <[email protected]>

---------

Co-authored-by: Sigbjørn Skjæret <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python python script changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants