---
title: dbrx-instruct-4bit
canonical_url: "https://www.modelscope.cn/models/mlx-community/dbrx-instruct-4bit"
md_url: "https://www.modelscope.cn/models/mlx-community/dbrx-instruct-4bit.md"
repository: mlx-community/dbrx-instruct-4bit
last_updated: 2024-12-19
license: other
model_type:
  - dbrx
architectures:
  - DbrxForCausalLM
parameters: 21.1B
tensor_type:
  - F16
  - U32
library_name:
  - mlx
  - safetensors
  - pytorch
frameworks:
  - pytorch
inference_backends:
  - "deploy_task text/emb"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 1029
stars: 0
tags:
  - mlx
---

# dbrx-instruct-4bit

> dbrx-instruct-4bit - mlx-community 在 ModelScope 开源的模型。mlx-community/dbrx-instruct-4bit This model was converted to MLX format from databricks/dbrx-instruct using mlx-lm version b80adbc after DBRX support was added by Awni Hannun. Refer to the original model…

mlx-community/dbrx-instruct-4bit 是 ModelScope 魔搭社区上的 21.1B 参数机器学习模型，采用 other 许可，可用 deploy_task text/emb、sglang 0.5.2、vllm 0.9.2 部署。

- **Repository**: mlx-community/dbrx-instruct-4bit
- **License**: other
- **Parameters**: 21.1B
- **Inference backends**: deploy_task text/emb, sglang 0.5.2, vllm 0.9.2
- **Tags**: mlx
- **Downloads**: 1029
- **Stars**: 0
- **Last updated**: 2024-12-19

Source: https://www.modelscope.cn/models/mlx-community/dbrx-instruct-4bit

---

# mlx-community/dbrx-instruct-4bit
This model was converted to MLX format from [`databricks/dbrx-instruct`]() using mlx-lm version [b80adbc
 ](https://github.com/ml-explore/mlx-examples/commit/b80adbcc3ee5b00ad43432faede408b983f152c2) after DBRX support was added by [Awni Hannun](https://github.com/awni).
 
Refer to the [original model card](https://huggingface.co/databricks/dbrx-instruct) for more details on the model.

## Conversion

Conversion was done with:
```bash
python -m mlx_lm.convert --hf-path databricks/dbrx-instruct -q --upload-repo mlx-community/dbrx-instruct-4bit
```

## Use with mlx

Make you you first upgrade mlx-lm and mlx to the latest.

```bash
pip install mlx --upgrade
pip install mlx-lm --upgrade

python -m mlx_lm.generate --model mlx-community/dbrx-instruct-4bit --prompt "Hello" --trust-remote-code --use-default-chat-template --max-tokens 500
```

Remember, this is an Instruct model, so you will need to use the instruct prompt template by appending `--use-default-chat-template`

## Example:

```bash
python -m mlx_lm.generate --model dbrx-instruct-4bit --prompt "What's the difference between PCA vs UMAP vs t-SNE?" --trust-remote-code --use-default-chat-template  --max-tokens 1000
```

Output:


![image/png](https://cdn-uploads.huggingface.co/production/uploads/630f2745982455e61cc5fb1d/AW-tHeKBOAVEfqP1zNH0j.png)

On my Macbook Pro M2 with 96GB of Unified Memory, DBRX Instruct in 4-bit for the above prompt it eats 70.2GB of RAM.


if the mlx-lm package was updated it can also be installed from pip:

```bash
pip install mlx-lm
```

To use it from Python you can do the following:

```python
from mlx_lm import load, generate

model, tokenizer = load(
   "mlx-community/dbrx-instruct-4bit",
   tokenizer_config={"trust_remote_code": True}
)

chat = [
   {"role": "user", "content": "What's the difference between PCA vs UMAP vs t-SNE?"},
   # We need to add the Assistant role as well, otherwise mlx_lm will error on generation.
   {"role": "assistant", "content": "The "},
]

prompt = tokenizer.apply_chat_template(chat, add_generation_prompt=True, tokenize=False)

response = generate(model, tokenizer, prompt=prompt, verbose=True, temp=0.6, max_tokens=1500)
```

Converted and uploaded by [eek](https://huggingface.co/eek)
