Stable Diffusion XL¶
Stable Diffusion XL(SDXL)은 이전 Stable Diffusion 버전에 비해 더 높은 해상도의 이미지를 더 세밀하고 사실적으로 생성하는 것으로 알려진 고급 텍스트-이미지 잠재 확산 모델입니다. 향상된 프롬프트 이해를 위해 두 개의 텍스트 인코더를 활용합니다. RBLN Optimum을 사용하면 RBLN NPU에서 Stable Diffusion XL 파이프라인을 가속할 수 있습니다.
지원 NPU
Diffusers 파이프라인은 ATOM™에서만 실행됩니다. Rebel100™은 아직 지원하지 않습니다.
지원하는 파이프라인¶
RBLN Optimum은 여러 Stable Diffusion XL 파이프라인을 지원합니다:
| 파이프라인 | 클래스 | 설명 |
|---|---|---|
| 텍스트-이미지 변환(Text-to-Image) | RBLNStableDiffusionXLPipeline | 텍스트 프롬프트에서 고해상도 이미지 생성. |
| 이미지-이미지 변환(Image-to-Image) | RBLNStableDiffusionXLImg2ImgPipeline | 텍스트 프롬프트를 기반으로 기존 이미지 수정. |
| 인페인팅(Inpainting) | RBLNStableDiffusionXLInpaintPipeline | 텍스트 프롬프트에 따라 이미지의 마스킹된 영역 채우기. |
중요: Guidance Scale에 따른 배치 크기 설정¶
배치 크기와 Guidance Scale
Stable Diffusion XL을 guidance scale > 1.0으로 사용할 때(기본값은 text-to-image와 image-to-image가 5.0, inpainting이 7.5), classifier-free guidance가 적용되어 UNet의 실제 배치 크기가 실행 시 2배가 됩니다.
RBLN NPU는 정적 그래프 컴파일을 사용하므로, 컴파일 시 UNet의 배치 크기가 실행 시 배치 크기와 일치해야 합니다. 그렇지 않으면 컴파일된 그래프를 실행할 수 없어 추론이 실패합니다.
기본 동작¶
UNet의 배치 크기를 명시적으로 지정하지 않는 경우, RBLN Optimum은 다음과 같이 동작합니다:
- 파이프라인의 기본 guidance scale(text-to-image와 image-to-image는 5.0, inpainting은 7.5)을 사용한다고 가정합니다.
- 자동으로 UNet의 배치 크기를 파이프라인 배치 크기의 2배로 설정합니다.
기본 guidance scale(1.0보다 큰 값)을 사용할 계획이라면, 이 자동 구성이 올바르게 작동합니다. 그러나 다른 guidance scale을 사용하거나 더 많은 제어가 필요한 경우에는 UNet의 배치 크기를 명시적으로 구성해야 합니다.
예시: UNet 배치 크기 명시적 설정¶
예시: Guidance 비활성화(guidance_scale = 0.0)¶
SDXL-Turbo와 같은 모델이나 classifier-free guidance를 비활성화하는 경우(guidance_scale=0.0 설정), UNet 배치 크기를 추론 배치 크기와 일치하도록 명시적으로 설정합니다:
사용 예제¶
API 참조¶
RBLNStableDiffusionXLPipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusionXLPipeline
RBLN-accelerated implementation of Stable Diffusion XL pipeline for high-resolution text-to-image generation.
This pipeline compiles Stable Diffusion XL models to run efficiently on RBLN NPUs, enabling high-performance inference for generating high-quality images with enhanced detail and improved prompt adherence.
from_pretrained(model_id, *, export=None, model_save_dir=None, rbln_config=None, lora_ids=None, lora_weights_names=None, lora_scales=None, **kwargs) classmethod ¶
Load a pretrained diffusion pipeline from a model checkpoint, with optional compilation for RBLN NPUs.
It supports various diffusion pipelines including Stable Diffusion, Kandinsky, ControlNet, and other diffusers-based models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id | `str` | The model ID or path to the pretrained model to load. Can be either:
| required |
export | bool | None | If True, takes a PyTorch model from | None |
model_save_dir | str | PathLike[str] | None | Directory to save the compiled model artifacts. Only used when | None |
rbln_config | dict[str, Any] | RBLNModelConfig | None | Configuration options for RBLN compilation. Can include settings for specific submodules such as | None |
lora_ids | str | list[str] | None | LoRA adapter ID(s) to load and apply before compilation. LoRA weights are fused into the model weights during compilation. Only used when | None |
lora_weights_names | str | list[str] | None | Names of specific LoRA weight files to load, corresponding to lora_ids. Only used when | None |
lora_scales | float | list[float] | None | Scaling factor(s) to apply to the LoRA adapter(s). Only used when | None |
kwargs | Any | Additional arguments to pass to the underlying diffusion pipeline constructor or the RBLN compilation process. These may include parameters specific to individual submodules or the particular diffusion pipeline being used. | {} |
Returns:
| Type | Description |
|---|---|
Self | A compiled or loaded diffusion pipeline that can be used for inference on RBLN NPU. The returned object is an instance of the class that called this method, inheriting from RBLNDiffusionMixin. |
RBLNStableDiffusionXLImg2ImgPipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusionXLImg2ImgPipeline
RBLN-accelerated implementation of Stable Diffusion XL pipeline for high-resolution image-to-image generation.
This pipeline compiles Stable Diffusion XL models to run efficiently on RBLN NPUs, enabling high-performance inference for transforming input images with enhanced quality and detail preservation.
from_pretrained(model_id, *, export=None, model_save_dir=None, rbln_config=None, lora_ids=None, lora_weights_names=None, lora_scales=None, **kwargs) classmethod ¶
Load a pretrained diffusion pipeline from a model checkpoint, with optional compilation for RBLN NPUs.
It supports various diffusion pipelines including Stable Diffusion, Kandinsky, ControlNet, and other diffusers-based models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id | `str` | The model ID or path to the pretrained model to load. Can be either:
| required |
export | bool | None | If True, takes a PyTorch model from | None |
model_save_dir | str | PathLike[str] | None | Directory to save the compiled model artifacts. Only used when | None |
rbln_config | dict[str, Any] | RBLNModelConfig | None | Configuration options for RBLN compilation. Can include settings for specific submodules such as | None |
lora_ids | str | list[str] | None | LoRA adapter ID(s) to load and apply before compilation. LoRA weights are fused into the model weights during compilation. Only used when | None |
lora_weights_names | str | list[str] | None | Names of specific LoRA weight files to load, corresponding to lora_ids. Only used when | None |
lora_scales | float | list[float] | None | Scaling factor(s) to apply to the LoRA adapter(s). Only used when | None |
kwargs | Any | Additional arguments to pass to the underlying diffusion pipeline constructor or the RBLN compilation process. These may include parameters specific to individual submodules or the particular diffusion pipeline being used. | {} |
Returns:
| Type | Description |
|---|---|
Self | A compiled or loaded diffusion pipeline that can be used for inference on RBLN NPU. The returned object is an instance of the class that called this method, inheriting from RBLNDiffusionMixin. |
RBLNStableDiffusionXLInpaintPipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusionXLInpaintPipeline
RBLN-accelerated implementation of Stable Diffusion XL pipeline for high-resolution image inpainting.
This pipeline compiles Stable Diffusion XL models to run efficiently on RBLN NPUs, enabling high-performance inference for filling masked regions with enhanced quality and seamless blending capabilities.
from_pretrained(model_id, *, export=None, model_save_dir=None, rbln_config=None, lora_ids=None, lora_weights_names=None, lora_scales=None, **kwargs) classmethod ¶
Load a pretrained diffusion pipeline from a model checkpoint, with optional compilation for RBLN NPUs.
It supports various diffusion pipelines including Stable Diffusion, Kandinsky, ControlNet, and other diffusers-based models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id | `str` | The model ID or path to the pretrained model to load. Can be either:
| required |
export | bool | None | If True, takes a PyTorch model from | None |
model_save_dir | str | PathLike[str] | None | Directory to save the compiled model artifacts. Only used when | None |
rbln_config | dict[str, Any] | RBLNModelConfig | None | Configuration options for RBLN compilation. Can include settings for specific submodules such as | None |
lora_ids | str | list[str] | None | LoRA adapter ID(s) to load and apply before compilation. LoRA weights are fused into the model weights during compilation. Only used when | None |
lora_weights_names | str | list[str] | None | Names of specific LoRA weight files to load, corresponding to lora_ids. Only used when | None |
lora_scales | float | list[float] | None | Scaling factor(s) to apply to the LoRA adapter(s). Only used when | None |
kwargs | Any | Additional arguments to pass to the underlying diffusion pipeline constructor or the RBLN compilation process. These may include parameters specific to individual submodules or the particular diffusion pipeline being used. | {} |
Returns:
| Type | Description |
|---|---|
Self | A compiled or loaded diffusion pipeline that can be used for inference on RBLN NPU. The returned object is an instance of the class that called this method, inheriting from RBLNDiffusionMixin. |
RBLNStableDiffusionXLPipelineBaseConfig ¶
Bases: RBLNModelConfig
__init__(text_encoder=None, text_encoder_2=None, unet=None, vae=None, *, batch_size=None, img_height=None, img_width=None, height=None, width=None, sample_size=None, image_size=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_encoder | RBLNCLIPTextModelConfig | None | Configuration for the primary text encoder component. Initialized as RBLNCLIPTextModelConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder component. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
unet | RBLNUNet2DConditionModelConfig | None | Configuration for the UNet model component. Initialized as RBLNUNet2DConditionModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
batch_size | int | None | Batch size for inference, applied to all submodules. | None |
img_height | int | None | Height of the generated images. | None |
img_width | int | None | Width of the generated images. | None |
height | int | None | Height of the generated images. | None |
width | int | None | Width of the generated images. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the UNet model. | None |
image_size | tuple[int, int] | None | Alternative way to specify image dimensions. Cannot be used together with img_height/img_width. | None |
guidance_scale | float | None | Scale for classifier-free guidance. | None |
kwargs | Any | Additional arguments passed to the parent RBLNModelConfig. | {} |
Raises:
| Type | Description |
|---|---|
ValueError | If both image_size and img_height/img_width are provided. |
Note
When guidance_scale > 1.0, the UNet batch size is automatically doubled to accommodate classifier-free guidance.
from_pretrained(path, rbln_config=None, return_unused_kwargs=False, **kwargs) classmethod ¶
Load a RBLNModelConfig from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the RBLNModelConfig file or directory containing the config file. | required |
rbln_config | dict[str, Any] | None | Additional configuration to override. | None |
return_unused_kwargs | bool | Whether to return unused kwargs. | False |
kwargs | Any | Additional keyword arguments to override configuration values. Keys starting with 'rbln_' will have the prefix removed and be used to update the configuration. | {} |
Returns:
| Name | Type | Description |
|---|---|---|
RBLNModelConfig | Self | tuple[Self, dict[str, Any]] | The loaded configuration instance. |
Note
This method loads the configuration from the specified path and applies any provided overrides. If the loaded configuration class doesn't match the expected class, a warning will be logged.
Examples:
initialize_submodule_config(submodule_config=None, force_kwargs=False, **kwargs) ¶
Build the config of a submodule from the parent's runtime options and kwargs.
Returns the submodule config instance when its class is known (an instance was passed, or cls_name was given), otherwise the merged kwargs dict for the model class to resolve later.
get_load_overrides() ¶
Extract the options that must cross the load boundary, for passing to from_pretrained.
Returns the explicitly-set runtime options (device, device_map, create_runtimes, activate_profiler, timeout) and the subclass-specific non-save attributes (load-behavior flags such as _load_visual_runtime, which are never serialized so they can only travel with the caller), recursively including submodules. Compile-time attributes are not included: when loading a compiled model they come from the artifact's rbln_config.json, and this dict is merged on top of it.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary of load overrides, keyed like the |
RBLNStableDiffusionXLPipelineConfig ¶
Bases: RBLNStableDiffusionXLPipelineBaseConfig
Config for SDXL Text2Img Pipeline
initialize_submodule_config(submodule_config=None, force_kwargs=False, **kwargs) ¶
Build the config of a submodule from the parent's runtime options and kwargs.
Returns the submodule config instance when its class is known (an instance was passed, or cls_name was given), otherwise the merged kwargs dict for the model class to resolve later.
__init__(text_encoder=None, text_encoder_2=None, unet=None, vae=None, *, batch_size=None, img_height=None, img_width=None, height=None, width=None, sample_size=None, image_size=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_encoder | RBLNCLIPTextModelConfig | None | Configuration for the primary text encoder component. Initialized as RBLNCLIPTextModelConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder component. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
unet | RBLNUNet2DConditionModelConfig | None | Configuration for the UNet model component. Initialized as RBLNUNet2DConditionModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
batch_size | int | None | Batch size for inference, applied to all submodules. | None |
img_height | int | None | Height of the generated images. | None |
img_width | int | None | Width of the generated images. | None |
height | int | None | Height of the generated images. | None |
width | int | None | Width of the generated images. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the UNet model. | None |
image_size | tuple[int, int] | None | Alternative way to specify image dimensions. Cannot be used together with img_height/img_width. | None |
guidance_scale | float | None | Scale for classifier-free guidance. | None |
kwargs | Any | Additional arguments passed to the parent RBLNModelConfig. | {} |
Raises:
| Type | Description |
|---|---|
ValueError | If both image_size and img_height/img_width are provided. |
Note
When guidance_scale > 1.0, the UNet batch size is automatically doubled to accommodate classifier-free guidance.
get_load_overrides() ¶
Extract the options that must cross the load boundary, for passing to from_pretrained.
Returns the explicitly-set runtime options (device, device_map, create_runtimes, activate_profiler, timeout) and the subclass-specific non-save attributes (load-behavior flags such as _load_visual_runtime, which are never serialized so they can only travel with the caller), recursively including submodules. Compile-time attributes are not included: when loading a compiled model they come from the artifact's rbln_config.json, and this dict is merged on top of it.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary of load overrides, keyed like the |
from_pretrained(path, rbln_config=None, return_unused_kwargs=False, **kwargs) classmethod ¶
Load a RBLNModelConfig from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the RBLNModelConfig file or directory containing the config file. | required |
rbln_config | dict[str, Any] | None | Additional configuration to override. | None |
return_unused_kwargs | bool | Whether to return unused kwargs. | False |
kwargs | Any | Additional keyword arguments to override configuration values. Keys starting with 'rbln_' will have the prefix removed and be used to update the configuration. | {} |
Returns:
| Name | Type | Description |
|---|---|---|
RBLNModelConfig | Self | tuple[Self, dict[str, Any]] | The loaded configuration instance. |
Note
This method loads the configuration from the specified path and applies any provided overrides. If the loaded configuration class doesn't match the expected class, a warning will be logged.
Examples:
RBLNStableDiffusionXLImg2ImgPipelineConfig ¶
Bases: RBLNStableDiffusionXLPipelineBaseConfig
Config for SDXL Img2Img Pipeline
initialize_submodule_config(submodule_config=None, force_kwargs=False, **kwargs) ¶
Build the config of a submodule from the parent's runtime options and kwargs.
Returns the submodule config instance when its class is known (an instance was passed, or cls_name was given), otherwise the merged kwargs dict for the model class to resolve later.
__init__(text_encoder=None, text_encoder_2=None, unet=None, vae=None, *, batch_size=None, img_height=None, img_width=None, height=None, width=None, sample_size=None, image_size=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_encoder | RBLNCLIPTextModelConfig | None | Configuration for the primary text encoder component. Initialized as RBLNCLIPTextModelConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder component. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
unet | RBLNUNet2DConditionModelConfig | None | Configuration for the UNet model component. Initialized as RBLNUNet2DConditionModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
batch_size | int | None | Batch size for inference, applied to all submodules. | None |
img_height | int | None | Height of the generated images. | None |
img_width | int | None | Width of the generated images. | None |
height | int | None | Height of the generated images. | None |
width | int | None | Width of the generated images. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the UNet model. | None |
image_size | tuple[int, int] | None | Alternative way to specify image dimensions. Cannot be used together with img_height/img_width. | None |
guidance_scale | float | None | Scale for classifier-free guidance. | None |
kwargs | Any | Additional arguments passed to the parent RBLNModelConfig. | {} |
Raises:
| Type | Description |
|---|---|
ValueError | If both image_size and img_height/img_width are provided. |
Note
When guidance_scale > 1.0, the UNet batch size is automatically doubled to accommodate classifier-free guidance.
get_load_overrides() ¶
Extract the options that must cross the load boundary, for passing to from_pretrained.
Returns the explicitly-set runtime options (device, device_map, create_runtimes, activate_profiler, timeout) and the subclass-specific non-save attributes (load-behavior flags such as _load_visual_runtime, which are never serialized so they can only travel with the caller), recursively including submodules. Compile-time attributes are not included: when loading a compiled model they come from the artifact's rbln_config.json, and this dict is merged on top of it.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary of load overrides, keyed like the |
from_pretrained(path, rbln_config=None, return_unused_kwargs=False, **kwargs) classmethod ¶
Load a RBLNModelConfig from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the RBLNModelConfig file or directory containing the config file. | required |
rbln_config | dict[str, Any] | None | Additional configuration to override. | None |
return_unused_kwargs | bool | Whether to return unused kwargs. | False |
kwargs | Any | Additional keyword arguments to override configuration values. Keys starting with 'rbln_' will have the prefix removed and be used to update the configuration. | {} |
Returns:
| Name | Type | Description |
|---|---|---|
RBLNModelConfig | Self | tuple[Self, dict[str, Any]] | The loaded configuration instance. |
Note
This method loads the configuration from the specified path and applies any provided overrides. If the loaded configuration class doesn't match the expected class, a warning will be logged.
Examples:
RBLNStableDiffusionXLInpaintPipelineConfig ¶
Bases: RBLNStableDiffusionXLPipelineBaseConfig
Config for SDXL Inpainting Pipeline
initialize_submodule_config(submodule_config=None, force_kwargs=False, **kwargs) ¶
Build the config of a submodule from the parent's runtime options and kwargs.
Returns the submodule config instance when its class is known (an instance was passed, or cls_name was given), otherwise the merged kwargs dict for the model class to resolve later.
__init__(text_encoder=None, text_encoder_2=None, unet=None, vae=None, *, batch_size=None, img_height=None, img_width=None, height=None, width=None, sample_size=None, image_size=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_encoder | RBLNCLIPTextModelConfig | None | Configuration for the primary text encoder component. Initialized as RBLNCLIPTextModelConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder component. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
unet | RBLNUNet2DConditionModelConfig | None | Configuration for the UNet model component. Initialized as RBLNUNet2DConditionModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
batch_size | int | None | Batch size for inference, applied to all submodules. | None |
img_height | int | None | Height of the generated images. | None |
img_width | int | None | Width of the generated images. | None |
height | int | None | Height of the generated images. | None |
width | int | None | Width of the generated images. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the UNet model. | None |
image_size | tuple[int, int] | None | Alternative way to specify image dimensions. Cannot be used together with img_height/img_width. | None |
guidance_scale | float | None | Scale for classifier-free guidance. | None |
kwargs | Any | Additional arguments passed to the parent RBLNModelConfig. | {} |
Raises:
| Type | Description |
|---|---|
ValueError | If both image_size and img_height/img_width are provided. |
Note
When guidance_scale > 1.0, the UNet batch size is automatically doubled to accommodate classifier-free guidance.
get_load_overrides() ¶
Extract the options that must cross the load boundary, for passing to from_pretrained.
Returns the explicitly-set runtime options (device, device_map, create_runtimes, activate_profiler, timeout) and the subclass-specific non-save attributes (load-behavior flags such as _load_visual_runtime, which are never serialized so they can only travel with the caller), recursively including submodules. Compile-time attributes are not included: when loading a compiled model they come from the artifact's rbln_config.json, and this dict is merged on top of it.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary of load overrides, keyed like the |
from_pretrained(path, rbln_config=None, return_unused_kwargs=False, **kwargs) classmethod ¶
Load a RBLNModelConfig from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the RBLNModelConfig file or directory containing the config file. | required |
rbln_config | dict[str, Any] | None | Additional configuration to override. | None |
return_unused_kwargs | bool | Whether to return unused kwargs. | False |
kwargs | Any | Additional keyword arguments to override configuration values. Keys starting with 'rbln_' will have the prefix removed and be used to update the configuration. | {} |
Returns:
| Name | Type | Description |
|---|---|---|
RBLNModelConfig | Self | tuple[Self, dict[str, Any]] | The loaded configuration instance. |
Note
This method loads the configuration from the specified path and applies any provided overrides. If the loaded configuration class doesn't match the expected class, a warning will be logged.
Examples: