model: support Longcat-Flash (need testing) - #19182
Conversation
|
Huh, interesting. Likely need to extend |
Hello, I'm also paying attention to the adaptation of the loncat-flash model. Suppose If we bypass the requirement of |
|
@hebangwen Not sure I follow, but I think simply setting the coefficient like this should work: # normal expert
alpha_i = 1.0f
beta_i = 0.0f
# zero-compute expert
alpha_i = 0.0f
beta_i = 1.0fAnd the matrix C is just the MoE input (i.e. |
|
It can be simpler to explain the
As @ggerganov suggested, I imagine the In the example above, computation for However, one issue is that the router weight However, yet another problem, even when the idea above is implemented: The output dim of For the calculation of the |
|
Seems like quite more works than I initially thought, so I think we should re-consider if this worth implementing. Currently, only longcat-flash family using this technique, so it can be quite risky to too many infrastructure to support it. |
|
Yes, seems more complicated. Let's reconsider later in case this architecture shows any promise. |
Full llama.cpp implementation of the LongCat-Flash-Lite architecture (meituan-longcat/LongCat-Flash-Lite), enabling GGUF conversion and inference for this 68.5B MoE model (3-4.5B activated parameters). Key architecture features implemented: - N-gram embedding: 12 polynomial rolling hash tables that augment the base token embedding (combined as base_embed/13 + 12 hash embeds) - Multi-head Latent Attention (MLA) with KV compression and LoRA scaling (sqrt(2) for Q, sqrt(6) for KV) - Mixture of Experts with 256 real + 128 identity experts (top-k=12), identity experts implemented via residual masking - Double-block layout: 14 HF layers map to 28 llama.cpp blocks, with MoE shortcut connections from even to odd blocks - YaRN RoPE (factor=10, freq_base=5M, mscale_all_dim=1) Achieves ~57 tok/s at Q4_K_M on NVIDIA GB10. Prior art and acknowledgments: - ngxson's llama.cpp PRs ggml-org#19167 (N-gram support) and ggml-org#19182 (LongCat-Flash base), both abandoned due to complexity - kernelpool's (Tarjei Mandt) mlx-lm PR ggml-org#819, merged Jan 2026, used as architectural reference - meituan-longcat for the original model (MIT license)
1fa084e to
e98e88e
Compare
|
This PR should be ready for testing now. I tested with a very small (8B params) sub-model extracted from the original one. Appreciate if someone can test with the bigger model. |
|
Oh, how I’d love to be able to test it :x |
|
A bit more digging, seems like CUDA doesn't support duplicated expert indexes, that need to be fixed first... Testing to see if other backend has the same problem: #26657 |
|
I've uploaded an IQ1_S (phew, that PPL and KLD look horrible) and was able to get it to infer with this patch (warning, AI slop ahead): cuda-mmid-duplicate-expert-ids.patch The repo includes the imatrix I made from the Q8_0, and the BF16 logits and the wiki.test.raw for others to run PPL / KLD if they want. |
|
Ok some conversion fixes and NMSE is reduced from 6.9e-05 down to 6.9e-08, perfect numerical match now @AesSedai appreciate if you can re-convert the GGUF, thanks :-) |
|
@ngxson the imatrix crashes with this cuda error: |
|
I updated the quant in the repo a few days ago, but it still needed the patch I posted earlier. |
|
@AesSedai thanks! I will go back to this a bit later this month it's currently blocked by the issue of duplicated experts on CUDA, can be merged once that's fixed. in any cases, GGUF is fine and won't need to be reconverted |
Overview
Support https://huggingface.co/meituan-longcat/LongCat-Flash-Chat
Next: impl the ngram model: #19167
LongCat-Flash-Chat uses MLA + "zero-computing experts" (see below). I tested with a slice of the bigger model (generated via this script, which extracts 2 layers and 64 experts from the original weight)
Additional information
This model is different from other MoE models, it use something called "zero-computing experts" (ref: link to paper)
Ideally #26631 is needed to make it correctly skip computation
The current impl support this by (provided that model has N+M expert, with N=real exp and M=zero exp):
Old comment
To illustrate what's the problem, I will take an example of how a normal MoE FFN work:
ggml_mul_mat_idThis means we spend the the same amount of computation for each token, proportionally to
n_expert_usedHowever, with longcat-flash:
n_zero_expertswill go through FFN; for the rest, they skip the FFN altogetherApart from the weird MoE, the model has double block architecture, meaning there are 2 attentions and 2 FFNs per layer. Upon converting to GGUF, we convert it to a model of
2 * n_layer, which make the implementation much easier.Requirements