Instructions to use tiny-random/mamba2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/mamba2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiny-random/mamba2")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("tiny-random/mamba2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/mamba2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/mamba2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/mamba2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tiny-random/mamba2
- SGLang
How to use tiny-random/mamba2 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 "tiny-random/mamba2" \ --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": "tiny-random/mamba2", "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 "tiny-random/mamba2" \ --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": "tiny-random/mamba2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tiny-random/mamba2 with Docker Model Runner:
docker model run hf.co/tiny-random/mamba2
Download .meta/create_model.py from tiny-random/mamba2: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/tiny-random/mamba2/resolve/main/.meta/create_model.py
- Command line
-
hf download hf://tiny-random/mamba2/.meta/create_model.py
-
curl -L -o create_model.py https://huggingface.co/tiny-random/mamba2/resolve/main/.meta/create_model.py
2.05 kB
| def create_model(source_model_id: str, source_revision: str, save_folder: str) -> str: | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from huggingface_hub import hf_hub_download | |
| from transformers import AutoConfig, AutoModelForCausalLM, set_seed | |
| folder = Path(save_folder) | |
| folder.mkdir(parents=True, exist_ok=True) | |
| for name in ( | |
| "special_tokens_map.json", | |
| "tokenizer.json", | |
| "tokenizer.model", | |
| "tokenizer_config.json", | |
| "generation_config.json", | |
| ): | |
| (folder / name).write_bytes(Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_bytes()) | |
| config = json.loads(Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text()) | |
| # Mamba2 requires hidden*expand == num_heads*head_dim. Source keeps head_dim | |
| # 64 and state 128, which are scan-kernel dimensions: 128*2 = 4 heads * 64. | |
| # n_groups divides num_heads; dt rank (8) divides num_heads for the reshape. | |
| config.update( | |
| hidden_size=128, | |
| intermediate_size=256, | |
| num_hidden_layers=4, | |
| num_heads=4, | |
| head_dim=64, | |
| n_groups=4, | |
| state_size=128, | |
| conv_kernel=4, | |
| expand=2, | |
| chunk_size=256, | |
| time_step_rank=8, | |
| tie_word_embeddings=False, | |
| ) | |
| (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n") | |
| set_seed(42) | |
| model = AutoModelForCausalLM.from_config(AutoConfig.from_pretrained(folder), dtype=torch.bfloat16) | |
| model.save_pretrained(folder) | |
| (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n") | |
| (folder / "generation_config.json").write_bytes( | |
| Path(hf_hub_download(source_model_id, "generation_config.json", revision=source_revision)).read_bytes() | |
| ) | |
| return str(model) | |
| if __name__ == "__main__": | |
| create_model( | |
| source_model_id="mistralai/Mamba-Codestral-7B-v0.1", | |
| source_revision="4f086c08c1e0f07bdc50ca25125dbbf7475d21da", | |
| save_folder="/tmp/mamba2", | |
| ) | |