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.
Files changed (66) hide show
  1. optimum/rbln/__init__.py +40 -2
  2. optimum/rbln/__version__.py +1 -1
  3. optimum/rbln/diffusers/models/autoencoder_kl.py +39 -32
  4. optimum/rbln/diffusers/models/controlnet.py +60 -43
  5. optimum/rbln/diffusers/models/unet_2d_condition.py +43 -31
  6. optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +2 -3
  7. optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +22 -15
  8. optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +22 -15
  9. optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +23 -17
  10. optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +24 -18
  11. optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +22 -11
  12. optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +22 -11
  13. optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +24 -14
  14. optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +24 -14
  15. optimum/rbln/modeling_alias.py +8 -4
  16. optimum/rbln/modeling_base.py +512 -238
  17. optimum/rbln/modeling_config.py +152 -77
  18. optimum/rbln/modeling_seq2seq.py +166 -77
  19. optimum/rbln/transformers/__init__.py +37 -1
  20. optimum/rbln/transformers/models/__init__.py +21 -1
  21. optimum/rbln/transformers/models/auto/__init__.py +14 -0
  22. optimum/rbln/transformers/models/auto/auto_factory.py +84 -0
  23. optimum/rbln/transformers/models/auto/modeling_auto.py +94 -0
  24. optimum/rbln/transformers/models/bart/__init__.py +1 -0
  25. optimum/rbln/transformers/models/bart/bart_architecture.py +189 -50
  26. optimum/rbln/transformers/models/bart/modeling_bart.py +106 -0
  27. optimum/rbln/transformers/models/bert/__init__.py +24 -0
  28. optimum/rbln/transformers/models/bert/modeling_bert.py +102 -0
  29. optimum/rbln/transformers/models/clip/__init__.py +1 -1
  30. optimum/rbln/transformers/models/clip/modeling_clip.py +128 -26
  31. optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +32 -7
  32. optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +406 -104
  33. optimum/rbln/transformers/models/dpt/modeling_dpt.py +21 -7
  34. optimum/rbln/transformers/models/gemma/gemma_architecture.py +10 -3
  35. optimum/rbln/transformers/models/gemma/modeling_gemma.py +9 -3
  36. optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +4 -1
  37. optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +6 -89
  38. optimum/rbln/transformers/models/llama/modeling_llama.py +9 -3
  39. optimum/rbln/transformers/models/llava_next/__init__.py +24 -0
  40. optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +666 -0
  41. optimum/rbln/transformers/models/midm/midm_architecture.py +5 -1
  42. optimum/rbln/transformers/models/midm/modeling_midm.py +5 -88
  43. optimum/rbln/transformers/models/mistral/__init__.py +24 -0
  44. optimum/rbln/transformers/models/mistral/mistral_architecture.py +29 -0
  45. optimum/rbln/transformers/models/mistral/modeling_mistral.py +68 -0
  46. optimum/rbln/transformers/models/phi/__init__.py +24 -0
  47. optimum/rbln/transformers/models/phi/modeling_phi.py +69 -0
  48. optimum/rbln/transformers/models/phi/phi_architecture.py +406 -0
  49. optimum/rbln/transformers/models/t5/t5_architecture.py +92 -31
  50. optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +18 -12
  51. optimum/rbln/transformers/models/whisper/generation_whisper.py +68 -0
  52. optimum/rbln/transformers/models/whisper/modeling_whisper.py +141 -105
  53. optimum/rbln/transformers/models/whisper/whisper_architecture.py +44 -17
  54. optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +25 -16
  55. optimum/rbln/transformers/utils/__init__.py +0 -0
  56. optimum/rbln/transformers/utils/rbln_quantization.py +97 -0
  57. optimum/rbln/utils/import_utils.py +37 -5
  58. optimum/rbln/utils/logging.py +82 -0
  59. optimum/rbln/utils/runtime_utils.py +35 -1
  60. optimum/rbln/utils/timer_utils.py +19 -0
  61. {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/METADATA +15 -7
  62. optimum_rbln-0.1.11.dist-info/RECORD +93 -0
  63. {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/WHEEL +1 -1
  64. optimum_rbln-0.1.11.dist-info/entry_points.txt +4 -0
  65. optimum_rbln-0.1.8.dist-info/RECORD +0 -73
  66. {optimum_rbln-0.1.8.dist-info → optimum_rbln-0.1.11.dist-info}/licenses/LICENSE +0 -0
@@ -23,11 +23,9 @@
23
23
 
24
24
  import inspect
25
25
  import logging
26
- from typing import TYPE_CHECKING, Any, Callable, Optional, Union
26
+ from typing import TYPE_CHECKING, Any, Callable
27
27
 
28
- from transformers import PretrainedConfig, PreTrainedModel
29
-
30
- from ....modeling_config import RBLNConfig, RBLNRuntimeConfig
28
+ from ....modeling_config import RBLNConfig
31
29
  from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
32
30
  from .hf_hub_cached.modeling_midm import MidmLMHeadModel
33
31
  from .midm_architecture import (
@@ -38,10 +36,7 @@ from .midm_architecture import (
38
36
  logger = logging.getLogger(__name__)
39
37
  if TYPE_CHECKING:
40
38
  from transformers import (
41
- AutoFeatureExtractor,
42
- AutoProcessor,
43
- AutoTokenizer,
44
- PretrainedConfig,
39
+ PreTrainedModel,
45
40
  )
46
41
 
47
42
 
@@ -60,7 +55,8 @@ class RBLNMidmLMHeadModel(RBLNDecoderOnlyModelForCausalLM):
60
55
  """
61
56
 
62
57
  @classmethod
63
- def wrapping_torch_model(self, model: "PreTrainedModel", rbln_max_seq_len: int):
58
+ def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
59
+ rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
64
60
  return MidmLMHeadModelWrapper(model, rbln_max_seq_len).eval()
65
61
 
66
62
  def __getattr__(self, __name: str) -> Any:
@@ -77,82 +73,3 @@ class RBLNMidmLMHeadModel(RBLNDecoderOnlyModelForCausalLM):
77
73
  if isinstance(val, Callable) and "self" in set(inspect.signature(val).parameters):
78
74
  return redirect(val)
79
75
  return val
80
-
81
- @classmethod
82
- def _get_rbln_config(
83
- cls,
84
- preprocessors: Union["AutoFeatureExtractor", "AutoProcessor", "AutoTokenizer"],
85
- model_config: "PretrainedConfig",
86
- rbln_max_seq_len: Optional[int] = None,
87
- rbln_batch_size: Optional[int] = None,
88
- **kwargs,
89
- ) -> RBLNConfig:
90
- meta = {}
91
-
92
- prefill_chunk_size = 128
93
- if rbln_max_seq_len is None:
94
- rbln_max_seq_len = getattr(model_config, "n_positions", None)
95
- rbln_batch_size = 1 if rbln_batch_size is None else rbln_batch_size
96
-
97
- meta["rbln_max_seq_len"] = rbln_max_seq_len
98
- meta["rbln_batch_size"] = rbln_batch_size
99
- meta["rbln_prefill_chunk_size"] = prefill_chunk_size
100
-
101
- def get_input_info(
102
- batch_size,
103
- query_length,
104
- ):
105
- head_dim = (
106
- model_config.head_dim
107
- if hasattr(model_config, "head_dim")
108
- else model_config.hidden_size // model_config.n_head
109
- )
110
- input_info = [
111
- ("input_ids", [batch_size, query_length], "int64"),
112
- ("attention_mask", [batch_size, 1, query_length, rbln_max_seq_len], "int64"),
113
- (
114
- "cache_position",
115
- [batch_size, query_length],
116
- "int32",
117
- ),
118
- ("batch_position", [], "int16"),
119
- ]
120
-
121
- input_info.extend(
122
- [
123
- (
124
- f"past_key_values_{i}",
125
- [
126
- rbln_batch_size,
127
- model_config.n_head,
128
- rbln_max_seq_len,
129
- head_dim,
130
- ],
131
- "float32",
132
- )
133
- for i in range(model_config.n_layer * 2)
134
- ]
135
- )
136
-
137
- return input_info
138
-
139
- prefill_input_info = get_input_info(
140
- batch_size=1,
141
- query_length=prefill_chunk_size,
142
- )
143
- dec_input_info = get_input_info(
144
- batch_size=rbln_batch_size,
145
- query_length=1,
146
- )
147
-
148
- prefill_rbln_runtime_config = RBLNRuntimeConfig(input_info=prefill_input_info)
149
- dec_rbln_runtime_config = RBLNRuntimeConfig(input_info=dec_input_info)
150
-
151
- dec_rbln_runtime_config.batch_size = rbln_batch_size
152
-
153
- rbln_config = RBLNConfig.from_rbln_runtime_configs(
154
- [prefill_rbln_runtime_config, dec_rbln_runtime_config],
155
- _rbln_meta=meta,
156
- )
157
-
158
- return rbln_config
@@ -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_mistral import RBLNMistralForCausalLM
@@ -0,0 +1,29 @@
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
+
25
+ from ..decoderonly.decoderonly_architecture import DecoderOnlyWrapper
26
+
27
+
28
+ class MistralForCausalLMWrapper(DecoderOnlyWrapper):
29
+ pass
@@ -0,0 +1,68 @@
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
+ import inspect
25
+ import logging
26
+ from typing import TYPE_CHECKING, Any, Callable
27
+
28
+ from transformers import MistralForCausalLM
29
+
30
+ from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
31
+ from .mistral_architecture import MistralForCausalLMWrapper
32
+
33
+
34
+ if TYPE_CHECKING:
35
+ from transformers import PreTrainedModel
36
+
37
+ from ....modeling_config import RBLNConfig
38
+
39
+
40
+ logger = logging.getLogger(__name__)
41
+
42
+
43
+ class RBLNMistralForCausalLM(RBLNDecoderOnlyModelForCausalLM):
44
+ """
45
+ The Llama Model transformer with a language modeling head (linear layer) on top.
46
+ This model inherits from [`RBLNMultiModel`]. Check the superclass documentation for the generic methods the library implements for all its models.
47
+
48
+ A class to convert and run pre-trained transformers based LlamaForCausalLM model on RBLN devices.
49
+ It implements the methods to convert a pre-trained transformers LlamaForCausalLM model into a RBLN transformer model by:
50
+ - transferring the checkpoint weights of the original into an optimized RBLN graph,
51
+ - compiling the resulting graph using the RBLN compiler.
52
+ """
53
+
54
+ @classmethod
55
+ def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
56
+ rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
57
+ return MistralForCausalLMWrapper(model, rbln_max_seq_len).eval()
58
+
59
+ def __getattr__(self, __name: str) -> Any:
60
+ def redirect(func):
61
+ return lambda *pargs, **kwargs: func(self, *pargs, **kwargs)
62
+
63
+ val = getattr(MistralForCausalLM, __name)
64
+
65
+ if isinstance(val, Callable) and "self" in set(inspect.signature(val).parameters):
66
+ return redirect(val)
67
+
68
+ return val
@@ -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_phi import RBLNPhiForCausalLM
@@ -0,0 +1,69 @@
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
+ import inspect
25
+ import logging
26
+ from typing import TYPE_CHECKING, Any, Callable
27
+
28
+ from transformers import PhiForCausalLM
29
+
30
+ from ..decoderonly import RBLNDecoderOnlyModelForCausalLM
31
+ from .phi_architecture import PhiWrapper
32
+
33
+
34
+ if TYPE_CHECKING:
35
+ from transformers import PreTrainedModel
36
+
37
+ from ....modeling_config import RBLNConfig
38
+
39
+ logger = logging.getLogger(__name__)
40
+
41
+
42
+ class RBLNPhiForCausalLM(RBLNDecoderOnlyModelForCausalLM):
43
+ """
44
+ The Phi Model transformer with a language modeling head (linear layer) on top.
45
+ This model inherits from [`RBLNMultiModel`]. Check the superclass documentation for the generic methods the library implements for all its models.
46
+
47
+ A class to convert and run pre-trained transformers based PhiForCausalLM model on RBLN devices.
48
+ It implements the methods to convert a pre-trained transformers PhiForCausalLM model into a RBLN transformer model by:
49
+ - transferring the checkpoint weights of the original into an optimized RBLN graph,
50
+ - compiling the resulting graph using the RBLN compiler.
51
+ """
52
+
53
+ @classmethod
54
+ def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
55
+ rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
56
+ return PhiWrapper(model, rbln_max_seq_len).eval()
57
+
58
+ def __getattr__(self, __name: str) -> Any:
59
+ def redirect(func):
60
+ return lambda *pargs, **kwargs: func(self, *pargs, **kwargs)
61
+
62
+ val = getattr(PhiForCausalLM, __name)
63
+
64
+ if isinstance(val, Callable) and "self" in set(
65
+ inspect.signature(val).parameters
66
+ ):
67
+ return redirect(val)
68
+
69
+ return val