Instructions to use TASMAYU/bonsai-diffusionLM-modernbert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TASMAYU/bonsai-diffusionLM-modernbert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TASMAYU/bonsai-diffusionLM-modernbert")# Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("TASMAYU/bonsai-diffusionLM-modernbert") model = AutoModelForMaskedLM.from_pretrained("TASMAYU/bonsai-diffusionLM-modernbert", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TASMAYU/bonsai-diffusionLM-modernbert with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TASMAYU/bonsai-diffusionLM-modernbert" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TASMAYU/bonsai-diffusionLM-modernbert", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TASMAYU/bonsai-diffusionLM-modernbert
- SGLang
How to use TASMAYU/bonsai-diffusionLM-modernbert 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 "TASMAYU/bonsai-diffusionLM-modernbert" \ --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": "TASMAYU/bonsai-diffusionLM-modernbert", "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 "TASMAYU/bonsai-diffusionLM-modernbert" \ --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": "TASMAYU/bonsai-diffusionLM-modernbert", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use TASMAYU/bonsai-diffusionLM-modernbert with Docker Model Runner:
docker model run hf.co/TASMAYU/bonsai-diffusionLM-modernbert
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- diffusion
|
| 6 |
+
- language-model
|
| 7 |
+
- modernbert
|
| 8 |
+
- text-generation
|
| 9 |
+
pipeline_tag: text-generation
|
| 10 |
+
library_name: transformers
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Bonsai Diffusion LM - ModernBERT
|
| 14 |
+
|
| 15 |
+
A **lightweight diffusion language model** based on the LLaDA paper (Large Language Diffusion with mAsking).
|
| 16 |
+
|
| 17 |
+
## Model Description
|
| 18 |
+
|
| 19 |
+
Unlike traditional autoregressive models (GPT) that generate left-to-right, this model **starts from pure noise and iteratively unmasks tokens** to generate coherent text.
|
| 20 |
+
|
| 21 |
+
| Property | Value |
|
| 22 |
+
|----------|-------|
|
| 23 |
+
| Architecture | ModernBERT-base |
|
| 24 |
+
| Parameters | 149M |
|
| 25 |
+
| Training Data | TinyStories (50,000 samples) |
|
| 26 |
+
| Context Length | 256 tokens |
|
| 27 |
+
|
| 28 |
+
## Quick Usage
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 32 |
+
import torch
|
| 33 |
+
|
| 34 |
+
model = AutoModelForMaskedLM.from_pretrained("TASMAYU/bonsai-diffusionLM-modernbert")
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained("TASMAYU/bonsai-diffusionLM-modernbert")
|
| 36 |
+
|
| 37 |
+
if tokenizer.mask_token is None:
|
| 38 |
+
tokenizer.mask_token = "[MASK]"
|
| 39 |
+
|
| 40 |
+
def generate(prompt=None, num_steps=64, seq_len=256):
|
| 41 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 42 |
+
model.to(device)
|
| 43 |
+
model.eval()
|
| 44 |
+
|
| 45 |
+
if prompt:
|
| 46 |
+
prompt_ids = tokenizer.encode(prompt, add_special_tokens=False)
|
| 47 |
+
input_ids = torch.full((1, seq_len), tokenizer.mask_token_id, device=device)
|
| 48 |
+
input_ids[0, :len(prompt_ids)] = torch.tensor(prompt_ids, device=device)
|
| 49 |
+
else:
|
| 50 |
+
input_ids = torch.full((1, seq_len), tokenizer.mask_token_id, device=device)
|
| 51 |
+
|
| 52 |
+
for step in range(num_steps):
|
| 53 |
+
t = 1.0 - (step / num_steps)
|
| 54 |
+
s = 1.0 - ((step + 1) / num_steps)
|
| 55 |
+
|
| 56 |
+
with torch.no_grad():
|
| 57 |
+
outputs = model(input_ids)
|
| 58 |
+
predictions = outputs.logits.argmax(dim=-1)
|
| 59 |
+
|
| 60 |
+
mask_positions = (input_ids == tokenizer.mask_token_id)
|
| 61 |
+
remask_prob = s / t if t > 0 else 0
|
| 62 |
+
remask = torch.rand_like(input_ids.float()) < remask_prob
|
| 63 |
+
|
| 64 |
+
new_input_ids = input_ids.clone()
|
| 65 |
+
new_input_ids[mask_positions] = predictions[mask_positions]
|
| 66 |
+
new_input_ids[remask & mask_positions] = tokenizer.mask_token_id
|
| 67 |
+
input_ids = new_input_ids
|
| 68 |
+
|
| 69 |
+
return tokenizer.decode(input_ids[0].cpu().tolist(), skip_special_tokens=True)
|
| 70 |
+
|
| 71 |
+
# Example
|
| 72 |
+
print(generate("Once upon a time", num_steps=64))
|