optimum-rbln 0.1.11__py3-none-any.whl → 0.1.12__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 +10 -7
- optimum/rbln/__version__.py +1 -1
- optimum/rbln/diffusers/models/autoencoder_kl.py +0 -2
- optimum/rbln/diffusers/models/controlnet.py +0 -6
- optimum/rbln/diffusers/models/unet_2d_condition.py +0 -3
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +4 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +18 -20
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +18 -20
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +19 -34
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +20 -35
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +12 -13
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +12 -14
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +13 -14
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +13 -14
- optimum/rbln/modeling_alias.py +4 -9
- optimum/rbln/modeling_base.py +105 -139
- optimum/rbln/modeling_config.py +51 -0
- optimum/rbln/transformers/__init__.py +8 -0
- optimum/rbln/transformers/models/__init__.py +4 -1
- optimum/rbln/transformers/models/auto/modeling_auto.py +1 -0
- optimum/rbln/transformers/models/bart/__init__.py +1 -1
- optimum/rbln/transformers/models/bart/bart_architecture.py +18 -12
- optimum/rbln/transformers/models/bart/modeling_bart.py +25 -6
- optimum/rbln/transformers/models/bert/modeling_bert.py +1 -2
- optimum/rbln/transformers/models/clip/modeling_clip.py +0 -1
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +172 -100
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +0 -1
- optimum/rbln/transformers/models/exaone/__init__.py +32 -0
- optimum/rbln/transformers/models/exaone/exaone_architecture.py +72 -0
- optimum/rbln/transformers/models/exaone/hf_hub_cached/configuration_exaone.py +181 -0
- optimum/rbln/transformers/models/exaone/hf_hub_cached/modeling_exaone.py +1725 -0
- optimum/rbln/transformers/models/exaone/modeling_exaone.py +78 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +148 -152
- optimum/rbln/transformers/models/midm/modeling_midm.py +5 -0
- optimum/rbln/transformers/models/qwen2/__init__.py +24 -0
- optimum/rbln/transformers/models/qwen2/modeling_qwen2.py +67 -0
- optimum/rbln/transformers/models/qwen2/qwen2_architecture.py +29 -0
- optimum/rbln/transformers/models/seq2seq/__init__.py +24 -0
- optimum/rbln/{modeling_seq2seq.py → transformers/models/seq2seq/modeling_seq2seq.py} +107 -166
- optimum/rbln/transformers/models/t5/__init__.py +1 -0
- optimum/rbln/transformers/models/t5/modeling_t5.py +55 -0
- optimum/rbln/transformers/models/t5/t5_architecture.py +46 -32
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +0 -1
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +37 -12
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +1 -2
- optimum/rbln/utils/import_utils.py +14 -0
- optimum/rbln/utils/logging.py +1 -1
- optimum/rbln/utils/runtime_utils.py +1 -1
- optimum/rbln/utils/timer_utils.py +26 -2
- {optimum_rbln-0.1.11.dist-info → optimum_rbln-0.1.12.dist-info}/METADATA +4 -3
- {optimum_rbln-0.1.11.dist-info → optimum_rbln-0.1.12.dist-info}/RECORD +54 -44
- {optimum_rbln-0.1.11.dist-info → optimum_rbln-0.1.12.dist-info}/WHEEL +1 -1
- {optimum_rbln-0.1.11.dist-info → optimum_rbln-0.1.12.dist-info}/entry_points.txt +0 -0
- {optimum_rbln-0.1.11.dist-info → optimum_rbln-0.1.12.dist-info}/licenses/LICENSE +0 -0
optimum/rbln/modeling_base.py
CHANGED
@@ -21,7 +21,6 @@
|
|
21
21
|
# copied, modified, or distributed without prior written permission
|
22
22
|
# from Rebellions Inc.
|
23
23
|
|
24
|
-
import copy
|
25
24
|
import importlib
|
26
25
|
import inspect
|
27
26
|
import logging
|
@@ -50,9 +49,9 @@ from transformers import (
|
|
50
49
|
PretrainedConfig,
|
51
50
|
)
|
52
51
|
|
53
|
-
from .modeling_config import DEFAULT_COMPILED_MODEL_NAME, RBLNCompileConfig, RBLNConfig
|
52
|
+
from .modeling_config import DEFAULT_COMPILED_MODEL_NAME, RBLNCompileConfig, RBLNConfig, use_rbln_config
|
54
53
|
from .utils.runtime_utils import UnavailableRuntime
|
55
|
-
from .utils.save_utils import maybe_load_preprocessors
|
54
|
+
from .utils.save_utils import maybe_load_preprocessors
|
56
55
|
|
57
56
|
|
58
57
|
if TYPE_CHECKING:
|
@@ -86,13 +85,11 @@ class SubModulesMixin:
|
|
86
85
|
setattr(self, submodule_meta["name"], submodule)
|
87
86
|
|
88
87
|
@classmethod
|
89
|
-
def
|
88
|
+
def _export_submodules_from_model(
|
90
89
|
cls,
|
91
90
|
model: "PreTrainedModel",
|
92
91
|
model_save_dir: str,
|
93
|
-
rbln_sub_configs_dict: Dict[str, Any],
|
94
92
|
rbln_kwargs: Dict[str, Any],
|
95
|
-
subfolder=None, # warning: will be ignored
|
96
93
|
**kwargs,
|
97
94
|
) -> List["RBLNBaseModel"]:
|
98
95
|
rbln_submodules = []
|
@@ -100,18 +97,15 @@ class SubModulesMixin:
|
|
100
97
|
submodule_name = submodule["name"]
|
101
98
|
torch_submodule: "PreTrainedModel" = getattr(model, submodule["name"])
|
102
99
|
cls_name = torch_submodule.__class__.__name__
|
103
|
-
submodule_cls: "
|
100
|
+
submodule_cls: "RBLNModel" = getattr(importlib.import_module("optimum.rbln"), f"RBLN{cls_name}")
|
104
101
|
|
105
|
-
if submodule_name in
|
106
|
-
kwargs["rbln_config"] =
|
102
|
+
if submodule_name in rbln_kwargs:
|
103
|
+
kwargs["rbln_config"] = rbln_kwargs[submodule_name]
|
107
104
|
|
108
|
-
rbln_submodule = submodule_cls.
|
109
|
-
|
110
|
-
config=torch_submodule.config,
|
105
|
+
rbln_submodule = submodule_cls.from_model(
|
106
|
+
model=torch_submodule,
|
111
107
|
subfolder=submodule_name,
|
112
108
|
model_save_dir=model_save_dir,
|
113
|
-
model=torch_submodule,
|
114
|
-
**rbln_kwargs,
|
115
109
|
**kwargs,
|
116
110
|
)
|
117
111
|
|
@@ -120,26 +114,29 @@ class SubModulesMixin:
|
|
120
114
|
return rbln_submodules
|
121
115
|
|
122
116
|
@classmethod
|
123
|
-
def
|
124
|
-
cls,
|
117
|
+
def _load_submodules_from_compiled_models(
|
118
|
+
cls,
|
119
|
+
model_save_dir: str,
|
120
|
+
rbln_kwargs: Dict[str, Any],
|
121
|
+
**kwargs,
|
125
122
|
):
|
126
123
|
rbln_submodules = []
|
127
124
|
for submodule in cls._rbln_submodules:
|
128
125
|
submodule_name = submodule["name"]
|
129
|
-
|
126
|
+
|
127
|
+
if submodule_name in rbln_kwargs:
|
128
|
+
kwargs["rbln_config"] = rbln_kwargs[submodule_name]
|
130
129
|
|
131
130
|
# Get cls name for call the constructor of the rbln class
|
132
131
|
submodule_rbln_config = RBLNConfig.load(Path(model_save_dir) / submodule_name)
|
133
132
|
submodule_cls_name = submodule_rbln_config.meta["cls"]
|
134
133
|
submodule_cls: "RBLNBaseModel" = getattr(importlib.import_module("optimum.rbln"), submodule_cls_name)
|
135
134
|
|
136
|
-
config = OptimizedModel._load_config(Path(model_save_dir) / submodule_name
|
135
|
+
config = OptimizedModel._load_config(Path(model_save_dir) / submodule_name)
|
137
136
|
rbln_submodule = submodule_cls._from_pretrained(
|
138
137
|
model_id=model_save_dir,
|
139
138
|
config=config,
|
140
139
|
subfolder=submodule_name,
|
141
|
-
rbln_config=rbln_submodule_config_dict,
|
142
|
-
**rbln_kwargs,
|
143
140
|
**kwargs,
|
144
141
|
)
|
145
142
|
rbln_submodules.append(rbln_submodule)
|
@@ -149,27 +146,24 @@ class SubModulesMixin:
|
|
149
146
|
def _load_submodules(
|
150
147
|
cls,
|
151
148
|
model_save_dir,
|
152
|
-
rbln_sub_configs_dict,
|
153
149
|
rbln_kwargs,
|
154
150
|
model=None,
|
155
151
|
**kwargs,
|
156
152
|
):
|
157
|
-
# Two
|
153
|
+
# Two ways :
|
158
154
|
# 1. Compile from pytorch object
|
159
155
|
# 2. Load from compiled file
|
160
156
|
if model is not None:
|
161
|
-
return cls.
|
157
|
+
return cls._export_submodules_from_model(
|
162
158
|
model=model,
|
163
159
|
model_save_dir=model_save_dir,
|
164
|
-
rbln_sub_configs_dict=rbln_sub_configs_dict,
|
165
160
|
rbln_kwargs=rbln_kwargs,
|
166
161
|
**kwargs,
|
167
162
|
)
|
168
163
|
|
169
164
|
else:
|
170
|
-
return cls.
|
165
|
+
return cls._load_submodules_from_compiled_models(
|
171
166
|
model_save_dir=model_save_dir,
|
172
|
-
rbln_sub_configs_dict=rbln_sub_configs_dict,
|
173
167
|
rbln_kwargs=rbln_kwargs,
|
174
168
|
**kwargs,
|
175
169
|
)
|
@@ -370,45 +364,7 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
370
364
|
return rbln_compiled_models
|
371
365
|
|
372
366
|
@classmethod
|
373
|
-
|
374
|
-
# {"language_model" : {"rbln_tensor_parallel_size":4}}
|
375
|
-
rbln_sub_configs_dict: Dict[str, Dict[str, Any]] = {}
|
376
|
-
|
377
|
-
# Remove submodule-configs from rbln_config
|
378
|
-
if len(cls._rbln_submodules) > 0:
|
379
|
-
keys = list(rbln_config_dict.keys())
|
380
|
-
submodule_names = [m["name"] for m in cls._rbln_submodules]
|
381
|
-
for key in keys:
|
382
|
-
if key in submodule_names:
|
383
|
-
rbln_sub_configs_dict[key] = rbln_config_dict.pop(key)
|
384
|
-
|
385
|
-
return rbln_sub_configs_dict
|
386
|
-
|
387
|
-
@classmethod
|
388
|
-
def resolve_rbln_config(cls, rbln_config: Union[RBLNConfig, Dict[str, Any]], kwargs):
|
389
|
-
if isinstance(rbln_config, RBLNConfig):
|
390
|
-
# Already resolved
|
391
|
-
return rbln_config, None
|
392
|
-
|
393
|
-
else:
|
394
|
-
if rbln_config is None:
|
395
|
-
rbln_config_dict = {}
|
396
|
-
else:
|
397
|
-
rbln_config_dict = rbln_config
|
398
|
-
|
399
|
-
rbln_kwargs = cls.pop_rbln_kwargs_from_kwargs(kwargs)
|
400
|
-
rbln_sub_configs_dict = cls._split_submodule_config(rbln_config_dict)
|
401
|
-
|
402
|
-
for key in rbln_config_dict:
|
403
|
-
if key in rbln_kwargs:
|
404
|
-
raise KeyError(f"duplicate key in both `rbln_config` and {key}")
|
405
|
-
|
406
|
-
merged_rbln_kwargs = copy.deepcopy(rbln_kwargs)
|
407
|
-
merged_rbln_kwargs.update(rbln_config_dict)
|
408
|
-
|
409
|
-
return (merged_rbln_kwargs, rbln_sub_configs_dict)
|
410
|
-
|
411
|
-
@classmethod
|
367
|
+
@use_rbln_config
|
412
368
|
def _from_pretrained(
|
413
369
|
cls,
|
414
370
|
model_id: Union[str, Path],
|
@@ -430,7 +386,7 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
430
386
|
|
431
387
|
if not from_export_method:
|
432
388
|
# from compiled dir
|
433
|
-
rbln_kwargs
|
389
|
+
rbln_kwargs = rbln_config or {}
|
434
390
|
|
435
391
|
model_path_subfolder = cls._load_compiled_model_dir(
|
436
392
|
model_id=model_id,
|
@@ -450,7 +406,6 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
450
406
|
if len(cls._rbln_submodules) > 0:
|
451
407
|
rbln_submodules = cls._load_submodules(
|
452
408
|
model_save_dir=model_id,
|
453
|
-
rbln_sub_configs_dict=rbln_sub_configs_dict,
|
454
409
|
rbln_kwargs=rbln_kwargs,
|
455
410
|
**kwargs,
|
456
411
|
)
|
@@ -477,9 +432,9 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
477
432
|
cls,
|
478
433
|
rbln_compiled_models: Dict[str, rebel.RBLNCompiledModel],
|
479
434
|
rbln_config: RBLNConfig,
|
480
|
-
config,
|
481
|
-
model_save_dir: str,
|
482
|
-
subfolder: str,
|
435
|
+
config: "PretrainedConfig",
|
436
|
+
model_save_dir: Union[Path, str],
|
437
|
+
subfolder: Union[Path, str],
|
483
438
|
rbln_submodules: List["RBLNBaseModel"] = [],
|
484
439
|
**kwargs,
|
485
440
|
):
|
@@ -538,25 +493,10 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
538
493
|
rbln_config = cls._get_rbln_config(**others, rbln_kwargs=rbln_kwargs)
|
539
494
|
return rbln_config
|
540
495
|
|
541
|
-
@staticmethod
|
542
|
-
def pop_rbln_kwargs_from_kwargs(kwargs: Dict[str, Any], runtime_only=False):
|
543
|
-
keys = list(kwargs.keys())
|
544
|
-
rbln_kwargs = {key[5:]: kwargs.pop(key) for key in keys if key.startswith("rbln_")}
|
545
|
-
|
546
|
-
if runtime_only:
|
547
|
-
rbln_kwargs = {
|
548
|
-
key: value
|
549
|
-
for key, value in rbln_kwargs.items()
|
550
|
-
if key in {"create_runtimes", "optimize_host_memory", "device", "device_map"}
|
551
|
-
}
|
552
|
-
|
553
|
-
return rbln_kwargs
|
554
|
-
|
555
496
|
def can_generate(self):
|
556
497
|
return False
|
557
498
|
|
558
499
|
def to(self, *args, **kwargs):
|
559
|
-
# Do nothing
|
560
500
|
return self
|
561
501
|
|
562
502
|
def __call__(self, *args, **kwargs):
|
@@ -599,12 +539,49 @@ class RBLNBaseModel(OptimizedModel, ABC, SubModulesMixin):
|
|
599
539
|
|
600
540
|
@classmethod
|
601
541
|
@abstractmethod
|
602
|
-
def
|
603
|
-
"""
|
604
|
-
Exports a vanilla Transformers model into a rbln-compiled Module.
|
605
|
-
"""
|
542
|
+
def get_pytorch_model(cls, *args, **kwargs):
|
606
543
|
pass
|
607
544
|
|
545
|
+
@classmethod
|
546
|
+
@abstractmethod
|
547
|
+
@use_rbln_config
|
548
|
+
def from_model(
|
549
|
+
cls,
|
550
|
+
model: "PreTrainedModel",
|
551
|
+
rbln_config: Dict[str, Any] = {},
|
552
|
+
model_save_dir: Optional[Union[str, Path, TemporaryDirectory]] = None,
|
553
|
+
subfolder: str = "",
|
554
|
+
**kwargs,
|
555
|
+
):
|
556
|
+
pass
|
557
|
+
|
558
|
+
@classmethod
|
559
|
+
@use_rbln_config
|
560
|
+
def _export(
|
561
|
+
cls,
|
562
|
+
model_id: Union[str, Path],
|
563
|
+
config: "PretrainedConfig", # FIXME : optimum passes config, but we ignore it.
|
564
|
+
rbln_config: Optional[Dict[str, Any]] = None,
|
565
|
+
**kwargs,
|
566
|
+
) -> "RBLNModel":
|
567
|
+
subfolder = kwargs.get("subfolder", "")
|
568
|
+
model_save_dir = kwargs.pop("model_save_dir", None)
|
569
|
+
|
570
|
+
rbln_kwargs = rbln_config
|
571
|
+
model: "PreTrainedModel" = cls.get_pytorch_model(
|
572
|
+
model_id=model_id,
|
573
|
+
rbln_kwargs=rbln_kwargs,
|
574
|
+
**kwargs,
|
575
|
+
)
|
576
|
+
preprocessors = maybe_load_preprocessors(model_id, subfolder=subfolder)
|
577
|
+
return cls.from_model(
|
578
|
+
model,
|
579
|
+
rbln_config=rbln_config,
|
580
|
+
preprocessors=preprocessors,
|
581
|
+
model_save_dir=model_save_dir,
|
582
|
+
**kwargs,
|
583
|
+
)
|
584
|
+
|
608
585
|
|
609
586
|
class RBLNModel(RBLNBaseModel):
|
610
587
|
"""
|
@@ -695,25 +672,19 @@ class RBLNModel(RBLNBaseModel):
|
|
695
672
|
return compiled_model
|
696
673
|
|
697
674
|
@classmethod
|
698
|
-
@
|
699
|
-
def
|
675
|
+
@use_rbln_config
|
676
|
+
def from_model(
|
700
677
|
cls,
|
701
|
-
|
702
|
-
|
703
|
-
use_auth_token: Optional[Union[bool, str]] = None,
|
704
|
-
revision: Optional[str] = None,
|
705
|
-
force_download: bool = False,
|
706
|
-
cache_dir: Optional[str] = None,
|
707
|
-
subfolder: str = "",
|
708
|
-
local_files_only: bool = False,
|
709
|
-
trust_remote_code: bool = False,
|
678
|
+
model: "PreTrainedModel",
|
679
|
+
rbln_config: Dict[str, Any] = {},
|
710
680
|
model_save_dir: Optional[Union[str, Path, TemporaryDirectory]] = None,
|
711
|
-
|
712
|
-
rbln_config: Optional[Dict[str, Any]] = None,
|
681
|
+
subfolder: str = "",
|
713
682
|
**kwargs,
|
714
|
-
)
|
715
|
-
|
683
|
+
):
|
684
|
+
preprocessors = kwargs.pop("preprocessors", [])
|
685
|
+
rbln_kwargs = rbln_config
|
716
686
|
|
687
|
+
# Directory to save compile artifacts(.rbln) and original configs
|
717
688
|
if model_save_dir is None:
|
718
689
|
save_dir = TemporaryDirectory()
|
719
690
|
save_dir_path = Path(save_dir.name)
|
@@ -725,43 +696,31 @@ class RBLNModel(RBLNBaseModel):
|
|
725
696
|
save_dir_path = Path(model_save_dir)
|
726
697
|
save_dir_path.mkdir(exist_ok=True)
|
727
698
|
|
728
|
-
#
|
729
|
-
|
730
|
-
|
731
|
-
model_id=model_id,
|
732
|
-
subfolder=subfolder,
|
733
|
-
revision=revision,
|
734
|
-
cache_dir=cache_dir,
|
735
|
-
use_auth_token=use_auth_token,
|
736
|
-
local_files_only=local_files_only,
|
737
|
-
force_download=force_download,
|
738
|
-
trust_remote_code=trust_remote_code,
|
739
|
-
rbln_kwargs=rbln_kwargs,
|
740
|
-
**kwargs,
|
741
|
-
)
|
742
|
-
preprocessors = maybe_save_preprocessors(model_id, save_dir_path, src_subfolder=subfolder)
|
743
|
-
else:
|
744
|
-
preprocessors = []
|
699
|
+
# (Optional) Save preprocessors (tokenizer, image preprocessors, etc)
|
700
|
+
for preprocessor in preprocessors:
|
701
|
+
preprocessor.save_pretrained(save_dir_path)
|
745
702
|
|
746
|
-
#
|
703
|
+
# Save configs
|
704
|
+
# FIXME :: optimum passes AutoConfig. But here we ignore it.
|
747
705
|
config = model.config
|
748
706
|
if hasattr(model, "can_generate") and model.can_generate():
|
749
707
|
generation_config = model.generation_config
|
750
708
|
generation_config.save_pretrained(save_dir_path / subfolder)
|
751
|
-
|
752
709
|
if not isinstance(config, PretrainedConfig): # diffusers config
|
753
710
|
config = PretrainedConfig(**config)
|
754
711
|
config.save_pretrained(save_dir_path / subfolder)
|
755
712
|
|
756
|
-
# Get compilation arguments
|
713
|
+
# Get compilation arguments (e.g. input_info)
|
757
714
|
rbln_config: RBLNConfig = cls.get_rbln_config(
|
758
715
|
preprocessors=preprocessors, model_config=config, rbln_kwargs=rbln_kwargs
|
759
716
|
)
|
717
|
+
# rbln_config.update_runtime_cfg(rbln_kwargs) # This is done in get_rbln_config
|
718
|
+
|
760
719
|
compiled_model: Union[rebel.RBLNCompiledModel, Dict[str, rebel.RBLNCompiledModel]] = cls.get_compiled_model(
|
761
720
|
model, rbln_config=rbln_config
|
762
721
|
)
|
763
722
|
|
764
|
-
# Save compiled models
|
723
|
+
# Save compiled models (.rbln)
|
765
724
|
(save_dir_path / subfolder).mkdir(exist_ok=True)
|
766
725
|
if not isinstance(compiled_model, dict):
|
767
726
|
compiled_models = {DEFAULT_COMPILED_MODEL_NAME: compiled_model}
|
@@ -771,6 +730,7 @@ class RBLNModel(RBLNBaseModel):
|
|
771
730
|
cm.save(save_dir_path / subfolder / f"{compiled_model_name}.rbln")
|
772
731
|
rbln_config.save(save_dir_path / subfolder)
|
773
732
|
|
733
|
+
# Save torch artifacts (e.g. embedding matrix if needed.)
|
774
734
|
cls.save_torch_artifacts(model, save_dir_path=save_dir_path, subfolder=subfolder, rbln_config=rbln_config)
|
775
735
|
|
776
736
|
# Load submodules
|
@@ -778,7 +738,6 @@ class RBLNModel(RBLNBaseModel):
|
|
778
738
|
rbln_submodules = cls._load_submodules(
|
779
739
|
model=model,
|
780
740
|
model_save_dir=save_dir,
|
781
|
-
rbln_sub_configs_dict=rbln_sub_configs_dict,
|
782
741
|
rbln_kwargs=rbln_kwargs,
|
783
742
|
**kwargs,
|
784
743
|
)
|
@@ -790,12 +749,7 @@ class RBLNModel(RBLNBaseModel):
|
|
790
749
|
model_id=save_dir_path,
|
791
750
|
config=config,
|
792
751
|
model_save_dir=save_dir,
|
793
|
-
use_auth_token=use_auth_token,
|
794
|
-
revision=revision,
|
795
|
-
force_download=force_download,
|
796
|
-
cache_dir=cache_dir,
|
797
752
|
subfolder=subfolder,
|
798
|
-
local_files_only=local_files_only,
|
799
753
|
rbln_config=rbln_config,
|
800
754
|
rbln_compiled_models=compiled_models,
|
801
755
|
rbln_submodules=rbln_submodules,
|
@@ -817,7 +771,6 @@ class RBLNModel(RBLNBaseModel):
|
|
817
771
|
|
818
772
|
|
819
773
|
class RBLNModelForQuestionAnswering(RBLNModel):
|
820
|
-
model_type = "rbln_model"
|
821
774
|
auto_model_class = AutoModelForQuestionAnswering
|
822
775
|
rbln_model_input_names = ["input_ids", "attention_mask", "token_type_ids"]
|
823
776
|
|
@@ -878,7 +831,6 @@ class RBLNModelForImageClassification(RBLNModel):
|
|
878
831
|
This is a generic model class that will be instantiated as one of the model classes of the library (with a image classification head) when created with the from_pretrained() class method
|
879
832
|
"""
|
880
833
|
|
881
|
-
model_type = "rbln_model"
|
882
834
|
auto_model_class = AutoModelForImageClassification
|
883
835
|
|
884
836
|
@classmethod
|
@@ -894,8 +846,17 @@ class RBLNModelForImageClassification(RBLNModel):
|
|
894
846
|
if rbln_image_size is None:
|
895
847
|
for processor in preprocessors:
|
896
848
|
if hasattr(processor, "size"):
|
897
|
-
|
849
|
+
if all(required_key in processor.size.keys() for required_key in ["height", "width"]):
|
850
|
+
rbln_image_size = (processor.size["height"], processor.size["width"])
|
851
|
+
elif "shortest_edge" in processor.size.keys():
|
852
|
+
rbln_image_size = (processor.size["shortest_edge"], processor.size["shortest_edge"])
|
853
|
+
elif "longest_edge" in processor.size.keys():
|
854
|
+
rbln_image_size = (processor.size["longest_edge"], processor.size["longest_edge"])
|
898
855
|
break
|
856
|
+
|
857
|
+
if rbln_image_size is None:
|
858
|
+
rbln_image_size = model_config.image_size
|
859
|
+
|
899
860
|
if rbln_image_size is None:
|
900
861
|
raise ValueError("`rbln_image_size` should be specified!")
|
901
862
|
|
@@ -903,12 +864,20 @@ class RBLNModelForImageClassification(RBLNModel):
|
|
903
864
|
rbln_batch_size = 1
|
904
865
|
|
905
866
|
if isinstance(rbln_image_size, int):
|
906
|
-
|
867
|
+
rbln_image_height, rbln_image_width = rbln_image_size, rbln_image_size
|
868
|
+
elif isinstance(rbln_image_size, (list, tuple)):
|
869
|
+
rbln_image_height, rbln_image_width = rbln_image_size[0], rbln_image_size[1]
|
870
|
+
elif isinstance(rbln_image_size, dict):
|
871
|
+
rbln_image_height, rbln_image_width = rbln_image_size["height"], rbln_image_size["width"]
|
872
|
+
else:
|
873
|
+
raise ValueError(
|
874
|
+
"`rbln_image_size` should be `int` (ex. 224), `tuple` (ex. 224, 224), `dict` (ex. {'height': 224, 'width': 224}) format"
|
875
|
+
)
|
907
876
|
|
908
877
|
input_info = [
|
909
878
|
(
|
910
879
|
"pixel_values",
|
911
|
-
[rbln_batch_size, 3,
|
880
|
+
[rbln_batch_size, 3, rbln_image_height, rbln_image_width],
|
912
881
|
"float32",
|
913
882
|
)
|
914
883
|
]
|
@@ -930,7 +899,6 @@ class RBLNModelForAudioClassification(RBLNModel):
|
|
930
899
|
Currently, this model class only supports the 'AST' model from the transformers library. Future updates may include support for additional model types.
|
931
900
|
"""
|
932
901
|
|
933
|
-
model_type = "rbln_model"
|
934
902
|
auto_model_class = AutoModelForAudioClassification
|
935
903
|
|
936
904
|
@classmethod
|
@@ -1005,7 +973,6 @@ class RBLNModelForSequenceClassification(RBLNModel):
|
|
1005
973
|
Currently, this model class supports the 'XLMRoberta' and 'Roberta' model from the transformers library. Future updates may include support for additional model types.
|
1006
974
|
"""
|
1007
975
|
|
1008
|
-
model_type = "rbln_model"
|
1009
976
|
auto_model_class = AutoModelForSequenceClassification
|
1010
977
|
|
1011
978
|
@classmethod
|
@@ -1070,7 +1037,6 @@ class RBLNModelForSequenceClassification(RBLNModel):
|
|
1070
1037
|
|
1071
1038
|
|
1072
1039
|
class RBLNModelForMaskedLM(RBLNModel):
|
1073
|
-
model_type = "rbln_model"
|
1074
1040
|
auto_model_class = AutoModelForMaskedLM
|
1075
1041
|
|
1076
1042
|
@classmethod
|
optimum/rbln/modeling_config.py
CHANGED
@@ -242,3 +242,54 @@ class RBLNConfig:
|
|
242
242
|
rbln_device_map[cfg.compiled_model_name] = device_val
|
243
243
|
return rbln_device_map
|
244
244
|
return self.runtime_cfg["device_map"]
|
245
|
+
|
246
|
+
|
247
|
+
def use_rbln_config(fn):
|
248
|
+
"""
|
249
|
+
If the function uses rbln_config and kwargs,
|
250
|
+
then extract `rbln_` prefix from kwargs.
|
251
|
+
|
252
|
+
If rbln_config is already an instance of RBLNConfig, then pass.
|
253
|
+
"""
|
254
|
+
|
255
|
+
def merged_rbln_config_fn(*args, **kwargs):
|
256
|
+
rbln_kwargs = kwargs.pop("rbln_kwargs", None)
|
257
|
+
if rbln_kwargs is not None:
|
258
|
+
raise KeyError("`rbln_kwargs` cannot be specified when using `rbln_config`!")
|
259
|
+
|
260
|
+
rbln_config = kwargs.pop("rbln_config", None)
|
261
|
+
|
262
|
+
keys = list(kwargs.keys())
|
263
|
+
rbln_kwargs = {key[5:]: kwargs.pop(key) for key in keys if key.startswith("rbln_")}
|
264
|
+
|
265
|
+
if isinstance(rbln_config, RBLNConfig):
|
266
|
+
# merge runtime kwargs if exists.
|
267
|
+
runtime_rbln_kwargs = {k: rbln_kwargs.pop(k) for k in RUNTIME_KEYWORDS if k in rbln_kwargs}
|
268
|
+
|
269
|
+
# ignore internal keys and recover "rbln_" prefix
|
270
|
+
RBLN_INTERNAL_KEYS = {"compiled_models", "submodules"}
|
271
|
+
internal_kwargs = {"rbln_" + k: rbln_kwargs.pop(k) for k in RBLN_INTERNAL_KEYS if k in rbln_kwargs}
|
272
|
+
|
273
|
+
if len(rbln_kwargs) > 0:
|
274
|
+
raise KeyError(
|
275
|
+
f"Failed to merging function argument : {rbln_kwargs.keys()}. "
|
276
|
+
"If you passed `rbln_config` an instance of `RBLNConfig`, "
|
277
|
+
"then none `rbln_` prefixes are allowed to be passed."
|
278
|
+
)
|
279
|
+
rbln_config.update_runtime_cfg(runtime_rbln_kwargs)
|
280
|
+
return fn(*args, **kwargs, **internal_kwargs, rbln_config=rbln_config)
|
281
|
+
|
282
|
+
elif rbln_config is None:
|
283
|
+
rbln_config_dict = {}
|
284
|
+
|
285
|
+
else:
|
286
|
+
rbln_config_dict = rbln_config
|
287
|
+
|
288
|
+
for key in rbln_config_dict:
|
289
|
+
if key in rbln_kwargs:
|
290
|
+
raise KeyError(f"Duplicated key in both `rbln_config` and rbln_{key}.")
|
291
|
+
|
292
|
+
rbln_kwargs.update(rbln_config_dict)
|
293
|
+
return fn(*args, **kwargs, rbln_config=rbln_kwargs)
|
294
|
+
|
295
|
+
return merged_rbln_config_fn
|
@@ -42,18 +42,22 @@ _import_structure = {
|
|
42
42
|
"RBLNAutoModelForSequenceClassification",
|
43
43
|
"RBLNAutoModelForSpeechSeq2Seq",
|
44
44
|
"RBLNAutoModelForVision2Seq",
|
45
|
+
"RBLNBartForConditionalGeneration",
|
45
46
|
"RBLNBartModel",
|
46
47
|
"RBLNBertModel",
|
47
48
|
"RBLNCLIPTextModel",
|
48
49
|
"RBLNCLIPTextModelWithProjection",
|
49
50
|
"RBLNCLIPVisionModel",
|
50
51
|
"RBLNDPTForDepthEstimation",
|
52
|
+
"RBLNExaoneForCausalLM",
|
51
53
|
"RBLNGemmaForCausalLM",
|
52
54
|
"RBLNGPT2LMHeadModel",
|
55
|
+
"RBLNQwen2ForCausalLM",
|
53
56
|
"RBLNWav2Vec2ForCTC",
|
54
57
|
"RBLNWhisperForConditionalGeneration",
|
55
58
|
"RBLNLlamaForCausalLM",
|
56
59
|
"RBLNPhiForCausalLM",
|
60
|
+
"RBLNT5ForConditionalGeneration",
|
57
61
|
"RBLNLlavaNextForConditionalGeneration",
|
58
62
|
"RBLNMidmLMHeadModel",
|
59
63
|
"RBLNXLMRobertaModel",
|
@@ -77,12 +81,14 @@ if TYPE_CHECKING:
|
|
77
81
|
RBLNAutoModelForSequenceClassification,
|
78
82
|
RBLNAutoModelForSpeechSeq2Seq,
|
79
83
|
RBLNAutoModelForVision2Seq,
|
84
|
+
RBLNBartForConditionalGeneration,
|
80
85
|
RBLNBartModel,
|
81
86
|
RBLNBertModel,
|
82
87
|
RBLNCLIPTextModel,
|
83
88
|
RBLNCLIPTextModelWithProjection,
|
84
89
|
RBLNCLIPVisionModel,
|
85
90
|
RBLNDPTForDepthEstimation,
|
91
|
+
RBLNExaoneForCausalLM,
|
86
92
|
RBLNGemmaForCausalLM,
|
87
93
|
RBLNGPT2LMHeadModel,
|
88
94
|
RBLNLlamaForCausalLM,
|
@@ -90,6 +96,8 @@ if TYPE_CHECKING:
|
|
90
96
|
RBLNMidmLMHeadModel,
|
91
97
|
RBLNMistralForCausalLM,
|
92
98
|
RBLNPhiForCausalLM,
|
99
|
+
RBLNQwen2ForCausalLM,
|
100
|
+
RBLNT5ForConditionalGeneration,
|
93
101
|
RBLNWav2Vec2ForCTC,
|
94
102
|
RBLNWhisperForConditionalGeneration,
|
95
103
|
RBLNXLMRobertaModel,
|
@@ -36,10 +36,11 @@ from .auto import (
|
|
36
36
|
RBLNAutoModelForSpeechSeq2Seq,
|
37
37
|
RBLNAutoModelForVision2Seq,
|
38
38
|
)
|
39
|
-
from .bart import RBLNBartModel
|
39
|
+
from .bart import RBLNBartForConditionalGeneration, RBLNBartModel
|
40
40
|
from .bert import RBLNBertModel
|
41
41
|
from .clip import RBLNCLIPTextModel, RBLNCLIPTextModelWithProjection, RBLNCLIPVisionModel
|
42
42
|
from .dpt import RBLNDPTForDepthEstimation
|
43
|
+
from .exaone import RBLNExaoneForCausalLM
|
43
44
|
from .gemma import RBLNGemmaForCausalLM
|
44
45
|
from .gpt2 import RBLNGPT2LMHeadModel
|
45
46
|
from .llama import RBLNLlamaForCausalLM
|
@@ -47,6 +48,8 @@ from .llava_next import RBLNLlavaNextForConditionalGeneration
|
|
47
48
|
from .midm import RBLNMidmLMHeadModel
|
48
49
|
from .mistral import RBLNMistralForCausalLM
|
49
50
|
from .phi import RBLNPhiForCausalLM
|
51
|
+
from .qwen2 import RBLNQwen2ForCausalLM
|
52
|
+
from .t5 import RBLNT5ForConditionalGeneration
|
50
53
|
from .wav2vec2 import RBLNWav2Vec2ForCTC
|
51
54
|
from .whisper import RBLNWhisperForConditionalGeneration
|
52
55
|
from .xlm_roberta import RBLNXLMRobertaModel
|