pixelgen2 / experiments /count_outputs.py
DJLougen's picture
PixelGen2: compositional hand-weighted pixel-art generator + 4 scaling experiments
6fbb543 verified
Raw History Blame Contribute Delete
2.04 kB
"""Enumerate PixelGen vs PixelGen2 output space at seed 0 and count distinct images."""
import itertools
import sys
import time
import numpy as np
sys.path.insert(0, ".")
from pixelgen.compose import PixelGen2 # noqa: E402
from pixelgen.model import PixelGen # noqa: E402
from pixelgen.palette import RAMP_NAMES # noqa: E402
from pixelgen.parts import ACCESSORIES # noqa: E402
from pixelgen.templates import CLASSES # noqa: E402
from pixelgen.tokenizer import ACCESSORY_SYNONYMS # noqa: E402
def distinct(model, prompts, bs=512):
seen = set()
for i in range(0, len(prompts), bs):
chunk = prompts[i:i + bs]
imgs = model.generate(chunk, [0] * len(chunk), scale=1)
for im in imgs:
seen.add(im.tobytes())
return len(seen)
m1, m2 = PixelGen(), PixelGen2()
p1 = sum(p.numel() for p in m1.parameters()); b1 = sum(b.numel() for b in m1.buffers())
p2 = sum(p.numel() for p in m2.parameters()); b2 = sum(b.numel() for b in m2.buffers())
base = [f"{r} {c}" for c in CLASSES for r in RAMP_NAMES]
t = time.perf_counter(); d1 = distinct(m1, base)
print(f"PixelGen : {p1:,} params + {b1:,} buffers | {len(base):,} prompts -> {d1:,} distinct images ({time.perf_counter()-t:.1f}s)")
acc_word = {a: ws[0] for a, ws in ACCESSORY_SYNONYMS.items() if ws}
comp = []
for c, r, size in itertools.product(CLASSES, RAMP_NAMES, ["", "small "]):
comp.append(f"{size}{r} {c}")
for a, r2 in itertools.product(acc_word, RAMP_NAMES):
comp.append(f"{size}{r} {c} with {r2} {acc_word[a]}")
t = time.perf_counter(); d2 = distinct(m2, comp)
print(f"PixelGen2: {p2:,} params + {b2:,} buffers | {len(comp):,} prompts -> {d2:,} distinct images ({time.perf_counter()-t:.1f}s)")
print(f"\nhand-drawn content: {len(CLASSES)} bodies + {len(ACCESSORIES)-1} parts = {len(CLASSES)+len(ACCESSORIES)-1} templates")
print(f"distinct images per template: PixelGen {d1/len(CLASSES):.0f} PixelGen2 {d2/(len(CLASSES)+len(ACCESSORIES)-1):.0f}")
print(f"param growth {p2/p1:.2f}x output growth {d2/d1:.1f}x")