Views
No views yet
llama.cpp.llama.cpp, and encountered a few obstacles along the way. Below, I share my full recipe and the workarounds I developed.| Settings | Toy 4B | Flash 284B |
|---|---|---|
| layer (block) count | 33 | 43 |
| context_length | 1048576 | 1048576 |
| embedding_length | 1024 | 4096 |
| attention.head_count | 32 | 64 |
| expert per token | 4 | 6 |
| attention.q_lora_rank | 256 | 1024 |
| expert_feed_forward_length | 512 | 2048 |
| expert_count | 64 | 256 |
| hash MoE layer count | 0 | 2 |
| sparse_attention ratio | 4 | 4 |
| heavily_compressed_attention | 128 | 128 |
| tokenizer | DeepSeek V3 | DeepSeek V3 |
1from transformers import DeepseekV4Config, DeepseekV4ForCausalLM, AutoTokenizer
2
3config = DeepseekV4Config(
4 vocab_size=129280,
5 hidden_size=1024,
6 moe_intermediate_size=512,
7 num_hidden_layers=33,
8 num_attention_heads=32,
9 num_key_value_heads=1,
10 head_dim=512,
11 q_lora_rank=256,
12 n_routed_experts=64,
13 n_shared_experts=1,
14 num_experts_per_tok=4,
15 scoring_func="sqrtsoftplus",
16 norm_topk_prob=True,
17 routed_scaling_factor=1.5,
18 max_position_embeddings=1048576,
19 rope_theta=10000.0,
20 compress_rope_theta=160000.0,
21 hc_mult=4,
22 hc_sinkhorn_iters=20,
23 hc_eps=1.0e-6,
24 swiglu_limit=10.0,
25 sliding_window=128,
26 o_groups=8,
27 o_lora_rank=256,
28 index_n_heads=32,
29 index_head_dim=64,
30 index_topk=256,
31 num_nextn_predict_layers=1,
32 hidden_act="silu",
33 rms_norm_eps=1.0e-6,
34 use_cache=True,
35 bos_token_id=0,
36 eos_token_id=1,
37 tie_word_embeddings=False,
38 partial_rotary_factor=None,
39 attention_bias=False,
40 mlp_bias=False,
41 attention_dropout=0.0,
42 mlp_layer_types=["moe"] * 33
43)
44
45model = DeepseekV4ForCausalLM(config)fix_format.pyllama.cpp. They must be fixed before conversion.fix_format.py model_folder_name fixed_model_folder_namellama.cpp, MoE experts are expected to already be quantized to MXFP4. However, for a newly created model, the experts are still in FP32 or FP16 format. I had to add a few lines to make the script work with non-quantized experts.llama.cpp folder and run:1python convert_hf_to_gguf.py fixed_model_folder_name --outfile toymodel.gguf
2llama-quantize.exe toymodel.gguf dsv4-4B-toy_Q8_MXFP4.gguf 38