carrot/tinygrad_repo/test/external/external_benchmark_load_stable_diffusion.py
Vehicle Researcher 4fca6dec8e openpilot v0.9.8 release
date: 2025-01-29T09:09:56
master commit: 227bb68e1891619b360b89809e6822d50d34228f
2025-01-29 09:09:58 +00:00

14 lines
565 B
Python

from tinygrad.helpers import fetch, Timing
from tinygrad.device import Device
from tinygrad.nn.state import torch_load, load_state_dict
from examples.stable_diffusion import StableDiffusion
# run "sudo purge" before testing on OS X to avoid the memory cache
if __name__ == "__main__":
fn = fetch('https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt', 'sd-v1-4.ckpt')
model = StableDiffusion()
with Timing():
load_state_dict(model, torch_load(fn)['state_dict'], strict=False)
Device[Device.DEFAULT].synchronize()