mlabonne commited on
Commit
db1d42d
1 Parent(s): 5117204

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -9
README.md CHANGED
@@ -1,24 +1,43 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
3
  tags:
4
  - moe
5
- - merge
6
- - mergekit
7
- - lazymergekit
8
  - cognitivecomputations/dolphin-2_6-phi-2
9
  - lxuechen/phi-2-dpo
 
 
10
  ---
11
 
12
  ![](https://i.imgur.com/UOb2fvh.jpg)
13
 
14
- # phixtral-2x2.8
15
 
16
- phixtral-2x2.8 is a Mixure of Experts (MoE) made with the following models using a custom version of mergekit:
17
- * [cognitivecomputations/dolphin-2_6-phi-2](https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2)
18
- * [lxuechen/phi-2-dpo](https://huggingface.co/lxuechen/phi-2-dpo)
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  ## 🧩 Configuration
21
 
 
 
22
  ```yaml
23
  base_model: cognitivecomputations/dolphin-2_6-phi-2
24
  gate_mode: cheap_embed
@@ -27,8 +46,67 @@ experts:
27
  positive_prompts: [""]
28
  - source_model: lxuechen/phi-2-dpo
29
  positive_prompts: [""]
 
 
 
 
30
  ```
31
 
32
  ## 💻 Usage
33
 
34
- This architecture is not compatible with the transformers library. I'm working on hacking something to run it. Contact me if you're interested!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ inference: false
3
+ license: mit
4
+ license_link: https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE
5
+ language:
6
+ - en
7
+ pipeline_tag: text-generation
8
  tags:
9
  - moe
10
+ - nlp
11
+ - code
 
12
  - cognitivecomputations/dolphin-2_6-phi-2
13
  - lxuechen/phi-2-dpo
14
+ - Yhyu13/phi-2-sft-dpo-gpt4_en-ep1
15
+ - mrm8488/phi-2-coder
16
  ---
17
 
18
  ![](https://i.imgur.com/UOb2fvh.jpg)
19
 
20
+ # phixtral-4x2_8
21
 
22
+ phixtral-4x2_8 is the first Mixure of Experts (MoE) made with four [microsoft/phi-2](https://huggingface.co/microsoft/phi-2) models, inspired by the [mistralai/Mixtral-8x7B-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) architecture. It performs better than each individual expert.
23
+
24
+ ## 🏆 Evaluation
25
+
26
+ | Model |AGIEval|GPT4All|TruthfulQA|Bigbench|Average|
27
+ |----------------------------------------------------------------|------:|------:|---------:|-------:|------:|
28
+ |[**phixtral-4x2_8**](https://huggingface.co/mlabonne/phixtral-2x2_8)| TBD| TBD| TBD| TBD| TBD|
29
+ |[dolphin-2_6-phi-2](https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2)| 33.12| 69.85| 47.39| 37.2| 46.89|
30
+ |[phi-2-dpo](https://huggingface.co/lxuechen/phi-2-dpo)| 30.39| 71.68| 50.75| 34.9| 46.93|
31
+ |[phi-2-sft-dpo-gpt4_en-ep1](https://huggingface.co/Yhyu13/phi-2-sft-dpo-gpt4_en-ep1)| 30.61| 71.13| 48.74| 35.23| 46.43|
32
+ |[phi-2-coder](https://huggingface.co/mrm8488/phi-2-coder)| TBD| TBD| TBD| TBD| TBD|
33
+ |[phi-2](https://huggingface.co/microsoft/phi-2)| 27.98| 70.8| 44.43| 35.21| 44.61|
34
+
35
+ Check [YALL - Yet Another LLM Leaderboard](https://huggingface.co/spaces/mlabonne/Yet_Another_LLM_Leaderboard) to compare it with other models.
36
 
37
  ## 🧩 Configuration
38
 
39
+ The model has been made with a custom version of the [mergekit](https://github.com/cg123/mergekit) library (mixtral branch) and the following configuration:
40
+
41
  ```yaml
42
  base_model: cognitivecomputations/dolphin-2_6-phi-2
43
  gate_mode: cheap_embed
 
46
  positive_prompts: [""]
47
  - source_model: lxuechen/phi-2-dpo
48
  positive_prompts: [""]
49
+ - source_model: Yhyu13/phi-2-sft-dpo-gpt4_en-ep1
50
+ positive_prompts: [""]
51
+ - source_model: mrm8488/phi-2-coder
52
+ positive_prompts: [""]
53
  ```
54
 
55
  ## 💻 Usage
56
 
57
+ Here's a [Colab notebook](https://colab.research.google.com/drive/1k6C_oJfEKUq0mtuWKisvoeMHxTcIxWRa?usp=sharing) to run Phixtral in 4-bit precision on a free T4 GPU.
58
+
59
+ ```python
60
+ !pip install -q --upgrade transformers einops accelerate bitsandbytes
61
+
62
+ import torch
63
+ from transformers import AutoModelForCausalLM, AutoTokenizer
64
+
65
+ model_name = "phixtral-4x2_8"
66
+ instruction = '''
67
+ def print_prime(n):
68
+ """
69
+ Print all primes between 1 and n
70
+ """
71
+ '''
72
+
73
+ torch.set_default_device("cuda")
74
+
75
+ # Load the model and tokenizer
76
+ model = AutoModelForCausalLM.from_pretrained(
77
+ f"mlabonne/{model_name}",
78
+ torch_dtype="auto",
79
+ load_in_4bit=True,
80
+ trust_remote_code=True
81
+ )
82
+ tokenizer = AutoTokenizer.from_pretrained(
83
+ f"mlabonne/{model_name}",
84
+ trust_remote_code=True
85
+ )
86
+
87
+ # Tokenize the input string
88
+ inputs = tokenizer(
89
+ instruction,
90
+ return_tensors="pt",
91
+ return_attention_mask=False
92
+ )
93
+
94
+ # Generate text using the model
95
+ outputs = model.generate(**inputs, max_length=200)
96
+
97
+ # Decode and print the output
98
+ text = tokenizer.batch_decode(outputs)[0]
99
+ print(text)
100
+ ```
101
+
102
+ Inspired by [mistralai/Mixtral-8x7B-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1), you can specify the `num_experts_per_tok` and `num_local_experts` in the [`config.json`](https://huggingface.co/mlabonne/phixtral-4x2_8/blob/main/config.json#L26-L27) file (2 and 4 by default). This configuration is automatically loaded in `configuration.py`.
103
+
104
+ [vince62s](https://huggingface.co/vince62s) implemented the MoE inference code in the `modeling_phi.py` file. In particular, see the [MoE class](https://huggingface.co/mlabonne/phixtral-4x2_8/blob/main/modeling_phi.py#L293-L317).
105
+
106
+ ## 🤝 Acknowledgments
107
+
108
+ A special thanks to [vince62s](https://huggingface.co/vince62s) for the inference code and the dynamic configuration of the number of experts. He was very patient and helped me to debug everything.
109
+
110
+ Thanks to [Charles Goddard](https://github.com/cg123) for the [mergekit](https://github.com/cg123/mergekit) library and the implementation of the [MoE for clowns](https://goddard.blog/posts/clown-moe/).
111
+
112
+ Thanks to [ehartford](https://huggingface.co/ehartford), [lxuechen](https://huggingface.co/lxuechen), [Yhyu13](https://huggingface.co/Yhyu13), and [mrm8488](https://huggingface.co/mrm8488) for their fine-tuned phi-2 models.