File size: 1,578 Bytes
4a1ea7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """Run-to-run reproducibility of a variant: the same request N times in one process; PSNR between consecutive runs (call 1 uses first-run kernels for the new shapes).
Usage: python repro_check.py --variant sft-int8 [--size 512] [--steps 0] [--repeat 3] [--device GPU]"""
import argparse
import os
import sys
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def psnr(a, b):
mse = np.mean((a.astype(np.float64) - b.astype(np.float64)) ** 2)
return 99.0 if mse == 0 else 10 * np.log10(255.0 ** 2 / mse)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--variant", default="sft-int8")
ap.add_argument("--size", type=int, default=512)
ap.add_argument("--steps", type=int, default=0)
ap.add_argument("--repeat", type=int, default=3)
ap.add_argument("--device", default="GPU")
ap.add_argument("--prompt", default="A red fox sitting in fresh snow at sunrise, photograph")
a = ap.parse_args()
from moss_pipeline import VARIANTS, MossImage
pipe = MossImage(device=a.device, variant=a.variant, log=lambda *x: None)
steps = a.steps or VARIANTS[a.variant]["default_steps"]
imgs = []
for i in range(a.repeat):
img, st = pipe.generate(a.prompt, "", a.size, a.size, steps, 3.0, 7)
imgs.append(img)
extra = f" PSNR vs previous run {psnr(imgs[-2], img):.1f} dB" if i else ""
print(f"[repro] {a.variant} {a.size}x{a.size} {steps} steps run {i + 1}: {st['denoise_s']} s, mean {img.mean():.1f}{extra}", flush=True)
if __name__ == "__main__":
main()
|