Skip to content

cohere: support untied head weight - #179

Open
LasseLegarth wants to merge 1 commit into
handy-computer:mainfrom
LasseLegarth:fix-cohere-untied-head
Open

LasseLegarth wants to merge 1 commit into
handy-computer:mainfrom
LasseLegarth:fix-cohere-untied-head

Conversation

@LasseLegarth

Copy link
Copy Markdown

Summary

Some Cohere fine-tunes (e.g. syvai/hviske-v5*) train the LM head
separately from the token embedding. The current code assumes they are
always tied, producing wrong logits for these checkpoints.

convert-cohere.py now detects an untied head and writes a dedicated
head.weight tensor. The runtime prefers it over the tied embedding
when present.

Scope

  • scripts/convert-cohere.py
  • src/arch/cohere/decoder.cpp, weights.cpp, weights.h

AI Assistance

Claude assisted with parts of the implementation. I reviewed and tested
the changes myself.

Validation

Converted and ran syvai/hviske-v5-tiny (untied head) against Danish
speech. Before/after:

Tied (before) Untied (after)
"Den var blô" "den var blå"
"Totest du lige hvordan det har seruet" "Så tester du lige hvordan det her ser ud"

I'm running Handy daily with these changes and hviske-v5-tiny as my
dictation model. Works well for Danish input.

Also accepts float32 source tensors and rebuilds the mel filterbank
via librosa when the checkpoint omits the preprocessor buffer.

Fine-tunes such as syvai/hviske-v5* train the LM head separately from
the token embedding. Detect this in convert-cohere.py and write a
dedicated head.weight tensor; at runtime, prefer it over the tied
embedding when present.

Also accept float32 source tensors and rebuild the mel filterbank from
librosa when the checkpoint omits the preprocessor buffer.
@cjpais

cjpais commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting this. I will take a look soon

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants