CompVis / stable-diffusion

A latent text-to-image diffusion model
https://ommer-lab.com/research/latent-diffusion-models/
Other
66.8k stars 9.99k forks source link

"LayerNormKernelImpl" not implemented for 'Half' #307

Open 2424004764 opened 1 year ago

2424004764 commented 1 year ago

my code:

` import torch from torch import autocast from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler

model_id = "CompVis/stable-diffusion-v1-4"
# model_id = "KoboldAI/GPT-J-6B-Adventure"
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print("running on {}".format(device))

use_auth_token = "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"
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear",
                                 num_train_timesteps=1000)
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16,
                                               revision="fp16",
                                               use_auth_token=use_auth_token)
pipe = pipe.to(device)

prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cpu"):
    # image = pipe(prompt).images[0]
    image = pipe(prompt, guidance_scale=7.5)

image.save("astronaut_rides_horse.png")`

run error: "LayerNormKernelImpl" not implemented for 'Half'

Naveen1k commented 1 year ago

my code:

` import torch from torch import autocast from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler

model_id = "CompVis/stable-diffusion-v1-4"
# model_id = "KoboldAI/GPT-J-6B-Adventure"
device = 'cuda' if torch.cuda.is_available() else 'cpu'
print("running on {}".format(device))

use_auth_token = "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"
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear",
                                 num_train_timesteps=1000)
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16,
                                               revision="fp16",
                                               use_auth_token=use_auth_token)
pipe = pipe.to(device)

prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cpu"):
    # image = pipe(prompt).images[0]
    image = pipe(prompt, guidance_scale=7.5)

image.save("astronaut_rides_horse.png")`

run error: "LayerNormKernelImpl" not implemented for 'Half'

in which file did u find this code in stable diffusion

Naveen1k commented 1 year ago

please reply i know how to solve it

DaburuTori commented 1 year ago

"LayerNormKernelImpl" not implemented for 'Half' happens for me when i try generating something.

Naveen1k commented 1 year ago

"LayerNormKernelImpl" not implemented for 'Half' happens for me when i try generating something.

yeah I have same error, but please guide me, what is the path of that file from which u posted the code In stable diffusion folder

DaburuTori commented 1 year ago

txt2img: mario Error completing request Arguments: ('mario', '', 'None', 'None', 20, 0, False, False, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, False, False, 0.7, 0, False, False, None, '', 1, '', 4, '', True, False) {} Traceback (most recent call last): File "C:\Users\szymo\Documents\SDLocal\modules\ui.py", line 153, in f res = list(func(*args, kwargs)) File "C:\Users\szymo\Documents\SDLocal\webui.py", line 63, in f res = func(*args, kwargs) File "C:\Users\szymo\Documents\SDLocal\modules\txt2img.py", line 41, in txt2img processed = process_images(p) File "C:\Users\szymo\Documents\SDLocal\modules\processing.py", line 351, in process_images uc = prompt_parser.get_learned_conditioning(len(prompts) [p.negative_prompt], p.steps) File "C:\Users\szymo\Documents\SDLocal\modules\prompt_parser.py", line 104, in get_learned_conditioning conds = shared.sd_model.get_learned_conditioning(texts) File "C:\Users\szymo\Documents\SDLocal\repositories\stable-diffusion\ldm\models\diffusion\ddpm.py", line 558, in get_learned_conditioning c = self.cond_stage_model(c) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(input, kwargs) File "C:\Users\szymo\Documents\SDLocal\modules\sd_hijack.py", line 490, in forward outputs = self.wrapped.transformer(input_ids=tokens) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, kwargs) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\transformers\models\clip\modeling_clip.py", line 722, in forward return self.text_model( File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, kwargs) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\transformers\models\clip\modeling_clip.py", line 643, in forward encoder_outputs = self.encoder( File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, *kwargs) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\transformers\models\clip\modeling_clip.py", line 574, in forward layer_outputs = encoder_layer( File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(input, kwargs) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\transformers\models\clip\modeling_clip.py", line 316, in forward hidden_states = self.layer_norm1(hidden_states) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\modules\normalization.py", line 189, in forward return F.layer_norm( File "C:\Users\szymo\Documents\SDLocal\venv\lib\site-packages\torch\nn\functional.py", line 2503, in layer_norm return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled) RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'

leszczyn commented 1 year ago

any solution?

BitBonker commented 1 year ago

any solution?

Solved: Add --precision full --no-half to the command line

popoala commented 1 year ago

any solution?

Solved: Add --precision full --no-half to the command line

How to "Add --precision full --no-half" with function like:

pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16, revision="fp16", use_auth_token=use_auth_token) pipe = pipe.to(device)

prompt = "a photo of an astronaut riding a horse on mars" with autocast("cpu"):

image = pipe(prompt).images[0]

image = pipe(prompt, guidance_scale=7.5)