stable diffusion: remove realizes we don't need

This commit is contained in:
2023-07-20 19:53:07 -07:00
parent b58dd015e3
commit f45013f0a3
2 changed files with 3 additions and 9 deletions
+2 -8
View File
@@ -102,7 +102,6 @@ class Decoder:
return self.conv_out(self.norm_out(x).swish())
class Encoder:
def __init__(self):
sz = [(128, 128), (128, 256), (256, 512), (512, 512)]
@@ -338,7 +337,6 @@ class UNetModel:
for bb in b:
x = run(x, bb)
saved_inputs.append(x)
x.realize()
for bb in self.middle_block:
x = run(x, bb)
for i,b in enumerate(self.output_blocks):
@@ -346,7 +344,6 @@ class UNetModel:
x = x.cat(saved_inputs.pop(), dim=1)
for bb in b:
x = run(x, bb)
x.realize()
return x.sequential(self.out)
class CLIPMLP:
@@ -586,8 +583,6 @@ class StableDiffusion:
# cond_stage_model.transformer.text_model
# this is sd-v1-4.ckpt
#FILENAME = "/Users/kafka/fun/mps/stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt"
#FILENAME = "/home/kafka/model.ckpt"
FILENAME = Path(__file__).parent.parent / "weights/sd-v1-4.ckpt"
if __name__ == "__main__":
@@ -619,8 +614,8 @@ if __name__ == "__main__":
def get_model_output(latent, timestep):
# put into diffuser
unconditional_latent = model.model.diffusion_model(latent, timestep, unconditional_context).realize()
latent = model.model.diffusion_model(latent, timestep, context).realize()
unconditional_latent = model.model.diffusion_model(latent, timestep, unconditional_context)
latent = model.model.diffusion_model(latent, timestep, context)
unconditional_guidance_scale = 7.5
e_t = unconditional_latent + unconditional_guidance_scale * (latent - unconditional_latent)
@@ -636,7 +631,6 @@ if __name__ == "__main__":
a_t, a_prev = alphas[index], alphas_prev[index]
sigma_t = 0
sqrt_one_minus_at = math.sqrt(1-a_t)
sqrt_one_minus_at = Tensor([sqrt_one_minus_at]).realize() # don't constant fold this
#print(a_t, a_prev, sigma_t, sqrt_one_minus_at)
pred_x0 = (x - sqrt_one_minus_at * e_t) / math.sqrt(a_t)
+1 -1
View File
@@ -47,7 +47,7 @@ class TestRealWorld(unittest.TestCase):
derandomize_model(model)
@TinyJit
def test(t, t2): return model(t, 801, t2).realize()
helper_test("test_sd", lambda: (Tensor.randn(1, 4, 64, 64),Tensor.randn(1, 77, 768)), test, 14.04, 912)
helper_test("test_sd", lambda: (Tensor.randn(1, 4, 64, 64),Tensor.randn(1, 77, 768)), test, 14.5, 924)
@unittest.skipUnless(Device.DEFAULT in JIT_SUPPORTED_DEVICE, "needs JIT")
def test_llama(self):