Skip to content

Commit 70111d7

Browse files
rebel-jonghorebel-junamsongrebel-seinparkrebel-thkimrebel-dkhong
authored
other: update docstrings and minor updates (#270)
Co-authored-by: rebel-junamsong <[email protected]> Co-authored-by: rebel-seinpark <[email protected]> Co-authored-by: rebel-thkim <[email protected]> Co-authored-by: thkim <[email protected]> Co-authored-by: rebel-dkhong <[email protected]> Co-authored-by: rebel-kblee <[email protected]>
1 parent d8691fd commit 70111d7

File tree

59 files changed

+610
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+610
-222
lines changed

src/optimum/rbln/configuration_utils.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ def load_config(path: str) -> Tuple[Type["RBLNModelConfig"], Dict[str, Any]]:
185185

186186

187187
class RBLNAutoConfig:
188+
"""
189+
Resolver and factory for RBLN model configurations.
190+
191+
This class selects the concrete `RBLNModelConfig` subclass, validates the
192+
provided data, and returns a frozen configuration object that serves as the
193+
single source of truth during export and load. It does not define the schema
194+
or control model behavior.
195+
"""
196+
188197
def __new__(cls, **kwargs):
189198
cls_name = kwargs.get("cls_name")
190199
if cls_name is None:
@@ -194,6 +203,33 @@ def __new__(cls, **kwargs):
194203

195204
@staticmethod
196205
def load_from_dict(config_dict: Dict[str, Any]) -> "RBLNModelConfig":
206+
"""
207+
Build a `RBLNModelConfig` from a plain dictionary.
208+
209+
The dictionary must contain `cls_name`, which identifies the concrete
210+
configuration class to instantiate. All other keys are forwarded to the
211+
target class initializer. This method does not mutate `config_dict`.
212+
213+
Args:
214+
config_dict: Mapping typically created by `json.load` or `yaml.safe_load`.
215+
For example, the parsed contents of `rbln_config.json`.
216+
217+
Returns:
218+
RBLNModelConfig: A configuration instance. The specific subclass is
219+
selected by `config_dict["cls_name"]`.
220+
221+
Raises:
222+
ValueError: If `cls_name` is missing.
223+
Exception: Any error raised by the target config class during init.
224+
225+
Examples:
226+
>>> data = {
227+
... "cls_name": "RBLNLlamaForCausalLMConfig",
228+
... "create_runtimes": False,
229+
... "tensor_parallel_size": 4
230+
... }
231+
>>> cfg = RBLNAutoConfig.load_from_dict(data)
232+
"""
197233
cls_name = config_dict.get("cls_name")
198234
if cls_name is None:
199235
raise ValueError("`cls_name` is required.")
@@ -206,7 +242,8 @@ def register(config: Type["RBLNModelConfig"], exist_ok=False):
206242
Register a new configuration for this class.
207243
208244
Args:
209-
config ([`RBLNModelConfig`]): The config to register.
245+
config (RBLNModelConfig): The config to register.
246+
exist_ok (bool): Whether to allow registering an already registered model.
210247
"""
211248
if not issubclass(config, RBLNModelConfig):
212249
raise ValueError("`config` must be a subclass of RBLNModelConfig.")
@@ -282,6 +319,7 @@ class RBLNModelConfig(RBLNSerializableConfigProtocol):
282319
"""Base configuration class for RBLN models that handles compilation settings, runtime options, and submodules.
283320
284321
This class provides functionality for:
322+
285323
1. Managing compilation configurations for RBLN devices
286324
2. Configuring runtime behavior such as device placement
287325
3. Handling nested configuration objects for complex model architectures
@@ -594,7 +632,7 @@ def __init__(
594632
optimum_rbln_version (Optional[str]): The optimum-rbln version used for this configuration.
595633
_torch_dtype (Optional[str]): The data type to use for the model.
596634
_compile_cfgs (List[RBLNCompileConfig]): List of compilation configurations for the model.
597-
**kwargs: Additional keyword arguments.
635+
kwargs: Additional keyword arguments.
598636
599637
Raises:
600638
ValueError: If unexpected keyword arguments are provided.
@@ -761,7 +799,7 @@ def load(cls, path: str, **kwargs: Any) -> "RBLNModelConfig":
761799
762800
Args:
763801
path (str): Path to the RBLNModelConfig file or directory containing the config file.
764-
**kwargs: Additional keyword arguments to override configuration values.
802+
kwargs: Additional keyword arguments to override configuration values.
765803
Keys starting with 'rbln_' will have the prefix removed and be used
766804
to update the configuration.
767805

src/optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
Determines how much smaller the latent representations are compared to the original images.
4747
in_channels (Optional[int]): Number of input channels for the model.
4848
latent_channels (Optional[int]): Number of channels in the latent space.
49-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
49+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
5050
5151
Raises:
5252
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl_cosmos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Optional
15+
from typing import Any, Dict, Optional
1616

1717
from ....configuration_utils import RBLNModelConfig
1818
from ....utils.logging import get_logger
@@ -35,7 +35,7 @@ def __init__(
3535
vae_scale_factor_temporal: Optional[int] = None,
3636
vae_scale_factor_spatial: Optional[int] = None,
3737
use_slicing: Optional[bool] = None,
38-
**kwargs: Any,
38+
**kwargs: Dict[str, Any],
3939
):
4040
"""
4141
Args:
@@ -52,7 +52,7 @@ def __init__(
5252
Determines how much smaller the latent representations are compared to the original videos.
5353
use_slicing (Optional[bool]): Enable sliced VAE encoding and decoding.
5454
If True, the VAE will split the input tensor in slices to compute encoding or decoding in several steps.
55-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
55+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
5656
5757
Raises:
5858
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_controlnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
of the VAE input/output images.
4343
text_model_hidden_size (Optional[int]): Hidden size of the text encoder model used
4444
for conditioning.
45-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
45+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
4646
4747
Raises:
4848
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RBLNPriorTransformerConfig(RBLNModelConfig):
2222
Configuration class for RBLN Prior Transformer models.
2323
2424
This class inherits from RBLNModelConfig and provides specific configuration options
25-
for Prior Transformer models used in diffusion models like Kandinsky V2.2.
25+
for Transformer models used in diffusion models like Kandinsky V2.2.
2626
"""
2727

2828
subclass_non_save_attributes = ["_batch_size_is_specified"]
@@ -39,7 +39,7 @@ def __init__(
3939
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
4040
embedding_dim (Optional[int]): Dimension of the embedding vectors in the model.
4141
num_embeddings (Optional[int]): Number of discrete embeddings in the codebook.
42-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
42+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
4343
4444
Raises:
4545
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_transformer_cosmos.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818

1919

2020
class RBLNCosmosTransformer3DModelConfig(RBLNModelConfig):
21-
"""Configuration class for RBLN Cosmos Transformer models."""
21+
"""
22+
Configuration class for RBLN Cosmos Transformer models.
23+
24+
This class inherits from RBLNModelConfig and provides specific configuration options
25+
for Transformer models used in diffusion models like Cosmos.
26+
"""
2227

2328
def __init__(
2429
self,
@@ -47,7 +52,7 @@ def __init__(
4752
num_channels_latents (Optional[int]): The number of channels in latent space.
4853
latent_height (Optional[int]): The height in pixels in latent space.
4954
latent_width (Optional[int]): The width in pixels in latent space.
50-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
55+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
5156
5257
Raises:
5358
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818

1919

2020
class RBLNSD3Transformer2DModelConfig(RBLNModelConfig):
21-
"""Configuration class for RBLN Stable Diffusion 3 Transformer models."""
21+
"""
22+
Configuration class for RBLN Stable Diffusion 3 Transformer models.
23+
24+
This class inherits from RBLNModelConfig and provides specific configuration options
25+
for Transformer models used in diffusion models like Stable Diffusion 3.
26+
"""
2227

2328
subclass_non_save_attributes = ["_batch_size_is_specified"]
2429

@@ -36,7 +41,7 @@ def __init__(
3641
of the generated samples. If an integer is provided, it's used for both height and width.
3742
prompt_embed_length (Optional[int]): The length of the embedded prompt vectors that
3843
will be used to condition the transformer model.
39-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
44+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
4045
4146
Raises:
4247
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
in_features (Optional[int]): Number of input features for the model.
5353
text_model_hidden_size (Optional[int]): Hidden size of the text encoder model.
5454
image_model_hidden_size (Optional[int]): Hidden size of the image encoder model.
55-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
55+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
5656
5757
Raises:
5858
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/models/configuration_vq_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
Determines the downsampling ratio between original images and latent representations.
4747
in_channels (Optional[int]): Number of input channels for the model.
4848
latent_channels (Optional[int]): Number of channels in the latent space.
49-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
49+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
5050
5151
Raises:
5252
ValueError: If batch_size is not a positive integer.

src/optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
6060
Cannot be used together with img_height/img_width.
6161
guidance_scale (Optional[float]): Scale for classifier-free guidance.
62-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
62+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
6363
6464
Raises:
6565
ValueError: If both image_size and img_height/img_width are provided.
@@ -201,7 +201,7 @@ def __init__(
201201
image_size (Optional[Tuple[int, int]]): Alternative way to specify image dimensions.
202202
Cannot be used together with img_height/img_width.
203203
guidance_scale (Optional[float]): Scale for classifier-free guidance.
204-
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
204+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
205205
206206
Raises:
207207
ValueError: If both image_size and img_height/img_width are provided.

0 commit comments

Comments
 (0)