Add arch support for cohere2-MoE - #24260
Conversation
|
@CISC FWIW I feel this implementation looks much cleaner: csabakecskemeti@7b08a0e |
Ah, wasn't aware there already was a MoE. The conversion doesn't look completely compatible though. A few more tweaks here should bring both in line I think. |
Well shucks, I didn't see any other version had been done before. I'll still try to get this cleaned up ASAP |
There was a problem hiding this comment.
Ha, I guess someone beat me to the punch ^^, was working on my own impl of this on arki05/llama.cpp-fork.
Instead of opening a rival pr; i assumed i should just diff our impls and suggest fixes/learn from yours. during that i noticed some discrepancies between our implementations; lots of tiny different choices , but i think these following few differences are worth noting on.
I'm happy to help fixing / collaborating on this pr; looking forward to using this model ^^
Appreciate all the fixes, thank you! I've put them all in place. Would be great to get another test confirmation. HF repo Q4K/NVFP4 new versions with new arch name just finished up. |
…not required, fallback to token_embd.weight
|
The model has officially been released now: https://huggingface.co/CohereLabs/North-Mini-Code-1.0 |
|
Just wanted to add here that this works great with the Vulkan backend. prompt processing is slower than with other models of the ~same size but still fast enough. |
|
Pushed one more change. Cohere needed |
|
I am getting some errors here while trying to use the llama-b9626 with the https://huggingface.co/DevQuasar/CohereLabs.command-a-plus-05-2026-bf16-GGUF 0.00.619.476 I llama_model_loader: - type f32: 65 tensors |
It helps to read the model card:
|
|
This is the problem: |
But details of b9626 literaly says: And the model at https://huggingface.co/DevQuasar/CohereLabs.command-a-plus-05-2026-bf16-GGUF is a "cohere2-MoE". So the change to "cohere2moe" was a typo or what? Because it doesn't seem to me logycal to change the naming inside the llama to something that would not recognize the official model itsel.f.. |
That model was not created using this PR, thus it is not compatible. |
|
That random GGUF is not exactly “the official model”. The official model uses an underscore not a hyphen: https://huggingface.co/CohereLabs/command-a-plus-05-2026-bf16/blob/main/config.json#L75 It’s just an unofficial GGUF that says it requires a vibecoded branch. Someone will hopefully push up better GGUFs soon. |
I believe the valid solution to this problem is to comment on this model that it should be regenerated |
The |
|
I actually do understand that, and thought about expanding my comment, but if we’re nitpicking, then I was just pointing out that the original creators did not even use a hyphen for anything, anywhere. The closest they came was an underscore. |
Nitpicking is my favorite hobby. :) |
|
@CISC something is actually off with this, we're missing a change to llama-vocab.cpp to recognize the new |
|
That said, the |
Interesting, @pwilkin want to have a look? :) |
|
@CISC yeah I'll look at it. |
|
I've been trying to reproduce this issue, but I always get correct output and code with However: with Here @bartowski1182 I think the model is probably OK and the issue may be the template in the gguf, because all the ones I tried were all crashing for me with ``--special` because of the end of turn token.. But yours is not, but just giving bad answers, so what is the chat template? |
|
I was using just the default template, didn't touch anything Also tried the suggested settings and prompt and still got the odd behaviour, though not every time it was consistent enough to be concerning |
|
Cohere seems to ship 2 templates, one in I also created a patched version that should (fingers crossed) support the default reasoning settings from llama.cpp. Not sure which you were using @bartowski1182 but main seems to default to using the outdated tokenizer_config.json one. |
|
Dedicated parser is on its way. |
|
@pwilkin would that fix the existing one or do I still need to remake with the one in the Jinja file? |
|
#24615 <= it's up Nah, the existing chat template is beyond repair, I think it's some early default or something - I got the correct one by clicking "chat template" on their model main page (think that redirects to |
I would recommend removing the ones in |
I've submitted PRs on affected models to Cohere Labs. Edit: Funnily the FP8 version of Command A+ did not have these. |
|
I have published a few Command A Plus GGUFs here: https://huggingface.co/coder543/command-a-plus-05-2026-gguf I cleared out the tokenizer_config templates prior to conversion so the chat_template.jinja would be used, which should be up to date. (But I still notice a couple of differences against the Cohere2MoE.jinja template, even apart from the “Your name is North Mini Code.” which wouldn’t be correct for Command) Apart from being text only, the Command A Plus model seems to be working fine in some limited testing I did. |
* Add arch support for cohere2-MoE * Removed redundant gating_func checks * Changed ffn lookup to prefer prefix_dense_intermediate_size * Renamed arch to cohere2moe * Removed redundant lmhead check and chat template changes * Removed lm_head.weight check from modify tensors, load output tensor not required, fallback to token_embd.weight * Changed to (routed+shared)*0.5 for shared expert combined avg * fixed sliding_window_pattern issue and pattern * Fixed transformers crash 'first_k_dense_replace' error * Remove comment * Removed cohere2-moe as a tokenizer type and kept as tiny_aya. Renamed North-Mini-Code-1.0. * Fixed MTP fail, changed to use iSWA * Fixed remaining todos: cohere2moe renamed, changed swa parsing to use get_key_or_arr, removed extra get_arr use * Force metadata usage Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove Cohere2 checkpoint comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove MTP comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Regenerate cohere2moe tokenizer hash * Add cohere2moe to Llama Model Saver supported list * Check for zerobios tensors and add support for Command to use LayerNorm * Map expert_selection_fn to sigmoid in base.py instead of command.py * use bools for foundnorm/foundnormrms Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
* Add arch support for cohere2-MoE * Removed redundant gating_func checks * Changed ffn lookup to prefer prefix_dense_intermediate_size * Renamed arch to cohere2moe * Removed redundant lmhead check and chat template changes * Removed lm_head.weight check from modify tensors, load output tensor not required, fallback to token_embd.weight * Changed to (routed+shared)*0.5 for shared expert combined avg * fixed sliding_window_pattern issue and pattern * Fixed transformers crash 'first_k_dense_replace' error * Remove comment * Removed cohere2-moe as a tokenizer type and kept as tiny_aya. Renamed North-Mini-Code-1.0. * Fixed MTP fail, changed to use iSWA * Fixed remaining todos: cohere2moe renamed, changed swa parsing to use get_key_or_arr, removed extra get_arr use * Force metadata usage Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove Cohere2 checkpoint comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove MTP comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Regenerate cohere2moe tokenizer hash * Add cohere2moe to Llama Model Saver supported list * Check for zerobios tensors and add support for Command to use LayerNorm * Map expert_selection_fn to sigmoid in base.py instead of command.py * use bools for foundnorm/foundnormrms Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Status update on this @CISC : I think I'm getting much closer. Amazing learning experience on learning more about ML even if this never works out (AdamW, backwards, etc) and working on it every day! Annoyingly each full training run is about ~16 hours in Bf16. The idea with the tool is to train any gguf model and get MTP tensors out of it. Last run got: According to AI review, I was still training tokens in the wrong order: d2 was not training on d1, d3 not on d2, etc, recursively that way. So n1 acceptance was only 32.4% which gave no speedup. Latest training run is training d2 on d1's prediction, d3 on d2's, d4 on d3's. Greedy on the full 256k vocab, LR 1e-04, d1 weighted extra high, and added a gate to only accept >95%. My whole (long) training params for the latest attempt below. It is resumable and can warmstart anytime I change anything. Details |
* Add arch support for cohere2-MoE * Removed redundant gating_func checks * Changed ffn lookup to prefer prefix_dense_intermediate_size * Renamed arch to cohere2moe * Removed redundant lmhead check and chat template changes * Removed lm_head.weight check from modify tensors, load output tensor not required, fallback to token_embd.weight * Changed to (routed+shared)*0.5 for shared expert combined avg * fixed sliding_window_pattern issue and pattern * Fixed transformers crash 'first_k_dense_replace' error * Remove comment * Removed cohere2-moe as a tokenizer type and kept as tiny_aya. Renamed North-Mini-Code-1.0. * Fixed MTP fail, changed to use iSWA * Fixed remaining todos: cohere2moe renamed, changed swa parsing to use get_key_or_arr, removed extra get_arr use * Force metadata usage Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove Cohere2 checkpoint comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Remove MTP comment Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Regenerate cohere2moe tokenizer hash * Add cohere2moe to Llama Model Saver supported list * Check for zerobios tensors and add support for Command to use LayerNorm * Map expert_selection_fn to sigmoid in base.py instead of command.py * use bools for foundnorm/foundnormrms Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>

Overview
There's a new early preview of CohereLab's
North-Mini-Code-1.0MoE coding model with weights that I wanted to test and add full implementation for.So, this PR adds new arch
cohere2_moein addition to the already implementedcohere2arch.The models are not finalized, but I have converted from HF SFT into preliminary first-gen models:
This model is incredibly fast at creating code and I was surprised by what it could do, and look forwarding to testing out more.
convert_hf_to_ggufscript.Llama-quantizewill successfully convert the BF16.gguf into a quantized modelLlama-cliwill show thinking properly with llama-cli: fix not copying preserved tokens #24258cohere2.cppwhile we're hereTest-llama-arches passes:
The model is fast:
Tool calling with build in tools is working through llama-server:
Additional information
The models are currently experimental and in development, the creators are seeking community feedback to shape its future, which is the reason I have created this PR!
Requirements
Yes, used to help code fast and identify how to create the arch, then debug issues, especially with chat parser and tokenizer incompatabilities. De-slop/adjust/review/quant/convert/full testing done manually.