|
| 1 | +# Copyright 2024 The HuggingFace Team. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from collections import OrderedDict |
| 16 | + |
| 17 | +# Import all the necessary block classes |
| 18 | +from .denoise import ( |
| 19 | + StableDiffusionXLAutoDenoiseStep, |
| 20 | + StableDiffusionXLDenoiseStep, |
| 21 | + StableDiffusionXLControlNetDenoiseStep |
| 22 | +) |
| 23 | +from .before_denoise import ( |
| 24 | + StableDiffusionXLAutoBeforeDenoiseStep, |
| 25 | + StableDiffusionXLInputStep, |
| 26 | + StableDiffusionXLSetTimestepsStep, |
| 27 | + StableDiffusionXLPrepareLatentsStep, |
| 28 | + StableDiffusionXLPrepareAdditionalConditioningStep, |
| 29 | + StableDiffusionXLImg2ImgSetTimestepsStep, |
| 30 | + StableDiffusionXLImg2ImgPrepareLatentsStep, |
| 31 | + StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep, |
| 32 | + StableDiffusionXLInpaintPrepareLatentsStep, |
| 33 | + StableDiffusionXLControlNetInputStep, |
| 34 | + StableDiffusionXLControlNetUnionInputStep |
| 35 | +) |
| 36 | +from .encoders import ( |
| 37 | + StableDiffusionXLTextEncoderStep, |
| 38 | + StableDiffusionXLAutoIPAdapterStep, |
| 39 | + StableDiffusionXLAutoVaeEncoderStep, |
| 40 | + StableDiffusionXLVaeEncoderStep, |
| 41 | + StableDiffusionXLInpaintVaeEncoderStep, |
| 42 | + StableDiffusionXLIPAdapterStep |
| 43 | +) |
| 44 | +from .after_denoise import ( |
| 45 | + StableDiffusionXLDecodeStep, |
| 46 | + StableDiffusionXLInpaintDecodeStep |
| 47 | +) |
| 48 | +from .after_denoise import StableDiffusionXLAutoDecodeStep |
| 49 | + |
| 50 | + |
| 51 | +# YiYi notes: comment out for now, work on this later |
| 52 | +# block mapping |
| 53 | +TEXT2IMAGE_BLOCKS = OrderedDict([ |
| 54 | + ("text_encoder", StableDiffusionXLTextEncoderStep), |
| 55 | + ("ip_adapter", StableDiffusionXLAutoIPAdapterStep), |
| 56 | + ("input", StableDiffusionXLInputStep), |
| 57 | + ("set_timesteps", StableDiffusionXLSetTimestepsStep), |
| 58 | + ("prepare_latents", StableDiffusionXLPrepareLatentsStep), |
| 59 | + ("prepare_add_cond", StableDiffusionXLPrepareAdditionalConditioningStep), |
| 60 | + ("denoise", StableDiffusionXLDenoiseStep), |
| 61 | + ("decode", StableDiffusionXLDecodeStep) |
| 62 | +]) |
| 63 | + |
| 64 | +IMAGE2IMAGE_BLOCKS = OrderedDict([ |
| 65 | + ("text_encoder", StableDiffusionXLTextEncoderStep), |
| 66 | + ("ip_adapter", StableDiffusionXLAutoIPAdapterStep), |
| 67 | + ("image_encoder", StableDiffusionXLVaeEncoderStep), |
| 68 | + ("input", StableDiffusionXLInputStep), |
| 69 | + ("set_timesteps", StableDiffusionXLImg2ImgSetTimestepsStep), |
| 70 | + ("prepare_latents", StableDiffusionXLImg2ImgPrepareLatentsStep), |
| 71 | + ("prepare_add_cond", StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep), |
| 72 | + ("denoise", StableDiffusionXLDenoiseStep), |
| 73 | + ("decode", StableDiffusionXLDecodeStep) |
| 74 | +]) |
| 75 | + |
| 76 | +INPAINT_BLOCKS = OrderedDict([ |
| 77 | + ("text_encoder", StableDiffusionXLTextEncoderStep), |
| 78 | + ("ip_adapter", StableDiffusionXLAutoIPAdapterStep), |
| 79 | + ("image_encoder", StableDiffusionXLInpaintVaeEncoderStep), |
| 80 | + ("input", StableDiffusionXLInputStep), |
| 81 | + ("set_timesteps", StableDiffusionXLImg2ImgSetTimestepsStep), |
| 82 | + ("prepare_latents", StableDiffusionXLInpaintPrepareLatentsStep), |
| 83 | + ("prepare_add_cond", StableDiffusionXLImg2ImgPrepareAdditionalConditioningStep), |
| 84 | + ("denoise", StableDiffusionXLDenoiseStep), |
| 85 | + ("decode", StableDiffusionXLInpaintDecodeStep) |
| 86 | +]) |
| 87 | + |
| 88 | +CONTROLNET_BLOCKS = OrderedDict([ |
| 89 | + ("controlnet_input", StableDiffusionXLControlNetInputStep), |
| 90 | + ("denoise", StableDiffusionXLControlNetDenoiseStep), |
| 91 | +]) |
| 92 | + |
| 93 | +CONTROLNET_UNION_BLOCKS = OrderedDict([ |
| 94 | + ("controlnet_input", StableDiffusionXLControlNetUnionInputStep), |
| 95 | + ("denoise", StableDiffusionXLControlNetDenoiseStep), |
| 96 | +]) |
| 97 | + |
| 98 | +IP_ADAPTER_BLOCKS = OrderedDict([ |
| 99 | + ("ip_adapter", StableDiffusionXLIPAdapterStep), |
| 100 | +]) |
| 101 | + |
| 102 | +AUTO_BLOCKS = OrderedDict([ |
| 103 | + ("text_encoder", StableDiffusionXLTextEncoderStep), |
| 104 | + ("ip_adapter", StableDiffusionXLAutoIPAdapterStep), |
| 105 | + ("image_encoder", StableDiffusionXLAutoVaeEncoderStep), |
| 106 | + ("before_denoise", StableDiffusionXLAutoBeforeDenoiseStep), |
| 107 | + ("denoise", StableDiffusionXLAutoDenoiseStep), |
| 108 | + ("decode", StableDiffusionXLAutoDecodeStep) |
| 109 | +]) |
| 110 | + |
| 111 | +AUTO_CORE_BLOCKS = OrderedDict([ |
| 112 | + ("before_denoise", StableDiffusionXLAutoBeforeDenoiseStep), |
| 113 | + ("denoise", StableDiffusionXLAutoDenoiseStep), |
| 114 | +]) |
| 115 | + |
| 116 | + |
| 117 | +SDXL_SUPPORTED_BLOCKS = { |
| 118 | + "text2img": TEXT2IMAGE_BLOCKS, |
| 119 | + "img2img": IMAGE2IMAGE_BLOCKS, |
| 120 | + "inpaint": INPAINT_BLOCKS, |
| 121 | + "controlnet": CONTROLNET_BLOCKS, |
| 122 | + "controlnet_union": CONTROLNET_UNION_BLOCKS, |
| 123 | + "ip_adapter": IP_ADAPTER_BLOCKS, |
| 124 | + "auto": AUTO_BLOCKS |
| 125 | +} |
| 126 | + |
| 127 | + |
| 128 | + |
0 commit comments