phixtral-4x2_8 is the first Mixure of Experts (MoE) made with four
microsoft/phi-2 models, inspired by the
mistralai/Mixtral-8x7B-v0.1 architecture. It performs better than each individual expert.
The evaluation was performed using
LLM AutoEval on Nous suite.
Check
YALL - Yet Another LLM Leaderboard to compare it with other models.
The model has been made with a custom version of the
mergekit library (mixtral branch) and the following configuration:
1base_model: cognitivecomputations/dolphin-2_6-phi-2
2gate_mode: cheap_embed
3experts:
4 - source_model: cognitivecomputations/dolphin-2_6-phi-2
5 positive_prompts: [""]
6 - source_model: lxuechen/phi-2-dpo
7 positive_prompts: [""]
8 - source_model: Yhyu13/phi-2-sft-dpo-gpt4_en-ep1
9 positive_prompts: [""]
10 - source_model: mrm8488/phi-2-coder
11 positive_prompts: [""]
Here's a
Colab notebook to run Phixtral in 4-bit precision on a free T4 GPU.
1!pip install -q --upgrade transformers einops accelerate bitsandbytes
2
3import torch
4from transformers import AutoModelForCausalLM, AutoTokenizer
5
6model_name = "phixtral-4x2_8"
7instruction = '''
8 def print_prime(n):
9 """
10 Print all primes between 1 and n
11 """
12'''
13
14torch.set_default_device("cuda")
15
16# Load the model and tokenizer
17model = AutoModelForCausalLM.from_pretrained(
18 f"mlabonne/{model_name}",
19 torch_dtype="auto",
20 load_in_4bit=True,
21 trust_remote_code=True
22)
23tokenizer = AutoTokenizer.from_pretrained(
24 f"mlabonne/{model_name}",
25 trust_remote_code=True
26)
27
28# Tokenize the input string
29inputs = tokenizer(
30 instruction,
31 return_tensors="pt",
32 return_attention_mask=False
33)
34
35# Generate text using the model
36outputs = model.generate(**inputs, max_length=200)
37
38# Decode and print the output
39text = tokenizer.batch_decode(outputs)[0]
40print(text)
Inspired by
mistralai/Mixtral-8x7B-v0.1, you can specify the
num_experts_per_tok and
num_local_experts in the
config.json file (2 and 4 by default). This configuration is automatically loaded in
configuration.py.
vince62s implemented the MoE inference code in the
modeling_phi.py file. In particular, see the
MoE class.
A special thanks to
vince62s for the inference code and the dynamic configuration of the number of experts. He was very patient and helped me to debug everything.
Thanks to
Charles Goddard for the
mergekit library and the implementation of the
MoE for clowns.
Thanks to
ehartford,
lxuechen,
Yhyu13, and
mrm8488 for their fine-tuned phi-2 models.