Skip to content

Commit 1a1953b

Browse files
committed
Add Qwen2.5
1 parent e422fff commit 1a1953b

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

examples/LLMs/readme.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,114 @@ wikitext perplexity 44195.69140625
590590

591591
</details>
592592

593+
### :rocket: Qwen/Qwen2.5-7B
594+
595+
The Qwen2.5-7b model has 28 heads with ``num_key_value_heads=4``. This limits the pruning ratio to be [1/7, 2/7, 3/7, 4/7, 5/7, 6/7] if you want to save and load the pruned model using hugingface transformers, since it HF only supports the same in_features and out_features for the ``q_proj`` and ``o_proj``.
596+
597+
```bash
598+
# 3/7 ~ 0.428571428, this script will craft a 2B model
599+
python prune_llm.py --model Qwen/Qwen2.5-7B --pruning_ratio 0.428571428 --max_seq_len 4096
600+
```
601+
602+
<details>
603+
<summary>Output:</summary>
604+
605+
```
606+
----------------- Before Pruning -----------------
607+
Qwen2ForCausalLM(
608+
(model): Qwen2Model(
609+
(embed_tokens): Embedding(152064, 3584)
610+
(layers): ModuleList(
611+
(0-27): 28 x Qwen2DecoderLayer(
612+
(self_attn): Qwen2SdpaAttention(
613+
(q_proj): Linear(in_features=3584, out_features=3584, bias=True)
614+
(k_proj): Linear(in_features=3584, out_features=512, bias=True)
615+
(v_proj): Linear(in_features=3584, out_features=512, bias=True)
616+
(o_proj): Linear(in_features=3584, out_features=3584, bias=False)
617+
(rotary_emb): Qwen2RotaryEmbedding()
618+
)
619+
(mlp): Qwen2MLP(
620+
(gate_proj): Linear(in_features=3584, out_features=18944, bias=False)
621+
(up_proj): Linear(in_features=3584, out_features=18944, bias=False)
622+
(down_proj): Linear(in_features=18944, out_features=3584, bias=False)
623+
(act_fn): SiLU()
624+
)
625+
(input_layernorm): Qwen2RMSNorm((3584,), eps=1e-06)
626+
(post_attention_layernorm): Qwen2RMSNorm((3584,), eps=1e-06)
627+
)
628+
)
629+
(norm): Qwen2RMSNorm((3584,), eps=1e-06)
630+
(rotary_emb): Qwen2RotaryEmbedding()
631+
)
632+
(lm_head): Linear(in_features=3584, out_features=152064, bias=False)
633+
)
634+
----------------- After Pruning -----------------
635+
Qwen2ForCausalLM(
636+
(model): Qwen2Model(
637+
(embed_tokens): Embedding(152064, 2048)
638+
(layers): ModuleList(
639+
(0-27): 28 x Qwen2DecoderLayer(
640+
(self_attn): Qwen2SdpaAttention(
641+
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
642+
(k_proj): Linear(in_features=2048, out_features=512, bias=True)
643+
(v_proj): Linear(in_features=2048, out_features=512, bias=True)
644+
(o_proj): Linear(in_features=2048, out_features=2048, bias=False)
645+
(rotary_emb): Qwen2RotaryEmbedding()
646+
)
647+
(mlp): Qwen2MLP(
648+
(gate_proj): Linear(in_features=2048, out_features=10824, bias=False)
649+
(up_proj): Linear(in_features=2048, out_features=10824, bias=False)
650+
(down_proj): Linear(in_features=10824, out_features=2048, bias=False)
651+
(act_fn): SiLU()
652+
)
653+
(input_layernorm): Qwen2RMSNorm((2048,), eps=1e-06)
654+
(post_attention_layernorm): Qwen2RMSNorm((2048,), eps=1e-06)
655+
)
656+
)
657+
(norm): Qwen2RMSNorm((2048,), eps=1e-06)
658+
(rotary_emb): Qwen2RotaryEmbedding()
659+
)
660+
(lm_head): Linear(in_features=2048, out_features=152064, bias=False)
661+
)
662+
Qwen2Config {
663+
"_attn_implementation_autoset": true,
664+
"_name_or_path": "Qwen/Qwen2.5-7B",
665+
"architectures": [
666+
"Qwen2ForCausalLM"
667+
],
668+
"attention_dropout": 0.0,
669+
"bos_token_id": 151643,
670+
"eos_token_id": 151643,
671+
"hidden_act": "silu",
672+
"hidden_size": 2048,
673+
"initializer_range": 0.02,
674+
"intermediate_size": 10824,
675+
"max_position_embeddings": 131072,
676+
"max_window_layers": 28,
677+
"model_type": "qwen2",
678+
"num_attention_heads": 16,
679+
"num_hidden_layers": 28,
680+
"num_key_value_heads": 4,
681+
"rms_norm_eps": 1e-06,
682+
"rope_scaling": null,
683+
"rope_theta": 1000000.0,
684+
"sliding_window": null,
685+
"tie_word_embeddings": false,
686+
"torch_dtype": "float16",
687+
"transformers_version": "4.46.2",
688+
"use_cache": true,
689+
"use_mrope": false,
690+
"use_sliding_window": false,
691+
"vocab_size": 152064
692+
}
693+
694+
num_params 2778732544
695+
evaluating on wikitext2
696+
Token indices sequence length is longer than the specified maximum sequence length for this model (2541000 > 131072). Running this sequence through the model will result in indexing errors
697+
nsamples 73
698+
sample 0
699+
sample 50
700+
wikitext perplexity 100281.03125
701+
```
702+
703+
</details>

0 commit comments

Comments
 (0)