Text Generation
Transformers
Safetensors
English
metadiffusion
diffusion
diffusion-lm
ar-to-diffusion
custom_code
Instructions to use CodeSoft/MetaDiffusion-600M-ChatBase with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CodeSoft/MetaDiffusion-600M-ChatBase with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="CodeSoft/MetaDiffusion-600M-ChatBase", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("CodeSoft/MetaDiffusion-600M-ChatBase", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CodeSoft/MetaDiffusion-600M-ChatBase with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CodeSoft/MetaDiffusion-600M-ChatBase" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CodeSoft/MetaDiffusion-600M-ChatBase", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/CodeSoft/MetaDiffusion-600M-ChatBase
- SGLang
How to use CodeSoft/MetaDiffusion-600M-ChatBase 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 "CodeSoft/MetaDiffusion-600M-ChatBase" \ --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": "CodeSoft/MetaDiffusion-600M-ChatBase", "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 "CodeSoft/MetaDiffusion-600M-ChatBase" \ --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": "CodeSoft/MetaDiffusion-600M-ChatBase", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use CodeSoft/MetaDiffusion-600M-ChatBase with Docker Model Runner:
docker model run hf.co/CodeSoft/MetaDiffusion-600M-ChatBase
Update chat.py
Browse files
chat.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
| 2 |
"""chat.py: ChatML chat with MetaDiffusion-600M checkpoints.
|
| 3 |
|
| 4 |
Left-to-right block commit (semi-autoregressive): the leftmost masked
|
| 5 |
-
positions are filled first, so <|im_end|> cannot win the race at position 0
|
|
|
|
| 6 |
|
| 7 |
Usage:
|
| 8 |
Interactive: python chat.py --model-path checkpoints/step_30000.pt
|
|
@@ -43,6 +44,15 @@ def load_model(model_path, device):
|
|
| 43 |
sd = load_file(path / "model.safetensors")
|
| 44 |
sd = {k[len("model."):] if k.startswith("model.") else k: v for k, v in sd.items()}
|
| 45 |
model.load_state_dict(sd, strict=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
ckpt = torch.load(model_path, map_location=device, weights_only=False)
|
| 48 |
config = build_config(ckpt["config"])
|
|
@@ -57,7 +67,7 @@ def load_model(model_path, device):
|
|
| 57 |
|
| 58 |
|
| 59 |
def ensure_special_tokens(tokenizer):
|
| 60 |
-
"""Add [MASK] + rainbow if missing"""
|
| 61 |
added = []
|
| 62 |
if tokenizer.convert_tokens_to_ids("[MASK]") == tokenizer.unk_token_id:
|
| 63 |
added.append("[MASK]")
|
|
|
|
| 2 |
"""chat.py: ChatML chat with MetaDiffusion-600M checkpoints.
|
| 3 |
|
| 4 |
Left-to-right block commit (semi-autoregressive): the leftmost masked
|
| 5 |
+
positions are filled first, so <|im_end|> cannot win the race at position 0
|
| 6 |
+
(which produced empty responses on the 150M architecture).
|
| 7 |
|
| 8 |
Usage:
|
| 9 |
Interactive: python chat.py --model-path checkpoints/step_30000.pt
|
|
|
|
| 44 |
sd = load_file(path / "model.safetensors")
|
| 45 |
sd = {k[len("model."):] if k.startswith("model.") else k: v for k, v in sd.items()}
|
| 46 |
model.load_state_dict(sd, strict=True)
|
| 47 |
+
elif path.suffix == ".safetensors":
|
| 48 |
+
from safetensors.torch import load_file
|
| 49 |
+
sd = load_file(model_path)
|
| 50 |
+
emb = sd["model.embed_tokens.weight"]
|
| 51 |
+
config = MetaDiffusionConfig(hidden_size=emb.shape[1],
|
| 52 |
+
mask_vocab_size=emb.shape[0])
|
| 53 |
+
model = MetaDiffusionLM(config).to(device)
|
| 54 |
+
sd = {k[len("model."):] if k.startswith("model.") else k: v for k, v in sd.items()}
|
| 55 |
+
model.load_state_dict(sd, strict=True)
|
| 56 |
else:
|
| 57 |
ckpt = torch.load(model_path, map_location=device, weights_only=False)
|
| 58 |
config = build_config(ckpt["config"])
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
def ensure_special_tokens(tokenizer):
|
| 70 |
+
"""Add [MASK] + rainbow if missing (source tokenizer case)."""
|
| 71 |
added = []
|
| 72 |
if tokenizer.convert_tokens_to_ids("[MASK]") == tokenizer.unk_token_id:
|
| 73 |
added.append("[MASK]")
|