Skip to content

Commit

Permalink
add docker-slim
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverinn committed Jul 13, 2023
1 parent 9dfad6f commit 785c431
Show file tree
Hide file tree
Showing 416 changed files with 76,899 additions and 8 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,4 @@ If you don't want to deploy the load balancing server but still want to test the
Finally, you can call your http API(test it using postman).

# Part 2: Deploy using Runpod Serverless
Check `handler.py` where I realized a demo handler for txt2img.

deploy steps:
- get a GPU server, download this repository and model files
- install docker: https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository
- cd to the project directory(which contains `Dockerfile`)
- docker build && docker tag && docker push (these are not bash commands!)
- create serverless Endpoint on runpod: https://runpod.io?ref=bz40v32s
see `sd-docker-slim`
37 changes: 37 additions & 0 deletions sd-docker-slim/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.10-slim

# install docker on ubuntu: https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository
# build image: docker build -t sd-multi .
# docker image ls
# dockerhub create repo
# login on ubuntu: docker login
# tag: docker tag sd-multi wolverinn/sd_multi_demo:v1
# push: docker push wolverinn/sd_multi_demo:v1

WORKDIR /

COPY requirements.txt /
# COPY torch-1.13.1+cu117-cp38-cp38-linux_x86_64.whl .

RUN apt-get update && apt-get install -y libgl1-mesa-glx && \
apt-get install -y libglib2.0-0 && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*

RUN pip3 install runpod==0.9.12 && \
pip3 install -r requirements.txt && \
# pip3 install torch-1.13.1+cu117-cp38-cp38-linux_x86_64.whl && \
pip3 install torch==1.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 && \
pip3 install torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 && \
# apt-get remove -y git && \
# rm -rf torch-1.13.1+cu117-cp38-cp38-linux_x86_64.whl && \
pip3 cache purge

COPY . /
RUN chmod +x docker_entrypoint.sh

# COPY . /

ENTRYPOINT ["/docker_entrypoint.sh"]

CMD [ "python", "-u", "/handler.py" ]
39 changes: 39 additions & 0 deletions sd-docker-slim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# stable-diffusion docker slim

# Features

- deploy on runpod serverless
- text2img, img2img, list models
- upload models at any time, takes effect immediately

# Deploy Steps

## Build and upload docker
- get a Ubuntu machine with GPU, download the project files
- install docker on ubuntu: https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository
- cd to the directory with `Dockerfile`
- to make your custom docker, modify `handler.py` for uploading outputs & supporting more API ...
- `docker build -t sd-multi .`
- `docker login`
- docker tag and then docker push

## Create a storage on runpod
- upload model files to storage volume. under `/workspace` you should upload the whole `models` directory. The directory structure should look like this:

```
/workspace
- /models
- /VAE
- /Lora
- /Stable-diffusion
...
```

## Deploy on runpod serverless
check the official guide: https://docs.runpod.io/docs/template-creation

# Test your API
check out `test_runpod.py`

## API definition
checkout `idl.yaml`
146 changes: 146 additions & 0 deletions sd-docker-slim/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"samples_save": true,
"samples_format": "png",
"samples_filename_pattern": "",
"save_images_add_number": true,
"grid_save": true,
"grid_format": "png",
"grid_extended_filename": false,
"grid_only_if_multiple": true,
"grid_prevent_empty_spots": false,
"n_rows": -1,
"enable_pnginfo": true,
"save_txt": false,
"save_images_before_face_restoration": false,
"save_images_before_highres_fix": false,
"save_images_before_color_correction": false,
"jpeg_quality": 80,
"export_for_4chan": true,
"img_downscale_threshold": 4.0,
"target_side_length": 4000,
"use_original_name_batch": true,
"use_upscaler_name_as_suffix": false,
"save_selected_only": true,
"do_not_add_watermark": false,
"temp_dir": "",
"clean_temp_dir_at_start": false,
"outdir_samples": "",
"outdir_txt2img_samples": "outputs/txt2img-images",
"outdir_img2img_samples": "outputs/img2img-images",
"outdir_extras_samples": "outputs/extras-images",
"outdir_grids": "",
"outdir_txt2img_grids": "outputs/txt2img-grids",
"outdir_img2img_grids": "outputs/img2img-grids",
"outdir_save": "log/images",
"save_to_dirs": true,
"grid_save_to_dirs": true,
"use_save_to_dirs_for_ui": false,
"directories_filename_pattern": "[date]",
"directories_max_prompt_words": 8,
"ESRGAN_tile": 192,
"ESRGAN_tile_overlap": 8,
"realesrgan_enabled_models": [
"R-ESRGAN 4x+",
"R-ESRGAN 4x+ Anime6B"
],
"upscaler_for_img2img": null,
"face_restoration_model": "CodeFormer",
"code_former_weight": 0.5,
"face_restoration_unload": false,
"show_warnings": false,
"memmon_poll_rate": 8,
"samples_log_stdout": false,
"multiple_tqdm": true,
"print_hypernet_extra": false,
"unload_models_when_training": false,
"pin_memory": false,
"save_optimizer_state": false,
"save_training_settings_to_txt": true,
"dataset_filename_word_regex": "",
"dataset_filename_join_string": " ",
"training_image_repeats_per_epoch": 1,
"training_write_csv_every": 500,
"training_xattention_optimizations": false,
"training_enable_tensorboard": false,
"training_tensorboard_save_images": false,
"training_tensorboard_flush_every": 120,
"sd_checkpoint_cache": 0,
"sd_vae_checkpoint_cache": 0,
"sd_vae": "Automatic",
"sd_vae_as_default": true,
"inpainting_mask_weight": 1.0,
"initial_noise_multiplier": 1.0,
"img2img_color_correction": false,
"img2img_fix_steps": false,
"img2img_background_color": "#ffffff",
"enable_quantization": false,
"enable_emphasis": true,
"enable_batch_seeds": true,
"comma_padding_backtrack": 20,
"CLIP_stop_at_last_layers": 1,
"upcast_attn": false,
"use_old_emphasis_implementation": false,
"use_old_karras_scheduler_sigmas": false,
"no_dpmpp_sde_batch_determinism": false,
"use_old_hires_fix_width_height": false,
"interrogate_keep_models_in_memory": false,
"interrogate_return_ranks": false,
"interrogate_clip_num_beams": 1,
"interrogate_clip_min_length": 24,
"interrogate_clip_max_length": 48,
"interrogate_clip_dict_limit": 1500,
"interrogate_clip_skip_categories": [],
"interrogate_deepbooru_score_threshold": 0.5,
"deepbooru_sort_alpha": true,
"deepbooru_use_spaces": false,
"deepbooru_escape": true,
"deepbooru_filter_tags": "",
"extra_networks_default_view": "cards",
"extra_networks_default_multiplier": 1.0,
"sd_hypernetwork": "None",
"return_grid": true,
"do_not_show_images": false,
"add_model_hash_to_info": true,
"add_model_name_to_info": true,
"disable_weights_auto_swap": true,
"send_seed": true,
"send_size": true,
"font": "",
"js_modal_lightbox": true,
"js_modal_lightbox_initially_zoomed": true,
"show_progress_in_title": true,
"samplers_in_dropdown": true,
"dimensions_and_batch_together": true,
"keyedit_precision_attention": 0.1,
"keyedit_precision_extra": 0.05,
"quicksettings": "sd_model_checkpoint",
"ui_reorder": "inpaint, sampler, checkboxes, hires_fix, dimensions, cfg, seed, batch, override_settings, scripts",
"ui_extra_networks_tab_reorder": "",
"localization": "zh_CN",
"show_progressbar": true,
"live_previews_enable": true,
"show_progress_grid": true,
"show_progress_every_n_steps": 10,
"show_progress_type": "Approx NN",
"live_preview_content": "Prompt",
"live_preview_refresh_period": 1000,
"hide_samplers": [],
"eta_ddim": 0.0,
"eta_ancestral": 1.0,
"ddim_discretize": "uniform",
"s_churn": 0.0,
"s_tmin": 0.0,
"s_noise": 1.0,
"eta_noise_seed_delta": 0,
"always_discard_next_to_last_sigma": false,
"postprocessing_enable_in_main_ui": [],
"postprocessing_operation_order": [],
"upscaling_max_images_in_cache": 5,
"disabled_extensions": [],
"ldsr_steps": 100,
"ldsr_cached": false,
"SWIN_tile": 192,
"SWIN_tile_overlap": 8,
"sd_lora": "None",
"lora_apply_to_outputs": false
}
72 changes: 72 additions & 0 deletions sd-docker-slim/configs/alt-diffusion-inference.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
model:
base_learning_rate: 1.0e-04
target: ldm.models.diffusion.ddpm.LatentDiffusion
params:
linear_start: 0.00085
linear_end: 0.0120
num_timesteps_cond: 1
log_every_t: 200
timesteps: 1000
first_stage_key: "jpg"
cond_stage_key: "txt"
image_size: 64
channels: 4
cond_stage_trainable: false # Note: different from the one we trained before
conditioning_key: crossattn
monitor: val/loss_simple_ema
scale_factor: 0.18215
use_ema: False

scheduler_config: # 10000 warmup steps
target: ldm.lr_scheduler.LambdaLinearScheduler
params:
warm_up_steps: [ 10000 ]
cycle_lengths: [ 10000000000000 ] # incredibly large number to prevent corner cases
f_start: [ 1.e-6 ]
f_max: [ 1. ]
f_min: [ 1. ]

unet_config:
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
params:
image_size: 32 # unused
in_channels: 4
out_channels: 4
model_channels: 320
attention_resolutions: [ 4, 2, 1 ]
num_res_blocks: 2
channel_mult: [ 1, 2, 4, 4 ]
num_heads: 8
use_spatial_transformer: True
transformer_depth: 1
context_dim: 768
use_checkpoint: True
legacy: False

first_stage_config:
target: ldm.models.autoencoder.AutoencoderKL
params:
embed_dim: 4
monitor: val/rec_loss
ddconfig:
double_z: true
z_channels: 4
resolution: 256
in_channels: 3
out_ch: 3
ch: 128
ch_mult:
- 1
- 2
- 4
- 4
num_res_blocks: 2
attn_resolutions: []
dropout: 0.0
lossconfig:
target: torch.nn.Identity

cond_stage_config:
target: modules.xlmr.BertSeriesModelWithTransformation
params:
name: "XLMR-Large"
Loading

0 comments on commit 785c431

Please sign in to comment.