Instructions to use DiscoResearch/mixtral-7b-8expert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DiscoResearch/mixtral-7b-8expert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DiscoResearch/mixtral-7b-8expert", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("DiscoResearch/mixtral-7b-8expert", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("DiscoResearch/mixtral-7b-8expert", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DiscoResearch/mixtral-7b-8expert with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DiscoResearch/mixtral-7b-8expert" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DiscoResearch/mixtral-7b-8expert", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/DiscoResearch/mixtral-7b-8expert
- SGLang
How to use DiscoResearch/mixtral-7b-8expert with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "DiscoResearch/mixtral-7b-8expert" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DiscoResearch/mixtral-7b-8expert", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "DiscoResearch/mixtral-7b-8expert" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DiscoResearch/mixtral-7b-8expert", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use DiscoResearch/mixtral-7b-8expert with Docker Model Runner:
docker model run hf.co/DiscoResearch/mixtral-7b-8expert
Update modeling_moe_mistral.py (#1)
Browse files- Update modeling_moe_mistral.py (36895657ceb8b36d400804a084468668deee6686)
- modeling_moe_mistral.py +3 -4
modeling_moe_mistral.py
CHANGED
|
@@ -196,9 +196,7 @@ class FeedForward(nn.Module):
|
|
| 196 |
)
|
| 197 |
|
| 198 |
def forward(self, x):
|
| 199 |
-
|
| 200 |
-
x = x.to(self.w1.weight.device)
|
| 201 |
-
return self.w2(F.silu(self.w1(x)) * self.w3(x)).to(device)
|
| 202 |
|
| 203 |
|
| 204 |
class MoE(nn.Module):
|
|
@@ -217,8 +215,9 @@ class MoE(nn.Module):
|
|
| 217 |
orig_shape = x.shape
|
| 218 |
x = x.view(-1, x.shape[-1])
|
| 219 |
|
| 220 |
-
scores = self.gate(x)
|
| 221 |
expert_weights, expert_indices = torch.topk(scores, self.num_experts_per_token, dim=-1)
|
|
|
|
| 222 |
flat_expert_indices = expert_indices.view(-1)
|
| 223 |
|
| 224 |
x = x.repeat_interleave(self.num_experts_per_token, dim=0)
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
def forward(self, x):
|
| 199 |
+
return self.w2(F.silu(self.w1(x)) * self.w3(x))
|
|
|
|
|
|
|
| 200 |
|
| 201 |
|
| 202 |
class MoE(nn.Module):
|
|
|
|
| 215 |
orig_shape = x.shape
|
| 216 |
x = x.view(-1, x.shape[-1])
|
| 217 |
|
| 218 |
+
scores = self.gate(x)
|
| 219 |
expert_weights, expert_indices = torch.topk(scores, self.num_experts_per_token, dim=-1)
|
| 220 |
+
expert_weights = expert_weights.softmax(dim=-1)
|
| 221 |
flat_expert_indices = expert_indices.view(-1)
|
| 222 |
|
| 223 |
x = x.repeat_interleave(self.num_experts_per_token, dim=0)
|