Views
No views yet
1from hdlm.hf_utils import smart_model_loader
2from hdlm.gamma_hybrid.sampling import get_sa_sampling_fn
3from transformers import GPT2TokenizerFast
4import torch
5
6# Load model using smart loader (automatically detects model type)
7model, cfg, device, accelerator, metaschedule = smart_model_loader(
8 model_path="hdlm-group/hdlm-base-gamma-0.05",
9 model_type="auto", # automatically detects gamma_hybrid
10 device="cuda"
11)
12
13# Load tokenizer
14tokenizer = GPT2TokenizerFast.from_pretrained('gpt2')
15
16# Generate text
17prompt = "The future of artificial intelligence"
18prompt_ids = tokenizer.encode(prompt, return_tensors='pt').to(device)
19
20# Configure sampling function (automatically set up from config)
21sampling_fn = get_sa_sampling_fn(
22 config=cfg,
23 graph=None, # Will be created from config
24 noise=None, # Will be created from config
25 meta_schedule=metaschedule,
26 batch_dims=(1,),
27 eps=1e-4,
28 device=device
29)
30
31# Generate samples
32generated = sampling_fn(
33 model=model,
34 prompt=prompt_ids,
35 context_length=1024
36)
37
38# Decode generated text
39generated_text = tokenizer.decode(generated[0], skip_special_tokens=True)
40print(generated_text)1# Text generation evaluation
2python hdlm/eval_generation.py \
3 --checkpoint_path hdlm-group/hdlm-base-gamma-0.05 \
4 --sampling_method SAR \
5 --save_samples
6
7# Perplexity evaluation
8python hdlm/eval_modeling.py \
9 --checkpoint_path hdlm-group/hdlm-base-gamma-0.05 \
10 --work_dir "./logs/eval_modeling_gamma" \
11 --dataset ptb1@article{fathi2025unifying,
2 title={Unifying autoregressive and diffusion-based sequence generation},
3 author={Fathi, Nima and Scholak, Torsten and No{\"e}l, Pierre-Andr{\'e}},
4 journal={arXiv preprint arXiv:2504.06416},
5 year={2025}
6}