Instructions to use alpindale/dbrx-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alpindale/dbrx-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="alpindale/dbrx-instruct", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("alpindale/dbrx-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("alpindale/dbrx-instruct", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use alpindale/dbrx-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "alpindale/dbrx-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alpindale/dbrx-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/alpindale/dbrx-instruct
- SGLang
How to use alpindale/dbrx-instruct 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 "alpindale/dbrx-instruct" \ --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": "alpindale/dbrx-instruct", "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 "alpindale/dbrx-instruct" \ --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": "alpindale/dbrx-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use alpindale/dbrx-instruct with Docker Model Runner:
docker model run hf.co/alpindale/dbrx-instruct
Failing to 4-bit quantize with BitsAndBytes
My goals is to run 4-bit quant of the model.
While this usual code provided executes fine... takes forever to generate single token on cpu but runs without errors:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("alpindale/dbrx-instruct", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("alpindale/dbrx-instruct", device_map="cpu", torch_dtype=torch.bfloat16, trust_remote_code=True)
input_text = "What does it take to build a great LLM?"
messages = [{"role": "user", "content": input_text}]
input_ids = tokenizer.apply_chat_template(messages, return_dict=True, tokenize=True, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(**input_ids, max_new_tokens=2)
print(tokenizer.decode(outputs[0]))
This code with BitsAndBytesConfig of nf4, throws an Error:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from transformers import BitsAndBytesConfig
tokenizer = AutoTokenizer.from_pretrained("alpindale/dbrx-instruct", trust_remote_code=True)
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
model = AutoModelForCausalLM.from_pretrained("alpindale/dbrx-instruct", device_map="cpu", quantization_config=quantization_config, trust_remote_code=True)
input_text = "What does it take to build a great LLM?"
messages = [{"role": "user", "content": input_text}]
input_ids = tokenizer.apply_chat_template(messages, return_dict=True, tokenize=True, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(**input_ids, max_new_tokens=200)
print(tokenizer.decode(outputs[0]))
Error:
RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'
I am guessing it's some new layer they implemented in the custom code. So while llama.cpp fellows, managing their own bugs with 16 experts, why not add support for the basic 4-bits from BitsAndBytes, I am guessing it's much less work, but I don't know how to do it. I am guessing it's something in the custom code provided by databricks.
I've seen this error on any model when I tried to run it quantized on CPU. Doesn't seem to be related to dbrx in any way.
Apparently it's an issue on some of the scripts since this SinclairSchneider/dbrx-instruct-quantization-fixed reupload works fine.