stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

Stable diffusion with half precision

Open ulysses500 opened this issue 2 years ago • 1 comments

In img2img, if I change the image to float 16 using sd-v1-4.ckpt:

image = np.array(image).astype(np.float16)

I get this error:

--> init_latent = model.get_first_stage_encoding(model.encode_first_stage(init_image)
...
    449 if self.padding_mode != 'zeros':
    450     return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),
    451                     weight, bias, self.stride,
    452                     _pair(0), self.dilation, self.groups)
--> 453 return F.conv2d(input, weight, bias, self.stride,
    454                 self.padding, self.dilation, self.groups)

RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same

Does the current model support fp16 images? If yes, how can I change the weight type to be HalfTensor?

ulysses500 avatar Apr 07 '23 14:04 ulysses500

You can change the model to fp16 before inference.

CreamyLong avatar Feb 04 '24 11:02 CreamyLong