Stage Harbor release files 34501-35000
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cohere2_vision.md +140 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/colpali.md +171 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/colqwen2.md +177 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/conditional_detr.md +84 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convbert.md +142 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convnext.md +105 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convnextv2.md +74 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cpm.md +63 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cpmant.md +52 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/csm.md +383 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/ctrl.md +111 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cvt.md +121 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/d_fine.md +77 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dab-detr.md +124 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dac.md +85 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/data2vec.md +235 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dbrx.md +126 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deberta-v2.md +219 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deberta.md +187 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/decision_transformer.md +58 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_v2.md +50 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_v3.md +185 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_vl.md +225 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_vl_hybrid.md +224 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deformable_detr.md +126 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deit.md +188 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deplot.md +71 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_anything.md +89 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_anything_v2.md +113 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_pro.md +188 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deta.md +78 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/detr.md +206 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dia.md +163 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dialogpt.md +64 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/diffllama.md +66 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinat.md +96 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinov2.md +210 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinov2_with_registers.md +61 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinov3.md +181 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/distilbert.md +216 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dit.md +98 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/doge.md +104 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/donut.md +239 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dots1.md +41 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dpr.md +126 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dpt.md +103 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/efficientformer.md +110 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/efficientloftr.md +150 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/efficientnet.md +61 -0
- tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/electra.md +251 -0
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cohere2_vision.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2025-07-31 and added to Hugging Face Transformers on 2025-07-31.*
|
| 17 |
+
|
| 18 |
+
# Command A Vision
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
<img alt="Tensor parallelism" src="https://img.shields.io/badge/Tensor%20parallelism-06b6d4?style=flat&logoColor=white">
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
Command A Vision ([blog post](https://cohere.com/blog/command-a-vision)) is a state-of-the-art multimodal model designed to seamlessly integrate visual and textual information for a wide range of applications. By combining advanced computer vision techniques with natural language processing capabilities, Command A Vision enables users to analyze, understand, and generate insights from both visual and textual data.
|
| 30 |
+
|
| 31 |
+
The model excels at tasks including image captioning, visual question answering, document understanding, and chart understanding. This makes it a versatile tool for AI practitioners. Its ability to process complex visual and textual inputs makes it useful in settings where text-only representations are imprecise or unavailable, like real-world image understanding and graphics-heavy document processing.
|
| 32 |
+
|
| 33 |
+
Command A Vision is built upon a robust architecture that leverages the latest advancements in VLMs. It's highly performant and efficient, even when dealing with large-scale datasets. The model's flexibility makes it suitable for a wide range of use cases, from content moderation and image search to medical imaging analysis and robotics.
|
| 34 |
+
|
| 35 |
+
## Usage tips
|
| 36 |
+
|
| 37 |
+
The model and image processor can be loaded as follows:
|
| 38 |
+
|
| 39 |
+
<hfoptions id="usage">
|
| 40 |
+
<hfoption id="AutoModel">
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
import torch
|
| 44 |
+
|
| 45 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 46 |
+
|
| 47 |
+
model_id = "CohereLabs/command-a-vision-07-2025"
|
| 48 |
+
|
| 49 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 50 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 51 |
+
model_id, device_map="auto", torch_dtype=torch.float16
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Format message with the Command-A-Vision chat template
|
| 55 |
+
messages = [
|
| 56 |
+
{
|
| 57 |
+
"role": "user",
|
| 58 |
+
"content": [
|
| 59 |
+
{
|
| 60 |
+
"type": "image",
|
| 61 |
+
"url": "https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg",
|
| 62 |
+
},
|
| 63 |
+
{"type": "text", "text": "what is in this image?"},
|
| 64 |
+
],
|
| 65 |
+
},
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
inputs = processor.apply_chat_template(
|
| 69 |
+
messages,
|
| 70 |
+
padding=True,
|
| 71 |
+
add_generation_prompt=True,
|
| 72 |
+
tokenize=True,
|
| 73 |
+
return_dict=True,
|
| 74 |
+
return_tensors="pt",
|
| 75 |
+
).to(model.device)
|
| 76 |
+
|
| 77 |
+
gen_tokens = model.generate(
|
| 78 |
+
**inputs,
|
| 79 |
+
max_new_tokens=300,
|
| 80 |
+
do_sample=True,
|
| 81 |
+
temperature=0.3,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
print(
|
| 85 |
+
processor.tokenizer.decode(
|
| 86 |
+
gen_tokens[0][inputs.input_ids.shape[1] :], skip_special_tokens=True
|
| 87 |
+
)
|
| 88 |
+
)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
</hfoption>
|
| 92 |
+
<hfoption id="Pipeline">
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
from transformers import pipeline
|
| 96 |
+
|
| 97 |
+
pipe = pipeline(model="CohereLabs/command-a-vision-07-2025", task="image-text-to-text", device_map="auto")
|
| 98 |
+
|
| 99 |
+
messages = [
|
| 100 |
+
{
|
| 101 |
+
"role": "user",
|
| 102 |
+
"content": [
|
| 103 |
+
{
|
| 104 |
+
"type": "image",
|
| 105 |
+
"url": "https://media.istockphoto.com/id/458012057/photo/istanbul-turkey.jpg?s=612x612&w=0&k=20&c=qogAOVvkpfUyqLUMr_XJQyq-HkACXyYUSZbKhBlPrxo=",
|
| 106 |
+
},
|
| 107 |
+
{"type": "text", "text": "Where was this taken ?"},
|
| 108 |
+
],
|
| 109 |
+
},
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
outputs = pipe(text=messages, max_new_tokens=300, return_full_text=False)
|
| 113 |
+
|
| 114 |
+
print(outputs)
|
| 115 |
+
```
|
| 116 |
+
</hfoption>
|
| 117 |
+
</hfoptions>
|
| 118 |
+
|
| 119 |
+
## Cohere2VisionConfig
|
| 120 |
+
|
| 121 |
+
[[autodoc]] Cohere2VisionConfig
|
| 122 |
+
|
| 123 |
+
## Cohere2VisionForConditionalGeneration
|
| 124 |
+
|
| 125 |
+
[[autodoc]] Cohere2VisionForConditionalGeneration
|
| 126 |
+
- forward
|
| 127 |
+
|
| 128 |
+
## Cohere2VisionModel
|
| 129 |
+
|
| 130 |
+
[[autodoc]] Cohere2VisionModel
|
| 131 |
+
- forward
|
| 132 |
+
|
| 133 |
+
## Cohere2VisionImageProcessorFast
|
| 134 |
+
|
| 135 |
+
[[autodoc]] Cohere2VisionImageProcessorFast
|
| 136 |
+
- preprocess
|
| 137 |
+
|
| 138 |
+
## Cohere2VisionProcessor
|
| 139 |
+
|
| 140 |
+
[[autodoc]] Cohere2VisionProcessor
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/colpali.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 3 |
+
the License. You may obtain a copy of the License at
|
| 4 |
+
|
| 5 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 6 |
+
|
| 7 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 8 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 9 |
+
specific language governing permissions and limitations under the License.
|
| 10 |
+
|
| 11 |
+
⚠️ Note that this file is in Markdown but contains specific syntax for our doc-builder (similar to MDX) that may not be
|
| 12 |
+
rendered properly in your Markdown viewer.
|
| 13 |
+
-->
|
| 14 |
+
*This model was released on 2024-06-27 and added to Hugging Face Transformers on 2024-12-17.*
|
| 15 |
+
|
| 16 |
+
<div style="float: right;">
|
| 17 |
+
<div class="flex flex-wrap space-x-1">
|
| 18 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 19 |
+
</div>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
# ColPali
|
| 23 |
+
|
| 24 |
+
[ColPali](https://huggingface.co/papers/2407.01449) is a model designed to retrieve documents by analyzing their visual features. Unlike traditional systems that rely heavily on text extraction and OCR, ColPali treats each page as an image. It uses [Paligemma-3B](./paligemma) to capture not only text, but also the layout, tables, charts, and other visual elements to create detailed multi-vector embeddings that can be used for retrieval by computing pairwise late interaction similarity scores. This offers a more comprehensive understanding of documents and enables more efficient and accurate retrieval.
|
| 25 |
+
|
| 26 |
+
This model was contributed by [@tonywu71](https://huggingface.co/tonywu71) (ILLUIN Technology) and [@yonigozlan](https://huggingface.co/yonigozlan) (HuggingFace).
|
| 27 |
+
|
| 28 |
+
You can find all the original ColPali checkpoints under Vidore's [Hf-native ColVision Models](https://huggingface.co/collections/vidore/hf-native-colvision-models-6755d68fc60a8553acaa96f7) collection.
|
| 29 |
+
|
| 30 |
+
> [!TIP]
|
| 31 |
+
> Click on the ColPali models in the right sidebar for more examples of how to use ColPali for image retrieval.
|
| 32 |
+
|
| 33 |
+
<hfoptions id="usage">
|
| 34 |
+
<hfoption id="image retrieval">
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
import requests
|
| 38 |
+
import torch
|
| 39 |
+
from PIL import Image
|
| 40 |
+
|
| 41 |
+
from transformers import ColPaliForRetrieval, ColPaliProcessor
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Load the model and the processor
|
| 45 |
+
model_name = "vidore/colpali-v1.3-hf"
|
| 46 |
+
|
| 47 |
+
model = ColPaliForRetrieval.from_pretrained(
|
| 48 |
+
model_name,
|
| 49 |
+
torch_dtype=torch.bfloat16,
|
| 50 |
+
device_map="auto", # "cpu", "cuda", "xpu", or "mps" for Apple Silicon
|
| 51 |
+
)
|
| 52 |
+
processor = ColPaliProcessor.from_pretrained(model_name)
|
| 53 |
+
|
| 54 |
+
# The document page screenshots from your corpus
|
| 55 |
+
url1 = "https://upload.wikimedia.org/wikipedia/commons/8/89/US-original-Declaration-1776.jpg"
|
| 56 |
+
url2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Romeoandjuliet1597.jpg/500px-Romeoandjuliet1597.jpg"
|
| 57 |
+
|
| 58 |
+
images = [
|
| 59 |
+
Image.open(requests.get(url1, stream=True).raw),
|
| 60 |
+
Image.open(requests.get(url2, stream=True).raw),
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
# The queries you want to retrieve documents for
|
| 64 |
+
queries = [
|
| 65 |
+
"When was the United States Declaration of Independence proclaimed?",
|
| 66 |
+
"Who printed the edition of Romeo and Juliet?",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
# Process the inputs
|
| 70 |
+
inputs_images = processor(images=images).to(model.device)
|
| 71 |
+
inputs_text = processor(text=queries).to(model.device)
|
| 72 |
+
|
| 73 |
+
# Forward pass
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
image_embeddings = model(**inputs_images).embeddings
|
| 76 |
+
query_embeddings = model(**inputs_text).embeddings
|
| 77 |
+
|
| 78 |
+
# Score the queries against the images
|
| 79 |
+
scores = processor.score_retrieval(query_embeddings, image_embeddings)
|
| 80 |
+
|
| 81 |
+
print("Retrieval scores (query x image):")
|
| 82 |
+
print(scores)
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
If you have issue with loading the images with PIL, you can use the following code to create dummy images:
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
images = [
|
| 89 |
+
Image.new("RGB", (128, 128), color="white"),
|
| 90 |
+
Image.new("RGB", (64, 32), color="black"),
|
| 91 |
+
]
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
</hfoption>
|
| 95 |
+
</hfoptions>
|
| 96 |
+
|
| 97 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 98 |
+
|
| 99 |
+
The example below uses [bitsandbytes](../quantization/bitsandbytes) to quantize the weights to int4.
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
import requests
|
| 103 |
+
import torch
|
| 104 |
+
from PIL import Image
|
| 105 |
+
|
| 106 |
+
from transformers import BitsAndBytesConfig, ColPaliForRetrieval, ColPaliProcessor
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
model_name = "vidore/colpali-v1.3-hf"
|
| 110 |
+
|
| 111 |
+
# 4-bit quantization configuration
|
| 112 |
+
bnb_config = BitsAndBytesConfig(
|
| 113 |
+
load_in_4bit=True,
|
| 114 |
+
bnb_4bit_use_double_quant=True,
|
| 115 |
+
bnb_4bit_quant_type="nf4",
|
| 116 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
model = ColPaliForRetrieval.from_pretrained(
|
| 120 |
+
model_name,
|
| 121 |
+
quantization_config=bnb_config,
|
| 122 |
+
device_map="auto",
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
processor = ColPaliProcessor.from_pretrained(model_name)
|
| 126 |
+
|
| 127 |
+
url1 = "https://upload.wikimedia.org/wikipedia/commons/8/89/US-original-Declaration-1776.jpg"
|
| 128 |
+
url2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Romeoandjuliet1597.jpg/500px-Romeoandjuliet1597.jpg"
|
| 129 |
+
|
| 130 |
+
images = [
|
| 131 |
+
Image.open(requests.get(url1, stream=True).raw),
|
| 132 |
+
Image.open(requests.get(url2, stream=True).raw),
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
queries = [
|
| 136 |
+
"When was the United States Declaration of Independence proclaimed?",
|
| 137 |
+
"Who printed the edition of Romeo and Juliet?",
|
| 138 |
+
]
|
| 139 |
+
|
| 140 |
+
# Process the inputs
|
| 141 |
+
inputs_images = processor(images=images, return_tensors="pt").to(model.device)
|
| 142 |
+
inputs_text = processor(text=queries, return_tensors="pt").to(model.device)
|
| 143 |
+
|
| 144 |
+
# Forward pass
|
| 145 |
+
with torch.no_grad():
|
| 146 |
+
image_embeddings = model(**inputs_images).embeddings
|
| 147 |
+
query_embeddings = model(**inputs_text).embeddings
|
| 148 |
+
|
| 149 |
+
# Score the queries against the images
|
| 150 |
+
scores = processor.score_retrieval(query_embeddings, image_embeddings)
|
| 151 |
+
|
| 152 |
+
print("Retrieval scores (query x image):")
|
| 153 |
+
print(scores)
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
## Notes
|
| 157 |
+
|
| 158 |
+
- [`~ColPaliProcessor.score_retrieval`] returns a 2D tensor where the first dimension is the number of queries and the second dimension is the number of images. A higher score indicates more similarity between the query and image.
|
| 159 |
+
|
| 160 |
+
## ColPaliConfig
|
| 161 |
+
|
| 162 |
+
[[autodoc]] ColPaliConfig
|
| 163 |
+
|
| 164 |
+
## ColPaliProcessor
|
| 165 |
+
|
| 166 |
+
[[autodoc]] ColPaliProcessor
|
| 167 |
+
|
| 168 |
+
## ColPaliForRetrieval
|
| 169 |
+
|
| 170 |
+
[[autodoc]] ColPaliForRetrieval
|
| 171 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/colqwen2.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-06-27 and added to Hugging Face Transformers on 2025-06-02.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
# ColQwen2
|
| 25 |
+
|
| 26 |
+
[ColQwen2](https://huggingface.co/papers/2407.01449) is a variant of the [ColPali](./colpali) model designed to retrieve documents by analyzing their visual features. Unlike traditional systems that rely heavily on text extraction and OCR, ColQwen2 treats each page as an image. It uses the [Qwen2-VL](./qwen2_vl) backbone to capture not only text, but also the layout, tables, charts, and other visual elements to create detailed multi-vector embeddings that can be used for retrieval by computing pairwise late interaction similarity scores. This offers a more comprehensive understanding of documents and enables more efficient and accurate retrieval.
|
| 27 |
+
|
| 28 |
+
This model was contributed by [@tonywu71](https://huggingface.co/tonywu71) (ILLUIN Technology) and [@yonigozlan](https://huggingface.co/yonigozlan) (HuggingFace).
|
| 29 |
+
|
| 30 |
+
You can find all the original ColPali checkpoints under Vidore's [Hf-native ColVision Models](https://huggingface.co/collections/vidore/hf-native-colvision-models-6755d68fc60a8553acaa96f7) collection.
|
| 31 |
+
|
| 32 |
+
> [!TIP]
|
| 33 |
+
> Click on the ColQwen2 models in the right sidebar for more examples of how to use ColQwen2 for image retrieval.
|
| 34 |
+
|
| 35 |
+
<hfoptions id="usage">
|
| 36 |
+
<hfoption id="image retrieval">
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import requests
|
| 40 |
+
import torch
|
| 41 |
+
from PIL import Image
|
| 42 |
+
|
| 43 |
+
from transformers import ColQwen2ForRetrieval, ColQwen2Processor
|
| 44 |
+
from transformers.utils.import_utils import is_flash_attn_2_available
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Load the model and the processor
|
| 48 |
+
model_name = "vidore/colqwen2-v1.0-hf"
|
| 49 |
+
|
| 50 |
+
model = ColQwen2ForRetrieval.from_pretrained(
|
| 51 |
+
model_name,
|
| 52 |
+
torch_dtype=torch.bfloat16,
|
| 53 |
+
device_map="auto", # "cpu", "cuda", or "mps" for Apple Silicon
|
| 54 |
+
attn_implementation="flash_attention_2" if is_flash_attn_2_available() else "sdpa",
|
| 55 |
+
)
|
| 56 |
+
processor = ColQwen2Processor.from_pretrained(model_name)
|
| 57 |
+
|
| 58 |
+
# The document page screenshots from your corpus
|
| 59 |
+
url1 = "https://upload.wikimedia.org/wikipedia/commons/8/89/US-original-Declaration-1776.jpg"
|
| 60 |
+
url2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Romeoandjuliet1597.jpg/500px-Romeoandjuliet1597.jpg"
|
| 61 |
+
|
| 62 |
+
images = [
|
| 63 |
+
Image.open(requests.get(url1, stream=True).raw),
|
| 64 |
+
Image.open(requests.get(url2, stream=True).raw),
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
# The queries you want to retrieve documents for
|
| 68 |
+
queries = [
|
| 69 |
+
"When was the United States Declaration of Independence proclaimed?",
|
| 70 |
+
"Who printed the edition of Romeo and Juliet?",
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
# Process the inputs
|
| 74 |
+
inputs_images = processor(images=images).to(model.device)
|
| 75 |
+
inputs_text = processor(text=queries).to(model.device)
|
| 76 |
+
|
| 77 |
+
# Forward pass
|
| 78 |
+
with torch.no_grad():
|
| 79 |
+
image_embeddings = model(**inputs_images).embeddings
|
| 80 |
+
query_embeddings = model(**inputs_text).embeddings
|
| 81 |
+
|
| 82 |
+
# Score the queries against the images
|
| 83 |
+
scores = processor.score_retrieval(query_embeddings, image_embeddings)
|
| 84 |
+
|
| 85 |
+
print("Retrieval scores (query x image):")
|
| 86 |
+
print(scores)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
If you have issue with loading the images with PIL, you can use the following code to create dummy images:
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
images = [
|
| 93 |
+
Image.new("RGB", (128, 128), color="white"),
|
| 94 |
+
Image.new("RGB", (64, 32), color="black"),
|
| 95 |
+
]
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
</hfoption>
|
| 99 |
+
</hfoptions>
|
| 100 |
+
|
| 101 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 102 |
+
|
| 103 |
+
The example below uses [bitsandbytes](../quantization/bitsandbytes) to quantize the weights to int4.
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
import requests
|
| 107 |
+
import torch
|
| 108 |
+
from PIL import Image
|
| 109 |
+
|
| 110 |
+
from transformers import BitsAndBytesConfig, ColQwen2ForRetrieval, ColQwen2Processor
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
model_name = "vidore/colqwen2-v1.0-hf"
|
| 114 |
+
|
| 115 |
+
# 4-bit quantization configuration
|
| 116 |
+
bnb_config = BitsAndBytesConfig(
|
| 117 |
+
load_in_4bit=True,
|
| 118 |
+
bnb_4bit_use_double_quant=True,
|
| 119 |
+
bnb_4bit_quant_type="nf4",
|
| 120 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
model = ColQwen2ForRetrieval.from_pretrained(
|
| 124 |
+
model_name,
|
| 125 |
+
quantization_config=bnb_config,
|
| 126 |
+
device_map="cuda",
|
| 127 |
+
).eval()
|
| 128 |
+
|
| 129 |
+
processor = ColQwen2Processor.from_pretrained(model_name)
|
| 130 |
+
|
| 131 |
+
url1 = "https://upload.wikimedia.org/wikipedia/commons/8/89/US-original-Declaration-1776.jpg"
|
| 132 |
+
url2 = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Romeoandjuliet1597.jpg/500px-Romeoandjuliet1597.jpg"
|
| 133 |
+
|
| 134 |
+
images = [
|
| 135 |
+
Image.open(requests.get(url1, stream=True).raw),
|
| 136 |
+
Image.open(requests.get(url2, stream=True).raw),
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
queries = [
|
| 140 |
+
"When was the United States Declaration of Independence proclaimed?",
|
| 141 |
+
"Who printed the edition of Romeo and Juliet?",
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
# Process the inputs
|
| 145 |
+
inputs_images = processor(images=images, return_tensors="pt").to(model.device)
|
| 146 |
+
inputs_text = processor(text=queries, return_tensors="pt").to(model.device)
|
| 147 |
+
|
| 148 |
+
# Forward pass
|
| 149 |
+
with torch.no_grad():
|
| 150 |
+
image_embeddings = model(**inputs_images).embeddings
|
| 151 |
+
query_embeddings = model(**inputs_text).embeddings
|
| 152 |
+
|
| 153 |
+
# Score the queries against the images
|
| 154 |
+
scores = processor.score_retrieval(query_embeddings, image_embeddings)
|
| 155 |
+
|
| 156 |
+
print("Retrieval scores (query x image):")
|
| 157 |
+
print(scores)
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## Notes
|
| 161 |
+
|
| 162 |
+
- [`~ColQwen2Processor.score_retrieval`] returns a 2D tensor where the first dimension is the number of queries and the second dimension is the number of images. A higher score indicates more similarity between the query and image.
|
| 163 |
+
- Unlike ColPali, ColQwen2 supports arbitrary image resolutions and aspect ratios, which means images are not resized into fixed-size squares. This preserves more of the original input signal.
|
| 164 |
+
- Larger input images generate longer multi-vector embeddings, allowing users to adjust image resolution to balance performance and memory usage.
|
| 165 |
+
|
| 166 |
+
## ColQwen2Config
|
| 167 |
+
|
| 168 |
+
[[autodoc]] ColQwen2Config
|
| 169 |
+
|
| 170 |
+
## ColQwen2Processor
|
| 171 |
+
|
| 172 |
+
[[autodoc]] ColQwen2Processor
|
| 173 |
+
|
| 174 |
+
## ColQwen2ForRetrieval
|
| 175 |
+
|
| 176 |
+
[[autodoc]] ColQwen2ForRetrieval
|
| 177 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/conditional_detr.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2021-08-13 and added to Hugging Face Transformers on 2022-09-22.*
|
| 17 |
+
|
| 18 |
+
# Conditional DETR
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
The Conditional DETR model was proposed in [Conditional DETR for Fast Training Convergence](https://huggingface.co/papers/2108.06152) by Depu Meng, Xiaokang Chen, Zejia Fan, Gang Zeng, Houqiang Li, Yuhui Yuan, Lei Sun, Jingdong Wang. Conditional DETR presents a conditional cross-attention mechanism for fast DETR training. Conditional DETR converges 6.7× to 10× faster than DETR.
|
| 27 |
+
|
| 28 |
+
The abstract from the paper is the following:
|
| 29 |
+
|
| 30 |
+
*The recently-developed DETR approach applies the transformer encoder and decoder architecture to object detection and achieves promising performance. In this paper, we handle the critical issue, slow training convergence, and present a conditional cross-attention mechanism for fast DETR training. Our approach is motivated by that the cross-attention in DETR relies highly on the content embeddings for localizing the four extremities and predicting the box, which increases the need for high-quality content embeddings and thus the training difficulty. Our approach, named conditional DETR, learns a conditional spatial query from the decoder embedding for decoder multi-head cross-attention. The benefit is that through the conditional spatial query, each cross-attention head is able to attend to a band containing a distinct region, e.g., one object extremity or a region inside the object box. This narrows down the spatial range for localizing the distinct regions for object classification and box regression, thus relaxing the dependence on the content embeddings and easing the training. Empirical results show that conditional DETR converges 6.7× faster for the backbones R50 and R101 and 10× faster for stronger backbones DC5-R50 and DC5-R101. Code is available at https://github.com/Atten4Vis/ConditionalDETR.*
|
| 31 |
+
|
| 32 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/conditional_detr_curve.jpg"
|
| 33 |
+
alt="drawing" width="600"/>
|
| 34 |
+
|
| 35 |
+
<small> Conditional DETR shows much faster convergence compared to the original DETR. Taken from the <a href="https://huggingface.co/papers/2108.06152">original paper</a>.</small>
|
| 36 |
+
|
| 37 |
+
This model was contributed by [DepuMeng](https://huggingface.co/DepuMeng). The original code can be found [here](https://github.com/Atten4Vis/ConditionalDETR).
|
| 38 |
+
|
| 39 |
+
## Resources
|
| 40 |
+
|
| 41 |
+
- Scripts for finetuning [`ConditionalDetrForObjectDetection`] with [`Trainer`] or [Accelerate](https://huggingface.co/docs/accelerate/index) can be found [here](https://github.com/huggingface/transformers/tree/main/examples/pytorch/object-detection).
|
| 42 |
+
- See also: [Object detection task guide](../tasks/object_detection).
|
| 43 |
+
|
| 44 |
+
## ConditionalDetrConfig
|
| 45 |
+
|
| 46 |
+
[[autodoc]] ConditionalDetrConfig
|
| 47 |
+
|
| 48 |
+
## ConditionalDetrImageProcessor
|
| 49 |
+
|
| 50 |
+
[[autodoc]] ConditionalDetrImageProcessor
|
| 51 |
+
- preprocess
|
| 52 |
+
|
| 53 |
+
## ConditionalDetrImageProcessorFast
|
| 54 |
+
|
| 55 |
+
[[autodoc]] ConditionalDetrImageProcessorFast
|
| 56 |
+
- preprocess
|
| 57 |
+
- post_process_object_detection
|
| 58 |
+
- post_process_instance_segmentation
|
| 59 |
+
- post_process_semantic_segmentation
|
| 60 |
+
- post_process_panoptic_segmentation
|
| 61 |
+
|
| 62 |
+
## ConditionalDetrFeatureExtractor
|
| 63 |
+
|
| 64 |
+
[[autodoc]] ConditionalDetrFeatureExtractor
|
| 65 |
+
- __call__
|
| 66 |
+
- post_process_object_detection
|
| 67 |
+
- post_process_instance_segmentation
|
| 68 |
+
- post_process_semantic_segmentation
|
| 69 |
+
- post_process_panoptic_segmentation
|
| 70 |
+
|
| 71 |
+
## ConditionalDetrModel
|
| 72 |
+
|
| 73 |
+
[[autodoc]] ConditionalDetrModel
|
| 74 |
+
- forward
|
| 75 |
+
|
| 76 |
+
## ConditionalDetrForObjectDetection
|
| 77 |
+
|
| 78 |
+
[[autodoc]] ConditionalDetrForObjectDetection
|
| 79 |
+
- forward
|
| 80 |
+
|
| 81 |
+
## ConditionalDetrForSegmentation
|
| 82 |
+
|
| 83 |
+
[[autodoc]] ConditionalDetrForSegmentation
|
| 84 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convbert.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-08-06 and added to Hugging Face Transformers on 2021-01-27.*
|
| 17 |
+
|
| 18 |
+
# ConvBERT
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
## Overview
|
| 26 |
+
|
| 27 |
+
The ConvBERT model was proposed in [ConvBERT: Improving BERT with Span-based Dynamic Convolution](https://huggingface.co/papers/2008.02496) by Zihang Jiang, Weihao Yu, Daquan Zhou, Yunpeng Chen, Jiashi Feng, Shuicheng
|
| 28 |
+
Yan.
|
| 29 |
+
|
| 30 |
+
The abstract from the paper is the following:
|
| 31 |
+
|
| 32 |
+
*Pre-trained language models like BERT and its variants have recently achieved impressive performance in various
|
| 33 |
+
natural language understanding tasks. However, BERT heavily relies on the global self-attention block and thus suffers
|
| 34 |
+
large memory footprint and computation cost. Although all its attention heads query on the whole input sequence for
|
| 35 |
+
generating the attention map from a global perspective, we observe some heads only need to learn local dependencies,
|
| 36 |
+
which means the existence of computation redundancy. We therefore propose a novel span-based dynamic convolution to
|
| 37 |
+
replace these self-attention heads to directly model local dependencies. The novel convolution heads, together with the
|
| 38 |
+
rest self-attention heads, form a new mixed attention block that is more efficient at both global and local context
|
| 39 |
+
learning. We equip BERT with this mixed attention design and build a ConvBERT model. Experiments have shown that
|
| 40 |
+
ConvBERT significantly outperforms BERT and its variants in various downstream tasks, with lower training cost and
|
| 41 |
+
fewer model parameters. Remarkably, ConvBERTbase model achieves 86.4 GLUE score, 0.7 higher than ELECTRAbase, while
|
| 42 |
+
using less than 1/4 training cost. Code and pre-trained models will be released.*
|
| 43 |
+
|
| 44 |
+
This model was contributed by [abhishek](https://huggingface.co/abhishek). The original implementation can be found
|
| 45 |
+
here: https://github.com/yitu-opensource/ConvBert
|
| 46 |
+
|
| 47 |
+
## Usage tips
|
| 48 |
+
|
| 49 |
+
ConvBERT training tips are similar to those of BERT. For usage tips refer to [BERT documentation](bert).
|
| 50 |
+
|
| 51 |
+
## Resources
|
| 52 |
+
|
| 53 |
+
- [Text classification task guide](../tasks/sequence_classification)
|
| 54 |
+
- [Token classification task guide](../tasks/token_classification)
|
| 55 |
+
- [Question answering task guide](../tasks/question_answering)
|
| 56 |
+
- [Masked language modeling task guide](../tasks/masked_language_modeling)
|
| 57 |
+
- [Multiple choice task guide](../tasks/multiple_choice)
|
| 58 |
+
|
| 59 |
+
## ConvBertConfig
|
| 60 |
+
|
| 61 |
+
[[autodoc]] ConvBertConfig
|
| 62 |
+
|
| 63 |
+
## ConvBertTokenizer
|
| 64 |
+
|
| 65 |
+
[[autodoc]] ConvBertTokenizer
|
| 66 |
+
- build_inputs_with_special_tokens
|
| 67 |
+
- get_special_tokens_mask
|
| 68 |
+
- create_token_type_ids_from_sequences
|
| 69 |
+
- save_vocabulary
|
| 70 |
+
|
| 71 |
+
## ConvBertTokenizerFast
|
| 72 |
+
|
| 73 |
+
[[autodoc]] ConvBertTokenizerFast
|
| 74 |
+
|
| 75 |
+
<frameworkcontent>
|
| 76 |
+
<pt>
|
| 77 |
+
|
| 78 |
+
## ConvBertModel
|
| 79 |
+
|
| 80 |
+
[[autodoc]] ConvBertModel
|
| 81 |
+
- forward
|
| 82 |
+
|
| 83 |
+
## ConvBertForMaskedLM
|
| 84 |
+
|
| 85 |
+
[[autodoc]] ConvBertForMaskedLM
|
| 86 |
+
- forward
|
| 87 |
+
|
| 88 |
+
## ConvBertForSequenceClassification
|
| 89 |
+
|
| 90 |
+
[[autodoc]] ConvBertForSequenceClassification
|
| 91 |
+
- forward
|
| 92 |
+
|
| 93 |
+
## ConvBertForMultipleChoice
|
| 94 |
+
|
| 95 |
+
[[autodoc]] ConvBertForMultipleChoice
|
| 96 |
+
- forward
|
| 97 |
+
|
| 98 |
+
## ConvBertForTokenClassification
|
| 99 |
+
|
| 100 |
+
[[autodoc]] ConvBertForTokenClassification
|
| 101 |
+
- forward
|
| 102 |
+
|
| 103 |
+
## ConvBertForQuestionAnswering
|
| 104 |
+
|
| 105 |
+
[[autodoc]] ConvBertForQuestionAnswering
|
| 106 |
+
- forward
|
| 107 |
+
|
| 108 |
+
</pt>
|
| 109 |
+
<tf>
|
| 110 |
+
|
| 111 |
+
## TFConvBertModel
|
| 112 |
+
|
| 113 |
+
[[autodoc]] TFConvBertModel
|
| 114 |
+
- call
|
| 115 |
+
|
| 116 |
+
## TFConvBertForMaskedLM
|
| 117 |
+
|
| 118 |
+
[[autodoc]] TFConvBertForMaskedLM
|
| 119 |
+
- call
|
| 120 |
+
|
| 121 |
+
## TFConvBertForSequenceClassification
|
| 122 |
+
|
| 123 |
+
[[autodoc]] TFConvBertForSequenceClassification
|
| 124 |
+
- call
|
| 125 |
+
|
| 126 |
+
## TFConvBertForMultipleChoice
|
| 127 |
+
|
| 128 |
+
[[autodoc]] TFConvBertForMultipleChoice
|
| 129 |
+
- call
|
| 130 |
+
|
| 131 |
+
## TFConvBertForTokenClassification
|
| 132 |
+
|
| 133 |
+
[[autodoc]] TFConvBertForTokenClassification
|
| 134 |
+
- call
|
| 135 |
+
|
| 136 |
+
## TFConvBertForQuestionAnswering
|
| 137 |
+
|
| 138 |
+
[[autodoc]] TFConvBertForQuestionAnswering
|
| 139 |
+
- call
|
| 140 |
+
|
| 141 |
+
</tf>
|
| 142 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convnext.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-01-10 and added to Hugging Face Transformers on 2022-02-07.*
|
| 17 |
+
|
| 18 |
+
# ConvNeXT
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
## Overview
|
| 26 |
+
|
| 27 |
+
The ConvNeXT model was proposed in [A ConvNet for the 2020s](https://huggingface.co/papers/2201.03545) by Zhuang Liu, Hanzi Mao, Chao-Yuan Wu, Christoph Feichtenhofer, Trevor Darrell, Saining Xie.
|
| 28 |
+
ConvNeXT is a pure convolutional model (ConvNet), inspired by the design of Vision Transformers, that claims to outperform them.
|
| 29 |
+
|
| 30 |
+
The abstract from the paper is the following:
|
| 31 |
+
|
| 32 |
+
*The "Roaring 20s" of visual recognition began with the introduction of Vision Transformers (ViTs), which quickly superseded ConvNets as the state-of-the-art image classification model.
|
| 33 |
+
A vanilla ViT, on the other hand, faces difficulties when applied to general computer vision tasks such as object detection and semantic segmentation. It is the hierarchical Transformers
|
| 34 |
+
(e.g., Swin Transformers) that reintroduced several ConvNet priors, making Transformers practically viable as a generic vision backbone and demonstrating remarkable performance on a wide
|
| 35 |
+
variety of vision tasks. However, the effectiveness of such hybrid approaches is still largely credited to the intrinsic superiority of Transformers, rather than the inherent inductive
|
| 36 |
+
biases of convolutions. In this work, we reexamine the design spaces and test the limits of what a pure ConvNet can achieve. We gradually "modernize" a standard ResNet toward the design
|
| 37 |
+
of a vision Transformer, and discover several key components that contribute to the performance difference along the way. The outcome of this exploration is a family of pure ConvNet models
|
| 38 |
+
dubbed ConvNeXt. Constructed entirely from standard ConvNet modules, ConvNeXts compete favorably with Transformers in terms of accuracy and scalability, achieving 87.8% ImageNet top-1 accuracy
|
| 39 |
+
and outperforming Swin Transformers on COCO detection and ADE20K segmentation, while maintaining the simplicity and efficiency of standard ConvNets.*
|
| 40 |
+
|
| 41 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/convnext_architecture.jpg"
|
| 42 |
+
alt="drawing" width="600"/>
|
| 43 |
+
|
| 44 |
+
<small> ConvNeXT architecture. Taken from the <a href="https://huggingface.co/papers/2201.03545">original paper</a>.</small>
|
| 45 |
+
|
| 46 |
+
This model was contributed by [nielsr](https://huggingface.co/nielsr). TensorFlow version of the model was contributed by [ariG23498](https://github.com/ariG23498),
|
| 47 |
+
[gante](https://github.com/gante), and [sayakpaul](https://github.com/sayakpaul) (equal contribution). The original code can be found [here](https://github.com/facebookresearch/ConvNeXt).
|
| 48 |
+
|
| 49 |
+
## Resources
|
| 50 |
+
|
| 51 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with ConvNeXT.
|
| 52 |
+
|
| 53 |
+
<PipelineTag pipeline="image-classification"/>
|
| 54 |
+
|
| 55 |
+
- [`ConvNextForImageClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb).
|
| 56 |
+
- See also: [Image classification task guide](../tasks/image_classification)
|
| 57 |
+
|
| 58 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 59 |
+
|
| 60 |
+
## ConvNextConfig
|
| 61 |
+
|
| 62 |
+
[[autodoc]] ConvNextConfig
|
| 63 |
+
|
| 64 |
+
## ConvNextFeatureExtractor
|
| 65 |
+
|
| 66 |
+
[[autodoc]] ConvNextFeatureExtractor
|
| 67 |
+
|
| 68 |
+
## ConvNextImageProcessor
|
| 69 |
+
|
| 70 |
+
[[autodoc]] ConvNextImageProcessor
|
| 71 |
+
- preprocess
|
| 72 |
+
|
| 73 |
+
## ConvNextImageProcessorFast
|
| 74 |
+
|
| 75 |
+
[[autodoc]] ConvNextImageProcessorFast
|
| 76 |
+
- preprocess
|
| 77 |
+
|
| 78 |
+
<frameworkcontent>
|
| 79 |
+
<pt>
|
| 80 |
+
|
| 81 |
+
## ConvNextModel
|
| 82 |
+
|
| 83 |
+
[[autodoc]] ConvNextModel
|
| 84 |
+
- forward
|
| 85 |
+
|
| 86 |
+
## ConvNextForImageClassification
|
| 87 |
+
|
| 88 |
+
[[autodoc]] ConvNextForImageClassification
|
| 89 |
+
- forward
|
| 90 |
+
|
| 91 |
+
</pt>
|
| 92 |
+
<tf>
|
| 93 |
+
|
| 94 |
+
## TFConvNextModel
|
| 95 |
+
|
| 96 |
+
[[autodoc]] TFConvNextModel
|
| 97 |
+
- call
|
| 98 |
+
|
| 99 |
+
## TFConvNextForImageClassification
|
| 100 |
+
|
| 101 |
+
[[autodoc]] TFConvNextForImageClassification
|
| 102 |
+
- call
|
| 103 |
+
|
| 104 |
+
</tf>
|
| 105 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/convnextv2.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2023-01-02 and added to Hugging Face Transformers on 2023-03-14.*
|
| 17 |
+
|
| 18 |
+
# ConvNeXt V2
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
## Overview
|
| 26 |
+
|
| 27 |
+
The ConvNeXt V2 model was proposed in [ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders](https://huggingface.co/papers/2301.00808) by Sanghyun Woo, Shoubhik Debnath, Ronghang Hu, Xinlei Chen, Zhuang Liu, In So Kweon, Saining Xie.
|
| 28 |
+
ConvNeXt V2 is a pure convolutional model (ConvNet), inspired by the design of Vision Transformers, and a successor of [ConvNeXT](convnext).
|
| 29 |
+
|
| 30 |
+
The abstract from the paper is the following:
|
| 31 |
+
|
| 32 |
+
*Driven by improved architectures and better representation learning frameworks, the field of visual recognition has enjoyed rapid modernization and performance boost in the early 2020s. For example, modern ConvNets, represented by ConvNeXt, have demonstrated strong performance in various scenarios. While these models were originally designed for supervised learning with ImageNet labels, they can also potentially benefit from self-supervised learning techniques such as masked autoencoders (MAE). However, we found that simply combining these two approaches leads to subpar performance. In this paper, we propose a fully convolutional masked autoencoder framework and a new Global Response Normalization (GRN) layer that can be added to the ConvNeXt architecture to enhance inter-channel feature competition. This co-design of self-supervised learning techniques and architectural improvement results in a new model family called ConvNeXt V2, which significantly improves the performance of pure ConvNets on various recognition benchmarks, including ImageNet classification, COCO detection, and ADE20K segmentation. We also provide pre-trained ConvNeXt V2 models of various sizes, ranging from an efficient 3.7M-parameter Atto model with 76.7% top-1 accuracy on ImageNet, to a 650M Huge model that achieves a state-of-the-art 88.9% accuracy using only public training data.*
|
| 33 |
+
|
| 34 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/convnextv2_architecture.png"
|
| 35 |
+
alt="drawing" width="600"/>
|
| 36 |
+
|
| 37 |
+
<small> ConvNeXt V2 architecture. Taken from the <a href="https://huggingface.co/papers/2301.00808">original paper</a>.</small>
|
| 38 |
+
|
| 39 |
+
This model was contributed by [adirik](https://huggingface.co/adirik). The original code can be found [here](https://github.com/facebookresearch/ConvNeXt-V2).
|
| 40 |
+
|
| 41 |
+
## Resources
|
| 42 |
+
|
| 43 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with ConvNeXt V2.
|
| 44 |
+
|
| 45 |
+
<PipelineTag pipeline="image-classification"/>
|
| 46 |
+
|
| 47 |
+
- [`ConvNextV2ForImageClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb).
|
| 48 |
+
|
| 49 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 50 |
+
|
| 51 |
+
## ConvNextV2Config
|
| 52 |
+
|
| 53 |
+
[[autodoc]] ConvNextV2Config
|
| 54 |
+
|
| 55 |
+
## ConvNextV2Model
|
| 56 |
+
|
| 57 |
+
[[autodoc]] ConvNextV2Model
|
| 58 |
+
- forward
|
| 59 |
+
|
| 60 |
+
## ConvNextV2ForImageClassification
|
| 61 |
+
|
| 62 |
+
[[autodoc]] ConvNextV2ForImageClassification
|
| 63 |
+
- forward
|
| 64 |
+
|
| 65 |
+
## TFConvNextV2Model
|
| 66 |
+
|
| 67 |
+
[[autodoc]] TFConvNextV2Model
|
| 68 |
+
- call
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
## TFConvNextV2ForImageClassification
|
| 72 |
+
|
| 73 |
+
[[autodoc]] TFConvNextV2ForImageClassification
|
| 74 |
+
- call
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cpm.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-12-01 and added to Hugging Face Transformers on 2021-04-10.*
|
| 17 |
+
|
| 18 |
+
# CPM
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ2QxLyKmsm3kL2xoMOehrRNb7RIbbOZgrGre68AUqwAqZqNN5aKJ5N/lMq+qsd8kMa4pcWzh7muhLMEV69juq2kbKqgUaOTR5uMMZWLLZSGAI5VAIdEAH+ovNDHuNCnxcy3qcaYx8K8msGplrx+wLahjbYdXrV6vbMvYK9DrZ8QrZ8tqJuFms+Sos6sw8ecy8RffsNVeMCvmb43aLltv7Q4Y7EZWK4QWa1gt6meZKUdr6GOAZVeA4xPAISyveLUwtivxtKTpNJ2jcqfvcltiMiwwcfAoMVxhL+Kx7xjdrqTe60tsaNQs6KaRKACrJ6UTZwkqpqTL5pkHY4AloSgsd2ptNXPvNOO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 |
+
">
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
The CPM model was proposed in [CPM: A Large-scale Generative Chinese Pre-trained Language Model](https://huggingface.co/papers/2012.00413) by Zhengyan Zhang, Xu Han, Hao Zhou, Pei Ke, Yuxian Gu, Deming Ye, Yujia Qin,
|
| 30 |
+
Yusheng Su, Haozhe Ji, Jian Guan, Fanchao Qi, Xiaozhi Wang, Yanan Zheng, Guoyang Zeng, Huanqi Cao, Shengqi Chen,
|
| 31 |
+
Daixuan Li, Zhenbo Sun, Zhiyuan Liu, Minlie Huang, Wentao Han, Jie Tang, Juanzi Li, Xiaoyan Zhu, Maosong Sun.
|
| 32 |
+
|
| 33 |
+
The abstract from the paper is the following:
|
| 34 |
+
|
| 35 |
+
*Pre-trained Language Models (PLMs) have proven to be beneficial for various downstream NLP tasks. Recently, GPT-3,
|
| 36 |
+
with 175 billion parameters and 570GB training data, drew a lot of attention due to the capacity of few-shot (even
|
| 37 |
+
zero-shot) learning. However, applying GPT-3 to address Chinese NLP tasks is still challenging, as the training corpus
|
| 38 |
+
of GPT-3 is primarily English, and the parameters are not publicly available. In this technical report, we release the
|
| 39 |
+
Chinese Pre-trained Language Model (CPM) with generative pre-training on large-scale Chinese training data. To the best
|
| 40 |
+
of our knowledge, CPM, with 2.6 billion parameters and 100GB Chinese training data, is the largest Chinese pre-trained
|
| 41 |
+
language model, which could facilitate several downstream Chinese NLP tasks, such as conversation, essay generation,
|
| 42 |
+
cloze test, and language understanding. Extensive experiments demonstrate that CPM achieves strong performance on many
|
| 43 |
+
NLP tasks in the settings of few-shot (even zero-shot) learning.*
|
| 44 |
+
|
| 45 |
+
This model was contributed by [canwenxu](https://huggingface.co/canwenxu). The original implementation can be found
|
| 46 |
+
here: https://github.com/TsinghuaAI/CPM-Generate
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
<Tip>
|
| 50 |
+
|
| 51 |
+
CPM's architecture is the same as GPT-2, except for tokenization method. Refer to [GPT-2 documentation](gpt2) for
|
| 52 |
+
API reference information.
|
| 53 |
+
|
| 54 |
+
</Tip>
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
## CpmTokenizer
|
| 58 |
+
|
| 59 |
+
[[autodoc]] CpmTokenizer
|
| 60 |
+
|
| 61 |
+
## CpmTokenizerFast
|
| 62 |
+
|
| 63 |
+
[[autodoc]] CpmTokenizerFast
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cpmant.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team and The OpenBMB Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-09-16 and added to Hugging Face Transformers on 2023-04-12.*
|
| 17 |
+
|
| 18 |
+
# CPMAnt
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
CPM-Ant is an open-source Chinese pre-trained language model (PLM) with 10B parameters. It is also the first milestone of the live training process of CPM-Live. The training process is cost-effective and environment-friendly. CPM-Ant also achieves promising results with delta tuning on the CUGE benchmark. Besides the full model, we also provide various compressed versions to meet the requirements of different hardware configurations. [See more](https://github.com/OpenBMB/CPM-Live/tree/cpm-ant/cpm-live)
|
| 27 |
+
|
| 28 |
+
This model was contributed by [OpenBMB](https://huggingface.co/openbmb). The original code can be found [here](https://github.com/OpenBMB/CPM-Live/tree/cpm-ant/cpm-live).
|
| 29 |
+
|
| 30 |
+
## Resources
|
| 31 |
+
|
| 32 |
+
- A tutorial on [CPM-Live](https://github.com/OpenBMB/CPM-Live/tree/cpm-ant/cpm-live).
|
| 33 |
+
|
| 34 |
+
## CpmAntConfig
|
| 35 |
+
|
| 36 |
+
[[autodoc]] CpmAntConfig
|
| 37 |
+
- all
|
| 38 |
+
|
| 39 |
+
## CpmAntTokenizer
|
| 40 |
+
|
| 41 |
+
[[autodoc]] CpmAntTokenizer
|
| 42 |
+
- all
|
| 43 |
+
|
| 44 |
+
## CpmAntModel
|
| 45 |
+
|
| 46 |
+
[[autodoc]] CpmAntModel
|
| 47 |
+
- all
|
| 48 |
+
|
| 49 |
+
## CpmAntForCausalLM
|
| 50 |
+
|
| 51 |
+
[[autodoc]] CpmAntForCausalLM
|
| 52 |
+
- all
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/csm.md
ADDED
|
@@ -0,0 +1,383 @@
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2025-02-27 and added to Hugging Face Transformers on 2025-05-07.*
|
| 17 |
+
|
| 18 |
+
# Csm
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
The Conversational Speech Model (CSM) is the first open-source contextual text-to-speech model [released by Sesame](https://www.sesame.com/research/crossing_the_uncanny_valley_of_voice). It is designed to generate natural-sounding speech with or without conversational context. This context typically consists of multi-turn dialogue between speakers, represented as sequences of text and corresponding spoken audio.
|
| 23 |
+
|
| 24 |
+
**Model Architecture:**
|
| 25 |
+
CSM is composed of two LLaMA-style auto-regressive transformer decoders: a backbone decoder that predicts the first codebook token and a depth decoder that generates the remaining tokens. It uses the pretrained codec model [Mimi](./mimi), introduced by Kyutai, to encode speech into discrete codebook tokens and decode them back into audio.
|
| 26 |
+
|
| 27 |
+
The original csm-1b checkpoint is available under the [Sesame](https://huggingface.co/sesame/csm-1b) organization on Hugging Face.
|
| 28 |
+
|
| 29 |
+
<div class="flex justify-center">
|
| 30 |
+
<img src="https://huggingface.co/datasets/eustlb/documentation-images/resolve/main/csm_architecture.png"/>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
## Usage Tips
|
| 34 |
+
|
| 35 |
+
### Without Conversational Context
|
| 36 |
+
|
| 37 |
+
CSM can be used to simply generate speech from a text prompt:
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import torch
|
| 41 |
+
from transformers import CsmForConditionalGeneration, AutoProcessor, infer_device
|
| 42 |
+
|
| 43 |
+
model_id = "sesame/csm-1b"
|
| 44 |
+
device = infer_device()
|
| 45 |
+
|
| 46 |
+
# load the model and the processor
|
| 47 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 48 |
+
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
|
| 49 |
+
|
| 50 |
+
# prepare the inputs
|
| 51 |
+
text = "[0]The past is just a story we tell ourselves." # `[0]` for speaker id 0
|
| 52 |
+
inputs = processor(text, add_special_tokens=True).to(device)
|
| 53 |
+
|
| 54 |
+
# another equivalent way to prepare the inputs
|
| 55 |
+
conversation = [
|
| 56 |
+
{"role": "0", "content": [{"type": "text", "text": "The past is just a story we tell ourselves."}]},
|
| 57 |
+
]
|
| 58 |
+
inputs = processor.apply_chat_template(
|
| 59 |
+
conversation,
|
| 60 |
+
tokenize=True,
|
| 61 |
+
return_dict=True,
|
| 62 |
+
).to(device)
|
| 63 |
+
|
| 64 |
+
# infer the model
|
| 65 |
+
audio = model.generate(**inputs, output_audio=True)
|
| 66 |
+
processor.save_audio(audio, "example_without_context.wav")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### With Conversational Context
|
| 70 |
+
|
| 71 |
+
CSM can be used to generate speech given a conversation, allowing consistency in the voices and content-aware generation:
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import torch
|
| 75 |
+
from transformers import CsmForConditionalGeneration, AutoProcessor, infer_device
|
| 76 |
+
from datasets import load_dataset, Audio
|
| 77 |
+
|
| 78 |
+
model_id = "sesame/csm-1b"
|
| 79 |
+
device = infer_device()
|
| 80 |
+
|
| 81 |
+
# load the model and the processor
|
| 82 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 83 |
+
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
|
| 84 |
+
|
| 85 |
+
# prepare the inputs
|
| 86 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 87 |
+
# ensure the audio is 24kHz
|
| 88 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=24000))
|
| 89 |
+
conversation = []
|
| 90 |
+
|
| 91 |
+
# 1. context
|
| 92 |
+
for text, audio, speaker_id in zip(ds[:4]["text"], ds[:4]["audio"], ds[:4]["speaker_id"]):
|
| 93 |
+
conversation.append(
|
| 94 |
+
{
|
| 95 |
+
"role": f"{speaker_id}",
|
| 96 |
+
"content": [{"type": "text", "text": text}, {"type": "audio", "path": audio["array"]}],
|
| 97 |
+
}
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# 2. text prompt
|
| 101 |
+
conversation.append({"role": f"{ds[4]['speaker_id']}", "content": [{"type": "text", "text": ds[4]["text"]}]})
|
| 102 |
+
|
| 103 |
+
inputs = processor.apply_chat_template(
|
| 104 |
+
conversation,
|
| 105 |
+
tokenize=True,
|
| 106 |
+
return_dict=True,
|
| 107 |
+
).to(device)
|
| 108 |
+
|
| 109 |
+
# infer the model
|
| 110 |
+
audio = model.generate(**inputs, output_audio=True)
|
| 111 |
+
processor.save_audio(audio, "example_with_context.wav")
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
### Batched Inference
|
| 115 |
+
|
| 116 |
+
CSM supports batched inference!
|
| 117 |
+
|
| 118 |
+
```python
|
| 119 |
+
import torch
|
| 120 |
+
from transformers import CsmForConditionalGeneration, AutoProcessor, infer_device
|
| 121 |
+
from datasets import load_dataset, Audio
|
| 122 |
+
|
| 123 |
+
model_id = "sesame/csm-1b"
|
| 124 |
+
device = infer_device()
|
| 125 |
+
|
| 126 |
+
# load the model and the processor
|
| 127 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 128 |
+
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
|
| 129 |
+
|
| 130 |
+
# prepare the inputs
|
| 131 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 132 |
+
# ensure the audio is 24kHz
|
| 133 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=24000))
|
| 134 |
+
# here a batch with two prompts
|
| 135 |
+
conversation = [
|
| 136 |
+
[
|
| 137 |
+
{
|
| 138 |
+
"role": f"{ds[0]['speaker_id']}",
|
| 139 |
+
"content": [
|
| 140 |
+
{"type": "text", "text": ds[0]["text"]},
|
| 141 |
+
{"type": "audio", "path": ds[0]["audio"]["array"]},
|
| 142 |
+
],
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"role": f"{ds[1]['speaker_id']}",
|
| 146 |
+
"content": [
|
| 147 |
+
{"type": "text", "text": ds[1]["text"]},
|
| 148 |
+
],
|
| 149 |
+
},
|
| 150 |
+
],
|
| 151 |
+
[
|
| 152 |
+
{
|
| 153 |
+
"role": f"{ds[0]['speaker_id']}",
|
| 154 |
+
"content": [
|
| 155 |
+
{"type": "text", "text": ds[0]["text"]},
|
| 156 |
+
],
|
| 157 |
+
}
|
| 158 |
+
],
|
| 159 |
+
]
|
| 160 |
+
inputs = processor.apply_chat_template(
|
| 161 |
+
conversation,
|
| 162 |
+
tokenize=True,
|
| 163 |
+
return_dict=True,
|
| 164 |
+
).to(device)
|
| 165 |
+
|
| 166 |
+
audio = model.generate(**inputs, output_audio=True)
|
| 167 |
+
processor.save_audio(audio, [f"speech_batch_idx_{i}.wav" for i in range(len(audio))])
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
### Making The Model Go Brrr
|
| 171 |
+
|
| 172 |
+
CSM supports full-graph compilation with CUDA graphs!
|
| 173 |
+
|
| 174 |
+
```python
|
| 175 |
+
import torch
|
| 176 |
+
import copy
|
| 177 |
+
from transformers import CsmForConditionalGeneration, AutoProcessor
|
| 178 |
+
from datasets import load_dataset
|
| 179 |
+
|
| 180 |
+
model_id = "sesame/csm-1b"
|
| 181 |
+
device = "cuda"
|
| 182 |
+
|
| 183 |
+
# set logs to ensure no recompilation and graph breaks
|
| 184 |
+
torch._logging.set_logs(graph_breaks=True, recompiles=True, cudagraphs=True)
|
| 185 |
+
|
| 186 |
+
# load the model and the processor
|
| 187 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 188 |
+
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
|
| 189 |
+
|
| 190 |
+
# use static cache, enabling automatically torch compile with fullgraph and reduce-overhead
|
| 191 |
+
model.generation_config.max_length = 250 # big enough to avoid recompilation
|
| 192 |
+
model.generation_config.max_new_tokens = None # would take precedence over max_length
|
| 193 |
+
model.generation_config.cache_implementation = "static"
|
| 194 |
+
model.depth_decoder.generation_config.cache_implementation = "static"
|
| 195 |
+
|
| 196 |
+
# generation kwargs
|
| 197 |
+
gen_kwargs = {
|
| 198 |
+
"do_sample": False,
|
| 199 |
+
"depth_decoder_do_sample": False,
|
| 200 |
+
"temperature": 1.0,
|
| 201 |
+
"depth_decoder_temperature": 1.0,
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
# Define a timing decorator
|
| 205 |
+
class TimerContext:
|
| 206 |
+
def __init__(self, name="Execution"):
|
| 207 |
+
self.name = name
|
| 208 |
+
self.start_event = None
|
| 209 |
+
self.end_event = None
|
| 210 |
+
|
| 211 |
+
def __enter__(self):
|
| 212 |
+
# Use CUDA events for more accurate GPU timing
|
| 213 |
+
self.start_event = torch.cuda.Event(enable_timing=True)
|
| 214 |
+
self.end_event = torch.cuda.Event(enable_timing=True)
|
| 215 |
+
self.start_event.record()
|
| 216 |
+
return self
|
| 217 |
+
|
| 218 |
+
def __exit__(self, *args):
|
| 219 |
+
self.end_event.record()
|
| 220 |
+
torch.cuda.synchronize()
|
| 221 |
+
elapsed_time = self.start_event.elapsed_time(self.end_event) / 1000.0
|
| 222 |
+
print(f"{self.name} time: {elapsed_time:.4f} seconds")
|
| 223 |
+
|
| 224 |
+
# prepare the inputs
|
| 225 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 226 |
+
|
| 227 |
+
conversation = [
|
| 228 |
+
{
|
| 229 |
+
"role": f"{ds[0]['speaker_id']}",
|
| 230 |
+
"content": [
|
| 231 |
+
{"type": "text", "text": ds[0]["text"]},
|
| 232 |
+
{"type": "audio", "path": ds[0]["audio"]["array"]},
|
| 233 |
+
],
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"role": f"{ds[1]['speaker_id']}",
|
| 237 |
+
"content": [
|
| 238 |
+
{"type": "text", "text": ds[1]["text"]},
|
| 239 |
+
{"type": "audio", "path": ds[1]["audio"]["array"]},
|
| 240 |
+
],
|
| 241 |
+
},
|
| 242 |
+
{
|
| 243 |
+
"role": f"{ds[2]['speaker_id']}",
|
| 244 |
+
"content": [
|
| 245 |
+
{"type": "text", "text": ds[2]["text"]},
|
| 246 |
+
],
|
| 247 |
+
},
|
| 248 |
+
]
|
| 249 |
+
|
| 250 |
+
padded_inputs_1 = processor.apply_chat_template(
|
| 251 |
+
conversation,
|
| 252 |
+
tokenize=True,
|
| 253 |
+
return_dict=True,
|
| 254 |
+
).to(device)
|
| 255 |
+
|
| 256 |
+
print("\n" + "="*50)
|
| 257 |
+
print("First generation - compiling and recording CUDA graphs...")
|
| 258 |
+
with TimerContext("First generation"):
|
| 259 |
+
_ = model.generate(**padded_inputs_1, **gen_kwargs)
|
| 260 |
+
print("="*50)
|
| 261 |
+
|
| 262 |
+
print("\n" + "="*50)
|
| 263 |
+
print("Second generation - fast !!!")
|
| 264 |
+
with TimerContext("Second generation"):
|
| 265 |
+
_ = model.generate(**padded_inputs_1, **gen_kwargs)
|
| 266 |
+
print("="*50)
|
| 267 |
+
|
| 268 |
+
# now with different inputs
|
| 269 |
+
conversation = [
|
| 270 |
+
{
|
| 271 |
+
"role": f"{ds[0]['speaker_id']}",
|
| 272 |
+
"content": [
|
| 273 |
+
{"type": "text", "text": ds[2]["text"]},
|
| 274 |
+
{"type": "audio", "path": ds[2]["audio"]["array"]},
|
| 275 |
+
],
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"role": f"{ds[1]['speaker_id']}",
|
| 279 |
+
"content": [
|
| 280 |
+
{"type": "text", "text": ds[3]["text"]},
|
| 281 |
+
{"type": "audio", "path": ds[3]["audio"]["array"]},
|
| 282 |
+
],
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"role": f"{ds[2]['speaker_id']}",
|
| 286 |
+
"content": [
|
| 287 |
+
{"type": "text", "text": ds[4]["text"]},
|
| 288 |
+
],
|
| 289 |
+
},
|
| 290 |
+
]
|
| 291 |
+
padded_inputs_2 = processor.apply_chat_template(
|
| 292 |
+
conversation,
|
| 293 |
+
tokenize=True,
|
| 294 |
+
return_dict=True,
|
| 295 |
+
).to(device)
|
| 296 |
+
|
| 297 |
+
print("\n" + "="*50)
|
| 298 |
+
print("Generation with other inputs!")
|
| 299 |
+
with TimerContext("Generation with different inputs"):
|
| 300 |
+
_ = model.generate(**padded_inputs_2, **gen_kwargs)
|
| 301 |
+
print("="*50)
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
+
### Training
|
| 305 |
+
|
| 306 |
+
CSM Transformers integration supports training!
|
| 307 |
+
|
| 308 |
+
```python
|
| 309 |
+
from transformers import CsmForConditionalGeneration, AutoProcessor, infer_device
|
| 310 |
+
from datasets import load_dataset, Audio
|
| 311 |
+
|
| 312 |
+
model_id = "sesame/csm-1b"
|
| 313 |
+
device = infer_device()
|
| 314 |
+
|
| 315 |
+
# load the model and the processor
|
| 316 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 317 |
+
model = CsmForConditionalGeneration.from_pretrained(model_id, device_map=device)
|
| 318 |
+
model.train()
|
| 319 |
+
model.codec_model.eval()
|
| 320 |
+
|
| 321 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 322 |
+
# ensure the audio is 24kHz
|
| 323 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=24000))
|
| 324 |
+
conversation = []
|
| 325 |
+
|
| 326 |
+
# context
|
| 327 |
+
for text, audio, speaker_id in zip(ds[:4]["text"], ds[:4]["audio"], ds[:4]["speaker_id"]):
|
| 328 |
+
conversation.append(
|
| 329 |
+
{
|
| 330 |
+
"role": f"{speaker_id}",
|
| 331 |
+
"content": [{"type": "text", "text": text}, {"type": "audio", "path": audio["array"]}],
|
| 332 |
+
}
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
inputs = processor.apply_chat_template(
|
| 336 |
+
conversation,
|
| 337 |
+
tokenize=True,
|
| 338 |
+
return_dict=True,
|
| 339 |
+
output_labels=True,
|
| 340 |
+
).to(device)
|
| 341 |
+
|
| 342 |
+
out = model(**inputs)
|
| 343 |
+
out.loss.backward()
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
This model was contributed by [Eustache Le Bihan](https://huggingface.co/eustlb).
|
| 347 |
+
The original code can be found [here](https://github.com/SesameAILabs/csm).
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
## CsmConfig
|
| 351 |
+
|
| 352 |
+
[[autodoc]] CsmConfig
|
| 353 |
+
|
| 354 |
+
## CsmDepthDecoderConfig
|
| 355 |
+
|
| 356 |
+
[[autodoc]] CsmDepthDecoderConfig
|
| 357 |
+
|
| 358 |
+
## CsmProcessor
|
| 359 |
+
|
| 360 |
+
<div class="flex justify-center">
|
| 361 |
+
<img src="https://huggingface.co/datasets/eustlb/documentation-images/resolve/main/fig1.jpg"/>
|
| 362 |
+
</div>
|
| 363 |
+
|
| 364 |
+
[[autodoc]] CsmProcessor
|
| 365 |
+
- __call__
|
| 366 |
+
|
| 367 |
+
## CsmForConditionalGeneration
|
| 368 |
+
|
| 369 |
+
[[autodoc]] CsmForConditionalGeneration
|
| 370 |
+
- forward
|
| 371 |
+
- generate
|
| 372 |
+
|
| 373 |
+
## CsmDepthDecoderForCausalLM
|
| 374 |
+
|
| 375 |
+
[[autodoc]] CsmDepthDecoderForCausalLM
|
| 376 |
+
|
| 377 |
+
## CsmDepthDecoderModel
|
| 378 |
+
|
| 379 |
+
[[autodoc]] CsmDepthDecoderModel
|
| 380 |
+
|
| 381 |
+
## CsmBackboneModel
|
| 382 |
+
|
| 383 |
+
[[autodoc]] CsmBackboneModel
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/ctrl.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2019-09-11 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
# CTRL
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
## Overview
|
| 26 |
+
|
| 27 |
+
CTRL model was proposed in [CTRL: A Conditional Transformer Language Model for Controllable Generation](https://huggingface.co/papers/1909.05858) by Nitish Shirish Keskar*, Bryan McCann*, Lav R. Varshney, Caiming Xiong and
|
| 28 |
+
Richard Socher. It's a causal (unidirectional) transformer pre-trained using language modeling on a very large corpus
|
| 29 |
+
of ~140 GB of text data with the first token reserved as a control code (such as Links, Books, Wikipedia etc.).
|
| 30 |
+
|
| 31 |
+
The abstract from the paper is the following:
|
| 32 |
+
|
| 33 |
+
*Large-scale language models show promising text generation capabilities, but users cannot easily control particular
|
| 34 |
+
aspects of the generated text. We release CTRL, a 1.63 billion-parameter conditional transformer language model,
|
| 35 |
+
trained to condition on control codes that govern style, content, and task-specific behavior. Control codes were
|
| 36 |
+
derived from structure that naturally co-occurs with raw text, preserving the advantages of unsupervised learning while
|
| 37 |
+
providing more explicit control over text generation. These codes also allow CTRL to predict which parts of the
|
| 38 |
+
training data are most likely given a sequence. This provides a potential method for analyzing large amounts of data
|
| 39 |
+
via model-based source attribution.*
|
| 40 |
+
|
| 41 |
+
This model was contributed by [keskarnitishr](https://huggingface.co/keskarnitishr). The original code can be found
|
| 42 |
+
[here](https://github.com/salesforce/ctrl).
|
| 43 |
+
|
| 44 |
+
## Usage tips
|
| 45 |
+
|
| 46 |
+
- CTRL makes use of control codes to generate text: it requires generations to be started by certain words, sentences
|
| 47 |
+
or links to generate coherent text. Refer to the [original implementation](https://github.com/salesforce/ctrl) for
|
| 48 |
+
more information.
|
| 49 |
+
- CTRL is a model with absolute position embeddings so it's usually advised to pad the inputs on the right rather than
|
| 50 |
+
the left.
|
| 51 |
+
- CTRL was trained with a causal language modeling (CLM) objective and is therefore powerful at predicting the next
|
| 52 |
+
token in a sequence. Leveraging this feature allows CTRL to generate syntactically coherent text as it can be
|
| 53 |
+
observed in the *run_generation.py* example script.
|
| 54 |
+
- The PyTorch models can take the `past_key_values` as input, which is the previously computed key/value attention pairs.
|
| 55 |
+
TensorFlow models accepts `past` as input. Using the `past_key_values` value prevents the model from re-computing
|
| 56 |
+
pre-computed values in the context of text generation. See the [`forward`](model_doc/ctrl#transformers.CTRLModel.forward)
|
| 57 |
+
method for more information on the usage of this argument.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
## Resources
|
| 61 |
+
|
| 62 |
+
- [Text classification task guide](../tasks/sequence_classification)
|
| 63 |
+
- [Causal language modeling task guide](../tasks/language_modeling)
|
| 64 |
+
|
| 65 |
+
## CTRLConfig
|
| 66 |
+
|
| 67 |
+
[[autodoc]] CTRLConfig
|
| 68 |
+
|
| 69 |
+
## CTRLTokenizer
|
| 70 |
+
|
| 71 |
+
[[autodoc]] CTRLTokenizer
|
| 72 |
+
- save_vocabulary
|
| 73 |
+
|
| 74 |
+
<frameworkcontent>
|
| 75 |
+
<pt>
|
| 76 |
+
|
| 77 |
+
## CTRLModel
|
| 78 |
+
|
| 79 |
+
[[autodoc]] CTRLModel
|
| 80 |
+
- forward
|
| 81 |
+
|
| 82 |
+
## CTRLLMHeadModel
|
| 83 |
+
|
| 84 |
+
[[autodoc]] CTRLLMHeadModel
|
| 85 |
+
- forward
|
| 86 |
+
|
| 87 |
+
## CTRLForSequenceClassification
|
| 88 |
+
|
| 89 |
+
[[autodoc]] CTRLForSequenceClassification
|
| 90 |
+
- forward
|
| 91 |
+
|
| 92 |
+
</pt>
|
| 93 |
+
<tf>
|
| 94 |
+
|
| 95 |
+
## TFCTRLModel
|
| 96 |
+
|
| 97 |
+
[[autodoc]] TFCTRLModel
|
| 98 |
+
- call
|
| 99 |
+
|
| 100 |
+
## TFCTRLLMHeadModel
|
| 101 |
+
|
| 102 |
+
[[autodoc]] TFCTRLLMHeadModel
|
| 103 |
+
- call
|
| 104 |
+
|
| 105 |
+
## TFCTRLForSequenceClassification
|
| 106 |
+
|
| 107 |
+
[[autodoc]] TFCTRLForSequenceClassification
|
| 108 |
+
- call
|
| 109 |
+
|
| 110 |
+
</tf>
|
| 111 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/cvt.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2021-03-29 and added to Hugging Face Transformers on 2022-05-18.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
# Convolutional Vision Transformer (CvT)
|
| 26 |
+
|
| 27 |
+
[Convolutional Vision Transformer (CvT)](https://huggingface.co/papers/2103.15808) is a model that combines the strengths of convolutional neural networks (CNNs) and Vision transformers for the computer vision tasks. It introduces convolutional layers into the vision transformer architecture, allowing it to capture local patterns in images while maintaining the global context provided by self-attention mechanisms.
|
| 28 |
+
|
| 29 |
+
You can find all the CvT checkpoints under the [Microsoft](https://huggingface.co/microsoft?search_models=cvt) organization.
|
| 30 |
+
|
| 31 |
+
> [!TIP]
|
| 32 |
+
> This model was contributed by [anujunj](https://huggingface.co/anugunj).
|
| 33 |
+
>
|
| 34 |
+
> Click on the CvT models in the right sidebar for more examples of how to apply CvT to different computer vision tasks.
|
| 35 |
+
|
| 36 |
+
The example below demonstrates how to classify an image with [`Pipeline`] or the [`AutoModel`] class.
|
| 37 |
+
|
| 38 |
+
<hfoptions id="usage">
|
| 39 |
+
<hfoption id="Pipeline">
|
| 40 |
+
|
| 41 |
+
```py
|
| 42 |
+
import torch
|
| 43 |
+
from transformers import pipeline
|
| 44 |
+
|
| 45 |
+
pipeline = pipeline(
|
| 46 |
+
task="image-classification",
|
| 47 |
+
model="microsoft/cvt-13",
|
| 48 |
+
torch_dtype=torch.float16,
|
| 49 |
+
device=0
|
| 50 |
+
)
|
| 51 |
+
pipeline("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
</hfoption>
|
| 55 |
+
<hfoption id="AutoModel">
|
| 56 |
+
|
| 57 |
+
```py
|
| 58 |
+
import torch
|
| 59 |
+
import requests
|
| 60 |
+
from PIL import Image
|
| 61 |
+
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 62 |
+
|
| 63 |
+
image_processor = AutoImageProcessor.from_pretrained("microsoft/cvt-13")
|
| 64 |
+
model = AutoModelForImageClassification.from_pretrained(
|
| 65 |
+
"microsoft/cvt-13",
|
| 66 |
+
torch_dtype=torch.float16,
|
| 67 |
+
device_map="auto"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
|
| 71 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 72 |
+
inputs = image_processor(image, return_tensors="pt").to(model.device)
|
| 73 |
+
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
logits = model(**inputs).logits
|
| 76 |
+
predicted_class_id = logits.argmax(dim=-1).item()
|
| 77 |
+
|
| 78 |
+
class_labels = model.config.id2label
|
| 79 |
+
predicted_class_label = class_labels[predicted_class_id]
|
| 80 |
+
print(f"The predicted class label is: {predicted_class_label}")
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
</hfoption>
|
| 84 |
+
</hfoptions>
|
| 85 |
+
|
| 86 |
+
## Resources
|
| 87 |
+
|
| 88 |
+
Refer to this set of ViT [notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/VisionTransformer) for examples of inference and fine-tuning on custom datasets. Replace [`ViTFeatureExtractor`] and [`ViTForImageClassification`] in these notebooks with [`AutoImageProcessor`] and [`CvtForImageClassification`].
|
| 89 |
+
|
| 90 |
+
## CvtConfig
|
| 91 |
+
|
| 92 |
+
[[autodoc]] CvtConfig
|
| 93 |
+
|
| 94 |
+
<frameworkcontent>
|
| 95 |
+
<pt>
|
| 96 |
+
|
| 97 |
+
## CvtModel
|
| 98 |
+
|
| 99 |
+
[[autodoc]] CvtModel
|
| 100 |
+
- forward
|
| 101 |
+
|
| 102 |
+
## CvtForImageClassification
|
| 103 |
+
|
| 104 |
+
[[autodoc]] CvtForImageClassification
|
| 105 |
+
- forward
|
| 106 |
+
|
| 107 |
+
</pt>
|
| 108 |
+
<tf>
|
| 109 |
+
|
| 110 |
+
## TFCvtModel
|
| 111 |
+
|
| 112 |
+
[[autodoc]] TFCvtModel
|
| 113 |
+
- call
|
| 114 |
+
|
| 115 |
+
## TFCvtForImageClassification
|
| 116 |
+
|
| 117 |
+
[[autodoc]] TFCvtForImageClassification
|
| 118 |
+
- call
|
| 119 |
+
|
| 120 |
+
</tf>
|
| 121 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/d_fine.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-10-17 and added to Hugging Face Transformers on 2025-04-29.*
|
| 17 |
+
|
| 18 |
+
# D-FINE
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
The D-FINE model was proposed in [D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement](https://huggingface.co/papers/2410.13842) by
|
| 23 |
+
Yansong Peng, Hebei Li, Peixi Wu, Yueyi Zhang, Xiaoyan Sun, Feng Wu
|
| 24 |
+
|
| 25 |
+
The abstract from the paper is the following:
|
| 26 |
+
|
| 27 |
+
*We introduce D-FINE, a powerful real-time object detector that achieves outstanding localization precision by redefining the bounding box regression task in DETR models. D-FINE comprises two key components: Fine-grained Distribution Refinement (FDR) and Global Optimal Localization Self-Distillation (GO-LSD).
|
| 28 |
+
FDR transforms the regression process from predicting fixed coordinates to iteratively refining probability distributions, providing a fine-grained intermediate representation that significantly enhances localization accuracy. GO-LSD is a bidirectional optimization strategy that transfers localization knowledge from refined distributions to shallower layers through self-distillation, while also simplifying the residual prediction tasks for deeper layers. Additionally, D-FINE incorporates lightweight optimizations in computationally intensive modules and operations, achieving a better balance between speed and accuracy. Specifically, D-FINE-L / X achieves 54.0% / 55.8% AP on the COCO dataset at 124 / 78 FPS on an NVIDIA T4 GPU. When pretrained on Objects365, D-FINE-L / X attains 57.1% / 59.3% AP, surpassing all existing real-time detectors. Furthermore, our method significantly enhances the performance of a wide range of DETR models by up to 5.3% AP with negligible extra parameters and training costs. Our code and pretrained models: this https URL.*
|
| 29 |
+
|
| 30 |
+
This model was contributed by [VladOS95-cyber](https://github.com/VladOS95-cyber).
|
| 31 |
+
The original code can be found [here](https://github.com/Peterande/D-FINE).
|
| 32 |
+
|
| 33 |
+
## Usage tips
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
>>> import torch
|
| 37 |
+
>>> from transformers.image_utils import load_image
|
| 38 |
+
>>> from transformers import DFineForObjectDetection, AutoImageProcessor
|
| 39 |
+
|
| 40 |
+
>>> url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 41 |
+
>>> image = load_image(url)
|
| 42 |
+
|
| 43 |
+
>>> image_processor = AutoImageProcessor.from_pretrained("ustc-community/dfine_x_coco")
|
| 44 |
+
>>> model = DFineForObjectDetection.from_pretrained("ustc-community/dfine_x_coco")
|
| 45 |
+
|
| 46 |
+
>>> inputs = image_processor(images=image, return_tensors="pt")
|
| 47 |
+
|
| 48 |
+
>>> with torch.no_grad():
|
| 49 |
+
... outputs = model(**inputs)
|
| 50 |
+
|
| 51 |
+
>>> results = image_processor.post_process_object_detection(outputs, target_sizes=[(image.height, image.width)], threshold=0.5)
|
| 52 |
+
|
| 53 |
+
>>> for result in results:
|
| 54 |
+
... for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 55 |
+
... score, label = score.item(), label_id.item()
|
| 56 |
+
... box = [round(i, 2) for i in box.tolist()]
|
| 57 |
+
... print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|
| 58 |
+
cat: 0.96 [344.49, 23.4, 639.84, 374.27]
|
| 59 |
+
cat: 0.96 [11.71, 53.52, 316.64, 472.33]
|
| 60 |
+
remote: 0.95 [40.46, 73.7, 175.62, 117.57]
|
| 61 |
+
sofa: 0.92 [0.59, 1.88, 640.25, 474.74]
|
| 62 |
+
remote: 0.89 [333.48, 77.04, 370.77, 187.3]
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## DFineConfig
|
| 66 |
+
|
| 67 |
+
[[autodoc]] DFineConfig
|
| 68 |
+
|
| 69 |
+
## DFineModel
|
| 70 |
+
|
| 71 |
+
[[autodoc]] DFineModel
|
| 72 |
+
- forward
|
| 73 |
+
|
| 74 |
+
## DFineForObjectDetection
|
| 75 |
+
|
| 76 |
+
[[autodoc]] DFineForObjectDetection
|
| 77 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dab-detr.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-01-28 and added to Hugging Face Transformers on 2025-02-04.*
|
| 17 |
+
|
| 18 |
+
# DAB-DETR
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
The DAB-DETR model was proposed in [DAB-DETR: Dynamic Anchor Boxes are Better Queries for DETR](https://huggingface.co/papers/2201.12329) by Shilong Liu, Feng Li, Hao Zhang, Xiao Yang, Xianbiao Qi, Hang Su, Jun Zhu, Lei Zhang.
|
| 27 |
+
DAB-DETR is an enhanced variant of Conditional DETR. It utilizes dynamically updated anchor boxes to provide both a reference query point (x, y) and a reference anchor size (w, h), improving cross-attention computation. This new approach achieves 45.7% AP when trained for 50 epochs with a single ResNet-50 model as the backbone.
|
| 28 |
+
|
| 29 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/dab_detr_convergence_plot.png"
|
| 30 |
+
alt="drawing" width="600"/>
|
| 31 |
+
|
| 32 |
+
The abstract from the paper is the following:
|
| 33 |
+
|
| 34 |
+
*We present in this paper a novel query formulation using dynamic anchor boxes
|
| 35 |
+
for DETR (DEtection TRansformer) and offer a deeper understanding of the role
|
| 36 |
+
of queries in DETR. This new formulation directly uses box coordinates as queries
|
| 37 |
+
in Transformer decoders and dynamically updates them layer-by-layer. Using box
|
| 38 |
+
coordinates not only helps using explicit positional priors to improve the query-to-feature similarity and eliminate the slow training convergence issue in DETR,
|
| 39 |
+
but also allows us to modulate the positional attention map using the box width
|
| 40 |
+
and height information. Such a design makes it clear that queries in DETR can be
|
| 41 |
+
implemented as performing soft ROI pooling layer-by-layer in a cascade manner.
|
| 42 |
+
As a result, it leads to the best performance on MS-COCO benchmark among
|
| 43 |
+
the DETR-like detection models under the same setting, e.g., AP 45.7% using
|
| 44 |
+
ResNet50-DC5 as backbone trained in 50 epochs. We also conducted extensive
|
| 45 |
+
experiments to confirm our analysis and verify the effectiveness of our methods.*
|
| 46 |
+
|
| 47 |
+
This model was contributed by [davidhajdu](https://huggingface.co/davidhajdu).
|
| 48 |
+
The original code can be found [here](https://github.com/IDEA-Research/DAB-DETR).
|
| 49 |
+
|
| 50 |
+
## How to Get Started with the Model
|
| 51 |
+
|
| 52 |
+
Use the code below to get started with the model.
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
import torch
|
| 56 |
+
import requests
|
| 57 |
+
|
| 58 |
+
from PIL import Image
|
| 59 |
+
from transformers import AutoModelForObjectDetection, AutoImageProcessor
|
| 60 |
+
|
| 61 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 62 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 63 |
+
|
| 64 |
+
image_processor = AutoImageProcessor.from_pretrained("IDEA-Research/dab-detr-resnet-50")
|
| 65 |
+
model = AutoModelForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50")
|
| 66 |
+
|
| 67 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 68 |
+
|
| 69 |
+
with torch.no_grad():
|
| 70 |
+
outputs = model(**inputs)
|
| 71 |
+
|
| 72 |
+
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
|
| 73 |
+
|
| 74 |
+
for result in results:
|
| 75 |
+
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 76 |
+
score, label = score.item(), label_id.item()
|
| 77 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 78 |
+
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|
| 79 |
+
```
|
| 80 |
+
This should output
|
| 81 |
+
```
|
| 82 |
+
cat: 0.87 [14.7, 49.39, 320.52, 469.28]
|
| 83 |
+
remote: 0.86 [41.08, 72.37, 173.39, 117.2]
|
| 84 |
+
cat: 0.86 [344.45, 19.43, 639.85, 367.86]
|
| 85 |
+
remote: 0.61 [334.27, 75.93, 367.92, 188.81]
|
| 86 |
+
couch: 0.59 [-0.04, 1.34, 639.9, 477.09]
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
There are three other ways to instantiate a DAB-DETR model (depending on what you prefer):
|
| 90 |
+
|
| 91 |
+
Option 1: Instantiate DAB-DETR with pre-trained weights for entire model
|
| 92 |
+
```py
|
| 93 |
+
>>> from transformers import DabDetrForObjectDetection
|
| 94 |
+
|
| 95 |
+
>>> model = DabDetrForObjectDetection.from_pretrained("IDEA-Research/dab-detr-resnet-50")
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
Option 2: Instantiate DAB-DETR with randomly initialized weights for Transformer, but pre-trained weights for backbone
|
| 99 |
+
```py
|
| 100 |
+
>>> from transformers import DabDetrConfig, DabDetrForObjectDetection
|
| 101 |
+
|
| 102 |
+
>>> config = DabDetrConfig()
|
| 103 |
+
>>> model = DabDetrForObjectDetection(config)
|
| 104 |
+
```
|
| 105 |
+
Option 3: Instantiate DAB-DETR with randomly initialized weights for backbone + Transformer
|
| 106 |
+
```py
|
| 107 |
+
>>> config = DabDetrConfig(use_pretrained_backbone=False)
|
| 108 |
+
>>> model = DabDetrForObjectDetection(config)
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
## DabDetrConfig
|
| 113 |
+
|
| 114 |
+
[[autodoc]] DabDetrConfig
|
| 115 |
+
|
| 116 |
+
## DabDetrModel
|
| 117 |
+
|
| 118 |
+
[[autodoc]] DabDetrModel
|
| 119 |
+
- forward
|
| 120 |
+
|
| 121 |
+
## DabDetrForObjectDetection
|
| 122 |
+
|
| 123 |
+
[[autodoc]] DabDetrForObjectDetection
|
| 124 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dac.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2023-06-11 and added to Hugging Face Transformers on 2024-08-19.*
|
| 17 |
+
|
| 18 |
+
# DAC
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
The DAC model was proposed in [Descript Audio Codec: High-Fidelity Audio Compression with Improved RVQGAN](https://huggingface.co/papers/2306.06546) by Rithesh Kumar, Prem Seetharaman, Alejandro Luebs, Ishaan Kumar, Kundan Kumar.
|
| 28 |
+
|
| 29 |
+
The Descript Audio Codec (DAC) model is a powerful tool for compressing audio data, making it highly efficient for storage and transmission. By compressing 44.1 KHz audio into tokens at just 8kbps bandwidth, the DAC model enables high-quality audio processing while significantly reducing the data footprint. This is particularly useful in scenarios where bandwidth is limited or storage space is at a premium, such as in streaming applications, remote conferencing, and archiving large audio datasets.
|
| 30 |
+
|
| 31 |
+
The abstract from the paper is the following:
|
| 32 |
+
|
| 33 |
+
*Language models have been successfully used to model natural signals, such as images, speech, and music. A key component of these models is a high quality neural compression model that can compress high-dimensional natural signals into lower dimensional discrete tokens. To that end, we introduce a high-fidelity universal neural audio compression algorithm that achieves ~90x compression of 44.1 KHz audio into tokens at just 8kbps bandwidth. We achieve this by combining advances in high-fidelity audio generation with better vector quantization techniques from the image domain, along with improved adversarial and reconstruction losses. We compress all domains (speech, environment, music, etc.) with a single universal model, making it widely applicable to generative modeling of all audio. We compare with competing audio compression algorithms, and find our method outperforms them significantly. We provide thorough ablations for every design choice, as well as open-source code and trained model weights. We hope our work can lay the foundation for the next generation of high-fidelity audio modeling.*
|
| 34 |
+
|
| 35 |
+
This model was contributed by [Kamil Akesbi](https://huggingface.co/kamilakesbi).
|
| 36 |
+
The original code can be found [here](https://github.com/descriptinc/descript-audio-codec/tree/main?tab=readme-ov-file).
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
## Model structure
|
| 40 |
+
|
| 41 |
+
The Descript Audio Codec (DAC) model is structured into three distinct stages:
|
| 42 |
+
|
| 43 |
+
1. Encoder Model: This stage compresses the input audio, reducing its size while retaining essential information.
|
| 44 |
+
2. Residual Vector Quantizer (RVQ) Model: Working in tandem with the encoder, this model quantizes the latent codes of the audio, refining the compression and ensuring high-quality reconstruction.
|
| 45 |
+
3. Decoder Model: This final stage reconstructs the audio from its compressed form, restoring it to a state that closely resembles the original input.
|
| 46 |
+
|
| 47 |
+
## Usage example
|
| 48 |
+
|
| 49 |
+
Here is a quick example of how to encode and decode an audio using this model:
|
| 50 |
+
|
| 51 |
+
```python
|
| 52 |
+
>>> from datasets import load_dataset, Audio
|
| 53 |
+
>>> from transformers import DacModel, AutoProcessor
|
| 54 |
+
>>> librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 55 |
+
|
| 56 |
+
>>> model = DacModel.from_pretrained("descript/dac_16khz")
|
| 57 |
+
>>> processor = AutoProcessor.from_pretrained("descript/dac_16khz")
|
| 58 |
+
>>> librispeech_dummy = librispeech_dummy.cast_column("audio", Audio(sampling_rate=processor.sampling_rate))
|
| 59 |
+
>>> audio_sample = librispeech_dummy[-1]["audio"]["array"]
|
| 60 |
+
>>> inputs = processor(raw_audio=audio_sample, sampling_rate=processor.sampling_rate, return_tensors="pt")
|
| 61 |
+
|
| 62 |
+
>>> encoder_outputs = model.encode(inputs["input_values"])
|
| 63 |
+
>>> # Get the intermediate audio codes
|
| 64 |
+
>>> audio_codes = encoder_outputs.audio_codes
|
| 65 |
+
>>> # Reconstruct the audio from its quantized representation
|
| 66 |
+
>>> audio_values = model.decode(encoder_outputs.quantized_representation)
|
| 67 |
+
>>> # or the equivalent with a forward pass
|
| 68 |
+
>>> audio_values = model(inputs["input_values"]).audio_values
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
## DacConfig
|
| 72 |
+
|
| 73 |
+
[[autodoc]] DacConfig
|
| 74 |
+
|
| 75 |
+
## DacFeatureExtractor
|
| 76 |
+
|
| 77 |
+
[[autodoc]] DacFeatureExtractor
|
| 78 |
+
- __call__
|
| 79 |
+
|
| 80 |
+
## DacModel
|
| 81 |
+
|
| 82 |
+
[[autodoc]] DacModel
|
| 83 |
+
- decode
|
| 84 |
+
- encode
|
| 85 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/data2vec.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-02-07 and added to Hugging Face Transformers on 2022-03-01.*
|
| 17 |
+
|
| 18 |
+
# Data2Vec
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
## Overview
|
| 27 |
+
|
| 28 |
+
The Data2Vec model was proposed in [data2vec: A General Framework for Self-supervised Learning in Speech, Vision and Language](https://huggingface.co/papers/2202.03555) by Alexei Baevski, Wei-Ning Hsu, Qiantong Xu, Arun Babu, Jiatao Gu and Michael Auli.
|
| 29 |
+
Data2Vec proposes a unified framework for self-supervised learning across different data modalities - text, audio and images.
|
| 30 |
+
Importantly, predicted targets for pre-training are contextualized latent representations of the inputs, rather than modality-specific, context-independent targets.
|
| 31 |
+
|
| 32 |
+
The abstract from the paper is the following:
|
| 33 |
+
|
| 34 |
+
*While the general idea of self-supervised learning is identical across modalities, the actual algorithms and
|
| 35 |
+
objectives differ widely because they were developed with a single modality in mind. To get us closer to general
|
| 36 |
+
self-supervised learning, we present data2vec, a framework that uses the same learning method for either speech,
|
| 37 |
+
NLP or computer vision. The core idea is to predict latent representations of the full input data based on a
|
| 38 |
+
masked view of the input in a selfdistillation setup using a standard Transformer architecture.
|
| 39 |
+
Instead of predicting modality-specific targets such as words, visual tokens or units of human speech which
|
| 40 |
+
are local in nature, data2vec predicts contextualized latent representations that contain information from
|
| 41 |
+
the entire input. Experiments on the major benchmarks of speech recognition, image classification, and
|
| 42 |
+
natural language understanding demonstrate a new state of the art or competitive performance to predominant approaches.
|
| 43 |
+
Models and code are available at www.github.com/pytorch/fairseq/tree/master/examples/data2vec.*
|
| 44 |
+
|
| 45 |
+
This model was contributed by [edugp](https://huggingface.co/edugp) and [patrickvonplaten](https://huggingface.co/patrickvonplaten).
|
| 46 |
+
[sayakpaul](https://github.com/sayakpaul) and [Rocketknight1](https://github.com/Rocketknight1) contributed Data2Vec for vision in TensorFlow.
|
| 47 |
+
|
| 48 |
+
The original code (for NLP and Speech) can be found [here](https://github.com/pytorch/fairseq/tree/main/examples/data2vec).
|
| 49 |
+
The original code for vision can be found [here](https://github.com/facebookresearch/data2vec_vision/tree/main/beit).
|
| 50 |
+
|
| 51 |
+
## Usage tips
|
| 52 |
+
|
| 53 |
+
- Data2VecAudio, Data2VecText, and Data2VecVision have all been trained using the same self-supervised learning method.
|
| 54 |
+
- For Data2VecAudio, preprocessing is identical to [`Wav2Vec2Model`], including feature extraction
|
| 55 |
+
- For Data2VecText, preprocessing is identical to [`RobertaModel`], including tokenization.
|
| 56 |
+
- For Data2VecVision, preprocessing is identical to [`BeitModel`], including feature extraction.
|
| 57 |
+
- The `head_mask` argument is ignored when using all attention implementation other than "eager". If you have a `head_mask` and want it to have effect, load the model with `XXXModel.from_pretrained(model_id, attn_implementation="eager")`
|
| 58 |
+
|
| 59 |
+
### Using Scaled Dot Product Attention (SDPA)
|
| 60 |
+
|
| 61 |
+
PyTorch includes a native scaled dot-product attention (SDPA) operator as part of `torch.nn.functional`. This function
|
| 62 |
+
encompasses several implementations that can be applied depending on the inputs and the hardware in use. See the
|
| 63 |
+
[official documentation](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)
|
| 64 |
+
or the [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)
|
| 65 |
+
page for more information.
|
| 66 |
+
|
| 67 |
+
SDPA is used by default for `torch>=2.1.1` when an implementation is available, but you may also set
|
| 68 |
+
`attn_implementation="sdpa"` in `from_pretrained()` to explicitly request SDPA to be used.
|
| 69 |
+
|
| 70 |
+
The SDPA implementation is currently available for the Data2VecAudio and Data2VecVision models.
|
| 71 |
+
|
| 72 |
+
```
|
| 73 |
+
from transformers import Data2VecVisionForImageClassification
|
| 74 |
+
model = Data2VecVisionForImageClassification.from_pretrained("facebook/data2vec-vision-base", attn_implementation="sdpa", torch_dtype=torch.float16)
|
| 75 |
+
...
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
For the best speedups, we recommend loading the model in half-precision (e.g. `torch.float16` or `torch.bfloat16`).
|
| 79 |
+
|
| 80 |
+
For the Data2VecVision model, on a local benchmark (NVIDIA GeForce RTX 2060-8GB, PyTorch 2.5.1, OS Ubuntu 20.04)
|
| 81 |
+
with `float16` and `facebook/data2vec-vision-base` model, we saw the following improvements during training and
|
| 82 |
+
inference:
|
| 83 |
+
|
| 84 |
+
#### Training
|
| 85 |
+
|
| 86 |
+
| num_training_steps | batch_size | image_size | is_cuda | Time per batch (eager - s) | Time per batch (sdpa - s) | Speedup (%) | Eager peak mem (MB) | SDPA peak mem (MB) | Mem saving (%) |
|
| 87 |
+
|--------------------|------------|--------------|---------|----------------------------|---------------------------|-------------|----------------------|--------------------|----------------|
|
| 88 |
+
| 50 | 2 | (1048, 640) | True | 0.996 | 0.754 | 32.147 | 6722.198 | 4264.653 | 57.626 |
|
| 89 |
+
|
| 90 |
+
#### Inference
|
| 91 |
+
|
| 92 |
+
| Image batch size | Eager (s/iter) | Eager CI, % | Eager memory (MB) | SDPA (s/iter) | SDPA CI, % | SDPA memory (MB) | SDPA speedup | SDPA memory saved |
|
| 93 |
+
|-------------------:|-----------------:|:--------------|--------------------:|----------------:|:-------------|-------------------:|---------------:|--------------------:|
|
| 94 |
+
| 1 | 0.011 | ±0.3% | 3.76143e+08 | 0.01 | ±0.3% | 3.74397e+08 | 1.101 | 0.466 |
|
| 95 |
+
| 4 | 0.014 | ±0.1% | 4.02756e+08 | 0.012 | ±0.2% | 3.91373e+08 | 1.219 | 2.909 |
|
| 96 |
+
| 16 | 0.046 | ±0.3% | 4.96482e+08 | 0.035 | ±0.2% | 4.51017e+08 | 1.314 | 10.081 |
|
| 97 |
+
| 32 | 0.088 | ±0.1% | 6.23903e+08 | 0.067 | ±0.1% | 5.32974e+08 | 1.33 | 17.061 |
|
| 98 |
+
|
| 99 |
+
## Resources
|
| 100 |
+
|
| 101 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Data2Vec.
|
| 102 |
+
|
| 103 |
+
<PipelineTag pipeline="image-classification"/>
|
| 104 |
+
|
| 105 |
+
- [`Data2VecVisionForImageClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb).
|
| 106 |
+
- To fine-tune [`TFData2VecVisionForImageClassification`] on a custom dataset, see [this notebook](https://colab.research.google.com/github/sayakpaul/TF-2.0-Hacks/blob/master/data2vec_vision_image_classification.ipynb).
|
| 107 |
+
|
| 108 |
+
**Data2VecText documentation resources**
|
| 109 |
+
- [Text classification task guide](../tasks/sequence_classification)
|
| 110 |
+
- [Token classification task guide](../tasks/token_classification)
|
| 111 |
+
- [Question answering task guide](../tasks/question_answering)
|
| 112 |
+
- [Causal language modeling task guide](../tasks/language_modeling)
|
| 113 |
+
- [Masked language modeling task guide](../tasks/masked_language_modeling)
|
| 114 |
+
- [Multiple choice task guide](../tasks/multiple_choice)
|
| 115 |
+
|
| 116 |
+
**Data2VecAudio documentation resources**
|
| 117 |
+
- [Audio classification task guide](../tasks/audio_classification)
|
| 118 |
+
- [Automatic speech recognition task guide](../tasks/asr)
|
| 119 |
+
|
| 120 |
+
**Data2VecVision documentation resources**
|
| 121 |
+
- [Image classification](../tasks/image_classification)
|
| 122 |
+
- [Semantic segmentation](../tasks/semantic_segmentation)
|
| 123 |
+
|
| 124 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 125 |
+
|
| 126 |
+
## Data2VecTextConfig
|
| 127 |
+
|
| 128 |
+
[[autodoc]] Data2VecTextConfig
|
| 129 |
+
|
| 130 |
+
## Data2VecAudioConfig
|
| 131 |
+
|
| 132 |
+
[[autodoc]] Data2VecAudioConfig
|
| 133 |
+
|
| 134 |
+
## Data2VecVisionConfig
|
| 135 |
+
|
| 136 |
+
[[autodoc]] Data2VecVisionConfig
|
| 137 |
+
|
| 138 |
+
<frameworkcontent>
|
| 139 |
+
<pt>
|
| 140 |
+
|
| 141 |
+
## Data2VecAudioModel
|
| 142 |
+
|
| 143 |
+
[[autodoc]] Data2VecAudioModel
|
| 144 |
+
- forward
|
| 145 |
+
|
| 146 |
+
## Data2VecAudioForAudioFrameClassification
|
| 147 |
+
|
| 148 |
+
[[autodoc]] Data2VecAudioForAudioFrameClassification
|
| 149 |
+
- forward
|
| 150 |
+
|
| 151 |
+
## Data2VecAudioForCTC
|
| 152 |
+
|
| 153 |
+
[[autodoc]] Data2VecAudioForCTC
|
| 154 |
+
- forward
|
| 155 |
+
|
| 156 |
+
## Data2VecAudioForSequenceClassification
|
| 157 |
+
|
| 158 |
+
[[autodoc]] Data2VecAudioForSequenceClassification
|
| 159 |
+
- forward
|
| 160 |
+
|
| 161 |
+
## Data2VecAudioForXVector
|
| 162 |
+
|
| 163 |
+
[[autodoc]] Data2VecAudioForXVector
|
| 164 |
+
- forward
|
| 165 |
+
|
| 166 |
+
## Data2VecTextModel
|
| 167 |
+
|
| 168 |
+
[[autodoc]] Data2VecTextModel
|
| 169 |
+
- forward
|
| 170 |
+
|
| 171 |
+
## Data2VecTextForCausalLM
|
| 172 |
+
|
| 173 |
+
[[autodoc]] Data2VecTextForCausalLM
|
| 174 |
+
- forward
|
| 175 |
+
|
| 176 |
+
## Data2VecTextForMaskedLM
|
| 177 |
+
|
| 178 |
+
[[autodoc]] Data2VecTextForMaskedLM
|
| 179 |
+
- forward
|
| 180 |
+
|
| 181 |
+
## Data2VecTextForSequenceClassification
|
| 182 |
+
|
| 183 |
+
[[autodoc]] Data2VecTextForSequenceClassification
|
| 184 |
+
- forward
|
| 185 |
+
|
| 186 |
+
## Data2VecTextForMultipleChoice
|
| 187 |
+
|
| 188 |
+
[[autodoc]] Data2VecTextForMultipleChoice
|
| 189 |
+
- forward
|
| 190 |
+
|
| 191 |
+
## Data2VecTextForTokenClassification
|
| 192 |
+
|
| 193 |
+
[[autodoc]] Data2VecTextForTokenClassification
|
| 194 |
+
- forward
|
| 195 |
+
|
| 196 |
+
## Data2VecTextForQuestionAnswering
|
| 197 |
+
|
| 198 |
+
[[autodoc]] Data2VecTextForQuestionAnswering
|
| 199 |
+
- forward
|
| 200 |
+
|
| 201 |
+
## Data2VecVisionModel
|
| 202 |
+
|
| 203 |
+
[[autodoc]] Data2VecVisionModel
|
| 204 |
+
- forward
|
| 205 |
+
|
| 206 |
+
## Data2VecVisionForImageClassification
|
| 207 |
+
|
| 208 |
+
[[autodoc]] Data2VecVisionForImageClassification
|
| 209 |
+
- forward
|
| 210 |
+
|
| 211 |
+
## Data2VecVisionForSemanticSegmentation
|
| 212 |
+
|
| 213 |
+
[[autodoc]] Data2VecVisionForSemanticSegmentation
|
| 214 |
+
- forward
|
| 215 |
+
|
| 216 |
+
</pt>
|
| 217 |
+
<tf>
|
| 218 |
+
|
| 219 |
+
## TFData2VecVisionModel
|
| 220 |
+
|
| 221 |
+
[[autodoc]] TFData2VecVisionModel
|
| 222 |
+
- call
|
| 223 |
+
|
| 224 |
+
## TFData2VecVisionForImageClassification
|
| 225 |
+
|
| 226 |
+
[[autodoc]] TFData2VecVisionForImageClassification
|
| 227 |
+
- call
|
| 228 |
+
|
| 229 |
+
## TFData2VecVisionForSemanticSegmentation
|
| 230 |
+
|
| 231 |
+
[[autodoc]] TFData2VecVisionForSemanticSegmentation
|
| 232 |
+
- call
|
| 233 |
+
|
| 234 |
+
</tf>
|
| 235 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dbrx.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
-->
|
| 12 |
+
*This model was released on 2024-03-27 and added to Hugging Face Transformers on 2024-04-18.*
|
| 13 |
+
|
| 14 |
+
# DBRX
|
| 15 |
+
|
| 16 |
+
<div class="flex flex-wrap space-x-1">
|
| 17 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 18 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 19 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
## Overview
|
| 23 |
+
|
| 24 |
+
DBRX is a [transformer-based](https://www.isattentionallyouneed.com/) decoder-only large language model (LLM) that was trained using next-token prediction.
|
| 25 |
+
It uses a *fine-grained* mixture-of-experts (MoE) architecture with 132B total parameters of which 36B parameters are active on any input.
|
| 26 |
+
It was pre-trained on 12T tokens of text and code data.
|
| 27 |
+
Compared to other open MoE models like Mixtral-8x7B and Grok-1, DBRX is fine-grained, meaning it uses a larger number of smaller experts. DBRX has 16 experts and chooses 4, while Mixtral-8x7B and Grok-1 have 8 experts and choose 2.
|
| 28 |
+
This provides 65x more possible combinations of experts and we found that this improves model quality.
|
| 29 |
+
DBRX uses rotary position encodings (RoPE), gated linear units (GLU), and grouped query attention (GQA).
|
| 30 |
+
It is a BPE based model and uses the GPT-4 tokenizer as described in the [tiktoken](https://github.com/openai/tiktoken) repository.
|
| 31 |
+
We made these choices based on exhaustive evaluation and scaling experiments.
|
| 32 |
+
|
| 33 |
+
DBRX was pretrained on 12T tokens of carefully curated data and a maximum context length of 32K tokens.
|
| 34 |
+
We estimate that this data is at least 2x better token-for-token than the data we used to pretrain the MPT family of models.
|
| 35 |
+
This new dataset was developed using the full suite of Databricks tools, including Apache Spark™ and Databricks notebooks for data processing, and Unity Catalog for data management and governance.
|
| 36 |
+
We used curriculum learning for pretraining, changing the data mix during training in ways we found to substantially improve model quality.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
More detailed information about DBRX Instruct and DBRX Base can be found in our [technical blog post](https://www.databricks.com/blog/introducing-dbrx-new-state-art-open-llm).
|
| 40 |
+
|
| 41 |
+
This model was contributed by [eitan-turok](https://huggingface.co/eitanturok) and [abhi-db](https://huggingface.co/abhi-db). The original code can be found [here](https://github.com/databricks/dbrx-instruct), though this may not be up to date.
|
| 42 |
+
|
| 43 |
+
## Usage Examples
|
| 44 |
+
|
| 45 |
+
The `generate()` method can be used to generate text using DBRX. You can generate using the standard attention implementation, flash-attention, and the PyTorch scaled dot product attention. The last two attention implementations give speed ups.
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import DbrxForCausalLM, AutoTokenizer
|
| 49 |
+
import torch
|
| 50 |
+
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained("databricks/dbrx-instruct", token="YOUR_HF_TOKEN")
|
| 52 |
+
model = DbrxForCausalLM.from_pretrained(
|
| 53 |
+
"databricks/dbrx-instruct",
|
| 54 |
+
device_map="auto",
|
| 55 |
+
torch_dtype=torch.bfloat16,
|
| 56 |
+
token="YOUR_HF_TOKEN",
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
input_text = "What does it take to build a great LLM?"
|
| 60 |
+
messages = [{"role": "user", "content": input_text}]
|
| 61 |
+
input_ids = tokenizer.apply_chat_template(messages, return_dict=True, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 62 |
+
|
| 63 |
+
outputs = model.generate(**input_ids, max_new_tokens=200)
|
| 64 |
+
print(tokenizer.decode(outputs[0]))
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
If you have flash-attention installed (`pip install flash-attn`), it is possible to generate faster. (The HuggingFace documentation for flash-attention can be found [here](https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-2).)
|
| 68 |
+
```python
|
| 69 |
+
from transformers import DbrxForCausalLM, AutoTokenizer
|
| 70 |
+
import torch
|
| 71 |
+
|
| 72 |
+
tokenizer = AutoTokenizer.from_pretrained("databricks/dbrx-instruct", token="YOUR_HF_TOKEN")
|
| 73 |
+
model = DbrxForCausalLM.from_pretrained(
|
| 74 |
+
"databricks/dbrx-instruct",
|
| 75 |
+
device_map="auto",
|
| 76 |
+
torch_dtype=torch.bfloat16,
|
| 77 |
+
token="YOUR_HF_TOKEN",
|
| 78 |
+
attn_implementation="flash_attention_2",
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
input_text = "What does it take to build a great LLM?"
|
| 82 |
+
messages = [{"role": "user", "content": input_text}]
|
| 83 |
+
input_ids = tokenizer.apply_chat_template(messages, return_dict=True, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 84 |
+
|
| 85 |
+
outputs = model.generate(**input_ids, max_new_tokens=200)
|
| 86 |
+
print(tokenizer.decode(outputs[0]))
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
You can also generate faster using the PyTorch scaled dot product attention. (The HuggingFace documentation for scaled dot product attention can be found [here](https://huggingface.co/docs/transformers/perf_infer_gpu_one#pytorch-scaled-dot-product-attention).)
|
| 90 |
+
```python
|
| 91 |
+
from transformers import DbrxForCausalLM, AutoTokenizer
|
| 92 |
+
import torch
|
| 93 |
+
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("databricks/dbrx-instruct", token="YOUR_HF_TOKEN")
|
| 95 |
+
model = DbrxForCausalLM.from_pretrained(
|
| 96 |
+
"databricks/dbrx-instruct",
|
| 97 |
+
device_map="auto",
|
| 98 |
+
torch_dtype=torch.bfloat16,
|
| 99 |
+
token="YOUR_HF_TOKEN",
|
| 100 |
+
attn_implementation="sdpa",
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
input_text = "What does it take to build a great LLM?"
|
| 104 |
+
messages = [{"role": "user", "content": input_text}]
|
| 105 |
+
input_ids = tokenizer.apply_chat_template(messages, return_dict=True, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 106 |
+
|
| 107 |
+
outputs = model.generate(**input_ids, max_new_tokens=200)
|
| 108 |
+
print(tokenizer.decode(outputs[0]))
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## DbrxConfig
|
| 112 |
+
|
| 113 |
+
[[autodoc]] DbrxConfig
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
## DbrxModel
|
| 117 |
+
|
| 118 |
+
[[autodoc]] DbrxModel
|
| 119 |
+
- forward
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
## DbrxForCausalLM
|
| 123 |
+
|
| 124 |
+
[[autodoc]] DbrxForCausalLM
|
| 125 |
+
- forward
|
| 126 |
+
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deberta-v2.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-06-05 and added to Hugging Face Transformers on 2021-02-19.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white" >
|
| 21 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# DeBERTa-v2
|
| 27 |
+
|
| 28 |
+
[DeBERTa-v2](https://huggingface.co/papers/2006.03654) improves on the original [DeBERTa](./deberta) architecture by using a SentencePiece-based tokenizer and a new vocabulary size of 128K. It also adds an additional convolutional layer within the first transformer layer to better learn local dependencies of input tokens. Finally, the position projection and content projection matrices are shared in the attention layer to reduce the number of parameters.
|
| 29 |
+
|
| 30 |
+
You can find all the original [DeBERTa-v2] checkpoints under the [Microsoft](https://huggingface.co/microsoft?search_models=deberta-v2) organization.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
> [!TIP]
|
| 34 |
+
> This model was contributed by [Pengcheng He](https://huggingface.co/DeBERTa).
|
| 35 |
+
>
|
| 36 |
+
> Click on the DeBERTa-v2 models in the right sidebar for more examples of how to apply DeBERTa-v2 to different language tasks.
|
| 37 |
+
|
| 38 |
+
The example below demonstrates how to classify text with [`Pipeline`] or the [`AutoModel`] class.
|
| 39 |
+
|
| 40 |
+
<hfoptions id="usage">
|
| 41 |
+
<hfoption id="Pipeline">
|
| 42 |
+
|
| 43 |
+
```py
|
| 44 |
+
import torch
|
| 45 |
+
from transformers import pipeline
|
| 46 |
+
|
| 47 |
+
pipeline = pipeline(
|
| 48 |
+
task="text-classification",
|
| 49 |
+
model="microsoft/deberta-v2-xlarge-mnli",
|
| 50 |
+
device=0,
|
| 51 |
+
torch_dtype=torch.float16
|
| 52 |
+
)
|
| 53 |
+
result = pipeline("DeBERTa-v2 is great at understanding context!")
|
| 54 |
+
print(result)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
</hfoption>
|
| 58 |
+
<hfoption id="AutoModel">
|
| 59 |
+
|
| 60 |
+
```py
|
| 61 |
+
import torch
|
| 62 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 63 |
+
|
| 64 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 65 |
+
"microsoft/deberta-v2-xlarge-mnli"
|
| 66 |
+
)
|
| 67 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 68 |
+
"microsoft/deberta-v2-xlarge-mnli",
|
| 69 |
+
torch_dtype=torch.float16,
|
| 70 |
+
device_map="auto"
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
inputs = tokenizer("DeBERTa-v2 is great at understanding context!", return_tensors="pt").to("cuda")
|
| 74 |
+
outputs = model(**inputs)
|
| 75 |
+
|
| 76 |
+
logits = outputs.logits
|
| 77 |
+
predicted_class_id = logits.argmax().item()
|
| 78 |
+
predicted_label = model.config.id2label[predicted_class_id]
|
| 79 |
+
print(f"Predicted label: {predicted_label}")
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
</hfoption>
|
| 84 |
+
|
| 85 |
+
<hfoption id="transformers CLI">
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
echo -e "DeBERTa-v2 is great at understanding context!" | transformers-cli run --task fill-mask --model microsoft/deberta-v2-xlarge-mnli --device 0
|
| 89 |
+
```
|
| 90 |
+
</hfoption>
|
| 91 |
+
</hfoptions>
|
| 92 |
+
|
| 93 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 94 |
+
|
| 95 |
+
The example below uses [bitsandbytes quantization](../quantization/bitsandbytes) to only quantize the weights to 4-bit.
|
| 96 |
+
|
| 97 |
+
```py
|
| 98 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, BitsAndBytesConfig
|
| 99 |
+
|
| 100 |
+
model_id = "microsoft/deberta-v2-xlarge-mnli"
|
| 101 |
+
quantization_config = BitsAndBytesConfig(
|
| 102 |
+
load_in_4bit=True,
|
| 103 |
+
bnb_4bit_quant_type="nf4",
|
| 104 |
+
bnb_4bit_compute_dtype="float16",
|
| 105 |
+
bnb_4bit_use_double_quant=True,
|
| 106 |
+
)
|
| 107 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 108 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 109 |
+
model_id,
|
| 110 |
+
quantization_config=quantization_config,
|
| 111 |
+
torch_dtype="float16"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
inputs = tokenizer("DeBERTa-v2 is great at understanding context!", return_tensors="pt").to("cuda")
|
| 115 |
+
outputs = model(**inputs)
|
| 116 |
+
logits = outputs.logits
|
| 117 |
+
predicted_class_id = logits.argmax().item()
|
| 118 |
+
predicted_label = model.config.id2label[predicted_class_id]
|
| 119 |
+
print(f"Predicted label: {predicted_label}")
|
| 120 |
+
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
## DebertaV2Config
|
| 125 |
+
|
| 126 |
+
[[autodoc]] DebertaV2Config
|
| 127 |
+
|
| 128 |
+
## DebertaV2Tokenizer
|
| 129 |
+
|
| 130 |
+
[[autodoc]] DebertaV2Tokenizer
|
| 131 |
+
- build_inputs_with_special_tokens
|
| 132 |
+
- get_special_tokens_mask
|
| 133 |
+
- create_token_type_ids_from_sequences
|
| 134 |
+
- save_vocabulary
|
| 135 |
+
|
| 136 |
+
## DebertaV2TokenizerFast
|
| 137 |
+
|
| 138 |
+
[[autodoc]] DebertaV2TokenizerFast
|
| 139 |
+
- build_inputs_with_special_tokens
|
| 140 |
+
- create_token_type_ids_from_sequences
|
| 141 |
+
|
| 142 |
+
<frameworkcontent>
|
| 143 |
+
<pt>
|
| 144 |
+
|
| 145 |
+
## DebertaV2Model
|
| 146 |
+
|
| 147 |
+
[[autodoc]] DebertaV2Model
|
| 148 |
+
- forward
|
| 149 |
+
|
| 150 |
+
## DebertaV2PreTrainedModel
|
| 151 |
+
|
| 152 |
+
[[autodoc]] DebertaV2PreTrainedModel
|
| 153 |
+
- forward
|
| 154 |
+
|
| 155 |
+
## DebertaV2ForMaskedLM
|
| 156 |
+
|
| 157 |
+
[[autodoc]] DebertaV2ForMaskedLM
|
| 158 |
+
- forward
|
| 159 |
+
|
| 160 |
+
## DebertaV2ForSequenceClassification
|
| 161 |
+
|
| 162 |
+
[[autodoc]] DebertaV2ForSequenceClassification
|
| 163 |
+
- forward
|
| 164 |
+
|
| 165 |
+
## DebertaV2ForTokenClassification
|
| 166 |
+
|
| 167 |
+
[[autodoc]] DebertaV2ForTokenClassification
|
| 168 |
+
- forward
|
| 169 |
+
|
| 170 |
+
## DebertaV2ForQuestionAnswering
|
| 171 |
+
|
| 172 |
+
[[autodoc]] DebertaV2ForQuestionAnswering
|
| 173 |
+
- forward
|
| 174 |
+
|
| 175 |
+
## DebertaV2ForMultipleChoice
|
| 176 |
+
|
| 177 |
+
[[autodoc]] DebertaV2ForMultipleChoice
|
| 178 |
+
- forward
|
| 179 |
+
|
| 180 |
+
</pt>
|
| 181 |
+
<tf>
|
| 182 |
+
|
| 183 |
+
## TFDebertaV2Model
|
| 184 |
+
|
| 185 |
+
[[autodoc]] TFDebertaV2Model
|
| 186 |
+
- call
|
| 187 |
+
|
| 188 |
+
## TFDebertaV2PreTrainedModel
|
| 189 |
+
|
| 190 |
+
[[autodoc]] TFDebertaV2PreTrainedModel
|
| 191 |
+
- call
|
| 192 |
+
|
| 193 |
+
## TFDebertaV2ForMaskedLM
|
| 194 |
+
|
| 195 |
+
[[autodoc]] TFDebertaV2ForMaskedLM
|
| 196 |
+
- call
|
| 197 |
+
|
| 198 |
+
## TFDebertaV2ForSequenceClassification
|
| 199 |
+
|
| 200 |
+
[[autodoc]] TFDebertaV2ForSequenceClassification
|
| 201 |
+
- call
|
| 202 |
+
|
| 203 |
+
## TFDebertaV2ForTokenClassification
|
| 204 |
+
|
| 205 |
+
[[autodoc]] TFDebertaV2ForTokenClassification
|
| 206 |
+
- call
|
| 207 |
+
|
| 208 |
+
## TFDebertaV2ForQuestionAnswering
|
| 209 |
+
|
| 210 |
+
[[autodoc]] TFDebertaV2ForQuestionAnswering
|
| 211 |
+
- call
|
| 212 |
+
|
| 213 |
+
## TFDebertaV2ForMultipleChoice
|
| 214 |
+
|
| 215 |
+
[[autodoc]] TFDebertaV2ForMultipleChoice
|
| 216 |
+
- call
|
| 217 |
+
|
| 218 |
+
</tf>
|
| 219 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-06-05 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
# DeBERTa
|
| 27 |
+
|
| 28 |
+
[DeBERTa](https://huggingface.co/papers/2006.03654) improves the pretraining efficiency of BERT and RoBERTa with two key ideas, disentangled attention and an enhanced mask decoder. Instead of mixing everything together like BERT, DeBERTa separates a word's *content* from its *position* and processes them independently. This gives it a clearer sense of what's being said and where in the sentence it's happening.
|
| 29 |
+
|
| 30 |
+
The enhanced mask decoder replaces the traditional softmax decoder to make better predictions.
|
| 31 |
+
|
| 32 |
+
Even with less training data than RoBERTa, DeBERTa manages to outperform it on several benchmarks.
|
| 33 |
+
|
| 34 |
+
You can find all the original DeBERTa checkpoints under the [Microsoft](https://huggingface.co/microsoft?search_models=deberta) organization.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
> [!TIP]
|
| 38 |
+
> Click on the DeBERTa models in the right sidebar for more examples of how to apply DeBERTa to different language tasks.
|
| 39 |
+
|
| 40 |
+
The example below demonstrates how to classify text with [`Pipeline`], [`AutoModel`], and from the command line.
|
| 41 |
+
|
| 42 |
+
<hfoptions id="usage">
|
| 43 |
+
<hfoption id="Pipeline">
|
| 44 |
+
|
| 45 |
+
```py
|
| 46 |
+
import torch
|
| 47 |
+
from transformers import pipeline
|
| 48 |
+
|
| 49 |
+
classifier = pipeline(
|
| 50 |
+
task="text-classification",
|
| 51 |
+
model="microsoft/deberta-base-mnli",
|
| 52 |
+
device=0,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
classifier({
|
| 56 |
+
"text": "A soccer game with multiple people playing.",
|
| 57 |
+
"text_pair": "Some people are playing a sport."
|
| 58 |
+
})
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
</hfoption>
|
| 62 |
+
<hfoption id="AutoModel">
|
| 63 |
+
|
| 64 |
+
```py
|
| 65 |
+
import torch
|
| 66 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 67 |
+
|
| 68 |
+
model_name = "microsoft/deberta-base-mnli"
|
| 69 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/deberta-base-mnli")
|
| 70 |
+
model = AutoModelForSequenceClassification.from_pretrained("microsoft/deberta-base-mnli", device_map="auto")
|
| 71 |
+
|
| 72 |
+
inputs = tokenizer(
|
| 73 |
+
"A soccer game with multiple people playing.",
|
| 74 |
+
"Some people are playing a sport.",
|
| 75 |
+
return_tensors="pt"
|
| 76 |
+
).to("cuda")
|
| 77 |
+
|
| 78 |
+
with torch.no_grad():
|
| 79 |
+
logits = model(**inputs).logits
|
| 80 |
+
predicted_class = logits.argmax().item()
|
| 81 |
+
|
| 82 |
+
labels = ["contradiction", "neutral", "entailment"]
|
| 83 |
+
print(f"The predicted relation is: {labels[predicted_class]}")
|
| 84 |
+
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
</hfoption>
|
| 88 |
+
<hfoption id="transformers CLI">
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
echo -e '{"text": "A soccer game with multiple people playing.", "text_pair": "Some people are playing a sport."}' | transformers run --task text-classification --model microsoft/deberta-base-mnli --device 0
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
</hfoption>
|
| 95 |
+
</hfoptions>
|
| 96 |
+
|
| 97 |
+
## Notes
|
| 98 |
+
- DeBERTa uses **relative position embeddings**, so it does not require **right-padding** like BERT.
|
| 99 |
+
- For best results, use DeBERTa on sentence-level or sentence-pair classification tasks like MNLI, RTE, or SST-2.
|
| 100 |
+
- If you're using DeBERTa for token-level tasks like masked language modeling, make sure to load a checkpoint specifically pretrained or fine-tuned for token-level tasks.
|
| 101 |
+
|
| 102 |
+
## DebertaConfig
|
| 103 |
+
|
| 104 |
+
[[autodoc]] DebertaConfig
|
| 105 |
+
|
| 106 |
+
## DebertaTokenizer
|
| 107 |
+
|
| 108 |
+
[[autodoc]] DebertaTokenizer
|
| 109 |
+
- build_inputs_with_special_tokens
|
| 110 |
+
- get_special_tokens_mask
|
| 111 |
+
- create_token_type_ids_from_sequences
|
| 112 |
+
- save_vocabulary
|
| 113 |
+
|
| 114 |
+
## DebertaTokenizerFast
|
| 115 |
+
|
| 116 |
+
[[autodoc]] DebertaTokenizerFast
|
| 117 |
+
- build_inputs_with_special_tokens
|
| 118 |
+
- create_token_type_ids_from_sequences
|
| 119 |
+
|
| 120 |
+
<frameworkcontent>
|
| 121 |
+
<pt>
|
| 122 |
+
|
| 123 |
+
## DebertaModel
|
| 124 |
+
|
| 125 |
+
[[autodoc]] DebertaModel
|
| 126 |
+
- forward
|
| 127 |
+
|
| 128 |
+
## DebertaPreTrainedModel
|
| 129 |
+
|
| 130 |
+
[[autodoc]] DebertaPreTrainedModel
|
| 131 |
+
|
| 132 |
+
## DebertaForMaskedLM
|
| 133 |
+
|
| 134 |
+
[[autodoc]] DebertaForMaskedLM
|
| 135 |
+
- forward
|
| 136 |
+
|
| 137 |
+
## DebertaForSequenceClassification
|
| 138 |
+
|
| 139 |
+
[[autodoc]] DebertaForSequenceClassification
|
| 140 |
+
- forward
|
| 141 |
+
|
| 142 |
+
## DebertaForTokenClassification
|
| 143 |
+
|
| 144 |
+
[[autodoc]] DebertaForTokenClassification
|
| 145 |
+
- forward
|
| 146 |
+
|
| 147 |
+
## DebertaForQuestionAnswering
|
| 148 |
+
|
| 149 |
+
[[autodoc]] DebertaForQuestionAnswering
|
| 150 |
+
- forward
|
| 151 |
+
|
| 152 |
+
</pt>
|
| 153 |
+
<tf>
|
| 154 |
+
|
| 155 |
+
## TFDebertaModel
|
| 156 |
+
|
| 157 |
+
[[autodoc]] TFDebertaModel
|
| 158 |
+
- call
|
| 159 |
+
|
| 160 |
+
## TFDebertaPreTrainedModel
|
| 161 |
+
|
| 162 |
+
[[autodoc]] TFDebertaPreTrainedModel
|
| 163 |
+
- call
|
| 164 |
+
|
| 165 |
+
## TFDebertaForMaskedLM
|
| 166 |
+
|
| 167 |
+
[[autodoc]] TFDebertaForMaskedLM
|
| 168 |
+
- call
|
| 169 |
+
|
| 170 |
+
## TFDebertaForSequenceClassification
|
| 171 |
+
|
| 172 |
+
[[autodoc]] TFDebertaForSequenceClassification
|
| 173 |
+
- call
|
| 174 |
+
|
| 175 |
+
## TFDebertaForTokenClassification
|
| 176 |
+
|
| 177 |
+
[[autodoc]] TFDebertaForTokenClassification
|
| 178 |
+
- call
|
| 179 |
+
|
| 180 |
+
## TFDebertaForQuestionAnswering
|
| 181 |
+
|
| 182 |
+
[[autodoc]] TFDebertaForQuestionAnswering
|
| 183 |
+
- call
|
| 184 |
+
|
| 185 |
+
</tf>
|
| 186 |
+
</frameworkcontent>
|
| 187 |
+
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/decision_transformer.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2021-06-02 and added to Hugging Face Transformers on 2022-03-23.*
|
| 17 |
+
|
| 18 |
+
# Decision Transformer
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
The Decision Transformer model was proposed in [Decision Transformer: Reinforcement Learning via Sequence Modeling](https://huggingface.co/papers/2106.01345)
|
| 27 |
+
by Lili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee, Aditya Grover, Michael Laskin, Pieter Abbeel, Aravind Srinivas, Igor Mordatch.
|
| 28 |
+
|
| 29 |
+
The abstract from the paper is the following:
|
| 30 |
+
|
| 31 |
+
*We introduce a framework that abstracts Reinforcement Learning (RL) as a sequence modeling problem.
|
| 32 |
+
This allows us to draw upon the simplicity and scalability of the Transformer architecture, and associated advances
|
| 33 |
+
in language modeling such as GPT-x and BERT. In particular, we present Decision Transformer, an architecture that
|
| 34 |
+
casts the problem of RL as conditional sequence modeling. Unlike prior approaches to RL that fit value functions or
|
| 35 |
+
compute policy gradients, Decision Transformer simply outputs the optimal actions by leveraging a causally masked
|
| 36 |
+
Transformer. By conditioning an autoregressive model on the desired return (reward), past states, and actions, our
|
| 37 |
+
Decision Transformer model can generate future actions that achieve the desired return. Despite its simplicity,
|
| 38 |
+
Decision Transformer matches or exceeds the performance of state-of-the-art model-free offline RL baselines on
|
| 39 |
+
Atari, OpenAI Gym, and Key-to-Door tasks.*
|
| 40 |
+
|
| 41 |
+
This version of the model is for tasks where the state is a vector.
|
| 42 |
+
|
| 43 |
+
This model was contributed by [edbeeching](https://huggingface.co/edbeeching). The original code can be found [here](https://github.com/kzl/decision-transformer).
|
| 44 |
+
|
| 45 |
+
## DecisionTransformerConfig
|
| 46 |
+
|
| 47 |
+
[[autodoc]] DecisionTransformerConfig
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
## DecisionTransformerGPT2Model
|
| 51 |
+
|
| 52 |
+
[[autodoc]] DecisionTransformerGPT2Model
|
| 53 |
+
- forward
|
| 54 |
+
|
| 55 |
+
## DecisionTransformerModel
|
| 56 |
+
|
| 57 |
+
[[autodoc]] DecisionTransformerModel
|
| 58 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_v2.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-05-07 and added to Hugging Face Transformers on 2025-07-09.*
|
| 17 |
+
|
| 18 |
+
# DeepSeek-V2
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
The DeepSeek-V2 model was proposed in [DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model](https://huggingface.co/papers/2405.04434) by DeepSeek-AI Team.
|
| 23 |
+
|
| 24 |
+
The abstract from the paper is the following:
|
| 25 |
+
We present DeepSeek-V2, a strong Mixture-of-Experts (MoE) language model characterized by economical training and efficient inference. It comprises 236B total parameters, of which 21B are activated for each token, and supports a context length of 128K tokens. DeepSeek-V2 adopts innovative architectures including Multi-head Latent Attention (MLA) and DeepSeekMoE. MLA guarantees efficient inference through significantly compressing the Key-Value (KV) cache into a latent vector, while DeepSeekMoE enables training strong models at an economical cost through sparse computation. Compared with DeepSeek 67B, DeepSeek-V2 achieves significantly stronger performance, and meanwhile saves 42.5% of training costs, reduces the KV cache by 93.3%, and boosts the maximum generation throughput to 5.76 times. We pretrain DeepSeek-V2 on a high-quality and multi-source corpus consisting of 8.1T tokens, and further perform Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) to fully unlock its potential. Evaluation results show that, even with only 21B activated parameters, DeepSeek-V2 and its chat versions still achieve top-tier performance among open-source models.
|
| 26 |
+
|
| 27 |
+
This model was contributed by [VladOS95-cyber](https://github.com/VladOS95-cyber).
|
| 28 |
+
The original code can be found [here](https://huggingface.co/deepseek-ai/DeepSeek-V2).
|
| 29 |
+
|
| 30 |
+
### Usage tips
|
| 31 |
+
The model uses Multi-head Latent Attention (MLA) and DeepSeekMoE architectures for efficient inference and cost-effective training. It employs an auxiliary-loss-free strategy for load balancing and multi-token prediction training objective. The model can be used for various language tasks after being pre-trained on 14.8 trillion tokens and going through Supervised Fine-Tuning and Reinforcement Learning stages.
|
| 32 |
+
|
| 33 |
+
## DeepseekV2Config
|
| 34 |
+
|
| 35 |
+
[[autodoc]] DeepseekV2Config
|
| 36 |
+
|
| 37 |
+
## DeepseekV2Model
|
| 38 |
+
|
| 39 |
+
[[autodoc]] DeepseekV2Model
|
| 40 |
+
- forward
|
| 41 |
+
|
| 42 |
+
## DeepseekV2ForCausalLM
|
| 43 |
+
|
| 44 |
+
[[autodoc]] DeepseekV2ForCausalLM
|
| 45 |
+
- forward
|
| 46 |
+
|
| 47 |
+
## DeepseekV2ForSequenceClassification
|
| 48 |
+
|
| 49 |
+
[[autodoc]] DeepseekV2ForSequenceClassification
|
| 50 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_v3.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-12-27 and added to Hugging Face Transformers on 2025-03-28.*
|
| 17 |
+
|
| 18 |
+
# DeepSeek-V3
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
The DeepSeek-V3 model was proposed in [DeepSeek-V3 Technical Report](https://huggingface.co/papers/2412.19437) by DeepSeek-AI Team.
|
| 23 |
+
|
| 24 |
+
The abstract from the paper is the following:
|
| 25 |
+
We present DeepSeek-V3, a strong Mixture-of-Experts (MoE) language model with 671B total parameters with 37B activated for each token. To achieve efficient inference and cost-effective training, DeepSeek-V3 adopts Multi-head Latent Attention (MLA) and DeepSeekMoE architectures, which were thoroughly validated in DeepSeek-V2. Furthermore, DeepSeek-V3 pioneers an auxiliary-loss-free strategy for load balancing and sets a multi-token prediction training objective for stronger performance. We pre-train DeepSeek-V3 on 14.8 trillion diverse and high-quality tokens, followed by Supervised Fine-Tuning and Reinforcement Learning stages to fully harness its capabilities. Comprehensive evaluations reveal that DeepSeek-V3 outperforms other open-source models and achieves performance comparable to leading closed-source models. Despite its excellent performance, DeepSeek-V3 requires only 2.788M H800 GPU hours for its full training. In addition, its training process is remarkably stable. Throughout the entire training process, we did not experience any irrecoverable loss spikes or perform any rollbacks. The model checkpoints are available at https://github.com/deepseek-ai/DeepSeek-V3.
|
| 26 |
+
|
| 27 |
+
## Limitations and call for contribution!
|
| 28 |
+
|
| 29 |
+
We are super happy to make this code community-powered, and would love to see how you can best optimize the following:
|
| 30 |
+
|
| 31 |
+
- current implementation uses the "naive" attention compution (so not really MLA)
|
| 32 |
+
- current implementation loops through the experts. This should be replaced. Pointers to use `get_packed_weights` from `integrations/tensor_parallel`.
|
| 33 |
+
- current implementation uses the eleuther formula for ROPE, using the original one would be more efficient! (should still follow our API)
|
| 34 |
+
- static cache is not supported (this should be just a generation config issue / config shape issues)
|
| 35 |
+
|
| 36 |
+
### Usage tips
|
| 37 |
+
The model uses Multi-head Latent Attention (MLA) and DeepSeekMoE architectures for efficient inference and cost-effective training. It employs an auxiliary-loss-free strategy for load balancing and multi-token prediction training objective. The model can be used for various language tasks after being pre-trained on 14.8 trillion tokens and going through Supervised Fine-Tuning and Reinforcement Learning stages.
|
| 38 |
+
|
| 39 |
+
You can run the model in `FP8` automatically, using 2 nodes of 8 H100 should be more than enough!
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
# `run_deepseek_v1.py`
|
| 43 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 44 |
+
import torch
|
| 45 |
+
torch.manual_seed(30)
|
| 46 |
+
|
| 47 |
+
tokenizer = AutoTokenizer.from_pretrained("deepseek-r1")
|
| 48 |
+
|
| 49 |
+
chat = [
|
| 50 |
+
{"role": "user", "content": "Hello, how are you?"},
|
| 51 |
+
{"role": "assistant", "content": "I'm doing great. How can I help you today?"},
|
| 52 |
+
{"role": "user", "content": "I'd like to show off how chat templating works!"},
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
model = AutoModelForCausalLM.from_pretrained("deepseek-r1", device_map="auto", torch_dtype=torch.bfloat16)
|
| 57 |
+
inputs = tokenizer.apply_chat_template(chat, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 58 |
+
import time
|
| 59 |
+
start = time.time()
|
| 60 |
+
outputs = model.generate(inputs, max_new_tokens=50)
|
| 61 |
+
print(tokenizer.batch_decode(outputs))
|
| 62 |
+
print(time.time()-start)
|
| 63 |
+
```
|
| 64 |
+
This generated:
|
| 65 |
+
|
| 66 |
+
``````
|
| 67 |
+
<|Assistant|><think>
|
| 68 |
+
Okay, the user wants to demonstrate how chat templating works. Let me break down what that means. Chat templating is about structuring the conversation data, especially for models that need specific input formats. Maybe they're referring to something like how messages are formatted with roles (user, assistant, system) in APIs like OpenAI.
|
| 69 |
+
|
| 70 |
+
First, I should explain what chat templating is. It's the process of formatting conversation data into a structured format that the model can understand. This usually includes roles and content. For example, user messages, assistant responses, and system messages each have their own role tags.
|
| 71 |
+
|
| 72 |
+
They might want an example. Let me think of a simple conversation. The user says "Hello, how are you?" and the assistant responds "I'm doing great. How can I help you today?" Then the user follows up with wanting to show off chat templating. So the example should include the history and the new message.
|
| 73 |
+
|
| 74 |
+
In some frameworks, like Hugging Face's Transformers, chat templates are applied using Jinja2 templates. The template might look something like combining system messages, then looping through user and assistant messages with appropriate tags. For instance, using {% for message in messages %} and assigning roles like <|user|>, <|assistant|>, etc.
|
| 75 |
+
|
| 76 |
+
I should structure the example with the messages array, showing each role and content. Then apply a hypothetical template to convert that into a formatted string the model uses. Also, mention that different models have different templating requirements, like using special tokens or varying role labels.
|
| 77 |
+
|
| 78 |
+
Wait, the user mentioned "chat templating" in the context of showing off. Maybe they want a practical example they can present. So providing a code snippet or a structured data example would be helpful. Let me outline a typical messages array and then the templated output.
|
| 79 |
+
|
| 80 |
+
Also, it's important to note that proper templating ensures the model knows the conversation flow, which is crucial for generating coherent responses. Maybe include a note about why it's important, like maintaining context and role-specific processing.
|
| 81 |
+
|
| 82 |
+
Let me check if there are any common mistakes or things to avoid. For example, not closing tags properly, or mismatching roles. But maybe that's too detailed unless the user asks. Focus on the positive example first.
|
| 83 |
+
|
| 84 |
+
Putting it all together, the response should have an example messages array, the applied template, and the final formatted string. Maybe use angle brackets or special tokens as placeholders. Also, mention that this helps in training or fine-tuning models with structured data.
|
| 85 |
+
|
| 86 |
+
I think that's a solid approach. Let me structure it step by step to make it clear.
|
| 87 |
+
</think>
|
| 88 |
+
|
| 89 |
+
Chat templating is a way to structure conversation data (e.g., user/assistant interactions) into a format that language models understand. This is especially important for models trained to handle multi-turn dialogues, where the input must explicitly separate roles (user, assistant, system, etc.) and messages. Let’s break this down with an example!
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
### **Step 1: Raw Conversation History**
|
| 94 |
+
Suppose we have this conversation:
|
| 95 |
+
- **User**: "Hello, how are you?"
|
| 96 |
+
- **Assistant**: "I'm doing great. How can I help you today?"
|
| 97 |
+
- **User**: "I'd like to show off how chat templating works!"
|
| 98 |
+
|
| 99 |
+
---
|
| 100 |
+
|
| 101 |
+
### **Step 2: Structured Messages**
|
| 102 |
+
In frameworks like Hugging Face Transformers or OpenAI, conversations are often formatted as a list of dictionaries with `role` and `content`:
|
| 103 |
+
```python
|
| 104 |
+
messages = [
|
| 105 |
+
{"role": "user", "content": "Hello, how are you?"},
|
| 106 |
+
{"role": "assistant", "content": "I'm doing great. How can I help you today?"},
|
| 107 |
+
{"role": "user", "content": "I'd like to show off how chat templating works!"},
|
| 108 |
+
]
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
### **Step 3: Apply a Chat Template**
|
| 114 |
+
A **chat template** converts this structured data into a single string formatted for the model. For example, using a Jinja-style template (common in Hugging Face):
|
| 115 |
+
|
| 116 |
+
```jinja
|
| 117 |
+
{% for message in messages %}
|
| 118 |
+
{% if message['role'] == 'user' %}
|
| 119 |
+
<|user|>{{ message['content'] }}<|end|>
|
| 120 |
+
{% elif message['role'] == 'assistant' %}
|
| 121 |
+
<|assistant|>{{ message['content'] }}<|end|>
|
| 122 |
+
{% endif %}
|
| 123 |
+
{% endfor %}
|
| 124 |
+
<|assistant|>
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
### **Step 4: Final Templated Output**
|
| 130 |
+
Applying the template to our `messages` list would produce:
|
| 131 |
+
```text
|
| 132 |
+
<|user|>Hello, how are you?<|end|>
|
| 133 |
+
<|assistant|>I'm doing great. How can I help you today?<|end|>
|
| 134 |
+
<|user|>I'd like to show off how chat templating works!<|end|>
|
| 135 |
+
<|assistant|>
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
This tells the model:
|
| 139 |
+
1. The conversation history (user/assistant turns).
|
| 140 |
+
2. The model’s turn to generate a response (`<|assistant|>` at the end).
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
### **Key Notes**:
|
| 145 |
+
- **Role Separation**: Tags like `<|user|>` and `<|assistant|>` help the model distinguish speakers.
|
| 146 |
+
- **Special Tokens**: Models often use unique tokens (e.g., `<|end|>`) to mark message boundaries.
|
| 147 |
+
- **Flexibility**: Templates vary by model (e.g., OpenAI uses `{"role": "user", "content": "..."}` instead of tags).
|
| 148 |
+
|
| 149 |
+
---
|
| 150 |
+
|
| 151 |
+
### **Why This Matters**:
|
| 152 |
+
- **Consistency**: Ensures the model understands dialogue structure.
|
| 153 |
+
- **Context Preservation**: Maintains the flow of multi-turn conversations.
|
| 154 |
+
- **Alignment**: Matches the format the model was trained on for better performance.
|
| 155 |
+
|
| 156 |
+
Want to dive deeper or see a specific framework’s implementation (e.g., OpenAI, Llama, Mistral)? Let me know! 😊<|end▁of▁sentence|>
|
| 157 |
+
``````
|
| 158 |
+
|
| 159 |
+
Use the following to run it
|
| 160 |
+
```bash
|
| 161 |
+
torchrun --nproc_per_node=8 --nnodes=2 --node_rank=0|1 --rdzv-id an_id --rdzv-backend c10d --rdzv-endpoint master_addr:master_port run_deepseek_r1.py
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
If you have:
|
| 165 |
+
```bash
|
| 166 |
+
[rank0]: ncclInternalError: Internal check failed.
|
| 167 |
+
[rank0]: Last error:
|
| 168 |
+
[rank0]: Bootstrap : no socket interface found
|
| 169 |
+
```
|
| 170 |
+
error, it means NCCL was probably not loaded.
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
## DeepseekV3Config
|
| 174 |
+
|
| 175 |
+
[[autodoc]] DeepseekV3Config
|
| 176 |
+
|
| 177 |
+
## DeepseekV3Model
|
| 178 |
+
|
| 179 |
+
[[autodoc]] DeepseekV3Model
|
| 180 |
+
- forward
|
| 181 |
+
|
| 182 |
+
## DeepseekV3ForCausalLM
|
| 183 |
+
|
| 184 |
+
[[autodoc]] DeepseekV3ForCausalLM
|
| 185 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deepseek_vl.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 Deepseek AI and The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-03-08 and added to Hugging Face Transformers on 2025-07-25.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 22 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
# DeepseekVL
|
| 27 |
+
|
| 28 |
+
[Deepseek-VL](https://huggingface.co/papers/2403.05525) was introduced by the DeepSeek AI team. It is a vision-language model (VLM) designed to process both text and images for generating contextually relevant responses. The model leverages [LLaMA](./llama) as its text encoder, while [SigLip](./siglip) is used for encoding images.
|
| 29 |
+
|
| 30 |
+
You can find all the original Deepseek-VL checkpoints under the [DeepSeek-community](https://huggingface.co/deepseek-community) organization.
|
| 31 |
+
|
| 32 |
+
> [!TIP]
|
| 33 |
+
> Click on the Deepseek-VL models in the right sidebar for more examples of how to apply Deepseek-VL to different vision and language tasks.
|
| 34 |
+
|
| 35 |
+
The example below demonstrates how to generate text based on an image with [`Pipeline`] or the [`AutoModel`] class.
|
| 36 |
+
|
| 37 |
+
<hfoptions id="usage">
|
| 38 |
+
<hfoption id="Pipeline">
|
| 39 |
+
|
| 40 |
+
```py
|
| 41 |
+
import torch
|
| 42 |
+
from transformers import pipeline
|
| 43 |
+
|
| 44 |
+
pipe = pipeline(
|
| 45 |
+
task="image-text-to-text",
|
| 46 |
+
model="deepseek-community/deepseek-vl-1.3b-chat",
|
| 47 |
+
device=0,
|
| 48 |
+
torch_dtype=torch.float16
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
messages = [
|
| 52 |
+
{
|
| 53 |
+
"role": "user",
|
| 54 |
+
"content": [
|
| 55 |
+
{
|
| 56 |
+
"type": "image",
|
| 57 |
+
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg",
|
| 58 |
+
},
|
| 59 |
+
{ "type": "text", "text": "Describe this image."},
|
| 60 |
+
]
|
| 61 |
+
}
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
pipe(text=messages, max_new_tokens=20, return_full_text=False)
|
| 65 |
+
```
|
| 66 |
+
</hfoption>
|
| 67 |
+
|
| 68 |
+
<hfoption id="AutoModel">
|
| 69 |
+
|
| 70 |
+
```py
|
| 71 |
+
import torch
|
| 72 |
+
from transformers import DeepseekVLForConditionalGeneration, AutoProcessor
|
| 73 |
+
|
| 74 |
+
model = DeepseekVLForConditionalGeneration.from_pretrained(
|
| 75 |
+
"deepseek-community/deepseek-vl-1.3b-chat",
|
| 76 |
+
torch_dtype=torch.float16,
|
| 77 |
+
device_map="auto",
|
| 78 |
+
attn_implementation="sdpa"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
processor = AutoProcessor.from_pretrained("deepseek-community/deepseek-vl-1.3b-chat")
|
| 82 |
+
|
| 83 |
+
messages = [
|
| 84 |
+
{
|
| 85 |
+
"role":"user",
|
| 86 |
+
"content":[
|
| 87 |
+
{
|
| 88 |
+
"type":"image",
|
| 89 |
+
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"type":"text",
|
| 93 |
+
"text":"Describe this image."
|
| 94 |
+
}
|
| 95 |
+
]
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
inputs = processor.apply_chat_template(
|
| 101 |
+
messages,
|
| 102 |
+
add_generation_prompt=True,
|
| 103 |
+
tokenize=True,
|
| 104 |
+
return_dict=True,
|
| 105 |
+
return_tensors="pt"
|
| 106 |
+
).to(model.device, dtype=model.dtype)
|
| 107 |
+
|
| 108 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 109 |
+
generated_ids_trimmed = [
|
| 110 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 111 |
+
]
|
| 112 |
+
output_text = processor.batch_decode(
|
| 113 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
print(output_text)
|
| 117 |
+
```
|
| 118 |
+
</hfoption>
|
| 119 |
+
</hfoptions>
|
| 120 |
+
|
| 121 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 122 |
+
|
| 123 |
+
The example below uses [torchao](../quantization/torchao) to only quantize the weights to int4.
|
| 124 |
+
|
| 125 |
+
```python
|
| 126 |
+
import torch
|
| 127 |
+
from transformers import TorchAoConfig, DeepseekVLForConditionalGeneration, AutoProcessor
|
| 128 |
+
|
| 129 |
+
quantization_config = TorchAoConfig(
|
| 130 |
+
"int4_weight_only",
|
| 131 |
+
group_size=128
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
model = DeepseekVLForConditionalGeneration.from_pretrained(
|
| 135 |
+
"deepseek-community/deepseek-vl-1.3b-chat",
|
| 136 |
+
torch_dtype=torch.bfloat16,
|
| 137 |
+
device_map="auto",
|
| 138 |
+
quantization_config=quantization_config
|
| 139 |
+
)
|
| 140 |
+
```
|
| 141 |
+
### Notes
|
| 142 |
+
|
| 143 |
+
- Do inference with multiple images in a single conversation.
|
| 144 |
+
```py
|
| 145 |
+
import torch
|
| 146 |
+
from transformers import DeepseekVLForConditionalGeneration, AutoProcessor
|
| 147 |
+
|
| 148 |
+
model = DeepseekVLForConditionalGeneration.from_pretrained(
|
| 149 |
+
"deepseek-community/deepseek-vl-1.3b-chat",
|
| 150 |
+
torch_dtype=torch.float16,
|
| 151 |
+
device_map="auto",
|
| 152 |
+
attn_implementation="sdpa"
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
processor = AutoProcessor.from_pretrained("deepseek-community/deepseek-vl-1.3b-chat")
|
| 156 |
+
|
| 157 |
+
messages = [
|
| 158 |
+
[
|
| 159 |
+
{
|
| 160 |
+
"role": "user",
|
| 161 |
+
"content": [
|
| 162 |
+
{"type": "text", "text": "What’s the difference between"},
|
| 163 |
+
{"type": "image", "url": "http://images.cocodataset.org/val2017/000000039769.jpg"},
|
| 164 |
+
{"type": "text", "text": " and "},
|
| 165 |
+
{"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
|
| 166 |
+
]
|
| 167 |
+
}
|
| 168 |
+
],
|
| 169 |
+
[
|
| 170 |
+
{
|
| 171 |
+
"role": "user",
|
| 172 |
+
"content": [
|
| 173 |
+
{"type": "image", "url": "https://huggingface.co/microsoft/kosmos-2-patch14-224/resolve/main/snowman.jpg"},
|
| 174 |
+
{"type": "text", "text": "What do you see in this image?"}
|
| 175 |
+
]
|
| 176 |
+
}
|
| 177 |
+
]
|
| 178 |
+
]
|
| 179 |
+
|
| 180 |
+
inputs = processor.apply_chat_template(
|
| 181 |
+
messages,
|
| 182 |
+
add_generation_prompt=True,
|
| 183 |
+
padding=True,
|
| 184 |
+
truncation=True,
|
| 185 |
+
tokenize=True,
|
| 186 |
+
return_dict=True,
|
| 187 |
+
return_tensors="pt"
|
| 188 |
+
).to(model.device, dtype=model.dtype)
|
| 189 |
+
|
| 190 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 191 |
+
generated_ids_trimmed = [
|
| 192 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 193 |
+
]
|
| 194 |
+
output_text = processor.batch_decode(
|
| 195 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
print(output_text)
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
## DeepseekVLConfig
|
| 202 |
+
|
| 203 |
+
[[autodoc]] DeepseekVLConfig
|
| 204 |
+
|
| 205 |
+
## DeepseekVLProcessor
|
| 206 |
+
|
| 207 |
+
[[autodoc]] DeepseekVLProcessor
|
| 208 |
+
|
| 209 |
+
## DeepseekVLImageProcessor
|
| 210 |
+
|
| 211 |
+
[[autodoc]] DeepseekVLImageProcessor
|
| 212 |
+
|
| 213 |
+
## DeepseekVLImageProcessorFast
|
| 214 |
+
|
| 215 |
+
[[autodoc]] DeepseekVLImageProcessorFast
|
| 216 |
+
|
| 217 |
+
## DeepseekVLModel
|
| 218 |
+
|
| 219 |
+
[[autodoc]] DeepseekVLModel
|
| 220 |
+
- forward
|
| 221 |
+
|
| 222 |
+
## DeepseekVLForConditionalGeneration
|
| 223 |
+
|
| 224 |
+
[[autodoc]] DeepseekVLForConditionalGeneration
|
| 225 |
+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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 Deepseek AI and The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-03-08 and added to Hugging Face Transformers on 2025-07-25.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
# DeepseekVLHybrid
|
| 26 |
+
|
| 27 |
+
[Deepseek-VL-Hybrid](https://huggingface.co/papers/2403.05525) was introduced by the DeepSeek AI team. It is a vision-language model (VLM) designed to process both text and images for generating contextually relevant responses. The model leverages [LLaMA](./llama) as its text encoder, while [SigLip](./siglip) is used for encoding low-resolution images and [SAM (Segment Anything Model)](./sam) is incorporated to handle high-resolution image encoding, enhancing the model’s ability to process fine-grained visual details. Deepseek-VL-Hybrid is a variant of Deepseek-VL that uses [SAM (Segment Anything Model)](./sam) to handle high-resolution image encoding.
|
| 28 |
+
|
| 29 |
+
You can find all the original Deepseek-VL-Hybrid checkpoints under the [DeepSeek-community](https://huggingface.co/deepseek-community) organization.
|
| 30 |
+
|
| 31 |
+
> [!TIP]
|
| 32 |
+
> Click on the Deepseek-VL-Hybrid models in the right sidebar for more examples of how to apply Deepseek-VL-Hybrid to different vision and language tasks.
|
| 33 |
+
|
| 34 |
+
The example below demonstrates how to generate text based on an image with [`Pipeline`] or the [`AutoModel`] class.
|
| 35 |
+
|
| 36 |
+
<hfoptions id="usage">
|
| 37 |
+
<hfoption id="Pipeline">
|
| 38 |
+
|
| 39 |
+
```py
|
| 40 |
+
import torch
|
| 41 |
+
from transformers import pipeline
|
| 42 |
+
|
| 43 |
+
pipe = pipeline(
|
| 44 |
+
task="image-text-to-text",
|
| 45 |
+
model="deepseek-community/deepseek-vl-7b-chat",
|
| 46 |
+
device=0,
|
| 47 |
+
torch_dtype=torch.float16
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
messages = [
|
| 51 |
+
{
|
| 52 |
+
"role": "user",
|
| 53 |
+
"content": [
|
| 54 |
+
{
|
| 55 |
+
"type": "image",
|
| 56 |
+
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg",
|
| 57 |
+
},
|
| 58 |
+
{ "type": "text", "text": "Describe this image."},
|
| 59 |
+
]
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
pipe(text=messages, max_new_tokens=20, return_full_text=False)
|
| 64 |
+
```
|
| 65 |
+
</hfoption>
|
| 66 |
+
|
| 67 |
+
<hfoption id="AutoModel">
|
| 68 |
+
|
| 69 |
+
```py
|
| 70 |
+
import torch
|
| 71 |
+
from transformers import DeepseekVLHybridForConditionalGeneration, AutoProcessor
|
| 72 |
+
|
| 73 |
+
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
|
| 74 |
+
"deepseek-community/deepseek-vl-7b-chat",
|
| 75 |
+
torch_dtype=torch.float16,
|
| 76 |
+
device_map="auto",
|
| 77 |
+
attn_implementation="sdpa"
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
processor = AutoProcessor.from_pretrained("deepseek-community/deepseek-vl-7b-chat")
|
| 81 |
+
|
| 82 |
+
messages = [
|
| 83 |
+
{
|
| 84 |
+
"role":"user",
|
| 85 |
+
"content":[
|
| 86 |
+
{
|
| 87 |
+
"type":"image",
|
| 88 |
+
"url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"type":"text",
|
| 92 |
+
"text":"Describe this image."
|
| 93 |
+
}
|
| 94 |
+
]
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
inputs = processor.apply_chat_template(
|
| 100 |
+
messages,
|
| 101 |
+
add_generation_prompt=True,
|
| 102 |
+
tokenize=True,
|
| 103 |
+
return_dict=True,
|
| 104 |
+
return_tensors="pt"
|
| 105 |
+
).to(model.device, dtype=model.dtype)
|
| 106 |
+
|
| 107 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 108 |
+
generated_ids_trimmed = [
|
| 109 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 110 |
+
]
|
| 111 |
+
output_text = processor.batch_decode(
|
| 112 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
print(output_text)
|
| 116 |
+
```
|
| 117 |
+
</hfoption>
|
| 118 |
+
</hfoptions>
|
| 119 |
+
|
| 120 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 121 |
+
|
| 122 |
+
The example below uses [torchao](../quantization/torchao) to only quantize the weights to int4.
|
| 123 |
+
|
| 124 |
+
```python
|
| 125 |
+
import torch
|
| 126 |
+
from transformers import TorchAoConfig, DeepseekVLHybridForConditionalGeneration, AutoProcessor
|
| 127 |
+
|
| 128 |
+
quantization_config = TorchAoConfig(
|
| 129 |
+
"int4_weight_only",
|
| 130 |
+
group_size=128
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
|
| 134 |
+
"deepseek-community/deepseek-vl-7b-chat",
|
| 135 |
+
torch_dtype=torch.bfloat16,
|
| 136 |
+
device_map="auto",
|
| 137 |
+
quantization_config=quantization_config
|
| 138 |
+
)
|
| 139 |
+
```
|
| 140 |
+
### Notes
|
| 141 |
+
|
| 142 |
+
- Do inference with multiple images in a single conversation.
|
| 143 |
+
```py
|
| 144 |
+
import torch
|
| 145 |
+
from transformers import DeepseekVLHybridForConditionalGeneration, AutoProcessor
|
| 146 |
+
|
| 147 |
+
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
|
| 148 |
+
"deepseek-community/deepseek-vl-7b-chat",
|
| 149 |
+
torch_dtype=torch.float16,
|
| 150 |
+
device_map="auto",
|
| 151 |
+
attn_implementation="sdpa"
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
processor = AutoProcessor.from_pretrained("deepseek-community/deepseek-vl-7b-chat")
|
| 155 |
+
|
| 156 |
+
messages = [
|
| 157 |
+
[
|
| 158 |
+
{
|
| 159 |
+
"role": "user",
|
| 160 |
+
"content": [
|
| 161 |
+
{"type": "text", "text": "What’s the difference between"},
|
| 162 |
+
{"type": "image", "url": "http://images.cocodataset.org/val2017/000000039769.jpg"},
|
| 163 |
+
{"type": "text", "text": " and "},
|
| 164 |
+
{"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
|
| 165 |
+
]
|
| 166 |
+
}
|
| 167 |
+
],
|
| 168 |
+
[
|
| 169 |
+
{
|
| 170 |
+
"role": "user",
|
| 171 |
+
"content": [
|
| 172 |
+
{"type": "image", "url": "https://huggingface.co/microsoft/kosmos-2-patch14-224/resolve/main/snowman.jpg"},
|
| 173 |
+
{"type": "text", "text": "What do you see in this image?"}
|
| 174 |
+
]
|
| 175 |
+
}
|
| 176 |
+
]
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
inputs = processor.apply_chat_template(
|
| 180 |
+
messages,
|
| 181 |
+
add_generation_prompt=True,
|
| 182 |
+
padding=True,
|
| 183 |
+
truncation=True,
|
| 184 |
+
tokenize=True,
|
| 185 |
+
return_dict=True,
|
| 186 |
+
return_tensors="pt"
|
| 187 |
+
).to(model.device, dtype=model.dtype)
|
| 188 |
+
|
| 189 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 190 |
+
generated_ids_trimmed = [
|
| 191 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 192 |
+
]
|
| 193 |
+
output_text = processor.batch_decode(
|
| 194 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
print(output_text)
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
## DeepseekVLHybridConfig
|
| 201 |
+
|
| 202 |
+
[[autodoc]] DeepseekVLHybridConfig
|
| 203 |
+
|
| 204 |
+
## DeepseekVLHybridProcessor
|
| 205 |
+
|
| 206 |
+
[[autodoc]] DeepseekVLHybridProcessor
|
| 207 |
+
|
| 208 |
+
## DeepseekVLHybridImageProcessor
|
| 209 |
+
|
| 210 |
+
[[autodoc]] DeepseekVLHybridImageProcessor
|
| 211 |
+
|
| 212 |
+
## DeepseekVLHybridImageProcessorFast
|
| 213 |
+
|
| 214 |
+
[[autodoc]] DeepseekVLHybridImageProcessorFast
|
| 215 |
+
|
| 216 |
+
## DeepseekVLHybridModel
|
| 217 |
+
|
| 218 |
+
[[autodoc]] DeepseekVLHybridModel
|
| 219 |
+
- forward
|
| 220 |
+
|
| 221 |
+
## DeepseekVLHybridForConditionalGeneration
|
| 222 |
+
|
| 223 |
+
[[autodoc]] DeepseekVLHybridForConditionalGeneration
|
| 224 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deformable_detr.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-10-08 and added to Hugging Face Transformers on 2022-09-14.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
# Deformable DETR
|
| 25 |
+
|
| 26 |
+
[Deformable DETR](https://huggingface.co/papers/2010.04159) improves on the original [DETR](./detr) by using a deformable attention module. This mechanism selectively attends to a small set of key sampling points around a reference. It improves training speed and improves accuracy.
|
| 27 |
+
|
| 28 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/deformable_detr_architecture.png"
|
| 29 |
+
alt="drawing" width="600"/>
|
| 30 |
+
|
| 31 |
+
<small> Deformable DETR architecture. Taken from the <a href="https://huggingface.co/papers/2010.04159">original paper</a>.</small>
|
| 32 |
+
|
| 33 |
+
You can find all the available Deformable DETR checkpoints under the [SenseTime](https://huggingface.co/SenseTime) organization.
|
| 34 |
+
|
| 35 |
+
> [!TIP]
|
| 36 |
+
> This model was contributed by [nielsr](https://huggingface.co/nielsr).
|
| 37 |
+
>
|
| 38 |
+
> Click on the Deformable DETR models in the right sidebar for more examples of how to apply Deformable DETR to different object detection and segmentation tasks.
|
| 39 |
+
|
| 40 |
+
The example below demonstrates how to perform object detection with the [`Pipeline`] and the [`AutoModel`] class.
|
| 41 |
+
|
| 42 |
+
<hfoptions id="usage">
|
| 43 |
+
<hfoption id="Pipeline">
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from transformers import pipeline
|
| 47 |
+
import torch
|
| 48 |
+
|
| 49 |
+
pipeline = pipeline(
|
| 50 |
+
"object-detection",
|
| 51 |
+
model="SenseTime/deformable-detr",
|
| 52 |
+
torch_dtype=torch.float16,
|
| 53 |
+
device_map=0
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
pipeline("http://images.cocodataset.org/val2017/000000039769.jpg")
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
</hfoption>
|
| 60 |
+
<hfoption id="AutoModel">
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 64 |
+
from PIL import Image
|
| 65 |
+
import requests
|
| 66 |
+
import torch
|
| 67 |
+
|
| 68 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 69 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 70 |
+
|
| 71 |
+
image_processor = AutoImageProcessor.from_pretrained("SenseTime/deformable-detr")
|
| 72 |
+
model = AutoModelForObjectDetection.from_pretrained("SenseTime/deformable-detr")
|
| 73 |
+
|
| 74 |
+
# prepare image for the model
|
| 75 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 76 |
+
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
outputs = model(**inputs)
|
| 79 |
+
|
| 80 |
+
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
|
| 81 |
+
|
| 82 |
+
for result in results:
|
| 83 |
+
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 84 |
+
score, label = score.item(), label_id.item()
|
| 85 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 86 |
+
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
</hfoption>
|
| 90 |
+
</hfoptions>
|
| 91 |
+
|
| 92 |
+
## Resources
|
| 93 |
+
|
| 94 |
+
- Refer to this set of [notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/Deformable-DETR) for inference and fine-tuning [`DeformableDetrForObjectDetection`] on a custom dataset.
|
| 95 |
+
|
| 96 |
+
## DeformableDetrImageProcessor
|
| 97 |
+
|
| 98 |
+
[[autodoc]] DeformableDetrImageProcessor
|
| 99 |
+
- preprocess
|
| 100 |
+
- post_process_object_detection
|
| 101 |
+
|
| 102 |
+
## DeformableDetrImageProcessorFast
|
| 103 |
+
|
| 104 |
+
[[autodoc]] DeformableDetrImageProcessorFast
|
| 105 |
+
- preprocess
|
| 106 |
+
- post_process_object_detection
|
| 107 |
+
|
| 108 |
+
## DeformableDetrFeatureExtractor
|
| 109 |
+
|
| 110 |
+
[[autodoc]] DeformableDetrFeatureExtractor
|
| 111 |
+
- __call__
|
| 112 |
+
- post_process_object_detection
|
| 113 |
+
|
| 114 |
+
## DeformableDetrConfig
|
| 115 |
+
|
| 116 |
+
[[autodoc]] DeformableDetrConfig
|
| 117 |
+
|
| 118 |
+
## DeformableDetrModel
|
| 119 |
+
|
| 120 |
+
[[autodoc]] DeformableDetrModel
|
| 121 |
+
- forward
|
| 122 |
+
|
| 123 |
+
## DeformableDetrForObjectDetection
|
| 124 |
+
|
| 125 |
+
[[autodoc]] DeformableDetrForObjectDetection
|
| 126 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deit.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2021 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-12-23 and added to Hugging Face Transformers on 2021-04-13.*
|
| 17 |
+
|
| 18 |
+
# DeiT
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 24 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
The DeiT model was proposed in [Training data-efficient image transformers & distillation through attention](https://huggingface.co/papers/2012.12877) by Hugo Touvron, Matthieu Cord, Matthijs Douze, Francisco Massa, Alexandre
|
| 30 |
+
Sablayrolles, Hervé Jégou. The [Vision Transformer (ViT)](vit) introduced in [Dosovitskiy et al., 2020](https://huggingface.co/papers/2010.11929) has shown that one can match or even outperform existing convolutional neural
|
| 31 |
+
networks using a Transformer encoder (BERT-like). However, the ViT models introduced in that paper required training on
|
| 32 |
+
expensive infrastructure for multiple weeks, using external data. DeiT (data-efficient image transformers) are more
|
| 33 |
+
efficiently trained transformers for image classification, requiring far less data and far less computing resources
|
| 34 |
+
compared to the original ViT models.
|
| 35 |
+
|
| 36 |
+
The abstract from the paper is the following:
|
| 37 |
+
|
| 38 |
+
*Recently, neural networks purely based on attention were shown to address image understanding tasks such as image
|
| 39 |
+
classification. However, these visual transformers are pre-trained with hundreds of millions of images using an
|
| 40 |
+
expensive infrastructure, thereby limiting their adoption. In this work, we produce a competitive convolution-free
|
| 41 |
+
transformer by training on Imagenet only. We train them on a single computer in less than 3 days. Our reference vision
|
| 42 |
+
transformer (86M parameters) achieves top-1 accuracy of 83.1% (single-crop evaluation) on ImageNet with no external
|
| 43 |
+
data. More importantly, we introduce a teacher-student strategy specific to transformers. It relies on a distillation
|
| 44 |
+
token ensuring that the student learns from the teacher through attention. We show the interest of this token-based
|
| 45 |
+
distillation, especially when using a convnet as a teacher. This leads us to report results competitive with convnets
|
| 46 |
+
for both Imagenet (where we obtain up to 85.2% accuracy) and when transferring to other tasks. We share our code and
|
| 47 |
+
models.*
|
| 48 |
+
|
| 49 |
+
This model was contributed by [nielsr](https://huggingface.co/nielsr). The TensorFlow version of this model was added by [amyeroberts](https://huggingface.co/amyeroberts).
|
| 50 |
+
|
| 51 |
+
## Usage tips
|
| 52 |
+
|
| 53 |
+
- Compared to ViT, DeiT models use a so-called distillation token to effectively learn from a teacher (which, in the
|
| 54 |
+
DeiT paper, is a ResNet like-model). The distillation token is learned through backpropagation, by interacting with
|
| 55 |
+
the class ([CLS]) and patch tokens through the self-attention layers.
|
| 56 |
+
- There are 2 ways to fine-tune distilled models, either (1) in a classic way, by only placing a prediction head on top
|
| 57 |
+
of the final hidden state of the class token and not using the distillation signal, or (2) by placing both a
|
| 58 |
+
prediction head on top of the class token and on top of the distillation token. In that case, the [CLS] prediction
|
| 59 |
+
head is trained using regular cross-entropy between the prediction of the head and the ground-truth label, while the
|
| 60 |
+
distillation prediction head is trained using hard distillation (cross-entropy between the prediction of the
|
| 61 |
+
distillation head and the label predicted by the teacher). At inference time, one takes the average prediction
|
| 62 |
+
between both heads as final prediction. (2) is also called "fine-tuning with distillation", because one relies on a
|
| 63 |
+
teacher that has already been fine-tuned on the downstream dataset. In terms of models, (1) corresponds to
|
| 64 |
+
[`DeiTForImageClassification`] and (2) corresponds to
|
| 65 |
+
[`DeiTForImageClassificationWithTeacher`].
|
| 66 |
+
- Note that the authors also did try soft distillation for (2) (in which case the distillation prediction head is
|
| 67 |
+
trained using KL divergence to match the softmax output of the teacher), but hard distillation gave the best results.
|
| 68 |
+
- All released checkpoints were pre-trained and fine-tuned on ImageNet-1k only. No external data was used. This is in
|
| 69 |
+
contrast with the original ViT model, which used external data like the JFT-300M dataset/Imagenet-21k for
|
| 70 |
+
pre-training.
|
| 71 |
+
- The authors of DeiT also released more efficiently trained ViT models, which you can directly plug into
|
| 72 |
+
[`ViTModel`] or [`ViTForImageClassification`]. Techniques like data
|
| 73 |
+
augmentation, optimization, and regularization were used in order to simulate training on a much larger dataset
|
| 74 |
+
(while only using ImageNet-1k for pre-training). There are 4 variants available (in 3 different sizes):
|
| 75 |
+
*facebook/deit-tiny-patch16-224*, *facebook/deit-small-patch16-224*, *facebook/deit-base-patch16-224* and
|
| 76 |
+
*facebook/deit-base-patch16-384*. Note that one should use [`DeiTImageProcessor`] in order to
|
| 77 |
+
prepare images for the model.
|
| 78 |
+
|
| 79 |
+
### Using Scaled Dot Product Attention (SDPA)
|
| 80 |
+
|
| 81 |
+
PyTorch includes a native scaled dot-product attention (SDPA) operator as part of `torch.nn.functional`. This function
|
| 82 |
+
encompasses several implementations that can be applied depending on the inputs and the hardware in use. See the
|
| 83 |
+
[official documentation](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)
|
| 84 |
+
or the [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)
|
| 85 |
+
page for more information.
|
| 86 |
+
|
| 87 |
+
SDPA is used by default for `torch>=2.1.1` when an implementation is available, but you may also set
|
| 88 |
+
`attn_implementation="sdpa"` in `from_pretrained()` to explicitly request SDPA to be used.
|
| 89 |
+
|
| 90 |
+
```
|
| 91 |
+
from transformers import DeiTForImageClassification
|
| 92 |
+
model = DeiTForImageClassification.from_pretrained("facebook/deit-base-distilled-patch16-224", attn_implementation="sdpa", torch_dtype=torch.float16)
|
| 93 |
+
...
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
For the best speedups, we recommend loading the model in half-precision (e.g. `torch.float16` or `torch.bfloat16`).
|
| 97 |
+
|
| 98 |
+
On a local benchmark (A100-40GB, PyTorch 2.3.0, OS Ubuntu 22.04) with `float32` and `facebook/deit-base-distilled-patch16-224` model, we saw the following speedups during inference.
|
| 99 |
+
|
| 100 |
+
| Batch size | Average inference time (ms), eager mode | Average inference time (ms), sdpa model | Speed up, Sdpa / Eager (x) |
|
| 101 |
+
|--------------|-------------------------------------------|-------------------------------------------|------------------------------|
|
| 102 |
+
| 1 | 8 | 6 | 1.33 |
|
| 103 |
+
| 2 | 9 | 6 | 1.5 |
|
| 104 |
+
| 4 | 9 | 6 | 1.5 |
|
| 105 |
+
| 8 | 8 | 6 | 1.33 |
|
| 106 |
+
|
| 107 |
+
## Resources
|
| 108 |
+
|
| 109 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DeiT.
|
| 110 |
+
|
| 111 |
+
<PipelineTag pipeline="image-classification"/>
|
| 112 |
+
|
| 113 |
+
- [`DeiTForImageClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb).
|
| 114 |
+
- See also: [Image classification task guide](../tasks/image_classification)
|
| 115 |
+
|
| 116 |
+
Besides that:
|
| 117 |
+
|
| 118 |
+
- [`DeiTForMaskedImageModeling`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-pretraining).
|
| 119 |
+
|
| 120 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 121 |
+
|
| 122 |
+
## DeiTConfig
|
| 123 |
+
|
| 124 |
+
[[autodoc]] DeiTConfig
|
| 125 |
+
|
| 126 |
+
## DeiTFeatureExtractor
|
| 127 |
+
|
| 128 |
+
[[autodoc]] DeiTFeatureExtractor
|
| 129 |
+
- __call__
|
| 130 |
+
|
| 131 |
+
## DeiTImageProcessor
|
| 132 |
+
|
| 133 |
+
[[autodoc]] DeiTImageProcessor
|
| 134 |
+
- preprocess
|
| 135 |
+
|
| 136 |
+
## DeiTImageProcessorFast
|
| 137 |
+
|
| 138 |
+
[[autodoc]] DeiTImageProcessorFast
|
| 139 |
+
- preprocess
|
| 140 |
+
|
| 141 |
+
<frameworkcontent>
|
| 142 |
+
<pt>
|
| 143 |
+
|
| 144 |
+
## DeiTModel
|
| 145 |
+
|
| 146 |
+
[[autodoc]] DeiTModel
|
| 147 |
+
- forward
|
| 148 |
+
|
| 149 |
+
## DeiTForMaskedImageModeling
|
| 150 |
+
|
| 151 |
+
[[autodoc]] DeiTForMaskedImageModeling
|
| 152 |
+
- forward
|
| 153 |
+
|
| 154 |
+
## DeiTForImageClassification
|
| 155 |
+
|
| 156 |
+
[[autodoc]] DeiTForImageClassification
|
| 157 |
+
- forward
|
| 158 |
+
|
| 159 |
+
## DeiTForImageClassificationWithTeacher
|
| 160 |
+
|
| 161 |
+
[[autodoc]] DeiTForImageClassificationWithTeacher
|
| 162 |
+
- forward
|
| 163 |
+
|
| 164 |
+
</pt>
|
| 165 |
+
<tf>
|
| 166 |
+
|
| 167 |
+
## TFDeiTModel
|
| 168 |
+
|
| 169 |
+
[[autodoc]] TFDeiTModel
|
| 170 |
+
- call
|
| 171 |
+
|
| 172 |
+
## TFDeiTForMaskedImageModeling
|
| 173 |
+
|
| 174 |
+
[[autodoc]] TFDeiTForMaskedImageModeling
|
| 175 |
+
- call
|
| 176 |
+
|
| 177 |
+
## TFDeiTForImageClassification
|
| 178 |
+
|
| 179 |
+
[[autodoc]] TFDeiTForImageClassification
|
| 180 |
+
- call
|
| 181 |
+
|
| 182 |
+
## TFDeiTForImageClassificationWithTeacher
|
| 183 |
+
|
| 184 |
+
[[autodoc]] TFDeiTForImageClassificationWithTeacher
|
| 185 |
+
- call
|
| 186 |
+
|
| 187 |
+
</tf>
|
| 188 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deplot.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2021 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-12-20 and added to Hugging Face Transformers on 2023-06-20.*
|
| 17 |
+
|
| 18 |
+
# DePlot
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
DePlot was proposed in the paper [DePlot: One-shot visual language reasoning by plot-to-table translation](https://huggingface.co/papers/2212.10505) from Fangyu Liu, Julian Martin Eisenschlos, Francesco Piccinno, Syrine Krichene, Chenxi Pang, Kenton Lee, Mandar Joshi, Wenhu Chen, Nigel Collier, Yasemin Altun.
|
| 27 |
+
|
| 28 |
+
The abstract of the paper states the following:
|
| 29 |
+
|
| 30 |
+
*Visual language such as charts and plots is ubiquitous in the human world. Comprehending plots and charts requires strong reasoning skills. Prior state-of-the-art (SOTA) models require at least tens of thousands of training examples and their reasoning capabilities are still much limited, especially on complex human-written queries. This paper presents the first one-shot solution to visual language reasoning. We decompose the challenge of visual language reasoning into two steps: (1) plot-to-text translation, and (2) reasoning over the translated text. The key in this method is a modality conversion module, named as DePlot, which translates the image of a plot or chart to a linearized table. The output of DePlot can then be directly used to prompt a pretrained large language model (LLM), exploiting the few-shot reasoning capabilities of LLMs. To obtain DePlot, we standardize the plot-to-table task by establishing unified task formats and metrics, and train DePlot end-to-end on this task. DePlot can then be used off-the-shelf together with LLMs in a plug-and-play fashion. Compared with a SOTA model finetuned on more than >28k data points, DePlot+LLM with just one-shot prompting achieves a 24.0% improvement over finetuned SOTA on human-written queries from the task of chart QA.*
|
| 31 |
+
|
| 32 |
+
DePlot is a model that is trained using `Pix2Struct` architecture. You can find more information about `Pix2Struct` in the [Pix2Struct documentation](https://huggingface.co/docs/transformers/main/en/model_doc/pix2struct).
|
| 33 |
+
DePlot is a Visual Question Answering subset of `Pix2Struct` architecture. It renders the input question on the image and predicts the answer.
|
| 34 |
+
|
| 35 |
+
## Usage example
|
| 36 |
+
|
| 37 |
+
Currently one checkpoint is available for DePlot:
|
| 38 |
+
|
| 39 |
+
- `google/deplot`: DePlot fine-tuned on ChartQA dataset
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from transformers import AutoProcessor, Pix2StructForConditionalGeneration
|
| 44 |
+
import requests
|
| 45 |
+
from PIL import Image
|
| 46 |
+
|
| 47 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/deplot")
|
| 48 |
+
processor = AutoProcessor.from_pretrained("google/deplot")
|
| 49 |
+
url = "https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/5090.png"
|
| 50 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 51 |
+
|
| 52 |
+
inputs = processor(images=image, text="Generate underlying data table of the figure below:", return_tensors="pt")
|
| 53 |
+
predictions = model.generate(**inputs, max_new_tokens=512)
|
| 54 |
+
print(processor.decode(predictions[0], skip_special_tokens=True))
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Fine-tuning
|
| 58 |
+
|
| 59 |
+
To fine-tune DePlot, refer to the pix2struct [fine-tuning notebook](https://github.com/huggingface/notebooks/blob/main/examples/image_captioning_pix2struct.ipynb). For `Pix2Struct` models, we have found out that fine-tuning the model with Adafactor and cosine learning rate scheduler leads to faster convergence:
|
| 60 |
+
```python
|
| 61 |
+
from transformers.optimization import Adafactor, get_cosine_schedule_with_warmup
|
| 62 |
+
|
| 63 |
+
optimizer = Adafactor(self.parameters(), scale_parameter=False, relative_step=False, lr=0.01, weight_decay=1e-05)
|
| 64 |
+
scheduler = get_cosine_schedule_with_warmup(optimizer, num_warmup_steps=1000, num_training_steps=40000)
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
<Tip>
|
| 68 |
+
|
| 69 |
+
DePlot is a model trained using `Pix2Struct` architecture. For API reference, see [`Pix2Struct` documentation](pix2struct).
|
| 70 |
+
|
| 71 |
+
</Tip>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_anything.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-01-19 and added to Hugging Face Transformers on 2024-01-25.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
# Depth Anything
|
| 25 |
+
|
| 26 |
+
[Depth Anything](https://huggingface.co/papers/2401.10891) is designed to be a foundation model for monocular depth estimation (MDE). It is jointly trained on labeled and ~62M unlabeled images to enhance the dataset. It uses a pretrained [DINOv2](./dinov2) model as an image encoder to inherit its existing rich semantic priors, and [DPT](./dpt) as the decoder. A teacher model is trained on unlabeled images to create pseudo-labels. The student model is trained on a combination of the pseudo-labels and labeled images. To improve the student model's performance, strong perturbations are added to the unlabeled images to challenge the student model to learn more visual knowledge from the image.
|
| 27 |
+
|
| 28 |
+
You can find all the original Depth Anything checkpoints under the [Depth Anything](https://huggingface.co/collections/LiheYoung/depth-anything-release-65b317de04eec72abf6b55aa) collection.
|
| 29 |
+
|
| 30 |
+
> [!TIP]
|
| 31 |
+
> Click on the Depth Anything models in the right sidebar for more examples of how to apply Depth Anything to different vision tasks.
|
| 32 |
+
|
| 33 |
+
The example below demonstrates how to obtain a depth map with [`Pipeline`] or the [`AutoModel`] class.
|
| 34 |
+
|
| 35 |
+
<hfoptions id="usage">
|
| 36 |
+
<hfoption id="Pipeline">
|
| 37 |
+
|
| 38 |
+
```py
|
| 39 |
+
import torch
|
| 40 |
+
from transformers import pipeline
|
| 41 |
+
|
| 42 |
+
pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf", torch_dtype=torch.bfloat16, device=0)
|
| 43 |
+
pipe("http://images.cocodataset.org/val2017/000000039769.jpg")["depth"]
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
</hfoption>
|
| 47 |
+
<hfoption id="AutoModel">
|
| 48 |
+
|
| 49 |
+
```py
|
| 50 |
+
import torch
|
| 51 |
+
import requests
|
| 52 |
+
import numpy as np
|
| 53 |
+
from PIL import Image
|
| 54 |
+
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
|
| 55 |
+
|
| 56 |
+
image_processor = AutoImageProcessor.from_pretrained("LiheYoung/depth-anything-base-hf")
|
| 57 |
+
model = AutoModelForDepthEstimation.from_pretrained("LiheYoung/depth-anything-base-hf", torch_dtype=torch.bfloat16)
|
| 58 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 59 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 60 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 61 |
+
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
outputs = model(**inputs)
|
| 64 |
+
|
| 65 |
+
post_processed_output = image_processor.post_process_depth_estimation(
|
| 66 |
+
outputs,
|
| 67 |
+
target_sizes=[(image.height, image.width)],
|
| 68 |
+
)
|
| 69 |
+
predicted_depth = post_processed_output[0]["predicted_depth"]
|
| 70 |
+
depth = (predicted_depth - predicted_depth.min()) / (predicted_depth.max() - predicted_depth.min())
|
| 71 |
+
depth = depth.detach().cpu().numpy() * 255
|
| 72 |
+
Image.fromarray(depth.astype("uint8"))
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
</hfoption>
|
| 76 |
+
</hfoptions>
|
| 77 |
+
|
| 78 |
+
## Notes
|
| 79 |
+
|
| 80 |
+
- [DepthAnythingV2](./depth_anything_v2), released in June 2024, uses the same architecture as Depth Anything and is compatible with all code examples and existing workflows. It uses synthetic data and a larger capacity teacher model to achieve much finer and robust depth predictions.
|
| 81 |
+
|
| 82 |
+
## DepthAnythingConfig
|
| 83 |
+
|
| 84 |
+
[[autodoc]] DepthAnythingConfig
|
| 85 |
+
|
| 86 |
+
## DepthAnythingForDepthEstimation
|
| 87 |
+
|
| 88 |
+
[[autodoc]] DepthAnythingForDepthEstimation
|
| 89 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_anything_v2.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-06-13 and added to Hugging Face Transformers on 2024-07-05.*
|
| 17 |
+
|
| 18 |
+
# Depth Anything V2
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
Depth Anything V2 was introduced in [the paper of the same name](https://huggingface.co/papers/2406.09414) by Lihe Yang et al. It uses the same architecture as the original [Depth Anything model](depth_anything), but uses synthetic data and a larger capacity teacher model to achieve much finer and robust depth predictions.
|
| 23 |
+
|
| 24 |
+
The abstract from the paper is the following:
|
| 25 |
+
|
| 26 |
+
*This work presents Depth Anything V2. Without pursuing fancy techniques, we aim to reveal crucial findings to pave the way towards building a powerful monocular depth estimation model. Notably, compared with V1, this version produces much finer and more robust depth predictions through three key practices: 1) replacing all labeled real images with synthetic images, 2) scaling up the capacity of our teacher model, and 3) teaching student models via the bridge of large-scale pseudo-labeled real images. Compared with the latest models built on Stable Diffusion, our models are significantly more efficient (more than 10x faster) and more accurate. We offer models of different scales (ranging from 25M to 1.3B params) to support extensive scenarios. Benefiting from their strong generalization capability, we fine-tune them with metric depth labels to obtain our metric depth models. In addition to our models, considering the limited diversity and frequent noise in current test sets, we construct a versatile evaluation benchmark with precise annotations and diverse scenes to facilitate future research.*
|
| 27 |
+
|
| 28 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/depth_anything_overview.jpg"
|
| 29 |
+
alt="drawing" width="600"/>
|
| 30 |
+
|
| 31 |
+
<small> Depth Anything overview. Taken from the <a href="https://huggingface.co/papers/2401.10891">original paper</a>.</small>
|
| 32 |
+
|
| 33 |
+
The Depth Anything models were contributed by [nielsr](https://huggingface.co/nielsr).
|
| 34 |
+
The original code can be found [here](https://github.com/DepthAnything/Depth-Anything-V2).
|
| 35 |
+
|
| 36 |
+
## Usage example
|
| 37 |
+
|
| 38 |
+
There are 2 main ways to use Depth Anything V2: either using the pipeline API, which abstracts away all the complexity for you, or by using the `DepthAnythingForDepthEstimation` class yourself.
|
| 39 |
+
|
| 40 |
+
### Pipeline API
|
| 41 |
+
|
| 42 |
+
The pipeline allows to use the model in a few lines of code:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
>>> from transformers import pipeline
|
| 46 |
+
>>> from PIL import Image
|
| 47 |
+
>>> import requests
|
| 48 |
+
|
| 49 |
+
>>> # load pipe
|
| 50 |
+
>>> pipe = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf")
|
| 51 |
+
|
| 52 |
+
>>> # load image
|
| 53 |
+
>>> url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 54 |
+
>>> image = Image.open(requests.get(url, stream=True).raw)
|
| 55 |
+
|
| 56 |
+
>>> # inference
|
| 57 |
+
>>> depth = pipe(image)["depth"]
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### Using the model yourself
|
| 61 |
+
|
| 62 |
+
If you want to do the pre- and post-processing yourself, here's how to do that:
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
>>> from transformers import AutoImageProcessor, AutoModelForDepthEstimation
|
| 66 |
+
>>> import torch
|
| 67 |
+
>>> import numpy as np
|
| 68 |
+
>>> from PIL import Image
|
| 69 |
+
>>> import requests
|
| 70 |
+
|
| 71 |
+
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 72 |
+
>>> image = Image.open(requests.get(url, stream=True).raw)
|
| 73 |
+
|
| 74 |
+
>>> image_processor = AutoImageProcessor.from_pretrained("depth-anything/Depth-Anything-V2-Small-hf")
|
| 75 |
+
>>> model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Small-hf")
|
| 76 |
+
|
| 77 |
+
>>> # prepare image for the model
|
| 78 |
+
>>> inputs = image_processor(images=image, return_tensors="pt")
|
| 79 |
+
|
| 80 |
+
>>> with torch.no_grad():
|
| 81 |
+
... outputs = model(**inputs)
|
| 82 |
+
|
| 83 |
+
>>> # interpolate to original size and visualize the prediction
|
| 84 |
+
>>> post_processed_output = image_processor.post_process_depth_estimation(
|
| 85 |
+
... outputs,
|
| 86 |
+
... target_sizes=[(image.height, image.width)],
|
| 87 |
+
... )
|
| 88 |
+
|
| 89 |
+
>>> predicted_depth = post_processed_output[0]["predicted_depth"]
|
| 90 |
+
>>> depth = (predicted_depth - predicted_depth.min()) / (predicted_depth.max() - predicted_depth.min())
|
| 91 |
+
>>> depth = depth.detach().cpu().numpy() * 255
|
| 92 |
+
>>> depth = Image.fromarray(depth.astype("uint8"))
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Resources
|
| 96 |
+
|
| 97 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Depth Anything.
|
| 98 |
+
|
| 99 |
+
- [Monocular depth estimation task guide](../tasks/monocular_depth_estimation)
|
| 100 |
+
- [Depth Anything V2 demo](https://huggingface.co/spaces/depth-anything/Depth-Anything-V2).
|
| 101 |
+
- A notebook showcasing inference with [`DepthAnythingForDepthEstimation`] can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/Depth%20Anything/Predicting_depth_in_an_image_with_Depth_Anything.ipynb). 🌎
|
| 102 |
+
- [Core ML conversion of the `small` variant for use on Apple Silicon](https://huggingface.co/apple/coreml-depth-anything-v2-small).
|
| 103 |
+
|
| 104 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 105 |
+
|
| 106 |
+
## DepthAnythingConfig
|
| 107 |
+
|
| 108 |
+
[[autodoc]] DepthAnythingConfig
|
| 109 |
+
|
| 110 |
+
## DepthAnythingForDepthEstimation
|
| 111 |
+
|
| 112 |
+
[[autodoc]] DepthAnythingForDepthEstimation
|
| 113 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/depth_pro.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-10-02 and added to Hugging Face Transformers on 2025-02-10.*
|
| 17 |
+
|
| 18 |
+
# DepthPro
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
The DepthPro model was proposed in [Depth Pro: Sharp Monocular Metric Depth in Less Than a Second](https://huggingface.co/papers/2410.02073) by Aleksei Bochkovskii, Amaël Delaunoy, Hugo Germain, Marcel Santos, Yichao Zhou, Stephan R. Richter, Vladlen Koltun.
|
| 27 |
+
|
| 28 |
+
DepthPro is a foundation model for zero-shot metric monocular depth estimation, designed to generate high-resolution depth maps with remarkable sharpness and fine-grained details. It employs a multi-scale Vision Transformer (ViT)-based architecture, where images are downsampled, divided into patches, and processed using a shared Dinov2 encoder. The extracted patch-level features are merged, upsampled, and refined using a DPT-like fusion stage, enabling precise depth estimation.
|
| 29 |
+
|
| 30 |
+
The abstract from the paper is the following:
|
| 31 |
+
|
| 32 |
+
*We present a foundation model for zero-shot metric monocular depth estimation. Our model, Depth Pro, synthesizes high-resolution depth maps with unparalleled sharpness and high-frequency details. The predictions are metric, with absolute scale, without relying on the availability of metadata such as camera intrinsics. And the model is fast, producing a 2.25-megapixel depth map in 0.3 seconds on a standard GPU. These characteristics are enabled by a number of technical contributions, including an efficient multi-scale vision transformer for dense prediction, a training protocol that combines real and synthetic datasets to achieve high metric accuracy alongside fine boundary tracing, dedicated evaluation metrics for boundary accuracy in estimated depth maps, and state-of-the-art focal length estimation from a single image. Extensive experiments analyze specific design choices and demonstrate that Depth Pro outperforms prior work along multiple dimensions.*
|
| 33 |
+
|
| 34 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/depth_pro_teaser.png"
|
| 35 |
+
alt="drawing" width="600"/>
|
| 36 |
+
|
| 37 |
+
<small> DepthPro Outputs. Taken from the <a href="https://github.com/apple/ml-depth-pro" target="_blank">official code</a>. </small>
|
| 38 |
+
|
| 39 |
+
This model was contributed by [geetu040](https://github.com/geetu040). The original code can be found [here](https://github.com/apple/ml-depth-pro).
|
| 40 |
+
|
| 41 |
+
## Usage Tips
|
| 42 |
+
|
| 43 |
+
The DepthPro model processes an input image by first downsampling it at multiple scales and splitting each scaled version into patches. These patches are then encoded using a shared Vision Transformer (ViT)-based Dinov2 patch encoder, while the full image is processed by a separate image encoder. The extracted patch features are merged into feature maps, upsampled, and fused using a DPT-like decoder to generate the final depth estimation. If enabled, an additional Field of View (FOV) encoder processes the image for estimating the camera's field of view, aiding in depth accuracy.
|
| 44 |
+
|
| 45 |
+
```py
|
| 46 |
+
>>> import requests
|
| 47 |
+
>>> from PIL import Image
|
| 48 |
+
>>> import torch
|
| 49 |
+
>>> from transformers import DepthProImageProcessorFast, DepthProForDepthEstimation, infer_device
|
| 50 |
+
|
| 51 |
+
>>> device = infer_device()
|
| 52 |
+
|
| 53 |
+
>>> url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 54 |
+
>>> image = Image.open(requests.get(url, stream=True).raw)
|
| 55 |
+
|
| 56 |
+
>>> image_processor = DepthProImageProcessorFast.from_pretrained("apple/DepthPro-hf")
|
| 57 |
+
>>> model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device)
|
| 58 |
+
|
| 59 |
+
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)
|
| 60 |
+
|
| 61 |
+
>>> with torch.no_grad():
|
| 62 |
+
... outputs = model(**inputs)
|
| 63 |
+
|
| 64 |
+
>>> post_processed_output = image_processor.post_process_depth_estimation(
|
| 65 |
+
... outputs, target_sizes=[(image.height, image.width)],
|
| 66 |
+
... )
|
| 67 |
+
|
| 68 |
+
>>> field_of_view = post_processed_output[0]["field_of_view"]
|
| 69 |
+
>>> focal_length = post_processed_output[0]["focal_length"]
|
| 70 |
+
>>> depth = post_processed_output[0]["predicted_depth"]
|
| 71 |
+
>>> depth = (depth - depth.min()) / depth.max()
|
| 72 |
+
>>> depth = depth * 255.
|
| 73 |
+
>>> depth = depth.detach().cpu().numpy()
|
| 74 |
+
>>> depth = Image.fromarray(depth.astype("uint8"))
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Architecture and Configuration
|
| 78 |
+
|
| 79 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/depth_pro_architecture.png"
|
| 80 |
+
alt="drawing" width="600"/>
|
| 81 |
+
|
| 82 |
+
<small> DepthPro architecture. Taken from the <a href="https://huggingface.co/papers/2410.02073" target="_blank">original paper</a>. </small>
|
| 83 |
+
|
| 84 |
+
The `DepthProForDepthEstimation` model uses a `DepthProEncoder`, for encoding the input image and a `FeatureFusionStage` for fusing the output features from encoder.
|
| 85 |
+
|
| 86 |
+
The `DepthProEncoder` further uses two encoders:
|
| 87 |
+
- `patch_encoder`
|
| 88 |
+
- Input image is scaled with multiple ratios, as specified in the `scaled_images_ratios` configuration.
|
| 89 |
+
- Each scaled image is split into smaller **patches** of size `patch_size` with overlapping areas determined by `scaled_images_overlap_ratios`.
|
| 90 |
+
- These patches are processed by the **`patch_encoder`**
|
| 91 |
+
- `image_encoder`
|
| 92 |
+
- Input image is also rescaled to `patch_size` and processed by the **`image_encoder`**
|
| 93 |
+
|
| 94 |
+
Both these encoders can be configured via `patch_model_config` and `image_model_config` respectively, both of which are separate `Dinov2Model` by default.
|
| 95 |
+
|
| 96 |
+
Outputs from both encoders (`last_hidden_state`) and selected intermediate states (`hidden_states`) from **`patch_encoder`** are fused by a `DPT`-based `FeatureFusionStage` for depth estimation.
|
| 97 |
+
|
| 98 |
+
### Field-of-View (FOV) Prediction
|
| 99 |
+
|
| 100 |
+
The network is supplemented with a focal length estimation head. A small convolutional head ingests frozen features from the depth estimation network and task-specific features from a separate ViT image encoder to predict the horizontal angular field-of-view.
|
| 101 |
+
|
| 102 |
+
The `use_fov_model` parameter in `DepthProConfig` controls whether **FOV prediction** is enabled. By default, it is set to `False` to conserve memory and computation. When enabled, the **FOV encoder** is instantiated based on the `fov_model_config` parameter, which defaults to a `Dinov2Model`. The `use_fov_model` parameter can also be passed when initializing the `DepthProForDepthEstimation` model.
|
| 103 |
+
|
| 104 |
+
The pretrained model at checkpoint `apple/DepthPro-hf` uses the FOV encoder. To use the pretrained-model without FOV encoder, set `use_fov_model=False` when loading the model, which saves computation.
|
| 105 |
+
```py
|
| 106 |
+
>>> from transformers import DepthProForDepthEstimation
|
| 107 |
+
>>> model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf", use_fov_model=False)
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
To instantiate a new model with FOV encoder, set `use_fov_model=True` in the config.
|
| 111 |
+
```py
|
| 112 |
+
>>> from transformers import DepthProConfig, DepthProForDepthEstimation
|
| 113 |
+
>>> config = DepthProConfig(use_fov_model=True)
|
| 114 |
+
>>> model = DepthProForDepthEstimation(config)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
Or set `use_fov_model=True` when initializing the model, which overrides the value in config.
|
| 118 |
+
```py
|
| 119 |
+
>>> from transformers import DepthProConfig, DepthProForDepthEstimation
|
| 120 |
+
>>> config = DepthProConfig()
|
| 121 |
+
>>> model = DepthProForDepthEstimation(config, use_fov_model=True)
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
### Using Scaled Dot Product Attention (SDPA)
|
| 125 |
+
|
| 126 |
+
PyTorch includes a native scaled dot-product attention (SDPA) operator as part of `torch.nn.functional`. This function
|
| 127 |
+
encompasses several implementations that can be applied depending on the inputs and the hardware in use. See the
|
| 128 |
+
[official documentation](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)
|
| 129 |
+
or the [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)
|
| 130 |
+
page for more information.
|
| 131 |
+
|
| 132 |
+
SDPA is used by default for `torch>=2.1.1` when an implementation is available, but you may also set
|
| 133 |
+
`attn_implementation="sdpa"` in `from_pretrained()` to explicitly request SDPA to be used.
|
| 134 |
+
|
| 135 |
+
```py
|
| 136 |
+
from transformers import DepthProForDepthEstimation
|
| 137 |
+
model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf", attn_implementation="sdpa", torch_dtype=torch.float16)
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
For the best speedups, we recommend loading the model in half-precision (e.g. `torch.float16` or `torch.bfloat16`).
|
| 141 |
+
|
| 142 |
+
On a local benchmark (A100-40GB, PyTorch 2.3.0, OS Ubuntu 22.04) with `float32` and `google/vit-base-patch16-224` model, we saw the following speedups during inference.
|
| 143 |
+
|
| 144 |
+
| Batch size | Average inference time (ms), eager mode | Average inference time (ms), sdpa model | Speed up, Sdpa / Eager (x) |
|
| 145 |
+
|--------------|-------------------------------------------|-------------------------------------------|------------------------------|
|
| 146 |
+
| 1 | 7 | 6 | 1.17 |
|
| 147 |
+
| 2 | 8 | 6 | 1.33 |
|
| 148 |
+
| 4 | 8 | 6 | 1.33 |
|
| 149 |
+
| 8 | 8 | 6 | 1.33 |
|
| 150 |
+
|
| 151 |
+
## Resources
|
| 152 |
+
|
| 153 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DepthPro:
|
| 154 |
+
|
| 155 |
+
- Research Paper: [Depth Pro: Sharp Monocular Metric Depth in Less Than a Second](https://huggingface.co/papers/2410.02073)
|
| 156 |
+
- Official Implementation: [apple/ml-depth-pro](https://github.com/apple/ml-depth-pro)
|
| 157 |
+
- DepthPro Inference Notebook: [DepthPro Inference](https://github.com/qubvel/transformers-notebooks/blob/main/notebooks/DepthPro_inference.ipynb)
|
| 158 |
+
- DepthPro for Super Resolution and Image Segmentation
|
| 159 |
+
- Read blog on Medium: [Depth Pro: Beyond Depth](https://medium.com/@raoarmaghanshakir040/depth-pro-beyond-depth-9d822fc557ba)
|
| 160 |
+
- Code on Github: [geetu040/depthpro-beyond-depth](https://github.com/geetu040/depthpro-beyond-depth)
|
| 161 |
+
|
| 162 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 163 |
+
|
| 164 |
+
## DepthProConfig
|
| 165 |
+
|
| 166 |
+
[[autodoc]] DepthProConfig
|
| 167 |
+
|
| 168 |
+
## DepthProImageProcessor
|
| 169 |
+
|
| 170 |
+
[[autodoc]] DepthProImageProcessor
|
| 171 |
+
- preprocess
|
| 172 |
+
- post_process_depth_estimation
|
| 173 |
+
|
| 174 |
+
## DepthProImageProcessorFast
|
| 175 |
+
|
| 176 |
+
[[autodoc]] DepthProImageProcessorFast
|
| 177 |
+
- preprocess
|
| 178 |
+
- post_process_depth_estimation
|
| 179 |
+
|
| 180 |
+
## DepthProModel
|
| 181 |
+
|
| 182 |
+
[[autodoc]] DepthProModel
|
| 183 |
+
- forward
|
| 184 |
+
|
| 185 |
+
## DepthProForDepthEstimation
|
| 186 |
+
|
| 187 |
+
[[autodoc]] DepthProForDepthEstimation
|
| 188 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/deta.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-12-12 and added to Hugging Face Transformers on 2023-06-20.*
|
| 17 |
+
|
| 18 |
+
# DETA
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<Tip warning={true}>
|
| 25 |
+
|
| 26 |
+
This model is in maintenance mode only, we don't accept any new PRs changing its code.
|
| 27 |
+
If you run into any issues running this model, please reinstall the last version that supported this model: v4.40.2.
|
| 28 |
+
You can do so by running the following command: `pip install -U transformers==4.40.2`.
|
| 29 |
+
|
| 30 |
+
</Tip>
|
| 31 |
+
|
| 32 |
+
## Overview
|
| 33 |
+
|
| 34 |
+
The DETA model was proposed in [NMS Strikes Back](https://huggingface.co/papers/2212.06137) by Jeffrey Ouyang-Zhang, Jang Hyun Cho, Xingyi Zhou, Philipp Krähenbühl.
|
| 35 |
+
DETA (short for Detection Transformers with Assignment) improves [Deformable DETR](deformable_detr) by replacing the one-to-one bipartite Hungarian matching loss
|
| 36 |
+
with one-to-many label assignments used in traditional detectors with non-maximum suppression (NMS). This leads to significant gains of up to 2.5 mAP.
|
| 37 |
+
|
| 38 |
+
The abstract from the paper is the following:
|
| 39 |
+
|
| 40 |
+
*Detection Transformer (DETR) directly transforms queries to unique objects by using one-to-one bipartite matching during training and enables end-to-end object detection. Recently, these models have surpassed traditional detectors on COCO with undeniable elegance. However, they differ from traditional detectors in multiple designs, including model architecture and training schedules, and thus the effectiveness of one-to-one matching is not fully understood. In this work, we conduct a strict comparison between the one-to-one Hungarian matching in DETRs and the one-to-many label assignments in traditional detectors with non-maximum supervision (NMS). Surprisingly, we observe one-to-many assignments with NMS consistently outperform standard one-to-one matching under the same setting, with a significant gain of up to 2.5 mAP. Our detector that trains Deformable-DETR with traditional IoU-based label assignment achieved 50.2 COCO mAP within 12 epochs (1x schedule) with ResNet50 backbone, outperforming all existing traditional or transformer-based detectors in this setting. On multiple datasets, schedules, and architectures, we consistently show bipartite matching is unnecessary for performant detection transformers. Furthermore, we attribute the success of detection transformers to their expressive transformer architecture.*
|
| 41 |
+
|
| 42 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/deta_architecture.jpg"
|
| 43 |
+
alt="drawing" width="600"/>
|
| 44 |
+
|
| 45 |
+
<small> DETA overview. Taken from the <a href="https://huggingface.co/papers/2212.06137">original paper</a>. </small>
|
| 46 |
+
|
| 47 |
+
This model was contributed by [nielsr](https://huggingface.co/nielsr).
|
| 48 |
+
The original code can be found [here](https://github.com/jozhang97/DETA).
|
| 49 |
+
|
| 50 |
+
## Resources
|
| 51 |
+
|
| 52 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DETA.
|
| 53 |
+
|
| 54 |
+
- Demo notebooks for DETA can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/DETA).
|
| 55 |
+
- Scripts for finetuning [`DetaForObjectDetection`] with [`Trainer`] or [Accelerate](https://huggingface.co/docs/accelerate/index) can be found [here](https://github.com/huggingface/transformers/tree/main/examples/pytorch/object-detection).
|
| 56 |
+
- See also: [Object detection task guide](../tasks/object_detection).
|
| 57 |
+
|
| 58 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 59 |
+
|
| 60 |
+
## DetaConfig
|
| 61 |
+
|
| 62 |
+
[[autodoc]] DetaConfig
|
| 63 |
+
|
| 64 |
+
## DetaImageProcessor
|
| 65 |
+
|
| 66 |
+
[[autodoc]] DetaImageProcessor
|
| 67 |
+
- preprocess
|
| 68 |
+
- post_process_object_detection
|
| 69 |
+
|
| 70 |
+
## DetaModel
|
| 71 |
+
|
| 72 |
+
[[autodoc]] DetaModel
|
| 73 |
+
- forward
|
| 74 |
+
|
| 75 |
+
## DetaForObjectDetection
|
| 76 |
+
|
| 77 |
+
[[autodoc]] DetaForObjectDetection
|
| 78 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/detr.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2021 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-05-26 and added to Hugging Face Transformers on 2021-06-09.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
# DETR
|
| 25 |
+
|
| 26 |
+
[DETR](https://huggingface.co/papers/2005.12872) consists of a convolutional backbone followed by an encoder-decoder Transformer which can be trained end-to-end for object detection. It greatly simplifies a lot of the complexity of models like Faster-R-CNN and Mask-R-CNN, which use things like region proposals, non-maximum suppression procedure and anchor generation. Moreover, DETR can also be naturally extended to perform panoptic segmentation, by simply adding a mask head on top of the decoder outputs.
|
| 27 |
+
|
| 28 |
+
You can find all the original DETR checkpoints under the [AI at Meta](https://huggingface.co/facebook/models?search=detr) organization.
|
| 29 |
+
|
| 30 |
+
> [!TIP]
|
| 31 |
+
> This model was contributed by [nielsr](https://huggingface.co/nielsr).
|
| 32 |
+
>
|
| 33 |
+
> Click on the DETR models in the right sidebar for more examples of how to apply DETR to different object detection and segmentation tasks.
|
| 34 |
+
|
| 35 |
+
The example below demonstrates how to perform object detection with the [`Pipeline`] or the [`AutoModel`] class.
|
| 36 |
+
|
| 37 |
+
<hfoptions id="usage">
|
| 38 |
+
<hfoption id="Pipeline">
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from transformers import pipeline
|
| 42 |
+
import torch
|
| 43 |
+
|
| 44 |
+
pipeline = pipeline(
|
| 45 |
+
"object-detection",
|
| 46 |
+
model="facebook/detr-resnet-50",
|
| 47 |
+
torch_dtype=torch.float16,
|
| 48 |
+
device_map=0
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
pipeline("http://images.cocodataset.org/val2017/000000039769.jpg")
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
</hfoption>
|
| 55 |
+
<hfoption id="AutoModel">
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 59 |
+
from PIL import Image
|
| 60 |
+
import requests
|
| 61 |
+
import torch
|
| 62 |
+
|
| 63 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 64 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 65 |
+
|
| 66 |
+
image_processor = AutoImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 67 |
+
model = AutoModelForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
| 68 |
+
|
| 69 |
+
# prepare image for the model
|
| 70 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
| 71 |
+
|
| 72 |
+
with torch.no_grad():
|
| 73 |
+
outputs = model(**inputs)
|
| 74 |
+
|
| 75 |
+
results = image_processor.post_process_object_detection(outputs, target_sizes=torch.tensor([image.size[::-1]]), threshold=0.3)
|
| 76 |
+
|
| 77 |
+
for result in results:
|
| 78 |
+
for score, label_id, box in zip(result["scores"], result["labels"], result["boxes"]):
|
| 79 |
+
score, label = score.item(), label_id.item()
|
| 80 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 81 |
+
print(f"{model.config.id2label[label]}: {score:.2f} {box}")
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
</hfoption>
|
| 85 |
+
</hfoptions>
|
| 86 |
+
|
| 87 |
+
<details>
|
| 88 |
+
<summary>How DETR works</summary>
|
| 89 |
+
|
| 90 |
+
Here's a TLDR explaining how [`~transformers.DetrForObjectDetection`] works:
|
| 91 |
+
|
| 92 |
+
First, an image is sent through a pre-trained convolutional backbone (in the paper, the authors use ResNet-50/ResNet-101). Let's assume we also add a batch dimension. This means that the input to the backbone is a tensor of shape `(batch_size, 3, height, width)`, assuming the image has 3 color channels (RGB). The CNN backbone outputs a new lower-resolution feature map, typically of shape `(batch_size, 2048, height/32, width/32)`. This is then projected to match the hidden dimension of the Transformer of DETR, which is `256` by default, using a `nn.Conv2D` layer. So now, we have a tensor of shape `(batch_size, 256, height/32, width/32).` Next, the feature map is flattened and transposed to obtain a tensor of shape `(batch_size, seq_len, d_model)` = `(batch_size, width/32*height/32, 256)`. So a difference with NLP models is that the sequence length is actually longer than usual, but with a smaller `d_model` (which in NLP is typically 768 or higher).
|
| 93 |
+
|
| 94 |
+
Next, this is sent through the encoder, outputting `encoder_hidden_states` of the same shape (you can consider these as image features). Next, so-called **object queries** are sent through the decoder. This is a tensor of shape `(batch_size, num_queries, d_model)`, with `num_queries` typically set to 100 and initialized with zeros. These input embeddings are learnt positional encodings that the authors refer to as object queries, and similarly to the encoder, they are added to the input of each attention layer. Each object query will look for a particular object in the image. The decoder updates these embeddings through multiple self-attention and encoder-decoder attention layers to output `decoder_hidden_states` of the same shape: `(batch_size, num_queries, d_model)`. Next, two heads are added on top for object detection: a linear layer for classifying each object query into one of the objects or "no object", and a MLP to predict bounding boxes for each query.
|
| 95 |
+
|
| 96 |
+
The model is trained using a **bipartite matching loss**: so what we actually do is compare the predicted classes + bounding boxes of each of the N = 100 object queries to the ground truth annotations, padded up to the same length N (so if an image only contains 4 objects, 96 annotations will just have a "no object" as class and "no bounding box" as bounding box). The [Hungarian matching algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm) is used to find an optimal one-to-one mapping of each of the N queries to each of the N annotations. Next, standard cross-entropy (for the classes) and a linear combination of the L1 and [generalized IoU loss](https://giou.stanford.edu/) (for the bounding boxes) are used to optimize the parameters of the model.
|
| 97 |
+
|
| 98 |
+
DETR can be naturally extended to perform panoptic segmentation (which unifies semantic segmentation and instance segmentation). [`~transformers.DetrForSegmentation`] adds a segmentation mask head on top of [`~transformers.DetrForObjectDetection`]. The mask head can be trained either jointly, or in a two steps process, where one first trains a [`~transformers.DetrForObjectDetection`] model to detect bounding boxes around both "things" (instances) and "stuff" (background things like trees, roads, sky), then freeze all the weights and train only the mask head for 25 epochs. Experimentally, these two approaches give similar results. Note that predicting boxes is required for the training to be possible, since the Hungarian matching is computed using distances between boxes.
|
| 99 |
+
|
| 100 |
+
</details>
|
| 101 |
+
|
| 102 |
+
## Notes
|
| 103 |
+
|
| 104 |
+
- DETR uses so-called **object queries** to detect objects in an image. The number of queries determines the maximum number of objects that can be detected in a single image, and is set to 100 by default (see parameter `num_queries` of [`~transformers.DetrConfig`]). Note that it's good to have some slack (in COCO, the authors used 100, while the maximum number of objects in a COCO image is ~70).
|
| 105 |
+
- The decoder of DETR updates the query embeddings in parallel. This is different from language models like GPT-2, which use autoregressive decoding instead of parallel. Hence, no causal attention mask is used.
|
| 106 |
+
- DETR adds position embeddings to the hidden states at each self-attention and cross-attention layer before projecting to queries and keys. For the position embeddings of the image, one can choose between fixed sinusoidal or learned absolute position embeddings. By default, the parameter `position_embedding_type` of [`~transformers.DetrConfig`] is set to `"sine"`.
|
| 107 |
+
- During training, the authors of DETR did find it helpful to use auxiliary losses in the decoder, especially to help the model output the correct number of objects of each class. If you set the parameter `auxiliary_loss` of [`~transformers.DetrConfig`] to `True`, then prediction feedforward neural networks and Hungarian losses are added after each decoder layer (with the FFNs sharing parameters).
|
| 108 |
+
- If you want to train the model in a distributed environment across multiple nodes, then one should update the _num_boxes_ variable in the _DetrLoss_ class of _modeling_detr.py_. When training on multiple nodes, this should be set to the average number of target boxes across all nodes, as can be seen in the original implementation [here](https://github.com/facebookresearch/detr/blob/a54b77800eb8e64e3ad0d8237789fcbf2f8350c5/models/detr.py#L227-L232).
|
| 109 |
+
- [`~transformers.DetrForObjectDetection`] and [`~transformers.DetrForSegmentation`] can be initialized with any convolutional backbone available in the [timm library](https://github.com/rwightman/pytorch-image-models). Initializing with a MobileNet backbone for example can be done by setting the `backbone` attribute of [`~transformers.DetrConfig`] to `"tf_mobilenetv3_small_075"`, and then initializing the model with that config.
|
| 110 |
+
- DETR resizes the input images such that the shortest side is at least a certain amount of pixels while the longest is at most 1333 pixels. At training time, scale augmentation is used such that the shortest side is randomly set to at least 480 and at most 800 pixels. At inference time, the shortest side is set to 800. One can use [`~transformers.DetrImageProcessor`] to prepare images (and optional annotations in COCO format) for the model. Due to this resizing, images in a batch can have different sizes. DETR solves this by padding images up to the largest size in a batch, and by creating a pixel mask that indicates which pixels are real/which are padding. Alternatively, one can also define a custom `collate_fn` in order to batch images together, using [`~transformers.DetrImageProcessor.pad_and_create_pixel_mask`].
|
| 111 |
+
- The size of the images will determine the amount of memory being used, and will thus determine the `batch_size`. It is advised to use a batch size of 2 per GPU. See [this Github thread](https://github.com/facebookresearch/detr/issues/150) for more info.
|
| 112 |
+
|
| 113 |
+
There are three other ways to instantiate a DETR model (depending on what you prefer):
|
| 114 |
+
|
| 115 |
+
- Option 1: Instantiate DETR with pre-trained weights for entire model
|
| 116 |
+
```python
|
| 117 |
+
from transformers import DetrForObjectDetection
|
| 118 |
+
|
| 119 |
+
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
- Option 2: Instantiate DETR with randomly initialized weights for Transformer, but pre-trained weights for backbone
|
| 123 |
+
```python
|
| 124 |
+
from transformers import DetrConfig, DetrForObjectDetection
|
| 125 |
+
|
| 126 |
+
config = DetrConfig()
|
| 127 |
+
model = DetrForObjectDetection(config)
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
- Option 3: Instantiate DETR with randomly initialized weights for backbone + Transformer
|
| 131 |
+
```python
|
| 132 |
+
config = DetrConfig(use_pretrained_backbone=False)
|
| 133 |
+
model = DetrForObjectDetection(config)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
As a summary, consider the following table:
|
| 137 |
+
|
| 138 |
+
| Task | Object detection | Instance segmentation | Panoptic segmentation |
|
| 139 |
+
|------|------------------|-----------------------|-----------------------|
|
| 140 |
+
| **Description** | Predicting bounding boxes and class labels around objects in an image | Predicting masks around objects (i.e. instances) in an image | Predicting masks around both objects (i.e. instances) as well as "stuff" (i.e. background things like trees and roads) in an image |
|
| 141 |
+
| **Model** | [`~transformers.DetrForObjectDetection`] | [`~transformers.DetrForSegmentation`] | [`~transformers.DetrForSegmentation`] |
|
| 142 |
+
| **Example dataset** | COCO detection | COCO detection, COCO panoptic | COCO panoptic | |
|
| 143 |
+
| **Format of annotations to provide to** [`~transformers.DetrImageProcessor`] | {'image_id': `int`, 'annotations': `list[Dict]`} each Dict being a COCO object annotation | {'image_id': `int`, 'annotations': `list[Dict]`} (in case of COCO detection) or {'file_name': `str`, 'image_id': `int`, 'segments_info': `list[Dict]`} (in case of COCO panoptic) | {'file_name': `str`, 'image_id': `int`, 'segments_info': `list[Dict]`} and masks_path (path to directory containing PNG files of the masks) |
|
| 144 |
+
| **Postprocessing** (i.e. converting the output of the model to Pascal VOC format) | [`~transformers.DetrImageProcessor.post_process`] | [`~transformers.DetrImageProcessor.post_process_segmentation`] | [`~transformers.DetrImageProcessor.post_process_segmentation`], [`~transformers.DetrImageProcessor.post_process_panoptic`] |
|
| 145 |
+
| **evaluators** | `CocoEvaluator` with `iou_types="bbox"` | `CocoEvaluator` with `iou_types="bbox"` or `"segm"` | `CocoEvaluator` with `iou_tupes="bbox"` or `"segm"`, `PanopticEvaluator` |
|
| 146 |
+
|
| 147 |
+
- In short, one should prepare the data either in COCO detection or COCO panoptic format, then use [`~transformers.DetrImageProcessor`] to create `pixel_values`, `pixel_mask` and optional `labels`, which can then be used to train (or fine-tune) a model.
|
| 148 |
+
- For evaluation, one should first convert the outputs of the model using one of the postprocessing methods of [`~transformers.DetrImageProcessor`]. These can be provided to either `CocoEvaluator` or `PanopticEvaluator`, which allow you to calculate metrics like mean Average Precision (mAP) and Panoptic Quality (PQ). The latter objects are implemented in the [original repository](https://github.com/facebookresearch/detr). See the [example notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/DETR) for more info regarding evaluation.
|
| 149 |
+
|
| 150 |
+
## Resources
|
| 151 |
+
|
| 152 |
+
- Refer to these [notebooks](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/DETR) for examples of fine-tuning [`DetrForObjectDetection`] and [`DetrForSegmentation`] on a custom dataset.
|
| 153 |
+
|
| 154 |
+
## DetrConfig
|
| 155 |
+
|
| 156 |
+
[[autodoc]] DetrConfig
|
| 157 |
+
|
| 158 |
+
## DetrImageProcessor
|
| 159 |
+
|
| 160 |
+
[[autodoc]] DetrImageProcessor
|
| 161 |
+
- preprocess
|
| 162 |
+
- post_process_object_detection
|
| 163 |
+
- post_process_semantic_segmentation
|
| 164 |
+
- post_process_instance_segmentation
|
| 165 |
+
- post_process_panoptic_segmentation
|
| 166 |
+
|
| 167 |
+
## DetrImageProcessorFast
|
| 168 |
+
|
| 169 |
+
[[autodoc]] DetrImageProcessorFast
|
| 170 |
+
- preprocess
|
| 171 |
+
- post_process_object_detection
|
| 172 |
+
- post_process_semantic_segmentation
|
| 173 |
+
- post_process_instance_segmentation
|
| 174 |
+
- post_process_panoptic_segmentation
|
| 175 |
+
|
| 176 |
+
## DetrFeatureExtractor
|
| 177 |
+
|
| 178 |
+
[[autodoc]] DetrFeatureExtractor
|
| 179 |
+
- __call__
|
| 180 |
+
- post_process_object_detection
|
| 181 |
+
- post_process_semantic_segmentation
|
| 182 |
+
- post_process_instance_segmentation
|
| 183 |
+
- post_process_panoptic_segmentation
|
| 184 |
+
|
| 185 |
+
## DETR specific outputs
|
| 186 |
+
|
| 187 |
+
[[autodoc]] models.detr.modeling_detr.DetrModelOutput
|
| 188 |
+
|
| 189 |
+
[[autodoc]] models.detr.modeling_detr.DetrObjectDetectionOutput
|
| 190 |
+
|
| 191 |
+
[[autodoc]] models.detr.modeling_detr.DetrSegmentationOutput
|
| 192 |
+
|
| 193 |
+
## DetrModel
|
| 194 |
+
|
| 195 |
+
[[autodoc]] DetrModel
|
| 196 |
+
- forward
|
| 197 |
+
|
| 198 |
+
## DetrForObjectDetection
|
| 199 |
+
|
| 200 |
+
[[autodoc]] DetrForObjectDetection
|
| 201 |
+
- forward
|
| 202 |
+
|
| 203 |
+
## DetrForSegmentation
|
| 204 |
+
|
| 205 |
+
[[autodoc]] DetrForSegmentation
|
| 206 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dia.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2025-04-21 and added to Hugging Face Transformers on 2025-06-26.*
|
| 17 |
+
|
| 18 |
+
# Dia
|
| 19 |
+
|
| 20 |
+
<div style="float: right;">
|
| 21 |
+
<div class="flex flex-wrap space-x-1">
|
| 22 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 23 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 24 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
## Overview
|
| 29 |
+
|
| 30 |
+
[Dia](https://github.com/nari-labs/dia) is an open-source text-to-speech (TTS) model (1.6B parameters) developed by [Nari Labs](https://huggingface.co/nari-labs).
|
| 31 |
+
It can generate highly realistic dialogue from transcript including non-verbal communications such as laughter and coughing.
|
| 32 |
+
Furthermore, emotion and tone control is also possible via audio conditioning (voice cloning).
|
| 33 |
+
|
| 34 |
+
**Model Architecture:**
|
| 35 |
+
Dia is an encoder-decoder transformer based on the original transformer architecture. However, some more modern features such as
|
| 36 |
+
rotational positional embeddings (RoPE) are also included. For its text portion (encoder), a byte tokenizer is utilized while
|
| 37 |
+
for the audio portion (decoder), a pretrained codec model [DAC](./dac) is used - DAC encodes speech into discrete codebook
|
| 38 |
+
tokens and decodes them back into audio.
|
| 39 |
+
|
| 40 |
+
## Usage Tips
|
| 41 |
+
|
| 42 |
+
### Generation with Text
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from transformers import AutoProcessor, DiaForConditionalGeneration, infer_device
|
| 46 |
+
|
| 47 |
+
torch_device = infer_device()
|
| 48 |
+
model_checkpoint = "nari-labs/Dia-1.6B-0626"
|
| 49 |
+
|
| 50 |
+
text = ["[S1] Dia is an open weights text to dialogue model."]
|
| 51 |
+
processor = AutoProcessor.from_pretrained(model_checkpoint)
|
| 52 |
+
inputs = processor(text=text, padding=True, return_tensors="pt").to(torch_device)
|
| 53 |
+
|
| 54 |
+
model = DiaForConditionalGeneration.from_pretrained(model_checkpoint).to(torch_device)
|
| 55 |
+
outputs = model.generate(**inputs, max_new_tokens=256) # corresponds to around ~2s
|
| 56 |
+
|
| 57 |
+
# save audio to a file
|
| 58 |
+
outputs = processor.batch_decode(outputs)
|
| 59 |
+
processor.save_audio(outputs, "example.wav")
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### Generation with Text and Audio (Voice Cloning)
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
from datasets import load_dataset, Audio
|
| 67 |
+
from transformers import AutoProcessor, DiaForConditionalGeneration, infer_device
|
| 68 |
+
|
| 69 |
+
torch_device = infer_device()
|
| 70 |
+
model_checkpoint = "nari-labs/Dia-1.6B-0626"
|
| 71 |
+
|
| 72 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 73 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=44100))
|
| 74 |
+
audio = ds[-1]["audio"]["array"]
|
| 75 |
+
# text is a transcript of the audio + additional text you want as new audio
|
| 76 |
+
text = ["[S1] I know. It's going to save me a lot of money, I hope. [S2] I sure hope so for you."]
|
| 77 |
+
|
| 78 |
+
processor = AutoProcessor.from_pretrained(model_checkpoint)
|
| 79 |
+
inputs = processor(text=text, audio=audio, padding=True, return_tensors="pt").to(torch_device)
|
| 80 |
+
prompt_len = processor.get_audio_prompt_len(inputs["decoder_attention_mask"])
|
| 81 |
+
|
| 82 |
+
model = DiaForConditionalGeneration.from_pretrained(model_checkpoint).to(torch_device)
|
| 83 |
+
outputs = model.generate(**inputs, max_new_tokens=256) # corresponds to around ~2s
|
| 84 |
+
|
| 85 |
+
# retrieve actually generated audio and save to a file
|
| 86 |
+
outputs = processor.batch_decode(outputs, audio_prompt_len=prompt_len)
|
| 87 |
+
processor.save_audio(outputs, "example_with_audio.wav")
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Training
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
from datasets import load_dataset, Audio
|
| 94 |
+
from transformers import AutoProcessor, DiaForConditionalGeneration, infer_device
|
| 95 |
+
|
| 96 |
+
torch_device = infer_device()
|
| 97 |
+
model_checkpoint = "nari-labs/Dia-1.6B-0626"
|
| 98 |
+
|
| 99 |
+
ds = load_dataset("hf-internal-testing/dailytalk-dummy", split="train")
|
| 100 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=44100))
|
| 101 |
+
audio = ds[-1]["audio"]["array"]
|
| 102 |
+
# text is a transcript of the audio
|
| 103 |
+
text = ["[S1] I know. It's going to save me a lot of money, I hope."]
|
| 104 |
+
|
| 105 |
+
processor = AutoProcessor.from_pretrained(model_checkpoint)
|
| 106 |
+
inputs = processor(
|
| 107 |
+
text=text,
|
| 108 |
+
audio=audio,
|
| 109 |
+
generation=False,
|
| 110 |
+
output_labels=True,
|
| 111 |
+
padding=True,
|
| 112 |
+
return_tensors="pt"
|
| 113 |
+
).to(torch_device)
|
| 114 |
+
|
| 115 |
+
model = DiaForConditionalGeneration.from_pretrained(model_checkpoint).to(torch_device)
|
| 116 |
+
out = model(**inputs)
|
| 117 |
+
out.loss.backward()
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
This model was contributed by [Jaeyong Sung](https://huggingface.co/buttercrab), [Arthur Zucker](https://huggingface.co/ArthurZ),
|
| 122 |
+
and [Anton Vlasjuk](https://huggingface.co/AntonV). The original code can be found [here](https://github.com/nari-labs/dia/).
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
## DiaConfig
|
| 126 |
+
|
| 127 |
+
[[autodoc]] DiaConfig
|
| 128 |
+
|
| 129 |
+
## DiaDecoderConfig
|
| 130 |
+
|
| 131 |
+
[[autodoc]] DiaDecoderConfig
|
| 132 |
+
|
| 133 |
+
## DiaEncoderConfig
|
| 134 |
+
|
| 135 |
+
[[autodoc]] DiaEncoderConfig
|
| 136 |
+
|
| 137 |
+
## DiaTokenizer
|
| 138 |
+
|
| 139 |
+
[[autodoc]] DiaTokenizer
|
| 140 |
+
- __call__
|
| 141 |
+
|
| 142 |
+
## DiaFeatureExtractor
|
| 143 |
+
|
| 144 |
+
[[autodoc]] DiaFeatureExtractor
|
| 145 |
+
- __call__
|
| 146 |
+
|
| 147 |
+
## DiaProcessor
|
| 148 |
+
|
| 149 |
+
[[autodoc]] DiaProcessor
|
| 150 |
+
- __call__
|
| 151 |
+
- batch_decode
|
| 152 |
+
- decode
|
| 153 |
+
|
| 154 |
+
## DiaModel
|
| 155 |
+
|
| 156 |
+
[[autodoc]] DiaModel
|
| 157 |
+
- forward
|
| 158 |
+
|
| 159 |
+
## DiaForConditionalGeneration
|
| 160 |
+
|
| 161 |
+
[[autodoc]] DiaForConditionalGeneration
|
| 162 |
+
- forward
|
| 163 |
+
- generate
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dialogpt.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2019-11-01 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
# DialoGPT
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ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Q61PF43zyDg9Bm9+3NNySn78jMZUUkumqE4Gp7JmFOdP1vc8PpRrzj9+wPinCy8K1PiJ4aYbnTYpCCbDkBSbzhu2QJ1Gd82t8jI8TH51+OzvXoWbnXUOBkNW+0mWFwGcGOUVpU81/n3TOHb5oMt2FgYGjzau0Nif0Ss7Q3XB33hjjQHjHA5E5aOyIQc8CBrLdQSs3j92VG+3nNEjbkbdbBr9zm04ruvw37vh0QKOdeGIkckc80fX3KH/h7PT4BOjgCty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC
|
| 24 |
+
">
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
DialoGPT was proposed in [DialoGPT: Large-Scale Generative Pre-training for Conversational Response Generation](https://huggingface.co/papers/1911.00536) by Yizhe Zhang, Siqi Sun, Michel Galley, Yen-Chun Chen, Chris Brockett, Xiang Gao,
|
| 30 |
+
Jianfeng Gao, Jingjing Liu, Bill Dolan. It's a GPT2 Model trained on 147M conversation-like exchanges extracted from
|
| 31 |
+
Reddit.
|
| 32 |
+
|
| 33 |
+
The abstract from the paper is the following:
|
| 34 |
+
|
| 35 |
+
*We present a large, tunable neural conversational response generation model, DialoGPT (dialogue generative pre-trained
|
| 36 |
+
transformer). Trained on 147M conversation-like exchanges extracted from Reddit comment chains over a period spanning
|
| 37 |
+
from 2005 through 2017, DialoGPT extends the Hugging Face PyTorch transformer to attain a performance close to human
|
| 38 |
+
both in terms of automatic and human evaluation in single-turn dialogue settings. We show that conversational systems
|
| 39 |
+
that leverage DialoGPT generate more relevant, contentful and context-consistent responses than strong baseline
|
| 40 |
+
systems. The pre-trained model and training pipeline are publicly released to facilitate research into neural response
|
| 41 |
+
generation and the development of more intelligent open-domain dialogue systems.*
|
| 42 |
+
|
| 43 |
+
The original code can be found [here](https://github.com/microsoft/DialoGPT).
|
| 44 |
+
|
| 45 |
+
## Usage tips
|
| 46 |
+
|
| 47 |
+
- DialoGPT is a model with absolute position embeddings so it's usually advised to pad the inputs on the right rather
|
| 48 |
+
than the left.
|
| 49 |
+
- DialoGPT was trained with a causal language modeling (CLM) objective on conversational data and is therefore powerful
|
| 50 |
+
at response generation in open-domain dialogue systems.
|
| 51 |
+
- DialoGPT enables the user to create a chat bot in just 10 lines of code as shown on [DialoGPT's model card](https://huggingface.co/microsoft/DialoGPT-medium).
|
| 52 |
+
|
| 53 |
+
Training:
|
| 54 |
+
|
| 55 |
+
In order to train or fine-tune DialoGPT, one can use causal language modeling training. To cite the official paper: *We
|
| 56 |
+
follow the OpenAI GPT-2 to model a multiturn dialogue session as a long text and frame the generation task as language
|
| 57 |
+
modeling. We first concatenate all dialog turns within a dialogue session into a long text x_1,..., x_N (N is the
|
| 58 |
+
sequence length), ended by the end-of-text token.* For more information please confer to the original paper.
|
| 59 |
+
|
| 60 |
+
<Tip>
|
| 61 |
+
|
| 62 |
+
DialoGPT's architecture is based on the GPT2 model, refer to [GPT2's documentation page](gpt2) for API reference and examples.
|
| 63 |
+
|
| 64 |
+
</Tip>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/diffllama.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-10-07 and added to Hugging Face Transformers on 2025-01-07.*
|
| 17 |
+
|
| 18 |
+
# DiffLlama
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
## Overview
|
| 27 |
+
|
| 28 |
+
The DiffLlama model was proposed in [Differential Transformer](https://huggingface.co/papers/2410.05258) by Kazuma Matsumoto and .
|
| 29 |
+
This model is combine Llama model and Differential Transformer's Attention.
|
| 30 |
+
|
| 31 |
+
The abstract from the paper is the following:
|
| 32 |
+
|
| 33 |
+
*Transformer tends to overallocate attention to irrelevant context. In this work, we introduce Diff Transformer, which amplifies attention to the relevant context while canceling noise. Specifically, the differential attention mechanism calculates attention scores as the difference between two separate softmax attention maps. The subtraction cancels noise, promoting the emergence of sparse attention patterns. Experimental results on language modeling show that Diff Transformer outperforms Transformer in various settings of scaling up model size and training tokens. More intriguingly, it offers notable advantages in practical applications, such as long-context modeling, key information retrieval, hallucination mitigation, in-context learning, and reduction of activation outliers. By being less distracted by irrelevant context, Diff Transformer can mitigate hallucination in question answering and text summarization. For in-context learning, Diff Transformer not only enhances accuracy but is also more robust to order permutation, which was considered as a chronic robustness issue. The results position Diff Transformer as a highly effective and promising architecture to advance large language models.*
|
| 34 |
+
|
| 35 |
+
### Usage tips
|
| 36 |
+
The hyperparameters of this model is the same as Llama model.
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
## DiffLlamaConfig
|
| 40 |
+
|
| 41 |
+
[[autodoc]] DiffLlamaConfig
|
| 42 |
+
|
| 43 |
+
## DiffLlamaModel
|
| 44 |
+
|
| 45 |
+
[[autodoc]] DiffLlamaModel
|
| 46 |
+
- forward
|
| 47 |
+
|
| 48 |
+
## DiffLlamaForCausalLM
|
| 49 |
+
|
| 50 |
+
[[autodoc]] DiffLlamaForCausalLM
|
| 51 |
+
- forward
|
| 52 |
+
|
| 53 |
+
## DiffLlamaForSequenceClassification
|
| 54 |
+
|
| 55 |
+
[[autodoc]] DiffLlamaForSequenceClassification
|
| 56 |
+
- forward
|
| 57 |
+
|
| 58 |
+
## DiffLlamaForQuestionAnswering
|
| 59 |
+
|
| 60 |
+
[[autodoc]] DiffLlamaForQuestionAnswering
|
| 61 |
+
- forward
|
| 62 |
+
|
| 63 |
+
## DiffLlamaForTokenClassification
|
| 64 |
+
|
| 65 |
+
[[autodoc]] DiffLlamaForTokenClassification
|
| 66 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinat.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-09-29 and added to Hugging Face Transformers on 2022-11-18.*
|
| 17 |
+
|
| 18 |
+
# Dilated Neighborhood Attention Transformer
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
DiNAT was proposed in [Dilated Neighborhood Attention Transformer](https://huggingface.co/papers/2209.15001)
|
| 27 |
+
by Ali Hassani and Humphrey Shi.
|
| 28 |
+
|
| 29 |
+
It extends [NAT](nat) by adding a Dilated Neighborhood Attention pattern to capture global context,
|
| 30 |
+
and shows significant performance improvements over it.
|
| 31 |
+
|
| 32 |
+
The abstract from the paper is the following:
|
| 33 |
+
|
| 34 |
+
*Transformers are quickly becoming one of the most heavily applied deep learning architectures across modalities,
|
| 35 |
+
domains, and tasks. In vision, on top of ongoing efforts into plain transformers, hierarchical transformers have
|
| 36 |
+
also gained significant attention, thanks to their performance and easy integration into existing frameworks.
|
| 37 |
+
These models typically employ localized attention mechanisms, such as the sliding-window Neighborhood Attention (NA)
|
| 38 |
+
or Swin Transformer's Shifted Window Self Attention. While effective at reducing self attention's quadratic complexity,
|
| 39 |
+
local attention weakens two of the most desirable properties of self attention: long range inter-dependency modeling,
|
| 40 |
+
and global receptive field. In this paper, we introduce Dilated Neighborhood Attention (DiNA), a natural, flexible and
|
| 41 |
+
efficient extension to NA that can capture more global context and expand receptive fields exponentially at no
|
| 42 |
+
additional cost. NA's local attention and DiNA's sparse global attention complement each other, and therefore we
|
| 43 |
+
introduce Dilated Neighborhood Attention Transformer (DiNAT), a new hierarchical vision transformer built upon both.
|
| 44 |
+
DiNAT variants enjoy significant improvements over strong baselines such as NAT, Swin, and ConvNeXt.
|
| 45 |
+
Our large model is faster and ahead of its Swin counterpart by 1.5% box AP in COCO object detection,
|
| 46 |
+
1.3% mask AP in COCO instance segmentation, and 1.1% mIoU in ADE20K semantic segmentation.
|
| 47 |
+
Paired with new frameworks, our large variant is the new state of the art panoptic segmentation model on COCO (58.2 PQ)
|
| 48 |
+
and ADE20K (48.5 PQ), and instance segmentation model on Cityscapes (44.5 AP) and ADE20K (35.4 AP) (no extra data).
|
| 49 |
+
It also matches the state of the art specialized semantic segmentation models on ADE20K (58.2 mIoU),
|
| 50 |
+
and ranks second on Cityscapes (84.5 mIoU) (no extra data). *
|
| 51 |
+
|
| 52 |
+
<img
|
| 53 |
+
src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dilated-neighborhood-attention-pattern.jpg"
|
| 54 |
+
alt="drawing" width="600"/>
|
| 55 |
+
|
| 56 |
+
<small> Neighborhood Attention with different dilation values.
|
| 57 |
+
Taken from the <a href="https://huggingface.co/papers/2209.15001">original paper</a>.</small>
|
| 58 |
+
|
| 59 |
+
This model was contributed by [Ali Hassani](https://huggingface.co/alihassanijr).
|
| 60 |
+
The original code can be found [here](https://github.com/SHI-Labs/Neighborhood-Attention-Transformer).
|
| 61 |
+
|
| 62 |
+
## Usage tips
|
| 63 |
+
|
| 64 |
+
DiNAT can be used as a *backbone*. When `output_hidden_states = True`,
|
| 65 |
+
it will output both `hidden_states` and `reshaped_hidden_states`. The `reshaped_hidden_states` have a shape of `(batch, num_channels, height, width)` rather than `(batch_size, height, width, num_channels)`.
|
| 66 |
+
|
| 67 |
+
Notes:
|
| 68 |
+
- DiNAT depends on [NATTEN](https://github.com/SHI-Labs/NATTEN/)'s implementation of Neighborhood Attention and Dilated Neighborhood Attention.
|
| 69 |
+
You can install it with pre-built wheels for Linux by referring to [shi-labs.com/natten](https://shi-labs.com/natten), or build on your system by running `pip install natten`.
|
| 70 |
+
Note that the latter will likely take time to compile. NATTEN does not support Windows devices yet.
|
| 71 |
+
- Patch size of 4 is only supported at the moment.
|
| 72 |
+
|
| 73 |
+
## Resources
|
| 74 |
+
|
| 75 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DiNAT.
|
| 76 |
+
|
| 77 |
+
<PipelineTag pipeline="image-classification"/>
|
| 78 |
+
|
| 79 |
+
- [`DinatForImageClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb).
|
| 80 |
+
- See also: [Image classification task guide](../tasks/image_classification)
|
| 81 |
+
|
| 82 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 83 |
+
|
| 84 |
+
## DinatConfig
|
| 85 |
+
|
| 86 |
+
[[autodoc]] DinatConfig
|
| 87 |
+
|
| 88 |
+
## DinatModel
|
| 89 |
+
|
| 90 |
+
[[autodoc]] DinatModel
|
| 91 |
+
- forward
|
| 92 |
+
|
| 93 |
+
## DinatForImageClassification
|
| 94 |
+
|
| 95 |
+
[[autodoc]] DinatForImageClassification
|
| 96 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinov2.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
-->
|
| 12 |
+
*This model was released on 2023-04-14 and added to Hugging Face Transformers on 2023-07-18.*
|
| 13 |
+
|
| 14 |
+
<div style="float: right;">
|
| 15 |
+
<div class="flex flex-wrap space-x-1">
|
| 16 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 17 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ2QxLyKmsm3kL2xoMOehrRNb7RIbbOZgrGre68AUqwAqZqNN5aKJ5N/lMq+qsd8kMa4pcWzh7muhLMEV69juq2kbKqgUaOTR5uMMZWLLZSGAI5VAIdEAH+ovNDHuNCnxcy3qcaYx8K8msGplrx+wLahjbYdXrV6vbMvYK9DrZ8QrZ8tqJuFms+Sos6sw8ecy8RffsNVeMCvmb43aLltv7Q4Y7EZWK4QWa1gt6meZKUdr6GOAZVeA4xPAISyveLUwtivxtKTpNJ2jcq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MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC">
|
| 18 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 19 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# DINOv2
|
| 25 |
+
|
| 26 |
+
[DINOv2](https://huggingface.co/papers/2304.07193) is a vision foundation model that uses [ViT](./vit) as a feature extractor for multiple downstream tasks like image classification and depth estimation. It focuses on stabilizing and accelerating training through techniques like a faster memory-efficient attention, sequence packing, improved stochastic depth, Fully Sharded Data Parallel (FSDP), and model distillation.
|
| 27 |
+
|
| 28 |
+
You can find all the original DINOv2 checkpoints under the [Dinov2](https://huggingface.co/collections/facebook/dinov2-6526c98554b3d2576e071ce3) collection.
|
| 29 |
+
|
| 30 |
+
> [!TIP]
|
| 31 |
+
> Click on the DINOv2 models in the right sidebar for more examples of how to apply DINOv2 to different vision tasks.
|
| 32 |
+
|
| 33 |
+
The example below demonstrates how to obtain an image embedding with [`Pipeline`] or the [`AutoModel`] class.
|
| 34 |
+
|
| 35 |
+
<hfoptions id="usage">
|
| 36 |
+
<hfoption id="Pipeline">
|
| 37 |
+
|
| 38 |
+
```py
|
| 39 |
+
import torch
|
| 40 |
+
from transformers import pipeline
|
| 41 |
+
|
| 42 |
+
pipe = pipeline(
|
| 43 |
+
task="image-classification",
|
| 44 |
+
model="facebook/dinov2-small-imagenet1k-1-layer",
|
| 45 |
+
torch_dtype=torch.float16,
|
| 46 |
+
device=0
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
</hfoption>
|
| 53 |
+
<hfoption id="AutoModel">
|
| 54 |
+
|
| 55 |
+
```py
|
| 56 |
+
import requests
|
| 57 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 58 |
+
from PIL import Image
|
| 59 |
+
|
| 60 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 61 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 62 |
+
|
| 63 |
+
processor = AutoImageProcessor.from_pretrained("facebook/dinov2-small-imagenet1k-1-layer")
|
| 64 |
+
model = AutoModelForImageClassification.from_pretrained(
|
| 65 |
+
"facebook/dinov2-small-imagenet1k-1-layer",
|
| 66 |
+
torch_dtype=torch.float16,
|
| 67 |
+
device_map="auto",
|
| 68 |
+
attn_implementation="sdpa"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 72 |
+
logits = model(**inputs).logits
|
| 73 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 74 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
</hfoption>
|
| 78 |
+
</hfoptions>
|
| 79 |
+
|
| 80 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 81 |
+
|
| 82 |
+
The example below uses [torchao](../quantization/torchao) to only quantize the weights to int4.
|
| 83 |
+
|
| 84 |
+
```py
|
| 85 |
+
# pip install torchao
|
| 86 |
+
import requests
|
| 87 |
+
from transformers import TorchAoConfig, AutoImageProcessor, AutoModelForImageClassification
|
| 88 |
+
from torchao.quantization import Int4WeightOnlyConfig
|
| 89 |
+
from PIL import Image
|
| 90 |
+
|
| 91 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 92 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 93 |
+
|
| 94 |
+
processor = AutoImageProcessor.from_pretrained('facebook/dinov2-giant-imagenet1k-1-layer')
|
| 95 |
+
|
| 96 |
+
quant_config = Int4WeightOnlyConfig(group_size=128)
|
| 97 |
+
quantization_config = TorchAoConfig(quant_type=quant_config)
|
| 98 |
+
|
| 99 |
+
model = AutoModelForImageClassification.from_pretrained(
|
| 100 |
+
'facebook/dinov2-giant-imagenet1k-1-layer',
|
| 101 |
+
torch_dtype=torch.bfloat16,
|
| 102 |
+
device_map="auto",
|
| 103 |
+
quantization_config=quantization_config
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 107 |
+
outputs = model(**inputs)
|
| 108 |
+
logits = outputs.logits
|
| 109 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 110 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## Notes
|
| 114 |
+
|
| 115 |
+
- The example below shows how to split the output tensor into:
|
| 116 |
+
- one embedding for the whole image, commonly referred to as a `CLS` token,
|
| 117 |
+
useful for classification and retrieval
|
| 118 |
+
- a set of local embeddings, one for each `14x14` patch of the input image,
|
| 119 |
+
useful for dense tasks, such as semantic segmentation
|
| 120 |
+
|
| 121 |
+
```py
|
| 122 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 123 |
+
from PIL import Image
|
| 124 |
+
import requests
|
| 125 |
+
|
| 126 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 127 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 128 |
+
print(image.height, image.width) # [480, 640]
|
| 129 |
+
|
| 130 |
+
processor = AutoImageProcessor.from_pretrained('facebook/dinov2-base')
|
| 131 |
+
model = AutoModel.from_pretrained('facebook/dinov2-base')
|
| 132 |
+
patch_size = model.config.patch_size
|
| 133 |
+
|
| 134 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 135 |
+
print(inputs.pixel_values.shape) # [1, 3, 224, 224]
|
| 136 |
+
batch_size, rgb, img_height, img_width = inputs.pixel_values.shape
|
| 137 |
+
num_patches_height, num_patches_width = img_height // patch_size, img_width // patch_size
|
| 138 |
+
num_patches_flat = num_patches_height * num_patches_width
|
| 139 |
+
|
| 140 |
+
outputs = model(**inputs)
|
| 141 |
+
last_hidden_states = outputs[0]
|
| 142 |
+
print(last_hidden_states.shape) # [1, 1 + 256, 768]
|
| 143 |
+
assert last_hidden_states.shape == (batch_size, 1 + num_patches_flat, model.config.hidden_size)
|
| 144 |
+
|
| 145 |
+
cls_token = last_hidden_states[:, 0, :]
|
| 146 |
+
patch_features = last_hidden_states[:, 1:, :].unflatten(1, (num_patches_height, num_patches_width))
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
- Use [torch.jit.trace](https://pytorch.org/docs/stable/generated/torch.jit.trace.html) to speedup inference.
|
| 150 |
+
However, it will produce some mismatched elements. The difference between the original and traced model is 1e-4.
|
| 151 |
+
|
| 152 |
+
```py
|
| 153 |
+
import torch
|
| 154 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 155 |
+
from PIL import Image
|
| 156 |
+
import requests
|
| 157 |
+
|
| 158 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
| 159 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 160 |
+
|
| 161 |
+
processor = AutoImageProcessor.from_pretrained('facebook/dinov2-base')
|
| 162 |
+
model = AutoModel.from_pretrained('facebook/dinov2-base')
|
| 163 |
+
|
| 164 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 165 |
+
outputs = model(**inputs)
|
| 166 |
+
last_hidden_states = outputs[0]
|
| 167 |
+
|
| 168 |
+
# We have to force return_dict=False for tracing
|
| 169 |
+
model.config.return_dict = False
|
| 170 |
+
|
| 171 |
+
with torch.no_grad():
|
| 172 |
+
traced_model = torch.jit.trace(model, [inputs.pixel_values])
|
| 173 |
+
traced_outputs = traced_model(inputs.pixel_values)
|
| 174 |
+
|
| 175 |
+
print((last_hidden_states - traced_outputs[0]).abs().max())
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
## Dinov2Config
|
| 179 |
+
|
| 180 |
+
[[autodoc]] Dinov2Config
|
| 181 |
+
|
| 182 |
+
<frameworkcontent>
|
| 183 |
+
<pt>
|
| 184 |
+
|
| 185 |
+
## Dinov2Model
|
| 186 |
+
|
| 187 |
+
[[autodoc]] Dinov2Model
|
| 188 |
+
- forward
|
| 189 |
+
|
| 190 |
+
## Dinov2ForImageClassification
|
| 191 |
+
|
| 192 |
+
[[autodoc]] Dinov2ForImageClassification
|
| 193 |
+
- forward
|
| 194 |
+
|
| 195 |
+
</pt>
|
| 196 |
+
<jax>
|
| 197 |
+
|
| 198 |
+
## FlaxDinov2Model
|
| 199 |
+
|
| 200 |
+
[[autodoc]] FlaxDinov2Model
|
| 201 |
+
- __call__
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
## FlaxDinov2ForImageClassification
|
| 205 |
+
|
| 206 |
+
[[autodoc]] FlaxDinov2ForImageClassification
|
| 207 |
+
- __call__
|
| 208 |
+
|
| 209 |
+
</jax>
|
| 210 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dinov2_with_registers.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 3 |
+
the License. You may obtain a copy of the License at
|
| 4 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 5 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 6 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 7 |
+
specific language governing permissions and limitations under the License.
|
| 8 |
+
-->
|
| 9 |
+
*This model was released on 2023-09-28 and added to Hugging Face Transformers on 2024-12-24.*
|
| 10 |
+
|
| 11 |
+
# DINOv2 with Registers
|
| 12 |
+
|
| 13 |
+
<div class="flex flex-wrap space-x-1">
|
| 14 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 15 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 16 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
## Overview
|
| 20 |
+
|
| 21 |
+
The DINOv2 with Registers model was proposed in [Vision Transformers Need Registers](https://huggingface.co/papers/2309.16588) by Timothée Darcet, Maxime Oquab, Julien Mairal, Piotr Bojanowski.
|
| 22 |
+
|
| 23 |
+
The [Vision Transformer](vit) (ViT) is a transformer encoder model (BERT-like) originally introduced to do supervised image classification on ImageNet.
|
| 24 |
+
|
| 25 |
+
Next, people figured out ways to make ViT work really well on self-supervised image feature extraction (i.e. learning meaningful features, also called embeddings) on images without requiring any labels. Some example papers here include [DINOv2](dinov2) and [MAE](vit_mae).
|
| 26 |
+
|
| 27 |
+
The authors of DINOv2 noticed that ViTs have artifacts in attention maps. It’s due to the model using some image patches as “registers”. The authors propose a fix: just add some new tokens (called "register" tokens), which you only use during pre-training (and throw away afterwards). This results in:
|
| 28 |
+
- no artifacts
|
| 29 |
+
- interpretable attention maps
|
| 30 |
+
- and improved performances.
|
| 31 |
+
|
| 32 |
+
The abstract from the paper is the following:
|
| 33 |
+
|
| 34 |
+
*Transformers have recently emerged as a powerful tool for learning visual representations. In this paper, we identify and characterize artifacts in feature maps of both supervised and self-supervised ViT networks. The artifacts correspond to high-norm tokens appearing during inference primarily in low-informative background areas of images, that are repurposed for internal computations. We propose a simple yet effective solution based on providing additional tokens to the input sequence of the Vision Transformer to fill that role. We show that this solution fixes that problem entirely for both supervised and self-supervised models, sets a new state of the art for self-supervised visual models on dense visual prediction tasks, enables object discovery methods with larger models, and most importantly leads to smoother feature maps and attention maps for downstream visual processing.*
|
| 35 |
+
|
| 36 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/dinov2_with_registers_visualization.png"
|
| 37 |
+
alt="drawing" width="600"/>
|
| 38 |
+
|
| 39 |
+
<small> Visualization of attention maps of various models trained with vs. without registers. Taken from the <a href="https://huggingface.co/papers/2309.16588">original paper</a>. </small>
|
| 40 |
+
|
| 41 |
+
Tips:
|
| 42 |
+
|
| 43 |
+
- Usage of DINOv2 with Registers is identical to DINOv2 without, you'll just get better performance.
|
| 44 |
+
|
| 45 |
+
This model was contributed by [nielsr](https://huggingface.co/nielsr).
|
| 46 |
+
The original code can be found [here](https://github.com/facebookresearch/dinov2).
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Dinov2WithRegistersConfig
|
| 50 |
+
|
| 51 |
+
[[autodoc]] Dinov2WithRegistersConfig
|
| 52 |
+
|
| 53 |
+
## Dinov2WithRegistersModel
|
| 54 |
+
|
| 55 |
+
[[autodoc]] Dinov2WithRegistersModel
|
| 56 |
+
- forward
|
| 57 |
+
|
| 58 |
+
## Dinov2WithRegistersForImageClassification
|
| 59 |
+
|
| 60 |
+
[[autodoc]] Dinov2WithRegistersForImageClassification
|
| 61 |
+
- forward
|
tasks/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
-->
|
| 12 |
+
|
| 13 |
+
<div style="float: right;">
|
| 14 |
+
<div class="flex flex-wrap space-x-1">
|
| 15 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 16 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQ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tUEsCJZL6/3PR5b4syeSjZMQG/T2maGANlXT2v8S4AULWaUkCxfLyW8iW4kdka+nEMjxpL2NCwsYNBp+Q61PF43zyDg9Bm9+3NNySn78jMZUUkumqE4Gp7JmFOdP1vc8PpRrzj9+wPinCy8K1PiJ4aYbnTYpCCbDkBSbzhu2QJ1Gd82t8jI8TH51+OzvXoWbnXUOBkNW+0mWFwGcGOUVpU81/n3TOHb5oMt2FgYGjzau0Nif0Ss7Q3XB33hjjQHjHA5E5aOyIQc8CBrLdQSs3j92VG+3nNEjbkbdbBr9zm04ruvw37vh0QKOdeGIkckc80fX3KH/h7PT4BOjgCty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC">
|
| 17 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 18 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 19 |
+
</div>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# DINOv3
|
| 24 |
+
|
| 25 |
+
DINOv3 is a family of versatile vision foundation models that outperforms the specialized state of the art across a broad range of settings, without fine-tuning. DINOv3 produces high-quality dense features that achieve outstanding performance on various vision tasks, significantly surpassing previous self- and weakly-supervised foundation models.
|
| 26 |
+
|
| 27 |
+
You can find all the original DINOv3 checkpoints under the [DINOv3](https://huggingface.co/collections/facebook/dinov3-68924841bd6b561778e31009) collection.
|
| 28 |
+
|
| 29 |
+
> [!TIP]
|
| 30 |
+
> Click on the DINOv3 models in the right sidebar for more examples of how to apply DINOv3 to different vision tasks.
|
| 31 |
+
|
| 32 |
+
The example below demonstrates how to obtain an image embedding with [`Pipeline`] or the [`AutoModel`] class.
|
| 33 |
+
|
| 34 |
+
<hfoptions id="usage">
|
| 35 |
+
<hfoption id="Pipeline">
|
| 36 |
+
|
| 37 |
+
```py
|
| 38 |
+
import torch
|
| 39 |
+
from transformers import pipeline
|
| 40 |
+
|
| 41 |
+
pipe = pipeline(
|
| 42 |
+
task="image-feature-extraction",
|
| 43 |
+
model="facebook/dinov3-vits16-pretrain-lvd1689m",
|
| 44 |
+
torch_dtype=torch.bfloat16,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg")
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
</hfoption>
|
| 51 |
+
<hfoption id="AutoModel">
|
| 52 |
+
|
| 53 |
+
```py
|
| 54 |
+
import torch
|
| 55 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 56 |
+
from transformers.image_utils import load_image
|
| 57 |
+
|
| 58 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 59 |
+
image = load_image(url)
|
| 60 |
+
|
| 61 |
+
processor = AutoImageProcessor.from_pretrained("facebook/dinov3-vits16-pretrain-lvd1689m")
|
| 62 |
+
model = AutoModel.from_pretrained(
|
| 63 |
+
"facebook/dinov3-vits16-pretrain-lvd1689m",
|
| 64 |
+
torch_dtype=torch.float16,
|
| 65 |
+
device_map="auto",
|
| 66 |
+
attn_implementation="sdpa"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
inputs = processor(images=image, return_tensors="pt").to(model.device)
|
| 70 |
+
with torch.inference_mode():
|
| 71 |
+
outputs = model(**inputs)
|
| 72 |
+
|
| 73 |
+
pooled_output = outputs.pooler_output
|
| 74 |
+
print("Pooled output shape:", pooled_output.shape)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
</hfoption>
|
| 78 |
+
</hfoptions>
|
| 79 |
+
|
| 80 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 81 |
+
|
| 82 |
+
The example below uses [torchao](../quantization/torchao) to only quantize the weights to int4.
|
| 83 |
+
|
| 84 |
+
```py
|
| 85 |
+
# pip install torchao
|
| 86 |
+
import torch
|
| 87 |
+
from transformers import TorchAoConfig, AutoImageProcessor, AutoModel
|
| 88 |
+
from torchao.quantization import Int4WeightOnlyConfig
|
| 89 |
+
from transformers.image_utils import load_image
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 93 |
+
image = load_image(url)
|
| 94 |
+
|
| 95 |
+
processor = AutoImageProcessor.from_pretrained("facebook/dinov3-vitsplus-pretrain-lvd1689m")
|
| 96 |
+
|
| 97 |
+
quant_type = Int4WeightOnlyConfig(group_size=128)
|
| 98 |
+
quantization_config = TorchAoConfig(quant_type=quant_type)
|
| 99 |
+
|
| 100 |
+
model = AutoModel.from_pretrained(
|
| 101 |
+
"facebook/dinov3-vit7b16-pretrain-lvd1689m",
|
| 102 |
+
torch_dtype=torch.bfloat16,
|
| 103 |
+
device_map="auto",
|
| 104 |
+
quantization_config=quantization_config
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
inputs = processor(images=image, return_tensors="pt").to(model.device)
|
| 108 |
+
with torch.inference_mode():
|
| 109 |
+
outputs = model(**inputs)
|
| 110 |
+
|
| 111 |
+
pooled_output = outputs.pooler_output
|
| 112 |
+
print("Pooled output shape:", pooled_output.shape)
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Notes
|
| 116 |
+
|
| 117 |
+
- The example below shows how to split the output tensor into:
|
| 118 |
+
- one embedding for the whole image, commonly referred to as a `CLS` token,
|
| 119 |
+
useful for classification and retrieval
|
| 120 |
+
- register tokens - learnable embeddings that act as dedicated “memory slots” for global information,
|
| 121 |
+
they reduce high-norm artifacts in patch tokens, yielding cleaner attention maps and better
|
| 122 |
+
performance on dense prediction tasks.
|
| 123 |
+
- a set of local embeddings, one for each `16x16` patch of the input image,
|
| 124 |
+
useful for dense tasks, such as semantic segmentation
|
| 125 |
+
|
| 126 |
+
```py
|
| 127 |
+
import torch
|
| 128 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 129 |
+
from transformers.image_utils import load_image
|
| 130 |
+
|
| 131 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
| 132 |
+
image = load_image(url)
|
| 133 |
+
print("Image size:", image.height, image.width) # [480, 640]
|
| 134 |
+
|
| 135 |
+
processor = AutoImageProcessor.from_pretrained("facebook/dinov3-vits16-pretrain-lvd1689m")
|
| 136 |
+
model = AutoModel.from_pretrained("facebook/dinov3-vits16-pretrain-lvd1689m")
|
| 137 |
+
patch_size = model.config.patch_size
|
| 138 |
+
print("Patch size:", patch_size) # 16
|
| 139 |
+
print("Num register tokens:", model.config.num_register_tokens) # 4
|
| 140 |
+
|
| 141 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 142 |
+
print("Preprocessed image size:", inputs.pixel_values.shape) # [1, 3, 224, 224]
|
| 143 |
+
|
| 144 |
+
batch_size, _, img_height, img_width = inputs.pixel_values.shape
|
| 145 |
+
num_patches_height, num_patches_width = img_height // patch_size, img_width // patch_size
|
| 146 |
+
num_patches_flat = num_patches_height * num_patches_width
|
| 147 |
+
|
| 148 |
+
with torch.inference_mode():
|
| 149 |
+
outputs = model(**inputs)
|
| 150 |
+
|
| 151 |
+
last_hidden_states = outputs.last_hidden_state
|
| 152 |
+
print(last_hidden_states.shape) # [1, 1 + 4 + 256, 384]
|
| 153 |
+
assert last_hidden_states.shape == (batch_size, 1 + model.config.num_register_tokens + num_patches_flat, model.config.hidden_size)
|
| 154 |
+
|
| 155 |
+
cls_token = last_hidden_states[:, 0, :]
|
| 156 |
+
patch_features_flat = last_hidden_states[:, 1 + model.config.num_register_tokens:, :]
|
| 157 |
+
patch_features = patch_features_flat.unflatten(1, (num_patches_height, num_patches_width))
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## DINOv3ViTConfig
|
| 161 |
+
|
| 162 |
+
[[autodoc]] DINOv3ViTConfig
|
| 163 |
+
|
| 164 |
+
## DINOv3ConvNextConfig
|
| 165 |
+
|
| 166 |
+
[[autodoc]] DINOv3ConvNextConfig
|
| 167 |
+
|
| 168 |
+
## DINOv3ViTModel
|
| 169 |
+
|
| 170 |
+
[[autodoc]] DINOv3ViTModel
|
| 171 |
+
- forward
|
| 172 |
+
|
| 173 |
+
## DINOv3ConvNextModel
|
| 174 |
+
|
| 175 |
+
[[autodoc]] DINOv3ConvNextModel
|
| 176 |
+
- forward
|
| 177 |
+
|
| 178 |
+
## DINOv3ViTImageProcessorFast
|
| 179 |
+
|
| 180 |
+
[[autodoc]] DINOv3ViTImageProcessorFast
|
| 181 |
+
- preprocess
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/distilbert.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2019-10-02 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 22 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ2QxLyKmsm3kL2xoMOehrRNb7RIbbOZgrGre68AUqwAqZqNN5aKJ5N/lMq+qsd8kMa4pcWzh7muhLMEV69juq2kbKqgUaOTR5uMMZWLLZSGAI5VAIdEAH+ovNDHuNCnxcy3qcaYx8K8msGplrx+wLahjbYdXrV6vbMvYK9DrZ8QrZ8tqJuFms+Sos6sw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IQc8CBrLdQSs3j92VG+3nNEjbkbdbBr9zm04ruvw37vh0QKOdeGIkckc80fX3KH/h7PT4BOjgCty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
# DistilBERT
|
| 29 |
+
|
| 30 |
+
[DistilBERT](https://huggingface.co/papers/1910.01108) is pretrained by knowledge distillation to create a smaller model with faster inference and requires less compute to train. Through a triple loss objective during pretraining, language modeling loss, distillation loss, cosine-distance loss, DistilBERT demonstrates similar performance to a larger transformer language model.
|
| 31 |
+
|
| 32 |
+
You can find all the original DistilBERT checkpoints under the [DistilBERT](https://huggingface.co/distilbert) organization.
|
| 33 |
+
|
| 34 |
+
> [!TIP]
|
| 35 |
+
> Click on the DistilBERT models in the right sidebar for more examples of how to apply DistilBERT to different language tasks.
|
| 36 |
+
|
| 37 |
+
The example below demonstrates how to classify text with [`Pipeline`], [`AutoModel`], and from the command line.
|
| 38 |
+
|
| 39 |
+
<hfoptions id="usage">
|
| 40 |
+
|
| 41 |
+
<hfoption id="Pipeline">
|
| 42 |
+
|
| 43 |
+
```py
|
| 44 |
+
from transformers import pipeline
|
| 45 |
+
|
| 46 |
+
classifier = pipeline(
|
| 47 |
+
task="text-classification",
|
| 48 |
+
model="distilbert-base-uncased-finetuned-sst-2-english",
|
| 49 |
+
torch_dtype=torch.float16,
|
| 50 |
+
device=0
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
result = classifier("I love using Hugging Face Transformers!")
|
| 54 |
+
print(result)
|
| 55 |
+
# Output: [{'label': 'POSITIVE', 'score': 0.9998}]
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
</hfoption>
|
| 59 |
+
|
| 60 |
+
<hfoption id="AutoModel">
|
| 61 |
+
|
| 62 |
+
```py
|
| 63 |
+
import torch
|
| 64 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 65 |
+
|
| 66 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 67 |
+
"distilbert/distilbert-base-uncased-finetuned-sst-2-english",
|
| 68 |
+
)
|
| 69 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 70 |
+
"distilbert/distilbert-base-uncased-finetuned-sst-2-english",
|
| 71 |
+
torch_dtype=torch.float16,
|
| 72 |
+
device_map="auto",
|
| 73 |
+
attn_implementation="sdpa"
|
| 74 |
+
)
|
| 75 |
+
inputs = tokenizer("I love using Hugging Face Transformers!", return_tensors="pt").to(model.device)
|
| 76 |
+
|
| 77 |
+
with torch.no_grad():
|
| 78 |
+
outputs = model(**inputs)
|
| 79 |
+
|
| 80 |
+
predicted_class_id = torch.argmax(outputs.logits, dim=-1).item()
|
| 81 |
+
predicted_label = model.config.id2label[predicted_class_id]
|
| 82 |
+
print(f"Predicted label: {predicted_label}")
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
</hfoption>
|
| 86 |
+
|
| 87 |
+
<hfoption id="transformers CLI">
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
echo -e "I love using Hugging Face Transformers!" | transformers run --task text-classification --model distilbert-base-uncased-finetuned-sst-2-english
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
</hfoption>
|
| 94 |
+
|
| 95 |
+
</hfoptions>
|
| 96 |
+
|
| 97 |
+
## Notes
|
| 98 |
+
|
| 99 |
+
- DistilBERT doesn't have `token_type_ids`, you don't need to indicate which token belongs to which segment. Just
|
| 100 |
+
separate your segments with the separation token `tokenizer.sep_token` (or `[SEP]`).
|
| 101 |
+
- DistilBERT doesn't have options to select the input positions (`position_ids` input). This could be added if
|
| 102 |
+
necessary though, just let us know if you need this option.
|
| 103 |
+
|
| 104 |
+
## DistilBertConfig
|
| 105 |
+
|
| 106 |
+
[[autodoc]] DistilBertConfig
|
| 107 |
+
|
| 108 |
+
## DistilBertTokenizer
|
| 109 |
+
|
| 110 |
+
[[autodoc]] DistilBertTokenizer
|
| 111 |
+
|
| 112 |
+
## DistilBertTokenizerFast
|
| 113 |
+
|
| 114 |
+
[[autodoc]] DistilBertTokenizerFast
|
| 115 |
+
|
| 116 |
+
<frameworkcontent>
|
| 117 |
+
<pt>
|
| 118 |
+
|
| 119 |
+
## DistilBertModel
|
| 120 |
+
|
| 121 |
+
[[autodoc]] DistilBertModel
|
| 122 |
+
- forward
|
| 123 |
+
|
| 124 |
+
## DistilBertForMaskedLM
|
| 125 |
+
|
| 126 |
+
[[autodoc]] DistilBertForMaskedLM
|
| 127 |
+
- forward
|
| 128 |
+
|
| 129 |
+
## DistilBertForSequenceClassification
|
| 130 |
+
|
| 131 |
+
[[autodoc]] DistilBertForSequenceClassification
|
| 132 |
+
- forward
|
| 133 |
+
|
| 134 |
+
## DistilBertForMultipleChoice
|
| 135 |
+
|
| 136 |
+
[[autodoc]] DistilBertForMultipleChoice
|
| 137 |
+
- forward
|
| 138 |
+
|
| 139 |
+
## DistilBertForTokenClassification
|
| 140 |
+
|
| 141 |
+
[[autodoc]] DistilBertForTokenClassification
|
| 142 |
+
- forward
|
| 143 |
+
|
| 144 |
+
## DistilBertForQuestionAnswering
|
| 145 |
+
|
| 146 |
+
[[autodoc]] DistilBertForQuestionAnswering
|
| 147 |
+
- forward
|
| 148 |
+
|
| 149 |
+
</pt>
|
| 150 |
+
<tf>
|
| 151 |
+
|
| 152 |
+
## TFDistilBertModel
|
| 153 |
+
|
| 154 |
+
[[autodoc]] TFDistilBertModel
|
| 155 |
+
- call
|
| 156 |
+
|
| 157 |
+
## TFDistilBertForMaskedLM
|
| 158 |
+
|
| 159 |
+
[[autodoc]] TFDistilBertForMaskedLM
|
| 160 |
+
- call
|
| 161 |
+
|
| 162 |
+
## TFDistilBertForSequenceClassification
|
| 163 |
+
|
| 164 |
+
[[autodoc]] TFDistilBertForSequenceClassification
|
| 165 |
+
- call
|
| 166 |
+
|
| 167 |
+
## TFDistilBertForMultipleChoice
|
| 168 |
+
|
| 169 |
+
[[autodoc]] TFDistilBertForMultipleChoice
|
| 170 |
+
- call
|
| 171 |
+
|
| 172 |
+
## TFDistilBertForTokenClassification
|
| 173 |
+
|
| 174 |
+
[[autodoc]] TFDistilBertForTokenClassification
|
| 175 |
+
- call
|
| 176 |
+
|
| 177 |
+
## TFDistilBertForQuestionAnswering
|
| 178 |
+
|
| 179 |
+
[[autodoc]] TFDistilBertForQuestionAnswering
|
| 180 |
+
- call
|
| 181 |
+
|
| 182 |
+
</tf>
|
| 183 |
+
<jax>
|
| 184 |
+
|
| 185 |
+
## FlaxDistilBertModel
|
| 186 |
+
|
| 187 |
+
[[autodoc]] FlaxDistilBertModel
|
| 188 |
+
- __call__
|
| 189 |
+
|
| 190 |
+
## FlaxDistilBertForMaskedLM
|
| 191 |
+
|
| 192 |
+
[[autodoc]] FlaxDistilBertForMaskedLM
|
| 193 |
+
- __call__
|
| 194 |
+
|
| 195 |
+
## FlaxDistilBertForSequenceClassification
|
| 196 |
+
|
| 197 |
+
[[autodoc]] FlaxDistilBertForSequenceClassification
|
| 198 |
+
- __call__
|
| 199 |
+
|
| 200 |
+
## FlaxDistilBertForMultipleChoice
|
| 201 |
+
|
| 202 |
+
[[autodoc]] FlaxDistilBertForMultipleChoice
|
| 203 |
+
- __call__
|
| 204 |
+
|
| 205 |
+
## FlaxDistilBertForTokenClassification
|
| 206 |
+
|
| 207 |
+
[[autodoc]] FlaxDistilBertForTokenClassification
|
| 208 |
+
- __call__
|
| 209 |
+
|
| 210 |
+
## FlaxDistilBertForQuestionAnswering
|
| 211 |
+
|
| 212 |
+
[[autodoc]] FlaxDistilBertForQuestionAnswering
|
| 213 |
+
- __call__
|
| 214 |
+
|
| 215 |
+
</jax>
|
| 216 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dit.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-03-04 and added to Hugging Face Transformers on 2022-03-10.*
|
| 17 |
+
<div style="float: right;">
|
| 18 |
+
<div class="flex flex-wrap space-x-1">
|
| 19 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 20 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ2QxLyKmsm3kL2xoMOehrRNb7RIbbOZgrGre68AUqwAqZqNN5aKJ5N/lMq+qsd8kMa4pcWzh7muhLMEV69juq2kbKqgUaOTR5uMMZWLLZSGAI5VAIdEAH+ovNDHuNCnxcy3qcaYx8K8msGplrx+wLahjbYdXrV6vbMvYK9DrZ8QrZ8tqJuFms+Sos6sw8ecy8RffsNVeMCvmb43aLltv7Q4Y7EZWK4QWa1gt6meZKUdr6GOAZVeA4xPAISyveLUwtivxt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Cty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC
|
| 21 |
+
">
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
# DiT
|
| 26 |
+
|
| 27 |
+
[DiT](https://huggingface.co/papers/2203.02378) is an image transformer pretrained on large-scale unlabeled document images. It learns to predict the missing visual tokens from a corrupted input image. The pretrained DiT model can be used as a backbone in other models for visual document tasks like document image classification and table detection.
|
| 28 |
+
|
| 29 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dit_architecture.jpg"/>
|
| 30 |
+
|
| 31 |
+
You can find all the original DiT checkpoints under the [Microsoft](https://huggingface.co/microsoft?search_models=dit) organization.
|
| 32 |
+
|
| 33 |
+
> [!TIP]
|
| 34 |
+
> Refer to the [BEiT](./beit) docs for more examples of how to apply DiT to different vision tasks.
|
| 35 |
+
|
| 36 |
+
The example below demonstrates how to classify an image with [`Pipeline`] or the [`AutoModel`] class.
|
| 37 |
+
|
| 38 |
+
<hfoptions id="usage">
|
| 39 |
+
<hfoption id="Pipeline">
|
| 40 |
+
|
| 41 |
+
```py
|
| 42 |
+
import torch
|
| 43 |
+
from transformers import pipeline
|
| 44 |
+
|
| 45 |
+
pipeline = pipeline(
|
| 46 |
+
task="image-classification",
|
| 47 |
+
model="microsoft/dit-base-finetuned-rvlcdip",
|
| 48 |
+
torch_dtype=torch.float16,
|
| 49 |
+
device=0
|
| 50 |
+
)
|
| 51 |
+
pipeline("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/dit-example.jpg")
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
</hfoption>
|
| 55 |
+
<hfoption id="AutoModel">
|
| 56 |
+
|
| 57 |
+
```py
|
| 58 |
+
import torch
|
| 59 |
+
import requests
|
| 60 |
+
from PIL import Image
|
| 61 |
+
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 62 |
+
|
| 63 |
+
image_processor = AutoImageProcessor.from_pretrained(
|
| 64 |
+
"microsoft/dit-base-finetuned-rvlcdip",
|
| 65 |
+
use_fast=True,
|
| 66 |
+
)
|
| 67 |
+
model = AutoModelForImageClassification.from_pretrained(
|
| 68 |
+
"microsoft/dit-base-finetuned-rvlcdip",
|
| 69 |
+
device_map="auto",
|
| 70 |
+
)
|
| 71 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/dit-example.jpg"
|
| 72 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 73 |
+
inputs = image_processor(image, return_tensors="pt").to(model.device)
|
| 74 |
+
|
| 75 |
+
with torch.no_grad():
|
| 76 |
+
logits = model(**inputs).logits
|
| 77 |
+
predicted_class_id = logits.argmax(dim=-1).item()
|
| 78 |
+
|
| 79 |
+
class_labels = model.config.id2label
|
| 80 |
+
predicted_class_label = class_labels[predicted_class_id]
|
| 81 |
+
print(f"The predicted class label is: {predicted_class_label}")
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
</hfoption>
|
| 85 |
+
</hfoptions>
|
| 86 |
+
|
| 87 |
+
## Notes
|
| 88 |
+
|
| 89 |
+
- The pretrained DiT weights can be loaded in a [BEiT] model with a modeling head to predict visual tokens.
|
| 90 |
+
```py
|
| 91 |
+
from transformers import BeitForMaskedImageModeling
|
| 92 |
+
|
| 93 |
+
model = BeitForMaskedImageModeling.from_pretraining("microsoft/dit-base")
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Resources
|
| 97 |
+
|
| 98 |
+
- Refer to this [notebook](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/DiT/Inference_with_DiT_(Document_Image_Transformer)_for_document_image_classification.ipynb) for a document image classification inference example.
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/doge.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2024-12-27 and added to Hugging Face Transformers on 2025-07-08.*
|
| 17 |
+
|
| 18 |
+
# Doge
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
## Overview
|
| 22 |
+
|
| 23 |
+
Doge is a series of small language models based on the [Doge](https://github.com/SmallDoges/small-doge) architecture, aiming to combine the advantages of state-space and self-attention algorithms, calculate dynamic masks from cached value states using the zero-order hold method, and solve the problem of existing mainstream language models getting lost in context. It uses the `wsd_scheduler` scheduler to pre-train on the `smollm-corpus`, and can continue training on new datasets or add sparse activation feedforward networks from stable stage checkpoints.
|
| 24 |
+
|
| 25 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/refs%2Fpr%2F426/transformers/model_doc/doge_architecture.png" alt="drawing" width="600"/>
|
| 26 |
+
|
| 27 |
+
As shown in the figure below, the sequence transformation part of the Doge architecture uses `Dynamic Mask Attention`, which can be understood as using self-attention related to value states during training, and using state-space without past state decay during inference, to solve the problem of existing Transformers or SSMs getting lost in long text. The state transformation part of Doge uses `Cross Domain Mixture of Experts`, which consists of dense linear layers and sparse embedding layers, and can additionally increase sparse parameters to continue training from dense weight checkpoints without retraining the entire model, thereby reducing the cost of continuous iteration of the model. In addition, Doge also uses `RMSNorm` and `Residual` with learnable parameters to adapt the gradient range of deep models.
|
| 28 |
+
|
| 29 |
+
Checkout all Doge model checkpoints [here](https://huggingface.co/collections/SmallDoge/doge-slm-679cc991f027c4a3abbded4a).
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
<details>
|
| 35 |
+
<summary>Using Doge-Base for text generation</summary>
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 39 |
+
|
| 40 |
+
tokenizer = AutoTokenizer.from_pretrained("SmallDoge/Doge-20M")
|
| 41 |
+
model = AutoModelForCausalLM.from_pretrained("SmallDoge/Doge-20M")
|
| 42 |
+
inputs = tokenizer("Hey how are you doing?", return_tensors="pt")
|
| 43 |
+
|
| 44 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 45 |
+
print(tokenizer.batch_decode(outputs))
|
| 46 |
+
```
|
| 47 |
+
</details>
|
| 48 |
+
|
| 49 |
+
<details>
|
| 50 |
+
<summary>Using Doge-Instruct for question answering</summary>
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig, TextStreamer
|
| 54 |
+
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained("SmallDoge/Doge-20M-Instruct")
|
| 56 |
+
model = AutoModelForCausalLM.from_pretrained("SmallDoge/Doge-20M-Instruct")
|
| 57 |
+
|
| 58 |
+
generation_config = GenerationConfig(
|
| 59 |
+
max_new_tokens=100,
|
| 60 |
+
use_cache=True,
|
| 61 |
+
do_sample=True,
|
| 62 |
+
temperature=0.8,
|
| 63 |
+
top_p=0.9,
|
| 64 |
+
repetition_penalty=1.0
|
| 65 |
+
)
|
| 66 |
+
steamer = TextStreamer(tokenizer=tokenizer, skip_prompt=True)
|
| 67 |
+
|
| 68 |
+
prompt = "Hi, how are you doing today?"
|
| 69 |
+
conversation = [
|
| 70 |
+
{"role": "user", "content": prompt}
|
| 71 |
+
]
|
| 72 |
+
inputs = tokenizer.apply_chat_template(
|
| 73 |
+
conversation=conversation,
|
| 74 |
+
tokenize=True,
|
| 75 |
+
return_tensors="pt",
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
outputs = model.generate(
|
| 79 |
+
inputs,
|
| 80 |
+
tokenizer=tokenizer,
|
| 81 |
+
generation_config=generation_config,
|
| 82 |
+
streamer=steamer
|
| 83 |
+
)
|
| 84 |
+
```
|
| 85 |
+
</details>
|
| 86 |
+
|
| 87 |
+
## DogeConfig
|
| 88 |
+
|
| 89 |
+
[[autodoc]] DogeConfig
|
| 90 |
+
|
| 91 |
+
## DogeModel
|
| 92 |
+
|
| 93 |
+
[[autodoc]] DogeModel
|
| 94 |
+
- forward
|
| 95 |
+
|
| 96 |
+
## DogeForCausalLM
|
| 97 |
+
|
| 98 |
+
[[autodoc]] DogeForCausalLM
|
| 99 |
+
- forward
|
| 100 |
+
|
| 101 |
+
## DogeForSequenceClassification
|
| 102 |
+
|
| 103 |
+
[[autodoc]] DogeForSequenceClassification
|
| 104 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/donut.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
|
| 4 |
+
License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
| 9 |
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
|
| 11 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 12 |
+
rendered properly in your Markdown viewer.
|
| 13 |
+
|
| 14 |
+
specific language governing permissions and limitations under the License. -->
|
| 15 |
+
*This model was released on 2021-11-30 and added to Hugging Face Transformers on 2022-08-12.*
|
| 16 |
+
|
| 17 |
+
<div style="float: right;">
|
| 18 |
+
<div class="flex flex-wrap space-x-1">
|
| 19 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
# Donut
|
| 24 |
+
|
| 25 |
+
[Donut (Document Understanding Transformer)](https://huggingface.co/papers/2111.15664) is a visual document understanding model that doesn't require an Optical Character Recognition (OCR) engine. Unlike traditional approaches that extract text using OCR before processing, Donut employs an end-to-end Transformer-based architecture to directly analyze document images. This eliminates OCR-related inefficiencies making it more accurate and adaptable to diverse languages and formats.
|
| 26 |
+
|
| 27 |
+
Donut features vision encoder ([Swin](./swin)) and a text decoder ([BART](./bart)). Swin converts document images into embeddings and BART processes them into meaningful text sequences.
|
| 28 |
+
|
| 29 |
+
You can find all the original Donut checkpoints under the [Naver Clova Information Extraction](https://huggingface.co/naver-clova-ix) organization.
|
| 30 |
+
|
| 31 |
+
> [!TIP]
|
| 32 |
+
> Click on the Donut models in the right sidebar for more examples of how to apply Donut to different language and vision tasks.
|
| 33 |
+
|
| 34 |
+
The examples below demonstrate how to perform document understanding tasks using Donut with [`Pipeline`] and [`AutoModel`]
|
| 35 |
+
|
| 36 |
+
<hfoptions id="usage">
|
| 37 |
+
<hfoption id="Pipeline">
|
| 38 |
+
|
| 39 |
+
```py
|
| 40 |
+
# pip install datasets
|
| 41 |
+
import torch
|
| 42 |
+
from transformers import pipeline
|
| 43 |
+
from PIL import Image
|
| 44 |
+
|
| 45 |
+
pipeline = pipeline(
|
| 46 |
+
task="document-question-answering",
|
| 47 |
+
model="naver-clova-ix/donut-base-finetuned-docvqa",
|
| 48 |
+
device=0,
|
| 49 |
+
torch_dtype=torch.float16
|
| 50 |
+
)
|
| 51 |
+
dataset = load_dataset("hf-internal-testing/example-documents", split="test")
|
| 52 |
+
image = dataset[0]["image"]
|
| 53 |
+
|
| 54 |
+
pipeline(image=image, question="What time is the coffee break?")
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
</hfoption>
|
| 58 |
+
<hfoption id="AutoModel">
|
| 59 |
+
|
| 60 |
+
```py
|
| 61 |
+
# pip install datasets
|
| 62 |
+
import torch
|
| 63 |
+
from datasets import load_dataset
|
| 64 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 65 |
+
|
| 66 |
+
processor = AutoProcessor.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa")
|
| 67 |
+
model = AutoModelForVision2Seq.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa")
|
| 68 |
+
|
| 69 |
+
dataset = load_dataset("hf-internal-testing/example-documents", split="test")
|
| 70 |
+
image = dataset[0]["image"]
|
| 71 |
+
question = "What time is the coffee break?"
|
| 72 |
+
task_prompt = f"<s_docvqa><s_question>{question}</s_question><s_answer>"
|
| 73 |
+
inputs = processor(image, task_prompt, return_tensors="pt")
|
| 74 |
+
|
| 75 |
+
outputs = model.generate(
|
| 76 |
+
input_ids=inputs.input_ids,
|
| 77 |
+
pixel_values=inputs.pixel_values,
|
| 78 |
+
max_length=512
|
| 79 |
+
)
|
| 80 |
+
answer = processor.decode(outputs[0], skip_special_tokens=True)
|
| 81 |
+
print(answer)
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
</hfoption>
|
| 85 |
+
</hfoptions>
|
| 86 |
+
|
| 87 |
+
Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the [Quantization](../quantization/overview) overview for more available quantization backends.
|
| 88 |
+
|
| 89 |
+
The example below uses [torchao](../quantization/torchao) to only quantize the weights to int4.
|
| 90 |
+
|
| 91 |
+
```py
|
| 92 |
+
# pip install datasets torchao
|
| 93 |
+
import torch
|
| 94 |
+
from datasets import load_dataset
|
| 95 |
+
from transformers import TorchAoConfig, AutoProcessor, AutoModelForVision2Seq
|
| 96 |
+
|
| 97 |
+
quantization_config = TorchAoConfig("int4_weight_only", group_size=128)
|
| 98 |
+
processor = AutoProcessor.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa")
|
| 99 |
+
model = AutoModelForVision2Seq.from_pretrained("naver-clova-ix/donut-base-finetuned-docvqa", quantization_config=quantization_config)
|
| 100 |
+
|
| 101 |
+
dataset = load_dataset("hf-internal-testing/example-documents", split="test")
|
| 102 |
+
image = dataset[0]["image"]
|
| 103 |
+
question = "What time is the coffee break?"
|
| 104 |
+
task_prompt = f"<s_docvqa><s_question>{question}</s_question><s_answer>"
|
| 105 |
+
inputs = processor(image, task_prompt, return_tensors="pt")
|
| 106 |
+
|
| 107 |
+
outputs = model.generate(
|
| 108 |
+
input_ids=inputs.input_ids,
|
| 109 |
+
pixel_values=inputs.pixel_values,
|
| 110 |
+
max_length=512
|
| 111 |
+
)
|
| 112 |
+
answer = processor.decode(outputs[0], skip_special_tokens=True)
|
| 113 |
+
print(answer)
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Notes
|
| 117 |
+
|
| 118 |
+
- Use Donut for document image classification as shown below.
|
| 119 |
+
|
| 120 |
+
```py
|
| 121 |
+
>>> import re
|
| 122 |
+
>>> from transformers import DonutProcessor, VisionEncoderDecoderModel, infer_device
|
| 123 |
+
>>> from datasets import load_dataset
|
| 124 |
+
>>> import torch
|
| 125 |
+
|
| 126 |
+
>>> processor = DonutProcessor.from_pretrained("naver-clova-ix/donut-base-finetuned-rvlcdip")
|
| 127 |
+
>>> model = VisionEncoderDecoderModel.from_pretrained("naver-clova-ix/donut-base-finetuned-rvlcdip")
|
| 128 |
+
|
| 129 |
+
>>> device = infer_device()
|
| 130 |
+
>>> model.to(device) # doctest: +IGNORE_RESULT
|
| 131 |
+
|
| 132 |
+
>>> # load document image
|
| 133 |
+
>>> dataset = load_dataset("hf-internal-testing/example-documents", split="test")
|
| 134 |
+
>>> image = dataset[1]["image"]
|
| 135 |
+
|
| 136 |
+
>>> # prepare decoder inputs
|
| 137 |
+
>>> task_prompt = "<s_rvlcdip>"
|
| 138 |
+
>>> decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt").input_ids
|
| 139 |
+
|
| 140 |
+
>>> pixel_values = processor(image, return_tensors="pt").pixel_values
|
| 141 |
+
|
| 142 |
+
>>> outputs = model.generate(
|
| 143 |
+
... pixel_values.to(device),
|
| 144 |
+
... decoder_input_ids=decoder_input_ids.to(device),
|
| 145 |
+
... max_length=model.decoder.config.max_position_embeddings,
|
| 146 |
+
... pad_token_id=processor.tokenizer.pad_token_id,
|
| 147 |
+
... eos_token_id=processor.tokenizer.eos_token_id,
|
| 148 |
+
... use_cache=True,
|
| 149 |
+
... bad_words_ids=[[processor.tokenizer.unk_token_id]],
|
| 150 |
+
... return_dict_in_generate=True,
|
| 151 |
+
... )
|
| 152 |
+
|
| 153 |
+
>>> sequence = processor.batch_decode(outputs.sequences)[0]
|
| 154 |
+
>>> sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
|
| 155 |
+
>>> sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
| 156 |
+
>>> print(processor.token2json(sequence))
|
| 157 |
+
{'class': 'advertisement'}
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
- Use Donut for document parsing as shown below.
|
| 161 |
+
|
| 162 |
+
```py
|
| 163 |
+
>>> import re
|
| 164 |
+
>>> from transformers import DonutProcessor, VisionEncoderDecoderModel, infer_device
|
| 165 |
+
>>> from datasets import load_dataset
|
| 166 |
+
>>> import torch
|
| 167 |
+
|
| 168 |
+
>>> processor = DonutProcessor.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
|
| 169 |
+
>>> model = VisionEncoderDecoderModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
|
| 170 |
+
|
| 171 |
+
>>> device = infer_device()
|
| 172 |
+
>>> model.to(device) # doctest: +IGNORE_RESULT
|
| 173 |
+
|
| 174 |
+
>>> # load document image
|
| 175 |
+
>>> dataset = load_dataset("hf-internal-testing/example-documents", split="test")
|
| 176 |
+
>>> image = dataset[2]["image"]
|
| 177 |
+
|
| 178 |
+
>>> # prepare decoder inputs
|
| 179 |
+
>>> task_prompt = "<s_cord-v2>"
|
| 180 |
+
>>> decoder_input_ids = processor.tokenizer(task_prompt, add_special_tokens=False, return_tensors="pt").input_ids
|
| 181 |
+
|
| 182 |
+
>>> pixel_values = processor(image, return_tensors="pt").pixel_values
|
| 183 |
+
|
| 184 |
+
>>> outputs = model.generate(
|
| 185 |
+
... pixel_values.to(device),
|
| 186 |
+
... decoder_input_ids=decoder_input_ids.to(device),
|
| 187 |
+
... max_length=model.decoder.config.max_position_embeddings,
|
| 188 |
+
... pad_token_id=processor.tokenizer.pad_token_id,
|
| 189 |
+
... eos_token_id=processor.tokenizer.eos_token_id,
|
| 190 |
+
... use_cache=True,
|
| 191 |
+
... bad_words_ids=[[processor.tokenizer.unk_token_id]],
|
| 192 |
+
... return_dict_in_generate=True,
|
| 193 |
+
... )
|
| 194 |
+
|
| 195 |
+
>>> sequence = processor.batch_decode(outputs.sequences)[0]
|
| 196 |
+
>>> sequence = sequence.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
|
| 197 |
+
>>> sequence = re.sub(r"<.*?>", "", sequence, count=1).strip() # remove first task start token
|
| 198 |
+
>>> print(processor.token2json(sequence))
|
| 199 |
+
{'menu': {'nm': 'CINNAMON SUGAR', 'unitprice': '17,000', 'cnt': '1 x', 'price': '17,000'}, 'sub_total': {'subtotal_price': '17,000'}, 'total':
|
| 200 |
+
{'total_price': '17,000', 'cashprice': '20,000', 'changeprice': '3,000'}}
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
## DonutSwinConfig
|
| 204 |
+
|
| 205 |
+
[[autodoc]] DonutSwinConfig
|
| 206 |
+
|
| 207 |
+
## DonutImageProcessor
|
| 208 |
+
|
| 209 |
+
[[autodoc]] DonutImageProcessor
|
| 210 |
+
- preprocess
|
| 211 |
+
|
| 212 |
+
## DonutImageProcessorFast
|
| 213 |
+
|
| 214 |
+
[[autodoc]] DonutImageProcessorFast
|
| 215 |
+
- preprocess
|
| 216 |
+
|
| 217 |
+
## DonutFeatureExtractor
|
| 218 |
+
|
| 219 |
+
[[autodoc]] DonutFeatureExtractor
|
| 220 |
+
- __call__
|
| 221 |
+
|
| 222 |
+
## DonutProcessor
|
| 223 |
+
|
| 224 |
+
[[autodoc]] DonutProcessor
|
| 225 |
+
- __call__
|
| 226 |
+
- from_pretrained
|
| 227 |
+
- save_pretrained
|
| 228 |
+
- batch_decode
|
| 229 |
+
- decode
|
| 230 |
+
|
| 231 |
+
## DonutSwinModel
|
| 232 |
+
|
| 233 |
+
[[autodoc]] DonutSwinModel
|
| 234 |
+
- forward
|
| 235 |
+
|
| 236 |
+
## DonutSwinForImageClassification
|
| 237 |
+
|
| 238 |
+
[[autodoc]] transformers.DonutSwinForImageClassification
|
| 239 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dots1.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2025-06-06 and added to Hugging Face Transformers on 2025-06-25.*
|
| 17 |
+
|
| 18 |
+
# dots.llm1
|
| 19 |
+
|
| 20 |
+
## Overview
|
| 21 |
+
|
| 22 |
+
The `dots.llm1` model was proposed in [dots.llm1 technical report](https://huggingface.co/papers/2506.05767) by rednote-hilab team.
|
| 23 |
+
|
| 24 |
+
The abstract from the report is the following:
|
| 25 |
+
|
| 26 |
+
*Mixture of Experts (MoE) models have emerged as a promising paradigm for scaling language models efficiently by activating only a subset of parameters for each input token. In this report, we present dots.llm1, a large-scale MoE model that activates 14B parameters out of a total of 142B parameters, delivering performance on par with state-of-the-art models while reducing training and inference costs. Leveraging our meticulously crafted and efficient data processing pipeline, dots.llm1 achieves performance comparable to Qwen2.5-72B after pretraining on high-quality corpus and post-training to fully unlock its capabilities. Notably, no synthetic data is used during pretraining. To foster further research, we open-source intermediate training checkpoints spanning the entire training process, providing valuable insights into the learning dynamics of large language models.*
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
## Dots1Config
|
| 30 |
+
|
| 31 |
+
[[autodoc]] Dots1Config
|
| 32 |
+
|
| 33 |
+
## Dots1Model
|
| 34 |
+
|
| 35 |
+
[[autodoc]] Dots1Model
|
| 36 |
+
- forward
|
| 37 |
+
|
| 38 |
+
## Dots1ForCausalLM
|
| 39 |
+
|
| 40 |
+
[[autodoc]] Dots1ForCausalLM
|
| 41 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dpr.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-04-10 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
# DPR
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
## Overview
|
| 27 |
+
|
| 28 |
+
Dense Passage Retrieval (DPR) is a set of tools and models for state-of-the-art open-domain Q&A research. It was
|
| 29 |
+
introduced in [Dense Passage Retrieval for Open-Domain Question Answering](https://huggingface.co/papers/2004.04906) by
|
| 30 |
+
Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, Wen-tau Yih.
|
| 31 |
+
|
| 32 |
+
The abstract from the paper is the following:
|
| 33 |
+
|
| 34 |
+
*Open-domain question answering relies on efficient passage retrieval to select candidate contexts, where traditional
|
| 35 |
+
sparse vector space models, such as TF-IDF or BM25, are the de facto method. In this work, we show that retrieval can
|
| 36 |
+
be practically implemented using dense representations alone, where embeddings are learned from a small number of
|
| 37 |
+
questions and passages by a simple dual-encoder framework. When evaluated on a wide range of open-domain QA datasets,
|
| 38 |
+
our dense retriever outperforms a strong Lucene-BM25 system largely by 9%-19% absolute in terms of top-20 passage
|
| 39 |
+
retrieval accuracy, and helps our end-to-end QA system establish new state-of-the-art on multiple open-domain QA
|
| 40 |
+
benchmarks.*
|
| 41 |
+
|
| 42 |
+
This model was contributed by [lhoestq](https://huggingface.co/lhoestq). The original code can be found [here](https://github.com/facebookresearch/DPR).
|
| 43 |
+
|
| 44 |
+
## Usage tips
|
| 45 |
+
|
| 46 |
+
- DPR consists in three models:
|
| 47 |
+
|
| 48 |
+
* Question encoder: encode questions as vectors
|
| 49 |
+
* Context encoder: encode contexts as vectors
|
| 50 |
+
* Reader: extract the answer of the questions inside retrieved contexts, along with a relevance score (high if the inferred span actually answers the question).
|
| 51 |
+
|
| 52 |
+
## DPRConfig
|
| 53 |
+
|
| 54 |
+
[[autodoc]] DPRConfig
|
| 55 |
+
|
| 56 |
+
## DPRContextEncoderTokenizer
|
| 57 |
+
|
| 58 |
+
[[autodoc]] DPRContextEncoderTokenizer
|
| 59 |
+
|
| 60 |
+
## DPRContextEncoderTokenizerFast
|
| 61 |
+
|
| 62 |
+
[[autodoc]] DPRContextEncoderTokenizerFast
|
| 63 |
+
|
| 64 |
+
## DPRQuestionEncoderTokenizer
|
| 65 |
+
|
| 66 |
+
[[autodoc]] DPRQuestionEncoderTokenizer
|
| 67 |
+
|
| 68 |
+
## DPRQuestionEncoderTokenizerFast
|
| 69 |
+
|
| 70 |
+
[[autodoc]] DPRQuestionEncoderTokenizerFast
|
| 71 |
+
|
| 72 |
+
## DPRReaderTokenizer
|
| 73 |
+
|
| 74 |
+
[[autodoc]] DPRReaderTokenizer
|
| 75 |
+
|
| 76 |
+
## DPRReaderTokenizerFast
|
| 77 |
+
|
| 78 |
+
[[autodoc]] DPRReaderTokenizerFast
|
| 79 |
+
|
| 80 |
+
## DPR specific outputs
|
| 81 |
+
|
| 82 |
+
[[autodoc]] models.dpr.modeling_dpr.DPRContextEncoderOutput
|
| 83 |
+
|
| 84 |
+
[[autodoc]] models.dpr.modeling_dpr.DPRQuestionEncoderOutput
|
| 85 |
+
|
| 86 |
+
[[autodoc]] models.dpr.modeling_dpr.DPRReaderOutput
|
| 87 |
+
|
| 88 |
+
<frameworkcontent>
|
| 89 |
+
<pt>
|
| 90 |
+
|
| 91 |
+
## DPRContextEncoder
|
| 92 |
+
|
| 93 |
+
[[autodoc]] DPRContextEncoder
|
| 94 |
+
- forward
|
| 95 |
+
|
| 96 |
+
## DPRQuestionEncoder
|
| 97 |
+
|
| 98 |
+
[[autodoc]] DPRQuestionEncoder
|
| 99 |
+
- forward
|
| 100 |
+
|
| 101 |
+
## DPRReader
|
| 102 |
+
|
| 103 |
+
[[autodoc]] DPRReader
|
| 104 |
+
- forward
|
| 105 |
+
|
| 106 |
+
</pt>
|
| 107 |
+
<tf>
|
| 108 |
+
|
| 109 |
+
## TFDPRContextEncoder
|
| 110 |
+
|
| 111 |
+
[[autodoc]] TFDPRContextEncoder
|
| 112 |
+
- call
|
| 113 |
+
|
| 114 |
+
## TFDPRQuestionEncoder
|
| 115 |
+
|
| 116 |
+
[[autodoc]] TFDPRQuestionEncoder
|
| 117 |
+
- call
|
| 118 |
+
|
| 119 |
+
## TFDPRReader
|
| 120 |
+
|
| 121 |
+
[[autodoc]] TFDPRReader
|
| 122 |
+
- call
|
| 123 |
+
|
| 124 |
+
</tf>
|
| 125 |
+
</frameworkcontent>
|
| 126 |
+
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/dpt.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2021-03-24 and added to Hugging Face Transformers on 2022-03-28.*
|
| 17 |
+
|
| 18 |
+
# DPT
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
|
| 23 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
## Overview
|
| 27 |
+
|
| 28 |
+
The DPT model was proposed in [Vision Transformers for Dense Prediction](https://huggingface.co/papers/2103.13413) by René Ranftl, Alexey Bochkovskiy, Vladlen Koltun.
|
| 29 |
+
DPT is a model that leverages the [Vision Transformer (ViT)](vit) as backbone for dense prediction tasks like semantic segmentation and depth estimation.
|
| 30 |
+
|
| 31 |
+
The abstract from the paper is the following:
|
| 32 |
+
|
| 33 |
+
*We introduce dense vision transformers, an architecture that leverages vision transformers in place of convolutional networks as a backbone for dense prediction tasks. We assemble tokens from various stages of the vision transformer into image-like representations at various resolutions and progressively combine them into full-resolution predictions using a convolutional decoder. The transformer backbone processes representations at a constant and relatively high resolution and has a global receptive field at every stage. These properties allow the dense vision transformer to provide finer-grained and more globally coherent predictions when compared to fully-convolutional networks. Our experiments show that this architecture yields substantial improvements on dense prediction tasks, especially when a large amount of training data is available. For monocular depth estimation, we observe an improvement of up to 28% in relative performance when compared to a state-of-the-art fully-convolutional network. When applied to semantic segmentation, dense vision transformers set a new state of the art on ADE20K with 49.02% mIoU. We further show that the architecture can be fine-tuned on smaller datasets such as NYUv2, KITTI, and Pascal Context where it also sets the new state of the art.*
|
| 34 |
+
|
| 35 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dpt_architecture.jpg"
|
| 36 |
+
alt="drawing" width="600"/>
|
| 37 |
+
|
| 38 |
+
<small> DPT architecture. Taken from the <a href="https://huggingface.co/papers/2103.13413" target="_blank">original paper</a>. </small>
|
| 39 |
+
|
| 40 |
+
This model was contributed by [nielsr](https://huggingface.co/nielsr). The original code can be found [here](https://github.com/isl-org/DPT).
|
| 41 |
+
|
| 42 |
+
## Usage tips
|
| 43 |
+
|
| 44 |
+
DPT is compatible with the [`AutoBackbone`] class. This allows to use the DPT framework with various computer vision backbones available in the library, such as [`VitDetBackbone`] or [`Dinov2Backbone`]. One can create it as follows:
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
from transformers import Dinov2Config, DPTConfig, DPTForDepthEstimation
|
| 48 |
+
|
| 49 |
+
# initialize with a Transformer-based backbone such as DINOv2
|
| 50 |
+
# in that case, we also specify `reshape_hidden_states=False` to get feature maps of shape (batch_size, num_channels, height, width)
|
| 51 |
+
backbone_config = Dinov2Config.from_pretrained("facebook/dinov2-base", out_features=["stage1", "stage2", "stage3", "stage4"], reshape_hidden_states=False)
|
| 52 |
+
|
| 53 |
+
config = DPTConfig(backbone_config=backbone_config)
|
| 54 |
+
model = DPTForDepthEstimation(config=config)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Resources
|
| 58 |
+
|
| 59 |
+
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DPT.
|
| 60 |
+
|
| 61 |
+
- Demo notebooks for [`DPTForDepthEstimation`] can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/DPT).
|
| 62 |
+
|
| 63 |
+
- [Semantic segmentation task guide](../tasks/semantic_segmentation)
|
| 64 |
+
- [Monocular depth estimation task guide](../tasks/monocular_depth_estimation)
|
| 65 |
+
|
| 66 |
+
If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.
|
| 67 |
+
|
| 68 |
+
## DPTConfig
|
| 69 |
+
|
| 70 |
+
[[autodoc]] DPTConfig
|
| 71 |
+
|
| 72 |
+
## DPTFeatureExtractor
|
| 73 |
+
|
| 74 |
+
[[autodoc]] DPTFeatureExtractor
|
| 75 |
+
- __call__
|
| 76 |
+
- post_process_semantic_segmentation
|
| 77 |
+
|
| 78 |
+
## DPTImageProcessor
|
| 79 |
+
|
| 80 |
+
[[autodoc]] DPTImageProcessor
|
| 81 |
+
- preprocess
|
| 82 |
+
|
| 83 |
+
## DPTImageProcessorFast
|
| 84 |
+
|
| 85 |
+
[[autodoc]] DPTImageProcessorFast
|
| 86 |
+
- preprocess
|
| 87 |
+
- post_process_semantic_segmentation
|
| 88 |
+
- post_process_depth_estimation
|
| 89 |
+
|
| 90 |
+
## DPTModel
|
| 91 |
+
|
| 92 |
+
[[autodoc]] DPTModel
|
| 93 |
+
- forward
|
| 94 |
+
|
| 95 |
+
## DPTForDepthEstimation
|
| 96 |
+
|
| 97 |
+
[[autodoc]] DPTForDepthEstimation
|
| 98 |
+
- forward
|
| 99 |
+
|
| 100 |
+
## DPTForSemanticSegmentation
|
| 101 |
+
|
| 102 |
+
[[autodoc]] DPTForSemanticSegmentation
|
| 103 |
+
- forward
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/efficientformer.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2022-06-02 and added to Hugging Face Transformers on 2023-06-20.*
|
| 17 |
+
|
| 18 |
+
# EfficientFormer
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
<Tip warning={true}>
|
| 26 |
+
|
| 27 |
+
This model is in maintenance mode only, we don't accept any new PRs changing its code.
|
| 28 |
+
If you run into any issues running this model, please reinstall the last version that supported this model: v4.40.2.
|
| 29 |
+
You can do so by running the following command: `pip install -U transformers==4.40.2`.
|
| 30 |
+
|
| 31 |
+
</Tip>
|
| 32 |
+
|
| 33 |
+
## Overview
|
| 34 |
+
|
| 35 |
+
The EfficientFormer model was proposed in [EfficientFormer: Vision Transformers at MobileNet Speed](https://huggingface.co/papers/2206.01191)
|
| 36 |
+
by Yanyu Li, Geng Yuan, Yang Wen, Eric Hu, Georgios Evangelidis, Sergey Tulyakov, Yanzhi Wang, Jian Ren. EfficientFormer proposes a
|
| 37 |
+
dimension-consistent pure transformer that can be run on mobile devices for dense prediction tasks like image classification, object
|
| 38 |
+
detection and semantic segmentation.
|
| 39 |
+
|
| 40 |
+
The abstract from the paper is the following:
|
| 41 |
+
|
| 42 |
+
*Vision Transformers (ViT) have shown rapid progress in computer vision tasks, achieving promising results on various benchmarks.
|
| 43 |
+
However, due to the massive number of parameters and model design, e.g., attention mechanism, ViT-based models are generally
|
| 44 |
+
times slower than lightweight convolutional networks. Therefore, the deployment of ViT for real-time applications is particularly
|
| 45 |
+
challenging, especially on resource-constrained hardware such as mobile devices. Recent efforts try to reduce the computation
|
| 46 |
+
complexity of ViT through network architecture search or hybrid design with MobileNet block, yet the inference speed is still
|
| 47 |
+
unsatisfactory. This leads to an important question: can transformers run as fast as MobileNet while obtaining high performance?
|
| 48 |
+
To answer this, we first revisit the network architecture and operators used in ViT-based models and identify inefficient designs.
|
| 49 |
+
Then we introduce a dimension-consistent pure transformer (without MobileNet blocks) as a design paradigm.
|
| 50 |
+
Finally, we perform latency-driven slimming to get a series of final models dubbed EfficientFormer.
|
| 51 |
+
Extensive experiments show the superiority of EfficientFormer in performance and speed on mobile devices.
|
| 52 |
+
Our fastest model, EfficientFormer-L1, achieves 79.2% top-1 accuracy on ImageNet-1K with only 1.6 ms inference latency on
|
| 53 |
+
iPhone 12 (compiled with CoreML), which { runs as fast as MobileNetV2×1.4 (1.6 ms, 74.7% top-1),} and our largest model,
|
| 54 |
+
EfficientFormer-L7, obtains 83.3% accuracy with only 7.0 ms latency. Our work proves that properly designed transformers can
|
| 55 |
+
reach extremely low latency on mobile devices while maintaining high performance.*
|
| 56 |
+
|
| 57 |
+
This model was contributed by [novice03](https://huggingface.co/novice03) and [Bearnardd](https://huggingface.co/Bearnardd).
|
| 58 |
+
The original code can be found [here](https://github.com/snap-research/EfficientFormer). The TensorFlow version of this model was added by [D-Roberts](https://huggingface.co/D-Roberts).
|
| 59 |
+
|
| 60 |
+
## Documentation resources
|
| 61 |
+
|
| 62 |
+
- [Image classification task guide](../tasks/image_classification)
|
| 63 |
+
|
| 64 |
+
## EfficientFormerConfig
|
| 65 |
+
|
| 66 |
+
[[autodoc]] EfficientFormerConfig
|
| 67 |
+
|
| 68 |
+
## EfficientFormerImageProcessor
|
| 69 |
+
|
| 70 |
+
[[autodoc]] EfficientFormerImageProcessor
|
| 71 |
+
- preprocess
|
| 72 |
+
|
| 73 |
+
<frameworkcontent>
|
| 74 |
+
<pt>
|
| 75 |
+
|
| 76 |
+
## EfficientFormerModel
|
| 77 |
+
|
| 78 |
+
[[autodoc]] EfficientFormerModel
|
| 79 |
+
- forward
|
| 80 |
+
|
| 81 |
+
## EfficientFormerForImageClassification
|
| 82 |
+
|
| 83 |
+
[[autodoc]] EfficientFormerForImageClassification
|
| 84 |
+
- forward
|
| 85 |
+
|
| 86 |
+
## EfficientFormerForImageClassificationWithTeacher
|
| 87 |
+
|
| 88 |
+
[[autodoc]] EfficientFormerForImageClassificationWithTeacher
|
| 89 |
+
- forward
|
| 90 |
+
|
| 91 |
+
</pt>
|
| 92 |
+
<tf>
|
| 93 |
+
|
| 94 |
+
## TFEfficientFormerModel
|
| 95 |
+
|
| 96 |
+
[[autodoc]] TFEfficientFormerModel
|
| 97 |
+
- call
|
| 98 |
+
|
| 99 |
+
## TFEfficientFormerForImageClassification
|
| 100 |
+
|
| 101 |
+
[[autodoc]] TFEfficientFormerForImageClassification
|
| 102 |
+
- call
|
| 103 |
+
|
| 104 |
+
## TFEfficientFormerForImageClassificationWithTeacher
|
| 105 |
+
|
| 106 |
+
[[autodoc]] TFEfficientFormerForImageClassificationWithTeacher
|
| 107 |
+
- call
|
| 108 |
+
|
| 109 |
+
</tf>
|
| 110 |
+
</frameworkcontent>
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|
+
|
| 3 |
+
Licensed under the MIT License; you may not use this file except in compliance with
|
| 4 |
+
the License.
|
| 5 |
+
|
| 6 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 7 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 8 |
+
specific language governing permissions and limitations under the License.
|
| 9 |
+
|
| 10 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 11 |
+
rendered properly in your Markdown viewer.
|
| 12 |
+
|
| 13 |
+
-->
|
| 14 |
+
*This model was released on 2024-03-07 and added to Hugging Face Transformers on 2025-07-22.*
|
| 15 |
+
|
| 16 |
+
<div style="float: right;">
|
| 17 |
+
<div class="flex flex-wrap space-x-1">
|
| 18 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white" >
|
| 19 |
+
</div>
|
| 20 |
+
</div>
|
| 21 |
+
|
| 22 |
+
# EfficientLoFTR
|
| 23 |
+
|
| 24 |
+
[EfficientLoFTR](https://huggingface.co/papers/2403.04765) is an efficient detector-free local feature matching method that produces semi-dense matches across images with sparse-like speed. It builds upon the original [LoFTR](https://huggingface.co/papers/2104.00680) architecture but introduces significant improvements for both efficiency and accuracy. The key innovation is an aggregated attention mechanism with adaptive token selection that makes the model ~2.5× faster than LoFTR while achieving higher accuracy. EfficientLoFTR can even surpass state-of-the-art efficient sparse matching pipelines like [SuperPoint](./superpoint) + [LightGlue](./lightglue) in terms of speed, making it suitable for large-scale or latency-sensitive applications such as image retrieval and 3D reconstruction.
|
| 25 |
+
|
| 26 |
+
> [!TIP]
|
| 27 |
+
> This model was contributed by [stevenbucaille](https://huggingface.co/stevenbucaille).
|
| 28 |
+
>
|
| 29 |
+
> Click on the EfficientLoFTR models in the right sidebar for more examples of how to apply EfficientLoFTR to different computer vision tasks.
|
| 30 |
+
|
| 31 |
+
The example below demonstrates how to match keypoints between two images with the [`AutoModel`] class.
|
| 32 |
+
|
| 33 |
+
<hfoptions id="usage">
|
| 34 |
+
<hfoption id="AutoModel">
|
| 35 |
+
|
| 36 |
+
```py
|
| 37 |
+
from transformers import AutoImageProcessor, AutoModelForKeypointMatching
|
| 38 |
+
import torch
|
| 39 |
+
from PIL import Image
|
| 40 |
+
import requests
|
| 41 |
+
|
| 42 |
+
url_image1 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg"
|
| 43 |
+
image1 = Image.open(requests.get(url_image1, stream=True).raw)
|
| 44 |
+
url_image2 = "https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/refs/heads/master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg"
|
| 45 |
+
image2 = Image.open(requests.get(url_image2, stream=True).raw)
|
| 46 |
+
|
| 47 |
+
images = [image1, image2]
|
| 48 |
+
|
| 49 |
+
processor = AutoImageProcessor.from_pretrained("zju-community/efficientloftr")
|
| 50 |
+
model = AutoModelForKeypointMatching.from_pretrained("zju-community/efficientloftr")
|
| 51 |
+
|
| 52 |
+
inputs = processor(images, return_tensors="pt")
|
| 53 |
+
with torch.no_grad():
|
| 54 |
+
outputs = model(**inputs)
|
| 55 |
+
|
| 56 |
+
# Post-process to get keypoints and matches
|
| 57 |
+
image_sizes = [[(image.height, image.width) for image in images]]
|
| 58 |
+
processed_outputs = processor.post_process_keypoint_matching(outputs, image_sizes, threshold=0.2)
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
</hfoption>
|
| 62 |
+
</hfoptions>
|
| 63 |
+
|
| 64 |
+
## Notes
|
| 65 |
+
|
| 66 |
+
- EfficientLoFTR is designed for efficiency while maintaining high accuracy. It uses an aggregated attention mechanism with adaptive token selection to reduce computational overhead compared to the original LoFTR.
|
| 67 |
+
|
| 68 |
+
```py
|
| 69 |
+
from transformers import AutoImageProcessor, AutoModelForKeypointMatching
|
| 70 |
+
import torch
|
| 71 |
+
from PIL import Image
|
| 72 |
+
import requests
|
| 73 |
+
|
| 74 |
+
processor = AutoImageProcessor.from_pretrained("zju-community/efficientloftr")
|
| 75 |
+
model = AutoModelForKeypointMatching.from_pretrained("zju-community/efficientloftr")
|
| 76 |
+
|
| 77 |
+
# EfficientLoFTR requires pairs of images
|
| 78 |
+
images = [image1, image2]
|
| 79 |
+
inputs = processor(images, return_tensors="pt")
|
| 80 |
+
outputs = model(**inputs)
|
| 81 |
+
|
| 82 |
+
# Extract matching information
|
| 83 |
+
keypoints = outputs.keypoints # Keypoints in both images
|
| 84 |
+
matches = outputs.matches # Matching indices
|
| 85 |
+
matching_scores = outputs.matching_scores # Confidence scores
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
- The model produces semi-dense matches, offering a good balance between the density of matches and computational efficiency. It excels in handling large viewpoint changes and texture-poor scenarios.
|
| 89 |
+
|
| 90 |
+
- For better visualization and analysis, use the [`~EfficientLoFTRImageProcessor.post_process_keypoint_matching`] method to get matches in a more readable format.
|
| 91 |
+
|
| 92 |
+
```py
|
| 93 |
+
# Process outputs for visualization
|
| 94 |
+
image_sizes = [[(image.height, image.width) for image in images]]
|
| 95 |
+
processed_outputs = processor.post_process_keypoint_matching(outputs, image_sizes, threshold=0.2)
|
| 96 |
+
|
| 97 |
+
for i, output in enumerate(processed_outputs):
|
| 98 |
+
print(f"For the image pair {i}")
|
| 99 |
+
for keypoint0, keypoint1, matching_score in zip(
|
| 100 |
+
output["keypoints0"], output["keypoints1"], output["matching_scores"]
|
| 101 |
+
):
|
| 102 |
+
print(f"Keypoint at {keypoint0.numpy()} matches with keypoint at {keypoint1.numpy()} with score {matching_score}")
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
- Visualize the matches between the images using the built-in plotting functionality.
|
| 106 |
+
|
| 107 |
+
```py
|
| 108 |
+
# Easy visualization using the built-in plotting method
|
| 109 |
+
visualized_images = processor.visualize_keypoint_matching(images, processed_outputs)
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
- EfficientLoFTR uses a novel two-stage correlation layer that achieves accurate subpixel correspondences, improving upon the original LoFTR's fine correlation module.
|
| 113 |
+
|
| 114 |
+
<div class="flex justify-center">
|
| 115 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/632885ba1558dac67c440aa8/2nJZQlFToCYp_iLurvcZ4.png">
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
## Resources
|
| 119 |
+
|
| 120 |
+
- Refer to the [original EfficientLoFTR repository](https://github.com/zju3dv/EfficientLoFTR) for more examples and implementation details.
|
| 121 |
+
- [EfficientLoFTR project page](https://zju3dv.github.io/efficientloftr/) with interactive demos and additional information.
|
| 122 |
+
|
| 123 |
+
## EfficientLoFTRConfig
|
| 124 |
+
|
| 125 |
+
[[autodoc]] EfficientLoFTRConfig
|
| 126 |
+
|
| 127 |
+
## EfficientLoFTRImageProcessor
|
| 128 |
+
|
| 129 |
+
[[autodoc]] EfficientLoFTRImageProcessor
|
| 130 |
+
|
| 131 |
+
- preprocess
|
| 132 |
+
- post_process_keypoint_matching
|
| 133 |
+
- visualize_keypoint_matching
|
| 134 |
+
|
| 135 |
+
<frameworkcontent>
|
| 136 |
+
<pt>
|
| 137 |
+
## EfficientLoFTRModel
|
| 138 |
+
|
| 139 |
+
[[autodoc]] EfficientLoFTRModel
|
| 140 |
+
|
| 141 |
+
- forward
|
| 142 |
+
|
| 143 |
+
## EfficientLoFTRForKeypointMatching
|
| 144 |
+
|
| 145 |
+
[[autodoc]] EfficientLoFTRForKeypointMatching
|
| 146 |
+
|
| 147 |
+
- forward
|
| 148 |
+
|
| 149 |
+
</pt>
|
| 150 |
+
</frameworkcontent>
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/efficientnet.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2019-05-28 and added to Hugging Face Transformers on 2023-02-20.*
|
| 17 |
+
|
| 18 |
+
# EfficientNet
|
| 19 |
+
|
| 20 |
+
<div class="flex flex-wrap space-x-1">
|
| 21 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
## Overview
|
| 25 |
+
|
| 26 |
+
The EfficientNet model was proposed in [EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks](https://huggingface.co/papers/1905.11946)
|
| 27 |
+
by Mingxing Tan and Quoc V. Le. EfficientNets are a family of image classification models, which achieve state-of-the-art accuracy, yet being an order-of-magnitude smaller and faster than previous models.
|
| 28 |
+
|
| 29 |
+
The abstract from the paper is the following:
|
| 30 |
+
|
| 31 |
+
*Convolutional Neural Networks (ConvNets) are commonly developed at a fixed resource budget, and then scaled up for better accuracy if more resources are available. In this paper, we systematically study model scaling and identify that carefully balancing network depth, width, and resolution can lead to better performance. Based on this observation, we propose a new scaling method that uniformly scales all dimensions of depth/width/resolution using a simple yet highly effective compound coefficient. We demonstrate the effectiveness of this method on scaling up MobileNets and ResNet.
|
| 32 |
+
To go even further, we use neural architecture search to design a new baseline network and scale it up to obtain a family of models, called EfficientNets, which achieve much better accuracy and efficiency than previous ConvNets. In particular, our EfficientNet-B7 achieves state-of-the-art 84.3% top-1 accuracy on ImageNet, while being 8.4x smaller and 6.1x faster on inference than the best existing ConvNet. Our EfficientNets also transfer well and achieve state-of-the-art accuracy on CIFAR-100 (91.7%), Flowers (98.8%), and 3 other transfer learning datasets, with an order of magnitude fewer parameters.*
|
| 33 |
+
|
| 34 |
+
This model was contributed by [adirik](https://huggingface.co/adirik).
|
| 35 |
+
The original code can be found [here](https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet).
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
## EfficientNetConfig
|
| 39 |
+
|
| 40 |
+
[[autodoc]] EfficientNetConfig
|
| 41 |
+
|
| 42 |
+
## EfficientNetImageProcessor
|
| 43 |
+
|
| 44 |
+
[[autodoc]] EfficientNetImageProcessor
|
| 45 |
+
- preprocess
|
| 46 |
+
|
| 47 |
+
## EfficientNetImageProcessorFast
|
| 48 |
+
|
| 49 |
+
[[autodoc]] EfficientNetImageProcessorFast
|
| 50 |
+
- preprocess
|
| 51 |
+
|
| 52 |
+
## EfficientNetModel
|
| 53 |
+
|
| 54 |
+
[[autodoc]] EfficientNetModel
|
| 55 |
+
- forward
|
| 56 |
+
|
| 57 |
+
## EfficientNetForImageClassification
|
| 58 |
+
|
| 59 |
+
[[autodoc]] EfficientNetForImageClassification
|
| 60 |
+
- forward
|
| 61 |
+
|
tasks/tasksmith-5cbfd9f64dbc/environment/source/docs/source/en/model_doc/electra.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
| 4 |
+
the License. You may obtain a copy of the License at
|
| 5 |
+
|
| 6 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 7 |
+
|
| 8 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
| 9 |
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 10 |
+
specific language governing permissions and limitations under the License.
|
| 11 |
+
|
| 12 |
+
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
| 13 |
+
rendered properly in your Markdown viewer.
|
| 14 |
+
|
| 15 |
+
-->
|
| 16 |
+
*This model was released on 2020-03-23 and added to Hugging Face Transformers on 2020-11-16.*
|
| 17 |
+
|
| 18 |
+
<div style="float: right;">
|
| 19 |
+
<div class="flex flex-wrap space-x-1">
|
| 20 |
+
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 21 |
+
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white">
|
| 22 |
+
<img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa0AS6ghW63O498vYa+lsdKz1NDRt9Kw1c672tbD3tnAxt7R6OHp5vDe7OrDyuDn6vLl6/EAQKak0MgATakkppo3ZK/Bz9y8w9yzu9jey97axdvHzeG21NHH4trTwthKZrVGZLSUSpuPQJiGAI+GAI8SWKydycLL4d7f2OTi1+S9xNzL0ePT6OLGzeEAo5U0qJw/aLEAo5JFa7JBabEAp5Y4qZ2QxLyKmsm3kL2xoMOehrRNb7RIbbOZgrGre68AUqwAqZqNN5aKJ5N/lMq+qsd8kMa4pcWzh7muhLMEV69juq2kbKqgUaOTR5uMMZWLLZSGAI5VAIdEAH+ovNDHuNCnxcy3qcaYx8K8msGplrx+wLahjbYdXrV6vbMvYK9DrZ8QrZ8tqJuFms+Sos6sw8ecy8RffsNVeMCvmb43aLltv7Q4Y7EZWK4QWa1gt6meZKUdr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eGIkckc80fX3KH/h7PT4BOjgCty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC
|
| 23 |
+
">
|
| 24 |
+
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white">
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
# ELECTRA
|
| 29 |
+
|
| 30 |
+
[ELECTRA](https://huggingface.co/papers/2003.10555) modifies the pretraining objective of traditional masked language models like BERT. Instead of just masking tokens and asking the model to predict them, ELECTRA trains two models, a generator and a discriminator. The generator replaces some tokens with plausible alternatives and the discriminator (the model you'll actually use) learns to detect which tokens are original and which were replaced. This training approach is very efficient and scales to larger models while using considerably less compute.
|
| 31 |
+
|
| 32 |
+
This approach is super efficient because ELECTRA learns from every single token in the input, not just the masked ones. That's why even the small ELECTRA models can match or outperform much larger models while using way less computing resources.
|
| 33 |
+
|
| 34 |
+
You can find all the original ELECTRA checkpoints under the [ELECTRA](https://huggingface.co/collections/google/electra-release-64ff6e8b18830fabea30a1ab) release.
|
| 35 |
+
|
| 36 |
+
> [!TIP]
|
| 37 |
+
> Click on the right sidebar for more examples of how to use ELECTRA for different language tasks like sequence classification, token classification, and question answering.
|
| 38 |
+
|
| 39 |
+
The example below demonstrates how to classify text with [`Pipeline`] or the [`AutoModel`] class.
|
| 40 |
+
|
| 41 |
+
<hfoptions id="usage">
|
| 42 |
+
<hfoption id="Pipeline">
|
| 43 |
+
|
| 44 |
+
```py
|
| 45 |
+
import torch
|
| 46 |
+
from transformers import pipeline
|
| 47 |
+
|
| 48 |
+
classifier = pipeline(
|
| 49 |
+
task="text-classification",
|
| 50 |
+
model="bhadresh-savani/electra-base-emotion",
|
| 51 |
+
torch_dtype=torch.float16,
|
| 52 |
+
device=0
|
| 53 |
+
)
|
| 54 |
+
classifier("This restaurant has amazing food!")
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
</hfoption>
|
| 58 |
+
<hfoption id="AutoModel">
|
| 59 |
+
|
| 60 |
+
```py
|
| 61 |
+
import torch
|
| 62 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 63 |
+
|
| 64 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 65 |
+
"bhadresh-savani/electra-base-emotion",
|
| 66 |
+
)
|
| 67 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 68 |
+
"bhadresh-savani/electra-base-emotion",
|
| 69 |
+
torch_dtype=torch.float16
|
| 70 |
+
)
|
| 71 |
+
inputs = tokenizer("ELECTRA is more efficient than BERT", return_tensors="pt")
|
| 72 |
+
|
| 73 |
+
with torch.no_grad():
|
| 74 |
+
outputs = model(**inputs)
|
| 75 |
+
logits = outputs.logits
|
| 76 |
+
predicted_class_id = logits.argmax(dim=-1).item()
|
| 77 |
+
predicted_label = model.config.id2label[predicted_class_id]
|
| 78 |
+
print(f"Predicted label: {predicted_label}")
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
</hfoption>
|
| 82 |
+
<hfoption id="transformers CLI">
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
echo -e "This restaurant has amazing food." | transformers run --task text-classification --model bhadresh-savani/electra-base-emotion --device 0
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
</hfoption>
|
| 89 |
+
</hfoptions>
|
| 90 |
+
|
| 91 |
+
## Notes
|
| 92 |
+
|
| 93 |
+
- ELECTRA consists of two transformer models, a generator (G) and a discriminator (D). For most downstream tasks, use the discriminator model (as indicated by `*-discriminator` in the name) rather than the generator.
|
| 94 |
+
- ELECTRA comes in three sizes: small (14M parameters), base (110M parameters), and large (335M parameters).
|
| 95 |
+
- ELECTRA can use a smaller embedding size than the hidden size for efficiency. When `embedding_size` is smaller than `hidden_size` in the configuration, a projection layer connects them.
|
| 96 |
+
- When using batched inputs with padding, make sure to use attention masks to prevent the model from attending to padding tokens.
|
| 97 |
+
|
| 98 |
+
```py
|
| 99 |
+
# Example of properly handling padding with attention masks
|
| 100 |
+
inputs = tokenizer(["Short text", "This is a much longer text that needs padding"],
|
| 101 |
+
padding=True,
|
| 102 |
+
return_tensors="pt")
|
| 103 |
+
outputs = model(**inputs) # automatically uses the attention_mask
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
- When using the discriminator for a downstream task, you can load it into any of the ELECTRA model classes ([`ElectraForSequenceClassification`], [`ElectraForTokenClassification`], etc.).
|
| 107 |
+
|
| 108 |
+
## ElectraConfig
|
| 109 |
+
|
| 110 |
+
[[autodoc]] ElectraConfig
|
| 111 |
+
|
| 112 |
+
## ElectraTokenizer
|
| 113 |
+
|
| 114 |
+
[[autodoc]] ElectraTokenizer
|
| 115 |
+
|
| 116 |
+
## ElectraTokenizerFast
|
| 117 |
+
|
| 118 |
+
[[autodoc]] ElectraTokenizerFast
|
| 119 |
+
|
| 120 |
+
## Electra specific outputs
|
| 121 |
+
|
| 122 |
+
[[autodoc]] models.electra.modeling_electra.ElectraForPreTrainingOutput
|
| 123 |
+
|
| 124 |
+
[[autodoc]] models.electra.modeling_tf_electra.TFElectraForPreTrainingOutput
|
| 125 |
+
|
| 126 |
+
<frameworkcontent>
|
| 127 |
+
<pt>
|
| 128 |
+
|
| 129 |
+
## ElectraModel
|
| 130 |
+
|
| 131 |
+
[[autodoc]] ElectraModel
|
| 132 |
+
- forward
|
| 133 |
+
|
| 134 |
+
## ElectraForPreTraining
|
| 135 |
+
|
| 136 |
+
[[autodoc]] ElectraForPreTraining
|
| 137 |
+
- forward
|
| 138 |
+
|
| 139 |
+
## ElectraForCausalLM
|
| 140 |
+
|
| 141 |
+
[[autodoc]] ElectraForCausalLM
|
| 142 |
+
- forward
|
| 143 |
+
|
| 144 |
+
## ElectraForMaskedLM
|
| 145 |
+
|
| 146 |
+
[[autodoc]] ElectraForMaskedLM
|
| 147 |
+
- forward
|
| 148 |
+
|
| 149 |
+
## ElectraForSequenceClassification
|
| 150 |
+
|
| 151 |
+
[[autodoc]] ElectraForSequenceClassification
|
| 152 |
+
- forward
|
| 153 |
+
|
| 154 |
+
## ElectraForMultipleChoice
|
| 155 |
+
|
| 156 |
+
[[autodoc]] ElectraForMultipleChoice
|
| 157 |
+
- forward
|
| 158 |
+
|
| 159 |
+
## ElectraForTokenClassification
|
| 160 |
+
|
| 161 |
+
[[autodoc]] ElectraForTokenClassification
|
| 162 |
+
- forward
|
| 163 |
+
|
| 164 |
+
## ElectraForQuestionAnswering
|
| 165 |
+
|
| 166 |
+
[[autodoc]] ElectraForQuestionAnswering
|
| 167 |
+
- forward
|
| 168 |
+
|
| 169 |
+
</pt>
|
| 170 |
+
<tf>
|
| 171 |
+
|
| 172 |
+
## TFElectraModel
|
| 173 |
+
|
| 174 |
+
[[autodoc]] TFElectraModel
|
| 175 |
+
- call
|
| 176 |
+
|
| 177 |
+
## TFElectraForPreTraining
|
| 178 |
+
|
| 179 |
+
[[autodoc]] TFElectraForPreTraining
|
| 180 |
+
- call
|
| 181 |
+
|
| 182 |
+
## TFElectraForMaskedLM
|
| 183 |
+
|
| 184 |
+
[[autodoc]] TFElectraForMaskedLM
|
| 185 |
+
- call
|
| 186 |
+
|
| 187 |
+
## TFElectraForSequenceClassification
|
| 188 |
+
|
| 189 |
+
[[autodoc]] TFElectraForSequenceClassification
|
| 190 |
+
- call
|
| 191 |
+
|
| 192 |
+
## TFElectraForMultipleChoice
|
| 193 |
+
|
| 194 |
+
[[autodoc]] TFElectraForMultipleChoice
|
| 195 |
+
- call
|
| 196 |
+
|
| 197 |
+
## TFElectraForTokenClassification
|
| 198 |
+
|
| 199 |
+
[[autodoc]] TFElectraForTokenClassification
|
| 200 |
+
- call
|
| 201 |
+
|
| 202 |
+
## TFElectraForQuestionAnswering
|
| 203 |
+
|
| 204 |
+
[[autodoc]] TFElectraForQuestionAnswering
|
| 205 |
+
- call
|
| 206 |
+
|
| 207 |
+
</tf>
|
| 208 |
+
<jax>
|
| 209 |
+
|
| 210 |
+
## FlaxElectraModel
|
| 211 |
+
|
| 212 |
+
[[autodoc]] FlaxElectraModel
|
| 213 |
+
- __call__
|
| 214 |
+
|
| 215 |
+
## FlaxElectraForPreTraining
|
| 216 |
+
|
| 217 |
+
[[autodoc]] FlaxElectraForPreTraining
|
| 218 |
+
- __call__
|
| 219 |
+
|
| 220 |
+
## FlaxElectraForCausalLM
|
| 221 |
+
|
| 222 |
+
[[autodoc]] FlaxElectraForCausalLM
|
| 223 |
+
- __call__
|
| 224 |
+
|
| 225 |
+
## FlaxElectraForMaskedLM
|
| 226 |
+
|
| 227 |
+
[[autodoc]] FlaxElectraForMaskedLM
|
| 228 |
+
- __call__
|
| 229 |
+
|
| 230 |
+
## FlaxElectraForSequenceClassification
|
| 231 |
+
|
| 232 |
+
[[autodoc]] FlaxElectraForSequenceClassification
|
| 233 |
+
- __call__
|
| 234 |
+
|
| 235 |
+
## FlaxElectraForMultipleChoice
|
| 236 |
+
|
| 237 |
+
[[autodoc]] FlaxElectraForMultipleChoice
|
| 238 |
+
- __call__
|
| 239 |
+
|
| 240 |
+
## FlaxElectraForTokenClassification
|
| 241 |
+
|
| 242 |
+
[[autodoc]] FlaxElectraForTokenClassification
|
| 243 |
+
- __call__
|
| 244 |
+
|
| 245 |
+
## FlaxElectraForQuestionAnswering
|
| 246 |
+
|
| 247 |
+
[[autodoc]] FlaxElectraForQuestionAnswering
|
| 248 |
+
- __call__
|
| 249 |
+
|
| 250 |
+
</jax>
|
| 251 |
+
</frameworkcontent>
|