Buckets:
| import"../chunks/DsnmJJEf.js";import{i as Ge,h as Ee,C as Qe,H as s,a as p,D as o,E as Xe,s as Le}from"../chunks/qxQfBDOH.js";import{p as Ye,o as He,s as e,f as m,a as d,b as $e,d as n,c as u,n as r,r as t}from"../chunks/Dpn4EqEf.js";import{T as h}from"../chunks/BRV980rc.js";import{E as J}from"../chunks/BD6i_DTX.js";const Ke='{"title":"DeepSeek-OCR-2","local":"deepseek-ocr-2","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage example","local":"usage-example","sections":[{"title":"Plain OCR","local":"plain-ocr","sections":[],"depth":3},{"title":"Grounding with markdown conversion","local":"grounding-with-markdown-conversion","sections":[],"depth":3}],"depth":2},{"title":"DeepseekOcr2Config","local":"transformers.DeepseekOcr2Config","sections":[],"depth":2},{"title":"DeepseekOcr2VisionConfig","local":"transformers.DeepseekOcr2VisionConfig","sections":[],"depth":2},{"title":"DeepseekOcr2SamVisionConfig","local":"transformers.DeepseekOcr2SamVisionConfig","sections":[],"depth":2},{"title":"DeepseekOcr2VisionEncoderConfig","local":"transformers.DeepseekOcr2VisionEncoderConfig","sections":[],"depth":2},{"title":"DeepseekOcr2TextConfig","local":"transformers.DeepseekOcr2TextConfig","sections":[],"depth":2},{"title":"DeepseekOcr2ImageProcessor","local":"transformers.DeepseekOcr2ImageProcessor","sections":[],"depth":2},{"title":"DeepseekOcr2ImageProcessorPil","local":"transformers.DeepseekOcr2ImageProcessorPil","sections":[],"depth":2},{"title":"DeepseekOcr2Processor","local":"transformers.DeepseekOcr2Processor","sections":[],"depth":2},{"title":"DeepseekOcr2TextModel","local":"transformers.DeepseekOcr2TextModel","sections":[],"depth":2},{"title":"DeepseekOcr2VisionModel","local":"transformers.DeepseekOcr2VisionModel","sections":[],"depth":2},{"title":"DeepseekOcr2Model","local":"transformers.DeepseekOcr2Model","sections":[],"depth":2},{"title":"DeepseekOcr2ForConditionalGeneration","local":"transformers.DeepseekOcr2ForConditionalGeneration","sections":[],"depth":2}],"depth":1}';var eo=u('<meta name="hf:doc:metadata"/>'),q=u("<p>Example:</p> <!>",1),g=u(`<p>Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code> instance afterwards instead of this since the former takes care of running the pre and post processing steps while | |
| the latter silently ignores them.</p>`),oo=u(`<p></p> <p><em>This model was published in HF papers on 2026-01-28 and contributed to Hugging Face Transformers on 2026-06-01.</em></p> <!> <!> <!> <p>The DeepSeek-OCR-2 model was proposed in <a href="https://huggingface.co/papers/2601.20552" rel="nofollow">Visual Causal Flow: A Novel Approach to OCR-Specialized Vision-Language Models</a> by the DeepSeek team.</p> <p>DeepSeek-OCR-2 is an OCR-specialized vision-language model built on a distinctive architecture: a SAM ViT-B vision encoder feeds into a Qwen2 hybrid attention encoder, which is connected through an MLP projector to a DeepSeek-V2 Mixture-of-Experts (MoE) language model. A key feature of the model is its hybrid attention mechanism, which applies bidirectional attention over image tokens and causal attention over query tokens, enabling efficient and accurate document understanding.</p> <img src="https://huggingface.co/deepseek-ai/DeepSeek-OCR-2/resolve/main/assets/fig1.png" width="600"/> <small>DeepSeek-OCR 2: Visual Causal Flow.</small> <p>This model was contributed by <a href="https://huggingface.co/thisisiron" rel="nofollow">thisisiron</a>.</p> <!> <!> <!> <!> <p>The <code><|grounding|></code> token enables coordinate-aware output with <code><|ref|></code> and <code><|det|></code> tags.</p> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DeepseekOcr2Model. It is used to instantiate a Deepseek Ocr2 | |
| 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 <a href="https://huggingface.co/deepseek-community/DeepSeek-OCR-2" rel="nofollow">deepseek-community/DeepSeek-OCR-2</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the | |
| documentation from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DeepseekOcr2Model. It is used to instantiate a Deepseek Ocr2 | |
| 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 <a href="https://huggingface.co/deepseek-community/DeepSeek-OCR-2" rel="nofollow">deepseek-community/DeepSeek-OCR-2</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the | |
| documentation from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DeepseekOcr2Model. It is used to instantiate a Deepseek Ocr2 | |
| 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 <a href="https://huggingface.co/deepseek-community/DeepSeek-OCR-2" rel="nofollow">deepseek-community/DeepSeek-OCR-2</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the | |
| documentation from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DeepseekOcr2Model. It is used to instantiate a Deepseek Ocr2 | |
| 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 <a href="https://huggingface.co/deepseek-community/DeepSeek-OCR-2" rel="nofollow">deepseek-community/DeepSeek-OCR-2</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the | |
| documentation from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DeepseekOcr2Model. It is used to instantiate a Deepseek Ocr2 | |
| 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 <a href="https://huggingface.co/deepseek-community/DeepSeek-OCR-2" rel="nofollow">deepseek-community/DeepSeek-OCR-2</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the | |
| documentation from <a href="/docs/transformers/pr_48731/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a DeepseekOcr2ImageProcessor image processor.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Crop batched images to patches based on optimal tiling.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Returns the number of image patches for a given image size (1 global + local patches).</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Pads an image to a square based on the longest edge.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a DeepseekOcr2ImageProcessor image processor.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Crop the image to patches and return a list of cropped images.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A utility that returns number patches for a given image size.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Pads an image to a square based on the longest edge.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Constructs a DeepseekOcr2Processor which wraps a image processor and a tokenizer into a single processor.</p> <p><a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Processor">DeepseekOcr2Processor</a> offers all the functionalities of <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a> and <a href="/docs/transformers/pr_48731/en/main_classes/tokenizer#transformers.TokenizersBackend">TokenizersBackend</a>. See the <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">~DeepseekOcr2ImageProcessor</a> and <a href="/docs/transformers/pr_48731/en/main_classes/tokenizer#transformers.TokenizersBackend">~TokenizersBackend</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The bare Deepseek Ocr2 Text Model outputting raw hidden-states without any specific head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass. | |
| Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage | |
| and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2TextModel">DeepseekOcr2TextModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>past_key_values</strong> (<code>Cache</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) — It is a <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance. For more details, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>.</p> <p>Contains pre-computed hidden-states (key and values in the self-attention blocks and optionally if <code>config.is_encoder_decoder=True</code> in the cross-attention blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li> <li><p><strong>router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_probs=True</code> and <code>config.add_router_probs=True</code> is passed or when <code>config.output_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Raw router logits (post-softmax) that are computed by MoE routers, these terms are used to compute the auxiliary | |
| loss for Mixture of Experts models.</p></li></ul></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Vision pipeline: SAM ViT-B (with neck)</p> <p>This model inherits from <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass. | |
| Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage | |
| and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2VisionModel">DeepseekOcr2VisionModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li></ul></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The Llava-Next model which consists of a vision backbone and a language model without language modeling head.</p> <p>This model inherits from <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass. | |
| Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage | |
| and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Model">DeepseekOcr2Model</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p> <p>If <code>past_key_values</code> is used only the last hidden-state of the sequences of shape <code>(batch_size, 1, hidden_size)</code> is output.</p></li> <li><p><strong>past_key_values</strong> (<code>Cache</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) — It is a <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance. For more details, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>.</p> <p>Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li> <li><p><strong>image_hidden_states</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) — A <code>torch.FloatTensor</code> of size <code>(batch_size, num_images, sequence_length, hidden_size)</code>. | |
| image_hidden_states of the model produced by the vision encoder and after projecting the last hidden state.</p></li> <li><p><strong>router_logits</strong> (<code>tuple[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Router logits of the model, useful to compute the auxiliary loss for Mixture of Experts models.</p></li></ul></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>pooler_output</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, hidden_size)</code>) — Last layer hidden-state of the first token of the sequence (classification token) after further processing | |
| through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns | |
| the classification token after processing through a linear layer and a tanh activation function. The linear | |
| layer weights are trained from the next sentence prediction (classification) objective during pretraining.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li></ul></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Obtains multimodal placeholder mask from <code>input_ids</code> or <code>inputs_embeds</code>, and checks that the placeholder token count is | |
| equal to the length of multimodal features. If the lengths are different, an error is raised.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The Deepseek Ocr2 Model for token generation conditioned on other modalities (e.g. image-text-to-text generation).</p> <p>This model inherits from <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass. | |
| Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage | |
| and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ForConditionalGeneration">DeepseekOcr2ForConditionalGeneration</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) — Language modeling loss (for next-token prediction).</p></li> <li><p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) — Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p></li> <li><p><strong>past_key_values</strong> (<code>Cache</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) — It is a <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance. For more details, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>.</p> <p>Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li> <li><p><strong>image_hidden_states</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) — A <code>torch.FloatTensor</code> of size (batch_size * num_patches, num_images, sequence_length, hidden_size)\`. | |
| image_hidden_states of the model produced by the vision encoder and after projecting the last hidden state.</p></li> <li><p><strong>router_logits</strong> (<code>tuple[torch.FloatTensor]</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Router logits of the model, useful to compute the auxiliary loss for Mixture of Experts models.</p></li></ul> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>pooler_output</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, hidden_size)</code>) — Last layer hidden-state of the first token of the sequence (classification token) after further processing | |
| through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns | |
| the classification token after processing through a linear layer and a tanh activation function. The linear | |
| layer weights are trained from the next sentence prediction (classification) objective during pretraining.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, + | |
| one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention | |
| heads.</p></li></ul> <!></div></div> <!> <p></p>`,1);function io(we,Me){Ye(Me,!1),He(()=>{new URLSearchParams(window.location.search).get("fw")}),Ge();var F=oo();Ee("1lbm809",a=>{var c=eo();Le(c,"content",Ke),d(a,c)});var R=e(m(F),4);Qe(R,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var V=e(R,2);s(V,{title:"DeepSeek-OCR-2",local:"deepseek-ocr-2",headingTag:"h1"});var W=e(V,2);s(W,{title:"Overview",local:"overview",headingTag:"h2"});var Z=e(W,12);s(Z,{title:"Usage example",local:"usage-example",headingTag:"h2"});var S=e(Z,2);s(S,{title:"Plain OCR",local:"plain-ocr",headingTag:"h3"});var A=e(S,2);p(A,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBBdXRvTW9kZWxGb3JJbWFnZVRleHRUb1RleHQlMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlVGV4dFRvVGV4dC5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyZGVlcHNlZWstY29tbXVuaXR5JTJGRGVlcFNlZWstT0NSLTIlMjIlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUwQSklMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJkZWVwc2Vlay1jb21tdW5pdHklMkZEZWVwU2Vlay1PQ1ItMiUyMiklMEElMEFpbWFnZSUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZkYXRhc2V0cyUyRmhmLWludGVybmFsLXRlc3RpbmclMkZmaXh0dXJlc19nb3Rfb2NyJTJGcmVzb2x2ZSUyRm1haW4lMkZpbWFnZV9vY3IuanBnJTIyJTBBaW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlJTJDJTIwdGV4dCUzRCUyMiUzQ2ltYWdlJTNFJTVDbkZyZWUlMjBPQ1IuJTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikudG8obW9kZWwuZGV2aWNlJTJDJTIwZHR5cGUlM0Rtb2RlbC5kdHlwZSklMEElMEFnZW5lcmF0ZV9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMGRvX3NhbXBsZSUzREZhbHNlJTJDJTIwbWF4X25ld190b2tlbnMlM0QyNTYpJTBBcHJvY2Vzc29yLmRlY29kZShnZW5lcmF0ZV9pZHMlNUIwJTJDJTIwaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVELnNoYXBlJTVCMSU1RCUyMCUzQSU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUyMyUyMCUyMlIlMjZEJTIwUVVBTElUWSUyMElNUFJPVkVNRU5UJTVDblNVR0dFU1RJT04lMkZTT0xVVElPTiUyMEZPUk0lNUNuTmFtZSUyRlBob25lJTIwRXh0LiUyMCUzQSUyMCguLi4pJTIy",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, AutoModelForImageTextToText | |
| model = AutoModelForImageTextToText.from_pretrained( | |
| <span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>, device_map=<span class="hljs-string">"auto"</span> | |
| ) | |
| processor = AutoProcessor.from_pretrained(<span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>) | |
| image = <span class="hljs-string">"https://huggingface.co/datasets/hf-internal-testing/fixtures_got_ocr/resolve/main/image_ocr.jpg"</span> | |
| inputs = processor(images=image, text=<span class="hljs-string">"<image>\\nFree OCR."</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device, dtype=model.dtype) | |
| generate_ids = model.generate(**inputs, do_sample=<span class="hljs-literal">False</span>, max_new_tokens=<span class="hljs-number">256</span>) | |
| processor.decode(generate_ids[<span class="hljs-number">0</span>, inputs[<span class="hljs-string">"input_ids"</span>].shape[<span class="hljs-number">1</span>] :], skip_special_tokens=<span class="hljs-literal">True</span>) | |
| <span class="hljs-comment"># "R&D QUALITY IMPROVEMENT\\nSUGGESTION/SOLUTION FORM\\nName/Phone Ext. : (...)"</span>`,lang:"python",wrap:!1});var B=e(A,2);s(B,{title:"Grounding with markdown conversion",local:"grounding-with-markdown-conversion",headingTag:"h3"});var G=e(B,4);p(G,{code:"aW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKCUwQSUyMCUyMCUyMCUyMGltYWdlcyUzRGltYWdlJTJDJTBBJTIwJTIwJTIwJTIwdGV4dCUzRCUyMiUzQ2ltYWdlJTNFJTVDbiUzQyU3Q2dyb3VuZGluZyU3QyUzRUNvbnZlcnQlMjB0aGUlMjBkb2N1bWVudCUyMHRvJTIwbWFya2Rvd24uJTIyJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiUyQyUwQSkudG8obW9kZWwuZGV2aWNlJTJDJTIwZHR5cGUlM0Rtb2RlbC5kdHlwZSklMEElMEFnZW5lcmF0ZV9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMGRvX3NhbXBsZSUzREZhbHNlJTJDJTIwbWF4X25ld190b2tlbnMlM0QyNTYpJTBBcHJvY2Vzc29yLmRlY29kZShnZW5lcmF0ZV9pZHMlNUIwJTJDJTIwaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVELnNoYXBlJTVCMSU1RCUyMCUzQSU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RGYWxzZSklMEElMjMlMjAlMjIlM0MlN0NyZWYlN0MlM0V0aXRsZSUzQyU3QyUyRnJlZiU3QyUzRSUzQyU3Q2RldCU3QyUzRSU1QiU1QjMzMCUyQyUyMDE5OCUyQyUyMDU1OCUyQyUyMDIzMCU1RCU1RCUzQyU3QyUyRmRldCU3QyUzRSU1Q24lMjMlMjBSJTI2RCUyMFFVQUxJVFklMjAoLi4uKSUyMg==",highlighted:`inputs = processor( | |
| images=image, | |
| text=<span class="hljs-string">"<image>\\n<|grounding|>Convert the document to markdown."</span>, | |
| return_tensors=<span class="hljs-string">"pt"</span>, | |
| ).to(model.device, dtype=model.dtype) | |
| generate_ids = model.generate(**inputs, do_sample=<span class="hljs-literal">False</span>, max_new_tokens=<span class="hljs-number">256</span>) | |
| processor.decode(generate_ids[<span class="hljs-number">0</span>, inputs[<span class="hljs-string">"input_ids"</span>].shape[<span class="hljs-number">1</span>] :], skip_special_tokens=<span class="hljs-literal">False</span>) | |
| <span class="hljs-comment"># "<|ref|>title<|/ref|><|det|>[[330, 198, 558, 230]]<|/det|>\\n# R&D QUALITY (...)"</span>`,lang:"python",wrap:!1});var E=e(G,2);s(E,{title:"DeepseekOcr2Config",local:"transformers.DeepseekOcr2Config",headingTag:"h2"});var _=e(E,2),xe=n(_);o(xe,{name:"class transformers.DeepseekOcr2Config",anchor:"transformers.DeepseekOcr2Config",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/configuration_deepseek_ocr2.py#L264",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"vision_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"text_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"image_token_id",val:": int = 128815"},{name:"tie_word_embeddings",val:": bool = False"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2Config.vision_config",description:`<strong>vision_config</strong> (<code>dict</code> or <code>DeepseekOcr2VisionConfig</code>, <em>optional</em>) — | |
| Configuration for the vision encoders. Defaults to <code>DeepseekOcr2VisionConfig()</code>.`,name:"vision_config"},{anchor:"transformers.DeepseekOcr2Config.text_config",description:`<strong>text_config</strong> (<code>Union[dict, ~configuration_utils.PreTrainedConfig]</code>, <em>optional</em>) — | |
| The config object or dictionary of the text backbone.`,name:"text_config"},{anchor:"transformers.DeepseekOcr2Config.image_token_id",description:`<strong>image_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to <code>128815</code>) — | |
| The image token index used as a placeholder for input images.`,name:"image_token_id"},{anchor:"transformers.DeepseekOcr2Config.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to tie weight embeddings according to model’s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"}]}),r(4),t(_);var Q=e(_,2);s(Q,{title:"DeepseekOcr2VisionConfig",local:"transformers.DeepseekOcr2VisionConfig",headingTag:"h2"});var f=e(Q,2),De=n(f);o(De,{name:"class transformers.DeepseekOcr2VisionConfig",anchor:"transformers.DeepseekOcr2VisionConfig",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/configuration_deepseek_ocr2.py#L150",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"sam_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"encoder_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2VisionConfig.sam_config",description:`<strong>sam_config</strong> (<code>dict</code> or <code>DeepseekOcr2SamVisionConfig</code>, <em>optional</em>) — | |
| Configuration for the SAM vision encoder. Defaults to <code>DeepseekOcr2SamVisionConfig()</code>.`,name:"sam_config"},{anchor:"transformers.DeepseekOcr2VisionConfig.encoder_config",description:`<strong>encoder_config</strong> (<code>dict</code> or <code>DeepseekOcr2VisionEncoderConfig</code>, <em>optional</em>) — | |
| Configuration for the DeepSeek-OCR-2 vision encoder. Defaults to <code>DeepseekOcr2VisionEncoderConfig()</code>.`,name:"encoder_config"}]}),r(4),t(f);var X=e(f,2);s(X,{title:"DeepseekOcr2SamVisionConfig",local:"transformers.DeepseekOcr2SamVisionConfig",headingTag:"h2"});var k=e(X,2),Oe=n(k);o(Oe,{name:"class transformers.DeepseekOcr2SamVisionConfig",anchor:"transformers.DeepseekOcr2SamVisionConfig",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/configuration_deepseek_ocr2.py#L30",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"hidden_size",val:": int = 768"},{name:"output_channels",val:": int = 256"},{name:"num_hidden_layers",val:": int = 12"},{name:"num_attention_heads",val:": int = 12"},{name:"num_channels",val:": int = 3"},{name:"image_size",val:": int | list[int] | tuple[int, int] = 1024"},{name:"patch_size",val:": int | list[int] | tuple[int, int] = 16"},{name:"hidden_act",val:": str = 'gelu'"},{name:"layer_norm_eps",val:": float = 1e-06"},{name:"attention_dropout",val:": float | int = 0.0"},{name:"initializer_range",val:": float = 1e-10"},{name:"qkv_bias",val:": bool = True"},{name:"mlp_ratio",val:": float = 4.0"},{name:"use_abs_pos",val:": bool = True"},{name:"use_rel_pos",val:": bool = True"},{name:"window_size",val:": int = 14"},{name:"global_attn_indexes",val:": list[int] | tuple[int, ...] = (2, 5, 8, 11)"},{name:"mlp_dim",val:": int | None = None"},{name:"downsample_channels",val:": list[int] | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2SamVisionConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>768</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.output_channels",description:`<strong>output_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 256) — | |
| The number of output channels in the SAM neck.`,name:"output_channels"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>12</code>) — | |
| Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>12</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.num_channels",description:`<strong>num_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>3</code>) — | |
| The number of input channels.`,name:"num_channels"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.image_size",description:`<strong>image_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>1024</code>) — | |
| The size (resolution) of each image.`,name:"image_size"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.patch_size",description:`<strong>patch_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>16</code>) — | |
| The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>gelu</code>) — | |
| The non-linear activation function (function or string) in the decoder. For example, <code>"gelu"</code>, | |
| <code>"relu"</code>, <code>"silu"</code>, etc.`,name:"hidden_act"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-06</code>) — | |
| The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-10</code>) — | |
| The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.qkv_bias",description:`<strong>qkv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to add a bias to the queries, keys and values.`,name:"qkv_bias"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>float</code>, <em>optional</em>, defaults to <code>4.0</code>) — | |
| Ratio of the MLP hidden dim to the embedding dim.`,name:"mlp_ratio"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.use_abs_pos",description:`<strong>use_abs_pos</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to use absolute position embeddings.`,name:"use_abs_pos"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.use_rel_pos",description:`<strong>use_rel_pos</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to use relative position bias in the self-attention layers.`,name:"use_rel_pos"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.window_size",description:`<strong>window_size</strong> (<code>int</code>, <em>optional</em>, defaults to 14) — | |
| Window size for windowed attention layers.`,name:"window_size"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.global_attn_indexes",description:`<strong>global_attn_indexes</strong> (<code>list[int]</code>, <em>optional</em>, defaults to <code>[2, 5, 8, 11]</code>) — | |
| Indices of encoder layers that use global (non-windowed) attention.`,name:"global_attn_indexes"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.mlp_dim",description:`<strong>mlp_dim</strong> (<code>int</code>, <em>optional</em>) — | |
| Dimensionality of the MLP layer in each vision encoder block. Defaults to <code>hidden_size * mlp_ratio</code>.`,name:"mlp_dim"},{anchor:"transformers.DeepseekOcr2SamVisionConfig.downsample_channels",description:`<strong>downsample_channels</strong> (<code>list[int]</code>, <em>optional</em>) — | |
| The channel dimensions for the multi-scale downsampling neck layers. Defaults to <code>[512, 896]</code>.`,name:"downsample_channels"}]}),r(4),t(k);var L=e(k,2);s(L,{title:"DeepseekOcr2VisionEncoderConfig",local:"transformers.DeepseekOcr2VisionEncoderConfig",headingTag:"h2"});var b=e(L,2),Y=n(b);o(Y,{name:"class transformers.DeepseekOcr2VisionEncoderConfig",anchor:"transformers.DeepseekOcr2VisionEncoderConfig",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/configuration_deepseek_ocr2.py#L78",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"vocab_size",val:": int = 151936"},{name:"hidden_size",val:": int = 4096"},{name:"intermediate_size",val:": int = 22016"},{name:"num_hidden_layers",val:": int = 32"},{name:"num_attention_heads",val:": int = 32"},{name:"num_key_value_heads",val:": int | None = 32"},{name:"hidden_act",val:": str = 'silu'"},{name:"max_position_embeddings",val:": int = 32768"},{name:"initializer_range",val:": float = 0.02"},{name:"rms_norm_eps",val:": float = 1e-06"},{name:"use_cache",val:": bool = True"},{name:"tie_word_embeddings",val:": bool = False"},{name:"rope_parameters",val:": transformers.modeling_rope_utils.RopeParameters | dict | None = None"},{name:"use_sliding_window",val:": bool = False"},{name:"sliding_window",val:": int | None = 4096"},{name:"max_window_layers",val:": int = 28"},{name:"layer_types",val:": list[str] | None = None"},{name:"attention_dropout",val:": float | int = 0.0"},{name:"pad_token_id",val:": int | None = None"},{name:"bos_token_id",val:": int | None = None"},{name:"eos_token_id",val:": int | list[int] | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>151936</code>) — | |
| Vocabulary size of the model. Defines the number of different tokens that can be represented by the <code>input_ids</code>.`,name:"vocab_size"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4096</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>22016</code>) — | |
| Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| This is the number of key_value heads that should be used to implement Grouped Query Attention. If | |
| <code>num_key_value_heads=num_attention_heads</code>, the model will use Multi Head Attention (MHA), if | |
| <code>num_key_value_heads=1</code> 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, check out <a href="https://huggingface.co/papers/2305.13245" rel="nofollow">this | |
| paper</a>. If it is not specified, will default to | |
| <code>num_attention_heads</code>.`,name:"num_key_value_heads"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>silu</code>) — | |
| The non-linear activation function (function or string) in the decoder. For example, <code>"gelu"</code>, | |
| <code>"relu"</code>, <code>"silu"</code>, etc.`,name:"hidden_act"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32768</code>) — | |
| The maximum sequence length that this model might ever be used with.`,name:"max_position_embeddings"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) — | |
| The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.rms_norm_eps",description:`<strong>rms_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-06</code>) — | |
| The epsilon used by the rms normalization layers.`,name:"rms_norm_eps"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether or not the model should return the last key/values attentions (not used by all models). Only | |
| relevant if <code>config.is_decoder=True</code> or when the model is a decoder-only generative model.`,name:"use_cache"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to tie weight embeddings according to model’s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.rope_parameters",description:`<strong>rope_parameters</strong> (<code>Union[~modeling_rope_utils.RopeParameters, dict]</code>, <em>optional</em>) — | |
| Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain | |
| a value for <code>rope_theta</code> and optionally parameters used for scaling in case you want to use RoPE | |
| with longer <code>max_position_embeddings</code>.`,name:"rope_parameters"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.use_sliding_window",description:`<strong>use_sliding_window</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to use sliding window attention.`,name:"use_sliding_window"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.sliding_window",description:`<strong>sliding_window</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4096</code>) — | |
| Sliding window attention window size. If <code>None</code>, no sliding window is applied.`,name:"sliding_window"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.max_window_layers",description:`<strong>max_window_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>28</code>) — | |
| The number of layers using full attention. The first <code>max_window_layers</code> layers will use full attention, while any | |
| additional layer afterwards will use SWA (Sliding Window Attention).`,name:"max_window_layers"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.layer_types",description:`<strong>layer_types</strong> (<code>list[str]</code>, <em>optional</em>) — | |
| A list that explicitly maps each layer index with its layer type. If not provided, it will be automatically | |
| generated based on config values.`,name:"layer_types"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>) — | |
| Token id used for padding in the vocabulary.`,name:"pad_token_id"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>) — | |
| Token id used for beginning-of-stream in the vocabulary.`,name:"bos_token_id"},{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>Union[int, list[int]]</code>, <em>optional</em>) — | |
| Token id used for end-of-stream in the vocabulary.`,name:"eos_token_id"}]});var Ce=e(Y,6);J(Ce,{anchor:"transformers.DeepseekOcr2VisionEncoderConfig.example",children:(a,c)=>{var i=q(),l=e(m(i),2);p(l,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZXBzZWVrT2NyMkNvbmZpZyUwQSUwQWNvbmZpZyUyMCUzRCUyMERlZXBzZWVrT2NyMkNvbmZpZygpJTBBZW5jb2Rlcl9jb25maWclMjAlM0QlMjBjb25maWcudmlzaW9uX2NvbmZpZy5lbmNvZGVyX2NvbmZpZw==",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DeepseekOcr2Config | |
| <span class="hljs-meta">>>> </span>config = DeepseekOcr2Config() | |
| <span class="hljs-meta">>>> </span>encoder_config = config.vision_config.encoder_config`,lang:"python",wrap:!1}),d(a,i)},$$slots:{default:!0}}),t(b);var H=e(b,2);s(H,{title:"DeepseekOcr2TextConfig",local:"transformers.DeepseekOcr2TextConfig",headingTag:"h2"});var y=e(H,2),ze=n(y);o(ze,{name:"class transformers.DeepseekOcr2TextConfig",anchor:"transformers.DeepseekOcr2TextConfig",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/configuration_deepseek_ocr2.py#L170",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"vocab_size",val:": int = 102400"},{name:"hidden_size",val:": int = 4096"},{name:"intermediate_size",val:": int = 11008"},{name:"num_hidden_layers",val:": int = 32"},{name:"num_attention_heads",val:": int = 32"},{name:"num_key_value_heads",val:": int | None = None"},{name:"hidden_act",val:": str = 'silu'"},{name:"max_position_embeddings",val:": int = 2048"},{name:"initializer_range",val:": float = 0.02"},{name:"rms_norm_eps",val:": float = 1e-06"},{name:"use_cache",val:": bool = True"},{name:"pad_token_id",val:": int | None = None"},{name:"bos_token_id",val:": int | None = 1"},{name:"eos_token_id",val:": int | list[int] | None = 2"},{name:"pretraining_tp",val:": int | None = 1"},{name:"tie_word_embeddings",val:": bool = False"},{name:"rope_parameters",val:": transformers.modeling_rope_utils.RopeParameters | dict | None = None"},{name:"attention_bias",val:": bool = False"},{name:"attention_dropout",val:": float | None = 0.0"},{name:"mlp_bias",val:": bool = False"},{name:"head_dim",val:": int | None = None"},{name:"n_group",val:": int | None = None"},{name:"n_routed_experts",val:": int = 64"},{name:"output_router_logits",val:": bool = False"},{name:"n_shared_experts",val:": int = 2"},{name:"routed_scaling_factor",val:": float = 1.0"},{name:"topk_group",val:": int | None = None"},{name:"topk_method",val:": str | None = 'greedy'"},{name:"num_experts_per_tok",val:": int | None = None"},{name:"moe_intermediate_size",val:": int = 1407"},{name:"mlp_layer_types",val:": list[str] | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2TextConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>102400</code>) — | |
| Vocabulary size of the model. Defines the number of different tokens that can be represented by the <code>input_ids</code>.`,name:"vocab_size"},{anchor:"transformers.DeepseekOcr2TextConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4096</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.DeepseekOcr2TextConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>11008</code>) — | |
| Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.DeepseekOcr2TextConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.DeepseekOcr2TextConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.DeepseekOcr2TextConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>) — | |
| This is the number of key_value heads that should be used to implement Grouped Query Attention. If | |
| <code>num_key_value_heads=num_attention_heads</code>, the model will use Multi Head Attention (MHA), if | |
| <code>num_key_value_heads=1</code> 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, check out <a href="https://huggingface.co/papers/2305.13245" rel="nofollow">this | |
| paper</a>. If it is not specified, will default to | |
| <code>num_attention_heads</code>.`,name:"num_key_value_heads"},{anchor:"transformers.DeepseekOcr2TextConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>silu</code>) — | |
| The non-linear activation function (function or string) in the decoder. For example, <code>"gelu"</code>, | |
| <code>"relu"</code>, <code>"silu"</code>, etc.`,name:"hidden_act"},{anchor:"transformers.DeepseekOcr2TextConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2048</code>) — | |
| The maximum sequence length that this model might ever be used with.`,name:"max_position_embeddings"},{anchor:"transformers.DeepseekOcr2TextConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) — | |
| The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DeepseekOcr2TextConfig.rms_norm_eps",description:`<strong>rms_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-06</code>) — | |
| The epsilon used by the rms normalization layers.`,name:"rms_norm_eps"},{anchor:"transformers.DeepseekOcr2TextConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether or not the model should return the last key/values attentions (not used by all models). Only | |
| relevant if <code>config.is_decoder=True</code> or when the model is a decoder-only generative model.`,name:"use_cache"},{anchor:"transformers.DeepseekOcr2TextConfig.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>) — | |
| Token id used for padding in the vocabulary.`,name:"pad_token_id"},{anchor:"transformers.DeepseekOcr2TextConfig.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Token id used for beginning-of-stream in the vocabulary.`,name:"bos_token_id"},{anchor:"transformers.DeepseekOcr2TextConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>Union[int, list[int]]</code>, <em>optional</em>, defaults to <code>2</code>) — | |
| Token id used for end-of-stream in the vocabulary.`,name:"eos_token_id"},{anchor:"transformers.DeepseekOcr2TextConfig.pretraining_tp",description:`<strong>pretraining_tp</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Experimental feature. Tensor parallelism rank used during pretraining. Please refer to <a href="https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism" rel="nofollow">this | |
| document</a> to | |
| understand more about it. This value is necessary to ensure exact reproducibility of the pretraining | |
| results. Please refer to <a href="https://github.com/pytorch/pytorch/issues/76232" rel="nofollow">this issue</a>.`,name:"pretraining_tp"},{anchor:"transformers.DeepseekOcr2TextConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to tie weight embeddings according to model’s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"},{anchor:"transformers.DeepseekOcr2TextConfig.rope_parameters",description:`<strong>rope_parameters</strong> (<code>Union[~modeling_rope_utils.RopeParameters, dict]</code>, <em>optional</em>) — | |
| Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain | |
| a value for <code>rope_theta</code> and optionally parameters used for scaling in case you want to use RoPE | |
| with longer <code>max_position_embeddings</code>.`,name:"rope_parameters"},{anchor:"transformers.DeepseekOcr2TextConfig.attention_bias",description:`<strong>attention_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to use a bias in the query, key, value and output projection layers during self-attention.`,name:"attention_bias"},{anchor:"transformers.DeepseekOcr2TextConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.DeepseekOcr2TextConfig.mlp_bias",description:`<strong>mlp_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.`,name:"mlp_bias"},{anchor:"transformers.DeepseekOcr2TextConfig.head_dim",description:`<strong>head_dim</strong> (<code>int</code>, <em>optional</em>) — | |
| The attention head dimension. If None, it will default to hidden_size // num_attention_heads`,name:"head_dim"},{anchor:"transformers.DeepseekOcr2TextConfig.n_group",description:`<strong>n_group</strong> (<code>int</code>, <em>optional</em>) — | |
| Number of groups for grouped top-k expert routing.`,name:"n_group"},{anchor:"transformers.DeepseekOcr2TextConfig.n_routed_experts",description:`<strong>n_routed_experts</strong> (<code>int</code>, <em>optional</em>, defaults to <code>64</code>) — | |
| Number of routed experts.`,name:"n_routed_experts"},{anchor:"transformers.DeepseekOcr2TextConfig.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not the router logits should be returned by the model. Enabling this will also allow the model | |
| to output the auxiliary loss, including load balancing loss and router z-loss.`,name:"output_router_logits"},{anchor:"transformers.DeepseekOcr2TextConfig.n_shared_experts",description:`<strong>n_shared_experts</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2</code>) — | |
| Number of shared experts.`,name:"n_shared_experts"},{anchor:"transformers.DeepseekOcr2TextConfig.routed_scaling_factor",description:`<strong>routed_scaling_factor</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1.0</code>) — | |
| Scaling factor or routed experts.`,name:"routed_scaling_factor"},{anchor:"transformers.DeepseekOcr2TextConfig.topk_group",description:`<strong>topk_group</strong> (<code>int</code>, <em>optional</em>) — | |
| Number of selected groups for each token (for each token, ensuring the selected experts is only within <code>topk_group</code> groups).`,name:"topk_group"},{anchor:"transformers.DeepseekOcr2TextConfig.topk_method",description:`<strong>topk_method</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"greedy"</code>) — | |
| Method for selecting top-k experts in MoE layers.`,name:"topk_method"},{anchor:"transformers.DeepseekOcr2TextConfig.num_experts_per_tok",description:`<strong>num_experts_per_tok</strong> (<code>int</code>, <em>optional</em>) — | |
| Number of experts to route each token to. This is the top-k value for the token-choice routing.`,name:"num_experts_per_tok"},{anchor:"transformers.DeepseekOcr2TextConfig.moe_intermediate_size",description:`<strong>moe_intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1407</code>) — | |
| Intermediate size of the routed expert MLPs.`,name:"moe_intermediate_size"},{anchor:"transformers.DeepseekOcr2TextConfig.mlp_layer_types",description:`<strong>mlp_layer_types</strong> (<code>list[str]</code>, <em>optional</em>) — | |
| MLP type (<code>"dense"</code> or <code>"sparse"</code>) for each decoder layer, e.g. <code>["dense", "sparse", "sparse", ...]</code>.`,name:"mlp_layer_types"}]}),r(4),t(y);var $=e(y,2);s($,{title:"DeepseekOcr2ImageProcessor",local:"transformers.DeepseekOcr2ImageProcessor",headingTag:"h2"});var v=e($,2),K=n(v);o(K,{name:"class transformers.DeepseekOcr2ImageProcessor",anchor:"transformers.DeepseekOcr2ImageProcessor",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_deepseek_ocr2.py#L134",parameters:[{name:"**kwargs",val:": *<class 'transformers.models.deepseek_ocr2.image_processing_deepseek_ocr2.DeepseekOcr2ImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessor.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DeepseekOcr2ImageProcessor.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DeepseekOcr2ImageProcessor.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>, defaults to <code>{'height' -- 1024, 'width': 1024}</code>): | |
| Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DeepseekOcr2ImageProcessor.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) — | |
| Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DeepseekOcr2ImageProcessor.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>, defaults to <code>3</code>) — | |
| Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only | |
| has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DeepseekOcr2ImageProcessor.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DeepseekOcr2ImageProcessor.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>0.00392156862745098</code>) — | |
| Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DeepseekOcr2ImageProcessor.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DeepseekOcr2ImageProcessor.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) — | |
| Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DeepseekOcr2ImageProcessor.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) — | |
| Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to | |
| <code>True</code>.`,name:"image_std"},{anchor:"transformers.DeepseekOcr2ImageProcessor.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to pad the image. Padding is done either to the largest size in the batch | |
| or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DeepseekOcr2ImageProcessor.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) — | |
| The size in <code>{"height": int, "width" int}</code> to pad the images to. Must be larger than any image size | |
| provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest | |
| height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DeepseekOcr2ImageProcessor.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DeepseekOcr2ImageProcessor.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DeepseekOcr2ImageProcessor.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) — | |
| The channel dimension format for the input image. If unset, the channel dimension format is inferred | |
| from the input image. Can be one of: | |
| <ul> | |
| <li><code>"channels_first"</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li> | |
| <li><code>"channels_last"</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li> | |
| <li><code>"none"</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li> | |
| </ul>`,name:"input_data_format"},{anchor:"transformers.DeepseekOcr2ImageProcessor.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) — | |
| The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DeepseekOcr2ImageProcessor.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) — | |
| Returns stacked tensors if set to <code>'pt'</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DeepseekOcr2ImageProcessor.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to disable grouping of images by size to process them individually and not in batches. | |
| If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on | |
| empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DeepseekOcr2ImageProcessor.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) — | |
| The number of image tokens to be used for each image in the input. | |
| Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_to_patches",description:`<strong>crop_to_patches</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.crop_to_patches</code>) — | |
| Whether to crop the image to patches. Can be overridden by the <code>crop_to_patches</code> parameter in the | |
| <code>preprocess</code> method.`,name:"crop_to_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessor.min_patches",description:`<strong>min_patches</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.min_patches</code>) — | |
| The minimum number of patches to be extracted from the image. Only has an effect if <code>crop_to_patches</code> is | |
| set to <code>True</code>. Can be overridden by the <code>min_patches</code> parameter in the <code>preprocess</code> method.`,name:"min_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessor.max_patches",description:`<strong>max_patches</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.max_patches</code>) — | |
| The maximum number of patches to be extracted from the image. Only has an effect if <code>crop_to_patches</code> is | |
| set to <code>True</code>. Can be overridden by the <code>max_patches</code> parameter in the <code>preprocess</code> method.`,name:"max_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessor.tile_size",description:`<strong>tile_size</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>768</code>) — | |
| The size of each local tile. Must match the model’s query embedding size.`,name:"tile_size"},{anchor:"transformers.DeepseekOcr2ImageProcessor.background_color",description:`<strong>background_color</strong> (<code>list[int]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[127, 127, 127]</code>) — | |
| The background color for padding.`,name:"background_color"}]});var T=e(K,4),Ue=n(T);o(Ue,{name:"crop_image_to_patches",anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_deepseek_ocr2.py#L154",parameters:[{name:"images",val:": torch.Tensor"},{name:"min_patches",val:": int"},{name:"max_patches",val:": int"},{name:"tile_size",val:": int"},{name:"resample",val:": PIL.Image.Resampling | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches.images",description:`<strong>images</strong> (<code>torch.Tensor</code>) — | |
| The images to crop, shape <code>(batch, channels, height, width)</code>.`,name:"images"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches.min_patches",description:`<strong>min_patches</strong> (<code>int</code>) — | |
| Minimum number of patches.`,name:"min_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches.max_patches",description:`<strong>max_patches</strong> (<code>int</code>) — | |
| Maximum number of patches.`,name:"max_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches.tile_size",description:`<strong>tile_size</strong> (<code>int</code>) — | |
| The size of each tile.`,name:"tile_size"},{anchor:"transformers.DeepseekOcr2ImageProcessor.crop_image_to_patches.resample",description:`<strong>resample</strong> (<code>PILImageResampling</code>, <em>optional</em>) — | |
| Resampling filter for resizing.`,name:"resample"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>Stacked patches <code>(batch, num_patches, channels, tile_size, tile_size)</code> | |
| and number of patches per image.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>tuple[torch.Tensor, int]</code></p> | |
| `}),r(2),t(T);var w=e(T,2),Ie=n(w);o(Ie,{name:"get_number_of_image_patches",anchor:"transformers.DeepseekOcr2ImageProcessor.get_number_of_image_patches",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_deepseek_ocr2.py#L288",parameters:[{name:"height",val:": int"},{name:"width",val:": int"},{name:"images_kwargs",val:": dict | None = None"}]}),r(2),t(w);var ee=e(w,2),Ne=n(ee);o(Ne,{name:"pad_to_square",anchor:"transformers.DeepseekOcr2ImageProcessor.pad_to_square",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_deepseek_ocr2.py#L308",parameters:[{name:"images",val:": torch.Tensor"},{name:"background_color",val:": int | tuple[int, int, int] = 0"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessor.pad_to_square.images",description:`<strong>images</strong> (<code>torch.Tensor</code>) — | |
| The images to pad. Shape: (batch_size, num_channels, height, width) or (num_channels, height, width).`,name:"images"},{anchor:"transformers.DeepseekOcr2ImageProcessor.pad_to_square.background_color",description:`<strong>background_color</strong> (<code>int</code> or <code>tuple[int, int, int]</code>, <em>optional</em>, defaults to 0) — | |
| The color to use for the padding. Can be an integer for single channel or a | |
| tuple of integers representing for multi-channel images. If passed as integer | |
| in multi-channel mode, it will default to <code>0</code> in subsequent channels.`,name:"background_color"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The padded images.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>torch.Tensor</code></p> | |
| `}),r(2),t(ee),t(v);var oe=e(v,2);s(oe,{title:"DeepseekOcr2ImageProcessorPil",local:"transformers.DeepseekOcr2ImageProcessorPil",headingTag:"h2"});var M=e(oe,2),ne=n(M);o(ne,{name:"class transformers.DeepseekOcr2ImageProcessorPil",anchor:"transformers.DeepseekOcr2ImageProcessorPil",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_pil_deepseek_ocr2.py#L144",parameters:[{name:"**kwargs",val:": *<class 'transformers.models.deepseek_ocr2.image_processing_pil_deepseek_ocr2.DeepseekOcr2ImageProcessorKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_convert_rgb",description:`<strong>do_convert_rgb</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to convert the image to RGB.`,name:"do_convert_rgb"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_resize",description:`<strong>do_resize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to resize the image.`,name:"do_resize"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.size",description:`<strong>size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>, defaults to <code>{'height' -- 1024, 'width': 1024}</code>): | |
| Describes the maximum input dimensions to the model.`,name:"size"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.default_to_square",description:`<strong>default_to_square</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to default to a square image when resizing, if size is an int.`,name:"default_to_square"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.crop_size",description:`<strong>crop_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) — | |
| Size of the output image after applying <code>center_crop</code>.`,name:"crop_size"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.resample",description:`<strong>resample</strong> (<code>Annotated[Union[int, PILImageResampling, NoneType], None]</code>, <em>kwargs</em>, defaults to <code>3</code>) — | |
| Resampling filter to use if resizing the image. This can be one of the enum <code>PILImageResampling</code>. Only | |
| has an effect if <code>do_resize</code> is set to <code>True</code>.`,name:"resample"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_rescale",description:`<strong>do_rescale</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to rescale the image.`,name:"do_rescale"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.rescale_factor",description:`<strong>rescale_factor</strong> (<code>float</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>0.00392156862745098</code>) — | |
| Rescale factor to rescale the image by if <code>do_rescale</code> is set to <code>True</code>.`,name:"rescale_factor"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to normalize the image.`,name:"do_normalize"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.image_mean",description:`<strong>image_mean</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) — | |
| Image mean to use for normalization. Only has an effect if <code>do_normalize</code> is set to <code>True</code>.`,name:"image_mean"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.image_std",description:`<strong>image_std</strong> (<code>Union[float, list[float], tuple[float, ...]]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[0.5, 0.5, 0.5]</code>) — | |
| Image standard deviation to use for normalization. Only has an effect if <code>do_normalize</code> is set to | |
| <code>True</code>.`,name:"image_std"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_pad",description:`<strong>do_pad</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to pad the image. Padding is done either to the largest size in the batch | |
| or to a fixed square size per image. The exact padding strategy depends on the model.`,name:"do_pad"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.pad_size",description:`<strong>pad_size</strong> (<code>Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None]</code>, <em>kwargs</em>) — | |
| The size in <code>{"height": int, "width" int}</code> to pad the images to. Must be larger than any image size | |
| provided for preprocessing. If <code>pad_size</code> is not provided, images will be padded to the largest | |
| height and width in the batch. Applied only when <code>do_pad=True.</code>`,name:"pad_size"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.do_center_crop",description:`<strong>do_center_crop</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to center crop the image.`,name:"do_center_crop"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.data_format",description:`<strong>data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Only <code>ChannelDimension.FIRST</code> is supported. Added for compatibility with slow processors.`,name:"data_format"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.input_data_format",description:`<strong>input_data_format</strong> (<code>Union[str, ~image_utils.ChannelDimension]</code>, <em>kwargs</em>, <em>optional</em>) — | |
| The channel dimension format for the input image. If unset, the channel dimension format is inferred | |
| from the input image. Can be one of: | |
| <ul> | |
| <li><code>"channels_first"</code> or <code>ChannelDimension.FIRST</code>: image in (num_channels, height, width) format.</li> | |
| <li><code>"channels_last"</code> or <code>ChannelDimension.LAST</code>: image in (height, width, num_channels) format.</li> | |
| <li><code>"none"</code> or <code>ChannelDimension.NONE</code>: image in (height, width) format.</li> | |
| </ul>`,name:"input_data_format"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.device",description:`<strong>device</strong> (<code>Annotated[Union[str, torch.device, NoneType], None]</code>, <em>kwargs</em>) — | |
| The device to process the videos on. If unset, the device is inferred from the input videos.`,name:"device"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.return_tensors",description:`<strong>return_tensors</strong> (<code>Annotated[str | ~utils.generic.TensorType | None, None]</code>, <em>kwargs</em>) — | |
| Returns stacked tensors if set to <code>'pt'</code>, otherwise returns a list of tensors.`,name:"return_tensors"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.disable_grouping",description:`<strong>disable_grouping</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>) — | |
| Whether to disable grouping of images by size to process them individually and not in batches. | |
| If None, will be set to True if the images are on CPU, and False otherwise. This choice is based on | |
| empirical observations, as detailed here: <a href="https://github.com/huggingface/transformers/pull/38157" rel="nofollow">https://github.com/huggingface/transformers/pull/38157</a>`,name:"disable_grouping"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.image_seq_length",description:`<strong>image_seq_length</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>) — | |
| The number of image tokens to be used for each image in the input. | |
| Added for backward compatibility but this should be set as a processor attribute in future models.`,name:"image_seq_length"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.crop_to_patches",description:`<strong>crop_to_patches</strong> (<code>bool</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.crop_to_patches</code>) — | |
| Whether to crop the image to patches. Can be overridden by the <code>crop_to_patches</code> parameter in the | |
| <code>preprocess</code> method.`,name:"crop_to_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.min_patches",description:`<strong>min_patches</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.min_patches</code>) — | |
| The minimum number of patches to be extracted from the image. Only has an effect if <code>crop_to_patches</code> is | |
| set to <code>True</code>. Can be overridden by the <code>min_patches</code> parameter in the <code>preprocess</code> method.`,name:"min_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.max_patches",description:`<strong>max_patches</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>self.max_patches</code>) — | |
| The maximum number of patches to be extracted from the image. Only has an effect if <code>crop_to_patches</code> is | |
| set to <code>True</code>. Can be overridden by the <code>max_patches</code> parameter in the <code>preprocess</code> method.`,name:"max_patches"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.tile_size",description:`<strong>tile_size</strong> (<code>int</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>768</code>) — | |
| The size of each local tile. Must match the model’s query embedding size.`,name:"tile_size"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.background_color",description:`<strong>background_color</strong> (<code>list[int]</code>, <em>kwargs</em>, <em>optional</em>, defaults to <code>[127, 127, 127]</code>) — | |
| The background color for padding.`,name:"background_color"}]});var x=e(ne,4),Pe=n(x);o(Pe,{name:"crop_image_to_patches",anchor:"transformers.DeepseekOcr2ImageProcessorPil.crop_image_to_patches",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_pil_deepseek_ocr2.py#L164",parameters:[{name:"image",val:": ndarray"},{name:"min_patches",val:": int"},{name:"max_patches",val:": int"},{name:"tile_size",val:": int"},{name:"resample",val:": PILImageResampling | int | None = None"}]}),r(2),t(x);var D=e(x,2),je=n(D);o(je,{name:"get_number_of_image_patches",anchor:"transformers.DeepseekOcr2ImageProcessorPil.get_number_of_image_patches",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_pil_deepseek_ocr2.py#L276",parameters:[{name:"height",val:": int"},{name:"width",val:": int"},{name:"images_kwargs",val:": dict | None = None"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessorPil.get_number_of_image_patches.height",description:`<strong>height</strong> (<code>int</code>) — | |
| Height of the input image.`,name:"height"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.get_number_of_image_patches.width",description:`<strong>width</strong> (<code>int</code>) — | |
| Width of the input image.`,name:"width"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.get_number_of_image_patches.images_kwargs",description:`<strong>images_kwargs</strong> (<code>dict</code>, <em>optional</em>) — | |
| Any kwargs to override defaults of the image processor.`,name:"images_kwargs"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>Number of patches per image.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>int</code></p> | |
| `}),r(2),t(D);var te=e(D,2),Je=n(te);o(Je,{name:"pad_to_square",anchor:"transformers.DeepseekOcr2ImageProcessorPil.pad_to_square",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/image_processing_pil_deepseek_ocr2.py#L311",parameters:[{name:"image",val:": ndarray"},{name:"background_color",val:": int | tuple[int, int, int] = 0"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ImageProcessorPil.pad_to_square.image",description:`<strong>image</strong> (<code>np.ndarray</code>) — | |
| The image to pad. Shape: (num_channels, height, width) - always channels_first in backend.`,name:"image"},{anchor:"transformers.DeepseekOcr2ImageProcessorPil.pad_to_square.background_color",description:`<strong>background_color</strong> (<code>int</code> or <code>tuple[int, int, int]</code>, <em>optional</em>, defaults to 0) — | |
| The color to use for the padding.`,name:"background_color"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The padded image.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>np.ndarray</code></p> | |
| `}),r(2),t(te),t(M);var se=e(M,2);s(se,{title:"DeepseekOcr2Processor",local:"transformers.DeepseekOcr2Processor",headingTag:"h2"});var O=e(se,2),qe=n(O);o(qe,{name:"class transformers.DeepseekOcr2Processor",anchor:"transformers.DeepseekOcr2Processor",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/processing_deepseek_ocr2.py#L43",parameters:[{name:"image_processor",val:" = None"},{name:"tokenizer",val:" = None"},{name:"chat_template",val:" = None"},{name:"patch_size",val:" = 16"},{name:"downsample_ratio",val:" = 4"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DeepseekOcr2Processor.image_processor",description:`<strong>image_processor</strong> (<code>DeepseekOcr2ImageProcessor</code>) — | |
| The image processor is a required input.`,name:"image_processor"},{anchor:"transformers.DeepseekOcr2Processor.tokenizer",description:`<strong>tokenizer</strong> (<code>TokenizersBackend</code>) — | |
| The tokenizer is a required input.`,name:"tokenizer"},{anchor:"transformers.DeepseekOcr2Processor.chat_template",description:`<strong>chat_template</strong> (<code>str</code>) — | |
| A Jinja template to convert lists of messages in a chat into a tokenizable string.`,name:"chat_template"},{anchor:"transformers.DeepseekOcr2Processor.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16</code>) — | |
| The patch size used by the vision encoder (SAM ViT patch embedding size).`,name:"patch_size"},{anchor:"transformers.DeepseekOcr2Processor.downsample_ratio",description:`<strong>downsample_ratio</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4</code>) — | |
| The downsampling ratio applied after the vision encoder.`,name:"downsample_ratio"}]}),r(4),t(O);var re=e(O,2);s(re,{title:"DeepseekOcr2TextModel",local:"transformers.DeepseekOcr2TextModel",headingTag:"h2"});var C=e(re,2),ae=n(C);o(ae,{name:"class transformers.DeepseekOcr2TextModel",anchor:"transformers.DeepseekOcr2TextModel",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1313",parameters:[{name:"config",val:": DeepseekOcr2TextConfig"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2TextModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2TextConfig">DeepseekOcr2TextConfig</a>) — | |
| 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 | |
| <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var ie=e(ae,8),ce=n(ie);o(ce,{name:"forward",anchor:"transformers.DeepseekOcr2TextModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1330",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"position_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"use_cache",val:": bool | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2TextModel.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.</p> | |
| <p>Indices can be obtained using <a href="/docs/transformers/pr_48731/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p> | |
| <p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.DeepseekOcr2TextModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p> | |
| <ul> | |
| <li>1 for tokens that are <strong>not masked</strong>,</li> | |
| <li>0 for tokens that are <strong>masked</strong>.</li> | |
| </ul> | |
| <p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.DeepseekOcr2TextModel.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of positions of each input sequence tokens in the position embeddings. Selected in the range <code>[0, config.n_positions - 1]</code>.</p> | |
| <p><a href="../glossary#position-ids">What are position IDs?</a>`,name:"position_ids"},{anchor:"transformers.DeepseekOcr2TextModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>~cache_utils.Cache</code>, <em>optional</em>) — | |
| Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention | |
| blocks) that can be used to speed up sequential decoding. This typically consists in the <code>past_key_values</code> | |
| returned by the model at a previous stage of decoding, when <code>use_cache=True</code> or <code>config.use_cache=True</code>.</p> | |
| <p>Only <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance is allowed as input, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>. | |
| If no <code>past_key_values</code> are passed, <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.DynamicCache">DynamicCache</a> will be initialized by default.</p> | |
| <p>The model will output the same cache format that is fed as input.</p> | |
| <p>If <code>past_key_values</code> are used, the user is expected to input only unprocessed <code>input_ids</code> (those that don’t | |
| have their past key value states given to this model) of shape <code>(batch_size, unprocessed_length)</code> instead of all <code>input_ids</code> | |
| of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.DeepseekOcr2TextModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — | |
| Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This | |
| is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the | |
| model’s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.DeepseekOcr2TextModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see | |
| <code>past_key_values</code>).`,name:"use_cache"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>MoeModelOutputWithPast</code> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>MoeModelOutputWithPast</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var Fe=e(ce,4);h(Fe,{children:(a,c)=>{var i=g();d(a,i)},$$slots:{default:!0}}),r(2),t(ie),t(C);var de=e(C,2);s(de,{title:"DeepseekOcr2VisionModel",local:"transformers.DeepseekOcr2VisionModel",headingTag:"h2"});var z=e(de,2),le=n(z);o(le,{name:"class transformers.DeepseekOcr2VisionModel",anchor:"transformers.DeepseekOcr2VisionModel",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L954",parameters:[{name:"config",val:": DeepseekOcr2VisionConfig"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2VisionModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2VisionConfig">DeepseekOcr2VisionConfig</a>) — | |
| 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 | |
| <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var pe=e(le,8),me=n(pe);o(me,{name:"forward",anchor:"transformers.DeepseekOcr2VisionModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L965",parameters:[{name:"pixel_values",val:": Tensor"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2VisionModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a>. See <a href="/docs/transformers/pr_48731/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DeepseekOcr2ImageProcessor.<strong>call</strong>()</a> for details (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Processor">DeepseekOcr2Processor</a> uses | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a> for processing images).`,name:"pixel_values"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutput" | |
| >BaseModelOutput</a> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutput" | |
| >BaseModelOutput</a> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var Re=e(me,4);h(Re,{children:(a,c)=>{var i=g();d(a,i)},$$slots:{default:!0}}),r(2),t(pe),t(z);var he=e(z,2);s(he,{title:"DeepseekOcr2Model",local:"transformers.DeepseekOcr2Model",headingTag:"h2"});var U=e(he,2),ge=n(U);o(ge,{name:"class transformers.DeepseekOcr2Model",anchor:"transformers.DeepseekOcr2Model",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1394",parameters:[{name:"config",val:": DeepseekOcr2Config"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2Model.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config">DeepseekOcr2Config</a>) — | |
| 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 | |
| <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var I=e(ge,8),ue=n(I);o(ue,{name:"forward",anchor:"transformers.DeepseekOcr2Model.forward",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1492",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"pixel_values",val:": typing.Optional[torch.FloatTensor] = None"},{name:"pixel_values_local",val:": typing.Optional[torch.FloatTensor] = None"},{name:"num_local_patches",val:": typing.Union[list[int], torch.Tensor, NoneType] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"position_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"use_cache",val:": bool | None = None"},{name:"mm_encoder_outputs",val:": dict[str, transformers.modeling_outputs.BaseModelOutputWithPooling] | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2Model.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.</p> | |
| <p>Indices can be obtained using <a href="/docs/transformers/pr_48731/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p> | |
| <p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.DeepseekOcr2Model.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a>. See <a href="/docs/transformers/pr_48731/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DeepseekOcr2ImageProcessor.<strong>call</strong>()</a> for details (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Processor">DeepseekOcr2Processor</a> uses | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DeepseekOcr2Model.forward.pixel_values_local",description:`<strong>pixel_values_local</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) — | |
| Local patch pixel values of shape <code>(total_patches, 3, H, W)</code>.`,name:"pixel_values_local"},{anchor:"transformers.DeepseekOcr2Model.forward.num_local_patches",description:`<strong>num_local_patches</strong> (<code>list[int]</code> or <code>torch.Tensor</code>, <em>optional</em>) — | |
| Number of local patches per image in the batch.`,name:"num_local_patches"},{anchor:"transformers.DeepseekOcr2Model.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p> | |
| <ul> | |
| <li>1 for tokens that are <strong>not masked</strong>,</li> | |
| <li>0 for tokens that are <strong>masked</strong>.</li> | |
| </ul> | |
| <p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.DeepseekOcr2Model.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of positions of each input sequence tokens in the position embeddings. Selected in the range <code>[0, config.n_positions - 1]</code>.</p> | |
| <p><a href="../glossary#position-ids">What are position IDs?</a>`,name:"position_ids"},{anchor:"transformers.DeepseekOcr2Model.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>~cache_utils.Cache</code>, <em>optional</em>) — | |
| Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention | |
| blocks) that can be used to speed up sequential decoding. This typically consists in the <code>past_key_values</code> | |
| returned by the model at a previous stage of decoding, when <code>use_cache=True</code> or <code>config.use_cache=True</code>.</p> | |
| <p>Only <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance is allowed as input, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>. | |
| If no <code>past_key_values</code> are passed, <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.DynamicCache">DynamicCache</a> will be initialized by default.</p> | |
| <p>The model will output the same cache format that is fed as input.</p> | |
| <p>If <code>past_key_values</code> are used, the user is expected to input only unprocessed <code>input_ids</code> (those that don’t | |
| have their past key value states given to this model) of shape <code>(batch_size, unprocessed_length)</code> instead of all <code>input_ids</code> | |
| of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.DeepseekOcr2Model.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — | |
| Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This | |
| is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the | |
| model’s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.DeepseekOcr2Model.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see | |
| <code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.DeepseekOcr2Model.forward.mm_encoder_outputs",description:`<strong>mm_encoder_outputs</strong> (<code>dict[str, ~modeling_outputs.BaseModelOutputWithPooling]</code>, <em>optional</em>) — | |
| Dict where keys are supported modalities and values are encoded outputs for that modality. Each encoded output is a tuple | |
| that consists of (<code>pooler_output</code>, <em>optional</em>: <code>last_hidden_states</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>) | |
| <code>pooler_output</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) is a sequence of | |
| multimmodal features of the encoder merged into text embeddings.`,name:"mm_encoder_outputs"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>DeepseekOcr2ModelOutputWithPast</code> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>DeepseekOcr2ModelOutputWithPast</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var Ve=e(ue,4);h(Ve,{children:(a,c)=>{var i=g();d(a,i)},$$slots:{default:!0}}),r(2),t(I);var N=e(I,2),We=n(N);o(We,{name:"get_image_features",anchor:"transformers.DeepseekOcr2Model.get_image_features",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1413",parameters:[{name:"pixel_values",val:": FloatTensor"},{name:"pixel_values_local",val:": typing.Optional[torch.FloatTensor] = None"},{name:"num_local_patches",val:": typing.Union[list[int], torch.Tensor, NoneType] = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2Model.get_image_features.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a>. See <a href="/docs/transformers/pr_48731/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DeepseekOcr2ImageProcessor.<strong>call</strong>()</a> for details (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Processor">DeepseekOcr2Processor</a> uses | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DeepseekOcr2Model.get_image_features.pixel_values_local",description:`<strong>pixel_values_local</strong> (<code>torch.FloatTensor</code> of shape <code>(total_patches, 3, height, width)</code>, <em>optional</em>) — | |
| All local patches flattened across the batch, or <code>None</code> if no local views.`,name:"pixel_values_local"},{anchor:"transformers.DeepseekOcr2Model.get_image_features.num_local_patches",description:`<strong>num_local_patches</strong> (<code>list[int]</code> or <code>torch.Tensor</code>, <em>optional</em>) — | |
| Number of local patches per image, e.g. <code>[6, 0, 4]</code>.`,name:"num_local_patches"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling" | |
| >BaseModelOutputWithPooling</a> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling" | |
| >BaseModelOutputWithPooling</a> or <code>tuple(torch.FloatTensor)</code></p> | |
| `}),r(2),t(N);var _e=e(N,2),Ze=n(_e);o(Ze,{name:"get_placeholder_mask",anchor:"transformers.DeepseekOcr2Model.get_placeholder_mask",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1469",parameters:[{name:"input_ids",val:": LongTensor"},{name:"inputs_embeds",val:": FloatTensor"},{name:"image_features",val:": FloatTensor"}]}),r(2),t(_e),t(U);var fe=e(U,2);s(fe,{title:"DeepseekOcr2ForConditionalGeneration",local:"transformers.DeepseekOcr2ForConditionalGeneration",headingTag:"h2"});var P=e(fe,2),ke=n(P);o(ke,{name:"class transformers.DeepseekOcr2ForConditionalGeneration",anchor:"transformers.DeepseekOcr2ForConditionalGeneration",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1553",parameters:[{name:"config",val:": DeepseekOcr2Config"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config">DeepseekOcr2Config</a>) — | |
| 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 | |
| <a href="/docs/transformers/pr_48731/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var j=e(ke,8),be=n(j);o(be,{name:"forward",anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1593",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"pixel_values",val:": typing.Optional[torch.FloatTensor] = None"},{name:"pixel_values_local",val:": typing.Optional[torch.FloatTensor] = None"},{name:"num_local_patches",val:": typing.Union[list[int], torch.Tensor, NoneType] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"position_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"use_cache",val:": bool | None = None"},{name:"logits_to_keep",val:": typing.Union[int, torch.Tensor] = 0"},{name:"mm_encoder_outputs",val:": dict[str, transformers.modeling_outputs.BaseModelOutputWithPooling] | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.</p> | |
| <p>Indices can be obtained using <a href="/docs/transformers/pr_48731/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_48731/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p> | |
| <p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a>. See <a href="/docs/transformers/pr_48731/en/model_doc/molmo2#transformers.Molmo2ImageProcessor.__call__">DeepseekOcr2ImageProcessor.<strong>call</strong>()</a> for details (<a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Processor">DeepseekOcr2Processor</a> uses | |
| <a href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2ImageProcessor">DeepseekOcr2ImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.pixel_values_local",description:`<strong>pixel_values_local</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) — | |
| Local patch pixel values of shape <code>(total_patches, 3, H, W)</code>.`,name:"pixel_values_local"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.num_local_patches",description:`<strong>num_local_patches</strong> (<code>list[int]</code> or <code>torch.Tensor</code>, <em>optional</em>) — | |
| Number of local patches per image in the batch.`,name:"num_local_patches"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p> | |
| <ul> | |
| <li>1 for tokens that are <strong>not masked</strong>,</li> | |
| <li>0 for tokens that are <strong>masked</strong>.</li> | |
| </ul> | |
| <p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Indices of positions of each input sequence tokens in the position embeddings. Selected in the range <code>[0, config.n_positions - 1]</code>.</p> | |
| <p><a href="../glossary#position-ids">What are position IDs?</a>`,name:"position_ids"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>~cache_utils.Cache</code>, <em>optional</em>) — | |
| Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention | |
| blocks) that can be used to speed up sequential decoding. This typically consists in the <code>past_key_values</code> | |
| returned by the model at a previous stage of decoding, when <code>use_cache=True</code> or <code>config.use_cache=True</code>.</p> | |
| <p>Only <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.Cache">Cache</a> instance is allowed as input, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>. | |
| If no <code>past_key_values</code> are passed, <a href="/docs/transformers/pr_48731/en/internal/generation_utils#transformers.DynamicCache">DynamicCache</a> will be initialized by default.</p> | |
| <p>The model will output the same cache format that is fed as input.</p> | |
| <p>If <code>past_key_values</code> are used, the user is expected to input only unprocessed <code>input_ids</code> (those that don’t | |
| have their past key value states given to this model) of shape <code>(batch_size, unprocessed_length)</code> instead of all <code>input_ids</code> | |
| of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — | |
| Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This | |
| is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the | |
| model’s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Labels for computing the masked language modeling loss. Indices should either be in <code>[0, ..., config.vocab_size]</code> or -100 (see <code>input_ids</code> docstring). Tokens with indices set to <code>-100</code> are ignored | |
| (masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>.`,name:"labels"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see | |
| <code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.logits_to_keep",description:`<strong>logits_to_keep</strong> (<code>Union[int, torch.Tensor]</code>, <em>optional</em>, defaults to <code>0</code>) — | |
| If an <code>int</code>, compute logits for the last <code>logits_to_keep</code> tokens. If <code>0</code>, calculate logits for all | |
| <code>input_ids</code> (special case). Only last token logits are needed for generation, and calculating them only for that | |
| token can save memory, which becomes pretty significant for long sequences or large vocabulary size. | |
| If a <code>torch.Tensor</code>, must be 1D corresponding to the indices to keep in the sequence length dimension. | |
| This is useful when using packed tensor format (single dimension for batch and sequence length).`,name:"logits_to_keep"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.mm_encoder_outputs",description:`<strong>mm_encoder_outputs</strong> (<code>dict[str, ~modeling_outputs.BaseModelOutputWithPooling]</code>, <em>optional</em>) — | |
| Dict where keys are supported modalities and values are encoded outputs for that modality. Each encoded output is a tuple | |
| that consists of (<code>pooler_output</code>, <em>optional</em>: <code>last_hidden_states</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>) | |
| <code>pooler_output</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) is a sequence of | |
| multimmodal features of the encoder merged into text embeddings.`,name:"mm_encoder_outputs"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>DeepseekOcr2CausalLMOutputWithPast</code> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>DeepseekOcr2CausalLMOutputWithPast</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var ye=e(be,4);h(ye,{children:(a,c)=>{var i=g();d(a,i)},$$slots:{default:!0}});var Se=e(ye,4);J(Se,{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.forward.example",children:(a,c)=>{var i=q(),l=e(m(i),2);p(l,{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBEZWVwc2Vla09jcjJGb3JDb25kaXRpb25hbEdlbmVyYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMERlZXBzZWVrT2NyMkZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyZGVlcHNlZWstY29tbXVuaXR5JTJGRGVlcFNlZWstT0NSLTIlMjIpJTBBcHJvY2Vzc29yJTIwJTNEJTIwQXV0b1Byb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyZGVlcHNlZWstY29tbXVuaXR5JTJGRGVlcFNlZWstT0NSLTIlMjIpJTBBJTBBbWVzc2FnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0IlMjJ0eXBlJTIyJTNBJTIwJTIyaW1hZ2UlMjIlMkMlMjAlMjJ1cmwlMjIlM0ElMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZodWdnaW5nZmFjZSUyRmRvY3VtZW50YXRpb24taW1hZ2VzJTJGcmVzb2x2ZSUyRm1haW4lMkZwaXBlbGluZS1jYXQtY2hvbmsuanBlZyUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUyMnR5cGUlMjIlM0ElMjAlMjJ0ZXh0JTIyJTJDJTIwJTIydGV4dCUyMiUzQSUyMCUyMldoZXJlJTIwaXMlMjB0aGUlMjBjYXQlMjBzdGFuZGluZyUzRiUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1RCUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSU1RCUwQSUwQWlucHV0cyUyMCUzRCUyMHByb2Nlc3Nvci5hcHBseV9jaGF0X3RlbXBsYXRlKCUwQSUyMCUyMCUyMCUyMG1lc3NhZ2VzJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX2RpY3QlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiUyQyUwQSUyMCUyMCUyMCUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMEEpJTBBJTIzJTIwR2VuZXJhdGUlMEFnZW5lcmF0ZV9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyklMEFwcm9jZXNzb3IuYmF0Y2hfZGVjb2RlKGdlbmVyYXRlX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, DeepseekOcr2ForConditionalGeneration | |
| <span class="hljs-meta">>>> </span>model = DeepseekOcr2ForConditionalGeneration.from_pretrained(<span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>) | |
| <span class="hljs-meta">>>> </span>processor = AutoProcessor.from_pretrained(<span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>) | |
| <span class="hljs-meta">>>> </span>messages = [ | |
| <span class="hljs-meta">... </span> { | |
| <span class="hljs-meta">... </span> <span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: [ | |
| <span class="hljs-meta">... </span> {<span class="hljs-string">"type"</span>: <span class="hljs-string">"image"</span>, <span class="hljs-string">"url"</span>: <span class="hljs-string">"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"</span>}, | |
| <span class="hljs-meta">... </span> {<span class="hljs-string">"type"</span>: <span class="hljs-string">"text"</span>, <span class="hljs-string">"text"</span>: <span class="hljs-string">"Where is the cat standing?"</span>}, | |
| <span class="hljs-meta">... </span> ] | |
| <span class="hljs-meta">... </span> }, | |
| <span class="hljs-meta">... </span>] | |
| <span class="hljs-meta">>>> </span>inputs = processor.apply_chat_template( | |
| <span class="hljs-meta">... </span> messages, | |
| <span class="hljs-meta">... </span> tokenize=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span> return_dict=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span> return_tensors=<span class="hljs-string">"pt"</span>, | |
| <span class="hljs-meta">... </span> add_generation_prompt=<span class="hljs-literal">True</span> | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Generate</span> | |
| <span class="hljs-meta">>>> </span>generate_ids = model.generate(**inputs) | |
| <span class="hljs-meta">>>> </span>processor.batch_decode(generate_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`,lang:"python",wrap:!1}),d(a,i)},$$slots:{default:!0}}),t(j);var ve=e(j,2),Te=n(ve);o(Te,{name:"get_image_features",anchor:"transformers.DeepseekOcr2ForConditionalGeneration.get_image_features",source:"https://github.com/huggingface/transformers/blob/vr_48731/src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py#L1569",parameters:[{name:"pixel_values",val:": FloatTensor"},{name:"pixel_values_local",val:": typing.Optional[torch.FloatTensor] = None"},{name:"num_local_patches",val:": typing.Union[list[int], torch.Tensor, NoneType] = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.get_image_features.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, 3, height, width)</code>) — | |
| The tensors corresponding to the global view input images.`,name:"pixel_values"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.get_image_features.pixel_values_local",description:`<strong>pixel_values_local</strong> (<code>torch.FloatTensor</code> of shape <code>(total_patches, 3, height, width)</code>, <em>optional</em>) — | |
| All local patches flattened across the batch, or <code>None</code> if no local views.`,name:"pixel_values_local"},{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.get_image_features.num_local_patches",description:`<strong>num_local_patches</strong> (<code>list[int]</code> or <code>torch.Tensor</code>, <em>optional</em>) — | |
| Number of local patches per image, e.g. <code>[6, 0, 4]</code>.`,name:"num_local_patches"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling" | |
| >BaseModelOutputWithPooling</a> or a tuple of | |
| <code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various | |
| elements depending on the configuration (<a | |
| href="/docs/transformers/pr_48731/en/model_doc/deepseek_ocr2#transformers.DeepseekOcr2Config" | |
| >DeepseekOcr2Config</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><a | |
| href="/docs/transformers/pr_48731/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling" | |
| >BaseModelOutputWithPooling</a> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var Ae=e(Te,4);J(Ae,{anchor:"transformers.DeepseekOcr2ForConditionalGeneration.get_image_features.example",children:(a,c)=>{var i=q(),l=e(m(i),2);p(l,{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMkMlMjBEZWVwc2Vla09jcjJGb3JDb25kaXRpb25hbEdlbmVyYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMERlZXBzZWVrT2NyMkZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyZGVlcHNlZWstY29tbXVuaXR5JTJGRGVlcFNlZWstT0NSLTIlMjIpJTBBcHJvY2Vzc29yJTIwJTNEJTIwQXV0b1Byb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyZGVlcHNlZWstY29tbXVuaXR5JTJGRGVlcFNlZWstT0NSLTIlMjIpJTBBJTBBbWVzc2FnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0IlMjJ0eXBlJTIyJTNBJTIwJTIyaW1hZ2UlMjIlMkMlMjAlMjJ1cmwlMjIlM0ElMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZodWdnaW5nZmFjZSUyRmRvY3VtZW50YXRpb24taW1hZ2VzJTJGcmVzb2x2ZSUyRm1haW4lMkZwaXBlbGluZS1jYXQtY2hvbmsuanBlZyUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUyMnR5cGUlMjIlM0ElMjAlMjJ0ZXh0JTIyJTJDJTIwJTIydGV4dCUyMiUzQSUyMCUyMldoZXJlJTIwaXMlMjB0aGUlMjBjYXQlMjBzdGFuZGluZyUzRiUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1RCUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSU1RCUwQSUwQWlucHV0cyUyMCUzRCUyMHByb2Nlc3Nvci5hcHBseV9jaGF0X3RlbXBsYXRlKCUwQSUyMCUyMCUyMCUyMG1lc3NhZ2VzJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX2RpY3QlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiUyQyUwQSUyMCUyMCUyMCUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMEEpJTBBJTIzJTIwR2VuZXJhdGUlMEFnZW5lcmF0ZV9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyklMEFwcm9jZXNzb3IuYmF0Y2hfZGVjb2RlKGdlbmVyYXRlX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, DeepseekOcr2ForConditionalGeneration | |
| <span class="hljs-meta">>>> </span>model = DeepseekOcr2ForConditionalGeneration.from_pretrained(<span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>) | |
| <span class="hljs-meta">>>> </span>processor = AutoProcessor.from_pretrained(<span class="hljs-string">"deepseek-community/DeepSeek-OCR-2"</span>) | |
| <span class="hljs-meta">>>> </span>messages = [ | |
| <span class="hljs-meta">... </span> { | |
| <span class="hljs-meta">... </span> <span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: [ | |
| <span class="hljs-meta">... </span> {<span class="hljs-string">"type"</span>: <span class="hljs-string">"image"</span>, <span class="hljs-string">"url"</span>: <span class="hljs-string">"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"</span>}, | |
| <span class="hljs-meta">... </span> {<span class="hljs-string">"type"</span>: <span class="hljs-string">"text"</span>, <span class="hljs-string">"text"</span>: <span class="hljs-string">"Where is the cat standing?"</span>}, | |
| <span class="hljs-meta">... </span> ] | |
| <span class="hljs-meta">... </span> }, | |
| <span class="hljs-meta">... </span>] | |
| <span class="hljs-meta">>>> </span>inputs = processor.apply_chat_template( | |
| <span class="hljs-meta">... </span> messages, | |
| <span class="hljs-meta">... </span> tokenize=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span> return_dict=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span> return_tensors=<span class="hljs-string">"pt"</span>, | |
| <span class="hljs-meta">... </span> add_generation_prompt=<span class="hljs-literal">True</span> | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Generate</span> | |
| <span class="hljs-meta">>>> </span>generate_ids = model.generate(**inputs) | |
| <span class="hljs-meta">>>> </span>processor.batch_decode(generate_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`,lang:"python",wrap:!1}),d(a,i)},$$slots:{default:!0}}),t(ve),t(P);var Be=e(P,2);Xe(Be,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/deepseek_ocr2.md"}),r(2),d(we,F),$e()}export{io as component}; | |
Xet Storage Details
- Size:
- 142 kB
- Xet hash:
- 97421feff9bb65af8a8f9311c8c535c5e8c9842a008e487f5686b1c951672b07
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.