optimum-rbln 0.1.9__py3-none-any.whl → 0.1.11__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 +37 -2
- optimum/rbln/__version__.py +1 -1
- optimum/rbln/diffusers/models/autoencoder_kl.py +36 -29
- optimum/rbln/diffusers/models/controlnet.py +56 -40
- optimum/rbln/diffusers/models/unet_2d_condition.py +40 -28
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +22 -15
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +22 -15
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +23 -17
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +24 -18
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +22 -11
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +22 -11
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +24 -14
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +24 -14
- optimum/rbln/modeling_alias.py +3 -3
- optimum/rbln/modeling_base.py +471 -231
- optimum/rbln/modeling_config.py +152 -77
- optimum/rbln/modeling_seq2seq.py +166 -77
- optimum/rbln/transformers/__init__.py +35 -1
- optimum/rbln/transformers/models/__init__.py +20 -1
- optimum/rbln/transformers/models/auto/__init__.py +14 -0
- optimum/rbln/transformers/models/auto/auto_factory.py +84 -0
- optimum/rbln/transformers/models/auto/modeling_auto.py +94 -0
- optimum/rbln/transformers/models/bart/__init__.py +1 -0
- optimum/rbln/transformers/models/bart/bart_architecture.py +189 -50
- optimum/rbln/transformers/models/bart/modeling_bart.py +106 -0
- optimum/rbln/transformers/models/bert/__init__.py +24 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +102 -0
- optimum/rbln/transformers/models/clip/__init__.py +1 -1
- optimum/rbln/transformers/models/clip/modeling_clip.py +127 -25
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +28 -4
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +302 -115
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +21 -7
- optimum/rbln/transformers/models/gemma/modeling_gemma.py +1 -1
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +4 -1
- optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +1 -1
- optimum/rbln/transformers/models/llama/modeling_llama.py +1 -1
- optimum/rbln/transformers/models/llava_next/__init__.py +24 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +666 -0
- optimum/rbln/transformers/models/midm/midm_architecture.py +5 -1
- optimum/rbln/transformers/models/midm/modeling_midm.py +1 -1
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +1 -1
- optimum/rbln/transformers/models/phi/__init__.py +24 -0
- optimum/rbln/transformers/models/phi/modeling_phi.py +69 -0
- optimum/rbln/transformers/models/phi/phi_architecture.py +406 -0
- optimum/rbln/transformers/models/t5/t5_architecture.py +92 -31
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +17 -11
- optimum/rbln/transformers/models/whisper/generation_whisper.py +68 -0
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +141 -105
- optimum/rbln/transformers/models/whisper/whisper_architecture.py +44 -17
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +17 -14
- optimum/rbln/transformers/utils/rbln_quantization.py +48 -60
- optimum/rbln/utils/import_utils.py +36 -1
- optimum/rbln/utils/logging.py +82 -0
- optimum/rbln/utils/runtime_utils.py +33 -0
- optimum/rbln/utils/timer_utils.py +19 -0
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.11.dist-info}/METADATA +8 -7
- optimum_rbln-0.1.11.dist-info/RECORD +93 -0
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.11.dist-info}/WHEEL +1 -1
- optimum_rbln-0.1.11.dist-info/entry_points.txt +4 -0
- optimum_rbln-0.1.9.dist-info/RECORD +0 -78
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.11.dist-info}/licenses/LICENSE +0 -0
@@ -36,6 +36,7 @@ from transformers import CLIPTextModel
|
|
36
36
|
|
37
37
|
from ....modeling_base import RBLNBaseModel
|
38
38
|
from ....transformers import RBLNCLIPTextModel
|
39
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
39
40
|
from ...models import RBLNAutoencoderKL, RBLNControlNetModel, RBLNUNet2DConditionModel
|
40
41
|
from ...pipelines.controlnet.multicontrolnet import RBLNMultiControlNetModel
|
41
42
|
|
@@ -68,8 +69,13 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
68
69
|
text_encoder = kwargs.pop("text_encoder", None)
|
69
70
|
controlnet = kwargs.pop("controlnet", None)
|
70
71
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
72
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
73
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
71
74
|
|
72
|
-
|
75
|
+
device = rbln_kwargs.get("device", None)
|
76
|
+
device_map = rbln_kwargs.get("device_map", None)
|
77
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
78
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
73
79
|
|
74
80
|
kwargs_dict = {
|
75
81
|
"pretrained_model_name_or_path": model_id,
|
@@ -97,13 +103,19 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
97
103
|
}
|
98
104
|
)
|
99
105
|
|
100
|
-
|
106
|
+
with ContextRblnConfig(
|
107
|
+
device=device,
|
108
|
+
device_map=device_map,
|
109
|
+
create_runtimes=create_runtimes,
|
110
|
+
optimze_host_mem=optimize_host_memory,
|
111
|
+
):
|
112
|
+
model = super().from_pretrained(**{k: v for k, v in kwargs_dict.items() if v is not None})
|
101
113
|
|
102
114
|
if export is None or export is False:
|
103
115
|
return model
|
104
116
|
|
105
117
|
do_classifier_free_guidance = (
|
106
|
-
|
118
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
107
119
|
)
|
108
120
|
|
109
121
|
# compile model, create runtime
|
@@ -116,8 +128,7 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
116
128
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
117
129
|
rbln_use_encode=True,
|
118
130
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
119
|
-
**
|
120
|
-
**rbln_constructor_kwargs,
|
131
|
+
rbln_config={**rbln_kwargs},
|
121
132
|
)
|
122
133
|
|
123
134
|
if not isinstance(text_encoder, RBLNCLIPTextModel):
|
@@ -126,11 +137,10 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
126
137
|
subfolder="text_encoder",
|
127
138
|
export=True,
|
128
139
|
model_save_dir=model_save_dir,
|
129
|
-
**
|
130
|
-
**rbln_constructor_kwargs,
|
140
|
+
rbln_config={**rbln_kwargs},
|
131
141
|
)
|
132
142
|
|
133
|
-
batch_size =
|
143
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
134
144
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
135
145
|
|
136
146
|
if not isinstance(unet, RBLNUNet2DConditionModel):
|
@@ -144,8 +154,7 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
144
154
|
rbln_use_encode=True,
|
145
155
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
146
156
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
147
|
-
**
|
148
|
-
**rbln_constructor_kwargs,
|
157
|
+
rbln_config={**rbln_kwargs},
|
149
158
|
)
|
150
159
|
|
151
160
|
if not isinstance(controlnet, (RBLNControlNetModel, RBLNMultiControlNetModel)):
|
@@ -161,8 +170,7 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
161
170
|
model_save_dir=model_save_dir,
|
162
171
|
rbln_batch_size=unet_batch_size,
|
163
172
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
164
|
-
**
|
165
|
-
**rbln_constructor_kwargs,
|
173
|
+
rbln_config={**rbln_kwargs},
|
166
174
|
)
|
167
175
|
)
|
168
176
|
controlnet = RBLNMultiControlNetModel(multicontrolnet, config=controlnet[0].config)
|
@@ -175,8 +183,7 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
175
183
|
model_save_dir=model_save_dir,
|
176
184
|
rbln_batch_size=unet_batch_size,
|
177
185
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
178
|
-
**
|
179
|
-
**rbln_constructor_kwargs,
|
186
|
+
rbln_config={**rbln_kwargs},
|
180
187
|
)
|
181
188
|
controlnet_dict = ("optimum.rbln", "RBLNControlNetModel")
|
182
189
|
|
@@ -208,7 +215,7 @@ class RBLNStableDiffusionControlNetImg2ImgPipeline(StableDiffusionControlNetImg2
|
|
208
215
|
model.save_config(model_save_dir)
|
209
216
|
|
210
217
|
# use for CI to access each compiled model
|
211
|
-
if
|
218
|
+
if optimize_host_memory is False:
|
212
219
|
model.compiled_models = [
|
213
220
|
vae.compiled_models[0],
|
214
221
|
vae.compiled_models[1],
|
@@ -36,6 +36,7 @@ from transformers import CLIPTextModel
|
|
36
36
|
|
37
37
|
from ....modeling_base import RBLNBaseModel
|
38
38
|
from ....transformers import RBLNCLIPTextModel, RBLNCLIPTextModelWithProjection
|
39
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
39
40
|
from ...models import RBLNAutoencoderKL, RBLNControlNetModel, RBLNUNet2DConditionModel
|
40
41
|
from ...pipelines.controlnet.multicontrolnet import RBLNMultiControlNetModel
|
41
42
|
|
@@ -69,8 +70,13 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
69
70
|
text_encoder_2 = kwargs.pop("text_encoder_2", None)
|
70
71
|
controlnet = kwargs.pop("controlnet", None)
|
71
72
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
73
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
74
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
72
75
|
|
73
|
-
|
76
|
+
device = rbln_kwargs.get("device", None)
|
77
|
+
device_map = rbln_kwargs.get("device_map", None)
|
78
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
79
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
74
80
|
|
75
81
|
kwargs_dict = {
|
76
82
|
"pretrained_model_name_or_path": model_id,
|
@@ -98,13 +104,19 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
98
104
|
}
|
99
105
|
)
|
100
106
|
|
101
|
-
|
107
|
+
with ContextRblnConfig(
|
108
|
+
device=device,
|
109
|
+
device_map=device_map,
|
110
|
+
create_runtimes=create_runtimes,
|
111
|
+
optimze_host_mem=optimize_host_memory,
|
112
|
+
):
|
113
|
+
model = super().from_pretrained(**{k: v for k, v in kwargs_dict.items() if v is not None})
|
102
114
|
|
103
115
|
if export is None or export is False:
|
104
116
|
return model
|
105
117
|
|
106
118
|
do_classifier_free_guidance = (
|
107
|
-
|
119
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
108
120
|
)
|
109
121
|
|
110
122
|
if not isinstance(vae, RBLNAutoencoderKL):
|
@@ -116,8 +128,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
116
128
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
117
129
|
rbln_use_encode=False,
|
118
130
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
119
|
-
**
|
120
|
-
**rbln_constructor_kwargs,
|
131
|
+
rbln_config={**rbln_kwargs},
|
121
132
|
)
|
122
133
|
|
123
134
|
if not isinstance(text_encoder, RBLNCLIPTextModel):
|
@@ -126,8 +137,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
126
137
|
subfolder="text_encoder",
|
127
138
|
export=True,
|
128
139
|
model_save_dir=model_save_dir,
|
129
|
-
**
|
130
|
-
**rbln_constructor_kwargs,
|
140
|
+
rbln_config={**rbln_kwargs},
|
131
141
|
)
|
132
142
|
|
133
143
|
if not isinstance(text_encoder_2, RBLNCLIPTextModel):
|
@@ -136,11 +146,10 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
136
146
|
subfolder="text_encoder_2",
|
137
147
|
export=True,
|
138
148
|
model_save_dir=model_save_dir,
|
139
|
-
**
|
140
|
-
**rbln_constructor_kwargs,
|
149
|
+
rbln_config={**rbln_kwargs},
|
141
150
|
)
|
142
151
|
|
143
|
-
batch_size =
|
152
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
144
153
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
145
154
|
|
146
155
|
if not isinstance(unet, RBLNUNet2DConditionModel):
|
@@ -155,8 +164,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
155
164
|
rbln_use_encode=False,
|
156
165
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
157
166
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
158
|
-
**
|
159
|
-
**rbln_constructor_kwargs,
|
167
|
+
rbln_config={**rbln_kwargs},
|
160
168
|
)
|
161
169
|
|
162
170
|
if not isinstance(controlnet, (RBLNControlNetModel, RBLNMultiControlNetModel)):
|
@@ -173,8 +181,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
173
181
|
rbln_batch_size=unet_batch_size,
|
174
182
|
rbln_text_model_hidden_size=model.text_encoder_2.config.hidden_size,
|
175
183
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
176
|
-
**
|
177
|
-
**rbln_constructor_kwargs,
|
184
|
+
rbln_config={**rbln_kwargs},
|
178
185
|
)
|
179
186
|
)
|
180
187
|
controlnet = RBLNMultiControlNetModel(multicontrolnet, config=controlnet[0].config)
|
@@ -188,8 +195,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
188
195
|
rbln_batch_size=unet_batch_size,
|
189
196
|
rbln_text_model_hidden_size=model.text_encoder_2.config.hidden_size,
|
190
197
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
191
|
-
**
|
192
|
-
**rbln_constructor_kwargs,
|
198
|
+
rbln_config={**rbln_kwargs},
|
193
199
|
)
|
194
200
|
controlnet_dict = ("optimum.rbln", "RBLNControlNetModel")
|
195
201
|
|
@@ -223,7 +229,7 @@ class RBLNStableDiffusionXLControlNetPipeline(StableDiffusionXLControlNetPipelin
|
|
223
229
|
model.save_config(model_save_dir)
|
224
230
|
|
225
231
|
# use for CI to access each compiled model
|
226
|
-
if
|
232
|
+
if optimize_host_memory is False:
|
227
233
|
model.compiled_models = [
|
228
234
|
vae.compiled_models[0],
|
229
235
|
text_encoder.compiled_models[0],
|
@@ -36,6 +36,7 @@ from transformers import CLIPTextModel
|
|
36
36
|
|
37
37
|
from ....modeling_base import RBLNBaseModel
|
38
38
|
from ....transformers import RBLNCLIPTextModel, RBLNCLIPTextModelWithProjection
|
39
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
39
40
|
from ...models import RBLNAutoencoderKL, RBLNControlNetModel, RBLNUNet2DConditionModel
|
40
41
|
from ...pipelines.controlnet.multicontrolnet import RBLNMultiControlNetModel
|
41
42
|
|
@@ -69,8 +70,13 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
69
70
|
text_encoder_2 = kwargs.pop("text_encoder_2", None)
|
70
71
|
controlnet = kwargs.pop("controlnet", None)
|
71
72
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
73
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
74
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
72
75
|
|
73
|
-
|
76
|
+
device = rbln_kwargs.get("device", None)
|
77
|
+
device_map = rbln_kwargs.get("device_map", None)
|
78
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
79
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
74
80
|
|
75
81
|
kwargs_dict = {
|
76
82
|
"pretrained_model_name_or_path": model_id,
|
@@ -98,13 +104,19 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
98
104
|
}
|
99
105
|
)
|
100
106
|
|
101
|
-
|
107
|
+
with ContextRblnConfig(
|
108
|
+
device=device,
|
109
|
+
device_map=device_map,
|
110
|
+
create_runtimes=create_runtimes,
|
111
|
+
optimze_host_mem=optimize_host_memory,
|
112
|
+
):
|
113
|
+
model = super().from_pretrained(**{k: v for k, v in kwargs_dict.items() if v is not None})
|
102
114
|
|
103
115
|
if export is None or export is False:
|
104
116
|
return model
|
105
117
|
|
106
118
|
do_classifier_free_guidance = (
|
107
|
-
|
119
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
108
120
|
)
|
109
121
|
|
110
122
|
if not isinstance(vae, RBLNAutoencoderKL):
|
@@ -116,8 +128,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
116
128
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
117
129
|
rbln_use_encode=True,
|
118
130
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
119
|
-
**
|
120
|
-
**rbln_constructor_kwargs,
|
131
|
+
rbln_config={**rbln_kwargs},
|
121
132
|
)
|
122
133
|
|
123
134
|
if not isinstance(text_encoder, RBLNCLIPTextModel):
|
@@ -126,8 +137,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
126
137
|
subfolder="text_encoder",
|
127
138
|
export=True,
|
128
139
|
model_save_dir=model_save_dir,
|
129
|
-
**
|
130
|
-
**rbln_constructor_kwargs,
|
140
|
+
rbln_config={**rbln_kwargs},
|
131
141
|
)
|
132
142
|
|
133
143
|
if not isinstance(text_encoder_2, RBLNCLIPTextModel):
|
@@ -136,11 +146,10 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
136
146
|
subfolder="text_encoder_2",
|
137
147
|
export=True,
|
138
148
|
model_save_dir=model_save_dir,
|
139
|
-
**
|
140
|
-
**rbln_constructor_kwargs,
|
149
|
+
rbln_config={**rbln_kwargs},
|
141
150
|
)
|
142
151
|
|
143
|
-
batch_size =
|
152
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
144
153
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
145
154
|
|
146
155
|
if not isinstance(unet, RBLNUNet2DConditionModel):
|
@@ -155,8 +164,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
155
164
|
rbln_use_encode=True,
|
156
165
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
157
166
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
158
|
-
**
|
159
|
-
**rbln_constructor_kwargs,
|
167
|
+
rbln_config={**rbln_kwargs},
|
160
168
|
)
|
161
169
|
|
162
170
|
if not isinstance(controlnet, (RBLNControlNetModel, RBLNMultiControlNetModel)):
|
@@ -173,8 +181,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
173
181
|
rbln_batch_size=unet_batch_size,
|
174
182
|
rbln_text_model_hidden_size=model.text_encoder_2.config.hidden_size,
|
175
183
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
176
|
-
**
|
177
|
-
**rbln_constructor_kwargs,
|
184
|
+
rbln_config={**rbln_kwargs},
|
178
185
|
)
|
179
186
|
)
|
180
187
|
controlnet = RBLNMultiControlNetModel(multicontrolnet, config=controlnet[0].config)
|
@@ -188,8 +195,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
188
195
|
rbln_batch_size=unet_batch_size,
|
189
196
|
rbln_text_model_hidden_size=model.text_encoder_2.config.hidden_size,
|
190
197
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
191
|
-
**
|
192
|
-
**rbln_constructor_kwargs,
|
198
|
+
rbln_config={**rbln_kwargs},
|
193
199
|
)
|
194
200
|
controlnet_dict = ("optimum.rbln", "RBLNControlNetModel")
|
195
201
|
|
@@ -213,7 +219,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
213
219
|
"vae": ("optimum.rbln", "RBLNAutoencoderKL"),
|
214
220
|
"text_encoder": ("optimum.rbln", "RBLNCLIPTextModel"),
|
215
221
|
"unet": ("optimum.rbln", "RBLNUNet2DConditionModel"),
|
216
|
-
"text_encoder_2": ("optimum.rbln", "
|
222
|
+
"text_encoder_2": ("optimum.rbln", "RBLNCLIPTextModelWithProjection"),
|
217
223
|
"controlnet": controlnet_dict,
|
218
224
|
}
|
219
225
|
model.register_to_config(**update_dict)
|
@@ -223,7 +229,7 @@ class RBLNStableDiffusionXLControlNetImg2ImgPipeline(StableDiffusionXLControlNet
|
|
223
229
|
model.save_config(model_save_dir)
|
224
230
|
|
225
231
|
# use for CI to access each compiled model
|
226
|
-
if
|
232
|
+
if optimize_host_memory is False:
|
227
233
|
model.compiled_models = [
|
228
234
|
vae.compiled_models[0],
|
229
235
|
vae.compiled_models[1],
|
@@ -26,6 +26,7 @@ from diffusers import StableDiffusionPipeline
|
|
26
26
|
|
27
27
|
from ....modeling_base import RBLNBaseModel
|
28
28
|
from ....transformers import RBLNCLIPTextModel
|
29
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
29
30
|
from ...models import RBLNAutoencoderKL, RBLNUNet2DConditionModel
|
30
31
|
|
31
32
|
|
@@ -50,14 +51,27 @@ class RBLNStableDiffusionPipeline(StableDiffusionPipeline):
|
|
50
51
|
"""
|
51
52
|
export = kwargs.pop("export", None)
|
52
53
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
53
|
-
|
54
|
-
|
54
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
55
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
56
|
+
|
57
|
+
device = rbln_kwargs.get("device", None)
|
58
|
+
device_map = rbln_kwargs.get("device_map", None)
|
59
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
60
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
61
|
+
|
62
|
+
with ContextRblnConfig(
|
63
|
+
device=device,
|
64
|
+
device_map=device_map,
|
65
|
+
create_runtimes=create_runtimes,
|
66
|
+
optimze_host_mem=optimize_host_memory,
|
67
|
+
):
|
68
|
+
model = super().from_pretrained(pretrained_model_name_or_path=model_id, **kwargs)
|
55
69
|
|
56
70
|
if export is None or export is False:
|
57
71
|
return model
|
58
72
|
|
59
73
|
do_classifier_free_guidance = (
|
60
|
-
|
74
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
61
75
|
)
|
62
76
|
|
63
77
|
vae = RBLNAutoencoderKL.from_pretrained(
|
@@ -67,19 +81,17 @@ class RBLNStableDiffusionPipeline(StableDiffusionPipeline):
|
|
67
81
|
model_save_dir=model_save_dir,
|
68
82
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
69
83
|
rbln_use_encode=False,
|
70
|
-
**
|
71
|
-
**rbln_constructor_kwargs,
|
84
|
+
rbln_config={**rbln_kwargs},
|
72
85
|
)
|
73
86
|
text_encoder = RBLNCLIPTextModel.from_pretrained(
|
74
87
|
model_id=model_id,
|
75
88
|
subfolder="text_encoder",
|
76
89
|
export=True,
|
77
90
|
model_save_dir=model_save_dir,
|
78
|
-
**
|
79
|
-
**rbln_constructor_kwargs,
|
91
|
+
rbln_config={**rbln_kwargs},
|
80
92
|
)
|
81
93
|
|
82
|
-
batch_size =
|
94
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
83
95
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
84
96
|
|
85
97
|
unet = RBLNUNet2DConditionModel.from_pretrained(
|
@@ -91,8 +103,7 @@ class RBLNStableDiffusionPipeline(StableDiffusionPipeline):
|
|
91
103
|
rbln_batch_size=unet_batch_size,
|
92
104
|
rbln_use_encode=False,
|
93
105
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
94
|
-
**
|
95
|
-
**rbln_constructor_kwargs,
|
106
|
+
rbln_config={**rbln_kwargs},
|
96
107
|
)
|
97
108
|
|
98
109
|
if model_save_dir is not None:
|
@@ -122,7 +133,7 @@ class RBLNStableDiffusionPipeline(StableDiffusionPipeline):
|
|
122
133
|
|
123
134
|
model.models = [vae.model[0], text_encoder.model[0], unet.model[0]]
|
124
135
|
|
125
|
-
if
|
136
|
+
if optimize_host_memory is False:
|
126
137
|
model.compiled_models = [vae.compiled_models[0], text_encoder.compiled_models[0], unet.compiled_models[0]]
|
127
138
|
|
128
139
|
return model
|
@@ -26,6 +26,7 @@ from diffusers import StableDiffusionImg2ImgPipeline
|
|
26
26
|
|
27
27
|
from ....modeling_base import RBLNBaseModel
|
28
28
|
from ....transformers import RBLNCLIPTextModel
|
29
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
29
30
|
from ...models import RBLNAutoencoderKL, RBLNUNet2DConditionModel
|
30
31
|
|
31
32
|
|
@@ -50,14 +51,27 @@ class RBLNStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipeline):
|
|
50
51
|
"""
|
51
52
|
export = kwargs.pop("export", None)
|
52
53
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
53
|
-
|
54
|
-
|
54
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
55
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
56
|
+
|
57
|
+
device = rbln_kwargs.get("device", None)
|
58
|
+
device_map = rbln_kwargs.get("device_map", None)
|
59
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
60
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
61
|
+
|
62
|
+
with ContextRblnConfig(
|
63
|
+
device=device,
|
64
|
+
device_map=device_map,
|
65
|
+
create_runtimes=create_runtimes,
|
66
|
+
optimze_host_mem=optimize_host_memory,
|
67
|
+
):
|
68
|
+
model = super().from_pretrained(pretrained_model_name_or_path=model_id, **kwargs)
|
55
69
|
|
56
70
|
if export is None or export is False:
|
57
71
|
return model
|
58
72
|
|
59
73
|
do_classifier_free_guidance = (
|
60
|
-
|
74
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
61
75
|
)
|
62
76
|
|
63
77
|
# compile model, create runtime
|
@@ -69,19 +83,17 @@ class RBLNStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipeline):
|
|
69
83
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
70
84
|
rbln_use_encode=True,
|
71
85
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
72
|
-
**
|
73
|
-
**rbln_constructor_kwargs,
|
86
|
+
rbln_config={**rbln_kwargs},
|
74
87
|
)
|
75
88
|
text_encoder = RBLNCLIPTextModel.from_pretrained(
|
76
89
|
model_id=model_id,
|
77
90
|
subfolder="text_encoder",
|
78
91
|
export=True,
|
79
92
|
model_save_dir=model_save_dir,
|
80
|
-
**
|
81
|
-
**rbln_constructor_kwargs,
|
93
|
+
rbln_config={**rbln_kwargs},
|
82
94
|
)
|
83
95
|
|
84
|
-
batch_size =
|
96
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
85
97
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
86
98
|
|
87
99
|
unet = RBLNUNet2DConditionModel.from_pretrained(
|
@@ -94,8 +106,7 @@ class RBLNStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipeline):
|
|
94
106
|
rbln_use_encode=True,
|
95
107
|
rbln_vae_scale_factor=model.vae_scale_factor,
|
96
108
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
97
|
-
**
|
98
|
-
**rbln_constructor_kwargs,
|
109
|
+
rbln_config={**rbln_kwargs},
|
99
110
|
)
|
100
111
|
|
101
112
|
if model_save_dir is not None:
|
@@ -126,7 +137,7 @@ class RBLNStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipeline):
|
|
126
137
|
# vae encoder, vae decoder, text_encoder, unet
|
127
138
|
model.models = [vae.model[0], vae.model[1], text_encoder.model[0], unet.model[0]]
|
128
139
|
|
129
|
-
if
|
140
|
+
if optimize_host_memory is False:
|
130
141
|
model.compiled_models = [
|
131
142
|
vae.compiled_models[0],
|
132
143
|
vae.compiled_models[1],
|
@@ -18,6 +18,7 @@ from diffusers import StableDiffusionXLPipeline
|
|
18
18
|
|
19
19
|
from ....modeling_base import RBLNBaseModel
|
20
20
|
from ....transformers import RBLNCLIPTextModel, RBLNCLIPTextModelWithProjection
|
21
|
+
from ....utils.runtime_utils import ContextRblnConfig
|
21
22
|
from ...models import RBLNAutoencoderKL, RBLNUNet2DConditionModel
|
22
23
|
|
23
24
|
|
@@ -42,14 +43,27 @@ class RBLNStableDiffusionXLPipeline(StableDiffusionXLPipeline):
|
|
42
43
|
"""
|
43
44
|
export = kwargs.pop("export", None)
|
44
45
|
model_save_dir = kwargs.pop("model_save_dir", None)
|
45
|
-
|
46
|
-
|
46
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
47
|
+
rbln_kwargs, _ = RBLNBaseModel.resolve_rbln_config(rbln_config, kwargs)
|
48
|
+
|
49
|
+
device = rbln_kwargs.get("device", None)
|
50
|
+
device_map = rbln_kwargs.get("device_map", None)
|
51
|
+
create_runtimes = rbln_kwargs.get("create_runtimes", None)
|
52
|
+
optimize_host_memory = rbln_kwargs.get("optimize_host_memory", None)
|
53
|
+
|
54
|
+
with ContextRblnConfig(
|
55
|
+
device=device,
|
56
|
+
device_map=device_map,
|
57
|
+
create_runtimes=create_runtimes,
|
58
|
+
optimze_host_mem=optimize_host_memory,
|
59
|
+
):
|
60
|
+
model = super().from_pretrained(pretrained_model_name_or_path=model_id, **kwargs)
|
47
61
|
|
48
62
|
if export is None or export is False:
|
49
63
|
return model
|
50
64
|
|
51
65
|
do_classifier_free_guidance = (
|
52
|
-
|
66
|
+
rbln_kwargs.pop("guidance_scale", 5.0) > 1.0 and model.unet.config.time_cond_proj_dim is None
|
53
67
|
)
|
54
68
|
|
55
69
|
vae = RBLNAutoencoderKL.from_pretrained(
|
@@ -59,27 +73,24 @@ class RBLNStableDiffusionXLPipeline(StableDiffusionXLPipeline):
|
|
59
73
|
model_save_dir=model_save_dir,
|
60
74
|
rbln_unet_sample_size=model.unet.config.sample_size,
|
61
75
|
rbln_use_encode=False,
|
62
|
-
**
|
63
|
-
**rbln_constructor_kwargs,
|
76
|
+
rbln_config={**rbln_kwargs},
|
64
77
|
)
|
65
78
|
text_encoder = RBLNCLIPTextModel.from_pretrained(
|
66
79
|
model_id=model_id,
|
67
80
|
subfolder="text_encoder",
|
68
81
|
export=True,
|
69
82
|
model_save_dir=model_save_dir,
|
70
|
-
**
|
71
|
-
**rbln_constructor_kwargs,
|
83
|
+
rbln_config={**rbln_kwargs},
|
72
84
|
)
|
73
85
|
text_encoder_2 = RBLNCLIPTextModelWithProjection.from_pretrained(
|
74
86
|
model_id=model_id,
|
75
87
|
subfolder="text_encoder_2",
|
76
88
|
export=True,
|
77
89
|
model_save_dir=model_save_dir,
|
78
|
-
**
|
79
|
-
**rbln_constructor_kwargs,
|
90
|
+
rbln_config={**rbln_kwargs},
|
80
91
|
)
|
81
92
|
|
82
|
-
batch_size =
|
93
|
+
batch_size = rbln_kwargs.pop("batch_size", 1)
|
83
94
|
unet_batch_size = batch_size * 2 if do_classifier_free_guidance else batch_size
|
84
95
|
|
85
96
|
unet = RBLNUNet2DConditionModel.from_pretrained(
|
@@ -92,8 +103,7 @@ class RBLNStableDiffusionXLPipeline(StableDiffusionXLPipeline):
|
|
92
103
|
rbln_batch_size=unet_batch_size,
|
93
104
|
rbln_use_encode=False,
|
94
105
|
rbln_is_controlnet=True if "controlnet" in model.config.keys() else False,
|
95
|
-
**
|
96
|
-
**rbln_constructor_kwargs,
|
106
|
+
rbln_config={**rbln_kwargs},
|
97
107
|
)
|
98
108
|
|
99
109
|
if model_save_dir is not None:
|
@@ -112,7 +122,7 @@ class RBLNStableDiffusionXLPipeline(StableDiffusionXLPipeline):
|
|
112
122
|
"vae": ("optimum.rbln", "RBLNAutoencoderKL"),
|
113
123
|
"text_encoder": ("optimum.rbln", "RBLNCLIPTextModel"),
|
114
124
|
"unet": ("optimum.rbln", "RBLNUNet2DConditionModel"),
|
115
|
-
"text_encoder_2": ("optimum.rbln", "
|
125
|
+
"text_encoder_2": ("optimum.rbln", "RBLNCLIPTextModelWithProjection"),
|
116
126
|
}
|
117
127
|
model.register_to_config(**update_dict)
|
118
128
|
|
@@ -122,7 +132,7 @@ class RBLNStableDiffusionXLPipeline(StableDiffusionXLPipeline):
|
|
122
132
|
|
123
133
|
model.models = [vae.model[0], unet.model[0], text_encoder.model[0], text_encoder_2.model[0]]
|
124
134
|
|
125
|
-
if
|
135
|
+
if optimize_host_memory is False:
|
126
136
|
model.compiled_models = [
|
127
137
|
vae.compiled_models[0],
|
128
138
|
unet.compiled_models[0],
|