llava
mindnlp.transformers.models.llava.configuration_llava
¶
Llava model configuration
mindnlp.transformers.models.llava.configuration_llava.LlavaConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [LlavaForConditionalGeneration
]. It is used to instantiate an
Llava model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the Llava-9B.
e.g. llava-hf/llava-9b
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
vision_config |
The config object or dictionary of the vision backbone.
TYPE:
|
text_config |
The config object or dictionary of the text backbone.
TYPE:
|
ignore_index |
The ignore index for the loss function.
TYPE:
|
image_token_index |
The image token index to encode the image prompt.
TYPE:
|
projector_hidden_act |
The activation function used by the multimodal projector.
TYPE:
|
vision_feature_select_strategy |
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of
TYPE:
|
vision_feature_layer |
The index of the layer to select the vision feature.
TYPE:
|
Example
>>> from transformers import LlavaForConditionalGeneration, LlavaConfig, CLIPVisionConfig, LlamaConfig
...
>>> # Initializing a CLIP-vision config
>>> vision_config = CLIPVisionConfig()
...
>>> # Initializing a Llama config
>>> text_config = LlamaConfig()
...
>>> # Initializing a Llava llava-1.5-7b style configuration
>>> configuration = LlavaConfig(vision_config, text_config)
...
>>> # Initializing a model from the llava-1.5-7b style configuration
>>> model = LlavaForConditionalGeneration(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/llava/configuration_llava.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
mindnlp.transformers.models.llava.configuration_llava.LlavaConfig.vocab_size
property
writable
¶
Method to retrieve the vocabulary size.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaConfig class. This parameter refers to the current instance of the LlavaConfig class. It is used to access the internal attributes and configurations of the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
FutureWarning
|
This method raises a FutureWarning when accessed, indicating that the 'vocab_size' attribute is deprecated. Users are advised to use 'text_config.vocab_size' instead. |
mindnlp.transformers.models.llava.configuration_llava.LlavaConfig.__init__(vision_config=None, text_config=None, ignore_index=-100, image_token_index=32000, projector_hidden_act='gelu', vision_feature_select_strategy='default', vision_feature_layer=-2, **kwargs)
¶
Initializes an instance of the LlavaConfig class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vision_config |
Configuration options for the vision model. If provided as a dictionary, must include the 'model_type' key. Default is None.
TYPE:
|
text_config |
Configuration options for the text model. If provided as a dictionary, must include the 'model_type' key. Default is None.
TYPE:
|
ignore_index |
The index to ignore during computations. Default is -100.
TYPE:
|
image_token_index |
The index assigned to image tokens. Default is 32000.
TYPE:
|
projector_hidden_act |
The activation function for the projector. Default is 'gelu'.
TYPE:
|
vision_feature_select_strategy |
The strategy to select vision features. Valid values are 'default' and 'full'. Default is 'default'.
TYPE:
|
vision_feature_layer |
The layer to extract vision features from. Default is -2.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the provided vision_feature_select_strategy is not 'default' or 'full'. |
FutureWarning
|
If the 'vocab_size' argument is deprecated and no longer has any effect. |
Note
- The 'vision_config' parameter can be provided as a dictionary or None. If a dictionary is provided, it must include the 'model_type' key.
- If 'vision_config' is None, a default configuration is used.
- The 'text_config' parameter can be provided as a dictionary or None. If a dictionary is provided, it must include the 'model_type' key.
- If 'text_config' is None, a default configuration is used.
- The '_vocab_size' attribute is set based on the 'text_config' vocabulary size.
Source code in mindnlp/transformers/models/llava/configuration_llava.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
mindnlp.transformers.models.llava.configuration_llava.LlavaConfig.to_dict()
¶
Converts the LlavaConfig object into a dictionary representation.
PARAMETER | DESCRIPTION |
---|---|
self |
The LlavaConfig object itself.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary representation of the LlavaConfig object, excluding the '_vocab_size' attribute. |
Note
This method is inherited from the parent class and modified to exclude the '_vocab_size' attribute from the output dictionary.
Source code in mindnlp/transformers/models/llava/configuration_llava.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
mindnlp.transformers.models.llava.modeling_llava
¶
MindSpore Llava model.
mindnlp.transformers.models.llava.modeling_llava.LlavaCausalLMOutputWithPast
dataclass
¶
Bases: ModelOutput
Base class for Llava causal language model (or autoregressive) outputs.
PARAMETER | DESCRIPTION |
---|---|
loss |
Language modeling loss (for next-token prediction).
TYPE:
|
logits |
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
TYPE:
|
image_hidden_states |
Tuple of image_hidden_states of the model produced by the vision encoder, and optionally by the perceiver
TYPE:
|
Source code in mindnlp/transformers/models/llava/modeling_llava.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration
¶
Bases: LlavaPreTrainedModel
LlavaForConditionalGeneration
This class is a language model for conditional generation based on the Llava architecture. It extends the LlavaPreTrainedModel class.
ATTRIBUTE | DESCRIPTION |
---|---|
vision_tower |
The vision tower model for extracting image features.
TYPE:
|
multi_modal_projector |
The multi-modal projector for combining image and text features.
TYPE:
|
vocab_size |
The size of the vocabulary used by the language model.
TYPE:
|
language_model |
The language model for generating text.
TYPE:
|
pad_token_id |
The ID of the padding token in the vocabulary. Defaults to -1 if not provided.
TYPE:
|
Example
>>> from PIL import Image
>>> import requests
>>> from transformers import LlavaForConditionalGeneration
...
>>> model = LlavaForConditionalGeneration(config)
...
>>> input_ids = [1, 2, 3]
>>> pixel_values = [0.1, 0.2, 0.3]
>>> attention_mask = [1, 1, 1]
...
>>> output = model.forward(input_ids=input_ids, pixel_values=pixel_values, attention_mask=attention_mask)
Source code in mindnlp/transformers/models/llava/modeling_llava.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.__init__(config)
¶
Initializes an instance of the LlavaForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of type LlavaConfig containing the configuration settings for the model. It specifies the configuration parameters for the vision tower, multi-modal projector, vocab size, language model, pad token id, and other model settings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.forward(input_ids=None, pixel_values=None, attention_mask=None, position_ids=None, past_key_values=None, inputs_embeds=None, vision_feature_layer=None, vision_feature_select_strategy=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, LlavaCausalLMOutputWithPast]
|
Union[Tuple, LlavaCausalLMOutputWithPast] |
Example
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, LlavaForConditionalGeneration
...
>>> model = LlavaForConditionalGeneration.from_pretrained("llava-hf/llava-1.5-7b-hf")
>>> processor = AutoProcessor.from_pretrained("llava-hf/llava-1.5-7b-hf")
...
>>> prompt = "USER: <image>\nWhat's the content of the image? ASSISTANT:"
>>> url = "https://www.ilankelman.org/stopsigns/australia.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
...
>>> inputs = processor(text=prompt, images=image, return_tensors="pt")
...
>>> # Generate
>>> generate_ids = model.generate(**inputs, max_new_tokens=15)
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"USER: \nWhat's the content of the image? ASSISTANT: The image features a busy city street with a stop sign prominently displayed"
Source code in mindnlp/transformers/models/llava/modeling_llava.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.get_decoder()
¶
Returns the decoder of the LlavaForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
The decoder from the language model used by the LlavaForConditionalGeneration model. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.get_input_embeddings()
¶
Get the input embeddings from the language model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaForConditionalGeneration class. |
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.get_output_embeddings()
¶
Retrieve the output embeddings from the language model used for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None, it simply delegates the call to the language model's get_output_embeddings method. |
RAISES | DESCRIPTION |
---|---|
None
|
However, if the language_model.get_output_embeddings() method raises any exceptions, they will propagate up to the caller. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.prepare_inputs_for_generation(input_ids, past_key_values=None, inputs_embeds=None, pixel_values=None, attention_mask=None, **kwargs)
¶
Prepares inputs for text generation in the LlavaForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaForConditionalGeneration class. |
input_ids |
The input tensor containing the tokenized input sequence.
TYPE:
|
past_key_values |
The cache of past key values or tuple of tensors containing past key values.
TYPE:
|
inputs_embeds |
The input embeddings tensor.
TYPE:
|
pixel_values |
The tensor containing the pixel values.
TYPE:
|
attention_mask |
The attention mask tensor.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared model inputs for text generation. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.resize_token_embeddings(new_num_tokens=None, pad_to_multiple_of=None)
¶
Resize the token embeddings for conditional generation in the LlavaForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaForConditionalGeneration class.
|
new_num_tokens |
The new number of tokens to resize the embeddings to. Defaults to None. If provided, the token embeddings will be resized to accommodate this number of tokens.
TYPE:
|
pad_to_multiple_of |
The value to pad the token embeddings to a multiple of. Defaults to None. If provided, the token embeddings will be padded to a multiple of this value.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Embedding
|
nn.Embedding: The resized token embeddings after the operation. This updated nn.Embedding object reflects the changes made to the token embeddings. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.set_decoder(decoder)
¶
Sets the decoder for the language model used in LlavaForConditionalGeneration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaForConditionalGeneration class. |
decoder |
The decoder object to be set for the language model. It should be compatible with the language model's requirements.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided decoder is not of the correct type. |
ValueError
|
If the decoder object is invalid or incompatible with the language model. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.set_input_embeddings(value)
¶
Set the input embeddings for the LlavaForConditionalGeneration language model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaForConditionalGeneration class. |
value |
The input embeddings to be set for the language model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the LlavaForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaForConditionalGeneration class. |
new_embeddings |
The new output embeddings to be set for the model. It should have the same shape as the original output embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided new_embeddings parameter is not of type Tensor. |
ValueError
|
If the shape of the new_embeddings parameter does not match the shape of the original output embeddings. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaForConditionalGeneration.tie_weights()
¶
Ties the weights of the language model used for conditional generation in the LlavaForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaForConditionalGeneration class. |
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaMultiModalProjector
¶
Bases: Module
LlavaMultiModalProjector is a class representing a multi-modal projector for processing image and text data simultaneously. It facilitates the transformation of image features through linear layers with activation functions to map them to text features.
This class inherits from nn.Module and contains methods for initialization and forwarding the projection of image features to text features. The initialization method initializes the linear layers and activation function based on the provided configuration. The forward method applies the linear transformations and activation functions to the input image features to generate the final hidden states for text representation.
Example
>>> config = LlavaConfig(vision_config=..., text_config=..., projector_hidden_act=...)
>>> projector = LlavaMultiModalProjector(config)
>>> hidden_states = projector.forward(image_features)
Source code in mindnlp/transformers/models/llava/modeling_llava.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaMultiModalProjector.__init__(config)
¶
Initializes an instance of the LlavaMultiModalProjector class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object containing the settings for the projector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaMultiModalProjector.forward(image_features)
¶
This method forwards a multi-modal projector within the LlavaMultiModalProjector class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaMultiModalProjector class.
TYPE:
|
image_features |
The input tensor containing image features.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tensor
|
The hidden states tensor obtained after processing the image features through linear and activation layers. |
Source code in mindnlp/transformers/models/llava/modeling_llava.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
mindnlp.transformers.models.llava.modeling_llava.LlavaPreTrainedModel
¶
Bases: PreTrainedModel
The LlavaPreTrainedModel
class is a subclass of the PreTrainedModel
class in the Hugging Face library.
It represents a pre-trained model for natural language processing tasks.
This class provides functionality for initializing the weights of the model's cells.
The _init_weights
method is used to set the initial weights of the model's cells based on the specified configuration.
The method supports different types of cells, including Dense
, Conv2d
, and Embedding
.
If the cell has a class_embedding
attribute, the method initializes it using a normal distribution with
a standard deviation specified by the initializer_range
attribute of the configuration.
For Dense
and Conv2d
cells, the method initializes the weight
attribute using a normal distribution
with the same standard deviation as above. If the cell has a bias
attribute, it is initialized with zeros.
For Embedding
cells, the method initializes the weight
attribute using a normal distribution with the same
standard deviation as above. If the cell has a padding_idx
attribute, the corresponding element in the
weight matrix is set to zero.
Note
The LlavaPreTrainedModel
class assumes that the PreTrainedModel
class is available in the code environment.
Source code in mindnlp/transformers/models/llava/modeling_llava.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
mindnlp.transformers.models.llava.processing_llava
¶
Processor class for Llava.
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor
¶
Bases: ProcessorMixin
Constructs a Llava processor which wraps a Llava image processor and a Llava tokenizer into a single processor.
[LlavaProcessor
] offers all the functionalities of [CLIPImageProcessor
] and [LlamaTokenizerFast
]. See the
[~LlavaProcessor.__call__
] and [~LlavaProcessor.decode
] for more information.
PARAMETER | DESCRIPTION |
---|---|
image_processor |
The image processor is a required input.
TYPE:
|
tokenizer |
The tokenizer is a required input.
TYPE:
|
Source code in mindnlp/transformers/models/llava/processing_llava.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor.model_input_names
property
¶
Retrieve the unique model input names from the tokenizer and image processor.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaProcessor class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
A list of unique model input names extracted from the tokenizer and image processor. |
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor.__call__(text=None, images=None, padding=False, truncation=None, max_length=None, return_tensors=None)
¶
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the text
and kwargs
arguments to LlamaTokenizerFast's [~LlamaTokenizerFast.__call__
] if text
is not None
to encode
the text. To prepare the image(s), this method forwards the images
and kwrags
arguments to
CLIPImageProcessor's [~CLIPImageProcessor.__call__
] if images
is not None
. Please refer to the doctsring
of the above two methods for more information.
PARAMETER | DESCRIPTION |
---|---|
text |
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
TYPE:
|
images |
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch tensor. Both channels-first and channels-last formats are supported.
TYPE:
|
padding |
Select a strategy to pad the returned sequences (according to the model's padding side and padding index) among:
TYPE:
|
max_length |
Maximum length of the returned list and optionally padding length (see above).
TYPE:
|
truncation |
Activates truncation to cut input sequences longer than
TYPE:
|
return_tensors |
If set, will return tensors of a particular framework. Acceptable values are:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchFeature
|
[
|
Source code in mindnlp/transformers/models/llava/processing_llava.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor.__init__(image_processor=None, tokenizer=None)
¶
Initializes a new instance of the LlavaProcessor class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the LlavaProcessor class.
TYPE:
|
image_processor |
An object that handles image processing operations. Defaults to None.
TYPE:
|
tokenizer |
An object that handles tokenization operations. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava/processing_llava.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor.batch_decode(*args, **kwargs)
¶
This method forwards all its arguments to LlamaTokenizerFast's [~PreTrainedTokenizer.batch_decode
]. Please
refer to the docstring of this method for more information.
Source code in mindnlp/transformers/models/llava/processing_llava.py
130 131 132 133 134 135 |
|
mindnlp.transformers.models.llava.processing_llava.LlavaProcessor.decode(*args, **kwargs)
¶
This method forwards all its arguments to LlamaTokenizerFast's [~PreTrainedTokenizer.decode
]. Please refer to
the docstring of this method for more information.
Source code in mindnlp/transformers/models/llava/processing_llava.py
138 139 140 141 142 143 |
|