|
--- |
|
license: apache-2.0 |
|
base_model: mistralai/Mixtral-8x7B-v0.1 |
|
inference: false |
|
model_link: https://huggingface.co/mistralai/Mixtral-8x7B-v0.1 |
|
model_name: mistralai/Mixtral-8x7B-v0.1 |
|
pipeline_tag: text-generation |
|
quantized_by: FriendliAI |
|
tags: |
|
- pretrained |
|
--- |
|
|
|
<!-- header start --> |
|
<p align="center"> |
|
<img src="https://i.imgur.com/mNM6Cai.png" width="100%" alt="Friendli Logo"> |
|
</p> |
|
<!-- header end --> |
|
|
|
# Mixtral-8x7B-v0.1 - FP8 |
|
|
|
- Model creator: [Mistral AI](https://huggingface.co/mistralai) |
|
- Original model: [Mixtral-8x7B-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) |
|
|
|
## Description |
|
|
|
This repo contains the Mixtral-8x7B-v0.1 model quantized to FP8 by FriendliAI, significantly enhancing its inference efficiency while maintaining high accuracy. |
|
Note that FP8 is only supported by NVIDIA Ada, Hopper, and Blackwell GPU architectures. |
|
Check out [FriendliAI documentation](https://docs.friendli.ai/) for more details. |
|
|
|
## Compatibility |
|
|
|
This model is compatible with **[Friendli Container](https://friendli.ai/products/container/)**. |
|
|
|
## Prerequisites |
|
|
|
- Before you begin, make sure you have signed up for [Friendli Suite](https://suite.friendli.ai/). **You can use Friendli Containers free of charge for four weeks.** |
|
- Prepare a Personal Access Token following [this guide](#preparing-personal-access-token). |
|
- Prepare a Friendli Container Secret following [this guide](#preparing-container-secret). |
|
|
|
### Preparing Personal Access Token |
|
|
|
PAT (Personal Access Token) is the user credential for for logging into our container registry. |
|
|
|
1. Sign in [Friendli Suite](https://suite.friendli.ai/). |
|
2. Go to **[User Settings > Tokens](https://suite.friendli.ai/user-settings/tokens)** and click **'Create new token'**. |
|
3. Save your created token value. |
|
|
|
### Pulling Friendli Container Image |
|
|
|
1. Log in to the Docker client using the personal access token created as outlined in [this guide](#preparing-personal-access-token). |
|
|
|
```sh |
|
export FRIENDLI_PAT="YOUR PAT" |
|
docker login registry.friendli.ai -u $YOUR_EMAIL -p $FRIENDLI_PAT |
|
``` |
|
|
|
2. Pull image |
|
|
|
```sh |
|
docker pull registry.friendli.ai/trial |
|
``` |
|
|
|
## Running Friendli Container |
|
|
|
Once you've prepared the image of Friendli Container, you can launch it to create a serving endpoint. |
|
|
|
```sh |
|
docker run \ |
|
--gpus '"device=0"' \ |
|
-p 8000:8000 \ |
|
-v ~/.cache/huggingface:/root/.cache/huggingface \ |
|
-e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \ |
|
registry.friendli.ai/trial \ |
|
--web-server-port 8000 \ |
|
--hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8 |
|
``` |
|
|
|
### Optimizing Inference Performance with Policy Search |
|
|
|
To serve MoE models efficiently, it is required to run a policy search to explore the optimal execution policy: |
|
|
|
```sh |
|
export POLICY_DIR=$PWD/policy |
|
|
|
mkdir -p $POLICY_DIR |
|
|
|
docker run \ |
|
--gpus '"device=0"' \ |
|
-p 8000:8000 \ |
|
-v ~/.cache/huggingface:/root/.cache/huggingface \ |
|
-v $POLICY_DIR:/policy \ |
|
-e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \ |
|
registry.friendli.ai/trial \ |
|
--web-server-port 8000 \ |
|
--hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8 \ |
|
--algo-policy-dir /policy \ |
|
--search-policy true |
|
``` |
|
|
|
When the optimal policy is successfully searched, the policy is compiled into a policy file and saved at `$POLICY_DIR`. |
|
Now you can create an inference endpoint with this optimal policy as follows: |
|
|
|
```sh |
|
docker run \ |
|
--gpus '"device=0"' \ |
|
-p 8000:8000 \ |
|
-v ~/.cache/huggingface:/root/.cache/huggingface \ |
|
-v $POLICY_DIR:/policy \ |
|
-e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \ |
|
registry.friendli.ai/trial \ |
|
--web-server-port 8000 \ |
|
--hf-model-name FriendliAI/Mixtral-8x7B-v0.1-fp8 \ |
|
--algo-policy-dir /policy |
|
``` |
|
|
|
--- |
|
|
|
# Original model card: MistralAI's Mixtral-8x7B v0.1 |
|
|
|
# Model Card for Mixtral-8x7B |
|
The Mixtral-8x7B Large Language Model (LLM) is a pretrained generative Sparse Mixture of Experts. The Mistral-8x7B outperforms Llama 2 70B on most benchmarks we tested. |
|
|
|
For full details of this model please read our [release blog post](https://mistral.ai/news/mixtral-of-experts/). |
|
|
|
## Warning |
|
This repo contains weights that are compatible with [vLLM](https://github.com/vllm-project/vllm) serving of the model as well as Hugging Face [transformers](https://github.com/huggingface/transformers) library. It is based on the original Mixtral [torrent release](magnet:?xt=urn:btih:5546272da9065eddeb6fcd7ffddeef5b75be79a7&dn=mixtral-8x7b-32kseqlen&tr=udp%3A%2F%http://2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=http%3A%2F%http://2Ftracker.openbittorrent.com%3A80%2Fannounce), but the file format and parameter names are different. Please note that model cannot (yet) be instantiated with HF. |
|
|
|
## Run the model |
|
|
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
model_id = "mistralai/Mixtral-8x7B-v0.1" |
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
model = AutoModelForCausalLM.from_pretrained(model_id) |
|
|
|
text = "Hello my name is" |
|
inputs = tokenizer(text, return_tensors="pt") |
|
|
|
outputs = model.generate(**inputs, max_new_tokens=20) |
|
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |
|
``` |
|
|
|
By default, transformers will load the model in full precision. Therefore you might be interested to further reduce down the memory requirements to run the model through the optimizations we offer in HF ecosystem: |
|
|
|
### In half-precision |
|
|
|
Note `float16` precision only works on GPU devices |
|
|
|
<details> |
|
<summary> Click to expand </summary> |
|
|
|
```diff |
|
+ import torch |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
model_id = "mistralai/Mixtral-8x7B-v0.1" |
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16).to(0) |
|
|
|
text = "Hello my name is" |
|
+ inputs = tokenizer(text, return_tensors="pt").to(0) |
|
|
|
outputs = model.generate(**inputs, max_new_tokens=20) |
|
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |
|
``` |
|
</details> |
|
|
|
### Lower precision using (8-bit & 4-bit) using `bitsandbytes` |
|
|
|
<details> |
|
<summary> Click to expand </summary> |
|
|
|
```diff |
|
+ import torch |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
model_id = "mistralai/Mixtral-8x7B-v0.1" |
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
+ model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True) |
|
|
|
text = "Hello my name is" |
|
+ inputs = tokenizer(text, return_tensors="pt").to(0) |
|
|
|
outputs = model.generate(**inputs, max_new_tokens=20) |
|
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |
|
``` |
|
</details> |
|
|
|
### Load the model with Flash Attention 2 |
|
|
|
<details> |
|
<summary> Click to expand </summary> |
|
|
|
```diff |
|
+ import torch |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
model_id = "mistralai/Mixtral-8x7B-v0.1" |
|
tokenizer = AutoTokenizer.from_pretrained(model_id) |
|
|
|
+ model = AutoModelForCausalLM.from_pretrained(model_id, use_flash_attention_2=True) |
|
|
|
text = "Hello my name is" |
|
+ inputs = tokenizer(text, return_tensors="pt").to(0) |
|
|
|
outputs = model.generate(**inputs, max_new_tokens=20) |
|
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |
|
``` |
|
</details> |
|
|
|
## Notice |
|
Mixtral-8x7B is a pretrained base model and therefore does not have any moderation mechanisms. |
|
|
|
# The Mistral AI Team |
|
Albert Jiang, Alexandre Sablayrolles, Arthur Mensch, Blanche Savary, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Emma Bou Hanna, Florian Bressand, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Lélio Renard Lavaud, Louis Ternon, Lucile Saulnier, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Théophile Gervet, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed. |