optimum-rbln 0.7.4a4__py3-none-any.whl → 0.7.4a6__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 +164 -36
- optimum/rbln/__version__.py +2 -2
- optimum/rbln/configuration_utils.py +772 -0
- optimum/rbln/diffusers/__init__.py +56 -0
- optimum/rbln/diffusers/configurations/__init__.py +30 -0
- optimum/rbln/diffusers/configurations/models/__init__.py +6 -0
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py +66 -0
- optimum/rbln/diffusers/configurations/models/configuration_controlnet.py +54 -0
- optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py +44 -0
- optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py +48 -0
- optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py +66 -0
- optimum/rbln/diffusers/configurations/models/configuration_vq_model.py +67 -0
- optimum/rbln/diffusers/configurations/pipelines/__init__.py +30 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py +221 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_kandinsky2_2.py +285 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion.py +118 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_3.py +143 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_xl.py +124 -0
- optimum/rbln/diffusers/modeling_diffusers.py +63 -122
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl.py +109 -128
- optimum/rbln/diffusers/models/autoencoders/vae.py +4 -6
- optimum/rbln/diffusers/models/autoencoders/vq_model.py +84 -85
- optimum/rbln/diffusers/models/controlnet.py +55 -70
- optimum/rbln/diffusers/models/transformers/prior_transformer.py +40 -77
- optimum/rbln/diffusers/models/transformers/transformer_sd3.py +43 -68
- optimum/rbln/diffusers/models/unets/unet_2d_condition.py +110 -113
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +3 -4
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +2 -1
- optimum/rbln/modeling.py +58 -39
- optimum/rbln/modeling_base.py +107 -78
- optimum/rbln/transformers/__init__.py +87 -8
- optimum/rbln/transformers/configuration_alias.py +49 -0
- optimum/rbln/transformers/configuration_generic.py +142 -0
- optimum/rbln/transformers/modeling_generic.py +193 -280
- optimum/rbln/transformers/models/__init__.py +108 -34
- optimum/rbln/transformers/models/auto/auto_factory.py +3 -3
- optimum/rbln/transformers/models/bart/__init__.py +1 -0
- optimum/rbln/transformers/models/bart/configuration_bart.py +24 -0
- optimum/rbln/transformers/models/bart/modeling_bart.py +10 -84
- optimum/rbln/transformers/models/bert/__init__.py +1 -0
- optimum/rbln/transformers/models/bert/configuration_bert.py +31 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +7 -80
- optimum/rbln/transformers/models/clip/__init__.py +6 -0
- optimum/rbln/transformers/models/clip/configuration_clip.py +79 -0
- optimum/rbln/transformers/models/clip/modeling_clip.py +72 -75
- optimum/rbln/transformers/models/decoderonly/__init__.py +1 -0
- optimum/rbln/transformers/models/decoderonly/configuration_decoderonly.py +90 -0
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +115 -84
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +282 -216
- optimum/rbln/transformers/models/dpt/__init__.py +1 -0
- optimum/rbln/transformers/models/dpt/configuration_dpt.py +19 -0
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +3 -76
- optimum/rbln/transformers/models/exaone/__init__.py +1 -0
- optimum/rbln/transformers/models/exaone/configuration_exaone.py +19 -0
- optimum/rbln/transformers/models/gemma/__init__.py +1 -0
- optimum/rbln/transformers/models/gemma/configuration_gemma.py +19 -0
- optimum/rbln/transformers/models/gpt2/__init__.py +1 -0
- optimum/rbln/transformers/models/gpt2/configuration_gpt2.py +19 -0
- optimum/rbln/transformers/models/llama/__init__.py +1 -0
- optimum/rbln/transformers/models/llama/configuration_llama.py +19 -0
- optimum/rbln/transformers/models/llava_next/__init__.py +1 -0
- optimum/rbln/transformers/models/llava_next/configuration_llava_next.py +46 -0
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +12 -23
- optimum/rbln/transformers/models/midm/__init__.py +1 -0
- optimum/rbln/transformers/models/midm/configuration_midm.py +19 -0
- optimum/rbln/transformers/models/mistral/__init__.py +1 -0
- optimum/rbln/transformers/models/mistral/configuration_mistral.py +19 -0
- optimum/rbln/transformers/models/phi/__init__.py +1 -0
- optimum/rbln/transformers/models/phi/configuration_phi.py +19 -0
- optimum/rbln/transformers/models/qwen2/__init__.py +1 -0
- optimum/rbln/transformers/models/qwen2/configuration_qwen2.py +19 -0
- optimum/rbln/transformers/models/qwen2_5_vl/__init__.py +19 -0
- optimum/rbln/transformers/models/qwen2_5_vl/configuration_qwen2_5_vl.py +68 -0
- optimum/rbln/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py +608 -0
- optimum/rbln/transformers/models/qwen2_5_vl/qwen2_5_vl_architecture.py +214 -0
- optimum/rbln/transformers/models/seq2seq/__init__.py +1 -0
- optimum/rbln/transformers/models/seq2seq/configuration_seq2seq2.py +66 -0
- optimum/rbln/transformers/models/seq2seq/modeling_seq2seq.py +80 -97
- optimum/rbln/transformers/models/t5/__init__.py +1 -0
- optimum/rbln/transformers/models/t5/configuration_t5.py +24 -0
- optimum/rbln/transformers/models/t5/modeling_t5.py +22 -150
- optimum/rbln/transformers/models/time_series_transformers/__init__.py +1 -0
- optimum/rbln/transformers/models/time_series_transformers/configuration_time_series_transformer.py +34 -0
- optimum/rbln/transformers/models/time_series_transformers/modeling_time_series_transformers.py +52 -54
- optimum/rbln/transformers/models/wav2vec2/__init__.py +1 -0
- optimum/rbln/transformers/models/wav2vec2/configuration_wav2vec.py +19 -0
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +9 -72
- optimum/rbln/transformers/models/whisper/__init__.py +1 -0
- optimum/rbln/transformers/models/whisper/configuration_whisper.py +64 -0
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +57 -72
- optimum/rbln/transformers/models/xlm_roberta/__init__.py +1 -0
- optimum/rbln/transformers/models/xlm_roberta/configuration_xlm_roberta.py +19 -0
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +3 -83
- optimum/rbln/utils/runtime_utils.py +33 -2
- optimum/rbln/utils/submodule.py +26 -43
- {optimum_rbln-0.7.4a4.dist-info → optimum_rbln-0.7.4a6.dist-info}/METADATA +1 -1
- optimum_rbln-0.7.4a6.dist-info/RECORD +166 -0
- optimum/rbln/modeling_config.py +0 -310
- optimum_rbln-0.7.4a4.dist-info/RECORD +0 -126
- {optimum_rbln-0.7.4a4.dist-info → optimum_rbln-0.7.4a6.dist-info}/WHEEL +0 -0
- {optimum_rbln-0.7.4a4.dist-info → optimum_rbln-0.7.4a6.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ...configuration_generic import RBLNModelForDepthEstimationConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNDPTForDepthEstimationConfig(RBLNModelForDepthEstimationConfig):
|
19
|
+
pass
|
@@ -12,82 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Union
|
16
15
|
|
17
|
-
from
|
18
|
-
from transformers.modeling_outputs import DepthEstimatorOutput
|
16
|
+
from ...modeling_generic import RBLNModelForDepthEstimation
|
19
17
|
|
20
|
-
from ....modeling import RBLNModel
|
21
|
-
from ....modeling_config import RBLNCompileConfig, RBLNConfig
|
22
|
-
from ....utils.logging import get_logger
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if TYPE_CHECKING:
|
28
|
-
from transformers import AutoFeatureExtractor, AutoProcessor, AutoTokenizer, PretrainedConfig
|
29
|
-
|
30
|
-
|
31
|
-
class RBLNDPTForDepthEstimation(RBLNModel):
|
32
|
-
auto_model_class = AutoModelForDepthEstimation
|
33
|
-
main_input_name = "pixel_values"
|
34
|
-
|
35
|
-
@classmethod
|
36
|
-
def _get_rbln_config(
|
37
|
-
cls,
|
38
|
-
preprocessors: Optional[Union["AutoFeatureExtractor", "AutoProcessor", "AutoTokenizer"]],
|
39
|
-
model_config: Optional["PretrainedConfig"] = None,
|
40
|
-
rbln_kwargs: Dict[str, Any] = {},
|
41
|
-
) -> RBLNConfig:
|
42
|
-
rbln_image_size = rbln_kwargs.get("image_size", None)
|
43
|
-
rbln_batch_size = rbln_kwargs.get("batch_size", None)
|
44
|
-
|
45
|
-
if rbln_batch_size is None:
|
46
|
-
rbln_batch_size = 1
|
47
|
-
|
48
|
-
if rbln_image_size is None:
|
49
|
-
for processor in preprocessors:
|
50
|
-
image_size = getattr(processor, "size", None)
|
51
|
-
|
52
|
-
if image_size is not None:
|
53
|
-
if isinstance(image_size, Iterable):
|
54
|
-
if "shortest_edge" in image_size:
|
55
|
-
rbln_image_size = image_size["shortest_edge"]
|
56
|
-
break
|
57
|
-
elif "height" in image_size and "width" in image_size:
|
58
|
-
rbln_image_size = image_size["height"], image_size["width"]
|
59
|
-
break
|
60
|
-
else:
|
61
|
-
rbln_image_size = image_size
|
62
|
-
|
63
|
-
if rbln_image_size is None:
|
64
|
-
rbln_image_size = getattr(model_config, "image_size", None)
|
65
|
-
|
66
|
-
if rbln_image_size is None:
|
67
|
-
raise ValueError("`rbln_image_size` should be specified!")
|
68
|
-
|
69
|
-
if isinstance(rbln_image_size, int):
|
70
|
-
rbln_image_size = rbln_image_size, rbln_image_size
|
71
|
-
|
72
|
-
input_info = [("pixel_values", [rbln_batch_size, 3, rbln_image_size[0], rbln_image_size[1]], "float32")]
|
73
|
-
|
74
|
-
rbln_compile_config = RBLNCompileConfig(input_info=input_info)
|
75
|
-
|
76
|
-
rbln_config = RBLNConfig(
|
77
|
-
rbln_cls=cls.__name__,
|
78
|
-
compile_cfgs=[rbln_compile_config],
|
79
|
-
rbln_kwargs=rbln_kwargs,
|
80
|
-
)
|
81
|
-
|
82
|
-
rbln_config.model_cfg.update(
|
83
|
-
{
|
84
|
-
"image_size": rbln_image_size,
|
85
|
-
"batch_size": rbln_batch_size,
|
86
|
-
}
|
87
|
-
)
|
88
|
-
|
89
|
-
return rbln_config
|
90
|
-
|
91
|
-
def forward(self, *args, **kwargs):
|
92
|
-
predicted_depth = super().forward(*args, **kwargs)
|
93
|
-
return DepthEstimatorOutput(predicted_depth=predicted_depth)
|
19
|
+
class RBLNDPTForDepthEstimation(RBLNModelForDepthEstimation):
|
20
|
+
pass
|
@@ -20,4 +20,5 @@ this_path = os.path.abspath(__file__)
|
|
20
20
|
local_dir = "/" + os.path.join(*this_path.split("/")[:-1]) + "/hf_hub_cached"
|
21
21
|
environ["LOCAL_CACHE_ROOT_CUSTOM_CODE_MIDM"] = local_dir
|
22
22
|
|
23
|
+
from .configuration_exaone import RBLNExaoneForCausalLMConfig
|
23
24
|
from .modeling_exaone import RBLNExaoneForCausalLM
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNExaoneForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNGemmaForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNGPT2LMHeadModelConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNLlamaForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -12,4 +12,5 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
from .configuration_llava_next import RBLNLlavaNextForConditionalGenerationConfig
|
15
16
|
from .modeling_llava_next import RBLNLlavaNextForConditionalGeneration
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from typing import Optional
|
16
|
+
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
18
|
+
|
19
|
+
|
20
|
+
class RBLNLlavaNextForConditionalGenerationConfig(RBLNModelConfig):
|
21
|
+
submodules = ["vision_tower", "language_model"]
|
22
|
+
|
23
|
+
def __init__(
|
24
|
+
self,
|
25
|
+
batch_size: Optional[int] = None,
|
26
|
+
vision_tower: Optional[RBLNModelConfig] = None,
|
27
|
+
language_model: Optional[RBLNModelConfig] = None,
|
28
|
+
**kwargs,
|
29
|
+
):
|
30
|
+
"""
|
31
|
+
Args:
|
32
|
+
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
33
|
+
vision_tower (Optional[RBLNModelConfig]): Configuration for the vision encoder component.
|
34
|
+
language_model (Optional[RBLNModelConfig]): Configuration for the language model component.
|
35
|
+
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
36
|
+
|
37
|
+
Raises:
|
38
|
+
ValueError: If batch_size is not a positive integer.
|
39
|
+
"""
|
40
|
+
super().__init__(**kwargs)
|
41
|
+
self.batch_size = batch_size or 1
|
42
|
+
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
43
|
+
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
44
|
+
|
45
|
+
self.vision_tower = vision_tower
|
46
|
+
self.language_model = language_model
|
@@ -26,8 +26,8 @@ from transformers import (
|
|
26
26
|
)
|
27
27
|
from transformers.modeling_outputs import BaseModelOutputWithPooling
|
28
28
|
|
29
|
+
from ....configuration_utils import RBLNCompileConfig, RBLNModelConfig
|
29
30
|
from ....modeling import RBLNModel
|
30
|
-
from ....modeling_config import RBLNCompileConfig, RBLNConfig
|
31
31
|
from ....utils.logging import get_logger
|
32
32
|
from ..decoderonly.modeling_decoderonly import RBLNDecoderOnlyOutput
|
33
33
|
|
@@ -134,7 +134,7 @@ class RBLNLlavaNextForConditionalGeneration(RBLNModel):
|
|
134
134
|
model: "LlavaNextForConditionalGeneration",
|
135
135
|
save_dir_path: Path,
|
136
136
|
subfolder: str,
|
137
|
-
rbln_config:
|
137
|
+
rbln_config: RBLNModelConfig,
|
138
138
|
):
|
139
139
|
"""
|
140
140
|
If you are unavoidably running on a CPU rather than an RBLN device,
|
@@ -161,42 +161,31 @@ class RBLNLlavaNextForConditionalGeneration(RBLNModel):
|
|
161
161
|
return self.language_model.get_input_embeddings()
|
162
162
|
|
163
163
|
@classmethod
|
164
|
-
def wrap_model_if_needed(cls, model: "PreTrainedModel", rbln_config:
|
164
|
+
def wrap_model_if_needed(cls, model: "PreTrainedModel", rbln_config: RBLNModelConfig):
|
165
165
|
return model.multi_modal_projector
|
166
166
|
|
167
167
|
@classmethod
|
168
|
-
def
|
168
|
+
def _update_rbln_config(
|
169
169
|
cls,
|
170
170
|
preprocessors: Optional[Union["AutoFeatureExtractor", "AutoProcessor", "AutoTokenizer"]],
|
171
|
+
model: Optional["PreTrainedModel"] = None,
|
171
172
|
model_config: Optional["PretrainedConfig"] = None,
|
172
|
-
|
173
|
-
) ->
|
174
|
-
vision_feature_select_strategy = rbln_kwargs.get("vision_feature_select_strategy", None)
|
175
|
-
|
176
|
-
# 1. Multi-modal projection layer
|
177
|
-
batch_size = rbln_kwargs.get("rbln_batch_size", None)
|
178
|
-
if batch_size is None:
|
179
|
-
batch_size = 1
|
180
|
-
|
173
|
+
rbln_config: Optional[RBLNModelConfig] = None,
|
174
|
+
) -> RBLNModelConfig:
|
181
175
|
feature_size = model_config.vision_config.hidden_size
|
182
176
|
|
183
|
-
# See forward function to see more details.
|
184
|
-
vision_feature_select_strategy = (
|
185
|
-
vision_feature_select_strategy
|
186
|
-
if vision_feature_select_strategy is not None
|
187
|
-
else model_config.vision_feature_select_strategy
|
188
|
-
)
|
189
|
-
|
190
177
|
# Calculating `num_positions` : See CLIPVisionEmbeddings of transformers for more details.
|
191
178
|
num_positions = (model_config.vision_config.image_size // model_config.vision_config.patch_size) ** 2 + 1
|
192
|
-
if vision_feature_select_strategy == "default":
|
179
|
+
if model_config.vision_feature_select_strategy == "default":
|
193
180
|
selected_image_feature_dim = num_positions - 1
|
194
181
|
else:
|
195
182
|
selected_image_feature_dim = num_positions
|
196
183
|
|
197
|
-
input_info = [
|
184
|
+
input_info = [
|
185
|
+
("image_features", [rbln_config.batch_size, selected_image_feature_dim, feature_size], "float32")
|
186
|
+
]
|
198
187
|
rbln_compile_config = RBLNCompileConfig(input_info=input_info)
|
199
|
-
rbln_config
|
188
|
+
rbln_config.set_compile_cfgs([rbln_compile_config])
|
200
189
|
return rbln_config
|
201
190
|
|
202
191
|
def prepare_inputs_for_generation(
|
@@ -20,4 +20,5 @@ this_path = os.path.abspath(__file__)
|
|
20
20
|
local_dir = "/" + os.path.join(*this_path.split("/")[:-1]) + "/hf_hub_cached"
|
21
21
|
environ["LOCAL_CACHE_ROOT_CUSTOM_CODE_MIDM"] = local_dir
|
22
22
|
|
23
|
+
from .configuration_midm import RBLNMidmLMHeadModelConfig
|
23
24
|
from .modeling_midm import RBLNMidmLMHeadModel
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNMidmLMHeadModelConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNMistralForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNPhiForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
16
|
+
|
17
|
+
|
18
|
+
class RBLNQwen2ForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
19
|
+
pass
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from .configuration_qwen2_5_vl import (
|
16
|
+
RBLNQwen2_5_VisionTransformerPretrainedModelConfig,
|
17
|
+
RBLNQwen2_5_VLForConditionalGenerationConfig,
|
18
|
+
)
|
19
|
+
from .modeling_qwen2_5_vl import RBLNQwen2_5_VisionTransformerPretrainedModel, RBLNQwen2_5_VLForConditionalGeneration
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Copyright 2025 Rebellions Inc. All rights reserved.
|
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
|
+
from typing import List, Optional, Union
|
16
|
+
|
17
|
+
from ....configuration_utils import RBLNModelConfig
|
18
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
19
|
+
|
20
|
+
|
21
|
+
class RBLNQwen2_5_VLForConditionalGenerationConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
22
|
+
submodules = ["visual"]
|
23
|
+
|
24
|
+
def __init__(
|
25
|
+
self,
|
26
|
+
visual: Optional[RBLNModelConfig] = None,
|
27
|
+
use_inputs_embeds: bool = True,
|
28
|
+
**kwargs,
|
29
|
+
):
|
30
|
+
super().__init__(use_inputs_embeds=use_inputs_embeds, **kwargs)
|
31
|
+
if not self.use_inputs_embeds:
|
32
|
+
raise ValueError(
|
33
|
+
"RBLNQwen2_5_VLForConditionalGenerationConfig does not allow `use_inputs_embeds` to be set to False, "
|
34
|
+
"as RBLNQwen2_5_VLForConditionalGeneration accepts only `inputs_embeds` as input."
|
35
|
+
)
|
36
|
+
self.visual = visual
|
37
|
+
|
38
|
+
|
39
|
+
class RBLNQwen2_5_VisionTransformerPretrainedModelConfig(RBLNModelConfig):
|
40
|
+
def __init__(self, max_seq_lens: Union[int, List[int]] = None, **kwargs):
|
41
|
+
"""
|
42
|
+
Args:
|
43
|
+
max_seq_lens (Optional[Union[int, List[int]]]): Maximum sequence lengths for Vision
|
44
|
+
Transformer attention. Can be an integer or list of integers, each indicating
|
45
|
+
the number of patches in a sequence for an image or video. For example, an image
|
46
|
+
of 224x196 pixels with patch size 14 and window size 112 has its width padded to
|
47
|
+
224, forming a 224x224 image. This yields 256 patches [(224/14) * (224/14)], so
|
48
|
+
`max_seq_len` must be at least 256. For window-based attention, `max_seq_len`
|
49
|
+
must be a multiple of `(window_size / patch_size)^2`, e.g., (112/14)^2 = 64,
|
50
|
+
making 256 (64 * 4) valid. RBLN optimization runs inference per image or video
|
51
|
+
frame, so set `max_seq_len` to match the maximum expected resolution to reduce
|
52
|
+
computation. If not provided, a `ValueError` is raised.
|
53
|
+
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
54
|
+
|
55
|
+
Raises:
|
56
|
+
ValueError: If batch_size is not a positive integer.
|
57
|
+
"""
|
58
|
+
super().__init__(**kwargs)
|
59
|
+
|
60
|
+
if max_seq_lens is not None:
|
61
|
+
if isinstance(max_seq_lens, int):
|
62
|
+
max_seq_lens = [max_seq_lens]
|
63
|
+
elif isinstance(max_seq_lens, list):
|
64
|
+
max_seq_lens.sort(reverse=True)
|
65
|
+
else:
|
66
|
+
raise ValueError("'max_seq_lens' must be specified.")
|
67
|
+
|
68
|
+
self.max_seq_lens = max_seq_lens
|