Skip to content

Instantly share code, notes, and snippets.

@madebyollin
madebyollin / notes_on_sd_vae.md
Last active April 23, 2024 06:21
notes_on_sd_vae

Notes / Links about Stable Diffusion VAE

Stable Diffusion's VAE is a neural network that encodes and decodes images into a compressed "latent" format. The encoder performs 48x lossy compression, and the decoder generates new detail to fill in the gaps.

(Calling this model a "VAE" is sort of a misnomer - it's an encoder with some very slight KL regularization, and a conditional GAN decoder)

This document is a big pile of various links with more info.

VAE Versions & Lineage

  • CompVis
@madebyollin
madebyollin / Mamba_Diffusion_IADB_Colab.ipynb
Created December 6, 2023 04:47
Mamba Diffusion (IADB)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Variational Autoencoders Will Never Work

So you want to generate images with neural networks. You're in luck! VAEs are here to save the day. They're simple to implement, they generate images in one inference step (unlike those awful slow autoregressive models) and (most importantly) VAEs are 🚀🎉🎂🥳 theoretically grounded 🚀🎉🎂🥳 (unlike those scary GANs - don't look at the GANs)!

The idea

The idea of VAE is so simple, even an AI chatbot could explain it:

  1. Your goal is to train a "decoder" neural network that consumes blobs of random noise from a fixed distribution (like torch.randn(1024)), interprets that noise as decisions about what to generate, and produces corresponding real-looking images. You want to train this network with nice simple image-space MSE loss against your dataset of real images.
@madebyollin
madebyollin / README.md
Last active April 2, 2024 13:50 — forked from mrsteyk/README.md
dalle_runner_api.model_infra.modules.public_diff_vae
@madebyollin
madebyollin / make_audiobook.py
Last active March 23, 2024 17:17
Converts an epub or text file to audiobook via Google Cloud TTS
#!/usr/bin/env python3
"""
To use:
1. install/set-up the google cloud api and dependencies listed on https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/texttospeech/cloud-client
2. install pandoc and pypandoc, also tqdm
3. create and download a service_account.json ("Service account key") from https://console.cloud.google.com/apis/credentials
4. run GOOGLE_APPLICATION_CREDENTIALS=service_account.json python make_audiobook.py book_name.epub
"""
import re
import sys
@madebyollin
madebyollin / automatic_profiling_markers.py
Created February 27, 2024 02:57
Add human-readable profiling markers to a pytorch module
def add_profiling_markers(model):
"""Monkey-patch profiling markers into an nn.Module.
Args:
model: an nn.Module
Effect:
all model.named_module() forward calls get wrapped in their
own profiling scope, making traces easier to understand.
"""
#!/usr/bin/env python
import numpy as np
import cv2
from scipy.signal import convolve2d
from skimage import color, data, restoration
import console
# read input
frame = cv2.imread("input.jpg").astype(np.float32) / 255.0
@madebyollin
madebyollin / stable_diffusion_m1.py
Last active February 10, 2024 02:25
Stable Diffusion on Apple Silicon GPUs via CoreML; 2s / step on M1 Pro
# ------------------------------------------------------------------
# EDIT: I eventually found a faster way to run SD on macOS, via MPSGraph (~0.8s / step on M1 Pro):
# https://github.com/madebyollin/maple-diffusion
# The original CoreML-related code & discussion is preserved below :)
# ------------------------------------------------------------------
# you too can run stable diffusion on the apple silicon GPU (no ANE sadly)
#
# quick test portraits (each took 50 steps x 2s / step ~= 100s on my M1 Pro):
# * https://i.imgur.com/5ywISvm.png
@madebyollin
madebyollin / list_of_good_image_generator_training_logs.md
Last active February 10, 2024 02:25
List of good image generator training logs

List of good image generator training logs

A list of public training logs from neural network image generation models, since I think they're interesting.

The Criteria

  • Publicly accessible link
  • Losses plotted every so often
  • Samples generated every so often
  • Nontrivial dataset (i.e. not MNIST - 64x64 output RGB or better)