• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Home of `erlich` and `ongo`. Finetune latent-diffusion/glid-3-xl text2image on your own data.

ldm-finetune

CompVis latent-diffusion finetuned on art (ongo), logo (erlich) and pixel-art (puck) generation.

This repo is modified from glid-3-xl. Aesthetic CLIP embeds are provided by aesthetic-predictor

Quick start (docker required)

The following command will download all weights and run a prediction with your inputs inside a proper docker container.

cog predict r8.im/laion-ai/erlich \
  -i prompt="an armchair in the form of an avocado" \
  -i negative="" \
  -i init_image=@path/to/image \
  -i mask=@path/to/mask \
  -i guidance_scale=5.0 \
  -i steps=100 \
  -i batch_size=4 \
  -i width=256 \
  -i height=256 \
  -i init_skip_fraction=0.0 \
  -i aesthetic_rating=9 \
  -i aesthetic_weight=0.5 \
  -i seed=-1 \
  -i intermediate_outputs=False

Valid remote image URL's are:

  • r8.im/laion-ai/erlich
  • r8.im/laion-ai/ongo
  • r8.im/laion-ai/puck

Setup

Prerequisites

Please ensure the following dependencies are installed prior to building this repo:

  • build-essential
  • libopenmpi-dev
  • liblzma-dev
  • zlib1g-dev

Pytorch

It's a good idea to use a virtual environment or a conda environment.

python3 -m venv .venv
source venv/bin/activate
(venv) $

Before installing, you should install pytorch manually by following the instructions at pytorch.org

(venv) $ pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

To check your cuda version, run nvidia-smi.

Install ldm-finetune

You can now install this repo by running pip install -e . in the project directory.

(venv) $ git clone https://github.com/laion-ai/ldm-finetune.git
(venv) $ cd ldm-finetune
(venv) $ pip install -e .
(venv) $ pip install -r requirements.txt

Checkpoints

Foundation/Backbone models:

# OpenAI CLIP ViT-L/14
wget -P /root/.cache/clip "https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt

### BERT Text Encoder
wget --continue https://dall-3.com/models/glid-3-xl/bert.pt

### kl-f8 VAE backbone
wget --continue https://dall-3.com/models/glid-3-xl/kl-f8.pt

Latent Diffusion Stage 2 (diffusion)

There are several stage 2 checkpoints to choose from:

(recommended) jack000 - inpaint.pt

The second finetune from jack000's glid-3-xl adds support for inpainting and can be used for unconditional output as well by setting the inpaint image_embed to zeros. Additionally finetuned to use the CLIP text embed via cross-attention (similar to unCLIP).

wget --continue https://dall-3.com/models/glid-3-xl/inpaint.pt

LAION Finetuning Checkpoints

Laion also finetuned inpaint.pt with the aim of improving logo generation and painting generation.

Erlich

erlich is inpaint.pt finetuned on a dataset collected from LAION-5B named Large Logo Dataset. It consists of roughly 100K images of logos with captions generated via BLIP using aggressive re-ranking and filtering.

wget --continue -O erlich.pt https://huggingface.co/laion/erlich/resolve/main/model/ema_0.9999_120000.pt

"You know aviato?"

Ongo

Ongo is inpaint.pt finetuned on the Wikiart dataset consisting of about 100K paintings with captions generated via BLIP using aggressive re-ranking and filtering. We also make use of the original captions which contain the author name and the painting title.

wget https://huggingface.co/laion/ongo/resolve/main/ongo.pt

"Ongo Gablogian, the art collector. Charmed, I'm sure."

LAION - puck.pt

puck has been trained on pixel art. While the underlying kl-f8 encoder seems to struggle somewhat with pixel art, results are still interesting.

wget https://huggingface.co/laion/puck/resolve/main/puck.pt

Other

### CompVis - `diffusion.pt`
# The original checkpoint from CompVis trained on `LAION-400M`. May output watermarks.
wget --continue https://dall-3.com/models/glid-3-xl/diffusion.pt

### jack000 - `finetune.pt`
# The first finetune from jack000's [glid-3-xl](https://github.com/jack000/glid-3-xl). Modified to accept a CLIP text embed and finetuned on curated data to help with watermarks. Doesn't support inpainting.
# wget https://dall-3.com/models/glid-3-xl/finetune.pt 

Generating images

You can run prediction via python or docker. Currently the docker method is best supported.

Docker/cog

If you have access to a linux machine (or WSL2.0 on Windows 11) with docker installed, you can very easily run models by installing cog:

sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m`
sudo chmod +x /usr/local/bin/cog

Modify the MODEL_PATH in cog_sample.py:

MODEL_PATH = "erlich.pt"  # Can be erlich, ongo, puck, etc.

Now you can run predictions via docker container using:

cog predict -i prompt="a logo of a fox made of fire"

Output will be returned as a base64 string at the end of generation and is also saved locally at current_{batch_idx}.png

Flask API

If you'd like to stand up your own ldm-finetune Flask API, you can run:

cog build -t my_ldm_image
docker run -d -p 5000:5000 --gpus all my_ldm_image

Predictions can then be accessed via HTTP:

curl http://localhost:5000/predictions -X POST \
    -H 'Content-Type: application/json' \
    -d '{"input": {"prompt": "a logo of a fox made of fire"}}'

The output from the API will be a list of base64 strings representing your generations.

Python

You can also use the standalone python scripts from glid-3-xl.

# fast PLMS sampling
(venv) $ python sample.py --model_path erlich.pt --batch_size 6 --num_batches 6 --text "a cyberpunk girl with a scifi neuralink device on her head"

# sample with an init image
(venv) $ python sample.py --init_image picture.jpg --skip_timesteps 10 --model_path ongo.pt --batch_size 6 --num_batches 6 --text "a cyberpunk girl with a scifi neuralink device on her head"

Autoedit

Autoedit uses the inpaint model to give the ldm an image prompting function (that works differently from --init_image) It continuously edits random parts of the image to maximize clip score for the text prompt

$ (venv) python autoedit.py \
    --model_path inpaint.pt --kl_path kl-f8.pt --bert_path bert.pt \
    --text "high quality professional pixel art" --negative "" --prefix autoedit_generations \
    --batch_size 16 --width 256 --height 256 --iterations 25 \
    --starting_threshold 0.6 --ending_threshold 0.5 \
    --starting_radius 5 --ending_radius 0.1 \
    --seed -1 --guidance_scale 5.0 --steps 30 \
    --aesthetic_rating 9 --aesthetic_weight 0.5 --wandb_name my_autoedit_wandb_artifact

Finetuning

See the script below for an example of finetuning your own model from one of the available chekcpoints.

Finetuning Tips/Tricks

  • NVIDIA GPU required. You will need an A100 or better to use a batch size of 64. Using less may present stability issues.
  • Monitor the grad_norm in the output log. If it ever goes above 1.0 the checkpoint may be ruined due to exploding gradients.
    • to fix, try reducing the learning rate, decreasing the batch size.
      • Train in 32-bit
      • Resume with saved optimizer state when possible.
#!/bin/bash
# Finetune glid-3-xl inpaint.pt on your own webdataset.
# Note: like all one-off scripts, this is likely to become out of date at some point.
# running python scripts/image_train_inpaint.py --help will give you more info.

# model flags
use_fp16=False # TODO can cause more trouble than it's worth.
MODEL_FLAGS="--dropout 0.1 --attention_resolutions 32,16,8 --class_cond False --diffusion_steps 1000 --image_size 32 --learn_sigma False --noise_schedule linear --num_channels 320 --num_heads 8 --num_res_blocks 2 --resblock_updown False --use_fp16 $use_fp16 --use_scale_shift_norm False"

# checkpoint flags
resume_checkpoint="inpaint.pt"
kl_model="kl-f8.pt"
bert_model="bert.pt"

# training flags
epochs=80
shard_size=512
batch_size=32
microbatch=-1
lr=1e-6 # lr=1e-5 seems to be stable. going above 3e-5 is not stable.
ema_rate=0.9999 # TODO you may want to lower this to 0.999, 0.99, 0.95, etc.
random_crop=False
random_flip=False
cache_dir="cache"
image_key="jpg"
caption_key="txt"
data_dir=/my/custom/webdataset/ # TODO set this to a real path

# interval flags
sample_interval=100
log_interval=1
save_interval=2000

CKPT_FLAGS="--kl_model $kl_model --bert_model $bert_model --resume_checkpoint $resume_checkpoint"
INTERVAL_FLAGS="--sample_interval $sample_interval --log_interval $log_interval --save_interval $save_interval"
TRAIN_FLAGS="--epochs $epochs --shard_size $shard_size --batch_size $batch_size --microbatch $microbatch --lr $lr --random_crop $random_crop --random_flip $random_flip --cache_dir $cache_dir --image_key $image_key --caption_key $caption_key --data_dir $data_dir"
COMBINED_FLAGS="$MODEL_FLAGS $CKPT_FLAGS $TRAIN_FLAGS $INTERVAL_FLAGS"
export OPENAI_LOGDIR=./erlich_on_pixel_logs_run6_part2/
export TOKENIZERS_PARALLELISM=false

# TODO comment out a line below to train either on a single GPU or multi-GPU
# single GPU
# python scripts/image_train_inpaint.py $COMBINED_FLAGS

# or multi-GPU
# mpirun -n 8 python scripts/image_train_inpaint.py $COMBINED_FLAGS

More Repositories

1

Open-Assistant

OpenAssistant is a chat-based assistant that understands tasks, can interact with third-party systems, and retrieve information dynamically to do so.
Python
37,011
star
2

audio-dataset

Audio Dataset for training CLAP and other models
Python
616
star
3

CLIP_benchmark

CLIP-like model evaluation
Jupyter Notebook
601
star
4

dalle2-laion

Pretrained Dalle2 from laion
Python
499
star
5

CLAP

Contrastive Language-Audio Pretraining
Python
479
star
6

natural_voice_assistant

Python
439
star
7

laion-3d

Collect large 3d dataset and build models
253
star
8

phenaki

A phenaki reproduction using pytorch.
Python
218
star
9

aesthetic-predictor

A linear estimator on top of clip to predict the aesthetic quality of pictures
Jupyter Notebook
199
star
10

Open-Instruction-Generalist

Open Instruction Generalist is an assistant trained on massive synthetic instructions to perform many millions of tasks
Python
195
star
11

scaling-laws-openclip

Reproducible scaling laws for contrastive language-image learning (https://arxiv.org/abs/2212.07143)
Jupyter Notebook
152
star
12

CLIP-based-NSFW-Detector

Python
135
star
13

laion-datasets

Description and pointers of laion datasets
HTML
131
star
14

laion-dreams

Aim for the moon. If you miss, you may hit a star.
121
star
15

laion.ai

HTML
110
star
16

AIW

Alice in Wonderland code base for experiments and raw experiments data
Python
108
star
17

LAION-5B-WatermarkDetection

Python
102
star
18

video-clip

Let's make a video clip
92
star
19

Open-GIA

O-GIA is an umbrella for research, infrastructure and projects ecosystem that should provide open source, reproducible datasets, models, applications & safety tools for Open Generalist Interactive Agents (O-GIA). O-GIA systems will act in collaboration with human or autonomously, supporting various kind of validated decision making and assistance.
91
star
20

General-GPT

Jupyter Notebook
64
star
21

Discord-Scrapers

Implementation of a discord channel scraper to generate datasets.
Python
60
star
22

Text-to-speech

Python
58
star
23

Big-Interleaved-Dataset

Big-Interleaved-Dataset
Python
57
star
24

riverbed

Tools for content datamining and NLP at scale
Python
41
star
25

OCR-ensemble

Jupyter Notebook
38
star
26

Conditional-Pretraining-of-Large-Language-Models

Python
37
star
27

interesting-text-datasets

33
star
28

blade2blade

Adversarial Training and SFT for Bot Safety Models
Python
32
star
29

temporal-embedding-aggregation

Aggregating embeddings over time
Python
31
star
30

deep-image-diffusion-prior

Inverts CLIP text embeds to image embeds and visualizes with deep-image-prior.
Jupyter Notebook
31
star
31

watermark-detection

A repository containing datasets and tools to train a watermark classifier.
Python
31
star
32

medical

This repository will be a summary and outlook on all our open, medical, AI advancements.
Jupyter Notebook
28
star
33

Anh

Anh - LAION's multilingual assistant datasets and models
Python
27
star
34

laion50BU

Un-*** 50 billions multimodality dataset
24
star
35

conditioned-prior

(wip) Use LAION-AI's CLIP "conditoned prior" to generate CLIP image embeds from CLIP text embeds.
Python
18
star
36

LAION-SAFETY

An open toolbox for NSFW & toxicity detection
Jupyter Notebook
16
star
37

opendream

Frontend (and soon also midleware and backend) for a new, opensource image generation platform.
TypeScript
14
star
38

laion5B-paper

Building the laion5B paper
13
star
39

laion-dedup

Python
13
star
40

notebooks

A collection of generative and training notebooks getting mirrored to google colab.
Jupyter Notebook
12
star
41

laionide

This repository contains training code and checkpoitns for finetuning glide.
Python
12
star
42

super-resolution

This is the LAION repository for creating open super-resolution models with the help of LAION-5B subsets.
11
star
43

dataset-spec

Describe the format of image/text datasets
Python
10
star
44

LAION-PEOPLE

This project provides a data set with bounding boxes, body poses, 3D face meshes & captions of people from our LAION-2.2B. Additionally it provides clusters based on the poses and face meshes and pose-related captions based on these cluster assignments.
10
star
45

image-deduplication-testset

HTML
8
star
46

project-menu

Projects at LAION
8
star
47

laion-ai.github.io

laion github website
Svelte
6
star
48

dataset-usage

This repository is a summary of all systems and scientific papers that use LAION datasets.
6
star
49

repository-overview

This repository will give a quick overview of all projects and repositories from LAION.
5
star
50

LionizeR

Experiments with Summarization, Long Context and Retrieval
Python
4
star
51

KAISER

Knowledge Acquisition and Interlinking via Semantic Embeddings and Reasoning
4
star
52

lucidrains-projects

A summary of all lucidrains repositores and links to training / research approaches by LAION or other communities.
Jupyter Notebook
3
star
53

decentralized-learning

A basic setup for decentralized-learning that can be used for training future DALLE/CLIP/CLAP models.
3
star
54

diffusion-prior

DALL-E2 diffusion prior
Python
3
star
55

GIF

General / Global Inference Framework
Python
3
star
56

website

This is the development repository of the LAION-AI website.
HTML
3
star
57

safety-pipeline

A collection of safety classifiers and models to process image and texts.
Python
3
star
58

NeoGen

3
star
59

laion5b-subsets

Creating subsets from laion5b via embeddings search
Jupyter Notebook
2
star
60

human_artifacts

A repo containing images for artifact annotation.
2
star
61

public-relations

All media / publicity on LAION and related stuff!
2
star
62

public-domain-images

A collection of public domain images donated for ML training.
2
star
63

math_problems-step-by-step_solutions

Here we provide and collect many functions to generate math problem and step by step solutions for LLM training
Python
2
star
64

language-models

2
star
65

dataset-inference

The new repository for the genral inference pipeline.
Python
2
star
66

introduction-resources

Recommended intro resources
2
star
67

balanced-laion5b

This repository shall help finding a good distribution for huge datasets like LAION-5B for more efficient training.
2
star
68

hand-inference

A model to run hand inference on a cluster.
Jupyter Notebook
2
star
69

BUD-E_V1.0

BUD-E (Buddy) is an open-source voice assistant framework that facilitates seamless interaction with AI models and APIs, enabling the creation and integration of diverse skills for educational and research applications.
1
star
70

laion5b-bias

This repository is a collection of found biases in the LAION-5B dataset.
1
star
71

dataset-tasks

datasets that should be downloaded & converted to our standard training formart.
1
star
72

LAION-AUDIO

This repository contains prompts & best practices to annotate audio clips with a very high degree of details using Audio-Language-Models
1
star
73

AIW_webpage

Alice in Wonderland project and initiative webpage
1
star