source
stringclasses
470 values
url
stringlengths
49
167
file_type
stringclasses
1 value
chunk
stringlengths
1
512
chunk_id
stringlengths
5
9
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2tokenizerfast
.md
>>> tokenizer(" Hello world")["input_ids"] [18435, 995] ``` You can get around that behavior by passing `add_prefix_space=True` when instantiating this tokenizer, but since the model was not pretrained this way, it might yield a decrease in performance. <Tip> When used with `is_split_into_words=True`, this tokenizer needs to be instantiated with `add_prefix_space=True`. </Tip> This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
295_15_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2tokenizerfast
.md
</Tip> This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should refer to this superclass for more information regarding those methods. Args: vocab_file (`str`, *optional*): Path to the vocabulary file. merges_file (`str`, *optional*): Path to the merges file. tokenizer_file (`str`, *optional*): Path to [tokenizers](https://github.com/huggingface/tokenizers) file (generally has a .json extension) that contains everything needed to load the tokenizer.
295_15_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2tokenizerfast
.md
contains everything needed to load the tokenizer. unk_token (`str`, *optional*, defaults to `"<|endoftext|>"`): The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead. bos_token (`str`, *optional*, defaults to `"<|endoftext|>"`): The beginning of sequence token. eos_token (`str`, *optional*, defaults to `"<|endoftext|>"`): The end of sequence token. add_prefix_space (`bool`, *optional*, defaults to `False`):
295_15_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2tokenizerfast
.md
The end of sequence token. add_prefix_space (`bool`, *optional*, defaults to `False`): Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (GPT2 tokenizer detect beginning of words by the preceding space).
295_15_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
models.gpt2.modeling_gpt2.GPT2DoubleHeadsModelOutput Base class for outputs of models predicting if two sentences are consecutive or not. Args: loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Language modeling loss. mc_loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `mc_labels` is provided): Multiple choice classification loss. logits (`torch.FloatTensor` of shape `(batch_size, num_choices, sequence_length, config.vocab_size)`):
295_16_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
logits (`torch.FloatTensor` of shape `(batch_size, num_choices, sequence_length, config.vocab_size)`): Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax). mc_logits (`torch.FloatTensor` of shape `(batch_size, num_choices)`): Prediction scores of the multiple choice classification head (scores for each choice before SoftMax). past_key_values (`Tuple[Tuple[torch.Tensor]]`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
295_16_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
Tuple of length `config.n_layers`, containing tuples of tensors of shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). Contains pre-computed hidden-states (key and values in the attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding. hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
295_16_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of the model at the output of each layer plus the initial embedding outputs. attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`): Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
295_16_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, sequence_length)`. GPT2Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads. [[autodoc]] models.gpt2.modeling_tf_gpt2.TFGPT2DoubleHeadsModelOutput: modeling_tf_gpt2 requires the TensorFlow library but it was not found in your environment. However, we were able to find a PyTorch installation. PyTorch classes do not begin
295_16_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2-specific-outputs
.md
However, we were able to find a PyTorch installation. PyTorch classes do not begin with "TF", but are otherwise identically named to our TF classes. If you want to use PyTorch, please use those classes instead! If you really do want to use TensorFlow, please follow the instructions on the installation page https://www.tensorflow.org/install that match your environment. <frameworkcontent> <pt>
295_16_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2model
.md
The bare GPT2 Model transformer outputting raw hidden-states without any specific head on top. This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
295_17_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2model
.md
etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the
295_17_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2model
.md
Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward
295_17_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2lmheadmodel
.md
The GPT2 Model transformer with a language modeling head on top (linear layer with weights tied to the input embeddings). This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
295_18_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2lmheadmodel
.md
etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the
295_18_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2lmheadmodel
.md
Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward
295_18_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2doubleheadsmodel
.md
The GPT2 Model transformer with a language modeling and a multiple-choice classification head on top e.g. for RocStories/SWAG tasks. The two heads are two linear layers. The language modeling head has its weights tied to the input embeddings, the classification head takes as input the input of a specified classification token index in the input sequence). This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
295_19_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2doubleheadsmodel
.md
input sequence). This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters:
295_19_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2doubleheadsmodel
.md
and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward
295_19_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forquestionanswering
.md
The GPT-2 Model transformer with a span classification head on top for extractive question-answering tasks like SQuAD (a linear layer on top of the hidden-states output to compute `span start logits` and `span end logits`). This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
295_20_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forquestionanswering
.md
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model.
295_20_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forquestionanswering
.md
and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward
295_20_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forsequenceclassification
.md
The GPT2 Model transformer with a sequence classification head on top (linear layer). [`GPT2ForSequenceClassification`] uses the last token in order to do the classification, as other causal models (e.g. GPT-1) do. Since it does classification on the last token, it requires to know the position of the last token. If a `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
295_21_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forsequenceclassification
.md
`pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in each row of the batch). This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
295_21_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forsequenceclassification
.md
This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters:
295_21_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2forsequenceclassification
.md
and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward
295_21_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2fortokenclassification
.md
GPT2 Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for Named-Entity-Recognition (NER) tasks. This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
295_22_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2fortokenclassification
.md
etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters: config ([`GPT2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the
295_22_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#gpt2fortokenclassification
.md
Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Methods: forward </pt> <tf>
295_22_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfgpt2model
.md
No docstring available for TFGPT2Model Methods: call
295_23_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfgpt2lmheadmodel
.md
No docstring available for TFGPT2LMHeadModel Methods: call
295_24_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfgpt2doubleheadsmodel
.md
No docstring available for TFGPT2DoubleHeadsModel Methods: call
295_25_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfgpt2forsequenceclassification
.md
No docstring available for TFGPT2ForSequenceClassification Methods: call
295_26_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfsequenceclassifieroutputwithpast
.md
[[autodoc]] modeling_tf_outputs.TFSequenceClassifierOutputWithPast: No module named 'tensorflow'
295_27_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#tfgpt2tokenizer
.md
No docstring available for TFGPT2Tokenizer </tf> <jax>
295_28_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#flaxgpt2model
.md
No docstring available for FlaxGPT2Model Methods: __call__
295_29_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/gpt2.md
https://huggingface.co/docs/transformers/en/model_doc/gpt2/#flaxgpt2lmheadmodel
.md
No docstring available for FlaxGPT2LMHeadModel Methods: __call__ </jax> </frameworkcontent>
295_30_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
296_0_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer. -->
296_0_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#overview
.md
The OLMo2 model is the successor of the OLMo model, which was proposed in [OLMo: Accelerating the Science of Language Models](https://arxiv.org/abs/2402.00838). The architectural changes from the original OLMo model to this model are: - RMSNorm is used instead of standard layer norm. - Norm is applied to attention queries and keys. - Norm is applied after attention/feedforward layers rather than before. This model was contributed by [shanearora](https://huggingface.co/shanearora).
296_1_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#overview
.md
This model was contributed by [shanearora](https://huggingface.co/shanearora). The original code can be found [here](https://github.com/allenai/OLMo/tree/main/olmo).
296_1_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
This is the configuration class to store the configuration of a [`Olmo2Model`]. It is used to instantiate an OLMo2 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 [allenai/Olmo2-7B-1124-hf](https://huggingface.co/allenai/Olmo2-7B-1124-hf). Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
296_2_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the documentation from [`PretrainedConfig`] for more information. Args: vocab_size (`int`, *optional*, defaults to 50304): Vocabulary size of the Olmo2 model. Defines the number of different tokens that can be represented by the `inputs_ids` passed when calling [`Olmo2Model`] hidden_size (`int`, *optional*, defaults to 4096): Dimension of the hidden representations.
296_2_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
hidden_size (`int`, *optional*, defaults to 4096): Dimension of the hidden representations. intermediate_size (`int`, *optional*, defaults to 11008): Dimension of the MLP representations. num_hidden_layers (`int`, *optional*, defaults to 32): Number of hidden layers in the Transformer decoder. num_attention_heads (`int`, *optional*, defaults to 32): Number of attention heads for each attention layer in the Transformer decoder. num_key_value_heads (`int`, *optional*):
296_2_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
Number of attention heads for each attention layer in the Transformer decoder. num_key_value_heads (`int`, *optional*): This is the number of key_value heads that should be used to implement Grouped Query Attention. If `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
296_2_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed by meanpooling all the original heads within that group. For more details checkout [this paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `num_attention_heads`. hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
296_2_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
`num_attention_heads`. hidden_act (`str` or `function`, *optional*, defaults to `"silu"`): The non-linear activation function (function or string) in the decoder. max_position_embeddings (`int`, *optional*, defaults to 2048): The maximum sequence length that this model might ever be used with. initializer_range (`float`, *optional*, defaults to 0.02): The standard deviation of the truncated_normal_initializer for initializing all weight matrices. use_cache (`bool`, *optional*, defaults to `True`):
296_2_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
use_cache (`bool`, *optional*, defaults to `True`): Whether or not the model should return the last key/values attentions (not used by all models). Only relevant if `config.is_decoder=True`. pad_token_id (`int`, *optional*, defaults to 1): Padding token id. bos_token_id (`int`, *optional*): Beginning of stream token id. eos_token_id (`int`, *optional*, defaults to 50279): End of stream token id. tie_word_embeddings (`bool`, *optional*, defaults to `False`): Whether to tie weight embeddings
296_2_6
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
End of stream token id. tie_word_embeddings (`bool`, *optional*, defaults to `False`): Whether to tie weight embeddings rope_theta (`float`, *optional*, defaults to 10000.0): The base period of the RoPE embeddings. rope_scaling (`Dict`, *optional*): Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
296_2_7
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update `max_position_embeddings` to the expected new maximum. See the following thread for more information on how these scaling strategies behave: https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
296_2_8
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an experimental feature, subject to breaking API changes in future versions. attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`): Whether to use a bias in the query, key, value and output projection layers during self-attention. attention_dropout (`float`, *optional*, defaults to 0.0): The dropout ratio for the attention probabilities.
296_2_9
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
attention_dropout (`float`, *optional*, defaults to 0.0): The dropout ratio for the attention probabilities. rms_norm_eps (`float`, *optional*, defaults to 1e-05): The epsilon used by the rms normalization layers. ```python >>> from transformers import Olmo2Model, Olmo2Config
296_2_10
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2config
.md
>>> # Initializing a Olmo2 7B style configuration >>> configuration = Olmo2Config() >>> # Initializing a model from the Olmo2 7B style configuration >>> model = Olmo2Model(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```
296_2_11
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2model
.md
The bare Olmo2 Model outputting raw hidden-states without any specific head on top. This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
296_3_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2model
.md
etc.) This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior. Parameters: config ([`Olmo2Config`]): Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the
296_3_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2model
.md
load the weights associated with the model, only the configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights. Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Olmo2DecoderLayer`] Args: config: Olmo2Config Methods: forward
296_3_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/olmo2.md
https://huggingface.co/docs/transformers/en/model_doc/olmo2/#olmo2forcausallm
.md
No docstring available for Olmo2ForCausalLM Methods: forward
296_4_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
297_0_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer. -->
297_0_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
The LLaVA-OneVision model was proposed in [LLaVA-OneVision: Easy Visual Task Transfer](https://arxiv.org/abs/2408.03326) by <Bo Li, Yuanhan Zhang, Dong Guo, Renrui Zhang, Feng Li, Hao Zhang, Kaichen Zhang, Yanwei Li, Ziwei Liu, Chunyuan Li
297_1_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
LLaVA-OneVision is a Vision-Language Model that can generate text conditioned on one or several images/videos. The model consists of SigLIP vision encoder and a Qwen2 language backbone. The images are processed with anyres-9 technique where the image is split into 9 patches to better process high resolution images and capture as much details as possible. However, videos are pooled to a total sequence length of 196 tokens each frame for more memory efficient computation. LLaVA-OneVision is available in
297_1_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
to a total sequence length of 196 tokens each frame for more memory efficient computation. LLaVA-OneVision is available in three sizes: 0.5B, 7B and 72B and achieves remarkable performance on benchmark evaluations.
297_1_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
The abstract from the paper is the following: *We present LLaVA-OneVision, a family of open large multimodal models (LMMs) developed by consolidating our insights into data, models, and visual representations in the LLaVA-NeXT blog series. Our experimental results demonstrate that LLaVA-OneVision is the first single model that can simultaneously push the performance boundaries of open LMMs in three important computer vision scenarios:
297_1_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
single-image, multi-image, and video scenarios. Importantly, the design of LLaVAOneVision allows strong transfer learning across different modalities/scenarios, yielding new emerging capabilities. In particular, strong video understanding and cross-scenario capabilities are demonstrated through task transfer from images to videos.* <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/llava-ov-acrhitecture.png" alt="drawing" width="600"/>
297_1_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
alt="drawing" width="600"/> <small> LLaVA-OneVision architecture. Taken from the <a href="https://arxiv.org/abs/2408.03326">original paper.</a> </small> Tips: - We advise users to use `padding_side="left"` when computing batched generation as it leads to more accurate results. Simply make sure to call `processor.tokenizer.padding_side = "left"` before generating. <Tip warning={true}>
297_1_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
<Tip warning={true}> - Llava-OneVision uses different number of patches for images and thus has to pad the inputs inside modeling code, aside from the padding done when processing the inputs. The default setting is "left-padding" if model is in `eval()` mode, otherwise "right-padding". </Tip>
297_1_6
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
</Tip> - Note that the model should use a specific prompt format, on which the large language model (LLM) was trained. You can use the processor's `apply_chat_template` to format your prompts correctly. For that you have to construct a conversation history, passing a plain string will not format your prompt. Each message in the conversation history for chat templates is a dictionary with keys "role" and "content". The "content" should be a list of dictionaries, for "text" and "image" modalities.
297_1_7
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
We will use [llava-onevision-qwen2-7b-si-hf](https://huggingface.co/llava-hf/llava-onevision-qwen2-7b-si-hf) and a conversation history of text and image. Each content field has to be a list of dicts, as follows: ```python from transformers import AutoProcessor
297_1_8
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
processor = AutoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-7b-si-hf") conversation = [ { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "What’s shown in this image?"}, ], }, { "role": "assistant", "content": [{"type": "text", "text": "This image shows a red stop sign."},] }, { "role": "user", "content": [ {"type": "text", "text": "Describe the image in more details."}, ], }, ] text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
297_1_9
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#overview
.md
# Note that the template simply formats your prompt, you still have to tokenize it and obtain pixel values for your images print(text_prompt) >>> "<|im_start|>user\n<image>What is shown in this image?<|im_end|>\n<|im_start|>assistant\nPage showing the list of options.<|im_end|>" ``` This model was contributed by [RaushanTurganbay](https://huggingface.co/RaushanTurganbay). The original code can be found [here](https://github.com/LLaVA-VL/LLaVA-NeXT/tree/main).
297_1_10
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#single-image-inference
.md
Here's how to load the model and perform inference in half-precision (`torch.float16`): ```python from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration import torch from PIL import Image import requests processor = AutoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf") model = LlavaOnevisionForConditionalGeneration.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf", torch_dtype=torch.float16, low_cpu_mem_usage=True) model.to("cuda:0")
297_2_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#single-image-inference
.md
# prepare image and text prompt, using the appropriate prompt template url = "https://github.com/haotian-liu/LLaVA/blob/1a91fc274d7c35a9b50b3cb29c4247ae5837ce39/images/llava_v1_5_radar.jpg?raw=true" image = Image.open(requests.get(url, stream=True).raw)
297_2_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#single-image-inference
.md
conversation = [ { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "What is shown in this image?"}, ], }, ] prompt = processor.apply_chat_template(conversation, add_generation_prompt=True) inputs = processor(images=image, text=prompt, return_tensors="pt").to("cuda:0", torch.float16)
297_2_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#single-image-inference
.md
# autoregressively complete prompt output = model.generate(**inputs, max_new_tokens=100) print(processor.decode(output[0], skip_special_tokens=True)) 'user\n\nWhat is shown in this image?\nassistant\nThe image shows a radar chart, also known as a spider chart or a star chart, which is used to compare multiple quantitative variables. Each axis represents a different variable, and the chart is filled with' ```
297_2_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
LLaVa-OneVision can perform inference with multiple images as input, where images either belong to the same prompt or different prompts (in batched inference). For that you have to use checkpoints with an "ov" suffix. Here is how you can do it: ```python import requests from PIL import Image import torch from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration
297_3_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
# Load the model in half-precision model = LlavaOnevisionForConditionalGeneration.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf", torch_dtype=torch.float16, device_map="auto") processor = AutoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf") # Get three different images url = "https://www.ilankelman.org/stopsigns/australia.jpg" image_stop = Image.open(requests.get(url, stream=True).raw)
297_3_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
url = "http://images.cocodataset.org/val2017/000000039769.jpg" image_cats = Image.open(requests.get(url, stream=True).raw) url = "https://huggingface.co/microsoft/kosmos-2-patch14-224/resolve/main/snowman.jpg" image_snowman = Image.open(requests.get(url, stream=True).raw)
297_3_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
# Prepare a batch of two prompts, where the first one is a multi-turn conversation and the second is not conversation_1 = [ { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "What is shown in this image?"}, ], }, { "role": "assistant", "content": [ {"type": "text", "text": "There is a red stop sign in the image."}, ], }, { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "What about this image? How many cats do you see?"}, ], }, ]
297_3_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
conversation_2 = [ { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "What is shown in this image?"}, ], }, ] prompt_1 = processor.apply_chat_template(conversation_1, add_generation_prompt=True) prompt_2 = processor.apply_chat_template(conversation_2, add_generation_prompt=True) prompts = [prompt_1, prompt_2]
297_3_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
# We can simply feed images in the order they have to be used in the text prompt inputs = processor(images=[image_stop, image_cats, image_snowman], text=prompts, padding=True, return_tensors="pt").to(model.device, torch.float16)
297_3_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#multi-image-inference
.md
# Generate generate_ids = model.generate(**inputs, max_new_tokens=30) processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False) ['user\n\nWhat is shown in this image?\nassistant\nThere is a red stop sign in the image.\nuser\n\nWhat about this image? How many cats do you see?\nassistant\ntwo', 'user\n\nWhat is shown in this image?\nassistant\n'] ```
297_3_6
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
LLaVa-OneVision also can perform inference with videos as input, where video frames are treated as multiple images. Here is how you can do it: ```python import av import numpy as np from huggingface_hub import hf_hub_download import torch from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration
297_4_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
import torch from transformers import AutoProcessor, LlavaOnevisionForConditionalGeneration # Load the model in half-precision model = LlavaOnevisionForConditionalGeneration.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf", torch_dtype=torch.float16, device_map="auto") processor = AutoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-7b-ov-hf")
297_4_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
def read_video_pyav(container, indices): ''' Decode the video with PyAV decoder. Args: container (`av.container.input.InputContainer`): PyAV container. indices (`List[int]`): List of frame indices to decode. Returns: result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3). ''' frames = [] container.seek(0) start_index = indices[0] end_index = indices[-1] for i, frame in enumerate(container.decode(video=0)): if i > end_index: break if i >= start_index and i in indices:
297_4_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
for i, frame in enumerate(container.decode(video=0)): if i > end_index: break if i >= start_index and i in indices: frames.append(frame) return np.stack([x.to_ndarray(format="rgb24") for x in frames])
297_4_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
# Load the video as an np.array, sampling uniformly 8 frames (can sample more for longer videos, up to 32 frames) video_path = hf_hub_download(repo_id="raushan-testing-hf/videos-test", filename="sample_demo_1.mp4", repo_type="dataset") container = av.open(video_path) total_frames = container.streams.video[0].frames indices = np.arange(0, total_frames, total_frames / 8).astype(int) video = read_video_pyav(container, indices) # For videos we have to feed a "video" type instead of "image" conversation = [ {
297_4_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
# For videos we have to feed a "video" type instead of "image" conversation = [ { "role": "user", "content": [ {"type": "video"}, {"type": "text", "text": "Why is this video funny?"}, ], }, ] prompt = processor.apply_chat_template(conversation, add_generation_prompt=True) inputs = processor(videos=list(video), text=prompt, return_tensors="pt").to("cuda:0", torch.float16)
297_4_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#video-inference
.md
out = model.generate(**inputs, max_new_tokens=60) processor.batch_decode(out, skip_special_tokens=True, clean_up_tokenization_spaces=True) ["user\n\nWhy is this video funny?\nassistant\nThe video appears to be humorous because it shows a young child, who is wearing glasses and holding a book, seemingly reading with a serious and focused expression. The child's glasses are a bit oversized for their face, which adds a comical touch, as it's a common trope to see children wearing"] ```
297_4_6
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#quantization-using-bitsandbytes
.md
The model can be loaded in 8 or 4 bits, greatly reducing the memory requirements while maintaining the performance of the original model. First make sure to install bitsandbytes, `pip install bitsandbytes` and make sure to have access to a GPU/accelerator that is supported by the library. <Tip>
297_5_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#quantization-using-bitsandbytes
.md
<Tip> bitsandbytes is being refactored to support multiple backends beyond CUDA. Currently, ROCm (AMD GPU) and Intel CPU implementations are mature, with Intel XPU in progress and Apple Silicon support expected by Q4/Q1. For installation instructions and the latest backend updates, visit [this link](https://huggingface.co/docs/bitsandbytes/main/en/installation#multi-backend).
297_5_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#quantization-using-bitsandbytes
.md
We value your feedback to help identify bugs before the full release! Check out [these docs](https://huggingface.co/docs/bitsandbytes/main/en/non_cuda_backends) for more details and feedback links. </Tip> Simply change the snippet above with: ```python from transformers import LlavaOnevisionForConditionalGeneration, BitsAndBytesConfig
297_5_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#quantization-using-bitsandbytes
.md
# specify how to quantize the model quantization_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16, ) model = LlavaOnevisionForConditionalGeneration.from_pretrained(model_id, quantization_config=quantization_config, device_map="auto") ```
297_5_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#use-flash-attention-2-to-further-speed-up-generation
.md
First make sure to install flash-attn. Refer to the [original repository of Flash Attention](https://github.com/Dao-AILab/flash-attention) regarding that package installation. Simply change the snippet above with: ```python from transformers import LlavaOnevisionForConditionalGeneration model = LlavaOnevisionForConditionalGeneration.from_pretrained( model_id, torch_dtype=torch.float16, low_cpu_mem_usage=True, use_flash_attention_2=True ).to(0) ```
297_6_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
This is the configuration class to store the configuration of a [`LlavaOnevisionForConditionalGeneration`]. It is used to instantiate an Llava-NeXT 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-hf/llava-onevision-qwen2-7b-ov-hf](https://huggingface.co/llava-hf/llava-onevision-qwen2-7b-ov-hf) model.
297_7_0
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
model. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the documentation from [`PretrainedConfig`] for more information. Args: vision_config (`Union[AutoConfig, dict]`, *optional*, defaults to `SiglipVisionConfig`): The config object or dictionary of the vision backbone. text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `Qwen2Config`): The config object or dictionary of the text backbone.
297_7_1
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
The config object or dictionary of the text backbone. image_token_index (`int`, *optional*, defaults to 151646): The image token index to encode the image prompt. video_token_index (`int`, *optional*, defaults to 151647): The video token index to encode the video prompt. projector_hidden_act (`str`, *optional*, defaults to `"gelu"`): The activation function used by the multimodal projector. vision_feature_select_strategy (`str`, *optional*, defaults to `"full"`):
297_7_2
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
vision_feature_select_strategy (`str`, *optional*, defaults to `"full"`): The feature selection strategy used to select the vision feature from the vision backbone. Can be one of `"default"` or `"full"`. If `"default"`, the CLS token is removed from the vision features. If `"full"`, the full vision features are used. vision_feature_layer (`int`, *optional*, defaults to -1): The index of the layer to select the vision feature. vision_aspect_ratio (`str`, *optional*, defaults to `"anyres_max_9"`):
297_7_3
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
The index of the layer to select the vision feature. vision_aspect_ratio (`str`, *optional*, defaults to `"anyres_max_9"`): Aspect ratio used when processong image features. The default value is "anyres_max_9". image_grid_pinpoints (`List`, *optional*): A list of possible resolutions to use for processing high resolution images. Each item in the list should be a tuple or list of the form `(height, width)`. tie_word_embeddings (`bool`, *optional*, defaults to `False`):
297_7_4
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
of the form `(height, width)`. tie_word_embeddings (`bool`, *optional*, defaults to `False`): Whether the model's input and output word embeddings should be tied. multimodal_projector_bias (`bool`, *optional*, defaults to `True`): Whether to use bias in the multimodal projector. Example: ```python >>> from transformers import LlavaOnevisionForConditionalGeneration, LlavaOnevisionConfig, SiglipVisionConfig, Qwen2Config
297_7_5
/Users/nielsrogge/Documents/python_projecten/transformers/docs/source/en/model_doc/llava_onevision.md
https://huggingface.co/docs/transformers/en/model_doc/llava_onevision/#llavaonevisionconfig
.md
>>> # Initializing a CLIP-vision config >>> vision_config = SiglipVisionConfig() >>> # Initializing a Llama config >>> text_config = Qwen2Config() >>> # Initializing a Llava-Next llava-hf/llava-onevision-qwen2-7b-ov-hf style configuration >>> configuration = LlavaOnevisionConfig(vision_config, text_config) >>> # Initializing a model from the llava-hf/llava-onevision-qwen2-7b-ov-hf style configuration >>> model = LlavaOnevisionForConditionalGeneration(configuration)
297_7_6