Spaces:
Running on Zero
Running on Zero
Any two checkpoints: two pickers listing every published checkpoint plus None, defaulting to each model's newest raw checkpoint (None where a model has none yet); picks counted by checkpoint
Browse files
README.md
CHANGED
|
@@ -25,11 +25,13 @@ Two small text-to-image models, trained the same way on COCO 2014 at 256 px, sho
|
|
| 25 |
- **A plain transformer** (about 42.9M parameters): the same embeddings and blocks, 13 of them, with no towers and no
|
| 26 |
oscillator. It is the control: the known working design at the same size and recipe.
|
| 27 |
|
| 28 |
-
Write a caption,
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
**Weights.** At early
|
| 33 |
training and catch up later.
|
| 34 |
|
| 35 |
**Where things come from.** The weights are in
|
|
|
|
| 25 |
- **A plain transformer** (about 42.9M parameters): the same embeddings and blocks, 13 of them, with no towers and no
|
| 26 |
oscillator. It is the control: the known working design at the same size and recipe.
|
| 27 |
|
| 28 |
+
Write a caption, choose two checkpoints, and generate. Each picker lists every checkpoint the training runs have published
|
| 29 |
+
(either model, any step, raw or averaged weights) plus None; by default they hold each model's newest raw checkpoint, and
|
| 30 |
+
None where a model has nothing published yet, so one checkpoint can also be viewed alone. Both sides start from the same noise
|
| 31 |
+
for every picture. In blind mode the two sides are shown in random order: pick the better side, then reveal which was which.
|
| 32 |
+
Your picks are counted for this session only.
|
| 33 |
|
| 34 |
+
**Weights.** At early checkpoints the raw weights give the sharper pictures. The averaged (EMA) weights lag behind early in
|
| 35 |
training and catch up later.
|
| 36 |
|
| 37 |
**Where things come from.** The weights are in
|
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
-
"""Agatha diffusion playground:
|
| 2 |
|
| 3 |
Weights: AbstractPhil/geofractal-agatha-diffusion-training, folder coco256/ (non-commercial: trained on COCO 2014 photos).
|
| 4 |
Code: github.com/AbstractEyes/geofractal, src/geofractal/router/prefab/agatha_v2, installed at the pinned commit below.
|
| 5 |
Sampling is the library's own sample_latents (the helper the training's picture sheets use), so a picture here matches a
|
| 6 |
-
sheet made at the same
|
| 7 |
"""
|
| 8 |
-
import os
|
| 9 |
import random
|
| 10 |
import re
|
| 11 |
import subprocess
|
|
@@ -49,64 +48,87 @@ TEXT_ENCODER, TEXT_REVISION, TEXT_MAX = "google-t5/t5-base", "a9723ea7f1b39c1eae
|
|
| 49 |
LATENT_SHAPE = (32, 32, 32)
|
| 50 |
ARMS = ("agatha", "plain")
|
| 51 |
NAMES = {"agatha": "Agatha", "plain": "Plain transformer"}
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
EXAMPLES = ["A man riding a bicycle down a city street.", "A herd of elephants walking through tall grass.",
|
| 55 |
"A baseball player swinging a bat at a ball.", "A plate of food with broccoli and rice.",
|
| 56 |
"A red double decker bus driving down a street.", "Two dogs playing in the snow.",
|
| 57 |
"A kitchen with wooden cabinets and a white stove.", "A person riding a wave on a surfboard."]
|
| 58 |
|
| 59 |
|
| 60 |
-
# ----------------------------------------------------------------------------- the
|
| 61 |
-
def
|
| 62 |
-
"""{(arm,
|
| 63 |
out = {}
|
| 64 |
for path in HfApi().list_repo_files(REPO):
|
| 65 |
m = FILE_RE.match(path)
|
| 66 |
if m:
|
| 67 |
-
out[(m.group(2),
|
| 68 |
return out
|
| 69 |
|
| 70 |
|
| 71 |
-
def
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
for (arm, seed, step, _w) in found:
|
| 75 |
-
have.setdefault((seed, step), set()).add(arm)
|
| 76 |
-
keys = sorted(k for k, arms in have.items() if set(ARMS) <= arms)
|
| 77 |
-
return ["seed %d, step %s" % (seed, format(step, ",")) for seed, step in keys]
|
| 78 |
|
| 79 |
|
| 80 |
-
def
|
| 81 |
-
|
| 82 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
def availability(found):
|
| 86 |
parts = []
|
| 87 |
for arm in ARMS:
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
parts.append("**%s:** %s" % (NAMES[arm], text))
|
| 91 |
-
return "
|
| 92 |
|
| 93 |
|
| 94 |
try:
|
| 95 |
-
FOUND =
|
| 96 |
except Exception as e: # noqa: BLE001
|
| 97 |
print("could not list the weights repository at start-up:", repr(e)[:200], flush=True)
|
| 98 |
FOUND = {}
|
|
|
|
| 99 |
|
| 100 |
# ----------------------------------------------------------------------------- encoders (CPU at import)
|
| 101 |
TOKENIZER = AutoTokenizer.from_pretrained(TEXT_ENCODER, revision=TEXT_REVISION)
|
| 102 |
TEXT_MODEL = T5EncoderModel.from_pretrained(TEXT_ENCODER, revision=TEXT_REVISION).eval()
|
| 103 |
VAE = AutoencoderKLFlux2.from_pretrained(VAE_REPO, subfolder=VAE_SUBFOLDER, revision=VAE_REVISION,
|
| 104 |
torch_dtype=torch.bfloat16).eval()
|
| 105 |
-
_LOADED = {} # (arm,
|
| 106 |
|
| 107 |
|
| 108 |
def fetch(key):
|
| 109 |
-
"""The
|
| 110 |
return hf_hub_download(REPO, FOUND[key])
|
| 111 |
|
| 112 |
|
|
@@ -124,21 +146,10 @@ def load_arm(key, path):
|
|
| 124 |
return _LOADED[key]
|
| 125 |
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
return
|
| 132 |
-
seed, step = parse_choice(labels[-1])
|
| 133 |
-
for arm in ARMS:
|
| 134 |
-
for w in ("raw", "ema"):
|
| 135 |
-
key = (arm, seed, step, w)
|
| 136 |
-
if key in FOUND:
|
| 137 |
-
load_arm(key, fetch(key))
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
try:
|
| 141 |
-
_preload_latest()
|
| 142 |
except Exception as e: # noqa: BLE001
|
| 143 |
print("preload skipped:", repr(e)[:200], flush=True)
|
| 144 |
|
|
@@ -169,7 +180,7 @@ def grid(images):
|
|
| 169 |
|
| 170 |
@spaces.GPU(duration=45)
|
| 171 |
def generate(prompt, jobs, seed, n, guidance, steps):
|
| 172 |
-
"""jobs: [(
|
| 173 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 174 |
out = {}
|
| 175 |
with torch.no_grad():
|
|
@@ -178,42 +189,45 @@ def generate(prompt, jobs, seed, n, guidance, steps):
|
|
| 178 |
noise = torch.stack([torch.randn(LATENT_SHAPE, generator=torch.Generator().manual_seed(seed + k))
|
| 179 |
for k in range(n)])
|
| 180 |
vae = VAE.to(device)
|
| 181 |
-
for
|
| 182 |
model, mean, std = load_arm(key, path)
|
| 183 |
model.to(device)
|
| 184 |
z = sample_latents(model, text, mask, noise, steps, guidance, device, use_amp=True, batch_size=8)
|
| 185 |
z_raw = z * std + mean
|
| 186 |
x = vae.decode(z_raw.to(device, torch.bfloat16)).sample.float()
|
| 187 |
-
out[
|
| 188 |
return out
|
| 189 |
|
| 190 |
|
| 191 |
-
def run(prompt,
|
| 192 |
prompt = (prompt or "").strip()
|
| 193 |
if not prompt:
|
| 194 |
raise gr.Error("Write a caption first.")
|
| 195 |
-
|
| 196 |
-
if
|
| 197 |
-
raise gr.Error("
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
| 211 |
order, note, tally)
|
| 212 |
|
| 213 |
|
| 214 |
def pick(side, order, tally):
|
| 215 |
-
if not order:
|
| 216 |
-
return "Generate a pair first.", tally
|
| 217 |
tally = dict(tally or {})
|
| 218 |
if side == "tie":
|
| 219 |
tally["tie"] = tally.get("tie", 0) + 1
|
|
@@ -225,47 +239,66 @@ def pick(side, order, tally):
|
|
| 225 |
|
| 226 |
def counts(tally):
|
| 227 |
tally = tally or {}
|
| 228 |
-
|
| 229 |
-
|
| 230 |
|
| 231 |
|
| 232 |
def reveal(order, tally):
|
| 233 |
if not order:
|
| 234 |
-
return "Generate
|
| 235 |
-
return "Left = %s, right = %s. %s" % (
|
| 236 |
|
| 237 |
|
| 238 |
-
def
|
| 239 |
-
global FOUND
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
try:
|
| 241 |
-
|
| 242 |
except Exception as e: # noqa: BLE001
|
| 243 |
-
return gr.update(), "Could not read the weights repository (%s); try
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
|
| 249 |
# ----------------------------------------------------------------------------- the page
|
| 250 |
with gr.Blocks(title="Agatha diffusion playground") as demo:
|
| 251 |
gr.Markdown("# Agatha diffusion playground\nAgatha and a plain transformer of the same size (about 42M parameters "
|
| 252 |
-
"each), trained the same way on COCO 2014 at 256 px.
|
|
|
|
| 253 |
"Non-commercial use only (trained on COCO photos).")
|
| 254 |
-
|
|
|
|
| 255 |
with gr.Row():
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
with gr.Row():
|
| 261 |
seed = gr.Number(value=0, precision=0, label="Seed")
|
| 262 |
n = gr.Slider(1, 4, value=4, step=1, label="Pictures per side")
|
| 263 |
guidance = gr.Slider(1.0, 7.0, value=3.0, step=0.5, label="Guidance")
|
| 264 |
steps = gr.Slider(10, 50, value=25, step=1, label="Sampling steps")
|
| 265 |
blind = gr.Checkbox(value=True, label="Blind (hide which side is which)")
|
| 266 |
-
|
| 267 |
-
go = gr.Button("Generate", variant="primary", scale=3)
|
| 268 |
-
refresh_btn = gr.Button("Refresh milestones", scale=1)
|
| 269 |
gr.Examples(EXAMPLES, inputs=prompt)
|
| 270 |
with gr.Row():
|
| 271 |
left = gr.Image(label="Left", type="pil", height=420)
|
|
@@ -279,14 +312,14 @@ with gr.Blocks(title="Agatha diffusion playground") as demo:
|
|
| 279 |
found_md = gr.Markdown(availability(FOUND))
|
| 280 |
order_state = gr.State([])
|
| 281 |
tally_state = gr.State({})
|
| 282 |
-
go.click(run, [prompt,
|
| 283 |
[left, right, order_state, status, tally_state])
|
| 284 |
b_left.click(lambda o, t: pick("left", o, t), [order_state, tally_state], [status, tally_state])
|
| 285 |
b_right.click(lambda o, t: pick("right", o, t), [order_state, tally_state], [status, tally_state])
|
| 286 |
b_tie.click(lambda o, t: pick("tie", o, t), [order_state, tally_state], [status, tally_state])
|
| 287 |
b_reveal.click(reveal, [order_state, tally_state], status)
|
| 288 |
-
refresh_btn.click(refresh,
|
| 289 |
-
demo.load(
|
| 290 |
|
| 291 |
if __name__ == "__main__":
|
| 292 |
demo.launch()
|
|
|
|
| 1 |
+
"""Agatha diffusion playground: any two checkpoints of the training runs side by side, from the same noise.
|
| 2 |
|
| 3 |
Weights: AbstractPhil/geofractal-agatha-diffusion-training, folder coco256/ (non-commercial: trained on COCO 2014 photos).
|
| 4 |
Code: github.com/AbstractEyes/geofractal, src/geofractal/router/prefab/agatha_v2, installed at the pinned commit below.
|
| 5 |
Sampling is the library's own sample_latents (the helper the training's picture sheets use), so a picture here matches a
|
| 6 |
+
sheet made at the same checkpoint, caption, seed, guidance and step count.
|
| 7 |
"""
|
|
|
|
| 8 |
import random
|
| 9 |
import re
|
| 10 |
import subprocess
|
|
|
|
| 48 |
LATENT_SHAPE = (32, 32, 32)
|
| 49 |
ARMS = ("agatha", "plain")
|
| 50 |
NAMES = {"agatha": "Agatha", "plain": "Plain transformer"}
|
| 51 |
+
NONE = "None"
|
| 52 |
+
FILE_RE = re.compile(r"^coco256/(agatha_v2_coco256_(agatha|plain)_s(\d+)(_rep)?)/\1_step(\d+)_(raw|ema)\.pt$")
|
| 53 |
+
KEEP_LOADED = 8 # checkpoints kept in memory per process (each about 170 MB)
|
| 54 |
EXAMPLES = ["A man riding a bicycle down a city street.", "A herd of elephants walking through tall grass.",
|
| 55 |
"A baseball player swinging a bat at a ball.", "A plate of food with broccoli and rice.",
|
| 56 |
"A red double decker bus driving down a street.", "Two dogs playing in the snow.",
|
| 57 |
"A kitchen with wooden cabinets and a white stove.", "A person riding a wave on a surfboard."]
|
| 58 |
|
| 59 |
|
| 60 |
+
# ----------------------------------------------------------------------------- the checkpoint list
|
| 61 |
+
def list_checkpoints():
|
| 62 |
+
"""{(arm, run, step, weights): path} for every milestone file in the weights repository."""
|
| 63 |
out = {}
|
| 64 |
for path in HfApi().list_repo_files(REPO):
|
| 65 |
m = FILE_RE.match(path)
|
| 66 |
if m:
|
| 67 |
+
out[(m.group(2), m.group(1), int(m.group(5)), m.group(6))] = path
|
| 68 |
return out
|
| 69 |
|
| 70 |
|
| 71 |
+
def label_of(key):
|
| 72 |
+
arm, run, step, weights = key
|
| 73 |
+
return "%s, %s, step %s, %s" % (NAMES[arm], run_words(run), format(step, ","), weights)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
+
def ordered(found):
|
| 77 |
+
"""Checkpoints by model, then run, newest step first, raw before averaged."""
|
| 78 |
+
return sorted(found, key=lambda k: (ARMS.index(k[0]), k[1], -k[2], k[3] != "raw"))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def catalog(found):
|
| 82 |
+
"""({label: key}, [labels in order])."""
|
| 83 |
+
keys = ordered(found)
|
| 84 |
+
return {label_of(k): k for k in keys}, [label_of(k) for k in keys]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def defaults(found):
|
| 88 |
+
"""The newest raw checkpoint of each model (seed 0 first); None for a model with nothing yet."""
|
| 89 |
+
out = []
|
| 90 |
+
for arm in ARMS:
|
| 91 |
+
keys = [k for k in ordered(found) if k[0] == arm and k[3] == "raw"]
|
| 92 |
+
out.append(label_of(keys[0]) if keys else NONE)
|
| 93 |
+
return out
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def run_words(run):
|
| 97 |
+
"""'agatha_v2_coco256_agatha_s0_rep' -> 'seed 0 (repeat)'."""
|
| 98 |
+
seed = re.search(r"_s(\d+)", run).group(1)
|
| 99 |
+
return "seed %s%s" % (seed, " (repeat)" if run.endswith("_rep") else "")
|
| 100 |
|
| 101 |
|
| 102 |
def availability(found):
|
| 103 |
parts = []
|
| 104 |
for arm in ARMS:
|
| 105 |
+
steps = {}
|
| 106 |
+
for k in found:
|
| 107 |
+
if k[0] == arm:
|
| 108 |
+
steps.setdefault(k[1], set()).add(k[2])
|
| 109 |
+
text = "; ".join("%s at %s" % (run_words(run), ", ".join(format(s, ",") for s in sorted(st)))
|
| 110 |
+
for run, st in sorted(steps.items())) or "none yet"
|
| 111 |
parts.append("**%s:** %s" % (NAMES[arm], text))
|
| 112 |
+
return "Checkpoints in the weights repository: " + " | ".join(parts)
|
| 113 |
|
| 114 |
|
| 115 |
try:
|
| 116 |
+
FOUND = list_checkpoints()
|
| 117 |
except Exception as e: # noqa: BLE001
|
| 118 |
print("could not list the weights repository at start-up:", repr(e)[:200], flush=True)
|
| 119 |
FOUND = {}
|
| 120 |
+
LABELS, ORDER = catalog(FOUND)
|
| 121 |
|
| 122 |
# ----------------------------------------------------------------------------- encoders (CPU at import)
|
| 123 |
TOKENIZER = AutoTokenizer.from_pretrained(TEXT_ENCODER, revision=TEXT_REVISION)
|
| 124 |
TEXT_MODEL = T5EncoderModel.from_pretrained(TEXT_ENCODER, revision=TEXT_REVISION).eval()
|
| 125 |
VAE = AutoencoderKLFlux2.from_pretrained(VAE_REPO, subfolder=VAE_SUBFOLDER, revision=VAE_REVISION,
|
| 126 |
torch_dtype=torch.bfloat16).eval()
|
| 127 |
+
_LOADED = {} # (arm, run, step, weights) -> (model, latent mean, latent std), this process only
|
| 128 |
|
| 129 |
|
| 130 |
def fetch(key):
|
| 131 |
+
"""The checkpoint file on local disk (the Hub's cache). Called outside the GPU function."""
|
| 132 |
return hf_hub_download(REPO, FOUND[key])
|
| 133 |
|
| 134 |
|
|
|
|
| 146 |
return _LOADED[key]
|
| 147 |
|
| 148 |
|
| 149 |
+
try: # the default pair, loaded at start-up so the first picture does not wait for it
|
| 150 |
+
for _label in defaults(FOUND):
|
| 151 |
+
if _label != NONE:
|
| 152 |
+
load_arm(LABELS[_label], fetch(LABELS[_label]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
except Exception as e: # noqa: BLE001
|
| 154 |
print("preload skipped:", repr(e)[:200], flush=True)
|
| 155 |
|
|
|
|
| 180 |
|
| 181 |
@spaces.GPU(duration=45)
|
| 182 |
def generate(prompt, jobs, seed, n, guidance, steps):
|
| 183 |
+
"""jobs: [(key, local path)]. Every checkpoint starts from the same noises (seeds seed .. seed + n - 1)."""
|
| 184 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 185 |
out = {}
|
| 186 |
with torch.no_grad():
|
|
|
|
| 189 |
noise = torch.stack([torch.randn(LATENT_SHAPE, generator=torch.Generator().manual_seed(seed + k))
|
| 190 |
for k in range(n)])
|
| 191 |
vae = VAE.to(device)
|
| 192 |
+
for key, path in jobs:
|
| 193 |
model, mean, std = load_arm(key, path)
|
| 194 |
model.to(device)
|
| 195 |
z = sample_latents(model, text, mask, noise, steps, guidance, device, use_amp=True, batch_size=8)
|
| 196 |
z_raw = z * std + mean
|
| 197 |
x = vae.decode(z_raw.to(device, torch.bfloat16)).sample.float()
|
| 198 |
+
out[key] = grid(((x + 1.0) / 2.0).clamp(0, 1).cpu())
|
| 199 |
return out
|
| 200 |
|
| 201 |
|
| 202 |
+
def run(prompt, a, b, seed, n, guidance, steps, blind, tally):
|
| 203 |
prompt = (prompt or "").strip()
|
| 204 |
if not prompt:
|
| 205 |
raise gr.Error("Write a caption first.")
|
| 206 |
+
chosen = [x for x in (a, b) if x and x != NONE]
|
| 207 |
+
if not chosen:
|
| 208 |
+
raise gr.Error("Choose at least one checkpoint.")
|
| 209 |
+
stale = [x for x in chosen if x not in LABELS]
|
| 210 |
+
if stale:
|
| 211 |
+
raise gr.Error("Not in the list any more: %s. Press Refresh." % ", ".join(stale))
|
| 212 |
+
keys = list(dict.fromkeys(LABELS[x] for x in chosen))
|
| 213 |
+
images = generate(prompt, [(k, fetch(k)) for k in keys], int(seed), int(n), float(guidance), int(steps))
|
| 214 |
+
if len(chosen) == 1:
|
| 215 |
+
order = [chosen[0], None]
|
| 216 |
+
note = "One checkpoint chosen: shown on the left."
|
| 217 |
+
else:
|
| 218 |
+
order = [a, b]
|
| 219 |
+
if blind:
|
| 220 |
+
random.shuffle(order)
|
| 221 |
+
note = "Which side is better? Pick, then reveal." if blind else "Shown by name (blind mode is off)."
|
| 222 |
+
show = [("Left", "Right")[i] if (blind and len(chosen) == 2) else (x or "No checkpoint") for i, x in enumerate(order)]
|
| 223 |
+
pictures = [images[LABELS[x]] if x else None for x in order]
|
| 224 |
+
return (gr.update(value=pictures[0], label=show[0]), gr.update(value=pictures[1], label=show[1]),
|
| 225 |
order, note, tally)
|
| 226 |
|
| 227 |
|
| 228 |
def pick(side, order, tally):
|
| 229 |
+
if not order or None in order:
|
| 230 |
+
return "Generate a pair of two checkpoints first.", tally
|
| 231 |
tally = dict(tally or {})
|
| 232 |
if side == "tie":
|
| 233 |
tally["tie"] = tally.get("tie", 0) + 1
|
|
|
|
| 239 |
|
| 240 |
def counts(tally):
|
| 241 |
tally = tally or {}
|
| 242 |
+
wins = ["%s: %d" % (k, v) for k, v in sorted(tally.items(), key=lambda kv: -kv[1]) if k != "tie"]
|
| 243 |
+
return "Picks this session: %s | ties: %d." % ("; ".join(wins) or "none yet", tally.get("tie", 0))
|
| 244 |
|
| 245 |
|
| 246 |
def reveal(order, tally):
|
| 247 |
if not order:
|
| 248 |
+
return "Generate first."
|
| 249 |
+
return "Left = %s, right = %s. %s" % (order[0], order[1] or "no checkpoint", counts(tally))
|
| 250 |
|
| 251 |
|
| 252 |
+
def _relist():
|
| 253 |
+
global FOUND, LABELS, ORDER
|
| 254 |
+
FOUND = list_checkpoints()
|
| 255 |
+
LABELS, ORDER = catalog(FOUND)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def refresh(a, b):
|
| 259 |
+
"""The Refresh button: re-read the list and keep each choice that is still in it."""
|
| 260 |
try:
|
| 261 |
+
_relist()
|
| 262 |
except Exception as e: # noqa: BLE001
|
| 263 |
+
return gr.update(), gr.update(), "Could not read the weights repository (%s); try again." % type(e).__name__
|
| 264 |
+
options = [NONE] + ORDER
|
| 265 |
+
d = defaults(FOUND)
|
| 266 |
+
a = a if a in options else d[0]
|
| 267 |
+
b = b if b in options else d[1]
|
| 268 |
+
return gr.update(choices=options, value=a), gr.update(choices=options, value=b), availability(FOUND)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def load_page():
|
| 272 |
+
"""A page load: the fresh list and the default pair (each model's newest checkpoint, None where it has none)."""
|
| 273 |
+
try:
|
| 274 |
+
_relist()
|
| 275 |
+
except Exception: # noqa: BLE001
|
| 276 |
+
pass
|
| 277 |
+
d = defaults(FOUND)
|
| 278 |
+
options = [NONE] + ORDER
|
| 279 |
+
return gr.update(choices=options, value=d[0]), gr.update(choices=options, value=d[1]), availability(FOUND)
|
| 280 |
|
| 281 |
|
| 282 |
# ----------------------------------------------------------------------------- the page
|
| 283 |
with gr.Blocks(title="Agatha diffusion playground") as demo:
|
| 284 |
gr.Markdown("# Agatha diffusion playground\nAgatha and a plain transformer of the same size (about 42M parameters "
|
| 285 |
+
"each), trained the same way on COCO 2014 at 256 px. Pick any two checkpoints (either model, any step, "
|
| 286 |
+
"raw or averaged weights) or one with None on the other side; both sides start from the same noise. "
|
| 287 |
"Non-commercial use only (trained on COCO photos).")
|
| 288 |
+
d0 = defaults(FOUND)
|
| 289 |
+
prompt = gr.Textbox(label="Caption", value=EXAMPLES[0])
|
| 290 |
with gr.Row():
|
| 291 |
+
ckpt_a = gr.Dropdown([NONE] + ORDER, value=d0[0], label="Checkpoint A")
|
| 292 |
+
ckpt_b = gr.Dropdown([NONE] + ORDER, value=d0[1], label="Checkpoint B")
|
| 293 |
+
refresh_btn = gr.Button("Refresh list", scale=0, min_width=140)
|
| 294 |
+
gr.Markdown("Early in training the raw weights are sharper; the averaged (EMA) weights catch up later.")
|
| 295 |
with gr.Row():
|
| 296 |
seed = gr.Number(value=0, precision=0, label="Seed")
|
| 297 |
n = gr.Slider(1, 4, value=4, step=1, label="Pictures per side")
|
| 298 |
guidance = gr.Slider(1.0, 7.0, value=3.0, step=0.5, label="Guidance")
|
| 299 |
steps = gr.Slider(10, 50, value=25, step=1, label="Sampling steps")
|
| 300 |
blind = gr.Checkbox(value=True, label="Blind (hide which side is which)")
|
| 301 |
+
go = gr.Button("Generate", variant="primary")
|
|
|
|
|
|
|
| 302 |
gr.Examples(EXAMPLES, inputs=prompt)
|
| 303 |
with gr.Row():
|
| 304 |
left = gr.Image(label="Left", type="pil", height=420)
|
|
|
|
| 312 |
found_md = gr.Markdown(availability(FOUND))
|
| 313 |
order_state = gr.State([])
|
| 314 |
tally_state = gr.State({})
|
| 315 |
+
go.click(run, [prompt, ckpt_a, ckpt_b, seed, n, guidance, steps, blind, tally_state],
|
| 316 |
[left, right, order_state, status, tally_state])
|
| 317 |
b_left.click(lambda o, t: pick("left", o, t), [order_state, tally_state], [status, tally_state])
|
| 318 |
b_right.click(lambda o, t: pick("right", o, t), [order_state, tally_state], [status, tally_state])
|
| 319 |
b_tie.click(lambda o, t: pick("tie", o, t), [order_state, tally_state], [status, tally_state])
|
| 320 |
b_reveal.click(reveal, [order_state, tally_state], status)
|
| 321 |
+
refresh_btn.click(refresh, [ckpt_a, ckpt_b], [ckpt_a, ckpt_b, found_md])
|
| 322 |
+
demo.load(load_page, None, [ckpt_a, ckpt_b, found_md])
|
| 323 |
|
| 324 |
if __name__ == "__main__":
|
| 325 |
demo.launch()
|