optimum-rbln 0.1.8__py3-none-any.whl → 0.1.11__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 +40 -2
- optimum/rbln/__version__.py +1 -1
- optimum/rbln/diffusers/models/autoencoder_kl.py +39 -32
- optimum/rbln/diffusers/models/controlnet.py +60 -43
- optimum/rbln/diffusers/models/unet_2d_condition.py +43 -31
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +2 -3
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +22 -15
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +22 -15
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +23 -17
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +24 -18
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +22 -11
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +22 -11
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +24 -14
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +24 -14
- optimum/rbln/modeling_alias.py +8 -4
- optimum/rbln/modeling_base.py +512 -238
- optimum/rbln/modeling_config.py +152 -77
- optimum/rbln/modeling_seq2seq.py +166 -77
- optimum/rbln/transformers/__init__.py +37 -1
- optimum/rbln/transformers/models/__init__.py +21 -1
- optimum/rbln/transformers/models/auto/__init__.py +14 -0
- optimum/rbln/transformers/models/auto/auto_factory.py +84 -0
- optimum/rbln/transformers/models/auto/modeling_auto.py +94 -0
- optimum/rbln/transformers/models/bart/__init__.py +1 -0
- optimum/rbln/transformers/models/bart/bart_architecture.py +189 -50
- optimum/rbln/transformers/models/bart/modeling_bart.py +106 -0
- optimum/rbln/transformers/models/bert/__init__.py +24 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +102 -0
- optimum/rbln/transformers/models/clip/__init__.py +1 -1
- optimum/rbln/transformers/models/clip/modeling_clip.py +128 -26
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +32 -7
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +406 -104
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +21 -7
- optimum/rbln/transformers/models/gemma/gemma_architecture.py +10 -3
- optimum/rbln/transformers/models/gemma/modeling_gemma.py +9 -3
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +4 -1
- optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +6 -89
- optimum/rbln/transformers/models/llama/modeling_llama.py +9 -3
- optimum/rbln/transformers/models/llava_next/__init__.py +24 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +666 -0
- optimum/rbln/transformers/models/midm/midm_architecture.py +5 -1
- optimum/rbln/transformers/models/midm/modeling_midm.py +5 -88
- optimum/rbln/transformers/models/mistral/__init__.py +24 -0
- optimum/rbln/transformers/models/mistral/mistral_architecture.py +29 -0
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +68 -0
- optimum/rbln/transformers/models/phi/__init__.py +24 -0
- optimum/rbln/transformers/models/phi/modeling_phi.py +69 -0
- optimum/rbln/transformers/models/phi/phi_architecture.py +406 -0
- optimum/rbln/transformers/models/t5/t5_architecture.py +92 -31
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +18 -12
- optimum/rbln/transformers/models/whisper/generation_whisper.py +68 -0
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +141 -105
- optimum/rbln/transformers/models/whisper/whisper_architecture.py +44 -17
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +25 -16
- optimum/rbln/transformers/utils/__init__.py +0 -0
- optimum/rbln/transformers/utils/rbln_quantization.py +97 -0
- optimum/rbln/utils/import_utils.py +37 -5
- optimum/rbln/utils/logging.py +82 -0
- optimum/rbln/utils/runtime_utils.py +35 -1
- optimum/rbln/utils/timer_utils.py +19 -0
- {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/METADATA +15 -7
- optimum_rbln-0.1.11.dist-info/RECORD +93 -0
- {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/WHEEL +1 -1
- optimum_rbln-0.1.11.dist-info/entry_points.txt +4 -0
- optimum_rbln-0.1.8.dist-info/RECORD +0 -73
- {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/licenses/LICENSE +0 -0
@@ -22,13 +22,13 @@
|
|
22
22
|
# from Rebellions Inc.
|
23
23
|
|
24
24
|
import logging
|
25
|
-
from typing import TYPE_CHECKING, Iterable, Optional, Union
|
25
|
+
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Union
|
26
26
|
|
27
27
|
from transformers import AutoModelForDepthEstimation
|
28
28
|
from transformers.modeling_outputs import DepthEstimatorOutput
|
29
29
|
|
30
30
|
from ....modeling_base import RBLNModel
|
31
|
-
from ....modeling_config import
|
31
|
+
from ....modeling_config import RBLNCompileConfig, RBLNConfig
|
32
32
|
|
33
33
|
|
34
34
|
logger = logging.getLogger(__name__)
|
@@ -47,9 +47,11 @@ class RBLNDPTForDepthEstimation(RBLNModel):
|
|
47
47
|
cls,
|
48
48
|
preprocessors: Optional[Union["AutoFeatureExtractor", "AutoProcessor", "AutoTokenizer"]],
|
49
49
|
model_config: Optional["PretrainedConfig"] = None,
|
50
|
-
|
51
|
-
rbln_batch_size: Optional[int] = None,
|
50
|
+
rbln_kwargs: Dict[str, Any] = {},
|
52
51
|
) -> RBLNConfig:
|
52
|
+
rbln_image_size = rbln_kwargs.get("image_size", None)
|
53
|
+
rbln_batch_size = rbln_kwargs.get("batch_size", None)
|
54
|
+
|
53
55
|
if rbln_batch_size is None:
|
54
56
|
rbln_batch_size = 1
|
55
57
|
|
@@ -79,10 +81,22 @@ class RBLNDPTForDepthEstimation(RBLNModel):
|
|
79
81
|
|
80
82
|
input_info = [("pixel_values", [rbln_batch_size, 3, rbln_image_size[0], rbln_image_size[1]], "float32")]
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
+
rbln_compile_config = RBLNCompileConfig(input_info=input_info)
|
85
|
+
|
86
|
+
rbln_config = RBLNConfig(
|
87
|
+
rbln_cls=cls.__name__,
|
88
|
+
compile_cfgs=[rbln_compile_config],
|
89
|
+
rbln_kwargs=rbln_kwargs,
|
90
|
+
)
|
91
|
+
|
92
|
+
rbln_config.model_cfg.update(
|
93
|
+
{
|
94
|
+
"image_size": rbln_image_size,
|
95
|
+
"batch_size": rbln_batch_size,
|
96
|
+
}
|
97
|
+
)
|
84
98
|
|
85
|
-
return
|
99
|
+
return rbln_config
|
86
100
|
|
87
101
|
def forward(self, *args, **kwargs):
|
88
102
|
predicted_depth = super().forward(*args, **kwargs)
|
@@ -39,9 +39,16 @@ from ...models.decoderonly import (
|
|
39
39
|
class GemmaWrapper(DecoderOnlyWrapper):
|
40
40
|
def get_forward_dict(self):
|
41
41
|
forward_dict = {}
|
42
|
-
forward_dict.update(
|
42
|
+
forward_dict.update(
|
43
|
+
{
|
44
|
+
"wrapper": GemmaModel.forward,
|
45
|
+
"model": DecoderOnlyDecoderLayer.forward,
|
46
|
+
"decoder_layer": DecoderOnlyAttention.forward,
|
47
|
+
}
|
48
|
+
)
|
43
49
|
return forward_dict
|
44
50
|
|
51
|
+
|
45
52
|
class GemmaModel:
|
46
53
|
def forward(
|
47
54
|
self,
|
@@ -54,7 +61,7 @@ class GemmaModel:
|
|
54
61
|
use_cache: Optional[bool] = True,
|
55
62
|
output_attentions: Optional[bool] = False,
|
56
63
|
output_hidden_states: Optional[bool] = False,
|
57
|
-
forward_dict
|
64
|
+
forward_dict: Optional[Dict[str, classmethod]] = None,
|
58
65
|
rotary_pos_emb=None,
|
59
66
|
) -> Union[Tuple, BaseModelOutputWithPast]:
|
60
67
|
# embed positions
|
@@ -89,7 +96,7 @@ class GemmaModel:
|
|
89
96
|
batch_ids=batch_ids,
|
90
97
|
cos=cos,
|
91
98
|
sin=sin,
|
92
|
-
forward_dict=forward_dict
|
99
|
+
forward_dict=forward_dict,
|
93
100
|
)
|
94
101
|
|
95
102
|
hidden_states = layer_outputs[0]
|
@@ -23,14 +23,19 @@
|
|
23
23
|
|
24
24
|
import inspect
|
25
25
|
import logging
|
26
|
-
from typing import Any, Callable
|
26
|
+
from typing import TYPE_CHECKING, Any, Callable
|
27
27
|
|
28
|
-
from transformers import GemmaForCausalLM
|
28
|
+
from transformers import GemmaForCausalLM
|
29
29
|
|
30
30
|
from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
|
31
31
|
from .gemma_architecture import GemmaWrapper
|
32
32
|
|
33
33
|
|
34
|
+
if TYPE_CHECKING:
|
35
|
+
from transformers import PreTrainedModel
|
36
|
+
|
37
|
+
from ....modeling_config import RBLNConfig
|
38
|
+
|
34
39
|
logger = logging.getLogger(__name__)
|
35
40
|
|
36
41
|
|
@@ -46,7 +51,8 @@ class RBLNGemmaForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
46
51
|
"""
|
47
52
|
|
48
53
|
@classmethod
|
49
|
-
def
|
54
|
+
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
55
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
50
56
|
return GemmaWrapper(model, rbln_max_seq_len).eval()
|
51
57
|
|
52
58
|
def __getattr__(self, __name: str) -> Any:
|
@@ -53,6 +53,7 @@ class GPT2LMHeadModelWrapper(torch.nn.Module):
|
|
53
53
|
attention_mask,
|
54
54
|
cache_position,
|
55
55
|
batch_position,
|
56
|
+
query_idx,
|
56
57
|
*past_key_values,
|
57
58
|
):
|
58
59
|
if input_ids.shape[1] == 1:
|
@@ -79,11 +80,13 @@ class GPT2LMHeadModelWrapper(torch.nn.Module):
|
|
79
80
|
)
|
80
81
|
|
81
82
|
hidden_states = outputs[0]
|
83
|
+
if batch_position >= 0:
|
84
|
+
hidden_states = hidden_states[:, query_idx].unsqueeze(1)
|
82
85
|
logits = self.lm_head(hidden_states)
|
83
86
|
|
84
87
|
output = (logits,) + outputs[1:]
|
85
88
|
|
86
|
-
return output, batch_position
|
89
|
+
return output, batch_position + query_idx
|
87
90
|
|
88
91
|
|
89
92
|
class _GPT2Model:
|
@@ -23,23 +23,18 @@
|
|
23
23
|
|
24
24
|
import inspect
|
25
25
|
import logging
|
26
|
-
from typing import TYPE_CHECKING, Any, Callable
|
26
|
+
from typing import TYPE_CHECKING, Any, Callable
|
27
27
|
|
28
|
-
from transformers import GPT2LMHeadModel
|
28
|
+
from transformers import GPT2LMHeadModel
|
29
29
|
|
30
|
-
from ....modeling_config import RBLNConfig
|
30
|
+
from ....modeling_config import RBLNConfig
|
31
31
|
from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
|
32
32
|
from .gpt2_architecture import GPT2LMHeadModelWrapper
|
33
33
|
|
34
34
|
|
35
35
|
logger = logging.getLogger(__name__)
|
36
36
|
if TYPE_CHECKING:
|
37
|
-
from transformers import
|
38
|
-
AutoFeatureExtractor,
|
39
|
-
AutoProcessor,
|
40
|
-
AutoTokenizer,
|
41
|
-
PretrainedConfig,
|
42
|
-
)
|
37
|
+
from transformers import PreTrainedModel
|
43
38
|
|
44
39
|
|
45
40
|
class RBLNGPT2LMHeadModel(RBLNDecoderOnlyModelForCausalLM):
|
@@ -57,7 +52,8 @@ class RBLNGPT2LMHeadModel(RBLNDecoderOnlyModelForCausalLM):
|
|
57
52
|
"""
|
58
53
|
|
59
54
|
@classmethod
|
60
|
-
def
|
55
|
+
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
56
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
61
57
|
return GPT2LMHeadModelWrapper(model, rbln_max_seq_len).eval()
|
62
58
|
|
63
59
|
def __getattr__(self, __name: str) -> Any:
|
@@ -74,82 +70,3 @@ class RBLNGPT2LMHeadModel(RBLNDecoderOnlyModelForCausalLM):
|
|
74
70
|
if isinstance(val, Callable) and "self" in set(inspect.signature(val).parameters):
|
75
71
|
return redirect(val)
|
76
72
|
return val
|
77
|
-
|
78
|
-
@classmethod
|
79
|
-
def _get_rbln_config(
|
80
|
-
cls,
|
81
|
-
preprocessors: Union["AutoFeatureExtractor", "AutoProcessor", "AutoTokenizer"],
|
82
|
-
model_config: "PretrainedConfig",
|
83
|
-
rbln_max_seq_len: Optional[int] = None,
|
84
|
-
rbln_batch_size: Optional[int] = None,
|
85
|
-
**kwargs,
|
86
|
-
) -> RBLNConfig:
|
87
|
-
meta = {}
|
88
|
-
|
89
|
-
prefill_chunk_size = 128
|
90
|
-
if rbln_max_seq_len is None: # differenct from llama
|
91
|
-
rbln_max_seq_len = getattr(model_config, "n_positions", None)
|
92
|
-
rbln_batch_size = 1 if rbln_batch_size is None else rbln_batch_size
|
93
|
-
|
94
|
-
meta["rbln_max_seq_len"] = rbln_max_seq_len
|
95
|
-
meta["rbln_batch_size"] = rbln_batch_size
|
96
|
-
meta["rbln_prefill_chunk_size"] = prefill_chunk_size
|
97
|
-
|
98
|
-
def get_input_info(
|
99
|
-
batch_size,
|
100
|
-
query_length,
|
101
|
-
):
|
102
|
-
head_dim = (
|
103
|
-
model_config.head_dim
|
104
|
-
if hasattr(model_config, "head_dim")
|
105
|
-
else model_config.hidden_size // model_config.n_head
|
106
|
-
)
|
107
|
-
input_info = [
|
108
|
-
("input_ids", [batch_size, query_length], "int64"),
|
109
|
-
("attention_mask", [batch_size, 1, query_length, rbln_max_seq_len], "int64"),
|
110
|
-
(
|
111
|
-
"cache_position",
|
112
|
-
[batch_size, query_length],
|
113
|
-
"int32",
|
114
|
-
),
|
115
|
-
("batch_position", [], "int16"),
|
116
|
-
]
|
117
|
-
|
118
|
-
input_info.extend(
|
119
|
-
[
|
120
|
-
(
|
121
|
-
f"past_key_values_{i}",
|
122
|
-
[
|
123
|
-
rbln_batch_size,
|
124
|
-
model_config.n_head, # differenct from llama
|
125
|
-
rbln_max_seq_len,
|
126
|
-
head_dim,
|
127
|
-
],
|
128
|
-
"float32",
|
129
|
-
)
|
130
|
-
for i in range(model_config.n_layer * 2) # differenct from llama
|
131
|
-
]
|
132
|
-
)
|
133
|
-
|
134
|
-
return input_info
|
135
|
-
|
136
|
-
prefill_input_info = get_input_info(
|
137
|
-
batch_size=1,
|
138
|
-
query_length=prefill_chunk_size,
|
139
|
-
)
|
140
|
-
dec_input_info = get_input_info(
|
141
|
-
batch_size=rbln_batch_size,
|
142
|
-
query_length=1,
|
143
|
-
)
|
144
|
-
|
145
|
-
prefill_rbln_runtime_config = RBLNRuntimeConfig(input_info=prefill_input_info)
|
146
|
-
dec_rbln_runtime_config = RBLNRuntimeConfig(input_info=dec_input_info)
|
147
|
-
|
148
|
-
dec_rbln_runtime_config.batch_size = rbln_batch_size
|
149
|
-
|
150
|
-
rbln_config = RBLNConfig.from_rbln_runtime_configs(
|
151
|
-
[prefill_rbln_runtime_config, dec_rbln_runtime_config],
|
152
|
-
_rbln_meta=meta,
|
153
|
-
)
|
154
|
-
|
155
|
-
return rbln_config
|
@@ -23,14 +23,19 @@
|
|
23
23
|
|
24
24
|
import inspect
|
25
25
|
import logging
|
26
|
-
from typing import Any, Callable
|
26
|
+
from typing import TYPE_CHECKING, Any, Callable
|
27
27
|
|
28
|
-
from transformers import LlamaForCausalLM
|
28
|
+
from transformers import LlamaForCausalLM
|
29
29
|
|
30
30
|
from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
|
31
31
|
from .llama_architecture import LlamaWrapper
|
32
32
|
|
33
33
|
|
34
|
+
if TYPE_CHECKING:
|
35
|
+
from transformers import PreTrainedModel
|
36
|
+
|
37
|
+
from ....modeling_config import RBLNConfig
|
38
|
+
|
34
39
|
logger = logging.getLogger(__name__)
|
35
40
|
|
36
41
|
|
@@ -46,7 +51,8 @@ class RBLNLlamaForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
46
51
|
"""
|
47
52
|
|
48
53
|
@classmethod
|
49
|
-
def
|
54
|
+
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
55
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
50
56
|
return LlamaWrapper(model, rbln_max_seq_len).eval()
|
51
57
|
|
52
58
|
def __getattr__(self, __name: str) -> Any:
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright 2024 Rebellions Inc.
|
2
|
+
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at:
|
6
|
+
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# Portions of this software are licensed under the Apache License,
|
16
|
+
# Version 2.0. See the NOTICE file distributed with this work for
|
17
|
+
# additional information regarding copyright ownership.
|
18
|
+
|
19
|
+
# All other portions of this software, including proprietary code,
|
20
|
+
# are the intellectual property of Rebellions Inc. and may not be
|
21
|
+
# copied, modified, or distributed without prior written permission
|
22
|
+
# from Rebellions Inc.
|
23
|
+
|
24
|
+
from .modeling_llava_next import RBLNLlavaNextForConditionalGeneration
|