Use DiffusionLM pipeline in usage example
Browse files
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
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
```python
|
| 58 |
-
import
|
| 59 |
-
from huggingface_hub import hf_hub_download
|
| 60 |
-
from transformers import PreTrainedTokenizerFast
|
| 61 |
-
from diffusionlm_from_scratch.model import DiT, DiTConfig
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
model.eval()
|
| 71 |
|
| 72 |
-
|
|
|
|
| 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)
|