optimum-rbln 0.8.0.post2__py3-none-any.whl → 0.8.1a1__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 +2 -0
- optimum/rbln/__version__.py +2 -2
- optimum/rbln/configuration_utils.py +45 -33
- optimum/rbln/diffusers/configurations/models/configuration_autoencoder_kl.py +9 -2
- optimum/rbln/diffusers/configurations/models/configuration_controlnet.py +4 -2
- optimum/rbln/diffusers/configurations/models/configuration_prior_transformer.py +9 -2
- optimum/rbln/diffusers/configurations/models/configuration_transformer_sd3.py +4 -2
- optimum/rbln/diffusers/configurations/models/configuration_unet_2d_condition.py +9 -2
- optimum/rbln/diffusers/configurations/models/configuration_vq_model.py +9 -2
- optimum/rbln/diffusers/configurations/pipelines/configuration_controlnet.py +33 -9
- optimum/rbln/diffusers/configurations/pipelines/configuration_kandinsky2_2.py +30 -12
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion.py +22 -6
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_3.py +16 -6
- optimum/rbln/diffusers/configurations/pipelines/configuration_stable_diffusion_xl.py +16 -6
- optimum/rbln/diffusers/modeling_diffusers.py +16 -26
- optimum/rbln/diffusers/models/autoencoders/autoencoder_kl.py +11 -0
- optimum/rbln/diffusers/models/autoencoders/vae.py +1 -8
- optimum/rbln/diffusers/models/autoencoders/vq_model.py +11 -0
- optimum/rbln/diffusers/models/controlnet.py +13 -7
- optimum/rbln/diffusers/models/transformers/prior_transformer.py +10 -0
- optimum/rbln/diffusers/models/transformers/transformer_sd3.py +2 -0
- optimum/rbln/diffusers/models/unets/unet_2d_condition.py +7 -0
- optimum/rbln/diffusers/pipelines/controlnet/multicontrolnet.py +1 -4
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet.py +7 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl.py +7 -0
- optimum/rbln/diffusers/pipelines/controlnet/pipeline_controlnet_sd_xl_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2.py +7 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_combined.py +48 -27
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_inpaint.py +7 -0
- optimum/rbln/diffusers/pipelines/kandinsky2_2/pipeline_kandinsky2_2_prior.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py +7 -0
- optimum/rbln/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py +7 -0
- optimum/rbln/modeling.py +33 -35
- optimum/rbln/modeling_base.py +45 -107
- optimum/rbln/transformers/__init__.py +39 -47
- optimum/rbln/transformers/configuration_generic.py +16 -13
- optimum/rbln/transformers/modeling_generic.py +18 -19
- optimum/rbln/transformers/modeling_rope_utils.py +1 -1
- optimum/rbln/transformers/models/__init__.py +46 -4
- optimum/rbln/transformers/models/audio_spectrogram_transformer/__init__.py +17 -0
- optimum/rbln/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py +21 -0
- optimum/rbln/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py +28 -0
- optimum/rbln/transformers/models/auto/auto_factory.py +30 -12
- optimum/rbln/transformers/models/blip_2/modeling_blip_2.py +35 -4
- optimum/rbln/transformers/models/clip/configuration_clip.py +3 -3
- optimum/rbln/transformers/models/clip/modeling_clip.py +11 -12
- optimum/rbln/transformers/models/decoderonly/configuration_decoderonly.py +111 -14
- optimum/rbln/transformers/models/decoderonly/decoderonly_architecture.py +102 -35
- optimum/rbln/transformers/models/decoderonly/modeling_decoderonly.py +231 -175
- optimum/rbln/transformers/models/distilbert/__init__.py +19 -0
- optimum/rbln/transformers/models/distilbert/configuration_distilbert.py +19 -0
- optimum/rbln/transformers/models/distilbert/modeling_distilbert.py +19 -0
- optimum/rbln/transformers/models/exaone/configuration_exaone.py +24 -1
- optimum/rbln/transformers/models/exaone/exaone_architecture.py +5 -1
- optimum/rbln/transformers/models/exaone/modeling_exaone.py +51 -5
- optimum/rbln/transformers/models/gemma/configuration_gemma.py +24 -1
- optimum/rbln/transformers/models/gemma/gemma_architecture.py +5 -1
- optimum/rbln/transformers/models/gemma/modeling_gemma.py +49 -0
- optimum/rbln/transformers/models/gemma3/configuration_gemma3.py +3 -3
- optimum/rbln/transformers/models/gemma3/gemma3_architecture.py +18 -250
- optimum/rbln/transformers/models/gemma3/modeling_gemma3.py +87 -236
- optimum/rbln/transformers/models/gpt2/configuration_gpt2.py +4 -1
- optimum/rbln/transformers/models/gpt2/gpt2_architecture.py +6 -1
- optimum/rbln/transformers/models/idefics3/configuration_idefics3.py +12 -2
- optimum/rbln/transformers/models/idefics3/modeling_idefics3.py +41 -4
- optimum/rbln/transformers/models/llama/configuration_llama.py +24 -1
- optimum/rbln/transformers/models/llama/modeling_llama.py +49 -0
- optimum/rbln/transformers/models/llava_next/configuration_llava_next.py +2 -2
- optimum/rbln/transformers/models/llava_next/modeling_llava_next.py +33 -4
- optimum/rbln/transformers/models/midm/configuration_midm.py +24 -1
- optimum/rbln/transformers/models/midm/midm_architecture.py +6 -1
- optimum/rbln/transformers/models/midm/modeling_midm.py +51 -5
- optimum/rbln/transformers/models/mistral/configuration_mistral.py +24 -1
- optimum/rbln/transformers/models/mistral/modeling_mistral.py +62 -4
- optimum/rbln/transformers/models/opt/configuration_opt.py +4 -1
- optimum/rbln/transformers/models/opt/modeling_opt.py +10 -0
- optimum/rbln/transformers/models/opt/opt_architecture.py +7 -1
- optimum/rbln/transformers/models/phi/configuration_phi.py +24 -1
- optimum/rbln/transformers/models/phi/modeling_phi.py +49 -0
- optimum/rbln/transformers/models/phi/phi_architecture.py +1 -1
- optimum/rbln/transformers/models/qwen2/configuration_qwen2.py +24 -1
- optimum/rbln/transformers/models/qwen2/modeling_qwen2.py +67 -4
- optimum/rbln/transformers/models/qwen2_5_vl/configuration_qwen2_5_vl.py +15 -3
- optimum/rbln/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py +46 -25
- optimum/rbln/transformers/models/qwen2_5_vl/qwen2_5_vl_architecture.py +4 -2
- optimum/rbln/transformers/models/resnet/__init__.py +23 -0
- optimum/rbln/transformers/models/resnet/configuration_resnet.py +20 -0
- optimum/rbln/transformers/models/resnet/modeling_resnet.py +22 -0
- optimum/rbln/transformers/models/roberta/__init__.py +24 -0
- optimum/rbln/transformers/{configuration_alias.py → models/roberta/configuration_roberta.py} +4 -30
- optimum/rbln/transformers/{modeling_alias.py → models/roberta/modeling_roberta.py} +2 -32
- optimum/rbln/transformers/models/seq2seq/__init__.py +1 -1
- optimum/rbln/transformers/models/seq2seq/{configuration_seq2seq2.py → configuration_seq2seq.py} +2 -2
- optimum/rbln/transformers/models/seq2seq/modeling_seq2seq.py +1 -1
- optimum/rbln/transformers/models/siglip/configuration_siglip.py +3 -0
- optimum/rbln/transformers/models/siglip/modeling_siglip.py +62 -21
- optimum/rbln/transformers/models/t5/modeling_t5.py +46 -4
- optimum/rbln/transformers/models/{time_series_transformers → time_series_transformer}/__init__.py +1 -1
- optimum/rbln/transformers/models/{time_series_transformers → time_series_transformer}/configuration_time_series_transformer.py +2 -2
- optimum/rbln/transformers/models/{time_series_transformers/modeling_time_series_transformers.py → time_series_transformer/modeling_time_series_transformer.py} +14 -9
- optimum/rbln/transformers/models/vit/__init__.py +19 -0
- optimum/rbln/transformers/models/vit/configuration_vit.py +19 -0
- optimum/rbln/transformers/models/vit/modeling_vit.py +19 -0
- optimum/rbln/transformers/models/wav2vec2/__init__.py +1 -1
- optimum/rbln/transformers/models/wav2vec2/modeling_wav2vec2.py +1 -1
- optimum/rbln/transformers/models/whisper/configuration_whisper.py +3 -1
- optimum/rbln/transformers/models/whisper/modeling_whisper.py +35 -15
- optimum/rbln/transformers/models/xlm_roberta/__init__.py +16 -2
- optimum/rbln/transformers/models/xlm_roberta/configuration_xlm_roberta.py +15 -2
- optimum/rbln/transformers/models/xlm_roberta/modeling_xlm_roberta.py +12 -3
- optimum/rbln/utils/model_utils.py +20 -0
- optimum/rbln/utils/submodule.py +6 -8
- {optimum_rbln-0.8.0.post2.dist-info → optimum_rbln-0.8.1a1.dist-info}/METADATA +1 -1
- {optimum_rbln-0.8.0.post2.dist-info → optimum_rbln-0.8.1a1.dist-info}/RECORD +127 -114
- /optimum/rbln/transformers/models/{time_series_transformers → time_series_transformer}/time_series_transformers_architecture.py +0 -0
- /optimum/rbln/transformers/models/wav2vec2/{configuration_wav2vec.py → configuration_wav2vec2.py} +0 -0
- {optimum_rbln-0.8.0.post2.dist-info → optimum_rbln-0.8.1a1.dist-info}/WHEEL +0 -0
- {optimum_rbln-0.8.0.post2.dist-info → optimum_rbln-0.8.1a1.dist-info}/licenses/LICENSE +0 -0
@@ -37,6 +37,7 @@ from ....utils.logging import get_logger
|
|
37
37
|
from ..decoderonly.modeling_decoderonly import RBLNDecoderOnlyModelForCausalLM, RBLNDecoderOnlyOutput
|
38
38
|
from .configuration_qwen2_5_vl import (
|
39
39
|
RBLNQwen2_5_VisionTransformerPretrainedModelConfig,
|
40
|
+
RBLNQwen2_5_VLForConditionalGenerationConfig,
|
40
41
|
)
|
41
42
|
from .qwen2_5_vl_architecture import Qwen2_5_VisionTransformerWrapper, Qwen2_5_VL_LanguageModelWrapper
|
42
43
|
|
@@ -338,6 +339,40 @@ class RBLNQwen2_5_VisionTransformerPretrainedModel(RBLNModel):
|
|
338
339
|
|
339
340
|
|
340
341
|
class RBLNQwen2_5_VLForConditionalGeneration(RBLNDecoderOnlyModelForCausalLM):
|
342
|
+
"""
|
343
|
+
RBLNQwen2_5_VLForConditionalGeneration is a multi-modal model that integrates vision and language processing capabilities,
|
344
|
+
optimized for RBLN NPUs. It is designed for conditional generation tasks that involve both image and text inputs.
|
345
|
+
|
346
|
+
This model inherits from [`RBLNDecoderOnlyModelForCausalLM`]. Check the superclass documentation for the generic methods the library implements for all its models.
|
347
|
+
|
348
|
+
Important Note:
|
349
|
+
This model includes a Large Language Model (LLM). For optimal performance, it is highly recommended to use
|
350
|
+
tensor parallelism for the language model. This can be achieved by using the `rbln_config` parameter in the
|
351
|
+
`from_pretrained` method. Refer to the `from_pretrained` documentation and the RBLNQwen2_5_VLForConditionalGenerationConfig class for details.
|
352
|
+
|
353
|
+
Examples:
|
354
|
+
```python
|
355
|
+
from optimum.rbln import RBLNQwen2_5_VLForConditionalGeneration
|
356
|
+
|
357
|
+
model = RBLNQwen2_5_VLForConditionalGeneration.from_pretrained(
|
358
|
+
"Qwen/Qwen2.5-VL-7B-Instruct",
|
359
|
+
export=True,
|
360
|
+
rbln_config={
|
361
|
+
"visual": {
|
362
|
+
"max_seq_lens": 6400,
|
363
|
+
"device": 0,
|
364
|
+
},
|
365
|
+
"tensor_parallel_size": 8,
|
366
|
+
"kvcache_partition_len": 16_384,
|
367
|
+
"max_seq_len": 114_688,
|
368
|
+
"device": [0, 1, 2, 3, 4, 5, 6, 7],
|
369
|
+
},
|
370
|
+
)
|
371
|
+
|
372
|
+
model.save_pretrained("compiled-qwen2.5-vl-7b-instruct")
|
373
|
+
```
|
374
|
+
"""
|
375
|
+
|
341
376
|
auto_model_class = AutoModelForVision2Seq
|
342
377
|
_rbln_submodules = [
|
343
378
|
{"name": "visual"},
|
@@ -369,33 +404,19 @@ class RBLNQwen2_5_VLForConditionalGeneration(RBLNDecoderOnlyModelForCausalLM):
|
|
369
404
|
cls,
|
370
405
|
batch_size: int,
|
371
406
|
query_length: int,
|
372
|
-
|
373
|
-
|
374
|
-
use_position_ids: bool,
|
375
|
-
max_seq_len: int,
|
376
|
-
kvcache_block_size: int,
|
377
|
-
kvcache_num_blocks: int,
|
378
|
-
num_key_value_heads: int,
|
379
|
-
num_hidden_layers: int,
|
380
|
-
hidden_size: int,
|
381
|
-
head_dim: int,
|
407
|
+
rbln_config: RBLNQwen2_5_VLForConditionalGenerationConfig,
|
408
|
+
model_config: PretrainedConfig,
|
382
409
|
):
|
383
|
-
input_info = super().get_input_info(
|
384
|
-
batch_size,
|
385
|
-
query_length,
|
386
|
-
use_inputs_embeds,
|
387
|
-
use_attention_mask,
|
388
|
-
use_position_ids,
|
389
|
-
max_seq_len,
|
390
|
-
kvcache_block_size,
|
391
|
-
kvcache_num_blocks,
|
392
|
-
num_key_value_heads,
|
393
|
-
num_hidden_layers,
|
394
|
-
hidden_size,
|
395
|
-
head_dim,
|
396
|
-
)
|
410
|
+
input_info = super().get_input_info(batch_size, query_length, rbln_config, model_config)
|
397
411
|
pos_idx = 3
|
398
|
-
input_info.insert(
|
412
|
+
input_info.insert(
|
413
|
+
pos_idx,
|
414
|
+
(
|
415
|
+
"position_emb",
|
416
|
+
[2, batch_size, 1, query_length, model_config.hidden_size // model_config.num_attention_heads],
|
417
|
+
"float32",
|
418
|
+
),
|
419
|
+
)
|
399
420
|
|
400
421
|
return input_info
|
401
422
|
|
@@ -162,7 +162,8 @@ class Qwen2_5_VL_LanguageModelWrapper(DecoderOnlyWrapper):
|
|
162
162
|
input_ids = None if self.use_inputs_embeds else args.pop(0)
|
163
163
|
inputs_embeds = args.pop(0) if self.use_inputs_embeds else None
|
164
164
|
cache_position = args.pop(0)
|
165
|
-
|
165
|
+
global_block_tables = args.pop(0)
|
166
|
+
local_block_tables = None
|
166
167
|
position_embeds = args.pop(0)
|
167
168
|
query_position = args.pop(0) if self.phase == "prefill" else None
|
168
169
|
position_ids = None
|
@@ -188,7 +189,8 @@ class Qwen2_5_VL_LanguageModelWrapper(DecoderOnlyWrapper):
|
|
188
189
|
input_ids,
|
189
190
|
inputs_embeds,
|
190
191
|
cache_position,
|
191
|
-
|
192
|
+
global_block_tables,
|
193
|
+
local_block_tables,
|
192
194
|
query_position,
|
193
195
|
attention_mask,
|
194
196
|
position_ids,
|
@@ -0,0 +1,23 @@
|
|
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 .configuration_resnet import RBLNResNetForImageClassificationConfig
|
17
|
+
from .modeling_resnet import RBLNResNetForImageClassification
|
18
|
+
|
19
|
+
|
20
|
+
__all__ = [
|
21
|
+
"RBLNResNetForImageClassificationConfig",
|
22
|
+
"RBLNResNetForImageClassification",
|
23
|
+
]
|
@@ -0,0 +1,20 @@
|
|
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 ...configuration_generic import RBLNModelForImageClassificationConfig
|
17
|
+
|
18
|
+
|
19
|
+
class RBLNResNetForImageClassificationConfig(RBLNModelForImageClassificationConfig):
|
20
|
+
""
|
@@ -0,0 +1,22 @@
|
|
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 ...modeling_generic import RBLNModelForImageClassification
|
17
|
+
|
18
|
+
|
19
|
+
class RBLNResNetForImageClassification(RBLNModelForImageClassification):
|
20
|
+
"""
|
21
|
+
ResNet model for image classification tasks on RBLN NPU.
|
22
|
+
"""
|
@@ -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_roberta import RBLNRobertaForMaskedLMConfig, RBLNRobertaForSequenceClassificationConfig
|
16
|
+
from .modeling_roberta import RBLNRobertaForMaskedLM, RBLNRobertaForSequenceClassification
|
17
|
+
|
18
|
+
|
19
|
+
__all__ = [
|
20
|
+
"RBLNRobertaForMaskedLMConfig",
|
21
|
+
"RBLNRobertaForSequenceClassificationConfig",
|
22
|
+
"RBLNRobertaForMaskedLM",
|
23
|
+
"RBLNRobertaForSequenceClassification",
|
24
|
+
]
|
optimum/rbln/transformers/{configuration_alias.py → models/roberta/configuration_roberta.py}
RENAMED
@@ -12,38 +12,12 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
from
|
16
|
-
RBLNModelForAudioClassificationConfig,
|
17
|
-
RBLNModelForImageClassificationConfig,
|
18
|
-
RBLNModelForMaskedLMConfig,
|
19
|
-
RBLNModelForQuestionAnsweringConfig,
|
20
|
-
RBLNModelForSequenceClassificationConfig,
|
21
|
-
)
|
22
|
-
|
23
|
-
|
24
|
-
class RBLNASTForAudioClassificationConfig(RBLNModelForAudioClassificationConfig):
|
25
|
-
pass
|
26
|
-
|
27
|
-
|
28
|
-
class RBLNDistilBertForQuestionAnsweringConfig(RBLNModelForQuestionAnsweringConfig):
|
29
|
-
pass
|
30
|
-
|
31
|
-
|
32
|
-
class RBLNResNetForImageClassificationConfig(RBLNModelForImageClassificationConfig):
|
33
|
-
pass
|
34
|
-
|
35
|
-
|
36
|
-
class RBLNXLMRobertaForSequenceClassificationConfig(RBLNModelForSequenceClassificationConfig):
|
37
|
-
pass
|
38
|
-
|
39
|
-
|
40
|
-
class RBLNRobertaForSequenceClassificationConfig(RBLNModelForSequenceClassificationConfig):
|
41
|
-
pass
|
15
|
+
from ...configuration_generic import RBLNModelForMaskedLMConfig, RBLNModelForSequenceClassificationConfig
|
42
16
|
|
43
17
|
|
44
18
|
class RBLNRobertaForMaskedLMConfig(RBLNModelForMaskedLMConfig):
|
45
|
-
|
19
|
+
""
|
46
20
|
|
47
21
|
|
48
|
-
class
|
49
|
-
|
22
|
+
class RBLNRobertaForSequenceClassificationConfig(RBLNModelForSequenceClassificationConfig):
|
23
|
+
""
|
@@ -12,42 +12,12 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
from
|
16
|
-
from .modeling_generic import (
|
17
|
-
RBLNModelForAudioClassification,
|
18
|
-
RBLNModelForImageClassification,
|
19
|
-
RBLNModelForMaskedLM,
|
20
|
-
RBLNModelForQuestionAnswering,
|
21
|
-
RBLNModelForSequenceClassification,
|
22
|
-
)
|
15
|
+
from ...modeling_generic import RBLNModelForMaskedLM, RBLNModelForSequenceClassification
|
23
16
|
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
class RBLNASTForAudioClassification(RBLNModelForAudioClassification):
|
29
|
-
pass
|
30
|
-
|
31
|
-
|
32
|
-
class RBLNDistilBertForQuestionAnswering(RBLNModelForQuestionAnswering):
|
33
|
-
rbln_model_input_names = ["input_ids", "attention_mask"]
|
34
|
-
|
35
|
-
|
36
|
-
class RBLNResNetForImageClassification(RBLNModelForImageClassification):
|
37
|
-
pass
|
38
|
-
|
39
|
-
|
40
|
-
class RBLNXLMRobertaForSequenceClassification(RBLNModelForSequenceClassification):
|
18
|
+
class RBLNRobertaForMaskedLM(RBLNModelForMaskedLM):
|
41
19
|
rbln_model_input_names = ["input_ids", "attention_mask"]
|
42
20
|
|
43
21
|
|
44
22
|
class RBLNRobertaForSequenceClassification(RBLNModelForSequenceClassification):
|
45
23
|
rbln_model_input_names = ["input_ids", "attention_mask"]
|
46
|
-
|
47
|
-
|
48
|
-
class RBLNRobertaForMaskedLM(RBLNModelForMaskedLM):
|
49
|
-
rbln_model_input_names = ["input_ids", "attention_mask"]
|
50
|
-
|
51
|
-
|
52
|
-
class RBLNViTForImageClassification(RBLNModelForImageClassification):
|
53
|
-
pass
|
@@ -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 .
|
15
|
+
from .configuration_seq2seq import RBLNModelForSeq2SeqLMConfig
|
16
16
|
from .modeling_seq2seq import RBLNModelForSeq2SeqLM
|
optimum/rbln/transformers/models/seq2seq/{configuration_seq2seq2.py → configuration_seq2seq.py}
RENAMED
@@ -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 typing import Optional
|
15
|
+
from typing import Any, Dict, Optional
|
16
16
|
|
17
17
|
import rebel
|
18
18
|
|
@@ -31,7 +31,7 @@ class RBLNModelForSeq2SeqLMConfig(RBLNModelConfig):
|
|
31
31
|
dec_max_seq_len: Optional[int] = None,
|
32
32
|
use_attention_mask: Optional[bool] = None,
|
33
33
|
pad_token_id: Optional[int] = None,
|
34
|
-
**kwargs,
|
34
|
+
**kwargs: Dict[str, Any],
|
35
35
|
):
|
36
36
|
"""
|
37
37
|
Args:
|
@@ -26,7 +26,7 @@ from ....configuration_utils import RBLNCompileConfig
|
|
26
26
|
from ....modeling import RBLNModel
|
27
27
|
from ....utils.logging import get_logger
|
28
28
|
from ....utils.runtime_utils import RBLNPytorchRuntime
|
29
|
-
from .
|
29
|
+
from .configuration_seq2seq import RBLNModelForSeq2SeqLMConfig
|
30
30
|
|
31
31
|
|
32
32
|
logger = get_logger(__name__)
|
@@ -24,6 +24,7 @@ class RBLNSiglipVisionModelConfig(RBLNModelConfig):
|
|
24
24
|
image_size: Optional[int] = None,
|
25
25
|
interpolate_pos_encoding: Optional[bool] = None,
|
26
26
|
output_hidden_states: Optional[bool] = None,
|
27
|
+
output_attentions: Optional[bool] = None,
|
27
28
|
**kwargs,
|
28
29
|
):
|
29
30
|
"""
|
@@ -33,6 +34,7 @@ class RBLNSiglipVisionModelConfig(RBLNModelConfig):
|
|
33
34
|
a tuple/list (height, width), or a dictionary with 'height' and 'width' keys.
|
34
35
|
interpolate_pos_encoding (Optional[bool]): Whether to interpolate the position encoding.
|
35
36
|
output_hidden_states: (Optional[bool]): Whether to return hidden states.
|
37
|
+
output_attentions: (Optional[bool]): Whether to return attentions.
|
36
38
|
**kwargs: Additional arguments passed to the parent RBLNModelConfig.
|
37
39
|
|
38
40
|
Raises:
|
@@ -46,6 +48,7 @@ class RBLNSiglipVisionModelConfig(RBLNModelConfig):
|
|
46
48
|
self.image_size = image_size
|
47
49
|
self.interpolate_pos_encoding = interpolate_pos_encoding or False
|
48
50
|
self.output_hidden_states = output_hidden_states
|
51
|
+
self.output_attentions = output_attentions
|
49
52
|
|
50
53
|
@property
|
51
54
|
def image_width(self):
|
@@ -12,12 +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 TYPE_CHECKING, Optional, Tuple, Union
|
15
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
|
16
16
|
|
17
17
|
import torch
|
18
18
|
from transformers import SiglipVisionConfig, SiglipVisionModel
|
19
19
|
from transformers.modeling_outputs import BaseModelOutputWithPooling
|
20
|
-
from transformers.models.siglip.modeling_siglip import SiglipVisionModelOutput
|
21
20
|
|
22
21
|
from ....configuration_utils import RBLNCompileConfig
|
23
22
|
from ....modeling import RBLNModel
|
@@ -34,11 +33,18 @@ if TYPE_CHECKING:
|
|
34
33
|
|
35
34
|
|
36
35
|
class _SiglipVisionModel(torch.nn.Module):
|
37
|
-
def __init__(
|
36
|
+
def __init__(
|
37
|
+
self,
|
38
|
+
model: SiglipVisionModel,
|
39
|
+
interpolate_pos_encoding: bool,
|
40
|
+
output_hidden_states: bool,
|
41
|
+
output_attentions: bool,
|
42
|
+
):
|
38
43
|
super().__init__()
|
39
44
|
self.vision_model = model.vision_model
|
40
45
|
self.interpolate_pos_encoding = interpolate_pos_encoding
|
41
46
|
self.output_hidden_states = output_hidden_states
|
47
|
+
self.output_attentions = output_attentions
|
42
48
|
|
43
49
|
def forward(self, inp):
|
44
50
|
enc_out = self.vision_model(
|
@@ -46,6 +52,7 @@ class _SiglipVisionModel(torch.nn.Module):
|
|
46
52
|
output_hidden_states=self.output_hidden_states,
|
47
53
|
return_dict=False,
|
48
54
|
interpolate_pos_encoding=self.interpolate_pos_encoding,
|
55
|
+
output_attentions=self.output_attentions,
|
49
56
|
)
|
50
57
|
return tuple(x for x in enc_out if x is not None)
|
51
58
|
|
@@ -56,6 +63,7 @@ class RBLNSiglipVisionModel(RBLNModel):
|
|
56
63
|
wrapper_cfg = {
|
57
64
|
"interpolate_pos_encoding": rbln_config.interpolate_pos_encoding,
|
58
65
|
"output_hidden_states": rbln_config.output_hidden_states,
|
66
|
+
"output_attentions": rbln_config.output_attentions,
|
59
67
|
}
|
60
68
|
return _SiglipVisionModel(model, **wrapper_cfg).eval()
|
61
69
|
|
@@ -81,8 +89,10 @@ class RBLNSiglipVisionModel(RBLNModel):
|
|
81
89
|
if rbln_config.image_size is None:
|
82
90
|
raise ValueError("`rbln_image_size` should be specified!")
|
83
91
|
|
92
|
+
if rbln_config.output_attentions is None:
|
93
|
+
rbln_config.output_attentions = getattr(model_config, "output_attentions", False)
|
84
94
|
if rbln_config.output_hidden_states is None:
|
85
|
-
rbln_config.output_hidden_states = model_config
|
95
|
+
rbln_config.output_hidden_states = getattr(model_config, "output_hidden_states", False)
|
86
96
|
|
87
97
|
rbln_compile_config = RBLNCompileConfig(
|
88
98
|
input_info=[
|
@@ -104,43 +114,74 @@ class RBLNSiglipVisionModel(RBLNModel):
|
|
104
114
|
|
105
115
|
def forward(
|
106
116
|
self,
|
107
|
-
pixel_values:
|
117
|
+
pixel_values: torch.Tensor,
|
108
118
|
return_dict: bool = None,
|
119
|
+
output_attentions: bool = None,
|
120
|
+
output_hidden_states: bool = None,
|
109
121
|
interpolate_pos_encoding: bool = False,
|
110
|
-
**kwargs,
|
111
|
-
) -> Union[Tuple,
|
112
|
-
if len(kwargs) > 0 and any(kwargs.values()):
|
113
|
-
logger.warning(
|
122
|
+
**kwargs: Dict[str, Any],
|
123
|
+
) -> Union[Tuple, BaseModelOutputWithPooling]:
|
124
|
+
if len(kwargs) > 0 and any(value is not None for value in kwargs.values()):
|
125
|
+
logger.warning(
|
126
|
+
f"Currently, optimum-rbln does not support kwargs {kwargs.keys()} for {self.__class__.__name__}."
|
127
|
+
)
|
128
|
+
|
129
|
+
output_attentions = output_attentions if output_attentions is not None else self.rbln_config.output_attentions
|
130
|
+
output_hidden_states = (
|
131
|
+
output_hidden_states if output_hidden_states is not None else self.rbln_config.output_hidden_states
|
132
|
+
)
|
133
|
+
|
134
|
+
if output_attentions != self.rbln_config.output_attentions:
|
135
|
+
raise ValueError(
|
136
|
+
f"Variable output_attentions {output_attentions} is not equal to rbln_config.output_attentions {self.rbln_config.output_attentions} "
|
137
|
+
f"Please compile again with the correct argument."
|
138
|
+
)
|
139
|
+
|
140
|
+
if output_hidden_states != self.rbln_config.output_hidden_states:
|
141
|
+
raise ValueError(
|
142
|
+
f"Variable output_hidden_states {output_hidden_states} is not equal to rbln_config.output_hidden_states {self.rbln_config.output_hidden_states} "
|
143
|
+
f"Please compile again with the correct argument."
|
144
|
+
)
|
114
145
|
|
115
146
|
if interpolate_pos_encoding != self.rbln_config.interpolate_pos_encoding:
|
116
147
|
raise ValueError(
|
117
|
-
f"Variable interpolate_pos_encoding {interpolate_pos_encoding} is not equal to rbln_config.interpolate_pos_encoding {self.rbln_config.interpolate_pos_encoding}"
|
148
|
+
f"Variable interpolate_pos_encoding {interpolate_pos_encoding} is not equal to rbln_config.interpolate_pos_encoding {self.rbln_config.interpolate_pos_encoding} "
|
118
149
|
f"Please compile again with the correct argument."
|
119
150
|
)
|
151
|
+
|
120
152
|
output = super().forward(pixel_values, return_dict=return_dict)
|
121
153
|
return output
|
122
154
|
|
123
155
|
def _prepare_output(self, output, return_dict):
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
"""
|
156
|
+
# Prepare model output based on return_dict flag.
|
157
|
+
# This method can be overridden by subclasses to provide task-specific output handling.
|
158
|
+
|
128
159
|
if not return_dict:
|
129
160
|
return (output,) if not isinstance(output, (tuple, list)) else output
|
130
161
|
else:
|
131
|
-
last_hidden_state = (
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
)
|
136
|
-
pooler_output = output[1] if self.rbln_config.interpolate_pos_encoding else None
|
162
|
+
last_hidden_state = output.pop(0) if isinstance(output, (tuple, list)) else output
|
163
|
+
vision_config = self.config.vision_config if hasattr(self.config, "vision_config") else self.config
|
164
|
+
pooler_output = output.pop(0) if getattr(vision_config, "vision_use_head", True) else None
|
165
|
+
|
137
166
|
if self.rbln_config.output_hidden_states:
|
138
|
-
hidden_states = (
|
167
|
+
hidden_states = ()
|
168
|
+
num_hidden_layers = vision_config.num_hidden_layers
|
169
|
+
for _ in range(num_hidden_layers + 1):
|
170
|
+
hidden_states += (output.pop(0),)
|
139
171
|
else:
|
140
172
|
hidden_states = None
|
141
173
|
|
174
|
+
if self.rbln_config.output_attentions:
|
175
|
+
attentions = ()
|
176
|
+
num_hidden_layers = vision_config.num_hidden_layers
|
177
|
+
for _ in range(num_hidden_layers):
|
178
|
+
attentions += (output.pop(0),)
|
179
|
+
else:
|
180
|
+
attentions = None
|
181
|
+
|
142
182
|
return BaseModelOutputWithPooling(
|
143
183
|
last_hidden_state=last_hidden_state,
|
144
184
|
pooler_output=pooler_output,
|
145
185
|
hidden_states=hidden_states,
|
186
|
+
attentions=attentions,
|
146
187
|
)
|
@@ -41,6 +41,28 @@ class T5EncoderWrapper(torch.nn.Module):
|
|
41
41
|
|
42
42
|
|
43
43
|
class RBLNT5EncoderModel(RBLNTransformerEncoderForFeatureExtraction):
|
44
|
+
"""
|
45
|
+
The T5 Model transformer with an encoder-only architecture for feature extraction.
|
46
|
+
This model inherits from [`RBLNTransformerEncoderForFeatureExtraction`]. Check the superclass documentation for the generic methods the library implements for all its models.
|
47
|
+
|
48
|
+
Important Note:
|
49
|
+
This model supports various sizes of the T5EncoderModel. For optimal performance, it is highly recommended to adjust the tensor parallelism setting
|
50
|
+
based on the model size. Please refer to the [Optimum RBLN Overview](../../../optimum_rbln.md) for guidance on choosing the appropriate tensor parallelism size for your model.
|
51
|
+
|
52
|
+
Examples:
|
53
|
+
```python
|
54
|
+
from optimum.rbln import RBLNT5EncoderModel
|
55
|
+
|
56
|
+
model = RBLNT5EncoderModel.from_pretrained(
|
57
|
+
"sentence-transformers/sentence-t5-xxl",
|
58
|
+
export=True,
|
59
|
+
rbln_tensor_parallel_size=4,
|
60
|
+
)
|
61
|
+
|
62
|
+
model.save_pretrained("compiled-sentence-t5-xxl")
|
63
|
+
```
|
64
|
+
"""
|
65
|
+
|
44
66
|
auto_model_class = AutoModelForTextEncoding
|
45
67
|
rbln_model_input_names = ["input_ids", "attention_mask"]
|
46
68
|
|
@@ -50,10 +72,7 @@ class RBLNT5EncoderModel(RBLNTransformerEncoderForFeatureExtraction):
|
|
50
72
|
|
51
73
|
@classmethod
|
52
74
|
def update_rbln_config_using_pipe(
|
53
|
-
cls,
|
54
|
-
pipe: "RBLNDiffusionMixin",
|
55
|
-
rbln_config: "RBLNDiffusionMixinConfig",
|
56
|
-
submodule_name: str,
|
75
|
+
cls, pipe: "RBLNDiffusionMixin", rbln_config: "RBLNDiffusionMixinConfig", submodule_name: str
|
57
76
|
) -> "RBLNDiffusionMixinConfig":
|
58
77
|
submodule_config = getattr(rbln_config, submodule_name)
|
59
78
|
submodule_config.max_seq_len = rbln_config.max_seq_len or 256
|
@@ -62,6 +81,29 @@ class RBLNT5EncoderModel(RBLNTransformerEncoderForFeatureExtraction):
|
|
62
81
|
|
63
82
|
|
64
83
|
class RBLNT5ForConditionalGeneration(RBLNModelForSeq2SeqLM):
|
84
|
+
"""
|
85
|
+
The T5 Model transformer with a language modeling head for conditional generation.
|
86
|
+
This model inherits from [`RBLNModelForSeq2SeqLM`]. Check the superclass documentation for the generic methods the library implements for all its models.
|
87
|
+
|
88
|
+
Important Note:
|
89
|
+
This model supports various sizes of the T5ForConditionalGeneration. For optimal performance, it is highly recommended to adjust the tensor parallelism setting
|
90
|
+
based on the model size. Please refer to the [Optimum RBLN Overview](../../../optimum_rbln.md) for guidance on choosing the appropriate tensor parallelism size for your model.
|
91
|
+
|
92
|
+
|
93
|
+
Examples:
|
94
|
+
```python
|
95
|
+
from optimum.rbln import RBLNT5ForConditionalGeneration
|
96
|
+
|
97
|
+
model = RBLNT5ForConditionalGeneration.from_pretrained(
|
98
|
+
"google-t5/t5-11b",
|
99
|
+
export=True,
|
100
|
+
rbln_tensor_parallel_size=4,
|
101
|
+
)
|
102
|
+
|
103
|
+
model.save_pretrained("compiled-sentence-t5-xxl")
|
104
|
+
```
|
105
|
+
"""
|
106
|
+
|
65
107
|
support_causal_attn = False
|
66
108
|
|
67
109
|
@classmethod
|
optimum/rbln/transformers/models/{time_series_transformers → time_series_transformer}/__init__.py
RENAMED
@@ -23,4 +23,4 @@
|
|
23
23
|
|
24
24
|
from ....ops import paged_add_softmax_attn_decode, rbln_cache_update
|
25
25
|
from .configuration_time_series_transformer import RBLNTimeSeriesTransformerForPredictionConfig
|
26
|
-
from .
|
26
|
+
from .modeling_time_series_transformer import RBLNTimeSeriesTransformerForPrediction
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Optional
|
1
|
+
from typing import Any, Dict, Optional
|
2
2
|
|
3
3
|
from ....configuration_utils import RBLNModelConfig
|
4
4
|
|
@@ -10,7 +10,7 @@ class RBLNTimeSeriesTransformerForPredictionConfig(RBLNModelConfig):
|
|
10
10
|
enc_max_seq_len: Optional[int] = None,
|
11
11
|
dec_max_seq_len: Optional[int] = None,
|
12
12
|
num_parallel_samples: Optional[int] = None,
|
13
|
-
**kwargs,
|
13
|
+
**kwargs: Dict[str, Any],
|
14
14
|
):
|
15
15
|
"""
|
16
16
|
Args:
|
@@ -120,6 +120,17 @@ class RBLNSeq2SeqTSDecoderOutput(ModelOutput):
|
|
120
120
|
|
121
121
|
|
122
122
|
class RBLNTimeSeriesTransformerForPrediction(RBLNModel):
|
123
|
+
"""
|
124
|
+
The Time Series Transformer Model with a distribution head on top for time-series forecasting. e.g., for datasets like M4, NN5, or other time series forecasting benchmarks.
|
125
|
+
This model inherits from [`RBLNModel`]. Check the superclass documentation for the generic methods the library implements for all its models.
|
126
|
+
|
127
|
+
A class to convert and run pre-trained transformer-based `TimeSeriesTransformerForPrediction` models on RBLN devices.
|
128
|
+
It implements the methods to convert a pre-trained transformers `TimeSeriesTransformerForPrediction` model into a RBLN transformer model by:
|
129
|
+
|
130
|
+
- transferring the checkpoint weights of the original into an optimized RBLN graph,
|
131
|
+
- compiling the resulting graph using the RBLN Compiler.
|
132
|
+
"""
|
133
|
+
|
123
134
|
auto_model_class = None
|
124
135
|
main_input_name = "inputs_embeds"
|
125
136
|
|
@@ -144,11 +155,6 @@ class RBLNTimeSeriesTransformerForPrediction(RBLNModel):
|
|
144
155
|
)
|
145
156
|
|
146
157
|
def __getattr__(self, __name: str) -> Any:
|
147
|
-
"""This is the key method to implement RBLN-TimeSeriesTransformersForPrediction.
|
148
|
-
Returns:
|
149
|
-
Any: TimeSeriesTransformersForPrediction's corresponding method
|
150
|
-
"""
|
151
|
-
|
152
158
|
def redirect(func):
|
153
159
|
return lambda *pargs, **kwargs: func(self, *pargs, **kwargs)
|
154
160
|
|
@@ -211,10 +217,9 @@ class RBLNTimeSeriesTransformerForPrediction(RBLNModel):
|
|
211
217
|
subfolder: str,
|
212
218
|
rbln_config: RBLNTimeSeriesTransformerForPredictionConfig,
|
213
219
|
):
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
"""
|
220
|
+
# If you are unavoidably running on a CPU rather than an RBLN device,
|
221
|
+
# store the torch tensor, weight, etc. in this function.
|
222
|
+
|
218
223
|
save_dict = {}
|
219
224
|
save_dict["embedder"] = model.model.embedder.state_dict()
|
220
225
|
torch.save(save_dict, save_dir_path / subfolder / "torch_artifacts.pth")
|