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.
Here's a
Colab notebook
to run Phixtral in 4-bit precision on a free T4 GPU.
!pip install -q --upgrade transformers einops accelerate bitsandbytes
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "phixtral-4x2_8"
instruction = ''' def print_prime(n): """ Print all primes between 1 and n """'''
torch.set_default_device("cuda")
# Load the model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
f"mlabonne/{model_name}",
torch_dtype="auto",
load_in_4bit=True,
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
f"mlabonne/{model_name}",
trust_remote_code=True
)
# Tokenize the input string
inputs = tokenizer(
instruction,
return_tensors="pt",
return_attention_mask=False
)
# Generate text using the model
outputs = model.generate(**inputs, max_length=200)
# Decode and print the output
text = tokenizer.batch_decode(outputs)[0]
print(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
.
🤝 Acknowledgments
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.
phixtral-4x2_8 huggingface.co is an AI model on huggingface.co that provides phixtral-4x2_8's model effect (), which can be used instantly with this mlabonne phixtral-4x2_8 model. huggingface.co supports a free trial of the phixtral-4x2_8 model, and also provides paid use of the phixtral-4x2_8. Support call phixtral-4x2_8 model through api, including Node.js, Python, http.
phixtral-4x2_8 huggingface.co is an online trial and call api platform, which integrates phixtral-4x2_8's modeling effects, including api services, and provides a free online trial of phixtral-4x2_8, you can try phixtral-4x2_8 online for free by clicking the link below.
mlabonne phixtral-4x2_8 online free url in huggingface.co:
phixtral-4x2_8 is an open source model from GitHub that offers a free installation service, and any user can find phixtral-4x2_8 on GitHub to install. At the same time, huggingface.co provides the effect of phixtral-4x2_8 install, users can directly use phixtral-4x2_8 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.