optimum-rbln 0.7.4a8__py3-none-any.whl → 0.7.5a0__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.
- optimum/rbln/__init__.py +1 -0
- optimum/rbln/__version__.py +2 -2
- optimum/rbln/configuration_utils.py +30 -4
- optimum/rbln/diffusers/configurations/models/configuration_controlnet.py +8 -0
- optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py +8 -0
- optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py +8 -0
- optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py +8 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py +32 -17
- optimum/rbln/diffusers/configurations/pipelines/configuration_kandinsky2_2.py +19 -15
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion.py +8 -8
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_3.py +8 -8
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_xl.py +8 -8
- optimum/rbln/diffusers/modeling_diffusers.py +9 -2
- optimum/rbln/diffusers/models/controlnet.py +1 -1
- optimum/rbln/diffusers/models/transformers/transformer_sd3.py +1 -1
- optimum/rbln/diffusers/models/unets/unet_2d_condition.py +1 -1
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +2 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +2 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +2 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +2 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpaint.py +2 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +2 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +2 -0
- optimum/rbln/transformers/models/decoderonly/configuration_decoderonly.py +31 -1
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +103 -59
- optimum/rbln/utils/import_utils.py +23 -6
- {optimum_rbln-0.7.4a8.dist-info → optimum_rbln-0.7.5a0.dist-info}/METADATA +1 -1
- {optimum_rbln-0.7.4a8.dist-info → optimum_rbln-0.7.5a0.dist-info}/RECORD +41 -41
- {optimum_rbln-0.7.4a8.dist-info → optimum_rbln-0.7.5a0.dist-info}/WHEEL +0 -0
- {optimum_rbln-0.7.4a8.dist-info → optimum_rbln-0.7.5a0.dist-info}/licenses/LICENSE +0 -0
optimum/rbln/__init__.py
CHANGED
optimum/rbln/__version__.py
CHANGED
@@ -17,5 +17,5 @@ __version__: str
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
18
18
|
version_tuple: VERSION_TUPLE
|
19
19
|
|
20
|
-
__version__ = version = '0.7.
|
21
|
-
__version_tuple__ = version_tuple = (0, 7,
|
20
|
+
__version__ = version = '0.7.5a0'
|
21
|
+
__version_tuple__ = version_tuple = (0, 7, 5, 'a0')
|
@@ -19,7 +19,6 @@ from dataclasses import asdict, dataclass
|
|
19
19
|
from pathlib import Path
|
20
20
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
21
21
|
|
22
|
-
import rebel
|
23
22
|
import torch
|
24
23
|
|
25
24
|
from .__version__ import __version__
|
@@ -452,6 +451,7 @@ class RBLNModelConfig:
|
|
452
451
|
"activate_profiler",
|
453
452
|
]
|
454
453
|
submodules: List[str] = []
|
454
|
+
subclass_non_save_attributes = []
|
455
455
|
|
456
456
|
def init_submodule_config(
|
457
457
|
self,
|
@@ -480,7 +480,11 @@ class RBLNModelConfig:
|
|
480
480
|
return submodule_config
|
481
481
|
|
482
482
|
def __setattr__(self, key, value):
|
483
|
-
if
|
483
|
+
if (
|
484
|
+
key != "_attributes_map"
|
485
|
+
and key not in self.non_save_attributes
|
486
|
+
and key not in self.subclass_non_save_attributes
|
487
|
+
):
|
484
488
|
self._attributes_map[key] = value
|
485
489
|
|
486
490
|
if hasattr(self, "_frozen") and self._frozen:
|
@@ -528,7 +532,7 @@ class RBLNModelConfig:
|
|
528
532
|
|
529
533
|
Args:
|
530
534
|
cls_name (Optional[str]): The class name of the configuration. Defaults to the current class name.
|
531
|
-
create_runtimes (Optional[bool]): Whether to create RBLN runtimes. Defaults to True
|
535
|
+
create_runtimes (Optional[bool]): Whether to create RBLN runtimes. Defaults to True.
|
532
536
|
optimize_host_memory (Optional[bool]): Whether to optimize host memory usage. Defaults to True.
|
533
537
|
device (Optional[Union[int, List[int]]]): The device(s) to load the model onto. Can be a single device ID or a list.
|
534
538
|
device_map (Optional[Dict[str, Union[int, List[int]]]]): Mapping from compiled model names to device IDs.
|
@@ -723,13 +727,35 @@ class RBLNModelConfig:
|
|
723
727
|
|
724
728
|
return rbln_config, kwargs
|
725
729
|
|
730
|
+
def get_default_values_for_original_cls(self, func_name: str, keys: List[str]) -> Dict[str, Any]:
|
731
|
+
"""
|
732
|
+
Get default values for original class attributes from RBLNModelConfig.
|
733
|
+
|
734
|
+
Args:
|
735
|
+
func_name (str): The name of the function to get the default values for.
|
736
|
+
keys (List[str]): The keys of the attributes to get.
|
737
|
+
|
738
|
+
Returns:
|
739
|
+
Dict[str, Any]: The default values for the attributes.
|
740
|
+
"""
|
741
|
+
model_cls = self.rbln_model_cls.get_hf_class()
|
742
|
+
func = getattr(model_cls, func_name)
|
743
|
+
func_signature = inspect.signature(func)
|
744
|
+
default_values = {}
|
745
|
+
for key in keys:
|
746
|
+
if key in func_signature.parameters:
|
747
|
+
default_values[key] = func_signature.parameters[key].default
|
748
|
+
else:
|
749
|
+
raise ValueError(f"Default value for `{key}` is not set for the model class.")
|
750
|
+
return default_values
|
751
|
+
|
726
752
|
@property
|
727
753
|
def create_runtimes(self):
|
728
754
|
context = ContextRblnConfig.get_current_context()["create_runtimes"]
|
729
755
|
if context is not None:
|
730
756
|
return context
|
731
757
|
elif self._runtime_options["create_runtimes"] is None:
|
732
|
-
return
|
758
|
+
return True
|
733
759
|
return self._runtime_options["create_runtimes"]
|
734
760
|
|
735
761
|
@create_runtimes.setter
|
@@ -18,6 +18,8 @@ from ....configuration_utils import RBLNModelConfig
|
|
18
18
|
|
19
19
|
|
20
20
|
class RBLNControlNetModelConfig(RBLNModelConfig):
|
21
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
22
|
+
|
21
23
|
def __init__(
|
22
24
|
self,
|
23
25
|
batch_size: Optional[int] = None,
|
@@ -44,6 +46,8 @@ class RBLNControlNetModelConfig(RBLNModelConfig):
|
|
44
46
|
ValueError: If batch_size is not a positive integer.
|
45
47
|
"""
|
46
48
|
super().__init__(**kwargs)
|
49
|
+
self._batch_size_is_specified = batch_size is not None
|
50
|
+
|
47
51
|
self.batch_size = batch_size or 1
|
48
52
|
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
49
53
|
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
@@ -52,3 +56,7 @@ class RBLNControlNetModelConfig(RBLNModelConfig):
|
|
52
56
|
self.unet_sample_size = unet_sample_size
|
53
57
|
self.vae_sample_size = vae_sample_size
|
54
58
|
self.text_model_hidden_size = text_model_hidden_size
|
59
|
+
|
60
|
+
@property
|
61
|
+
def batch_size_is_specified(self):
|
62
|
+
return self._batch_size_is_specified
|
@@ -18,6 +18,8 @@ from ....configuration_utils import RBLNModelConfig
|
|
18
18
|
|
19
19
|
|
20
20
|
class RBLNPriorTransformerConfig(RBLNModelConfig):
|
21
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
22
|
+
|
21
23
|
def __init__(
|
22
24
|
self,
|
23
25
|
batch_size: Optional[int] = None,
|
@@ -36,9 +38,15 @@ class RBLNPriorTransformerConfig(RBLNModelConfig):
|
|
36
38
|
ValueError: If batch_size is not a positive integer.
|
37
39
|
"""
|
38
40
|
super().__init__(**kwargs)
|
41
|
+
self._batch_size_is_specified = batch_size is not None
|
42
|
+
|
39
43
|
self.batch_size = batch_size or 1
|
40
44
|
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
41
45
|
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
42
46
|
|
43
47
|
self.embedding_dim = embedding_dim
|
44
48
|
self.num_embeddings = num_embeddings
|
49
|
+
|
50
|
+
@property
|
51
|
+
def batch_size_is_specified(self):
|
52
|
+
return self._batch_size_is_specified
|
@@ -18,6 +18,8 @@ from ....configuration_utils import RBLNModelConfig
|
|
18
18
|
|
19
19
|
|
20
20
|
class RBLNSD3Transformer2DModelConfig(RBLNModelConfig):
|
21
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
22
|
+
|
21
23
|
def __init__(
|
22
24
|
self,
|
23
25
|
batch_size: Optional[int] = None,
|
@@ -38,6 +40,8 @@ class RBLNSD3Transformer2DModelConfig(RBLNModelConfig):
|
|
38
40
|
ValueError: If batch_size is not a positive integer.
|
39
41
|
"""
|
40
42
|
super().__init__(**kwargs)
|
43
|
+
self._batch_size_is_specified = batch_size is not None
|
44
|
+
|
41
45
|
self.batch_size = batch_size or 1
|
42
46
|
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
43
47
|
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
@@ -46,3 +50,7 @@ class RBLNSD3Transformer2DModelConfig(RBLNModelConfig):
|
|
46
50
|
self.sample_size = sample_size
|
47
51
|
if isinstance(self.sample_size, int):
|
48
52
|
self.sample_size = (self.sample_size, self.sample_size)
|
53
|
+
|
54
|
+
@property
|
55
|
+
def batch_size_is_specified(self):
|
56
|
+
return self._batch_size_is_specified
|
@@ -18,6 +18,8 @@ from ....configuration_utils import RBLNModelConfig
|
|
18
18
|
|
19
19
|
|
20
20
|
class RBLNUNet2DConditionModelConfig(RBLNModelConfig):
|
21
|
+
subclass_non_save_attributes = ["_batch_size_is_specified"]
|
22
|
+
|
21
23
|
def __init__(
|
22
24
|
self,
|
23
25
|
batch_size: Optional[int] = None,
|
@@ -49,6 +51,8 @@ class RBLNUNet2DConditionModelConfig(RBLNModelConfig):
|
|
49
51
|
ValueError: If batch_size is not a positive integer.
|
50
52
|
"""
|
51
53
|
super().__init__(**kwargs)
|
54
|
+
self._batch_size_is_specified = batch_size is not None
|
55
|
+
|
52
56
|
self.batch_size = batch_size or 1
|
53
57
|
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
54
58
|
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
@@ -64,3 +68,7 @@ class RBLNUNet2DConditionModelConfig(RBLNModelConfig):
|
|
64
68
|
self.sample_size = sample_size
|
65
69
|
if isinstance(sample_size, int):
|
66
70
|
self.sample_size = (sample_size, sample_size)
|
71
|
+
|
72
|
+
@property
|
73
|
+
def batch_size_is_specified(self):
|
74
|
+
return self._batch_size_is_specified
|
@@ -16,13 +16,9 @@ from typing import Optional, Tuple
|
|
16
16
|
|
17
17
|
from ....configuration_utils import RBLNModelConfig
|
18
18
|
from ....transformers import RBLNCLIPTextModelConfig, RBLNCLIPTextModelWithProjectionConfig
|
19
|
-
from ....utils.logging import get_logger
|
20
19
|
from ..models import RBLNAutoencoderKLConfig, RBLNControlNetModelConfig, RBLNUNet2DConditionModelConfig
|
21
20
|
|
22
21
|
|
23
|
-
logger = get_logger(__name__)
|
24
|
-
|
25
|
-
|
26
22
|
class _RBLNStableDiffusionControlNetPipelineBaseConfig(RBLNModelConfig):
|
27
23
|
submodules = ["text_encoder", "unet", "vae", "controlnet"]
|
28
24
|
_vae_uses_encoder = False
|
@@ -58,7 +54,7 @@ class _RBLNStableDiffusionControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
58
54
|
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
59
55
|
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
60
56
|
Cannot be used together with img_height/img_width.
|
61
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
57
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
62
58
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
63
59
|
|
64
60
|
Raises:
|
@@ -79,7 +75,6 @@ class _RBLNStableDiffusionControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
79
75
|
self.unet = self.init_submodule_config(
|
80
76
|
RBLNUNet2DConditionModelConfig,
|
81
77
|
unet,
|
82
|
-
batch_size=batch_size,
|
83
78
|
sample_size=sample_size,
|
84
79
|
)
|
85
80
|
self.vae = self.init_submodule_config(
|
@@ -89,14 +84,24 @@ class _RBLNStableDiffusionControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
89
84
|
uses_encoder=self.__class__._vae_uses_encoder,
|
90
85
|
sample_size=image_size, # image size is equal to sample size in vae
|
91
86
|
)
|
92
|
-
self.controlnet = self.init_submodule_config(RBLNControlNetModelConfig, controlnet
|
87
|
+
self.controlnet = self.init_submodule_config(RBLNControlNetModelConfig, controlnet)
|
88
|
+
|
89
|
+
# Get default guidance scale from original class to set UNet and ControlNet batch size
|
90
|
+
if guidance_scale is None:
|
91
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
93
92
|
|
94
93
|
if guidance_scale is not None:
|
95
|
-
logger.warning("Specifying `guidance_scale` is deprecated. It will be removed in a future version.")
|
96
94
|
do_classifier_free_guidance = guidance_scale > 1.0
|
97
95
|
if do_classifier_free_guidance:
|
98
|
-
|
99
|
-
|
96
|
+
if not self.unet.batch_size_is_specified:
|
97
|
+
self.unet.batch_size = self.text_encoder.batch_size * 2
|
98
|
+
if not self.controlnet.batch_size_is_specified:
|
99
|
+
self.controlnet.batch_size = self.text_encoder.batch_size * 2
|
100
|
+
else:
|
101
|
+
if not self.unet.batch_size_is_specified:
|
102
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
103
|
+
if not self.controlnet.batch_size_is_specified:
|
104
|
+
self.controlnet.batch_size = self.text_encoder.batch_size
|
100
105
|
|
101
106
|
@property
|
102
107
|
def batch_size(self):
|
@@ -157,7 +162,7 @@ class _RBLNStableDiffusionXLControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
157
162
|
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
158
163
|
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
159
164
|
Cannot be used together with img_height/img_width.
|
160
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
165
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
161
166
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
162
167
|
|
163
168
|
Raises:
|
@@ -181,7 +186,6 @@ class _RBLNStableDiffusionXLControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
181
186
|
self.unet = self.init_submodule_config(
|
182
187
|
RBLNUNet2DConditionModelConfig,
|
183
188
|
unet,
|
184
|
-
batch_size=batch_size,
|
185
189
|
sample_size=sample_size,
|
186
190
|
)
|
187
191
|
self.vae = self.init_submodule_config(
|
@@ -191,14 +195,25 @@ class _RBLNStableDiffusionXLControlNetPipelineBaseConfig(RBLNModelConfig):
|
|
191
195
|
uses_encoder=self.__class__._vae_uses_encoder,
|
192
196
|
sample_size=image_size, # image size is equal to sample size in vae
|
193
197
|
)
|
194
|
-
self.controlnet = self.init_submodule_config(RBLNControlNetModelConfig, controlnet
|
198
|
+
self.controlnet = self.init_submodule_config(RBLNControlNetModelConfig, controlnet)
|
195
199
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
+
# Get default guidance scale from original class to set UNet and ControlNet batch size
|
201
|
+
guidance_scale = (
|
202
|
+
guidance_scale
|
203
|
+
or self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
204
|
+
)
|
205
|
+
|
206
|
+
do_classifier_free_guidance = guidance_scale > 1.0
|
207
|
+
if do_classifier_free_guidance:
|
208
|
+
if not self.unet.batch_size_is_specified:
|
200
209
|
self.unet.batch_size = self.text_encoder.batch_size * 2
|
210
|
+
if not self.controlnet.batch_size_is_specified:
|
201
211
|
self.controlnet.batch_size = self.text_encoder.batch_size * 2
|
212
|
+
else:
|
213
|
+
if not self.unet.batch_size_is_specified:
|
214
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
215
|
+
if not self.controlnet.batch_size_is_specified:
|
216
|
+
self.controlnet.batch_size = self.text_encoder.batch_size
|
202
217
|
|
203
218
|
@property
|
204
219
|
def batch_size(self):
|
@@ -16,14 +16,10 @@ from typing import Optional, Tuple
|
|
16
16
|
|
17
17
|
from ....configuration_utils import RBLNModelConfig
|
18
18
|
from ....transformers import RBLNCLIPTextModelWithProjectionConfig, RBLNCLIPVisionModelWithProjectionConfig
|
19
|
-
from ....utils.logging import get_logger
|
20
19
|
from ..models import RBLNUNet2DConditionModelConfig, RBLNVQModelConfig
|
21
20
|
from ..models.configuration_prior_transformer import RBLNPriorTransformerConfig
|
22
21
|
|
23
22
|
|
24
|
-
logger = get_logger(__name__)
|
25
|
-
|
26
|
-
|
27
23
|
class _RBLNKandinskyV22PipelineBaseConfig(RBLNModelConfig):
|
28
24
|
submodules = ["unet", "movq"]
|
29
25
|
_movq_uses_encoder = False
|
@@ -49,7 +45,7 @@ class _RBLNKandinskyV22PipelineBaseConfig(RBLNModelConfig):
|
|
49
45
|
Initialized as RBLNVQModelConfig if not provided.
|
50
46
|
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
51
47
|
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
52
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
48
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
53
49
|
image_size (Optional[Tuple[int, int]]): Dimensions for the generated images.
|
54
50
|
Cannot be used together with img_height/img_width.
|
55
51
|
img_height (Optional[int]): Height of the generated images.
|
@@ -70,9 +66,7 @@ class _RBLNKandinskyV22PipelineBaseConfig(RBLNModelConfig):
|
|
70
66
|
if img_height is not None and img_width is not None:
|
71
67
|
image_size = (img_height, img_width)
|
72
68
|
|
73
|
-
self.unet = self.init_submodule_config(
|
74
|
-
RBLNUNet2DConditionModelConfig, unet, batch_size=batch_size, sample_size=sample_size
|
75
|
-
)
|
69
|
+
self.unet = self.init_submodule_config(RBLNUNet2DConditionModelConfig, unet, sample_size=sample_size)
|
76
70
|
self.movq = self.init_submodule_config(
|
77
71
|
RBLNVQModelConfig,
|
78
72
|
movq,
|
@@ -81,11 +75,16 @@ class _RBLNKandinskyV22PipelineBaseConfig(RBLNModelConfig):
|
|
81
75
|
uses_encoder=self._movq_uses_encoder,
|
82
76
|
)
|
83
77
|
|
84
|
-
|
85
|
-
|
78
|
+
# Get default guidance scale from original class to set UNet batch size
|
79
|
+
if guidance_scale is None:
|
80
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
81
|
+
|
82
|
+
if not self.unet.batch_size_is_specified:
|
86
83
|
do_classifier_free_guidance = guidance_scale > 1.0
|
87
84
|
if do_classifier_free_guidance:
|
88
85
|
self.unet.batch_size = self.movq.batch_size * 2
|
86
|
+
else:
|
87
|
+
self.unet.batch_size = self.movq.batch_size
|
89
88
|
|
90
89
|
@property
|
91
90
|
def batch_size(self):
|
@@ -136,7 +135,7 @@ class RBLNKandinskyV22PriorPipelineConfig(RBLNModelConfig):
|
|
136
135
|
prior (Optional[RBLNPriorTransformerConfig]): Configuration for the prior transformer component.
|
137
136
|
Initialized as RBLNPriorTransformerConfig if not provided.
|
138
137
|
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
139
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
138
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
140
139
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
141
140
|
|
142
141
|
Note:
|
@@ -151,13 +150,18 @@ class RBLNKandinskyV22PriorPipelineConfig(RBLNModelConfig):
|
|
151
150
|
RBLNCLIPVisionModelWithProjectionConfig, image_encoder, batch_size=batch_size
|
152
151
|
)
|
153
152
|
|
154
|
-
self.prior = self.init_submodule_config(RBLNPriorTransformerConfig, prior
|
153
|
+
self.prior = self.init_submodule_config(RBLNPriorTransformerConfig, prior)
|
154
|
+
|
155
|
+
# Get default guidance scale from original class to set UNet batch size
|
156
|
+
if guidance_scale is None:
|
157
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
155
158
|
|
156
|
-
if
|
157
|
-
logger.warning("Specifying `guidance_scale` is deprecated. It will be removed in a future version.")
|
159
|
+
if not self.prior.batch_size_is_specified:
|
158
160
|
do_classifier_free_guidance = guidance_scale > 1.0
|
159
161
|
if do_classifier_free_guidance:
|
160
162
|
self.prior.batch_size = self.text_encoder.batch_size * 2
|
163
|
+
else:
|
164
|
+
self.prior.batch_size = self.text_encoder.batch_size
|
161
165
|
|
162
166
|
@property
|
163
167
|
def batch_size(self):
|
@@ -208,7 +212,7 @@ class _RBLNKandinskyV22CombinedPipelineBaseConfig(RBLNModelConfig):
|
|
208
212
|
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
209
213
|
img_height (Optional[int]): Height of the generated images.
|
210
214
|
img_width (Optional[int]): Width of the generated images.
|
211
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
215
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
212
216
|
prior_prior (Optional[RBLNPriorTransformerConfig]): Direct configuration for the prior transformer.
|
213
217
|
Used if prior_pipe is not provided.
|
214
218
|
prior_image_encoder (Optional[RBLNCLIPVisionModelWithProjectionConfig]): Direct configuration for the image encoder.
|
@@ -16,13 +16,9 @@ from typing import Optional, Tuple
|
|
16
16
|
|
17
17
|
from ....configuration_utils import RBLNModelConfig
|
18
18
|
from ....transformers import RBLNCLIPTextModelConfig
|
19
|
-
from ....utils.logging import get_logger
|
20
19
|
from ..models import RBLNAutoencoderKLConfig, RBLNUNet2DConditionModelConfig
|
21
20
|
|
22
21
|
|
23
|
-
logger = get_logger(__name__)
|
24
|
-
|
25
|
-
|
26
22
|
class _RBLNStableDiffusionPipelineBaseConfig(RBLNModelConfig):
|
27
23
|
submodules = ["text_encoder", "unet", "vae"]
|
28
24
|
_vae_uses_encoder = False
|
@@ -55,7 +51,7 @@ class _RBLNStableDiffusionPipelineBaseConfig(RBLNModelConfig):
|
|
55
51
|
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
56
52
|
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
57
53
|
Cannot be used together with img_height/img_width.
|
58
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
54
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
59
55
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
60
56
|
|
61
57
|
Raises:
|
@@ -76,7 +72,6 @@ class _RBLNStableDiffusionPipelineBaseConfig(RBLNModelConfig):
|
|
76
72
|
self.unet = self.init_submodule_config(
|
77
73
|
RBLNUNet2DConditionModelConfig,
|
78
74
|
unet,
|
79
|
-
batch_size=batch_size,
|
80
75
|
sample_size=sample_size,
|
81
76
|
)
|
82
77
|
self.vae = self.init_submodule_config(
|
@@ -87,11 +82,16 @@ class _RBLNStableDiffusionPipelineBaseConfig(RBLNModelConfig):
|
|
87
82
|
sample_size=image_size, # image size is equal to sample size in vae
|
88
83
|
)
|
89
84
|
|
90
|
-
|
91
|
-
|
85
|
+
# Get default guidance scale from original class to set UNet batch size
|
86
|
+
if guidance_scale is None:
|
87
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
88
|
+
|
89
|
+
if not self.unet.batch_size_is_specified:
|
92
90
|
do_classifier_free_guidance = guidance_scale > 1.0
|
93
91
|
if do_classifier_free_guidance:
|
94
92
|
self.unet.batch_size = self.text_encoder.batch_size * 2
|
93
|
+
else:
|
94
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
95
95
|
|
96
96
|
@property
|
97
97
|
def batch_size(self):
|
@@ -16,13 +16,9 @@ from typing import Optional, Tuple
|
|
16
16
|
|
17
17
|
from ....configuration_utils import RBLNModelConfig
|
18
18
|
from ....transformers import RBLNCLIPTextModelWithProjectionConfig, RBLNT5EncoderModelConfig
|
19
|
-
from ....utils.logging import get_logger
|
20
19
|
from ..models import RBLNAutoencoderKLConfig, RBLNSD3Transformer2DModelConfig
|
21
20
|
|
22
21
|
|
23
|
-
logger = get_logger(__name__)
|
24
|
-
|
25
|
-
|
26
22
|
class _RBLNStableDiffusion3PipelineBaseConfig(RBLNModelConfig):
|
27
23
|
submodules = ["transformer", "text_encoder", "text_encoder_2", "text_encoder_3", "vae"]
|
28
24
|
_vae_uses_encoder = False
|
@@ -63,7 +59,7 @@ class _RBLNStableDiffusion3PipelineBaseConfig(RBLNModelConfig):
|
|
63
59
|
batch_size (Optional[int]): Batch size for inference, applied to all submodules.
|
64
60
|
img_height (Optional[int]): Height of the generated images.
|
65
61
|
img_width (Optional[int]): Width of the generated images.
|
66
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
62
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
67
63
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
68
64
|
|
69
65
|
Raises:
|
@@ -97,7 +93,6 @@ class _RBLNStableDiffusion3PipelineBaseConfig(RBLNModelConfig):
|
|
97
93
|
self.transformer = self.init_submodule_config(
|
98
94
|
RBLNSD3Transformer2DModelConfig,
|
99
95
|
transformer,
|
100
|
-
batch_size=batch_size,
|
101
96
|
sample_size=sample_size,
|
102
97
|
)
|
103
98
|
self.vae = self.init_submodule_config(
|
@@ -108,11 +103,16 @@ class _RBLNStableDiffusion3PipelineBaseConfig(RBLNModelConfig):
|
|
108
103
|
sample_size=image_size,
|
109
104
|
)
|
110
105
|
|
111
|
-
|
112
|
-
|
106
|
+
# Get default guidance scale from original class to set Transformer batch size
|
107
|
+
if guidance_scale is None:
|
108
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
109
|
+
|
110
|
+
if not self.transformer.batch_size_is_specified:
|
113
111
|
do_classifier_free_guidance = guidance_scale > 1.0
|
114
112
|
if do_classifier_free_guidance:
|
115
113
|
self.transformer.batch_size = self.text_encoder.batch_size * 2
|
114
|
+
else:
|
115
|
+
self.transformer.batch_size = self.text_encoder.batch_size
|
116
116
|
|
117
117
|
@property
|
118
118
|
def max_seq_len(self):
|
@@ -16,13 +16,9 @@ from typing import Optional, Tuple
|
|
16
16
|
|
17
17
|
from ....configuration_utils import RBLNModelConfig
|
18
18
|
from ....transformers import RBLNCLIPTextModelConfig, RBLNCLIPTextModelWithProjectionConfig
|
19
|
-
from ....utils.logging import get_logger
|
20
19
|
from ..models import RBLNAutoencoderKLConfig, RBLNUNet2DConditionModelConfig
|
21
20
|
|
22
21
|
|
23
|
-
logger = get_logger(__name__)
|
24
|
-
|
25
|
-
|
26
22
|
class _RBLNStableDiffusionXLPipelineBaseConfig(RBLNModelConfig):
|
27
23
|
submodules = ["text_encoder", "text_encoder_2", "unet", "vae"]
|
28
24
|
_vae_uses_encoder = False
|
@@ -58,7 +54,7 @@ class _RBLNStableDiffusionXLPipelineBaseConfig(RBLNModelConfig):
|
|
58
54
|
sample_size (Optional[Tuple[int, int]]): Spatial dimensions for the UNet model.
|
59
55
|
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
|
60
56
|
Cannot be used together with img_height/img_width.
|
61
|
-
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
57
|
+
guidance_scale (Optional[float]): Scale for classifier-free guidance.
|
62
58
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
63
59
|
|
64
60
|
Raises:
|
@@ -82,7 +78,6 @@ class _RBLNStableDiffusionXLPipelineBaseConfig(RBLNModelConfig):
|
|
82
78
|
self.unet = self.init_submodule_config(
|
83
79
|
RBLNUNet2DConditionModelConfig,
|
84
80
|
unet,
|
85
|
-
batch_size=batch_size,
|
86
81
|
sample_size=sample_size,
|
87
82
|
)
|
88
83
|
self.vae = self.init_submodule_config(
|
@@ -93,11 +88,16 @@ class _RBLNStableDiffusionXLPipelineBaseConfig(RBLNModelConfig):
|
|
93
88
|
sample_size=image_size, # image size is equal to sample size in vae
|
94
89
|
)
|
95
90
|
|
96
|
-
|
97
|
-
|
91
|
+
# Get default guidance scale from original class to set UNet batch size
|
92
|
+
if guidance_scale is None:
|
93
|
+
guidance_scale = self.get_default_values_for_original_cls("__call__", ["guidance_scale"])["guidance_scale"]
|
94
|
+
|
95
|
+
if not self.unet.batch_size_is_specified:
|
98
96
|
do_classifier_free_guidance = guidance_scale > 1.0
|
99
97
|
if do_classifier_free_guidance:
|
100
98
|
self.unet.batch_size = self.text_encoder.batch_size * 2
|
99
|
+
else:
|
100
|
+
self.unet.batch_size = self.text_encoder.batch_size
|
101
101
|
|
102
102
|
@property
|
103
103
|
def batch_size(self):
|
@@ -21,8 +21,6 @@ import torch
|
|
21
21
|
|
22
22
|
from ..configuration_utils import ContextRblnConfig, RBLNModelConfig
|
23
23
|
from ..modeling import RBLNModel
|
24
|
-
|
25
|
-
# from ..transformers import RBLNCLIPTextModelConfig
|
26
24
|
from ..utils.decorator_utils import remove_compile_time_kwargs
|
27
25
|
from ..utils.logging import get_logger
|
28
26
|
|
@@ -70,6 +68,7 @@ class RBLNDiffusionMixin:
|
|
70
68
|
_submodules = []
|
71
69
|
_prefix = {}
|
72
70
|
_rbln_config_class = None
|
71
|
+
_hf_class = None
|
73
72
|
|
74
73
|
@staticmethod
|
75
74
|
def _maybe_apply_and_fuse_lora(
|
@@ -125,6 +124,14 @@ class RBLNDiffusionMixin:
|
|
125
124
|
)
|
126
125
|
return cls._rbln_config_class
|
127
126
|
|
127
|
+
@classmethod
|
128
|
+
def get_hf_class(cls):
|
129
|
+
if cls._hf_class is None:
|
130
|
+
hf_cls_name = cls.__name__[4:]
|
131
|
+
library = importlib.import_module("diffusers")
|
132
|
+
cls._hf_class = getattr(library, hf_cls_name, None)
|
133
|
+
return cls._hf_class
|
134
|
+
|
128
135
|
@classmethod
|
129
136
|
def from_pretrained(
|
130
137
|
cls,
|
@@ -222,7 +222,7 @@ class RBLNControlNetModel(RBLNModel):
|
|
222
222
|
f"Mismatch between ControlNet's runtime batch size ({sample_batch_size}) and compiled batch size ({compiled_batch_size}). "
|
223
223
|
"This may be caused by the 'guidance_scale' parameter, which doubles the runtime batch size of ControlNet in Stable Diffusion. "
|
224
224
|
"Adjust the batch size of ControlNet during compilation to match the runtime batch size.\n\n"
|
225
|
-
"For details, see: https://docs.rbln.ai/software/optimum/model_api.html#
|
225
|
+
"For details, see: https://docs.rbln.ai/software/optimum/model_api/diffusers/pipelines/controlnet.html#important-batch-size-configuration-for-guidance-scale"
|
226
226
|
)
|
227
227
|
|
228
228
|
added_cond_kwargs = {} if added_cond_kwargs is None else added_cond_kwargs
|
@@ -161,7 +161,7 @@ class RBLNSD3Transformer2DModel(RBLNModel):
|
|
161
161
|
f"Mismatch between transformer's runtime batch size ({sample_batch_size}) and compiled batch size ({compiled_batch_size}). "
|
162
162
|
"This may be caused by the 'guidance scale' parameter, which doubles the runtime batch size in Stable Diffusion. "
|
163
163
|
"Adjust the batch size of transformer during compilation.\n\n"
|
164
|
-
"For details, see: https://docs.rbln.ai/software/optimum/model_api.html#
|
164
|
+
"For details, see: https://docs.rbln.ai/software/optimum/model_api/diffusers/pipelines/stable_diffusion_3.html#important-batch-size-configuration-for-guidance-scale"
|
165
165
|
)
|
166
166
|
|
167
167
|
return super().forward(
|
@@ -346,7 +346,7 @@ class RBLNUNet2DConditionModel(RBLNModel):
|
|
346
346
|
f"Mismatch between UNet's runtime batch size ({sample_batch_size}) and compiled batch size ({compiled_batch_size}). "
|
347
347
|
"This may be caused by the 'guidance scale' parameter, which doubles the runtime batch size of UNet in Stable Diffusion. "
|
348
348
|
"Adjust the batch size of UNet during compilation to match the runtime batch size.\n\n"
|
349
|
-
"For details, see: https://docs.rbln.ai/software/optimum/model_api.html#
|
349
|
+
"For details, see: https://docs.rbln.ai/software/optimum/model_api/diffusers/pipelines/stable_diffusion.html#important-batch-size-configuration-for-guidance-scale"
|
350
350
|
)
|
351
351
|
|
352
352
|
added_cond_kwargs = {} if added_cond_kwargs is None else added_cond_kwargs
|
@@ -39,6 +39,7 @@ from diffusers.utils.torch_utils import is_compiled_module, is_torch_version
|
|
39
39
|
|
40
40
|
from ....utils.decorator_utils import remove_compile_time_kwargs
|
41
41
|
from ....utils.logging import get_logger
|
42
|
+
from ...configurations import RBLNStableDiffusionControlNetPipelineConfig
|
42
43
|
from ...modeling_diffusers import RBLNDiffusionMixin
|
43
44
|
from ...models import RBLNControlNetModel
|
44
45
|
from ...pipelines.controlnet.multicontrolnet import RBLNMultiControlNetModel
|
@@ -49,6 +50,7 @@ logger = get_logger(__name__)
|
|
49
50
|
|
50
51
|
class RBLNStableDiffusionControlNetPipeline(RBLNDiffusionMixin, StableDiffusionControlNetPipeline):
|
51
52
|
original_class = StableDiffusionControlNetPipeline
|
53
|
+
_rbln_config_class = RBLNStableDiffusionControlNetPipelineConfig
|
52
54
|
_submodules = ["text_encoder", "unet", "vae", "controlnet"]
|
53
55
|
|
54
56
|
# Almost copied from diffusers.pipelines.controlnet.pipeline_controlnet.py
|
@@ -37,6 +37,7 @@ from diffusers.utils import deprecate, logging
|
|
37
37
|
from diffusers.utils.torch_utils import is_compiled_module
|
38
38
|
|
39
39
|
from ....utils.decorator_utils import remove_compile_time_kwargs
|
40
|
+
from ...configurations import RBLNStableDiffusionControlNetImg2ImgPipelineConfig
|
40
41
|
from ...modeling_diffusers import RBLNDiffusionMixin
|
41
42
|
from ...models import RBLNControlNetModel
|
42
43
|
from ...pipelines.controlnet.multicontrolnet import RBLNMultiControlNetModel
|
@@ -48,6 +49,7 @@ logger = logging.get_logger(__name__)
|
|
48
49
|
class RBLNStableDiffusionControlNetImg2ImgPipeline(RBLNDiffusionMixin, StableDiffusionControlNetImg2ImgPipeline):
|
49
50
|
original_class = StableDiffusionControlNetImg2ImgPipeline
|
50
51
|
_submodules = ["text_encoder", "unet", "vae", "controlnet"]
|
52
|
+
_rbln_config_class = RBLNStableDiffusionControlNetImg2ImgPipelineConfig
|
51
53
|
|
52
54
|
# Almost copied from diffusers.pipelines.controlnet.pipeline_controlnet_img2img.py
|
53
55
|
def check_inputs(
|