| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
DreamOn is a novel discrete diffusion algorithm designed to address the variable-length generation challenge in code infilling. Unlike current discrete diffusion language models, our approach enables dynamic expansion and contraction of mask tokens during inference, providing flexible length control without requiring predetermined canvas sizes.
This work is done as part of the HKU NLP Group and Klear Team@Kuaishou Technology.
[2025/7/25] We open-source our code for training and evaluation. We also release a demo for DreamOn on Hugging Face Spaces. You can try it out here.
[2025/7/15] We release our model DreamOn and its accompanying model DreamCoder.
Our implementation follows our previous work Dream. Please install transformers by pip install transformers==4.46.2 and torch==2.5.1 as Dream uses the SdpaAttention built in torch.
import torch
import time
from transformers import AutoModel, AutoTokenizer
def process_infilling_prompt(prefix, suffix, tokenizer, number_of_mask):
prefix = [tokenizer.bos_token_id] + tokenizer.encode(prefix, add_special_tokens=False)
middle = [tokenizer.mask_token_id] * number_of_mask
suffix = tokenizer.encode(suffix, add_special_tokens=False) + [tokenizer.eos_token_id]
return prefix + middle + suffix
prefix = '''from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
""" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
False
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
True
"""
'''
suffix = ''' for idx2, elem2 in enumerate(numbers):
if idx != idx2:
distance = abs(elem - elem2)
if distance < threshold:
return True
return False
'''
model_path = 'Dream-org/DreamOn-v0-7B'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
## Set the initial mask token length when processing the prompt
input_ids = process_infilling_prompt(prefix, suffix, tokenizer, 4)
input_ids = torch.LongTensor([input_ids]).to("cuda")
model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True)
model = model.to("cuda").eval()
output = model.diffusion_generate(
input_ids,
temperature=0.2,
alg = 'entropy',
alg_temp = 0,
top_p = 0.9,
max_new_tokens = 64, ## Set the maximum number of new tokens for infilling
return_dict_in_generate = True,
output_history = True,
number_transfer_tokens = 1
)
history = output.history
for i, h in enumerate(history):
print(f"########################")
time.sleep(0.2)
print(tokenizer.decode(h.tolist()), end="\n\n") Note: We currently do not support attention mask, as we recompute attention mask each denoising step to support variable-length generation.
Use the following command to replicate our results.
git clone https://github.com/openai/human-eval-infilling pip install -e human-eval-infilling pip install omegaconf
bash eval/eval_humaneval_infilling.sh bash eval/eval_santa_fim.sh
Our training implementation is built upon the SFT trainer from verl. To train DreamOn, please install verl first, and then execute the following command:
python data/prepare_data.py bash run_dreamon.sh
@misc{wu2026dreamon,
title={DreamOn: Diffusion Language Models For Code Infilling Beyond Fixed-size Canvas},
author={Zirui Wu and Lin Zheng and Zhihui Xie and Jiacheng Ye and Jiahui Gao and Shansan Gong and Yansong Feng and Zhenguo Li and Wei Bi and Guorui Zhou and Lingpeng Kong},
year={2026},
eprint={2602.01326},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2602.01326},
}| Back | FazBrowse Home | New Git URL |