Stable Diffusion 3¶
Stable Diffusion 3 (SD3) is a text-to-image model from Stability AI built on a Multimodal Diffusion Transformer (MMDiT) architecture. It excels at handling complex prompts involving multiple subjects, spatial relationships, and diverse text styles. SD3 uses three distinct text encoders (CLIP-L, OpenCLIP-G, T5-XXL) for enhanced prompt interpretation. RBLN NPUs can accelerate Stable Diffusion 3 pipelines using RBLN Optimum.
Supported NPU
Diffusers pipelines run on ATOM™ only. Rebel100™ does not support them yet.
Supported Pipelines¶
RBLN Optimum supports several Stable Diffusion 3 pipelines:
| Pipeline | Class | Description |
|---|---|---|
| Text-to-Image | RBLNStableDiffusion3Pipeline | Generate images from text prompts. |
| Image-to-Image | RBLNStableDiffusion3Img2ImgPipeline | Modify existing images based on text prompts. |
| Inpainting | RBLNStableDiffusion3InpaintPipeline | Fill masked regions of an image guided by text prompts. |
Important: Batch Size Configuration for Guidance Scale¶
Batch Size and Guidance Scale
When using Stable Diffusion 3 with a guidance scale > 1.0 (the default is 7.0), the MMDiT Transformer's effective batch size is doubled during runtime because of the classifier-free guidance technique.
Because RBLN NPUs use static graph compilation, the Transformer's batch size at compilation time must match its runtime batch size. Otherwise, the compiled graph cannot execute and inference fails.
Default Behavior¶
By default, if you do not explicitly specify the Transformer's batch size, RBLN Optimum does the following:
- Assumes you'll use a guidance scale > 1.0.
- Automatically sets the Transformer's batch size to 2× your pipeline's batch size.
If you plan to use the default guidance scale (which is > 1.0), this automatic configuration works correctly. However, if you plan to use a different guidance scale or want more control, explicitly configure the Transformer's batch size.
Example: Explicitly Setting the Transformer Batch Size (guidance_scale > 1.0)¶
Example: Disabling Guidance (guidance_scale = 0.0)¶
If you plan to use a guidance scale of exactly 0.0 (disabling classifier-free guidance), explicitly set the Transformer batch size to match your inference batch size:
Usage Example (Text-to-Image)¶
API Reference¶
RBLNStableDiffusion3Pipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusion3Pipeline
RBLN-accelerated implementation of Stable Diffusion 3 pipeline for advanced text-to-image generation.
This pipeline compiles Stable Diffusion 3 models to run efficiently on RBLN NPUs, enabling high-performance inference with improved text understanding, enhanced image quality, and superior 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. |
RBLNStableDiffusion3Img2ImgPipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusion3Img2ImgPipeline
RBLN-accelerated implementation of Stable Diffusion 3 pipeline for advanced image-to-image generation.
This pipeline compiles Stable Diffusion 3 models to run efficiently on RBLN NPUs, enabling high-performance inference for transforming input images with superior text understanding and enhanced visual quality.
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. |
RBLNStableDiffusion3InpaintPipeline ¶
Bases: RBLNDiffusionMixin, StableDiffusion3InpaintPipeline
RBLN-accelerated implementation of Stable Diffusion 3 pipeline for advanced image inpainting.
This pipeline compiles Stable Diffusion 3 models to run efficiently on RBLN NPUs, enabling high-performance inference for filling masked regions with superior text understanding and seamless content generation.
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. |
RBLNStableDiffusion3PipelineBaseConfig ¶
Bases: RBLNModelConfig
__init__(transformer=None, text_encoder=None, text_encoder_2=None, text_encoder_3=None, vae=None, *, max_seq_len=None, sample_size=None, image_size=None, batch_size=None, img_height=None, img_width=None, height=None, width=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer | RBLNSD3Transformer2DModelConfig | None | Configuration for the transformer model component. Initialized as RBLNSD3Transformer2DModelConfig if not provided. | None |
text_encoder | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the primary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_3 | RBLNT5EncoderModelConfig | None | Configuration for the tertiary text encoder. Initialized as RBLNT5EncoderModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
max_seq_len | int | None | Maximum sequence length for text inputs. Defaults to 256. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the transformer model. | None |
image_size | tuple[int, int] | None | Dimensions for the generated images. Cannot be used together with img_height/img_width. | 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 |
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 transformer 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 |
RBLNStableDiffusion3PipelineConfig ¶
Bases: RBLNStableDiffusion3PipelineBaseConfig
Config for SD3 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__(transformer=None, text_encoder=None, text_encoder_2=None, text_encoder_3=None, vae=None, *, max_seq_len=None, sample_size=None, image_size=None, batch_size=None, img_height=None, img_width=None, height=None, width=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer | RBLNSD3Transformer2DModelConfig | None | Configuration for the transformer model component. Initialized as RBLNSD3Transformer2DModelConfig if not provided. | None |
text_encoder | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the primary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_3 | RBLNT5EncoderModelConfig | None | Configuration for the tertiary text encoder. Initialized as RBLNT5EncoderModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
max_seq_len | int | None | Maximum sequence length for text inputs. Defaults to 256. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the transformer model. | None |
image_size | tuple[int, int] | None | Dimensions for the generated images. Cannot be used together with img_height/img_width. | 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 |
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 transformer 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:
RBLNStableDiffusion3Img2ImgPipelineConfig ¶
Bases: RBLNStableDiffusion3PipelineBaseConfig
Config for SD3 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__(transformer=None, text_encoder=None, text_encoder_2=None, text_encoder_3=None, vae=None, *, max_seq_len=None, sample_size=None, image_size=None, batch_size=None, img_height=None, img_width=None, height=None, width=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer | RBLNSD3Transformer2DModelConfig | None | Configuration for the transformer model component. Initialized as RBLNSD3Transformer2DModelConfig if not provided. | None |
text_encoder | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the primary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_3 | RBLNT5EncoderModelConfig | None | Configuration for the tertiary text encoder. Initialized as RBLNT5EncoderModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
max_seq_len | int | None | Maximum sequence length for text inputs. Defaults to 256. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the transformer model. | None |
image_size | tuple[int, int] | None | Dimensions for the generated images. Cannot be used together with img_height/img_width. | 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 |
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 transformer 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:
RBLNStableDiffusion3InpaintPipelineConfig ¶
Bases: RBLNStableDiffusion3PipelineBaseConfig
Config for SD3 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__(transformer=None, text_encoder=None, text_encoder_2=None, text_encoder_3=None, vae=None, *, max_seq_len=None, sample_size=None, image_size=None, batch_size=None, img_height=None, img_width=None, height=None, width=None, guidance_scale=None, **kwargs) ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer | RBLNSD3Transformer2DModelConfig | None | Configuration for the transformer model component. Initialized as RBLNSD3Transformer2DModelConfig if not provided. | None |
text_encoder | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the primary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_2 | RBLNCLIPTextModelWithProjectionConfig | None | Configuration for the secondary text encoder. Initialized as RBLNCLIPTextModelWithProjectionConfig if not provided. | None |
text_encoder_3 | RBLNT5EncoderModelConfig | None | Configuration for the tertiary text encoder. Initialized as RBLNT5EncoderModelConfig if not provided. | None |
vae | RBLNAutoencoderKLConfig | None | Configuration for the VAE model component. Initialized as RBLNAutoencoderKLConfig if not provided. | None |
max_seq_len | int | None | Maximum sequence length for text inputs. Defaults to 256. | None |
sample_size | tuple[int, int] | None | Spatial dimensions for the transformer model. | None |
image_size | tuple[int, int] | None | Dimensions for the generated images. Cannot be used together with img_height/img_width. | 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 |
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 transformer 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: