mlabonne commited on
Commit
4e43879
1 Parent(s): f05d5a6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -9
README.md CHANGED
@@ -1,24 +1,40 @@
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
@@ -31,4 +47,59 @@ experts:
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
  ---
15
 
16
  ![](https://i.imgur.com/UOb2fvh.jpg)
17
 
18
+ # phixtral-2x2_8
19
 
20
+ phixtral-2x2_8 is the first Mixure of Experts (MoE) made with two [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.
21
+
22
+ ## 🏆 Evaluation
23
+
24
+ | Model |AGIEval|GPT4All|TruthfulQA|Bigbench|Average|
25
+ |----------------------------------------------------------------|------:|------:|---------:|-------:|------:|
26
+ |[**phixtral-2x2_8**](https://huggingface.co/mlabonne/phixtral-2x2_8)| **34.1**| **70.44**| **48.78**| **37.82**| **47.78**|
27
+ |[dolphin-2_6-phi-2](https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2)| 33.12| 69.85| 47.39| 37.2| 46.89|
28
+ |[phi-2-dpo](https://huggingface.co/lxuechen/phi-2-dpo)| 30.39| 71.68| 50.75| 34.9| 46.93|
29
+ |[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|
30
+ |[phi-2](https://huggingface.co/microsoft/phi-2)| 27.98| 70.8| 44.43| 35.21| 44.61|
31
+
32
+ Check [YALL - Yet Another LLM Leaderboard](https://huggingface.co/spaces/mlabonne/Yet_Another_LLM_Leaderboard) to compare it with other models.
33
 
34
  ## 🧩 Configuration
35
 
36
+ The model has been made with a custom version of the [mergekit](https://github.com/cg123/mergekit) library (mixtral branch) and the following configuration:
37
+
38
  ```yaml
39
  base_model: cognitivecomputations/dolphin-2_6-phi-2
40
  gate_mode: cheap_embed
 
47
 
48
  ## 💻 Usage
49
 
50
+ 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.
51
+
52
+ ```python
53
+ !pip install -q --upgrade transformers einops accelerate bitsandbytes
54
+
55
+ import torch
56
+ from transformers import AutoModelForCausalLM, AutoTokenizer
57
+
58
+ model_name = "phixtral-4x2_8"
59
+ instruction = '''
60
+ def print_prime(n):
61
+ """
62
+ Print all primes between 1 and n
63
+ """
64
+ '''
65
+
66
+ torch.set_default_device("cuda")
67
+
68
+ # Load the model and tokenizer
69
+ model = AutoModelForCausalLM.from_pretrained(
70
+ f"mlabonne/{model_name}",
71
+ torch_dtype="auto",
72
+ load_in_4bit=True,
73
+ trust_remote_code=True
74
+ )
75
+ tokenizer = AutoTokenizer.from_pretrained(
76
+ f"mlabonne/{model_name}",
77
+ trust_remote_code=True
78
+ )
79
+
80
+ # Tokenize the input string
81
+ inputs = tokenizer(
82
+ instruction,
83
+ return_tensors="pt",
84
+ return_attention_mask=False
85
+ )
86
+
87
+ # Generate text using the model
88
+ outputs = model.generate(**inputs, max_length=200)
89
+
90
+ # Decode and print the output
91
+ text = tokenizer.batch_decode(outputs)[0]
92
+ print(text)
93
+ ```
94
+
95
+ 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-2x2_8/blob/main/config.json#L26-L27) file (2 for both by default). This configuration is automatically loaded in `configuration.py`.
96
+
97
+ [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-2x2_8/blob/main/modeling_phi.py#L293-L317).
98
+
99
+ ## 🤝 Acknowledgments
100
+
101
+ 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.
102
+
103
+ 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/).
104
+
105
+ Thanks to [ehartford](https://huggingface.co/ehartford) and [lxuechen](https://huggingface.co/lxuechen) for their fine-tuned phi-2 models.