D3LM
Collection
2 items • Updated
How to use Hengchang-Liu/D3LM-scratch with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Hengchang-Liu/D3LM-scratch", trust_remote_code=True) # Load model directly
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("Hengchang-Liu/D3LM-scratch", trust_remote_code=True)
model = AutoModelForMaskedLM.from_pretrained("Hengchang-Liu/D3LM-scratch", trust_remote_code=True)How to use Hengchang-Liu/D3LM-scratch with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Hengchang-Liu/D3LM-scratch"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Hengchang-Liu/D3LM-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/Hengchang-Liu/D3LM-scratch
How to use Hengchang-Liu/D3LM-scratch with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Hengchang-Liu/D3LM-scratch" \
--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": "Hengchang-Liu/D3LM-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "Hengchang-Liu/D3LM-scratch" \
--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": "Hengchang-Liu/D3LM-scratch",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use Hengchang-Liu/D3LM-scratch with Docker Model Runner:
docker model run hf.co/Hengchang-Liu/D3LM-scratch
This repository contains the model presented in D3LM: A Discrete DNA Diffusion Language Model for Bidirectional DNA Understanding and Generation.
A masked diffusion language model for unconditional mammalian DNA sequence generation, built on the ESM encoder with Rotary Positional Embeddings.
Initialization: trained from scratch (random initialization) with masked diffusion objective on mammalian DNA.
| Parameters | Hidden | Layers | Heads | Max Length | Vocab |
|---|---|---|---|---|---|
| ~50M | 512 | 12 | 16 | 2,048 | 4,107 |
pip install transformers torch tqdm
import sys
import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM
model_name = "Hengchang-Liu/D3LM-scratch"
model = AutoModelForMaskedLM.from_pretrained(model_name, trust_remote_code=True).eval()
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
# Import MDMGenerationConfig from the model's auto-downloaded module
MDMGenerationConfig = getattr(sys.modules[type(model).__module__], "MDMGenerationConfig")
# Unconditional generation: create a fully-masked prompt of desired length
length = 200
input_ids = torch.full((1, length), tokenizer.mask_token_id, dtype=torch.long)
config = MDMGenerationConfig(
mask_token_id=tokenizer.mask_token_id,
max_length=length,
steps=50,
temperature=1.0,
top_p=0.9,
alg="random",
num_return_sequences=4,
return_dict_in_generate=True,
)
with torch.no_grad():
outputs = model.diffusion_generate(inputs=input_ids, generation_config=config)
for i, seq in enumerate(outputs.sequences):
print(f">{i}
{tokenizer.decode(seq, skip_special_tokens=True).replace(' ', '')}")
| Parameter | Default | Description |
|---|---|---|
steps |
50 | Diffusion denoising steps |
temperature |
1.0 | Sampling temperature |
top_p |
0.9 | Nucleus sampling cutoff |
top_k |
0 | Top-k cutoff (0 = off) |
alg |
"random" |
Unmasking order: random, entropy, maskgit_plus, topk_margin, origin, p2 |
alg_temp |
0.9 | Gumbel temperature for confidence ordering (0 = deterministic) |
@misc{yang2026d3lmdiscretednadiffusion,
title={D3LM: A Discrete DNA Diffusion Language Model for Bidirectional DNA Understanding and Generation},
author={Zhao Yang and Hengchang Liu and Chuan Cao and Bing Su},
year={2026},
eprint={2603.01780},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2603.01780},
}
Apache 2.0