Instructions to use jonathanjordan21/mos-mamba-6x130m-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jonathanjordan21/mos-mamba-6x130m-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="jonathanjordan21/mos-mamba-6x130m-hf", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("jonathanjordan21/mos-mamba-6x130m-hf", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use jonathanjordan21/mos-mamba-6x130m-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jonathanjordan21/mos-mamba-6x130m-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jonathanjordan21/mos-mamba-6x130m-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/jonathanjordan21/mos-mamba-6x130m-hf
- SGLang
How to use jonathanjordan21/mos-mamba-6x130m-hf 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 "jonathanjordan21/mos-mamba-6x130m-hf" \ --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": "jonathanjordan21/mos-mamba-6x130m-hf", "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 "jonathanjordan21/mos-mamba-6x130m-hf" \ --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": "jonathanjordan21/mos-mamba-6x130m-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use jonathanjordan21/mos-mamba-6x130m-hf with Docker Model Runner:
docker model run hf.co/jonathanjordan21/mos-mamba-6x130m-hf
Update modeling_mos_mamba.py
Browse files- modeling_mos_mamba.py +6 -6
modeling_mos_mamba.py
CHANGED
|
@@ -604,12 +604,12 @@ class MoSMambaMixer(nn.Module):
|
|
| 604 |
# expert_layer.grad = torch.zeros_like(expert_layer.weight)
|
| 605 |
# current_hidden_states = expert_layer(current_state)
|
| 606 |
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
final_hidden_states = final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
|
| 614 |
|
| 615 |
return final_hidden_states, router_logits
|
|
|
|
| 604 |
# expert_layer.grad = torch.zeros_like(expert_layer.weight)
|
| 605 |
# current_hidden_states = expert_layer(current_state)
|
| 606 |
|
| 607 |
+
current_hidden_states = current_hidden_states.reshape(-1, hidden_dim)
|
| 608 |
+
# print(current_hidden_states.shape, final_hidden_states.shape)
|
| 609 |
+
|
| 610 |
+
# However `index_add_` only support torch tensors for indexing so we'll use
|
| 611 |
+
# the `top_x` tensor here.
|
| 612 |
+
final_hidden_states.index_add_(0, top_x, current_hidden_states.to(hidden_states.dtype))
|
| 613 |
final_hidden_states = final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
|
| 614 |
|
| 615 |
return final_hidden_states, router_logits
|