tchauffi commited on
Commit
a3f2b3f
·
verified ·
1 Parent(s): 64f0c94

Use DiffusionLM pipeline in usage example

Browse files
Files changed (1) hide show
  1. README.md +15 -12
README.md CHANGED
@@ -52,24 +52,27 @@ weight `1/σ(t)`, is what turned word-salad into coherent stories.
52
 
53
  ## Usage
54
 
55
- Install the model code from the GitHub repo, then:
 
 
 
56
 
57
  ```python
58
- import torch
59
- from huggingface_hub import hf_hub_download
60
- from transformers import PreTrainedTokenizerFast
61
- from diffusionlm_from_scratch.model import DiT, DiTConfig
62
 
63
- repo = "tchauffi/diffusionlm-from-scratch"
 
 
 
64
 
65
- ckpt_path = hf_hub_download(repo, "final.pt")
66
- ck = torch.load(ckpt_path, map_location="cpu", weights_only=False)
67
 
68
- model = DiT(DiTConfig(**ck["config"]))
69
- model.load_state_dict(ck["model"]) # EMA weights ("raw" also available)
70
- model.eval()
71
 
72
- tokenizer = PreTrainedTokenizerFast.from_pretrained(repo)
 
73
  ```
74
 
75
  See [`scripts/capture_trajectories.py`](https://github.com/tchauffi/diffusionlm-from-scratch/blob/main/scripts/capture_trajectories.py)
 
52
 
53
  ## Usage
54
 
55
+ Install the model code from the
56
+ [GitHub repo](https://github.com/tchauffi/diffusionlm-from-scratch), then
57
+ generate stories in two lines — `DiffusionLM` bundles the model, tokenizer, and
58
+ absorbing-state scheduler:
59
 
60
  ```python
61
+ from diffusionlm_from_scratch import DiffusionLM
 
 
 
62
 
63
+ lm = DiffusionLM.from_pretrained("tchauffi/diffusionlm-from-scratch")
64
+ for story in lm.generate(n=4, seq_len=80, temperature=0.9):
65
+ print(story)
66
+ ```
67
 
68
+ `generate` exposes the sampler knobs (`order`, `steps`, `corrector_frac`,
69
+ `confidence_threshold`, …). For lower-level access, load just the model:
70
 
71
+ ```python
72
+ from diffusionlm_from_scratch.model import DiT
 
73
 
74
+ model = DiT.from_pretrained("tchauffi/diffusionlm-from-scratch") # downloads final.pt
75
+ # the raw checkpoint carries ck["config"], ck["model"] (EMA), and ck["raw"].
76
  ```
77
 
78
  See [`scripts/capture_trajectories.py`](https://github.com/tchauffi/diffusionlm-from-scratch/blob/main/scripts/capture_trajectories.py)