Package: sige
Spatially Incremental Generative Engine (SIGE)Paper|Project|Slides|YouTube|Bilibili[NEW!]SIGE supportsStable Diffusionand Mac MPS backend! We also release the codes ofan interactive demo for DDPMon M1 Macbook Pro![NEW!]SIGE  is accepted by NeurIPS 2022! Our code and benchmark datasets are publicly available!We introduce Spatially Incremental Generative Engine (SIGE),an engine that selectively performs computations at the edited regions for image editing applications. The computation and latency are measured for a single forward. For the above examples, SIGE significantly reduces the computation ofSDEditwithDDPM(4-6x) andStable Diffusion(8x), andGauGAN(15x) while preserving the image quality. When combined with existing model compression methods such asGAN Compression, it further reduces the computation of GauGAN by 47x. On NVIDIA RTX 3090, SIGE achieves up to 7.2x speedups.Efficient Spatially Sparse Inference for Conditional GANs and Diffusion ModelsMuyang Li,Ji Lin,Chenlin Meng,Stefano Ermon,Song Han, andJun-Yan ZhuCMU, MIT, and StanfordIn NeurIPS 2022.DemosSIGE achieves 2x less conversion time compared to original DDPM on M1 MacBook Pro GPU as we selectively perform computation on the edited regions.OverviewTiling-based sparse convolution overview. For each convolutionFlin the network, we wrap it into SIGE Convl. The activations of the original image are already pre-computed. When getting the edited image, we first compute a difference mask between the original and edited image and reduce the mask to the active block indices to locate the edited regions. In each SIGE Convl, we directly gather the active blocks from the edited activationAleditedaccording to the reduced indices, stack the blocks along the batch dimension, and feed them intoFl. The gathered blocks have an overlap of width 2 ifFlis 3×3 convolution with stride 1. After getting the output blocks fromFl, we scatter them back intoFl(Aloriginal) to get the edited output, which approximatesFl(Aledited).PerformanceEfficiencyWith 1.2% edits, SIGE could reduce the computation of DDPM, Progressive Distillation and GauGAN by 7-18x, achieve a 2-4x speedup on NVIDIA RTX 3090, 3-5x speedup on Apple M1 Pro GPU and 4-14x on M1 Pro CPU. When combined with GAN Compression, it further reduces 50x computation on GauGAN, achieving 38x speedup on M1 Pro CPU. Please check our paper for more details and results.QualityQualitative results under different edit sizes. PD is Progressive Distillation. Our method well preserves the visual fidelity of the original model without losing global context.More qualitative results of Stable Diffusion on both image inpainting and editing, measured on NVIDIA RTX 3090.References:Denoising Diffusion Probabilistic Models (DDPM), Ho et al., ICLR 2020Denoising Diffusion Implicit Model (DDIM), Song et al., ICLR 2021Progressive Distillation for Fast Sampling of Diffusion Models, Salimans et al., ICLR 2022Semantic Image Synthesis with Spatially-Adaptive Normalization (GauGAN), Park et al., CVPR 2019GAN Compression: Efficient Architectures for Interactive Conditional GANs, Li et al., CVPR 2020High-Resolution Image Synthesis with Latent Diffusion Models, Rombach et al., CVPR 2022PrerequisitesPython3CPU, M1 GPU, or NVIDIA GPU + CUDA CuDNNPyTorch>= 1.7. For M1 GPU support, please installPyTorch>=2.0.Getting StartedInstallationAfter installingPyTorch, you should be able to install SIGE with PyPIpipinstallsigeor via GitHub:pipinstallgit+https://github.com/lmxyy/sige.gitor locally for developmentgitclonegit@github.com:lmxyy/sige.gitcdsige
pipinstall-e.For MPS backend, please set the environment variables:exportPYTORCH_ENABLE_MPS_FALLBACK=1Usage ExampleSeeexample.pyfor the minimal SIGE convolution example. Please first install SIGE with the above instructions andtorchprofilewithpipinstalltorchprofileThen you can run it withpythonexample.pyWe also haveexample.BenchmarkTo reproduce the results ofDDPMandProgressive Distillationor download the LSUN Church editing datasets, please follow the instructions indiffusion/README.md.To reproduce the results ofGauGANandGAN Compressionor download the Cityscapes editing datasets, please follow the instructions ingaugan/README.md.CitationIf you use this code for your research, please cite our paper.@inproceedings{li2022efficient,title={Efficient Spatially Sparse Inference for Conditional GANs and Diffusion Models},author={Li, Muyang and Lin, Ji and Meng, Chenlin and Ermon, Stefano and Han, Song and Zhu, Jun-Yan},booktitle={Advances in Neural Information Processing Systems (NeurIPS)},year={2022}}AcknowledgmentsOur code is developed based onSDEdit,ddim,diffusion_distillation,gan-compression,dpm-solver, andstable-diffusion. We refer tosbnetfor the tiling-based sparse convolution algorithm implementation. Our work is also inspired by the gather/scatter implementations intorchsparse.We thanktorchprofilefor MACs measurement,clean-fidfor FID computation anddrnfor Cityscapes mIoU computation.We thank Yaoyao Ding, Zihao Ye, Lianmin Zheng, Haotian Tang, and Ligeng Zhu for the helpful comments on the engine design. We also thank George Cazenavette, Kangle Deng, Ruihan Gao, Daohan Lu, Sheng-Yu Wang and Bingliang Zhang for their valuable feedback. The project is partly supported by NSF, MIT-IBM Watson AI Lab, Kwai Inc, and Sony Corporation.