> For the complete documentation index, see [llms.txt](https://aisuko.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aisuko.gitbook.io/wiki/ai-techniques/stable-diffusion/vae.md).

# VAE

## Variational Autoencoder

{% hint style="info" %}
It is done using a technique called the <mark style="color:red;">**variational autoencoder. (VAE file)**</mark>
{% endhint %}

The VAE neural network has two parts:

* An encoder
* A decoder

The encoder compresses an image to a lower dimensional representation in the latent space. The decoder restores the image from the latent space.

<figure><img src="/files/sebGjkyl1WEwfOqeT8xP" alt=""><figcaption><p>Variational autoencoder transforms the image to and from the latent space.</p></figcaption></figure>

*<mark style="color:red;">**The latent space of the Stable Diffusion model is 4x64x64, 48 times smaller than the image pixel space**</mark>*. All the *<mark style="color:green;">**forward and reverse diffusions**</mark>* we talked about are done in the latent space.

And during training, *<mark style="color:red;">**instead of generating a noisy image, it generates a random tensor in latent space**</mark>* (latent noise). Instead of corrupting an image with noise, it corrupts the representation of the image in latent space with the latent noise. *<mark style="color:red;">**The reason for doing that is it is a lot faster since the latent space is smaller.**</mark>*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://aisuko.gitbook.io/wiki/ai-techniques/stable-diffusion/vae.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
