optimum-rbln 0.7.4a7__py3-none-any.whl → 0.7.4a8__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/__version__.py +2 -2
- optimum/rbln/configuration_utils.py +18 -1
- optimum/rbln/diffusers/modeling_diffusers.py +41 -15
- optimum/rbln/modeling_base.py +4 -3
- optimum/rbln/transformers/models/auto/auto_factory.py +3 -3
- optimum/rbln/utils/hub.py +2 -2
- optimum/rbln/utils/model_utils.py +4 -4
- {optimum_rbln-0.7.4a7.dist-info → optimum_rbln-0.7.4a8.dist-info}/METADATA +2 -2
- {optimum_rbln-0.7.4a7.dist-info → optimum_rbln-0.7.4a8.dist-info}/RECORD +11 -11
- {optimum_rbln-0.7.4a7.dist-info → optimum_rbln-0.7.4a8.dist-info}/WHEEL +0 -0
- {optimum_rbln-0.7.4a7.dist-info → optimum_rbln-0.7.4a8.dist-info}/licenses/LICENSE +0 -0
optimum/rbln/__version__.py
CHANGED
@@ -17,5 +17,5 @@ __version__: str
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
18
18
|
version_tuple: VERSION_TUPLE
|
19
19
|
|
20
|
-
__version__ = version = '0.7.
|
21
|
-
__version_tuple__ = version_tuple = (0, 7, 4, '
|
20
|
+
__version__ = version = '0.7.4a8'
|
21
|
+
__version_tuple__ = version_tuple = (0, 7, 4, 'a8')
|
@@ -174,6 +174,14 @@ class RBLNAutoConfig:
|
|
174
174
|
cls = getattr(importlib.import_module("optimum.rbln"), cls_name)
|
175
175
|
return cls(**kwargs)
|
176
176
|
|
177
|
+
@staticmethod
|
178
|
+
def load_from_dict(config_dict: Dict[str, Any]) -> "RBLNModelConfig":
|
179
|
+
cls_name = config_dict.get("cls_name")
|
180
|
+
if cls_name is None:
|
181
|
+
raise ValueError("`cls_name` is required.")
|
182
|
+
cls = getattr(importlib.import_module("optimum.rbln"), cls_name)
|
183
|
+
return cls(**config_dict)
|
184
|
+
|
177
185
|
@staticmethod
|
178
186
|
def load(
|
179
187
|
path: str,
|
@@ -195,8 +203,9 @@ class RBLNAutoConfig:
|
|
195
203
|
cls, config_file = load_config(path)
|
196
204
|
|
197
205
|
rbln_keys = [key for key in kwargs.keys() if key.startswith("rbln_")]
|
198
|
-
|
199
206
|
rbln_runtime_kwargs = {key[5:]: kwargs.pop(key) for key in rbln_keys if key[5:] in RUNTIME_KEYWORDS}
|
207
|
+
rbln_submodule_kwargs = {key[5:]: kwargs.pop(key) for key in rbln_keys if key[5:] in cls.submodules}
|
208
|
+
|
200
209
|
rbln_kwargs = {
|
201
210
|
key[5:]: kwargs.pop(key)
|
202
211
|
for key in rbln_keys
|
@@ -206,6 +215,14 @@ class RBLNAutoConfig:
|
|
206
215
|
if len(rbln_kwargs) > 0:
|
207
216
|
raise ValueError(f"Cannot set the following arguments: {list(rbln_kwargs.keys())}")
|
208
217
|
|
218
|
+
# Process submodule's rbln_config
|
219
|
+
for submodule in cls.submodules:
|
220
|
+
if submodule not in config_file:
|
221
|
+
raise ValueError(f"Submodule {submodule} not found in rbln_config.json.")
|
222
|
+
submodule_config = config_file[submodule]
|
223
|
+
submodule_config.update(rbln_submodule_kwargs.pop(submodule, {}))
|
224
|
+
config_file[submodule] = RBLNAutoConfig.load_from_dict(submodule_config)
|
225
|
+
|
209
226
|
if passed_rbln_config is not None:
|
210
227
|
config_file.update(passed_rbln_config._runtime_options)
|
211
228
|
# TODO(jongho): Reject if the passed_rbln_config has different attributes from the config_file
|
@@ -47,17 +47,11 @@ class RBLNDiffusionMixin:
|
|
47
47
|
|
48
48
|
1. Create a new pipeline class that inherits from both this mixin and the original StableDiffusionPipeline.
|
49
49
|
2. Define the required _submodules class variable listing the components to be compiled.
|
50
|
-
3. If needed, implement get_default_rbln_config for custom configuration of submodules.
|
51
50
|
|
52
51
|
Example:
|
53
52
|
```python
|
54
53
|
class RBLNStableDiffusionPipeline(RBLNDiffusionMixin, StableDiffusionPipeline):
|
55
54
|
_submodules = ["text_encoder", "unet", "vae"]
|
56
|
-
|
57
|
-
@classmethod
|
58
|
-
def get_default_rbln_config(cls, model, submodule_name, rbln_config):
|
59
|
-
# Configuration for other submodules...
|
60
|
-
pass
|
61
55
|
```
|
62
56
|
|
63
57
|
Class Variables:
|
@@ -77,14 +71,6 @@ class RBLNDiffusionMixin:
|
|
77
71
|
_prefix = {}
|
78
72
|
_rbln_config_class = None
|
79
73
|
|
80
|
-
@classmethod
|
81
|
-
def is_img2img_pipeline(cls):
|
82
|
-
return "Img2Img" in cls.__name__
|
83
|
-
|
84
|
-
@classmethod
|
85
|
-
def is_inpaint_pipeline(cls):
|
86
|
-
return "Inpaint" in cls.__name__
|
87
|
-
|
88
74
|
@staticmethod
|
89
75
|
def _maybe_apply_and_fuse_lora(
|
90
76
|
model: torch.nn.Module,
|
@@ -151,7 +137,47 @@ class RBLNDiffusionMixin:
|
|
151
137
|
lora_weights_names: Optional[Union[str, List[str]]] = None,
|
152
138
|
lora_scales: Optional[Union[float, List[float]]] = None,
|
153
139
|
**kwargs,
|
154
|
-
) ->
|
140
|
+
) -> "RBLNDiffusionMixin":
|
141
|
+
"""
|
142
|
+
Load a pretrained diffusion pipeline from a model checkpoint, with optional compilation for RBLN NPUs.
|
143
|
+
|
144
|
+
This method has two distinct operating modes:
|
145
|
+
- When `export=True`: Takes a PyTorch-based diffusion model, compiles it for RBLN NPUs, and loads the compiled model
|
146
|
+
- When `export=False`: Loads an already compiled RBLN model from `model_id` without recompilation
|
147
|
+
|
148
|
+
It supports various diffusion pipelines including Stable Diffusion, Kandinsky, ControlNet, and other diffusers-based models.
|
149
|
+
|
150
|
+
Args:
|
151
|
+
model_id (`str`):
|
152
|
+
The model ID or path to the pretrained model to load. Can be either:
|
153
|
+
- A model ID from the HuggingFace Hub
|
154
|
+
- A local path to a saved model directory
|
155
|
+
export (`bool`, *optional*, defaults to `False`):
|
156
|
+
If True, takes a PyTorch model from `model_id` and compiles it for RBLN NPU execution.
|
157
|
+
If False, loads an already compiled RBLN model from `model_id` without recompilation.
|
158
|
+
model_save_dir (`os.PathLike`, *optional*):
|
159
|
+
Directory to save the compiled model artifacts. Only used when `export=True`.
|
160
|
+
If not provided and `export=True`, a temporary directory is used.
|
161
|
+
rbln_config (`Dict[str, Any]`, *optional*, defaults to `{}`):
|
162
|
+
Configuration options for RBLN compilation. Can include settings for specific submodules
|
163
|
+
such as `text_encoder`, `unet`, and `vae`. Configuration can be tailored to the specific
|
164
|
+
pipeline being compiled.
|
165
|
+
lora_ids (`str` or `List[str]`, *optional*):
|
166
|
+
LoRA adapter ID(s) to load and apply before compilation. LoRA weights are fused
|
167
|
+
into the model weights during compilation. Only used when `export=True`.
|
168
|
+
lora_weights_names (`str` or `List[str]`, *optional*):
|
169
|
+
Names of specific LoRA weight files to load, corresponding to lora_ids. Only used when `export=True`.
|
170
|
+
lora_scales (`float` or `List[float]`, *optional*):
|
171
|
+
Scaling factor(s) to apply to the LoRA adapter(s). Only used when `export=True`.
|
172
|
+
**kwargs:
|
173
|
+
Additional arguments to pass to the underlying diffusion pipeline constructor or the
|
174
|
+
RBLN compilation process. These may include parameters specific to individual submodules
|
175
|
+
or the particular diffusion pipeline being used.
|
176
|
+
|
177
|
+
Returns:
|
178
|
+
`RBLNDiffusionMixin`: A compiled or loaded diffusion pipeline that can be used for inference on RBLN NPU.
|
179
|
+
The returned object is an instance of the class that called this method, inheriting from RBLNDiffusionMixin.
|
180
|
+
"""
|
155
181
|
rbln_config, kwargs = cls.get_rbln_config_class().initialize_from_kwargs(rbln_config, **kwargs)
|
156
182
|
|
157
183
|
if export:
|
optimum/rbln/modeling_base.py
CHANGED
@@ -216,6 +216,7 @@ class RBLNBaseModel(SubModulesMixin, PushToHubMixin, PreTrainedModel):
|
|
216
216
|
if isinstance(rbln_config, dict):
|
217
217
|
rbln_config_as_kwargs = {f"rbln_{key}": value for key, value in rbln_config.items()}
|
218
218
|
kwargs.update(rbln_config_as_kwargs)
|
219
|
+
rbln_config = None
|
219
220
|
elif isinstance(rbln_config, RBLNModelConfig) and rbln_config.rbln_model_cls_name != cls.__name__:
|
220
221
|
raise ValueError(
|
221
222
|
f"Cannot use the passed rbln_config. Its model class name ({rbln_config.rbln_model_cls_name}) "
|
@@ -392,13 +393,13 @@ class RBLNBaseModel(SubModulesMixin, PushToHubMixin, PreTrainedModel):
|
|
392
393
|
@classmethod
|
393
394
|
def get_hf_class(cls):
|
394
395
|
"""
|
395
|
-
Lazily loads and caches the corresponding
|
396
|
+
Lazily loads and caches the corresponding HuggingFace model class.
|
396
397
|
Removes 'RBLN' prefix from the class name to get the original class name
|
397
398
|
(e.g., RBLNLlamaForCausalLM -> LlamaForCausalLM) and imports it from
|
398
399
|
the transformers/diffusers module.
|
399
400
|
|
400
401
|
Returns:
|
401
|
-
type: The original
|
402
|
+
type: The original HuggingFace model class
|
402
403
|
"""
|
403
404
|
if cls._hf_class is None:
|
404
405
|
hf_cls_name = cls.__name__[4:]
|
@@ -478,7 +479,7 @@ class RBLNBaseModel(SubModulesMixin, PushToHubMixin, PreTrainedModel):
|
|
478
479
|
save_directory (`Union[str, Path]`):
|
479
480
|
Directory where to save the model file.
|
480
481
|
push_to_hub (`bool`, *optional*, defaults to `False`):
|
481
|
-
Whether or not to push your model to the
|
482
|
+
Whether or not to push your model to the HuggingFace model hub after saving it.
|
482
483
|
|
483
484
|
"""
|
484
485
|
if os.path.isfile(save_directory):
|
@@ -48,7 +48,7 @@ class _BaseAutoModelClass:
|
|
48
48
|
|
49
49
|
Args:
|
50
50
|
pretrained_model_name_or_path (str): Identifier or path to the pretrained model.
|
51
|
-
export (bool): Whether to infer the class based on
|
51
|
+
export (bool): Whether to infer the class based on HuggingFace (HF) architecture.
|
52
52
|
kwargs: Additional arguments for configuration and loading.
|
53
53
|
|
54
54
|
Returns:
|
@@ -86,14 +86,14 @@ class _BaseAutoModelClass:
|
|
86
86
|
**kwargs,
|
87
87
|
):
|
88
88
|
"""
|
89
|
-
Infer the
|
89
|
+
Infer the HuggingFace model class based on the configuration or model name.
|
90
90
|
|
91
91
|
Args:
|
92
92
|
pretrained_model_name_or_path (str): Identifier or path to the pretrained model.
|
93
93
|
kwargs: Additional arguments for configuration and loading.
|
94
94
|
|
95
95
|
Returns:
|
96
|
-
PretrainedModel: The inferred
|
96
|
+
PretrainedModel: The inferred HuggingFace model class.
|
97
97
|
"""
|
98
98
|
|
99
99
|
# Try to load configuration if provided or retrieve it from the model ID
|
optimum/rbln/utils/hub.py
CHANGED
@@ -63,7 +63,7 @@ def pull_compiled_model_from_hub(
|
|
63
63
|
force_download: bool,
|
64
64
|
local_files_only: bool,
|
65
65
|
) -> Path:
|
66
|
-
"""Pull model files from the
|
66
|
+
"""Pull model files from the HuggingFace Hub."""
|
67
67
|
huggingface_token = _get_huggingface_token(use_auth_token)
|
68
68
|
repo_files = list(
|
69
69
|
map(
|
@@ -119,4 +119,4 @@ def _get_huggingface_token(use_auth_token: Union[bool, str]) -> str:
|
|
119
119
|
elif use_auth_token:
|
120
120
|
return HfFolder.get_token()
|
121
121
|
else:
|
122
|
-
raise ValueError("`use_auth_token` must be provided to interact with the
|
122
|
+
raise ValueError("`use_auth_token` must be provided to interact with the HuggingFace Hub.")
|
@@ -18,10 +18,10 @@ RBLN_PREFIX = "RBLN"
|
|
18
18
|
|
19
19
|
def convert_hf_to_rbln_model_name(hf_model_name: str):
|
20
20
|
"""
|
21
|
-
Convert
|
21
|
+
Convert HuggingFace model name to RBLN model name.
|
22
22
|
|
23
23
|
Args:
|
24
|
-
hf_model_name (str): The
|
24
|
+
hf_model_name (str): The HuggingFace model name.
|
25
25
|
|
26
26
|
Returns:
|
27
27
|
str: The corresponding RBLN model name.
|
@@ -31,13 +31,13 @@ def convert_hf_to_rbln_model_name(hf_model_name: str):
|
|
31
31
|
|
32
32
|
def convert_rbln_to_hf_model_name(rbln_model_name: str):
|
33
33
|
"""
|
34
|
-
Convert RBLN model name to
|
34
|
+
Convert RBLN model name to HuggingFace model name.
|
35
35
|
|
36
36
|
Args:
|
37
37
|
rbln_model_name (str): The RBLN model name.
|
38
38
|
|
39
39
|
Returns:
|
40
|
-
str: The corresponding
|
40
|
+
str: The corresponding HuggingFace model name.
|
41
41
|
"""
|
42
42
|
|
43
43
|
return rbln_model_name.removeprefix(RBLN_PREFIX)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: optimum-rbln
|
3
|
-
Version: 0.7.
|
4
|
-
Summary: Optimum RBLN is the interface between the
|
3
|
+
Version: 0.7.4a8
|
4
|
+
Summary: Optimum RBLN is the interface between the HuggingFace Transformers and Diffusers libraries and RBLN accelerators. It provides a set of tools enabling easy model loading and inference on single and multiple rbln device settings for different downstream tasks.
|
5
5
|
Project-URL: Homepage, https://rebellions.ai
|
6
6
|
Project-URL: Documentation, https://docs.rbln.ai
|
7
7
|
Project-URL: Repository, https://github.com/rebellions-sw/optimum-rbln
|
@@ -1,10 +1,10 @@
|
|
1
1
|
optimum/rbln/__init__.py,sha256=c2whRR6XkelNLlH1MwAKYMoaBEhmGxSQFrhfKS1JC-I,13186
|
2
|
-
optimum/rbln/__version__.py,sha256=
|
3
|
-
optimum/rbln/configuration_utils.py,sha256=
|
2
|
+
optimum/rbln/__version__.py,sha256=QL0a_B-kCttMpg_RwbPMs7mYzsY06SEmJHJVDUYponM,519
|
3
|
+
optimum/rbln/configuration_utils.py,sha256=S2RGzl-gdE5evUd5ZsO9i8LXgPGCrQEOGZJTa6t1A9Y,30044
|
4
4
|
optimum/rbln/modeling.py,sha256=qDXB69Oq0jx9hfONebDiSNe2_DgKYhnAGLTbGAtwYVw,9677
|
5
|
-
optimum/rbln/modeling_base.py,sha256=
|
5
|
+
optimum/rbln/modeling_base.py,sha256=iQKw2IORu1cN6sOK0xeBVrhatt-ZPeinT_v6l2FnGRw,24173
|
6
6
|
optimum/rbln/diffusers/__init__.py,sha256=XL6oKPHbPCV6IVCw3fu0-M9mD2KO_x6unx5kJdAtpVY,6180
|
7
|
-
optimum/rbln/diffusers/modeling_diffusers.py,sha256=
|
7
|
+
optimum/rbln/diffusers/modeling_diffusers.py,sha256=DrB-UZbNYXGQYyY5DXOeH88_AfSg35JPEQ3AXnkrCP4,19294
|
8
8
|
optimum/rbln/diffusers/configurations/__init__.py,sha256=Sk_sQVTuTl01RVgYViWknQSLmulxKaISS0w-oPdNoBQ,1164
|
9
9
|
optimum/rbln/diffusers/configurations/models/__init__.py,sha256=P3vif5I4wYeol50jzHCZ1ttujuEFZSYJPzUdSF6_jsU,407
|
10
10
|
optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py,sha256=61QHgb_tVF6lxvy6vBxst2TjnebeKQy3rKHOOOc6e68,2952
|
@@ -68,7 +68,7 @@ optimum/rbln/transformers/modeling_generic.py,sha256=nT_lytAILkYtwBVJKxXg0dxmh0U
|
|
68
68
|
optimum/rbln/transformers/modeling_rope_utils.py,sha256=3zwkhYUyTZhxCJUSmwCc88iiY1TppRWEY9ShwUqNB2k,14293
|
69
69
|
optimum/rbln/transformers/models/__init__.py,sha256=72eMPN5UYGJ9P5gnJ2yi25cGdX1jV7viTOKmsX2OqBg,7221
|
70
70
|
optimum/rbln/transformers/models/auto/__init__.py,sha256=GvGbb3ZpMv-h6euXeZ42jSizoOfrL2O1uvpAnfKxYEo,1034
|
71
|
-
optimum/rbln/transformers/models/auto/auto_factory.py,sha256=
|
71
|
+
optimum/rbln/transformers/models/auto/auto_factory.py,sha256=Uf5rCUoxec2qhIAwbAeZNZN4NIMFaLurSB1EdI79lwA,7044
|
72
72
|
optimum/rbln/transformers/models/auto/modeling_auto.py,sha256=Un9qoqdy3dO8JBza_bTJF_6_fRVNM9QisihSgTRFI-o,3933
|
73
73
|
optimum/rbln/transformers/models/bart/__init__.py,sha256=fVo-gZEmJ0yxkIxEX6ciuRAGgXNyuvaXE2s88bhbjAE,830
|
74
74
|
optimum/rbln/transformers/models/bart/bart_architecture.py,sha256=Oo-Cdne7igKEex8wwP-gztKJHgs5GLHQjK1oc3IZIDE,5801
|
@@ -156,14 +156,14 @@ optimum/rbln/transformers/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
156
156
|
optimum/rbln/transformers/utils/rbln_quantization.py,sha256=gwBVHf97sQgPNmGa0wq87E8mPyrtXYhMnO4X4sKp3c8,7639
|
157
157
|
optimum/rbln/utils/__init__.py,sha256=ieDBT2VFTt2E0M4v_POLBpuGW9LxSydpb_DuPd6PQqc,712
|
158
158
|
optimum/rbln/utils/decorator_utils.py,sha256=xu-TrsNi33SRC2a7DBsyoo6-pEQxWKZPZSmM9QlDe2Y,3745
|
159
|
-
optimum/rbln/utils/hub.py,sha256=
|
159
|
+
optimum/rbln/utils/hub.py,sha256=Z_R9Ic9VAew8bUmlaAlxZf5JGMDBivHvvFRI557pILY,4196
|
160
160
|
optimum/rbln/utils/import_utils.py,sha256=uMldLJmDVMj5uHvxBfb96uV29bfGEDvlksLY26GOHAs,4389
|
161
161
|
optimum/rbln/utils/logging.py,sha256=VKKBmlQSdg6iZCGmAXaWYiW67K84jyp1QJhLQSSjPPE,3453
|
162
|
-
optimum/rbln/utils/model_utils.py,sha256=
|
162
|
+
optimum/rbln/utils/model_utils.py,sha256=V2kFpUe2aqVzLwbpztD8JOVFQqRHncvIWwJbgnUPr4E,1274
|
163
163
|
optimum/rbln/utils/runtime_utils.py,sha256=LoKNK3AQNV_BSScstIZWjICkJf265MnUgy360BOocVI,5454
|
164
164
|
optimum/rbln/utils/save_utils.py,sha256=hG5uOtYmecSXZuGTvCXsTM-SiyZpr5q3InUGCCq_jzQ,3619
|
165
165
|
optimum/rbln/utils/submodule.py,sha256=TtcH3OLctFd2Dosc-zNMGZ8xOXKKUfE91dLQ1v09E8Q,4636
|
166
|
-
optimum_rbln-0.7.
|
167
|
-
optimum_rbln-0.7.
|
168
|
-
optimum_rbln-0.7.
|
169
|
-
optimum_rbln-0.7.
|
166
|
+
optimum_rbln-0.7.4a8.dist-info/METADATA,sha256=jkrw5KRSdUkdaY3ZJYv0A4HHNhUDdOB59D_tNSMa7Ss,5299
|
167
|
+
optimum_rbln-0.7.4a8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
168
|
+
optimum_rbln-0.7.4a8.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
169
|
+
optimum_rbln-0.7.4a8.dist-info/RECORD,,
|
File without changes
|
File without changes
|