Instructions to use tiny-random/dbrx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/dbrx with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiny-random/dbrx")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiny-random/dbrx") model = AutoModelForCausalLM.from_pretrained("tiny-random/dbrx", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/dbrx with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/dbrx" # 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/dbrx", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tiny-random/dbrx
- SGLang
How to use tiny-random/dbrx 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/dbrx" \ --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/dbrx", "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/dbrx" \ --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/dbrx", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tiny-random/dbrx with Docker Model Runner:
docker model run hf.co/tiny-random/dbrx
Download .meta/create_model.py from tiny-random/dbrx: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/tiny-random/dbrx/resolve/main/.meta/create_model.py
- Command line
-
hf download hf://tiny-random/dbrx/.meta/create_model.py
-
curl -L -o create_model.py https://huggingface.co/tiny-random/dbrx/resolve/main/.meta/create_model.py
2.25 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) | |
| # The tiktoken-based tokenizer loads through the pinned tiktoken.py helper. | |
| for name in ( | |
| "special_tokens_map.json", | |
| "tokenizer_config.json", | |
| "added_tokens.json", | |
| "tiktoken.py", | |
| "generation_config.json", | |
| "LICENSE.txt", | |
| "NOTICE.txt", | |
| ): | |
| (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()) | |
| # DBRX is MoE in every layer: keep 16 experts and top-4 routing. The source | |
| # GQA ratio is 6:1 (48/8); four TP=4-legal heads cannot carry that, so KV | |
| # heads drop to 4. Per-expert FFN keeps the source 1.75x ratio (10752/6144). | |
| config.update( | |
| d_model=128, | |
| n_layers=4, | |
| n_heads=4, | |
| max_seq_len=4096, | |
| ) | |
| config["attn_config"]["kv_n_heads"] = 4 | |
| config["ffn_config"]["ffn_hidden_size"] = 224 | |
| config["ffn_config"]["moe_num_experts"] = 16 | |
| config["ffn_config"]["moe_top_k"] = 4 | |
| config.pop("auto_map", None) | |
| (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n") | |
| set_seed(42) | |
| model = AutoModelForCausalLM.from_config( | |
| AutoConfig.from_pretrained(folder, trust_remote_code=True), | |
| dtype=torch.bfloat16, | |
| trust_remote_code=True, | |
| ) | |
| 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="alpindale/dbrx-instruct", | |
| source_revision="8007650525bf3b67d6a4763caf02230061452d45", | |
| save_folder="/tmp/dbrx", | |
| ) | |