Skip to content

[Community] CPU Under Utilized #834

@WASasquatch

Description

@WASasquatch

Describe the bug

When using CPU as device, the CPU is very under utilized. I get about 50-66% utilization. The fans don't even need to turn on. Should I be running a special version of PyTorch, or?

image

Reproduction

# make sure you're logged in with `huggingface-cli login`
from diffusers import StableDiffusionPipeline
import subprocess, random, time, torch

prompt = "A beautiful 3d matte portrait of a _identity-adult_ warrior by Ilya Kuvshinov in a _color_ color scheme, featured on ArtStation"
neg_prompt = ""
width = 512
height = 640
steps = 50
cfg = 13.5
batches = 5
seed = -1
device = 'cpu'

print('Setting up Diffusion Pipeline...')
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", use_auth_token=True)
pipe = pipe.to(device)
pipe.enable_attention_slicing() # Tried on and off, seems to be no real difference in time of about 22m a image on Ryzen 5 2600
print('Pipeline setup complete.')


if seed == -1:
    seed = random.randint(0, 9999999999)

for batch in range(batches):
    if batch != 0:
        seed += 1
    gen_seed = torch.Generator(device).manual_seed(seed)
    print(f'Starting diffusion run {batch} of {batches} ...\n')
    print('PROMPT:')
    print(prompt+"\n")
    if neg_prompt != '':
        print('NEGATIVE PROMPT:')
        print(neg_prompt+"\n")
    image = pipe(prompt=prompt, negative_prompt=neg_prompt, num_inference_steps=steps, width=width, height=height, guidance_scale=cfg, generator=gen_seed).images[0]
    print('Diffusion Complete!')
    file = str(time.time())+"_result.png"
    print(f'Saving result as \'{file}\'\n')
    image.save(file)

Logs

No response

System Info

  • diffusers version: 0.4.2
  • Platform: Windows-10-10.0.22621-SP0
  • Python version: 3.10.2
  • PyTorch version (GPU?): 1.11.0+cpu (False)
  • Huggingface_hub version: 0.10.1
  • Transformers version: 4.23.1
  • Using GPU in script?: False
  • Using distributed or parallel set-up in script?: False

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions