optimum-rbln 0.9.3.post1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of optimum-rbln might be problematic. Click here for more details.
- optimum/rbln/__init__.py +505 -0
- optimum/rbln/__version__.py +34 -0
- optimum/rbln/cli.py +660 -0
- optimum/rbln/configuration_utils.py +968 -0
- optimum/rbln/diffusers/__init__.py +198 -0
- optimum/rbln/diffusers/configurations/__init__.py +37 -0
- optimum/rbln/diffusers/configurations/models/__init__.py +10 -0
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py +73 -0
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl_cosmos.py +84 -0
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl_temporal_decoder.py +67 -0
- optimum/rbln/diffusers/configurations/models/configuration_controlnet.py +64 -0
- optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py +59 -0
- optimum/rbln/diffusers/configurations/models/configuration_transformer_cosmos.py +78 -0
- optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py +63 -0
- optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py +81 -0
- optimum/rbln/diffusers/configurations/models/configuration_unet_spatio_temporal_condition.py +59 -0
- optimum/rbln/diffusers/configurations/models/configuration_vq_model.py +74 -0
- optimum/rbln/diffusers/configurations/pipelines/__init__.py +34 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py +316 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_cosmos.py +117 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_kandinsky2_2.py +363 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion.py +156 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_3.py +176 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_xl.py +159 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_video_diffusion.py +114 -0
- optimum/rbln/diffusers/modeling_diffusers.py +451 -0
- optimum/rbln/diffusers/models/__init__.py +64 -0
- optimum/rbln/diffusers/models/autoencoders/__init__.py +18 -0
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl.py +255 -0
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl_cosmos.py +245 -0
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +275 -0
- optimum/rbln/diffusers/models/autoencoders/vae.py +178 -0
- optimum/rbln/diffusers/models/autoencoders/vq_model.py +211 -0
- optimum/rbln/diffusers/models/controlnet.py +281 -0
- optimum/rbln/diffusers/models/transformers/__init__.py +17 -0
- optimum/rbln/diffusers/models/transformers/prior_transformer.py +160 -0
- optimum/rbln/diffusers/models/transformers/transformer_cosmos.py +344 -0
- optimum/rbln/diffusers/models/transformers/transformer_sd3.py +191 -0
- optimum/rbln/diffusers/models/unets/__init__.py +16 -0
- optimum/rbln/diffusers/models/unets/unet_2d_condition.py +408 -0
- optimum/rbln/diffusers/models/unets/unet_spatio_temporal_condition.py +201 -0
- optimum/rbln/diffusers/pipelines/__init__.py +113 -0
- optimum/rbln/diffusers/pipelines/auto_pipeline.py +307 -0
- optimum/rbln/diffusers/pipelines/controlnet/__init__.py +19 -0
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +139 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +669 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +640 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +825 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +837 -0
- optimum/rbln/diffusers/pipelines/cosmos/__init__.py +17 -0
- optimum/rbln/diffusers/pipelines/cosmos/configuration_cosmos_guardrail.py +113 -0
- optimum/rbln/diffusers/pipelines/cosmos/cosmos_guardrail.py +425 -0
- optimum/rbln/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py +128 -0
- optimum/rbln/diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py +128 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/__init__.py +23 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +34 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +207 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +34 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpaint.py +34 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/__init__.py +17 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +32 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/__init__.py +17 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/__init__.py +17 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +31 -0
- optimum/rbln/diffusers/pipelines/stable_video_diffusion/__init__.py +15 -0
- optimum/rbln/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +46 -0
- optimum/rbln/modeling.py +364 -0
- optimum/rbln/modeling_base.py +637 -0
- optimum/rbln/ops/__init__.py +19 -0
- optimum/rbln/ops/attn.py +455 -0
- optimum/rbln/ops/flash_attn.py +350 -0
- optimum/rbln/ops/kv_cache_update.py +29 -0
- optimum/rbln/ops/linear.py +32 -0
- optimum/rbln/ops/sliding_window_attn.py +111 -0
- optimum/rbln/transformers/__init__.py +340 -0
- optimum/rbln/transformers/configuration_generic.py +120 -0
- optimum/rbln/transformers/modeling_attention_utils.py +385 -0
- optimum/rbln/transformers/modeling_generic.py +280 -0
- optimum/rbln/transformers/modeling_outputs.py +37 -0
- optimum/rbln/transformers/modeling_rope_utils.py +314 -0
- optimum/rbln/transformers/models/__init__.py +343 -0
- optimum/rbln/transformers/models/audio_spectrogram_transformer/__init__.py +17 -0
- optimum/rbln/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py +47 -0
- optimum/rbln/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py +91 -0
- optimum/rbln/transformers/models/auto/__init__.py +31 -0
- optimum/rbln/transformers/models/auto/auto_factory.py +267 -0
- optimum/rbln/transformers/models/auto/modeling_auto.py +162 -0
- optimum/rbln/transformers/models/bart/__init__.py +17 -0
- optimum/rbln/transformers/models/bart/bart_architecture.py +163 -0
- optimum/rbln/transformers/models/bart/configuration_bart.py +36 -0
- optimum/rbln/transformers/models/bart/modeling_bart.py +86 -0
- optimum/rbln/transformers/models/bert/__init__.py +16 -0
- optimum/rbln/transformers/models/bert/bert_architecture.py +16 -0
- optimum/rbln/transformers/models/bert/configuration_bert.py +46 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +148 -0
- optimum/rbln/transformers/models/blip_2/__init__.py +20 -0
- optimum/rbln/transformers/models/blip_2/configuration_blip_2.py +115 -0
- optimum/rbln/transformers/models/blip_2/modeling_blip_2.py +526 -0
- optimum/rbln/transformers/models/clip/__init__.py +26 -0
- optimum/rbln/transformers/models/clip/configuration_clip.py +103 -0
- optimum/rbln/transformers/models/clip/modeling_clip.py +384 -0
- optimum/rbln/transformers/models/colpali/__init__.py +2 -0
- optimum/rbln/transformers/models/colpali/colpali_architecture.py +218 -0
- optimum/rbln/transformers/models/colpali/configuration_colpali.py +84 -0
- optimum/rbln/transformers/models/colpali/modeling_colpali.py +361 -0
- optimum/rbln/transformers/models/colqwen2/__init__.py +2 -0
- optimum/rbln/transformers/models/colqwen2/colqwen2_architecture.py +233 -0
- optimum/rbln/transformers/models/colqwen2/configuration_colqwen2.py +74 -0
- optimum/rbln/transformers/models/colqwen2/modeling_colqwen2.py +446 -0
- optimum/rbln/transformers/models/decoderonly/__init__.py +27 -0
- optimum/rbln/transformers/models/decoderonly/configuration_decoderonly.py +300 -0
- optimum/rbln/transformers/models/decoderonly/configuration_lora.py +411 -0
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +1224 -0
- optimum/rbln/transformers/models/decoderonly/decoderonly_runtime_utils.py +508 -0
- optimum/rbln/transformers/models/decoderonly/generation_decoderonly.py +119 -0
- optimum/rbln/transformers/models/decoderonly/lora_architecture.py +204 -0
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +823 -0
- optimum/rbln/transformers/models/depth_anything/__init__.py +16 -0
- optimum/rbln/transformers/models/depth_anything/configuration_depth_anything.py +24 -0
- optimum/rbln/transformers/models/depth_anything/modeling_depth_anything.py +42 -0
- optimum/rbln/transformers/models/distilbert/__init__.py +19 -0
- optimum/rbln/transformers/models/distilbert/configuration_distilbert.py +24 -0
- optimum/rbln/transformers/models/distilbert/modeling_distilbert.py +51 -0
- optimum/rbln/transformers/models/dpt/__init__.py +16 -0
- optimum/rbln/transformers/models/dpt/configuration_dpt.py +24 -0
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +42 -0
- optimum/rbln/transformers/models/exaone/__init__.py +24 -0
- optimum/rbln/transformers/models/exaone/configuration_exaone.py +42 -0
- optimum/rbln/transformers/models/exaone/exaone_architecture.py +77 -0
- optimum/rbln/transformers/models/exaone/modeling_exaone.py +145 -0
- optimum/rbln/transformers/models/gemma/__init__.py +16 -0
- optimum/rbln/transformers/models/gemma/configuration_gemma.py +50 -0
- optimum/rbln/transformers/models/gemma/gemma_architecture.py +27 -0
- optimum/rbln/transformers/models/gemma/modeling_gemma.py +104 -0
- optimum/rbln/transformers/models/gemma3/__init__.py +16 -0
- optimum/rbln/transformers/models/gemma3/configuration_gemma3.py +109 -0
- optimum/rbln/transformers/models/gemma3/gemma3_architecture.py +170 -0
- optimum/rbln/transformers/models/gemma3/gemma3_runtime_utils.py +245 -0
- optimum/rbln/transformers/models/gemma3/modeling_gemma3.py +611 -0
- optimum/rbln/transformers/models/gpt2/__init__.py +16 -0
- optimum/rbln/transformers/models/gpt2/configuration_gpt2.py +50 -0
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +93 -0
- optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +55 -0
- optimum/rbln/transformers/models/grounding_dino/__init__.py +10 -0
- optimum/rbln/transformers/models/grounding_dino/configuration_grounding_dino.py +92 -0
- optimum/rbln/transformers/models/grounding_dino/grounding_dino_architecture.py +599 -0
- optimum/rbln/transformers/models/grounding_dino/modeling_grounding_dino.py +1048 -0
- optimum/rbln/transformers/models/idefics3/__init__.py +16 -0
- optimum/rbln/transformers/models/idefics3/configuration_idefics3.py +89 -0
- optimum/rbln/transformers/models/idefics3/modeling_idefics3.py +497 -0
- optimum/rbln/transformers/models/llama/__init__.py +16 -0
- optimum/rbln/transformers/models/llama/configuration_llama.py +50 -0
- optimum/rbln/transformers/models/llama/llama_architecture.py +19 -0
- optimum/rbln/transformers/models/llama/modeling_llama.py +104 -0
- optimum/rbln/transformers/models/llava/__init__.py +16 -0
- optimum/rbln/transformers/models/llava/configuration_llava.py +72 -0
- optimum/rbln/transformers/models/llava/modeling_llava.py +490 -0
- optimum/rbln/transformers/models/llava_next/__init__.py +16 -0
- optimum/rbln/transformers/models/llava_next/configuration_llava_next.py +69 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +493 -0
- optimum/rbln/transformers/models/midm/__init__.py +24 -0
- optimum/rbln/transformers/models/midm/configuration_midm.py +42 -0
- optimum/rbln/transformers/models/midm/midm_architecture.py +144 -0
- optimum/rbln/transformers/models/midm/modeling_midm.py +144 -0
- optimum/rbln/transformers/models/mistral/__init__.py +16 -0
- optimum/rbln/transformers/models/mistral/configuration_mistral.py +50 -0
- optimum/rbln/transformers/models/mistral/mistral_architecture.py +19 -0
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +115 -0
- optimum/rbln/transformers/models/opt/__init__.py +16 -0
- optimum/rbln/transformers/models/opt/configuration_opt.py +29 -0
- optimum/rbln/transformers/models/opt/modeling_opt.py +102 -0
- optimum/rbln/transformers/models/opt/opt_architecture.py +74 -0
- optimum/rbln/transformers/models/pegasus/__init__.py +17 -0
- optimum/rbln/transformers/models/pegasus/configuration_pegasus.py +38 -0
- optimum/rbln/transformers/models/pegasus/modeling_pegasus.py +71 -0
- optimum/rbln/transformers/models/pegasus/pegasus_architecture.py +161 -0
- optimum/rbln/transformers/models/phi/__init__.py +16 -0
- optimum/rbln/transformers/models/phi/configuration_phi.py +50 -0
- optimum/rbln/transformers/models/phi/modeling_phi.py +92 -0
- optimum/rbln/transformers/models/phi/phi_architecture.py +115 -0
- optimum/rbln/transformers/models/pixtral/__init__.py +16 -0
- optimum/rbln/transformers/models/pixtral/configuration_pixtral.py +43 -0
- optimum/rbln/transformers/models/pixtral/modeling_pixtral.py +322 -0
- optimum/rbln/transformers/models/pixtral/pixtral_architecture.py +73 -0
- optimum/rbln/transformers/models/qwen2/__init__.py +16 -0
- optimum/rbln/transformers/models/qwen2/configuration_qwen2.py +50 -0
- optimum/rbln/transformers/models/qwen2/modeling_qwen2.py +123 -0
- optimum/rbln/transformers/models/qwen2/qwen2_architecture.py +19 -0
- optimum/rbln/transformers/models/qwen2_5_vl/__init__.py +19 -0
- optimum/rbln/transformers/models/qwen2_5_vl/configuration_qwen2_5_vl.py +111 -0
- optimum/rbln/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py +636 -0
- optimum/rbln/transformers/models/qwen2_5_vl/qwen2_5_vl_architecture.py +220 -0
- optimum/rbln/transformers/models/qwen2_vl/__init__.py +19 -0
- optimum/rbln/transformers/models/qwen2_vl/configuration_qwen2_vl.py +88 -0
- optimum/rbln/transformers/models/qwen2_vl/modeling_qwen2_vl.py +513 -0
- optimum/rbln/transformers/models/qwen2_vl/qwen2_vl_architecture.py +165 -0
- optimum/rbln/transformers/models/qwen3/__init__.py +16 -0
- optimum/rbln/transformers/models/qwen3/configuration_qwen3.py +71 -0
- optimum/rbln/transformers/models/qwen3/modeling_qwen3.py +133 -0
- optimum/rbln/transformers/models/qwen3/qwen3_architecture.py +31 -0
- optimum/rbln/transformers/models/resnet/__init__.py +23 -0
- optimum/rbln/transformers/models/resnet/configuration_resnet.py +42 -0
- optimum/rbln/transformers/models/resnet/modeling_resnet.py +99 -0
- optimum/rbln/transformers/models/roberta/__init__.py +24 -0
- optimum/rbln/transformers/models/roberta/configuration_roberta.py +33 -0
- optimum/rbln/transformers/models/roberta/modeling_roberta.py +72 -0
- optimum/rbln/transformers/models/seq2seq/__init__.py +16 -0
- optimum/rbln/transformers/models/seq2seq/configuration_seq2seq.py +71 -0
- optimum/rbln/transformers/models/seq2seq/modeling_seq2seq.py +477 -0
- optimum/rbln/transformers/models/seq2seq/seq2seq_architecture.py +527 -0
- optimum/rbln/transformers/models/siglip/__init__.py +16 -0
- optimum/rbln/transformers/models/siglip/configuration_siglip.py +76 -0
- optimum/rbln/transformers/models/siglip/modeling_siglip.py +199 -0
- optimum/rbln/transformers/models/swin/__init__.py +16 -0
- optimum/rbln/transformers/models/swin/configuration_swin.py +42 -0
- optimum/rbln/transformers/models/swin/modeling_swin.py +354 -0
- optimum/rbln/transformers/models/t5/__init__.py +17 -0
- optimum/rbln/transformers/models/t5/configuration_t5.py +36 -0
- optimum/rbln/transformers/models/t5/modeling_t5.py +130 -0
- optimum/rbln/transformers/models/t5/t5_architecture.py +264 -0
- optimum/rbln/transformers/models/time_series_transformer/__init__.py +26 -0
- optimum/rbln/transformers/models/time_series_transformer/configuration_time_series_transformer.py +41 -0
- optimum/rbln/transformers/models/time_series_transformer/modeling_time_series_transformer.py +435 -0
- optimum/rbln/transformers/models/time_series_transformer/time_series_transformers_architecture.py +337 -0
- optimum/rbln/transformers/models/vit/__init__.py +19 -0
- optimum/rbln/transformers/models/vit/configuration_vit.py +24 -0
- optimum/rbln/transformers/models/vit/modeling_vit.py +44 -0
- optimum/rbln/transformers/models/wav2vec2/__init__.py +16 -0
- optimum/rbln/transformers/models/wav2vec2/configuration_wav2vec2.py +38 -0
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +104 -0
- optimum/rbln/transformers/models/whisper/__init__.py +17 -0
- optimum/rbln/transformers/models/whisper/configuration_whisper.py +72 -0
- optimum/rbln/transformers/models/whisper/generation_whisper.py +159 -0
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +475 -0
- optimum/rbln/transformers/models/whisper/whisper_architecture.py +349 -0
- optimum/rbln/transformers/models/xlm_roberta/__init__.py +24 -0
- optimum/rbln/transformers/models/xlm_roberta/configuration_xlm_roberta.py +32 -0
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +82 -0
- optimum/rbln/transformers/utils/__init__.py +0 -0
- optimum/rbln/transformers/utils/rbln_quantization.py +589 -0
- optimum/rbln/transformers/utils/rbln_runtime_wrapper.py +79 -0
- optimum/rbln/utils/__init__.py +16 -0
- optimum/rbln/utils/decorator_utils.py +86 -0
- optimum/rbln/utils/deprecation.py +213 -0
- optimum/rbln/utils/hub.py +94 -0
- optimum/rbln/utils/import_utils.py +170 -0
- optimum/rbln/utils/logging.py +110 -0
- optimum/rbln/utils/model_utils.py +63 -0
- optimum/rbln/utils/runtime_utils.py +249 -0
- optimum/rbln/utils/save_utils.py +102 -0
- optimum/rbln/utils/submodule.py +152 -0
- optimum_rbln-0.9.3.post1.dist-info/METADATA +124 -0
- optimum_rbln-0.9.3.post1.dist-info/RECORD +264 -0
- optimum_rbln-0.9.3.post1.dist-info/WHEEL +4 -0
- optimum_rbln-0.9.3.post1.dist-info/entry_points.txt +2 -0
- optimum_rbln-0.9.3.post1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright 2025 Rebellions Inc. 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 typing import Any, Optional, Tuple, Union
|
|
16
|
+
|
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RBLNSD3Transformer2DModelConfig(RBLNModelConfig):
|
|
21
|
+
"""
|
|
22
|
+
Configuration class for RBLN Stable Diffusion 3 Transformer models.
|
|
23
|
+
|
|
24
|
+
This class inherits from RBLNModelConfig and provides specific configuration options
|
|
25
|
+
for Transformer models used in diffusion models like Stable Diffusion 3.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
batch_size: Optional[int] = None,
|
|
33
|
+
sample_size: Optional[Union[int, Tuple[int, int]]] = None,
|
|
34
|
+
prompt_embed_length: Optional[int] = None,
|
|
35
|
+
**kwargs: Any,
|
|
36
|
+
):
|
|
37
|
+
"""
|
|
38
|
+
Args:
|
|
39
|
+
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
|
40
|
+
sample_size (Optional[Union[int, Tuple[int, int]]]): The spatial dimensions (height, width)
|
|
41
|
+
of the generated samples. If an integer is provided, it's used for both height and width.
|
|
42
|
+
prompt_embed_length (Optional[int]): The length of the embedded prompt vectors that
|
|
43
|
+
will be used to condition the transformer model.
|
|
44
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
ValueError: If batch_size is not a positive integer.
|
|
48
|
+
"""
|
|
49
|
+
super().__init__(**kwargs)
|
|
50
|
+
self._batch_size_is_specified = batch_size is not None
|
|
51
|
+
|
|
52
|
+
self.batch_size = batch_size or 1
|
|
53
|
+
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
|
54
|
+
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
|
55
|
+
|
|
56
|
+
self.prompt_embed_length = prompt_embed_length
|
|
57
|
+
self.sample_size = sample_size
|
|
58
|
+
if isinstance(self.sample_size, int):
|
|
59
|
+
self.sample_size = (self.sample_size, self.sample_size)
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def batch_size_is_specified(self):
|
|
63
|
+
return self._batch_size_is_specified
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright 2025 Rebellions Inc. 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 typing import Any, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RBLNUNet2DConditionModelConfig(RBLNModelConfig):
|
|
21
|
+
"""
|
|
22
|
+
Configuration class for RBLN UNet2DCondition models.
|
|
23
|
+
|
|
24
|
+
This class inherits from RBLNModelConfig and provides specific configuration options
|
|
25
|
+
for UNet2DCondition models used in diffusion-based image generation.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
batch_size: Optional[int] = None,
|
|
33
|
+
sample_size: Optional[Tuple[int, int]] = None,
|
|
34
|
+
in_channels: Optional[int] = None,
|
|
35
|
+
cross_attention_dim: Optional[int] = None,
|
|
36
|
+
use_additional_residuals: Optional[bool] = None,
|
|
37
|
+
max_seq_len: Optional[int] = None,
|
|
38
|
+
in_features: Optional[int] = None,
|
|
39
|
+
text_model_hidden_size: Optional[int] = None,
|
|
40
|
+
image_model_hidden_size: Optional[int] = None,
|
|
41
|
+
**kwargs: Any,
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Args:
|
|
45
|
+
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
|
46
|
+
sample_size (Optional[Tuple[int, int]]): The spatial dimensions (height, width) of the generated samples.
|
|
47
|
+
If an integer is provided, it's used for both height and width.
|
|
48
|
+
in_channels (Optional[int]): Number of input channels for the UNet.
|
|
49
|
+
cross_attention_dim (Optional[int]): Dimension of the cross-attention features.
|
|
50
|
+
use_additional_residuals (Optional[bool]): Whether to use additional residual connections in the model.
|
|
51
|
+
max_seq_len (Optional[int]): Maximum sequence length for text inputs when used with cross-attention.
|
|
52
|
+
in_features (Optional[int]): Number of input features for the model.
|
|
53
|
+
text_model_hidden_size (Optional[int]): Hidden size of the text encoder model.
|
|
54
|
+
image_model_hidden_size (Optional[int]): Hidden size of the image encoder model.
|
|
55
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If batch_size is not a positive integer.
|
|
59
|
+
"""
|
|
60
|
+
super().__init__(**kwargs)
|
|
61
|
+
self._batch_size_is_specified = batch_size is not None
|
|
62
|
+
|
|
63
|
+
self.batch_size = batch_size or 1
|
|
64
|
+
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
|
65
|
+
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
|
66
|
+
|
|
67
|
+
self.in_channels = in_channels
|
|
68
|
+
self.cross_attention_dim = cross_attention_dim
|
|
69
|
+
self.use_additional_residuals = use_additional_residuals
|
|
70
|
+
self.max_seq_len = max_seq_len
|
|
71
|
+
self.in_features = in_features
|
|
72
|
+
self.text_model_hidden_size = text_model_hidden_size
|
|
73
|
+
self.image_model_hidden_size = image_model_hidden_size
|
|
74
|
+
|
|
75
|
+
self.sample_size = sample_size
|
|
76
|
+
if isinstance(sample_size, int):
|
|
77
|
+
self.sample_size = (sample_size, sample_size)
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def batch_size_is_specified(self):
|
|
81
|
+
return self._batch_size_is_specified
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2025 Rebellions Inc. 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 typing import Any, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RBLNUNetSpatioTemporalConditionModelConfig(RBLNModelConfig):
|
|
21
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
batch_size: Optional[int] = None,
|
|
26
|
+
sample_size: Optional[Tuple[int, int]] = None,
|
|
27
|
+
in_features: Optional[int] = None,
|
|
28
|
+
num_frames: Optional[int] = None,
|
|
29
|
+
**kwargs: Any,
|
|
30
|
+
):
|
|
31
|
+
"""
|
|
32
|
+
Args:
|
|
33
|
+
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
|
34
|
+
sample_size (Optional[Tuple[int, int]]): The spatial dimensions (height, width) of the generated samples.
|
|
35
|
+
If an integer is provided, it's used for both height and width.
|
|
36
|
+
in_features (Optional[int]): Number of input features for the model.
|
|
37
|
+
num_frames (Optional[int]): The number of frames in the generated video.
|
|
38
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ValueError: If batch_size is not a positive integer.
|
|
42
|
+
"""
|
|
43
|
+
super().__init__(**kwargs)
|
|
44
|
+
self._batch_size_is_specified = batch_size is not None
|
|
45
|
+
|
|
46
|
+
self.batch_size = batch_size or 1
|
|
47
|
+
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
|
48
|
+
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
|
49
|
+
|
|
50
|
+
self.in_features = in_features
|
|
51
|
+
self.num_frames = num_frames
|
|
52
|
+
|
|
53
|
+
self.sample_size = sample_size
|
|
54
|
+
if isinstance(sample_size, int):
|
|
55
|
+
self.sample_size = (sample_size, sample_size)
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def batch_size_is_specified(self):
|
|
59
|
+
return self._batch_size_is_specified
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Copyright 2025 Rebellions Inc. 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 typing import Any, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RBLNVQModelConfig(RBLNModelConfig):
|
|
21
|
+
"""
|
|
22
|
+
Configuration class for RBLN VQModel models, used in Kandinsky.
|
|
23
|
+
|
|
24
|
+
This class inherits from RBLNModelConfig and provides specific configuration options
|
|
25
|
+
for VQModel, which acts similarly to a VAE but uses vector quantization.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
batch_size: Optional[int] = None,
|
|
31
|
+
sample_size: Optional[Tuple[int, int]] = None,
|
|
32
|
+
uses_encoder: Optional[bool] = None,
|
|
33
|
+
vqmodel_scale_factor: Optional[float] = None, # TODO: rename to scaling_factor
|
|
34
|
+
in_channels: Optional[int] = None,
|
|
35
|
+
latent_channels: Optional[int] = None,
|
|
36
|
+
**kwargs: Any,
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Args:
|
|
40
|
+
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
|
41
|
+
sample_size (Optional[Tuple[int, int]]): The spatial dimensions (height, width) of the input/output images.
|
|
42
|
+
If an integer is provided, it's used for both height and width.
|
|
43
|
+
uses_encoder (Optional[bool]): Whether to include the encoder part of the VAE in the model.
|
|
44
|
+
When False, only the decoder is used (for latent-to-image conversion).
|
|
45
|
+
vqmodel_scale_factor (Optional[float]): The scaling factor between pixel space and latent space.
|
|
46
|
+
Determines the downsampling ratio between original images and latent representations.
|
|
47
|
+
in_channels (Optional[int]): Number of input channels for the model.
|
|
48
|
+
latent_channels (Optional[int]): Number of channels in the latent space.
|
|
49
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
50
|
+
|
|
51
|
+
Raises:
|
|
52
|
+
ValueError: If batch_size is not a positive integer.
|
|
53
|
+
"""
|
|
54
|
+
super().__init__(**kwargs)
|
|
55
|
+
self.batch_size = batch_size or 1
|
|
56
|
+
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
|
57
|
+
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
|
58
|
+
|
|
59
|
+
self.uses_encoder = uses_encoder
|
|
60
|
+
self.sample_size = sample_size
|
|
61
|
+
if isinstance(self.sample_size, int):
|
|
62
|
+
self.sample_size = (self.sample_size, self.sample_size)
|
|
63
|
+
|
|
64
|
+
self.vqmodel_scale_factor = vqmodel_scale_factor
|
|
65
|
+
self.in_channels = in_channels
|
|
66
|
+
self.latent_channels = latent_channels
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def image_size(self):
|
|
70
|
+
return self.sample_size
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def latent_sample_size(self):
|
|
74
|
+
return (self.image_size[0] // self.vqmodel_scale_factor, self.image_size[1] // self.vqmodel_scale_factor)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from .configuration_controlnet import (
|
|
2
|
+
RBLNStableDiffusionControlNetImg2ImgPipelineConfig,
|
|
3
|
+
RBLNStableDiffusionControlNetPipelineConfig,
|
|
4
|
+
RBLNStableDiffusionXLControlNetImg2ImgPipelineConfig,
|
|
5
|
+
RBLNStableDiffusionXLControlNetPipelineConfig,
|
|
6
|
+
)
|
|
7
|
+
from .configuration_cosmos import RBLNCosmosTextToWorldPipelineConfig, RBLNCosmosVideoToWorldPipelineConfig
|
|
8
|
+
from .configuration_kandinsky2_2 import (
|
|
9
|
+
RBLNKandinskyV22CombinedPipelineConfig,
|
|
10
|
+
RBLNKandinskyV22Img2ImgCombinedPipelineConfig,
|
|
11
|
+
RBLNKandinskyV22Img2ImgPipelineConfig,
|
|
12
|
+
RBLNKandinskyV22InpaintCombinedPipelineConfig,
|
|
13
|
+
RBLNKandinskyV22InpaintPipelineConfig,
|
|
14
|
+
RBLNKandinskyV22PipelineConfig,
|
|
15
|
+
RBLNKandinskyV22PriorPipelineConfig,
|
|
16
|
+
)
|
|
17
|
+
from .configuration_stable_diffusion import (
|
|
18
|
+
RBLNStableDiffusionImg2ImgPipelineConfig,
|
|
19
|
+
RBLNStableDiffusionInpaintPipelineConfig,
|
|
20
|
+
RBLNStableDiffusionPipelineConfig,
|
|
21
|
+
)
|
|
22
|
+
from .configuration_stable_diffusion_3 import (
|
|
23
|
+
RBLNStableDiffusion3Img2ImgPipelineConfig,
|
|
24
|
+
RBLNStableDiffusion3InpaintPipelineConfig,
|
|
25
|
+
RBLNStableDiffusion3PipelineConfig,
|
|
26
|
+
)
|
|
27
|
+
from .configuration_stable_diffusion_xl import (
|
|
28
|
+
RBLNStableDiffusionXLImg2ImgPipelineConfig,
|
|
29
|
+
RBLNStableDiffusionXLInpaintPipelineConfig,
|
|
30
|
+
RBLNStableDiffusionXLPipelineConfig,
|
|
31
|
+
)
|
|
32
|
+
from .configuration_stable_video_diffusion import (
|
|
33
|
+
RBLNStableVideoDiffusionPipelineConfig,
|
|
34
|
+
)
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# Copyright 2025 Rebellions Inc. 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 typing import Any, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
|
18
|
+
from ....transformers import RBLNCLIPTextModelConfig, RBLNCLIPTextModelWithProjectionConfig
|
|
19
|
+
from ..models import RBLNAutoencoderKLConfig, RBLNControlNetModelConfig, RBLNUNet2DConditionModelConfig
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RBLNStableDiffusionControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
23
|
+
submodules = ["text_encoder", "unet", "vae", "controlnet"]
|
|
24
|
+
_vae_uses_encoder = False
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
text_encoder: Optional[RBLNCLIPTextModelConfig] = None,
|
|
29
|
+
unet: Optional[RBLNUNet2DConditionModelConfig] = None,
|
|
30
|
+
vae: Optional[RBLNAutoencoderKLConfig] = None,
|
|
31
|
+
controlnet: Optional[RBLNControlNetModelConfig] = None,
|
|
32
|
+
*,
|
|
33
|
+
batch_size: Optional[int] = None,
|
|
34
|
+
img_height: Optional[int] = None,
|
|
35
|
+
img_width: Optional[int] = None,
|
|
36
|
+
height: Optional[int] = None,
|
|
37
|
+
width: Optional[int] = None,
|
|
38
|
+
sample_size: Optional[Tuple[int, int]] = None,
|
|
39
|
+
image_size: Optional[Tuple[int, int]] = None,
|
|
40
|
+
guidance_scale: Optional[float] = None,
|
|
41
|
+
**kwargs: Any,
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Args:
|
|
45
|
+
text_encoder (Optional[RBLNCLIPTextModelConfig]): Configuration for the text encoder component.
|
|
46
|
+
Initialized as RBLNCLIPTextModelConfig if not provided.
|
|
47
|
+
unet (Optional[RBLNUNet2DConditionModelConfig]): Configuration for the UNet model component.
|
|
48
|
+
Initialized as RBLNUNet2DConditionModelConfig if not provided.
|
|
49
|
+
vae (Optional[RBLNAutoencoderKLConfig]): Configuration for the VAE model component.
|
|
50
|
+
Initialized as RBLNAutoencoderKLConfig if not provided.
|
|
51
|
+
controlnet (Optional[RBLNControlNetModelConfig]): Configuration for the ControlNet model component.
|
|
52
|
+
Initialized as RBLNControlNetModelConfig if not provided.
|
|
53
|
+
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
|
54
|
+
img_height (Optional[int]): Height of the generated images.
|
|
55
|
+
img_width (Optional[int]): Width of the generated images.
|
|
56
|
+
height (Optional[int]): Height of the generated images.
|
|
57
|
+
width (Optional[int]): Width of the generated images.
|
|
58
|
+
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
|
59
|
+
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
|
60
|
+
Cannot be used together with img_height/img_width.
|
|
61
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
|
62
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
ValueError: If both image_size and img_height/img_width are provided.
|
|
66
|
+
|
|
67
|
+
Note:
|
|
68
|
+
When guidance_scale > 1.0, the UNet batch size is automatically doubled to
|
|
69
|
+
accommodate classifier-free guidance.
|
|
70
|
+
"""
|
|
71
|
+
super().__init__(**kwargs)
|
|
72
|
+
|
|
73
|
+
# Initial check for image_size conflict remains as is
|
|
74
|
+
if image_size is not None and (
|
|
75
|
+
img_height is not None or img_width is not None or height is not None or width is not None
|
|
76
|
+
):
|
|
77
|
+
raise ValueError("image_size cannot be provided alongside img_height/img_width or height/width")
|
|
78
|
+
|
|
79
|
+
# Prioritize height/width (HF-aligned)
|
|
80
|
+
if height is not None and width is not None:
|
|
81
|
+
if img_height is not None or img_width is not None:
|
|
82
|
+
# Raise error if both sets of arguments are provided
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"Cannot provide both 'height'/'width' and 'img_height'/'img_width' simultaneously. "
|
|
85
|
+
"Please use one set of arguments for image dimensions, preferring 'height'/'width'."
|
|
86
|
+
)
|
|
87
|
+
image_size = (height, width)
|
|
88
|
+
elif (height is not None and width is None) or (height is None and width is not None):
|
|
89
|
+
raise ValueError("Both height and width must be provided together if used")
|
|
90
|
+
# Fallback to img_height/img_width for backward compatibility
|
|
91
|
+
elif img_height is not None and img_width is not None:
|
|
92
|
+
image_size = (img_height, img_width)
|
|
93
|
+
elif (img_height is not None and img_width is None) or (img_height is None and img_width is not None):
|
|
94
|
+
raise ValueError("Both img_height and img_width must be provided together if used")
|
|
95
|
+
|
|
96
|
+
self.text_encoder = self.initialize_submodule_config(
|
|
97
|
+
text_encoder,
|
|
98
|
+
cls_name="RBLNCLIPTextModelConfig",
|
|
99
|
+
batch_size=batch_size,
|
|
100
|
+
)
|
|
101
|
+
self.unet = self.initialize_submodule_config(
|
|
102
|
+
unet,
|
|
103
|
+
cls_name="RBLNUNet2DConditionModelConfig",
|
|
104
|
+
sample_size=sample_size,
|
|
105
|
+
)
|
|
106
|
+
self.vae = self.initialize_submodule_config(
|
|
107
|
+
vae,
|
|
108
|
+
cls_name="RBLNAutoencoderKLConfig",
|
|
109
|
+
batch_size=batch_size,
|
|
110
|
+
uses_encoder=self.__class__._vae_uses_encoder,
|
|
111
|
+
sample_size=image_size, # image size is equal to sample size in vae
|
|
112
|
+
)
|
|
113
|
+
self.controlnet = self.initialize_submodule_config(
|
|
114
|
+
controlnet,
|
|
115
|
+
cls_name="RBLNControlNetModelConfig",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Get default guidance scale from original class to set UNet and ControlNet batch size
|
|
119
|
+
if guidance_scale is None:
|
|
120
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
|
121
|
+
|
|
122
|
+
if guidance_scale is not None:
|
|
123
|
+
do_classifier_free_guidance = guidance_scale > 1.0
|
|
124
|
+
if do_classifier_free_guidance:
|
|
125
|
+
if not self.unet.batch_size_is_specified:
|
|
126
|
+
self.unet.batch_size = self.text_encoder.batch_size * 2
|
|
127
|
+
if not self.controlnet.batch_size_is_specified:
|
|
128
|
+
self.controlnet.batch_size = self.text_encoder.batch_size * 2
|
|
129
|
+
else:
|
|
130
|
+
if not self.unet.batch_size_is_specified:
|
|
131
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
|
132
|
+
if not self.controlnet.batch_size_is_specified:
|
|
133
|
+
self.controlnet.batch_size = self.text_encoder.batch_size
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def batch_size(self):
|
|
137
|
+
return self.vae.batch_size
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def sample_size(self):
|
|
141
|
+
return self.unet.sample_size
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def image_size(self):
|
|
145
|
+
return self.vae.sample_size
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class RBLNStableDiffusionControlNetPipelineConfig(RBLNStableDiffusionControlNetPipelineBaseConfig):
|
|
149
|
+
"""
|
|
150
|
+
Configuration for Stable Diffusion ControlNet pipeline.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
_vae_uses_encoder = False
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class RBLNStableDiffusionControlNetImg2ImgPipelineConfig(RBLNStableDiffusionControlNetPipelineBaseConfig):
|
|
157
|
+
"""
|
|
158
|
+
Configuration for Stable Diffusion ControlNet image-to-image pipeline.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
_vae_uses_encoder = True
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class RBLNStableDiffusionXLControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
165
|
+
"""
|
|
166
|
+
Base configuration for Stable Diffusion XL ControlNet pipelines.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
submodules = ["text_encoder", "text_encoder_2", "unet", "vae", "controlnet"]
|
|
170
|
+
_vae_uses_encoder = False
|
|
171
|
+
|
|
172
|
+
def __init__(
|
|
173
|
+
self,
|
|
174
|
+
text_encoder: Optional[RBLNCLIPTextModelConfig] = None,
|
|
175
|
+
text_encoder_2: Optional[RBLNCLIPTextModelWithProjectionConfig] = None,
|
|
176
|
+
unet: Optional[RBLNUNet2DConditionModelConfig] = None,
|
|
177
|
+
vae: Optional[RBLNAutoencoderKLConfig] = None,
|
|
178
|
+
controlnet: Optional[RBLNControlNetModelConfig] = None,
|
|
179
|
+
*,
|
|
180
|
+
batch_size: Optional[int] = None,
|
|
181
|
+
img_height: Optional[int] = None,
|
|
182
|
+
img_width: Optional[int] = None,
|
|
183
|
+
height: Optional[int] = None,
|
|
184
|
+
width: Optional[int] = None,
|
|
185
|
+
sample_size: Optional[Tuple[int, int]] = None,
|
|
186
|
+
image_size: Optional[Tuple[int, int]] = None,
|
|
187
|
+
guidance_scale: Optional[float] = None,
|
|
188
|
+
**kwargs: Any,
|
|
189
|
+
):
|
|
190
|
+
"""
|
|
191
|
+
Args:
|
|
192
|
+
text_encoder (Optional[RBLNCLIPTextModelConfig]): Configuration for the primary text encoder.
|
|
193
|
+
Initialized as RBLNCLIPTextModelConfig if not provided.
|
|
194
|
+
text_encoder_2 (Optional[RBLNCLIPTextModelWithProjectionConfig]): Configuration for the secondary text encoder.
|
|
195
|
+
Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided.
|
|
196
|
+
unet (Optional[RBLNUNet2DConditionModelConfig]): Configuration for the UNet model component.
|
|
197
|
+
Initialized as RBLNUNet2DConditionModelConfig if not provided.
|
|
198
|
+
vae (Optional[RBLNAutoencoderKLConfig]): Configuration for the VAE model component.
|
|
199
|
+
Initialized as RBLNAutoencoderKLConfig if not provided.
|
|
200
|
+
controlnet (Optional[RBLNControlNetModelConfig]): Configuration for the ControlNet model component.
|
|
201
|
+
Initialized as RBLNControlNetModelConfig if not provided.
|
|
202
|
+
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
|
203
|
+
img_height (Optional[int]): Height of the generated images.
|
|
204
|
+
img_width (Optional[int]): Width of the generated images.
|
|
205
|
+
height (Optional[int]): Height of the generated images.
|
|
206
|
+
width (Optional[int]): Width of the generated images.
|
|
207
|
+
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
|
208
|
+
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
|
209
|
+
Cannot be used together with img_height/img_width.
|
|
210
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
|
211
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
212
|
+
|
|
213
|
+
Raises:
|
|
214
|
+
ValueError: If both image_size and img_height/img_width are provided.
|
|
215
|
+
|
|
216
|
+
Note:
|
|
217
|
+
When guidance_scale > 1.0, the UNet batch size is automatically doubled to
|
|
218
|
+
accommodate classifier-free guidance.
|
|
219
|
+
"""
|
|
220
|
+
super().__init__(**kwargs)
|
|
221
|
+
|
|
222
|
+
# Initial check for image_size conflict remains as is
|
|
223
|
+
if image_size is not None and (
|
|
224
|
+
img_height is not None or img_width is not None or height is not None or width is not None
|
|
225
|
+
):
|
|
226
|
+
raise ValueError("image_size cannot be provided alongside img_height/img_width or height/width")
|
|
227
|
+
|
|
228
|
+
# Prioritize height/width (HF-aligned)
|
|
229
|
+
if height is not None and width is not None:
|
|
230
|
+
if img_height is not None or img_width is not None:
|
|
231
|
+
# Raise error if both sets of arguments are provided
|
|
232
|
+
raise ValueError(
|
|
233
|
+
"Cannot provide both 'height'/'width' and 'img_height'/'img_width' simultaneously. "
|
|
234
|
+
"Please use one set of arguments for image dimensions, preferring 'height'/'width'."
|
|
235
|
+
)
|
|
236
|
+
image_size = (height, width)
|
|
237
|
+
elif (height is not None and width is None) or (height is None and width is not None):
|
|
238
|
+
raise ValueError("Both height and width must be provided together if used")
|
|
239
|
+
# Fallback to img_height/img_width for backward compatibility
|
|
240
|
+
elif img_height is not None and img_width is not None:
|
|
241
|
+
image_size = (img_height, img_width)
|
|
242
|
+
elif (img_height is not None and img_width is None) or (img_height is None and img_width is not None):
|
|
243
|
+
raise ValueError("Both img_height and img_width must be provided together if used")
|
|
244
|
+
|
|
245
|
+
self.text_encoder = self.initialize_submodule_config(
|
|
246
|
+
text_encoder,
|
|
247
|
+
cls_name="RBLNCLIPTextModelConfig",
|
|
248
|
+
batch_size=batch_size,
|
|
249
|
+
)
|
|
250
|
+
self.text_encoder_2 = self.initialize_submodule_config(
|
|
251
|
+
text_encoder_2,
|
|
252
|
+
cls_name="RBLNCLIPTextModelWithProjectionConfig",
|
|
253
|
+
batch_size=batch_size,
|
|
254
|
+
)
|
|
255
|
+
self.unet = self.initialize_submodule_config(
|
|
256
|
+
unet,
|
|
257
|
+
cls_name="RBLNUNet2DConditionModelConfig",
|
|
258
|
+
sample_size=sample_size,
|
|
259
|
+
)
|
|
260
|
+
self.vae = self.initialize_submodule_config(
|
|
261
|
+
vae,
|
|
262
|
+
cls_name="RBLNAutoencoderKLConfig",
|
|
263
|
+
batch_size=batch_size,
|
|
264
|
+
uses_encoder=self.__class__._vae_uses_encoder,
|
|
265
|
+
sample_size=image_size, # image size is equal to sample size in vae
|
|
266
|
+
)
|
|
267
|
+
self.controlnet = self.initialize_submodule_config(
|
|
268
|
+
controlnet,
|
|
269
|
+
cls_name="RBLNControlNetModelConfig",
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
# Get default guidance scale from original class to set UNet and ControlNet batch size
|
|
273
|
+
guidance_scale = (
|
|
274
|
+
guidance_scale
|
|
275
|
+
or self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
do_classifier_free_guidance = guidance_scale > 1.0
|
|
279
|
+
if do_classifier_free_guidance:
|
|
280
|
+
if not self.unet.batch_size_is_specified:
|
|
281
|
+
self.unet.batch_size = self.text_encoder.batch_size * 2
|
|
282
|
+
if not self.controlnet.batch_size_is_specified:
|
|
283
|
+
self.controlnet.batch_size = self.text_encoder.batch_size * 2
|
|
284
|
+
else:
|
|
285
|
+
if not self.unet.batch_size_is_specified:
|
|
286
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
|
287
|
+
if not self.controlnet.batch_size_is_specified:
|
|
288
|
+
self.controlnet.batch_size = self.text_encoder.batch_size
|
|
289
|
+
|
|
290
|
+
@property
|
|
291
|
+
def batch_size(self):
|
|
292
|
+
return self.vae.batch_size
|
|
293
|
+
|
|
294
|
+
@property
|
|
295
|
+
def sample_size(self):
|
|
296
|
+
return self.unet.sample_size
|
|
297
|
+
|
|
298
|
+
@property
|
|
299
|
+
def image_size(self):
|
|
300
|
+
return self.vae.sample_size
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class RBLNStableDiffusionXLControlNetPipelineConfig(RBLNStableDiffusionXLControlNetPipelineBaseConfig):
|
|
304
|
+
"""
|
|
305
|
+
Configuration for Stable Diffusion XL ControlNet pipeline.
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
_vae_uses_encoder = False
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class RBLNStableDiffusionXLControlNetImg2ImgPipelineConfig(RBLNStableDiffusionXLControlNetPipelineBaseConfig):
|
|
312
|
+
"""
|
|
313
|
+
Configuration for Stable Diffusion XL ControlNet image-to-image pipeline.
|
|
314
|
+
"""
|
|
315
|
+
|
|
316
|
+
_vae_uses_encoder = True
|