Instructions to use Q-bert/Mamba-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Q-bert/Mamba-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Q-bert/Mamba-3B", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Q-bert/Mamba-3B", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Q-bert/Mamba-3B", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Q-bert/Mamba-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Q-bert/Mamba-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Q-bert/Mamba-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Q-bert/Mamba-3B
- SGLang
How to use Q-bert/Mamba-3B 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 "Q-bert/Mamba-3B" \ --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": "Q-bert/Mamba-3B", "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 "Q-bert/Mamba-3B" \ --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": "Q-bert/Mamba-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Q-bert/Mamba-3B with Docker Model Runner:
docker model run hf.co/Q-bert/Mamba-3B
Update README.md
Browse files
README.md
CHANGED
|
@@ -35,6 +35,30 @@ print(generated_text)
|
|
| 35 |
```
|
| 36 |
> Hi, I'm looking for a new job. I've been working at a company for about a year now.
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Credits:
|
| 39 |
|
| 40 |
https://huggingface.co/state-spaces
|
|
|
|
| 35 |
```
|
| 36 |
> Hi, I'm looking for a new job. I've been working at a company for about a year now.
|
| 37 |
|
| 38 |
+
# For Training:
|
| 39 |
+
```python
|
| 40 |
+
from transformers import Trainer ,TrainingArguments
|
| 41 |
+
import torch
|
| 42 |
+
import os
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class MambaTrainer(Trainer):
|
| 46 |
+
def compute_loss(self, model, inputs, return_outputs=False):
|
| 47 |
+
input_ids = inputs.pop("input_ids")
|
| 48 |
+
lm_logits = model(input_ids)[0]
|
| 49 |
+
|
| 50 |
+
labels = input_ids.to(lm_logits.device)
|
| 51 |
+
shift_logits = lm_logits[:, :-1, :].contiguous()
|
| 52 |
+
labels = labels[:, 1:].contiguous()
|
| 53 |
+
|
| 54 |
+
loss_fct = torch.nn.CrossEntropyLoss()
|
| 55 |
+
lm_loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), labels.view(-1))
|
| 56 |
+
|
| 57 |
+
return lm_loss
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
You must use this class for training. And fp16 must be **False**.
|
| 61 |
+
|
| 62 |
# Credits:
|
| 63 |
|
| 64 |
https://huggingface.co/state-spaces
|