Instructions to use yujiepan/mamba2-tiny-random with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yujiepan/mamba2-tiny-random with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yujiepan/mamba2-tiny-random")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("yujiepan/mamba2-tiny-random", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yujiepan/mamba2-tiny-random with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yujiepan/mamba2-tiny-random" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yujiepan/mamba2-tiny-random", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/yujiepan/mamba2-tiny-random
- SGLang
How to use yujiepan/mamba2-tiny-random 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 "yujiepan/mamba2-tiny-random" \ --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": "yujiepan/mamba2-tiny-random", "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 "yujiepan/mamba2-tiny-random" \ --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": "yujiepan/mamba2-tiny-random", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use yujiepan/mamba2-tiny-random with Docker Model Runner:
docker model run hf.co/yujiepan/mamba2-tiny-random
Upload folder using huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
inference: true
|
| 5 |
+
widget:
|
| 6 |
+
- text: Hello!
|
| 7 |
+
example_title: Hello world
|
| 8 |
+
group: Python
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
This model is for debugging. It is randomly initialized using the config from [mistralai/Mamba-Codestral-7B-v0.1](https://huggingface.co/mistralai/Mamba-Codestral-7B-v0.1) but with smaller size.
|
| 12 |
+
|
| 13 |
+
Codes:
|
| 14 |
+
```python
|
| 15 |
+
import os
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
from huggingface_hub import create_repo, upload_folder
|
| 20 |
+
from transformers import (
|
| 21 |
+
AutoModelForCausalLM,
|
| 22 |
+
AutoTokenizer,
|
| 23 |
+
GenerationConfig,
|
| 24 |
+
Mamba2Config,
|
| 25 |
+
pipeline,
|
| 26 |
+
set_seed,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
model_id = "mistralai/Mamba-Codestral-7B-v0.1"
|
| 30 |
+
repo_id = "yujiepan/mamba2-tiny-random"
|
| 31 |
+
save_path = f"/tmp/{repo_id}"
|
| 32 |
+
|
| 33 |
+
os.system(f'rm -rf {save_path}')
|
| 34 |
+
|
| 35 |
+
config = Mamba2Config.from_pretrained(model_id)
|
| 36 |
+
config.use_cache = True
|
| 37 |
+
config.num_hidden_layers = 2
|
| 38 |
+
config.num_heads = 8
|
| 39 |
+
config.head_dim = 4
|
| 40 |
+
config.hidden_size = 8
|
| 41 |
+
config.expand = 4
|
| 42 |
+
config.intermediate_size = 32
|
| 43 |
+
config.state_size = 8
|
| 44 |
+
config.n_groups = 2
|
| 45 |
+
|
| 46 |
+
assert config.intermediate_size == \
|
| 47 |
+
config.hidden_size * config.expand == config.num_heads * config.head_dim
|
| 48 |
+
assert config.num_heads // config.n_groups > 0
|
| 49 |
+
assert config.num_heads % 8 == 0
|
| 50 |
+
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 52 |
+
tokenizer.save_pretrained(save_path)
|
| 53 |
+
|
| 54 |
+
model = AutoModelForCausalLM.from_config(
|
| 55 |
+
config, torch_dtype=torch.bfloat16,
|
| 56 |
+
trust_remote_code=True,
|
| 57 |
+
)
|
| 58 |
+
model.generation_config = GenerationConfig.from_pretrained(
|
| 59 |
+
model_id,
|
| 60 |
+
trust_remote_code=True,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
set_seed(42)
|
| 64 |
+
with torch.no_grad():
|
| 65 |
+
for name, p in sorted(model.named_parameters()):
|
| 66 |
+
print(name, p.shape)
|
| 67 |
+
torch.nn.init.uniform_(p, -0.5, 0.5)
|
| 68 |
+
|
| 69 |
+
model.save_pretrained(save_path)
|
| 70 |
+
|
| 71 |
+
pipe = pipeline(
|
| 72 |
+
"text-generation",
|
| 73 |
+
model=save_path,
|
| 74 |
+
device="cuda",
|
| 75 |
+
trust_remote_code=True,
|
| 76 |
+
max_new_tokens=20,
|
| 77 |
+
)
|
| 78 |
+
print(pipe("Hello World!"))
|
| 79 |
+
|
| 80 |
+
create_repo(repo_id, exist_ok=True)
|
| 81 |
+
upload_folder(repo_id=repo_id, folder_path=save_path, repo_type='model')
|
| 82 |
+
```
|