optimum-rbln 0.1.9__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 +47 -9
- optimum/rbln/__version__.py +1 -1
- optimum/rbln/diffusers/models/autoencoder_kl.py +36 -31
- optimum/rbln/diffusers/models/controlnet.py +53 -43
- optimum/rbln/diffusers/models/unet_2d_condition.py +40 -31
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +4 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +28 -23
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +28 -23
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +28 -37
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +30 -39
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +24 -14
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +24 -15
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +26 -17
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +26 -17
- optimum/rbln/modeling_alias.py +6 -11
- optimum/rbln/modeling_base.py +467 -261
- optimum/rbln/modeling_config.py +199 -73
- optimum/rbln/transformers/__init__.py +43 -1
- optimum/rbln/transformers/models/__init__.py +23 -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 +95 -0
- optimum/rbln/transformers/models/bart/__init__.py +1 -0
- optimum/rbln/transformers/models/bart/bart_architecture.py +203 -58
- optimum/rbln/transformers/models/bart/modeling_bart.py +125 -0
- optimum/rbln/transformers/models/bert/__init__.py +24 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +101 -0
- optimum/rbln/transformers/models/clip/__init__.py +1 -1
- optimum/rbln/transformers/models/clip/modeling_clip.py +127 -26
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +28 -4
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +409 -150
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +21 -8
- 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/gemma/modeling_gemma.py +1 -1
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +4 -1
- optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +1 -1
- optimum/rbln/transformers/models/llama/modeling_llama.py +1 -1
- optimum/rbln/transformers/models/llava_next/__init__.py +24 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +662 -0
- optimum/rbln/transformers/models/midm/midm_architecture.py +5 -1
- optimum/rbln/transformers/models/midm/modeling_midm.py +6 -1
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +1 -1
- 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/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} +198 -168
- 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 +122 -47
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +17 -12
- optimum/rbln/transformers/models/whisper/generation_whisper.py +68 -0
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +172 -111
- optimum/rbln/transformers/models/whisper/whisper_architecture.py +44 -17
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +18 -16
- optimum/rbln/transformers/utils/rbln_quantization.py +48 -60
- optimum/rbln/utils/import_utils.py +50 -1
- optimum/rbln/utils/logging.py +82 -0
- optimum/rbln/utils/runtime_utils.py +33 -0
- optimum/rbln/utils/timer_utils.py +43 -0
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.12.dist-info}/METADATA +9 -7
- optimum_rbln-0.1.12.dist-info/RECORD +103 -0
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.12.dist-info}/WHEEL +1 -1
- optimum_rbln-0.1.12.dist-info/entry_points.txt +4 -0
- optimum_rbln-0.1.9.dist-info/RECORD +0 -78
- {optimum_rbln-0.1.9.dist-info → optimum_rbln-0.1.12.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,78 @@
|
|
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 ....modeling_config import RBLNConfig
|
29
|
+
from ..decoderonly import RBLNDecoderOnlyModelForCausalLM
|
30
|
+
from .exaone_architecture import ExaoneForCausalLMWrapper
|
31
|
+
from .hf_hub_cached.modeling_exaone import ExaoneForCausalLM
|
32
|
+
|
33
|
+
|
34
|
+
logger = logging.getLogger(__name__)
|
35
|
+
if TYPE_CHECKING:
|
36
|
+
from transformers import (
|
37
|
+
PreTrainedModel,
|
38
|
+
)
|
39
|
+
|
40
|
+
|
41
|
+
class RBLNExaoneForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
42
|
+
"""
|
43
|
+
The Exaone Model transformer with a language modeling head on top (linear layer with weights tied to the input
|
44
|
+
embeddings).
|
45
|
+
|
46
|
+
This model inherits from [`RBLNDecoderOnlyModelForCausalLM`]. Check the superclass documentation for the generic methods the
|
47
|
+
library implements for all its model.
|
48
|
+
|
49
|
+
It implements the methods to convert a pre-trained transformers Exaone 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
|
+
|
55
|
+
@classmethod
|
56
|
+
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
57
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
58
|
+
return ExaoneForCausalLMWrapper(model, rbln_max_seq_len).eval()
|
59
|
+
|
60
|
+
def __getattr__(self, __name: str) -> Any:
|
61
|
+
"""This is the key method to implement RBLN-Exaone.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
Any: Exaone's corresponding method
|
65
|
+
"""
|
66
|
+
|
67
|
+
def redirect(func):
|
68
|
+
return lambda *pargs, **kwargs: func(self, *pargs, **kwargs)
|
69
|
+
|
70
|
+
val = getattr(ExaoneForCausalLM, __name)
|
71
|
+
if isinstance(val, Callable) and "self" in set(inspect.signature(val).parameters):
|
72
|
+
return redirect(val)
|
73
|
+
return val
|
74
|
+
|
75
|
+
@classmethod
|
76
|
+
def from_pretrained(cls, *args, **kwargs):
|
77
|
+
kwargs.setdefault("trust_remote_code", True)
|
78
|
+
return super().from_pretrained(*args, **kwargs)
|
@@ -52,7 +52,7 @@ class RBLNGemmaForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
52
52
|
|
53
53
|
@classmethod
|
54
54
|
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
55
|
-
rbln_max_seq_len = rbln_config.
|
55
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
56
56
|
return GemmaWrapper(model, rbln_max_seq_len).eval()
|
57
57
|
|
58
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:
|
@@ -53,7 +53,7 @@ class RBLNGPT2LMHeadModel(RBLNDecoderOnlyModelForCausalLM):
|
|
53
53
|
|
54
54
|
@classmethod
|
55
55
|
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
56
|
-
rbln_max_seq_len = rbln_config.
|
56
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
57
57
|
return GPT2LMHeadModelWrapper(model, rbln_max_seq_len).eval()
|
58
58
|
|
59
59
|
def __getattr__(self, __name: str) -> Any:
|
@@ -52,7 +52,7 @@ class RBLNLlamaForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
52
52
|
|
53
53
|
@classmethod
|
54
54
|
def wrap_model_if_needed(self, model: "PreTrainedModel", rbln_config: "RBLNConfig"):
|
55
|
-
rbln_max_seq_len = rbln_config.
|
55
|
+
rbln_max_seq_len = rbln_config.model_cfg["max_seq_len"]
|
56
56
|
return LlamaWrapper(model, rbln_max_seq_len).eval()
|
57
57
|
|
58
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
|