question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'AutoencoderKLOutput' object has no attribute 'sample'

See original GitHub issue

Describe the bug

running notebook https://colab.research.google.com/github/patil-suraj/Notebooks/blob/master/image_2_image_using_diffusers.ipynb

when running this cell (after previously run all the preceding cell )

generator = torch.Generator(device=device).manual_seed(1024) with autocast(“cuda”): images = pipe(prompt=prompt, init_image=init_image, generator=generator)[“sample”] ! images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5, generator=generator)[“sample”]

I get this output


AttributeError Traceback (most recent call last) <ipython-input-18-01521f904f0c> in <module> 1 generator = torch.Generator(device=device).manual_seed(1024) 2 with autocast(“cuda”): ----> 3 images = pipe(prompt=prompt, init_image=init_image, generator=generator)[“sample”] 4 get_ipython().system(’ images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5, generator=generator)[“sample”]')

1 frames <ipython-input-5-4fb8144e2978> in call(self, prompt, init_image, strength, num_inference_steps, guidance_scale, eta, generator, output_type) 56 57 # encode the init image into latents and scale the latents —> 58 init_latents = self.vae.encode(init_image.to(self.device)).sample() 59 init_latents = 0.18215 * init_latents 60

AttributeError: ‘AutoencoderKLOutput’ object has no attribute ‘sample’

Reproduction

generator = torch.Generator(device=device).manual_seed(1024) with autocast(“cuda”): images = pipe(prompt=prompt, init_image=init_image, generator=generator)[“sample”] ! images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5, generator=generator)[“sample”]

Logs

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-01521f904f0c> in <module>
      1 generator = torch.Generator(device=device).manual_seed(1024)
      2 with autocast("cuda"):
----> 3     images = pipe(prompt=prompt, init_image=init_image, generator=generator)["sample"]
      4 get_ipython().system('    images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5, generator=generator)["sample"]')

1 frames
<ipython-input-5-4fb8144e2978> in __call__(self, prompt, init_image, strength, num_inference_steps, guidance_scale, eta, generator, output_type)
     56 
     57         # encode the init image into latents and scale the latents
---> 58         init_latents = self.vae.encode(init_image.to(self.device)).sample()
     59         init_latents = 0.18215 * init_latents
     60 

AttributeError: 'AutoencoderKLOutput' object has no attribute 'sample'

System Info

Same colab as its on this site as yesterday.

Thu Sep 8 17:43:09 2022
±----------------------------------------------------------------------------+ | NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 | |-------------------------------±---------------------±---------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 | | N/A 37C P8 9W / 70W | 0MiB / 15109MiB | 0% Default | | | | N/A |

the libs intsalled

!pip install -qq -U diffusers transformers ftfy !pip install -qq “ipywidgets>=7,<8”

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
patrickvonplatencommented, Sep 8, 2022
1reaction
WASasquatchcommented, Sep 8, 2022

I’m assuming you’re using the old image 2 image script, like I was doing on Easy Diffusion. This is no longer needed. You can just import the image 2 image pipeline.

from diffusers import StableDiffusionImg2ImgPipeline   
Read more comments on GitHub >

github_iconTop Results From Across the Web

This Error with AutoEncoder started happening just hours ago
... 59 init_latents = 0.18215 * init_latents 60 AttributeError: 'AutoencoderKLOutput' object has no attribute 'sample'.
Read more >
CompVis/stable-diffusion-v1-4 · AttributeError - Hugging Face
AttributeError : 'AutoencoderKLOutput' object has no attribute 'mode' #127 · ```.
Read more >
AttributeError: 'module' object has no attribute 'sample'
Sounds like an import issue. Is there another module in the same directory named random(.py)? If so, you need to (re)move this file....
Read more >
[open] AttributeError: 'module' object has no attribute 'sample'
Hi, I'am working on a gaze-contingent project and was really happy to read that PyGaze can help me because I just begin to...
Read more >
HuggingFace has added textual inversion to their diffusers ...
At this point , getting an AttributeError: 'AutoencoderKLOutput' object has no attribute 'sample'. Has anyone faced this too?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found