optimum-rbln 0.8.2a4__py3-none-any.whl → 0.9.3__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 +108 -9
- optimum/rbln/__version__.py +16 -3
- optimum/rbln/cli.py +660 -0
- optimum/rbln/configuration_utils.py +156 -43
- optimum/rbln/diffusers/__init__.py +19 -0
- optimum/rbln/diffusers/configurations/__init__.py +3 -0
- optimum/rbln/diffusers/configurations/models/__init__.py +2 -0
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py +3 -3
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl_cosmos.py +1 -1
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl_temporal_decoder.py +67 -0
- optimum/rbln/diffusers/configurations/models/configuration_controlnet.py +3 -3
- optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py +4 -4
- optimum/rbln/diffusers/configurations/models/configuration_transformer_cosmos.py +9 -4
- optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py +9 -4
- optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py +3 -3
- optimum/rbln/diffusers/configurations/models/configuration_unet_spatio_temporal_condition.py +59 -0
- optimum/rbln/diffusers/configurations/models/configuration_vq_model.py +3 -3
- optimum/rbln/diffusers/configurations/pipelines/__init__.py +3 -0
- optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py +35 -19
- optimum/rbln/diffusers/configurations/pipelines/configuration_cosmos.py +14 -11
- optimum/rbln/diffusers/configurations/pipelines/configuration_kandinsky2_2.py +30 -20
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion.py +13 -9
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_3.py +17 -13
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_xl.py +17 -10
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_video_diffusion.py +114 -0
- optimum/rbln/diffusers/modeling_diffusers.py +30 -14
- optimum/rbln/diffusers/models/__init__.py +4 -0
- optimum/rbln/diffusers/models/autoencoders/__init__.py +1 -0
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl.py +31 -3
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl_cosmos.py +31 -6
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl_temporal_decoder.py +275 -0
- optimum/rbln/diffusers/models/autoencoders/vae.py +27 -8
- optimum/rbln/diffusers/models/autoencoders/vq_model.py +31 -3
- optimum/rbln/diffusers/models/controlnet.py +16 -1
- optimum/rbln/diffusers/models/transformers/prior_transformer.py +17 -3
- optimum/rbln/diffusers/models/transformers/transformer_cosmos.py +25 -2
- optimum/rbln/diffusers/models/transformers/transformer_sd3.py +23 -2
- optimum/rbln/diffusers/models/unets/__init__.py +1 -0
- optimum/rbln/diffusers/models/unets/unet_2d_condition.py +23 -4
- optimum/rbln/diffusers/models/unets/unet_spatio_temporal_condition.py +201 -0
- optimum/rbln/diffusers/pipelines/__init__.py +15 -5
- optimum/rbln/diffusers/pipelines/auto_pipeline.py +307 -0
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +20 -0
- optimum/rbln/diffusers/pipelines/cosmos/configuration_cosmos_guardrail.py +19 -16
- optimum/rbln/diffusers/pipelines/cosmos/cosmos_guardrail.py +14 -18
- optimum/rbln/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py +31 -1
- optimum/rbln/diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py +31 -1
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +1 -6
- optimum/rbln/diffusers/pipelines/stable_video_diffusion/__init__.py +15 -0
- optimum/rbln/diffusers/pipelines/stable_video_diffusion/pipeline_stable_video_diffusion.py +46 -0
- optimum/rbln/modeling.py +48 -21
- optimum/rbln/modeling_base.py +99 -22
- optimum/rbln/ops/attn.py +158 -0
- optimum/rbln/ops/flash_attn.py +166 -0
- optimum/rbln/ops/kv_cache_update.py +5 -0
- optimum/rbln/ops/linear.py +7 -0
- optimum/rbln/transformers/__init__.py +92 -0
- optimum/rbln/transformers/configuration_generic.py +7 -32
- optimum/rbln/transformers/modeling_attention_utils.py +385 -0
- optimum/rbln/transformers/modeling_generic.py +48 -65
- optimum/rbln/transformers/modeling_outputs.py +37 -0
- optimum/rbln/transformers/models/__init__.py +91 -30
- optimum/rbln/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py +28 -2
- optimum/rbln/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py +68 -5
- optimum/rbln/transformers/models/auto/__init__.py +2 -0
- optimum/rbln/transformers/models/auto/auto_factory.py +92 -17
- optimum/rbln/transformers/models/auto/modeling_auto.py +45 -0
- optimum/rbln/transformers/models/bart/bart_architecture.py +1 -3
- optimum/rbln/transformers/models/bart/configuration_bart.py +2 -0
- optimum/rbln/transformers/models/bart/modeling_bart.py +23 -2
- optimum/rbln/transformers/models/bert/bert_architecture.py +16 -0
- optimum/rbln/transformers/models/bert/modeling_bert.py +93 -4
- optimum/rbln/transformers/models/blip_2/configuration_blip_2.py +42 -11
- optimum/rbln/transformers/models/blip_2/modeling_blip_2.py +135 -44
- optimum/rbln/transformers/models/clip/configuration_clip.py +10 -7
- optimum/rbln/transformers/models/clip/modeling_clip.py +67 -6
- optimum/rbln/transformers/models/colpali/colpali_architecture.py +3 -6
- optimum/rbln/transformers/models/colpali/configuration_colpali.py +37 -21
- optimum/rbln/transformers/models/colpali/modeling_colpali.py +82 -104
- optimum/rbln/transformers/models/colqwen2/__init__.py +2 -0
- optimum/rbln/transformers/models/colqwen2/colqwen2_architecture.py +233 -0
- optimum/rbln/transformers/models/colqwen2/configuration_colqwen2.py +74 -0
- optimum/rbln/transformers/models/colqwen2/modeling_colqwen2.py +446 -0
- optimum/rbln/transformers/models/decoderonly/__init__.py +3 -2
- optimum/rbln/transformers/models/decoderonly/configuration_decoderonly.py +114 -37
- optimum/rbln/transformers/models/decoderonly/configuration_lora.py +411 -0
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +318 -309
- optimum/rbln/transformers/models/decoderonly/decoderonly_runtime_utils.py +508 -0
- optimum/rbln/transformers/models/decoderonly/generation_decoderonly.py +119 -0
- optimum/rbln/transformers/models/decoderonly/lora_architecture.py +204 -0
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +485 -905
- optimum/rbln/transformers/models/depth_anything/__init__.py +16 -0
- optimum/rbln/transformers/models/depth_anything/configuration_depth_anything.py +24 -0
- optimum/rbln/transformers/models/depth_anything/modeling_depth_anything.py +42 -0
- optimum/rbln/transformers/models/distilbert/modeling_distilbert.py +24 -0
- optimum/rbln/transformers/models/dpt/modeling_dpt.py +17 -0
- optimum/rbln/transformers/models/exaone/modeling_exaone.py +42 -4
- optimum/rbln/transformers/models/gemma/__init__.py +2 -2
- optimum/rbln/transformers/models/gemma/configuration_gemma.py +9 -1
- optimum/rbln/transformers/models/gemma/gemma_architecture.py +1 -4
- optimum/rbln/transformers/models/gemma/modeling_gemma.py +22 -1
- optimum/rbln/transformers/models/gemma3/configuration_gemma3.py +49 -13
- optimum/rbln/transformers/models/gemma3/gemma3_architecture.py +12 -2
- optimum/rbln/transformers/models/gemma3/gemma3_runtime_utils.py +245 -0
- optimum/rbln/transformers/models/gemma3/modeling_gemma3.py +201 -351
- optimum/rbln/transformers/models/gpt2/__init__.py +2 -2
- optimum/rbln/transformers/models/gpt2/configuration_gpt2.py +31 -3
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +10 -8
- optimum/rbln/transformers/models/gpt2/modeling_gpt2.py +18 -1
- optimum/rbln/transformers/models/grounding_dino/__init__.py +10 -0
- optimum/rbln/transformers/models/grounding_dino/configuration_grounding_dino.py +92 -0
- optimum/rbln/transformers/models/grounding_dino/grounding_dino_architecture.py +599 -0
- optimum/rbln/transformers/models/grounding_dino/modeling_grounding_dino.py +1048 -0
- optimum/rbln/transformers/models/idefics3/configuration_idefics3.py +35 -7
- optimum/rbln/transformers/models/idefics3/modeling_idefics3.py +29 -32
- optimum/rbln/transformers/models/llama/__init__.py +2 -2
- optimum/rbln/transformers/models/llama/configuration_llama.py +9 -1
- optimum/rbln/transformers/models/llama/modeling_llama.py +22 -1
- optimum/rbln/transformers/models/llava/__init__.py +16 -0
- optimum/rbln/transformers/models/llava/configuration_llava.py +72 -0
- optimum/rbln/transformers/models/llava/modeling_llava.py +490 -0
- optimum/rbln/transformers/models/llava_next/configuration_llava_next.py +15 -17
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +234 -376
- optimum/rbln/transformers/models/midm/midm_architecture.py +4 -1
- optimum/rbln/transformers/models/midm/modeling_midm.py +42 -4
- optimum/rbln/transformers/models/mistral/__init__.py +2 -2
- optimum/rbln/transformers/models/mistral/configuration_mistral.py +9 -1
- optimum/rbln/transformers/models/mistral/mistral_architecture.py +1 -1
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +26 -3
- optimum/rbln/transformers/models/opt/__init__.py +2 -2
- optimum/rbln/transformers/models/opt/configuration_opt.py +8 -1
- optimum/rbln/transformers/models/opt/modeling_opt.py +29 -17
- optimum/rbln/transformers/models/opt/opt_architecture.py +4 -4
- optimum/rbln/transformers/models/pegasus/__init__.py +17 -0
- optimum/rbln/transformers/models/pegasus/configuration_pegasus.py +38 -0
- optimum/rbln/transformers/models/pegasus/modeling_pegasus.py +71 -0
- optimum/rbln/transformers/models/pegasus/pegasus_architecture.py +161 -0
- optimum/rbln/transformers/models/phi/__init__.py +2 -2
- optimum/rbln/transformers/models/phi/configuration_phi.py +9 -1
- optimum/rbln/transformers/models/phi/modeling_phi.py +10 -1
- optimum/rbln/transformers/models/phi/phi_architecture.py +11 -7
- optimum/rbln/transformers/models/pixtral/__init__.py +16 -0
- optimum/rbln/transformers/models/pixtral/configuration_pixtral.py +43 -0
- optimum/rbln/transformers/models/pixtral/modeling_pixtral.py +322 -0
- optimum/rbln/transformers/models/pixtral/pixtral_architecture.py +73 -0
- optimum/rbln/transformers/models/qwen2/__init__.py +2 -2
- optimum/rbln/transformers/models/qwen2/configuration_qwen2.py +9 -1
- optimum/rbln/transformers/models/qwen2/modeling_qwen2.py +27 -1
- optimum/rbln/transformers/models/qwen2_5_vl/configuration_qwen2_5_vl.py +21 -6
- optimum/rbln/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py +15 -22
- optimum/rbln/transformers/models/qwen2_5_vl/qwen2_5_vl_architecture.py +28 -7
- optimum/rbln/transformers/models/qwen2_vl/__init__.py +19 -0
- optimum/rbln/transformers/models/qwen2_vl/configuration_qwen2_vl.py +88 -0
- optimum/rbln/transformers/models/qwen2_vl/modeling_qwen2_vl.py +513 -0
- optimum/rbln/transformers/models/qwen2_vl/qwen2_vl_architecture.py +165 -0
- optimum/rbln/transformers/models/qwen3/configuration_qwen3.py +2 -2
- optimum/rbln/transformers/models/qwen3/modeling_qwen3.py +86 -330
- optimum/rbln/transformers/models/qwen3/qwen3_architecture.py +1 -245
- optimum/rbln/transformers/models/resnet/configuration_resnet.py +17 -0
- optimum/rbln/transformers/models/resnet/modeling_resnet.py +73 -0
- optimum/rbln/transformers/models/roberta/modeling_roberta.py +33 -0
- optimum/rbln/transformers/models/seq2seq/configuration_seq2seq.py +21 -16
- optimum/rbln/transformers/models/seq2seq/modeling_seq2seq.py +58 -13
- optimum/rbln/transformers/models/seq2seq/seq2seq_architecture.py +2 -2
- optimum/rbln/transformers/models/siglip/__init__.py +2 -6
- optimum/rbln/transformers/models/siglip/configuration_siglip.py +1 -1
- optimum/rbln/transformers/models/siglip/modeling_siglip.py +21 -16
- optimum/rbln/transformers/models/swin/__init__.py +16 -0
- optimum/rbln/transformers/models/swin/configuration_swin.py +42 -0
- optimum/rbln/transformers/models/swin/modeling_swin.py +354 -0
- optimum/rbln/transformers/models/t5/configuration_t5.py +2 -0
- optimum/rbln/transformers/models/t5/modeling_t5.py +2 -2
- optimum/rbln/transformers/models/t5/t5_architecture.py +8 -1
- optimum/rbln/transformers/models/time_series_transformer/configuration_time_series_transformer.py +3 -3
- optimum/rbln/transformers/models/time_series_transformer/modeling_time_series_transformer.py +20 -16
- optimum/rbln/transformers/models/time_series_transformer/time_series_transformers_architecture.py +7 -1
- optimum/rbln/transformers/models/vit/modeling_vit.py +19 -0
- optimum/rbln/transformers/models/wav2vec2/configuration_wav2vec2.py +15 -3
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +61 -8
- optimum/rbln/transformers/models/whisper/configuration_whisper.py +12 -13
- optimum/rbln/transformers/models/whisper/generation_whisper.py +62 -6
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +30 -5
- optimum/rbln/transformers/models/xlm_roberta/__init__.py +2 -8
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +43 -0
- optimum/rbln/transformers/utils/rbln_quantization.py +400 -75
- optimum/rbln/transformers/utils/rbln_runtime_wrapper.py +79 -0
- optimum/rbln/utils/deprecation.py +213 -0
- optimum/rbln/utils/hub.py +14 -3
- optimum/rbln/utils/runtime_utils.py +60 -18
- optimum/rbln/utils/submodule.py +31 -9
- {optimum_rbln-0.8.2a4.dist-info → optimum_rbln-0.9.3.dist-info}/METADATA +8 -7
- optimum_rbln-0.9.3.dist-info/RECORD +264 -0
- {optimum_rbln-0.8.2a4.dist-info → optimum_rbln-0.9.3.dist-info}/WHEEL +1 -1
- optimum_rbln-0.9.3.dist-info/entry_points.txt +2 -0
- optimum_rbln-0.8.2a4.dist-info/RECORD +0 -215
- {optimum_rbln-0.8.2a4.dist-info → optimum_rbln-0.9.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
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_depth_anything import RBLNDepthAnythingForDepthEstimationConfig
|
|
16
|
+
from .modeling_depth_anything import RBLNDepthAnythingForDepthEstimation
|
|
@@ -0,0 +1,24 @@
|
|
|
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 RBLNDepthAnythingForDepthEstimationConfig(RBLNModelForDepthEstimationConfig):
|
|
19
|
+
"""
|
|
20
|
+
Configuration class for DepthAnythingForDepthEstimation.
|
|
21
|
+
|
|
22
|
+
This configuration class stores the configuration parameters specific to
|
|
23
|
+
RBLN-optimized Depth Anything V2 Small models for depth estimation tasks.
|
|
24
|
+
"""
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
|
|
16
|
+
from typing import Tuple, Union
|
|
17
|
+
|
|
18
|
+
import torch
|
|
19
|
+
from transformers.modeling_outputs import DepthEstimatorOutput
|
|
20
|
+
|
|
21
|
+
from ...modeling_generic import RBLNModelForDepthEstimation
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class RBLNDepthAnythingForDepthEstimation(RBLNModelForDepthEstimation):
|
|
25
|
+
"""
|
|
26
|
+
RBLN optimized DepthAnythingForDepthEstimation model for depth estimation tasks.
|
|
27
|
+
|
|
28
|
+
This class provides hardware-accelerated inference for Depth Anything V2
|
|
29
|
+
models on RBLN devices, providing the most capable monocular depth estimation (MDE) model.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def forward(self, pixel_values: torch.Tensor, **kwargs) -> Union[Tuple, DepthEstimatorOutput]:
|
|
33
|
+
"""
|
|
34
|
+
Forward pass for the RBLN-optimized DepthAnythingForDepthEstimation model.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
pixel_values (torch.FloatTensor of shape (batch_size, num_channels, height, width)): The tensors corresponding to the input images.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The model outputs. If return_dict=False is passed, returns a tuple of tensors. Otherwise, returns a DepthEstimatorOutput object.
|
|
41
|
+
"""
|
|
42
|
+
return super().forward(pixel_values, **kwargs)
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from typing import Optional, Tuple, Union
|
|
16
|
+
|
|
17
|
+
import torch
|
|
18
|
+
from transformers.modeling_outputs import QuestionAnsweringModelOutput
|
|
19
|
+
|
|
15
20
|
from ...modeling_generic import RBLNModelForQuestionAnswering
|
|
16
21
|
|
|
17
22
|
|
|
@@ -25,3 +30,22 @@ class RBLNDistilBertForQuestionAnswering(RBLNModelForQuestionAnswering):
|
|
|
25
30
|
"""
|
|
26
31
|
|
|
27
32
|
rbln_model_input_names = ["input_ids", "attention_mask"]
|
|
33
|
+
|
|
34
|
+
def forward(
|
|
35
|
+
self,
|
|
36
|
+
input_ids: Optional[torch.Tensor] = None,
|
|
37
|
+
attention_mask: Optional[torch.Tensor] = None,
|
|
38
|
+
**kwargs,
|
|
39
|
+
) -> Union[Tuple, QuestionAnsweringModelOutput]:
|
|
40
|
+
"""
|
|
41
|
+
Forward pass for the RBLN-optimized DistilBERT model for question answering tasks.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
input_ids (torch.Tensor of shape (batch_size, sequence_length), optional): Indices of input sequence tokens in the vocabulary.
|
|
45
|
+
attention_mask (torch.Tensor of shape (batch_size, sequence_length), optional): Mask to avoid performing attention on padding token indices.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
The model outputs. If return_dict=False is passed, returns a tuple of tensors. Otherwise, returns a QuestionAnsweringModelOutput object.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
return super().forward(input_ids, attention_mask, **kwargs)
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
from typing import Tuple, Union
|
|
17
|
+
|
|
18
|
+
import torch
|
|
19
|
+
from transformers.modeling_outputs import DepthEstimatorOutput
|
|
20
|
+
|
|
16
21
|
from ...modeling_generic import RBLNModelForDepthEstimation
|
|
17
22
|
|
|
18
23
|
|
|
@@ -23,3 +28,15 @@ class RBLNDPTForDepthEstimation(RBLNModelForDepthEstimation):
|
|
|
23
28
|
This class provides hardware-accelerated inference for DPT (Dense Prediction Transformer)
|
|
24
29
|
models on RBLN devices, supporting monocular depth estimation from single images.
|
|
25
30
|
"""
|
|
31
|
+
|
|
32
|
+
def forward(self, pixel_values: torch.Tensor, **kwargs) -> Union[Tuple, DepthEstimatorOutput]:
|
|
33
|
+
"""
|
|
34
|
+
Forward pass for the RBLN-optimized DPT model.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
pixel_values (torch.FloatTensor of shape (batch_size, num_channels, image_size, image_size)): The tensors corresponding to the input images.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The model outputs. If return_dict=False is passed, returns a tuple of tensors. Otherwise, returns a DepthEstimatorOutput object.
|
|
41
|
+
"""
|
|
42
|
+
return super().forward(pixel_values, **kwargs)
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
import inspect
|
|
17
|
-
from
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Callable, Dict, Optional, Union
|
|
18
19
|
|
|
19
20
|
from transformers import AutoModelForCausalLM
|
|
20
21
|
from transformers.generation.utils import GenerationMixin
|
|
21
22
|
|
|
23
|
+
from ....configuration_utils import RBLNModelConfig
|
|
22
24
|
from ....utils import logging
|
|
23
25
|
from ..decoderonly import RBLNDecoderOnlyModelForCausalLM
|
|
24
26
|
from .exaone_architecture import ExaoneForCausalLMWrapper
|
|
@@ -92,9 +94,45 @@ class RBLNExaoneForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
|
92
94
|
_supports_cache_class = True
|
|
93
95
|
|
|
94
96
|
@classmethod
|
|
95
|
-
def from_pretrained(
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
def from_pretrained(
|
|
98
|
+
cls,
|
|
99
|
+
model_id: Union[str, Path],
|
|
100
|
+
*,
|
|
101
|
+
export: Optional[bool] = None,
|
|
102
|
+
rbln_config: Optional[Union[Dict, RBLNModelConfig]] = None,
|
|
103
|
+
trust_remote_code: Optional[bool] = None,
|
|
104
|
+
**kwargs: Any,
|
|
105
|
+
):
|
|
106
|
+
"""
|
|
107
|
+
The `from_pretrained()` function is utilized in its standard form as in the HuggingFace transformers library.
|
|
108
|
+
User can use this function to load a pre-trained model from the HuggingFace library and convert it to a RBLN model to be run on RBLN NPUs.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
model_id (Union[str, Path]): The model id of the pre-trained model to be loaded.
|
|
112
|
+
It can be downloaded from the HuggingFace model hub or a local path, or a model id of a compiled model using the RBLN Compiler.
|
|
113
|
+
export (Optional[bool]): A boolean flag to indicate whether the model should be compiled.
|
|
114
|
+
If None, it will be determined based on the existence of the compiled model files in the model_id.
|
|
115
|
+
rbln_config (Optional[Union[Dict, RBLNModelConfig]]): Configuration for RBLN model compilation and runtime.
|
|
116
|
+
This can be provided as a dictionary or an instance of the model's configuration class (e.g., `RBLNExaoneForCausalLMConfig` for EXAONE models).
|
|
117
|
+
For detailed configuration options, see the specific model's configuration class documentation.
|
|
118
|
+
trust_remote_code (bool): Whether or not to trust the remote code when loading a model from the Hub.
|
|
119
|
+
kwargs: Additional keyword arguments. Arguments with the prefix `rbln_` are passed to rbln_config, while the remaining arguments are passed to the HuggingFace library.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
(RBLNModel): A RBLN model instance ready for inference on RBLN NPU devices.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
if trust_remote_code is not None:
|
|
126
|
+
kwargs["trust_remote_code"] = trust_remote_code
|
|
127
|
+
elif "trust_remote_code" not in kwargs:
|
|
128
|
+
kwargs["trust_remote_code"] = True
|
|
129
|
+
|
|
130
|
+
return super().from_pretrained(
|
|
131
|
+
model_id=model_id,
|
|
132
|
+
export=export,
|
|
133
|
+
rbln_config=rbln_config,
|
|
134
|
+
**kwargs,
|
|
135
|
+
)
|
|
98
136
|
|
|
99
137
|
def __getattr__(self, __name: str) -> Any:
|
|
100
138
|
def redirect(func):
|
|
@@ -12,5 +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_gemma import RBLNGemmaForCausalLMConfig
|
|
16
|
-
from .modeling_gemma import RBLNGemmaForCausalLM
|
|
15
|
+
from .configuration_gemma import RBLNGemmaForCausalLMConfig, RBLNGemmaModelConfig
|
|
16
|
+
from .modeling_gemma import RBLNGemmaForCausalLM, RBLNGemmaModel
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
|
15
|
+
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelConfig, RBLNDecoderOnlyModelForCausalLMConfig
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class RBLNGemmaForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
|
@@ -40,3 +40,11 @@ class RBLNGemmaForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
|
|
40
40
|
)
|
|
41
41
|
```
|
|
42
42
|
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class RBLNGemmaModelConfig(RBLNDecoderOnlyModelConfig):
|
|
46
|
+
"""
|
|
47
|
+
Configuration class for RBLN Gemma models.
|
|
48
|
+
|
|
49
|
+
This class is an alias of RBLNDecoderOnlyModelConfig.
|
|
50
|
+
"""
|
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
from ...models.decoderonly.decoderonly_architecture import
|
|
17
|
-
DecoderOnlyModel,
|
|
18
|
-
DecoderOnlyWrapper,
|
|
19
|
-
)
|
|
16
|
+
from ...models.decoderonly.decoderonly_architecture import DecoderOnlyModel, DecoderOnlyWrapper
|
|
20
17
|
|
|
21
18
|
|
|
22
19
|
class GemmaWrapper(DecoderOnlyWrapper):
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
from ....utils import logging
|
|
16
|
-
from ...models.decoderonly import RBLNDecoderOnlyModelForCausalLM
|
|
16
|
+
from ...models.decoderonly import RBLNDecoderOnlyModel, RBLNDecoderOnlyModelForCausalLM
|
|
17
17
|
from .gemma_architecture import GemmaWrapper
|
|
18
18
|
|
|
19
19
|
|
|
@@ -81,3 +81,24 @@ class RBLNGemmaForCausalLM(RBLNDecoderOnlyModelForCausalLM):
|
|
|
81
81
|
"""
|
|
82
82
|
|
|
83
83
|
_decoder_wrapper_cls = GemmaWrapper
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class RBLNGemmaModel(RBLNDecoderOnlyModel):
|
|
87
|
+
"""
|
|
88
|
+
The Gemma Model transformer without a language modeling head.
|
|
89
|
+
This model inherits from [`RBLNDecoderOnlyModel`]. Check the superclass documentation for the generic methods the library implements for all its models.
|
|
90
|
+
|
|
91
|
+
A class to convert and run pre-trained transformers based GemmaModel model on RBLN devices.
|
|
92
|
+
It implements the methods to convert a pre-trained transformers GemmaModel model into a RBLN transformer model by:
|
|
93
|
+
|
|
94
|
+
- transferring the checkpoint weights of the original into an optimized RBLN graph,
|
|
95
|
+
- compiling the resulting graph using the RBLN compiler.
|
|
96
|
+
|
|
97
|
+
**Configuration:**
|
|
98
|
+
This model uses [`RBLNGemmaModelConfig`] for configuration. When calling methods like `from_pretrained` or `from_model`,
|
|
99
|
+
the `rbln_config` parameter should be an instance of [`RBLNGemmaModelConfig`] or a dictionary conforming to its structure.
|
|
100
|
+
|
|
101
|
+
See the [`RBLNGemmaModelConfig`] class for all available configuration options.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
_decoder_wrapper_cls = GemmaWrapper
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
from typing import Any,
|
|
15
|
-
|
|
16
|
-
import rebel
|
|
14
|
+
from typing import Any, Optional
|
|
17
15
|
|
|
18
16
|
from ....configuration_utils import RBLNModelConfig
|
|
17
|
+
from ....utils.logging import get_logger
|
|
19
18
|
from ..decoderonly.configuration_decoderonly import RBLNDecoderOnlyModelForCausalLMConfig
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
logger = get_logger(__name__)
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class RBLNGemma3ForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
|
@@ -25,23 +26,45 @@ class RBLNGemma3ForCausalLMConfig(RBLNDecoderOnlyModelForCausalLMConfig):
|
|
|
25
26
|
self,
|
|
26
27
|
use_position_ids: Optional[bool] = None,
|
|
27
28
|
use_attention_mask: Optional[bool] = None,
|
|
29
|
+
prefill_chunk_size: Optional[int] = None,
|
|
28
30
|
image_prefill_chunk_size: Optional[int] = None,
|
|
29
|
-
**kwargs:
|
|
31
|
+
**kwargs: Any,
|
|
30
32
|
):
|
|
33
|
+
"""
|
|
34
|
+
Args:
|
|
35
|
+
use_position_ids (Optional[bool]): Whether or not to use `position_ids`, which is indices of positions of each input sequence tokens in the position embeddings.
|
|
36
|
+
use_attention_mask (Optional[bool]): Whether or not to use `attention_mask` to to avoid performing attention on padding token indices.
|
|
37
|
+
prefill_chunk_size (Optional[int]): The chunk size used during the prefill phase for
|
|
38
|
+
processing input sequences. Defaults to 256. Must be a positive integer
|
|
39
|
+
divisible by 64. Affects prefill performance and memory usage.
|
|
40
|
+
image_prefill_chunk_size (Optional[int]): The chunk size used during the prefill phase for
|
|
41
|
+
processing images. This config is used when `use_image_prefill` is True.
|
|
42
|
+
Currently, the `prefill_chunk_size` and `image_prefill_chunk_size` should be the same value.
|
|
43
|
+
kwargs: Additional arguments passed to the parent `RBLNDecoderOnlyModelForCausalLMConfig`.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
ValueError: If `use_attention_mask` or `use_position_ids` are False.
|
|
47
|
+
"""
|
|
31
48
|
# use_attention_mask and use_position_ids are always True for Gemma3
|
|
32
49
|
use_attention_mask = use_attention_mask or True
|
|
33
50
|
use_position_ids = use_position_ids or True
|
|
51
|
+
prefill_chunk_size = prefill_chunk_size or 256
|
|
34
52
|
|
|
35
53
|
super().__init__(
|
|
54
|
+
prefill_chunk_size=prefill_chunk_size,
|
|
36
55
|
use_attention_mask=use_attention_mask,
|
|
37
56
|
use_position_ids=use_position_ids,
|
|
38
57
|
**kwargs,
|
|
39
58
|
)
|
|
40
59
|
self.image_prefill_chunk_size = image_prefill_chunk_size
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
@property
|
|
62
|
+
def use_image_prefill(self):
|
|
63
|
+
return self.image_prefill_chunk_size is not None
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def decoder_runtime_idx(self):
|
|
67
|
+
return 2 if self.use_image_prefill else 1
|
|
45
68
|
|
|
46
69
|
|
|
47
70
|
class RBLNGemma3ForConditionalGenerationConfig(RBLNModelConfig):
|
|
@@ -52,22 +75,35 @@ class RBLNGemma3ForConditionalGenerationConfig(RBLNModelConfig):
|
|
|
52
75
|
batch_size: Optional[int] = None,
|
|
53
76
|
vision_tower: Optional[RBLNModelConfig] = None,
|
|
54
77
|
language_model: Optional[RBLNModelConfig] = None,
|
|
55
|
-
**kwargs:
|
|
78
|
+
**kwargs: Any,
|
|
56
79
|
):
|
|
57
80
|
"""
|
|
58
81
|
Args:
|
|
59
82
|
batch_size (Optional[int]): The batch size for inference. Defaults to 1.
|
|
60
83
|
vision_tower (Optional[RBLNModelConfig]): Configuration for the vision encoder component.
|
|
61
84
|
language_model (Optional[RBLNModelConfig]): Configuration for the language model component.
|
|
62
|
-
|
|
85
|
+
kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
|
63
86
|
|
|
64
87
|
Raises:
|
|
65
|
-
ValueError: If batch_size is not a positive integer.
|
|
88
|
+
ValueError: If `batch_size` is not a positive integer.
|
|
66
89
|
"""
|
|
67
90
|
super().__init__(**kwargs)
|
|
68
91
|
self.batch_size = batch_size or 1
|
|
69
92
|
if not isinstance(self.batch_size, int) or self.batch_size < 0:
|
|
70
93
|
raise ValueError(f"batch_size must be a positive integer, got {self.batch_size}")
|
|
71
94
|
|
|
72
|
-
self.
|
|
73
|
-
|
|
95
|
+
if self.batch_size != 1:
|
|
96
|
+
logger.warning("Ignore batch_size for Gemma3 vision tower. It will be set to 1.")
|
|
97
|
+
|
|
98
|
+
self.vision_tower = self.initialize_submodule_config(
|
|
99
|
+
submodule_config=vision_tower, batch_size=1, force_kwargs=True
|
|
100
|
+
)
|
|
101
|
+
self.language_model = self.initialize_submodule_config(submodule_config=language_model)
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def image_prefill_chunk_size(self):
|
|
105
|
+
return self.language_model.image_prefill_chunk_size
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def prefill_chunk_size(self):
|
|
109
|
+
return self.language_model.prefill_chunk_size
|
|
@@ -63,6 +63,7 @@ class Gemma3TextModel(DecoderOnlyModel):
|
|
|
63
63
|
rotary_emb: torch.nn.Module = None,
|
|
64
64
|
global_block_tables: Optional[torch.Tensor] = None,
|
|
65
65
|
local_block_tables: Optional[torch.Tensor] = None,
|
|
66
|
+
lora_int_id: Optional[torch.Tensor] = None,
|
|
66
67
|
):
|
|
67
68
|
# retrieve input_ids and inputs_embeds
|
|
68
69
|
if (input_ids is None) ^ (inputs_embeds is not None):
|
|
@@ -105,6 +106,7 @@ class Gemma3TextModel(DecoderOnlyModel):
|
|
|
105
106
|
cos=cos_local if is_sliding else cos_global,
|
|
106
107
|
sin=sin_local if is_sliding else sin_global,
|
|
107
108
|
block_tables=local_block_tables if is_sliding else global_block_tables,
|
|
109
|
+
lora_int_id=lora_int_id,
|
|
108
110
|
)
|
|
109
111
|
|
|
110
112
|
hidden_states = self.get_last_layernorm()(hidden_states)
|
|
@@ -127,12 +129,20 @@ class Gemma3DecoderLayer(DecoderOnlyLayer):
|
|
|
127
129
|
cos: Optional[torch.Tensor] = None,
|
|
128
130
|
sin: Optional[torch.Tensor] = None,
|
|
129
131
|
block_tables: Optional[torch.Tensor] = None,
|
|
132
|
+
lora_int_id: Optional[torch.Tensor] = None,
|
|
130
133
|
):
|
|
131
134
|
residual = hidden_states
|
|
132
135
|
hidden_states = self.get_pre_attention_layernorm()(hidden_states)
|
|
133
136
|
|
|
134
137
|
hidden_states = self.self_attn(
|
|
135
|
-
hidden_states,
|
|
138
|
+
hidden_states=hidden_states,
|
|
139
|
+
attention_mask=attention_mask,
|
|
140
|
+
seq_positions=seq_positions,
|
|
141
|
+
past_key_values=past_key_values,
|
|
142
|
+
cos=cos,
|
|
143
|
+
sin=sin,
|
|
144
|
+
block_tables=block_tables,
|
|
145
|
+
lora_int_id=lora_int_id,
|
|
136
146
|
)
|
|
137
147
|
hidden_states = self.get_post_attention_layernorm()(hidden_states)
|
|
138
148
|
hidden_states = residual + hidden_states
|
|
@@ -140,7 +150,7 @@ class Gemma3DecoderLayer(DecoderOnlyLayer):
|
|
|
140
150
|
# Fully Connected
|
|
141
151
|
residual = hidden_states
|
|
142
152
|
hidden_states = self.get_pre_feedforward_layernorm()(hidden_states)
|
|
143
|
-
hidden_states = self.
|
|
153
|
+
hidden_states = self.forward_mlp(hidden_states, lora_int_id)
|
|
144
154
|
hidden_states = self.get_post_feedforward_layernorm()(hidden_states)
|
|
145
155
|
hidden_states = residual + hidden_states
|
|
146
156
|
|