AdithyaSK HF Staff commited on
Commit
0b7d313
·
verified ·
1 Parent(s): 93993b2

Stage Harbor release files 47001-47500

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/flava.md +103 -0
  2. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fnet.md +110 -0
  3. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/focalnet.md +50 -0
  4. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fsmt.md +64 -0
  5. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/funnel.md +185 -0
  6. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fuyu.md +115 -0
  7. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gemma.md +76 -0
  8. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gemma2.md +64 -0
  9. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/git.md +79 -0
  10. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/glm.md +99 -0
  11. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/glpn.md +72 -0
  12. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt-sw3.md +69 -0
  13. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt2.md +306 -0
  14. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_bigcode.md +106 -0
  15. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neo.md +147 -0
  16. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neox.md +195 -0
  17. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neox_japanese.md +74 -0
  18. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gptj.md +200 -0
  19. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gptsan-japanese.md +129 -0
  20. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/granite.md +74 -0
  21. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/granitemoe.md +74 -0
  22. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/graphormer.md +55 -0
  23. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/grounding-dino.md +118 -0
  24. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/groupvit.md +96 -0
  25. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/herbert.md +76 -0
  26. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/hiera.md +62 -0
  27. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/hubert.md +124 -0
  28. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/ibert.md +83 -0
  29. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics.md +73 -0
  30. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics2.md +218 -0
  31. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics3.md +80 -0
  32. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/ijepa.md +92 -0
  33. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/imagegpt.md +115 -0
  34. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/informer.md +50 -0
  35. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/instructblip.md +72 -0
  36. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/instructblipvideo.md +78 -0
  37. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jamba.md +122 -0
  38. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jetmoe.md +49 -0
  39. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jukebox.md +93 -0
  40. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/kosmos-2.md +98 -0
  41. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlm.md +175 -0
  42. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlmv2.md +340 -0
  43. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlmv3.md +154 -0
  44. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutxlm.md +85 -0
  45. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/led.md +143 -0
  46. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/levit.md +106 -0
  47. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/lilt.md +88 -0
  48. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama.md +137 -0
  49. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama2.md +140 -0
  50. tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama3.md +82 -0
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/flava.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
+
17
+ # FLAVA
18
+
19
+ ## Overview
20
+
21
+ The FLAVA model was proposed in [FLAVA: A Foundational Language And Vision Alignment Model](https://arxiv.org/abs/2112.04482) by Amanpreet Singh, Ronghang Hu, Vedanuj Goswami, Guillaume Couairon, Wojciech Galuba, Marcus Rohrbach, and Douwe Kiela and is accepted at CVPR 2022.
22
+
23
+ The paper aims at creating a single unified foundation model which can work across vision, language
24
+ as well as vision-and-language multimodal tasks.
25
+
26
+ The abstract from the paper is the following:
27
+
28
+ *State-of-the-art vision and vision-and-language models rely on large-scale visio-linguistic pretraining for obtaining good performance on a variety
29
+ of downstream tasks. Generally, such models are often either cross-modal (contrastive) or multi-modal
30
+ (with earlier fusion) but not both; and they often only target specific modalities or tasks. A promising
31
+ direction would be to use a single holistic universal model, as a "foundation", that targets all modalities
32
+ at once -- a true vision and language foundation model should be good at vision tasks, language tasks, and
33
+ cross- and multi-modal vision and language tasks. We introduce FLAVA as such a model and demonstrate
34
+ impressive performance on a wide range of 35 tasks spanning these target modalities.*
35
+
36
+ This model was contributed by [aps](https://huggingface.co/aps). The original code can be found [here](https://github.com/facebookresearch/multimodal/tree/main/examples/flava).
37
+
38
+ ## FlavaConfig
39
+
40
+ [[autodoc]] FlavaConfig
41
+
42
+ ## FlavaTextConfig
43
+
44
+ [[autodoc]] FlavaTextConfig
45
+
46
+ ## FlavaImageConfig
47
+
48
+ [[autodoc]] FlavaImageConfig
49
+
50
+ ## FlavaMultimodalConfig
51
+
52
+ [[autodoc]] FlavaMultimodalConfig
53
+
54
+ ## FlavaImageCodebookConfig
55
+
56
+ [[autodoc]] FlavaImageCodebookConfig
57
+
58
+ ## FlavaProcessor
59
+
60
+ [[autodoc]] FlavaProcessor
61
+
62
+ ## FlavaFeatureExtractor
63
+
64
+ [[autodoc]] FlavaFeatureExtractor
65
+
66
+ ## FlavaImageProcessor
67
+
68
+ [[autodoc]] FlavaImageProcessor
69
+ - preprocess
70
+
71
+ ## FlavaForPreTraining
72
+
73
+ [[autodoc]] FlavaForPreTraining
74
+ - forward
75
+
76
+ ## FlavaModel
77
+
78
+ [[autodoc]] FlavaModel
79
+ - forward
80
+ - get_text_features
81
+ - get_image_features
82
+
83
+ ## FlavaImageCodebook
84
+
85
+ [[autodoc]] FlavaImageCodebook
86
+ - forward
87
+ - get_codebook_indices
88
+ - get_codebook_probs
89
+
90
+ ## FlavaTextModel
91
+
92
+ [[autodoc]] FlavaTextModel
93
+ - forward
94
+
95
+ ## FlavaImageModel
96
+
97
+ [[autodoc]] FlavaImageModel
98
+ - forward
99
+
100
+ ## FlavaMultimodalModel
101
+
102
+ [[autodoc]] FlavaMultimodalModel
103
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fnet.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # FNet
18
+
19
+ ## Overview
20
+
21
+ The FNet model was proposed in [FNet: Mixing Tokens with Fourier Transforms](https://arxiv.org/abs/2105.03824) by
22
+ James Lee-Thorp, Joshua Ainslie, Ilya Eckstein, Santiago Ontanon. The model replaces the self-attention layer in a BERT
23
+ model with a fourier transform which returns only the real parts of the transform. The model is significantly faster
24
+ than the BERT model because it has fewer parameters and is more memory efficient. The model achieves about 92-97%
25
+ accuracy of BERT counterparts on GLUE benchmark, and trains much faster than the BERT model. The abstract from the
26
+ paper is the following:
27
+
28
+ *We show that Transformer encoder architectures can be sped up, with limited accuracy costs, by replacing the
29
+ self-attention sublayers with simple linear transformations that "mix" input tokens. These linear mixers, along with
30
+ standard nonlinearities in feed-forward layers, prove competent at modeling semantic relationships in several text
31
+ classification tasks. Most surprisingly, we find that replacing the self-attention sublayer in a Transformer encoder
32
+ with a standard, unparameterized Fourier Transform achieves 92-97% of the accuracy of BERT counterparts on the GLUE
33
+ benchmark, but trains 80% faster on GPUs and 70% faster on TPUs at standard 512 input lengths. At longer input lengths,
34
+ our FNet model is significantly faster: when compared to the "efficient" Transformers on the Long Range Arena
35
+ benchmark, FNet matches the accuracy of the most accurate models, while outpacing the fastest models across all
36
+ sequence lengths on GPUs (and across relatively shorter lengths on TPUs). Finally, FNet has a light memory footprint
37
+ and is particularly efficient at smaller model sizes; for a fixed speed and accuracy budget, small FNet models
38
+ outperform Transformer counterparts.*
39
+
40
+ This model was contributed by [gchhablani](https://huggingface.co/gchhablani). The original code can be found [here](https://github.com/google-research/google-research/tree/master/f_net).
41
+
42
+ ## Usage tips
43
+
44
+ The model was trained without an attention mask as it is based on Fourier Transform. The model was trained with
45
+ maximum sequence length 512 which includes pad tokens. Hence, it is highly recommended to use the same maximum
46
+ sequence length for fine-tuning and inference.
47
+
48
+ ## Resources
49
+
50
+ - [Text classification task guide](../tasks/sequence_classification)
51
+ - [Token classification task guide](../tasks/token_classification)
52
+ - [Question answering task guide](../tasks/question_answering)
53
+ - [Masked language modeling task guide](../tasks/masked_language_modeling)
54
+ - [Multiple choice task guide](../tasks/multiple_choice)
55
+
56
+ ## FNetConfig
57
+
58
+ [[autodoc]] FNetConfig
59
+
60
+ ## FNetTokenizer
61
+
62
+ [[autodoc]] FNetTokenizer
63
+ - build_inputs_with_special_tokens
64
+ - get_special_tokens_mask
65
+ - create_token_type_ids_from_sequences
66
+ - save_vocabulary
67
+
68
+ ## FNetTokenizerFast
69
+
70
+ [[autodoc]] FNetTokenizerFast
71
+
72
+ ## FNetModel
73
+
74
+ [[autodoc]] FNetModel
75
+ - forward
76
+
77
+ ## FNetForPreTraining
78
+
79
+ [[autodoc]] FNetForPreTraining
80
+ - forward
81
+
82
+ ## FNetForMaskedLM
83
+
84
+ [[autodoc]] FNetForMaskedLM
85
+ - forward
86
+
87
+ ## FNetForNextSentencePrediction
88
+
89
+ [[autodoc]] FNetForNextSentencePrediction
90
+ - forward
91
+
92
+ ## FNetForSequenceClassification
93
+
94
+ [[autodoc]] FNetForSequenceClassification
95
+ - forward
96
+
97
+ ## FNetForMultipleChoice
98
+
99
+ [[autodoc]] FNetForMultipleChoice
100
+ - forward
101
+
102
+ ## FNetForTokenClassification
103
+
104
+ [[autodoc]] FNetForTokenClassification
105
+ - forward
106
+
107
+ ## FNetForQuestionAnswering
108
+
109
+ [[autodoc]] FNetForQuestionAnswering
110
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/focalnet.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # FocalNet
18
+
19
+ ## Overview
20
+
21
+ The FocalNet model was proposed in [Focal Modulation Networks](https://arxiv.org/abs/2203.11926) by Jianwei Yang, Chunyuan Li, Xiyang Dai, Lu Yuan, Jianfeng Gao.
22
+ FocalNets completely replace self-attention (used in models like [ViT](vit) and [Swin](swin)) by a focal modulation mechanism for modeling token interactions in vision.
23
+ The authors claim that FocalNets outperform self-attention based models with similar computational costs on the tasks of image classification, object detection, and segmentation.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *We propose focal modulation networks (FocalNets in short), where self-attention (SA) is completely replaced by a focal modulation mechanism for modeling token interactions in vision. Focal modulation comprises three components: (i) hierarchical contextualization, implemented using a stack of depth-wise convolutional layers, to encode visual contexts from short to long ranges, (ii) gated aggregation to selectively gather contexts for each query token based on its
28
+ content, and (iii) element-wise modulation or affine transformation to inject the aggregated context into the query. Extensive experiments show FocalNets outperform the state-of-the-art SA counterparts (e.g., Swin and Focal Transformers) with similar computational costs on the tasks of image classification, object detection, and segmentation. Specifically, FocalNets with tiny and base size achieve 82.3% and 83.9% top-1 accuracy on ImageNet-1K. After pretrained on ImageNet-22K in 224 resolution, it attains 86.5% and 87.3% top-1 accuracy when finetuned with resolution 224 and 384, respectively. When transferred to downstream tasks, FocalNets exhibit clear superiority. For object detection with Mask R-CNN, FocalNet base trained with 1\times outperforms the Swin counterpart by 2.1 points and already surpasses Swin trained with 3\times schedule (49.0 v.s. 48.5). For semantic segmentation with UPerNet, FocalNet base at single-scale outperforms Swin by 2.4, and beats Swin at multi-scale (50.5 v.s. 49.7). Using large FocalNet and Mask2former, we achieve 58.5 mIoU for ADE20K semantic segmentation, and 57.9 PQ for COCO Panoptic Segmentation. Using huge FocalNet and DINO, we achieved 64.3 and 64.4 mAP on COCO minival and test-dev, respectively, establishing new SoTA on top of much larger attention-based models like Swinv2-G and BEIT-3.*
29
+
30
+ This model was contributed by [nielsr](https://huggingface.co/nielsr).
31
+ The original code can be found [here](https://github.com/microsoft/FocalNet).
32
+
33
+ ## FocalNetConfig
34
+
35
+ [[autodoc]] FocalNetConfig
36
+
37
+ ## FocalNetModel
38
+
39
+ [[autodoc]] FocalNetModel
40
+ - forward
41
+
42
+ ## FocalNetForMaskedImageModeling
43
+
44
+ [[autodoc]] FocalNetForMaskedImageModeling
45
+ - forward
46
+
47
+ ## FocalNetForImageClassification
48
+
49
+ [[autodoc]] FocalNetForImageClassification
50
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fsmt.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
+
17
+ # FSMT
18
+
19
+ ## Overview
20
+
21
+ FSMT (FairSeq MachineTranslation) models were introduced in [Facebook FAIR's WMT19 News Translation Task Submission](https://arxiv.org/abs/1907.06616) by Nathan Ng, Kyra Yee, Alexei Baevski, Myle Ott, Michael Auli, Sergey Edunov.
22
+
23
+ The abstract of the paper is the following:
24
+
25
+ *This paper describes Facebook FAIR's submission to the WMT19 shared news translation task. We participate in two
26
+ language pairs and four language directions, English <-> German and English <-> Russian. Following our submission from
27
+ last year, our baseline systems are large BPE-based transformer models trained with the Fairseq sequence modeling
28
+ toolkit which rely on sampled back-translations. This year we experiment with different bitext data filtering schemes,
29
+ as well as with adding filtered back-translated data. We also ensemble and fine-tune our models on domain-specific
30
+ data, then decode using noisy channel model reranking. Our submissions are ranked first in all four directions of the
31
+ human evaluation campaign. On En->De, our system significantly outperforms other systems as well as human translations.
32
+ This system improves upon our WMT'18 submission by 4.5 BLEU points.*
33
+
34
+ This model was contributed by [stas](https://huggingface.co/stas). The original code can be found
35
+ [here](https://github.com/pytorch/fairseq/tree/master/examples/wmt19).
36
+
37
+ ## Implementation Notes
38
+
39
+ - FSMT uses source and target vocabulary pairs that aren't combined into one. It doesn't share embeddings tokens
40
+ either. Its tokenizer is very similar to [`XLMTokenizer`] and the main model is derived from
41
+ [`BartModel`].
42
+
43
+
44
+ ## FSMTConfig
45
+
46
+ [[autodoc]] FSMTConfig
47
+
48
+ ## FSMTTokenizer
49
+
50
+ [[autodoc]] FSMTTokenizer
51
+ - build_inputs_with_special_tokens
52
+ - get_special_tokens_mask
53
+ - create_token_type_ids_from_sequences
54
+ - save_vocabulary
55
+
56
+ ## FSMTModel
57
+
58
+ [[autodoc]] FSMTModel
59
+ - forward
60
+
61
+ ## FSMTForConditionalGeneration
62
+
63
+ [[autodoc]] FSMTForConditionalGeneration
64
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/funnel.md ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Funnel Transformer
18
+
19
+ <div class="flex flex-wrap space-x-1">
20
+ <a href="https://huggingface.co/models?filter=funnel">
21
+ <img alt="Models" src="https://img.shields.io/badge/All_model_pages-funnel-blueviolet">
22
+ </a>
23
+ <a href="https://huggingface.co/spaces/docs-demos/funnel-transformer-small">
24
+ <img alt="Spaces" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">
25
+ </a>
26
+ </div>
27
+
28
+
29
+ ## Overview
30
+
31
+ The Funnel Transformer model was proposed in the paper [Funnel-Transformer: Filtering out Sequential Redundancy for
32
+ Efficient Language Processing](https://arxiv.org/abs/2006.03236). It is a bidirectional transformer model, like
33
+ BERT, but with a pooling operation after each block of layers, a bit like in traditional convolutional neural networks
34
+ (CNN) in computer vision.
35
+
36
+ The abstract from the paper is the following:
37
+
38
+ *With the success of language pretraining, it is highly desirable to develop more efficient architectures of good
39
+ scalability that can exploit the abundant unlabeled data at a lower cost. To improve the efficiency, we examine the
40
+ much-overlooked redundancy in maintaining a full-length token-level presentation, especially for tasks that only
41
+ require a single-vector presentation of the sequence. With this intuition, we propose Funnel-Transformer which
42
+ gradually compresses the sequence of hidden states to a shorter one and hence reduces the computation cost. More
43
+ importantly, by re-investing the saved FLOPs from length reduction in constructing a deeper or wider model, we further
44
+ improve the model capacity. In addition, to perform token-level predictions as required by common pretraining
45
+ objectives, Funnel-Transformer is able to recover a deep representation for each token from the reduced hidden sequence
46
+ via a decoder. Empirically, with comparable or fewer FLOPs, Funnel-Transformer outperforms the standard Transformer on
47
+ a wide variety of sequence-level prediction tasks, including text classification, language understanding, and reading
48
+ comprehension.*
49
+
50
+ This model was contributed by [sgugger](https://huggingface.co/sgugger). The original code can be found [here](https://github.com/laiguokun/Funnel-Transformer).
51
+
52
+ ## Usage tips
53
+
54
+ - Since Funnel Transformer uses pooling, the sequence length of the hidden states changes after each block of layers. This way, their length is divided by 2, which speeds up the computation of the next hidden states.
55
+ The base model therefore has a final sequence length that is a quarter of the original one. This model can be used
56
+ directly for tasks that just require a sentence summary (like sequence classification or multiple choice). For other
57
+ tasks, the full model is used; this full model has a decoder that upsamples the final hidden states to the same
58
+ sequence length as the input.
59
+ - For tasks such as classification, this is not a problem, but for tasks like masked language modeling or token classification, we need a hidden state with the same sequence length as the original input. In those cases, the final hidden states are upsampled to the input sequence length and go through two additional layers. That's why there are two versions of each checkpoint. The version suffixed with “-base” contains only the three blocks, while the version without that suffix contains the three blocks and the upsampling head with its additional layers.
60
+ - The Funnel Transformer checkpoints are all available with a full version and a base version. The first ones should be
61
+ used for [`FunnelModel`], [`FunnelForPreTraining`],
62
+ [`FunnelForMaskedLM`], [`FunnelForTokenClassification`] and
63
+ [`FunnelForQuestionAnswering`]. The second ones should be used for
64
+ [`FunnelBaseModel`], [`FunnelForSequenceClassification`] and
65
+ [`FunnelForMultipleChoice`].
66
+
67
+ ## Resources
68
+
69
+ - [Text classification task guide](../tasks/sequence_classification)
70
+ - [Token classification task guide](../tasks/token_classification)
71
+ - [Question answering task guide](../tasks/question_answering)
72
+ - [Masked language modeling task guide](../tasks/masked_language_modeling)
73
+ - [Multiple choice task guide](../tasks/multiple_choice)
74
+
75
+
76
+ ## FunnelConfig
77
+
78
+ [[autodoc]] FunnelConfig
79
+
80
+ ## FunnelTokenizer
81
+
82
+ [[autodoc]] FunnelTokenizer
83
+ - build_inputs_with_special_tokens
84
+ - get_special_tokens_mask
85
+ - create_token_type_ids_from_sequences
86
+ - save_vocabulary
87
+
88
+ ## FunnelTokenizerFast
89
+
90
+ [[autodoc]] FunnelTokenizerFast
91
+
92
+ ## Funnel specific outputs
93
+
94
+ [[autodoc]] models.funnel.modeling_funnel.FunnelForPreTrainingOutput
95
+
96
+ [[autodoc]] models.funnel.modeling_tf_funnel.TFFunnelForPreTrainingOutput
97
+
98
+ <frameworkcontent>
99
+ <pt>
100
+
101
+ ## FunnelBaseModel
102
+
103
+ [[autodoc]] FunnelBaseModel
104
+ - forward
105
+
106
+ ## FunnelModel
107
+
108
+ [[autodoc]] FunnelModel
109
+ - forward
110
+
111
+ ## FunnelModelForPreTraining
112
+
113
+ [[autodoc]] FunnelForPreTraining
114
+ - forward
115
+
116
+ ## FunnelForMaskedLM
117
+
118
+ [[autodoc]] FunnelForMaskedLM
119
+ - forward
120
+
121
+ ## FunnelForSequenceClassification
122
+
123
+ [[autodoc]] FunnelForSequenceClassification
124
+ - forward
125
+
126
+ ## FunnelForMultipleChoice
127
+
128
+ [[autodoc]] FunnelForMultipleChoice
129
+ - forward
130
+
131
+ ## FunnelForTokenClassification
132
+
133
+ [[autodoc]] FunnelForTokenClassification
134
+ - forward
135
+
136
+ ## FunnelForQuestionAnswering
137
+
138
+ [[autodoc]] FunnelForQuestionAnswering
139
+ - forward
140
+
141
+ </pt>
142
+ <tf>
143
+
144
+ ## TFFunnelBaseModel
145
+
146
+ [[autodoc]] TFFunnelBaseModel
147
+ - call
148
+
149
+ ## TFFunnelModel
150
+
151
+ [[autodoc]] TFFunnelModel
152
+ - call
153
+
154
+ ## TFFunnelModelForPreTraining
155
+
156
+ [[autodoc]] TFFunnelForPreTraining
157
+ - call
158
+
159
+ ## TFFunnelForMaskedLM
160
+
161
+ [[autodoc]] TFFunnelForMaskedLM
162
+ - call
163
+
164
+ ## TFFunnelForSequenceClassification
165
+
166
+ [[autodoc]] TFFunnelForSequenceClassification
167
+ - call
168
+
169
+ ## TFFunnelForMultipleChoice
170
+
171
+ [[autodoc]] TFFunnelForMultipleChoice
172
+ - call
173
+
174
+ ## TFFunnelForTokenClassification
175
+
176
+ [[autodoc]] TFFunnelForTokenClassification
177
+ - call
178
+
179
+ ## TFFunnelForQuestionAnswering
180
+
181
+ [[autodoc]] TFFunnelForQuestionAnswering
182
+ - call
183
+
184
+ </tf>
185
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/fuyu.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Fuyu
18
+
19
+ ## Overview
20
+
21
+ The Fuyu model was created by [ADEPT](https://www.adept.ai/blog/fuyu-8b), and authored by Rohan Bavishi, Erich Elsen, Curtis Hawthorne, Maxwell Nye, Augustus Odena, Arushi Somani, Sağnak Taşırlar.
22
+
23
+ The authors introduced Fuyu-8B, a decoder-only multimodal model based on the classic transformers architecture, with query and key normalization. A linear encoder is added to create multimodal embeddings from image inputs.
24
+
25
+ By treating image tokens like text tokens and using a special image-newline character, the model knows when an image line ends. Image positional embeddings are removed. This avoids the need for different training phases for various image resolutions. With 8 billion parameters and licensed under CC-BY-NC, Fuyu-8B is notable for its ability to handle both text and images, its impressive context size of 16K, and its overall performance.
26
+
27
+ <Tip warning={true}>
28
+
29
+ The `Fuyu` models were trained using `bfloat16`, but the original inference uses `float16` The checkpoints uploaded on the hub use `torch_dtype = 'float16'` which will be
30
+ used by the `AutoModel` API to cast the checkpoints from `torch.float32` to `torch.float16`.
31
+
32
+ The `dtype` of the online weights is mostly irrelevant, unless you are using `torch_dtype="auto"` when initializing a model using `model = AutoModelForCausalLM.from_pretrained("path", torch_dtype = "auto")`. The reason is that the model will first be downloaded ( using the `dtype` of the checkpoints online) then it will be cast to the default `dtype` of `torch` (becomes `torch.float32`). Users should specify the `torch_dtype` they want, and if they don't it will be `torch.float32`.
33
+
34
+ Finetuning the model in `float16` is not recommended and known to produce `nan`, as such the model should be fine-tuned in `bfloat16`.
35
+
36
+ </Tip>
37
+
38
+
39
+ Tips:
40
+
41
+ - To convert the model, you need to clone the original repository using `git clone https://github.com/persimmon-ai-labs/adept-inference`, then get the checkpoints:
42
+
43
+ ```bash
44
+ git clone https://github.com/persimmon-ai-labs/adept-inference
45
+ wget path/to/fuyu-8b-model-weights.tar
46
+ tar -xvf fuyu-8b-model-weights.tar
47
+ python src/transformers/models/fuyu/convert_fuyu_weights_to_hf.py --input_dir /path/to/downloaded/fuyu/weights/ --output_dir /output/path \
48
+ --pt_model_path /path/to/fuyu_8b_release/iter_0001251/mp_rank_00/model_optim_rng.pt
49
+ --ada_lib_path /path/to/adept-inference
50
+ ```
51
+
52
+ For the chat model:
53
+ ```bash
54
+ wget https://axtkn4xl5cip.objectstorage.us-phoenix-1.oci.customer-oci.com/n/axtkn4xl5cip/b/adept-public-data/o/8b_chat_model_release.tar
55
+ tar -xvf 8b_base_model_release.tar
56
+ ```
57
+ Then, model can be loaded via:
58
+
59
+ ```py
60
+ from transformers import FuyuConfig, FuyuForCausalLM
61
+ model_config = FuyuConfig()
62
+ model = FuyuForCausalLM(model_config).from_pretrained('/output/path')
63
+ ```
64
+
65
+ Inputs need to be passed through a specific Processor to have the correct formats.
66
+ A processor requires an image_processor and a tokenizer. Hence, inputs can be loaded via:
67
+
68
+ ```py
69
+ from PIL import Image
70
+ from transformers import AutoTokenizer
71
+ from transformers.models.fuyu.processing_fuyu import FuyuProcessor
72
+ from transformers.models.fuyu.image_processing_fuyu import FuyuImageProcessor
73
+
74
+
75
+ tokenizer = AutoTokenizer.from_pretrained('adept-hf-collab/fuyu-8b')
76
+ image_processor = FuyuImageProcessor()
77
+
78
+
79
+ processor = FuyuProcessor(image_processor=image_processor, tokenizer=tokenizer)
80
+ text_prompt = "Generate a coco-style caption.\\n"
81
+
82
+ bus_image_url = "https://huggingface.co/datasets/hf-internal-testing/fixtures-captioning/resolve/main/bus.png"
83
+ bus_image_pil = Image.open(io.BytesIO(requests.get(bus_image_url).content))
84
+ inputs_to_model = processor(images=bus_image_pil, text=text_prompt)
85
+
86
+
87
+ ```
88
+
89
+ This model was contributed by [Molbap](https://huggingface.co/Molbap).
90
+ The original code can be found [here](https://github.com/persimmon-ai-labs/adept-inference).
91
+
92
+ - Fuyu uses a `sentencepiece` based tokenizer, with a `Unigram` model. It supports bytefallback, which is only available in `tokenizers==0.14.0` for the fast tokenizer.
93
+ The `LlamaTokenizer` is used as it is a standard wrapper around sentencepiece.
94
+
95
+ - The authors suggest to use the following prompt for image captioning: `f"Generate a coco-style caption.\\n"`
96
+
97
+
98
+ ## FuyuConfig
99
+
100
+ [[autodoc]] FuyuConfig
101
+
102
+ ## FuyuForCausalLM
103
+
104
+ [[autodoc]] FuyuForCausalLM
105
+ - forward
106
+
107
+ ## FuyuImageProcessor
108
+
109
+ [[autodoc]] FuyuImageProcessor
110
+ - __call__
111
+
112
+ ## FuyuProcessor
113
+
114
+ [[autodoc]] FuyuProcessor
115
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gemma.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Gemma
18
+
19
+ ## Overview
20
+
21
+ The Gemma model was proposed in [Gemma: Open Models Based on Gemini Technology and Research](https://blog.google/technology/developers/gemma-open-models/) by Gemma Team, Google.
22
+ Gemma models are trained on 6T tokens, and released with 2 versions, 2b and 7b.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ *This work introduces Gemma, a new family of open language models demonstrating strong performance across academic benchmarks for language understanding, reasoning, and safety. We release two sizes of models (2 billion and 7 billion parameters), and provide both pretrained and fine-tuned checkpoints. Gemma outperforms similarly sized open models on 11 out of 18 text-based tasks, and we present comprehensive evaluations of safety and responsibility aspects of the models, alongside a detailed description of our model development. We believe the responsible release of LLMs is critical for improving the safety of frontier models, and for enabling the next wave of LLM innovations*
27
+
28
+ Tips:
29
+
30
+ - The original checkpoints can be converted using the conversion script `src/transformers/models/gemma/convert_gemma_weights_to_hf.py`
31
+
32
+ This model was contributed by [Arthur Zucker](https://huggingface.co/ArthurZ), [Younes Belkada](https://huggingface.co/ybelkada), [Sanchit Gandhi](https://huggingface.co/sanchit-gandhi), [Pedro Cuenca](https://huggingface.co/pcuenq).
33
+
34
+
35
+ ## GemmaConfig
36
+
37
+ [[autodoc]] GemmaConfig
38
+
39
+ ## GemmaTokenizer
40
+
41
+ [[autodoc]] GemmaTokenizer
42
+
43
+
44
+ ## GemmaTokenizerFast
45
+
46
+ [[autodoc]] GemmaTokenizerFast
47
+
48
+ ## GemmaModel
49
+
50
+ [[autodoc]] GemmaModel
51
+ - forward
52
+
53
+ ## GemmaForCausalLM
54
+
55
+ [[autodoc]] GemmaForCausalLM
56
+ - forward
57
+
58
+ ## GemmaForSequenceClassification
59
+
60
+ [[autodoc]] GemmaForSequenceClassification
61
+ - forward
62
+
63
+ ## GemmaForTokenClassification
64
+
65
+ [[autodoc]] GemmaForTokenClassification
66
+ - forward
67
+
68
+ ## FlaxGemmaModel
69
+
70
+ [[autodoc]] FlaxGemmaModel
71
+ - __call__
72
+
73
+ ## FlaxGemmaForCausalLM
74
+
75
+ [[autodoc]] FlaxGemmaForCausalLM
76
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gemma2.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!--Copyright 2024 The HuggingFace Team. All rights reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5
+ the License. You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11
+ specific language governing permissions and limitations under the License.
12
+
13
+ ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
14
+ rendered properly in your Markdown viewer.
15
+
16
+ -->
17
+
18
+ # Gemma2
19
+
20
+ ## Overview
21
+
22
+ The Gemma2 model was proposed in [Gemma2: Open Models Based on Gemini Technology and Research](https://blog.google/technology/developers/google-gemma-2/) by Gemma2 Team, Google.
23
+ Two Gemma2 models are released, with parameters sizes of 9 billion (9B) and 27 billion (27B).
24
+
25
+ The abstract from the blog post is the following:
26
+
27
+ *Now we’re officially releasing Gemma 2 to researchers and developers globally. Available in both 9 billion (9B) and 27 billion (27B) parameter sizes, Gemma 2 is higher-performing and more efficient at inference than the first generation, with significant safety advancements built in. In fact, at 27B, it offers competitive alternatives to models more than twice its size, delivering the kind of performance that was only possible with proprietary models as recently as December.*
28
+
29
+ Tips:
30
+
31
+ - The original checkpoints can be converted using the conversion script `src/transformers/models/Gemma2/convert_Gemma2_weights_to_hf.py`
32
+
33
+ <Tip warning={true}>
34
+
35
+ - Gemma2 uses sliding window attention every second layer, which makes it unsuitable for typical kv caching with [`~DynamicCache`] or tuples of tensors. To enable caching in Gemma2 forward call, you must initialize a [`~HybridCache`] instance and pass it as `past_key_values` to the forward call. Note, that you also have to prepare `cache_position` if the `past_key_values` already contains previous keys and values.
36
+
37
+ </Tip>
38
+
39
+ This model was contributed by [Arthur Zucker](https://huggingface.co/ArthurZ), [Pedro Cuenca](https://huggingface.co/pcuenq) and [Tom Arsen]().
40
+
41
+
42
+ ## Gemma2Config
43
+
44
+ [[autodoc]] Gemma2Config
45
+
46
+ ## Gemma2Model
47
+
48
+ [[autodoc]] Gemma2Model
49
+ - forward
50
+
51
+ ## Gemma2ForCausalLM
52
+
53
+ [[autodoc]] Gemma2ForCausalLM
54
+ - forward
55
+
56
+ ## Gemma2ForSequenceClassification
57
+
58
+ [[autodoc]] Gemma2ForSequenceClassification
59
+ - forward
60
+
61
+ ## Gemma2ForTokenClassification
62
+
63
+ [[autodoc]] Gemma2ForTokenClassification
64
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/git.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GIT
18
+
19
+ ## Overview
20
+
21
+ The GIT model was proposed in [GIT: A Generative Image-to-text Transformer for Vision and Language](https://arxiv.org/abs/2205.14100) by
22
+ Jianfeng Wang, Zhengyuan Yang, Xiaowei Hu, Linjie Li, Kevin Lin, Zhe Gan, Zicheng Liu, Ce Liu, Lijuan Wang. GIT is a decoder-only Transformer
23
+ that leverages [CLIP](clip)'s vision encoder to condition the model on vision inputs besides text. The model obtains state-of-the-art results on
24
+ image captioning and visual question answering benchmarks.
25
+
26
+ The abstract from the paper is the following:
27
+
28
+ *In this paper, we design and train a Generative Image-to-text Transformer, GIT, to unify vision-language tasks such as image/video captioning and question answering. While generative models provide a consistent network architecture between pre-training and fine-tuning, existing work typically contains complex structures (uni/multi-modal encoder/decoder) and depends on external modules such as object detectors/taggers and optical character recognition (OCR). In GIT, we simplify the architecture as one image encoder and one text decoder under a single language modeling task. We also scale up the pre-training data and the model size to boost the model performance. Without bells and whistles, our GIT establishes new state of the arts on 12 challenging benchmarks with a large margin. For instance, our model surpasses the human performance for the first time on TextCaps (138.2 vs. 125.5 in CIDEr). Furthermore, we present a new scheme of generation-based image classification and scene text recognition, achieving decent performance on standard benchmarks.*
29
+
30
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/git_architecture.jpg"
31
+ alt="drawing" width="600"/>
32
+
33
+ <small> GIT architecture. Taken from the <a href="https://arxiv.org/abs/2205.14100" target="_blank">original paper</a>. </small>
34
+
35
+ This model was contributed by [nielsr](https://huggingface.co/nielsr).
36
+ The original code can be found [here](https://github.com/microsoft/GenerativeImage2Text).
37
+
38
+ ## Usage tips
39
+
40
+ - GIT is implemented in a very similar way to GPT-2, the only difference being that the model is also conditioned on `pixel_values`.
41
+
42
+ ## Resources
43
+
44
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with GIT.
45
+
46
+ - Demo notebooks regarding inference + fine-tuning GIT on custom data can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/GIT).
47
+ - See also: [Causal language modeling task guide](../tasks/language_modeling)
48
+
49
+ If you're interested in submitting a resource to be included here, please feel free to open a Pull Request and we will review it.
50
+ The resource should ideally demonstrate something new instead of duplicating an existing resource.
51
+
52
+ ## GitVisionConfig
53
+
54
+ [[autodoc]] GitVisionConfig
55
+
56
+ ## GitVisionModel
57
+
58
+ [[autodoc]] GitVisionModel
59
+ - forward
60
+
61
+ ## GitConfig
62
+
63
+ [[autodoc]] GitConfig
64
+ - all
65
+
66
+ ## GitProcessor
67
+
68
+ [[autodoc]] GitProcessor
69
+ - __call__
70
+
71
+ ## GitModel
72
+
73
+ [[autodoc]] GitModel
74
+ - forward
75
+
76
+ ## GitForCausalLM
77
+
78
+ [[autodoc]] GitForCausalLM
79
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/glm.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2024 The GLM & ZhipuAI team 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
+
17
+ # GLM
18
+
19
+ ## Overview
20
+
21
+ The GLM Model was proposed
22
+ in [ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools](https://arxiv.org/html/2406.12793v1)
23
+ by GLM Team, THUDM & ZhipuAI.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *We introduce ChatGLM, an evolving family of large language models that we have been developing over time. This report
28
+ primarily focuses on the GLM-4 language series, which includes GLM-4, GLM-4-Air, and GLM-4-9B. They represent our most
29
+ capable models that are trained with all the insights and lessons gained from the preceding three generations of
30
+ ChatGLM. To date, the GLM-4 models are pre-trained on ten trillions of tokens mostly in Chinese and English, along with
31
+ a small set of corpus from 24 languages, and aligned primarily for Chinese and English usage. The high-quality alignment
32
+ is achieved via a multi-stage post-training process, which involves supervised fine-tuning and learning from human
33
+ feedback. Evaluations show that GLM-4 1) closely rivals or outperforms GPT-4 in terms of general metrics such as MMLU,
34
+ GSM8K, MATH, BBH, GPQA, and HumanEval, 2) gets close to GPT-4-Turbo in instruction following as measured by IFEval, 3)
35
+ matches GPT-4 Turbo (128K) and Claude 3 for long context tasks, and 4) outperforms GPT-4 in Chinese alignments as
36
+ measured by AlignBench. The GLM-4 All Tools model is further aligned to understand user intent and autonomously decide
37
+ when and which tool(s) to use—including web browser, Python interpreter, text-to-image model, and user-defined
38
+ functions—to effectively complete complex tasks. In practical applications, it matches and even surpasses GPT-4 All
39
+ Tools in tasks like accessing online information via web browsing and solving math problems using Python interpreter.
40
+ Over the course, we have open-sourced a series of models, including ChatGLM-6B (three generations), GLM-4-9B (128K, 1M),
41
+ GLM-4V-9B, WebGLM, and CodeGeeX, attracting over 10 million downloads on Hugging face in the year 2023 alone.*
42
+
43
+ Tips:
44
+
45
+ - This model was contributed by [THUDM](https://huggingface.co/THUDM). The most recent code can be
46
+ found [here](https://github.com/thudm/GLM-4).
47
+
48
+
49
+ ## Usage tips
50
+
51
+ `GLM-4` can be found on the [Huggingface Hub](https://huggingface.co/collections/THUDM/glm-4-665fcf188c414b03c2f7e3b7)
52
+
53
+ In the following, we demonstrate how to use `glm-4-9b-chat` for the inference. Note that we have used the ChatML format for dialog, in this demo we show how to leverage `apply_chat_template` for this purpose.
54
+
55
+ ```python
56
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
57
+ >>> device = "cuda" # the device to load the model onto
58
+
59
+ >>> model = AutoModelForCausalLM.from_pretrained("THUDM/glm-4-9b-chat", device_map="auto")
60
+ >>> tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat")
61
+
62
+ >>> prompt = "Give me a short introduction to large language model."
63
+
64
+ >>> messages = [{"role": "user", "content": prompt}]
65
+
66
+ >>> text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67
+
68
+ >>> model_inputs = tokenizer([text], return_tensors="pt").to(device)
69
+
70
+ >>> generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=512, do_sample=True)
71
+
72
+ >>> generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
73
+
74
+ >>> response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
75
+ ```
76
+
77
+ ## GlmConfig
78
+
79
+ [[autodoc]] GlmConfig
80
+
81
+ ## GlmModel
82
+
83
+ [[autodoc]] GlmModel
84
+ - forward
85
+
86
+ ## GlmForCausalLM
87
+
88
+ [[autodoc]] GlmForCausalLM
89
+ - forward
90
+
91
+ ## GlmForSequenceClassification
92
+
93
+ [[autodoc]] GlmForSequenceClassification
94
+ - forward
95
+
96
+ ## GlmForTokenClassification
97
+
98
+ [[autodoc]] GlmForTokenClassification
99
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/glpn.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GLPN
18
+
19
+ <Tip>
20
+
21
+ This is a recently introduced model so the API hasn't been tested extensively. There may be some bugs or slight
22
+ breaking changes to fix it in the future. If you see something strange, file a [Github Issue](https://github.com/huggingface/transformers/issues/new?assignees=&labels=&template=bug-report.md&title).
23
+
24
+ </Tip>
25
+
26
+ ## Overview
27
+
28
+ The GLPN model was proposed in [Global-Local Path Networks for Monocular Depth Estimation with Vertical CutDepth](https://arxiv.org/abs/2201.07436) by Doyeon Kim, Woonghyun Ga, Pyungwhan Ahn, Donggyu Joo, Sehwan Chun, Junmo Kim.
29
+ GLPN combines [SegFormer](segformer)'s hierarchical mix-Transformer with a lightweight decoder for monocular depth estimation. The proposed decoder shows better performance than the previously proposed decoders, with considerably
30
+ less computational complexity.
31
+
32
+ The abstract from the paper is the following:
33
+
34
+ *Depth estimation from a single image is an important task that can be applied to various fields in computer vision, and has grown rapidly with the development of convolutional neural networks. In this paper, we propose a novel structure and training strategy for monocular depth estimation to further improve the prediction accuracy of the network. We deploy a hierarchical transformer encoder to capture and convey the global context, and design a lightweight yet powerful decoder to generate an estimated depth map while considering local connectivity. By constructing connected paths between multi-scale local features and the global decoding stream with our proposed selective feature fusion module, the network can integrate both representations and recover fine details. In addition, the proposed decoder shows better performance than the previously proposed decoders, with considerably less computational complexity. Furthermore, we improve the depth-specific augmentation method by utilizing an important observation in depth estimation to enhance the model. Our network achieves state-of-the-art performance over the challenging depth dataset NYU Depth V2. Extensive experiments have been conducted to validate and show the effectiveness of the proposed approach. Finally, our model shows better generalisation ability and robustness than other comparative models.*
35
+
36
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/glpn_architecture.jpg"
37
+ alt="drawing" width="600"/>
38
+
39
+ <small> Summary of the approach. Taken from the <a href="https://arxiv.org/abs/2201.07436" target="_blank">original paper</a>. </small>
40
+
41
+ This model was contributed by [nielsr](https://huggingface.co/nielsr). The original code can be found [here](https://github.com/vinvino02/GLPDepth).
42
+
43
+ ## Resources
44
+
45
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with GLPN.
46
+
47
+ - Demo notebooks for [`GLPNForDepthEstimation`] can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/GLPN).
48
+ - [Monocular depth estimation task guide](../tasks/monocular_depth_estimation)
49
+
50
+ ## GLPNConfig
51
+
52
+ [[autodoc]] GLPNConfig
53
+
54
+ ## GLPNFeatureExtractor
55
+
56
+ [[autodoc]] GLPNFeatureExtractor
57
+ - __call__
58
+
59
+ ## GLPNImageProcessor
60
+
61
+ [[autodoc]] GLPNImageProcessor
62
+ - preprocess
63
+
64
+ ## GLPNModel
65
+
66
+ [[autodoc]] GLPNModel
67
+ - forward
68
+
69
+ ## GLPNForDepthEstimation
70
+
71
+ [[autodoc]] GLPNForDepthEstimation
72
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt-sw3.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPT-Sw3
18
+
19
+ ## Overview
20
+
21
+ The GPT-Sw3 model was first proposed in
22
+ [Lessons Learned from GPT-SW3: Building the First Large-Scale Generative Language Model for Swedish](http://www.lrec-conf.org/proceedings/lrec2022/pdf/2022.lrec-1.376.pdf)
23
+ by Ariel Ekgren, Amaru Cuba Gyllensten, Evangelia Gogoulou, Alice Heiman, Severine Verlinden, Joey Öhman,
24
+ Fredrik Carlsson, Magnus Sahlgren.
25
+
26
+ Since that first paper the authors have extended their work and trained new models on their new 1.2TB corpora named The Nordic Pile.
27
+
28
+ GPT-Sw3 is a collection of large decoder-only pretrained transformer language models that were developed by AI Sweden
29
+ in collaboration with RISE and the WASP WARA for Media and Language. GPT-Sw3 has been trained on a dataset containing
30
+ 320B tokens in Swedish, Norwegian, Danish, Icelandic, English, and programming code. The model was pretrained using a
31
+ causal language modeling (CLM) objective utilizing the NeMo Megatron GPT implementation.
32
+
33
+ This model was contributed by [AI Sweden Models](https://huggingface.co/AI-Sweden-Models).
34
+
35
+ ## Usage example
36
+
37
+ ```python
38
+ >>> from transformers import AutoTokenizer, AutoModelForCausalLM
39
+
40
+ >>> tokenizer = AutoTokenizer.from_pretrained("AI-Sweden-Models/gpt-sw3-356m")
41
+ >>> model = AutoModelForCausalLM.from_pretrained("AI-Sweden-Models/gpt-sw3-356m")
42
+
43
+ >>> input_ids = tokenizer("Träd är fina för att", return_tensors="pt")["input_ids"]
44
+
45
+ >>> generated_token_ids = model.generate(inputs=input_ids, max_new_tokens=10, do_sample=True)[0]
46
+
47
+ >>> print(tokenizer.decode(generated_token_ids))
48
+ Träd är fina för att de är färgstarka. Men ibland är det fint
49
+ ```
50
+
51
+ ## Resources
52
+
53
+ - [Text classification task guide](../tasks/sequence_classification)
54
+ - [Token classification task guide](../tasks/token_classification)
55
+ - [Causal language modeling task guide](../tasks/language_modeling)
56
+
57
+ <Tip>
58
+
59
+ The implementation uses the `GPT2Model` coupled with our `GPTSw3Tokenizer`. Refer to [GPT2Model documentation](gpt2)
60
+ for API reference and examples.
61
+
62
+ Note that sentencepiece is required to use our tokenizer and can be installed with `pip install transformers[sentencepiece]` or `pip install sentencepiece`
63
+
64
+ </Tip>
65
+
66
+ ## GPTSw3Tokenizer
67
+
68
+ [[autodoc]] GPTSw3Tokenizer
69
+ - save_vocabulary
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt2.md ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # OpenAI GPT2
18
+
19
+ <div class="flex flex-wrap space-x-1">
20
+ <a href="https://huggingface.co/models?filter=gpt2">
21
+ <img alt="Models" src="https://img.shields.io/badge/All_model_pages-gpt2-blueviolet">
22
+ </a>
23
+ <a href="https://huggingface.co/spaces/docs-demos/gpt2">
24
+ <img alt="Spaces" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">
25
+ </a>
26
+ </div>
27
+
28
+ ## Overview
29
+
30
+ OpenAI GPT-2 model was proposed in [Language Models are Unsupervised Multitask Learners](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf) by Alec
31
+ Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei and Ilya Sutskever from [OpenAI](https://huggingface.co/openai). It's a causal (unidirectional)
32
+ transformer pretrained using language modeling on a very large corpus of ~40 GB of text data.
33
+
34
+ The abstract from the paper is the following:
35
+
36
+ *GPT-2 is a large transformer-based language model with 1.5 billion parameters, trained on a dataset[1] of 8 million
37
+ web pages. GPT-2 is trained with a simple objective: predict the next word, given all of the previous words within some
38
+ text. The diversity of the dataset causes this simple goal to contain naturally occurring demonstrations of many tasks
39
+ across diverse domains. GPT-2 is a direct scale-up of GPT, with more than 10X the parameters and trained on more than
40
+ 10X the amount of data.*
41
+
42
+ [Write With Transformer](https://transformer.huggingface.co/doc/gpt2-large) is a webapp created and hosted by
43
+ Hugging Face showcasing the generative capabilities of several models. GPT-2 is one of them and is available in five
44
+ different sizes: small, medium, large, xl and a distilled version of the small checkpoint: *distilgpt-2*.
45
+
46
+ This model was contributed by [thomwolf](https://huggingface.co/thomwolf). The original code can be found [here](https://openai.com/blog/better-language-models/).
47
+
48
+ ## Usage tips
49
+
50
+ - GPT-2 is a model with absolute position embeddings so it's usually advised to pad the inputs on the right rather than
51
+ the left.
52
+ - GPT-2 was trained with a causal language modeling (CLM) objective and is therefore powerful at predicting the next
53
+ token in a sequence. Leveraging this feature allows GPT-2 to generate syntactically coherent text as it can be
54
+ observed in the *run_generation.py* example script.
55
+ - The model can take the *past_key_values* (for PyTorch) or *past* (for TF) as input, which is the previously computed
56
+ key/value attention pairs. Using this (*past_key_values* or *past*) value prevents the model from re-computing
57
+ pre-computed values in the context of text generation. For PyTorch, see *past_key_values* argument of the
58
+ [`GPT2Model.forward`] method, or for TF the *past* argument of the
59
+ [`TFGPT2Model.call`] method for more information on its usage.
60
+ - Enabling the *scale_attn_by_inverse_layer_idx* and *reorder_and_upcast_attn* flags will apply the training stability
61
+ improvements from [Mistral](https://github.com/stanford-crfm/mistral/) (for PyTorch only).
62
+
63
+ ## Usage example
64
+
65
+ The `generate()` method can be used to generate text using GPT2 model.
66
+
67
+ ```python
68
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
69
+
70
+ >>> model = AutoModelForCausalLM.from_pretrained("gpt2")
71
+ >>> tokenizer = AutoTokenizer.from_pretrained("gpt2")
72
+
73
+ >>> prompt = "GPT2 is a model developed by OpenAI."
74
+
75
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids
76
+
77
+ >>> gen_tokens = model.generate(
78
+ ... input_ids,
79
+ ... do_sample=True,
80
+ ... temperature=0.9,
81
+ ... max_length=100,
82
+ ... )
83
+ >>> gen_text = tokenizer.batch_decode(gen_tokens)[0]
84
+ ```
85
+
86
+ ## Using Flash Attention 2
87
+
88
+ Flash Attention 2 is a faster, optimized version of the attention scores computation which relies on `cuda` kernels.
89
+
90
+ ### Installation
91
+
92
+ First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the [official documentation](https://github.com/Dao-AILab/flash-attention#installation-and-features). If your hardware is not compatible with Flash Attention 2, you can still benefit from attention kernel optimisations through Better Transformer support covered [above](https://huggingface.co/docs/transformers/main/en/model_doc/bark#using-better-transformer).
93
+
94
+ Next, [install](https://github.com/Dao-AILab/flash-attention#installation-and-features) the latest version of Flash Attention 2:
95
+
96
+ ```bash
97
+ pip install -U flash-attn --no-build-isolation
98
+ ```
99
+
100
+ ### Usage
101
+
102
+ To load a model using Flash Attention 2, we can pass the argument `attn_implementation="flash_attention_2"` to [`.from_pretrained`](https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained). We'll also load the model in half-precision (e.g. `torch.float16`), since it results in almost no degradation to audio quality but significantly lower memory usage and faster inference:
103
+
104
+ ```python
105
+ >>> import torch
106
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
107
+ >>> device = "cuda" # the device to load the model onto
108
+
109
+ >>> model = AutoModelForCausalLM.from_pretrained("gpt2", torch_dtype=torch.float16, attn_implementation="flash_attention_2")
110
+ >>> tokenizer = AutoTokenizer.from_pretrained("gpt2")
111
+
112
+ >>> prompt = "def hello_world():"
113
+
114
+ >>> model_inputs = tokenizer([prompt], return_tensors="pt").to(device)
115
+ >>> model.to(device)
116
+
117
+ >>> generated_ids = model.generate(**model_inputs, max_new_tokens=100, do_sample=True)
118
+ >>> tokenizer.batch_decode(generated_ids)[0]
119
+ ```
120
+
121
+
122
+ ### Expected speedups
123
+
124
+ Below is an expected speedup diagram that compares pure inference time between the native implementation in transformers using `gpt2` checkpoint and the Flash Attention 2 version of the model using a sequence length of 512.
125
+
126
+ <div style="text-align: center">
127
+ <img src="https://huggingface.co/datasets/EduardoPacheco/documentation-images/resolve/main/gpt2_flash_attention_2_speedup.jpg">
128
+ </div>
129
+
130
+
131
+ ## Using Scaled Dot Product Attention (SDPA)
132
+ PyTorch includes a native scaled dot-product attention (SDPA) operator as part of `torch.nn.functional`. This function
133
+ encompasses several implementations that can be applied depending on the inputs and the hardware in use. See the
134
+ [official documentation](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)
135
+ or the [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)
136
+ page for more information.
137
+
138
+ SDPA is used by default for `torch>=2.1.1` when an implementation is available, but you may also set
139
+ `attn_implementation="sdpa"` in `from_pretrained()` to explicitly request SDPA to be used.
140
+
141
+ ```python
142
+ from transformers import AutoModelForCausalLM
143
+ model = AutoModelForCausalLM.from_pretrained("gpt2", torch_dtype=torch.float16, attn_implementation="sdpa")
144
+ ...
145
+ ```
146
+
147
+ For the best speedups, we recommend loading the model in half-precision (e.g. `torch.float16` or `torch.bfloat16`).
148
+
149
+ On a local benchmark (rtx3080ti-16GB, PyTorch 2.2.1, OS Ubuntu 22.04) using `float16` with
150
+ [gpt2-large](https://huggingface.co/openai-community/gpt2-large), we saw the
151
+ following speedups during training and inference.
152
+
153
+ ### Training
154
+ | Batch size | Seq len | Time per batch (Eager - s) | Time per batch (SDPA - s) | Speedup (%) | Eager peak mem (MB) | SDPA peak mem (MB) | Mem saving (%) |
155
+ |-----------:|--------:|----------------------------:|--------------------------:|------------:|--------------------:|-------------------:|------------------:|
156
+ | 1 | 128 | 0.039 | 0.032 | 23.042 | 3482.32 | 3494.62 | -0.352 |
157
+ | 1 | 256 | 0.073 | 0.059 | 25.15 | 3546.66 | 3552.6 | -0.167 |
158
+ | 1 | 512 | 0.155 | 0.118 | 30.96 | 4230.1 | 3665.59 | 15.4 |
159
+ | 1 | 1024 | 0.316 | 0.209 | 50.839 | 8682.26 | 4881.09 | 77.875 |
160
+ | 2 | 128 | 0.07 | 0.06 | 15.324 | 3557.8 | 3545.91 | 0.335 |
161
+ | 2 | 256 | 0.143 | 0.122 | 16.53 | 3901.5 | 3657.68 | 6.666 |
162
+ | 2 | 512 | 0.267 | 0.213 | 25.626 | 7062.21 | 4876.47 | 44.822 |
163
+ | 2 | 1024 | OOM | 0.404 | / | OOM | 8096.35 | SDPA does not OOM |
164
+ | 4 | 128 | 0.134 | 0.128 | 4.412 | 3675.79 | 3648.72 | 0.742 |
165
+ | 4 | 256 | 0.243 | 0.217 | 12.292 | 6129.76 | 4871.12 | 25.839 |
166
+ | 4 | 512 | 0.494 | 0.406 | 21.687 | 12466.6 | 8102.64 | 53.858 |
167
+ | 4 | 1024 | OOM | 0.795 | / | OOM | 14568.2 | SDPA does not OOM |
168
+
169
+ ### Inference
170
+ | Batch size | Seq len | Per token latency Eager (ms) | Per token latency SDPA (ms) | Speedup (%) | Mem Eager (MB) | Mem SDPA (MB) | Mem saved (%) |
171
+ |-----------:|--------:|-----------------------------:|----------------------------:|------------:|---------------:|--------------:|--------------:|
172
+ | 1 | 128 | 7.991 | 6.968 | 14.681 | 1685.2 | 1701.32 | -0.947 |
173
+ | 1 | 256 | 8.462 | 7.199 | 17.536 | 1745.49 | 1770.78 | -1.428 |
174
+ | 1 | 512 | 8.68 | 7.853 | 10.529 | 1907.69 | 1921.29 | -0.708 |
175
+ | 1 | 768 | 9.101 | 8.365 | 8.791 | 2032.93 | 2068.12 | -1.701 |
176
+ | 2 | 128 | 9.169 | 9.001 | 1.861 | 1803.84 | 1811.4 | -0.418 |
177
+ | 2 | 256 | 9.907 | 9.78 | 1.294 | 1907.72 | 1921.44 | -0.714 |
178
+ | 2 | 512 | 11.519 | 11.644 | -1.071 | 2176.86 | 2197.75 | -0.951 |
179
+ | 2 | 768 | 13.022 | 13.407 | -2.873 | 2464.3 | 2491.06 | -1.074 |
180
+ | 4 | 128 | 10.097 | 9.831 | 2.709 | 1942.25 | 1985.13 | -2.16 |
181
+ | 4 | 256 | 11.599 | 11.398 | 1.764 | 2177.28 | 2197.86 | -0.937 |
182
+ | 4 | 512 | 14.653 | 14.45 | 1.411 | 2753.16 | 2772.57 | -0.7 |
183
+ | 4 | 768 | 17.846 | 17.617 | 1.299 | 3327.04 | 3343.97 | -0.506 |
184
+
185
+
186
+
187
+
188
+ ## Resources
189
+
190
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with GPT2. 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.
191
+
192
+ <PipelineTag pipeline="text-generation"/>
193
+
194
+ - A blog on how to [Finetune a non-English GPT-2 Model with Hugging Face](https://www.philschmid.de/fine-tune-a-non-english-gpt-2-model-with-huggingface).
195
+ - A blog on [How to generate text: using different decoding methods for language generation with Transformers](https://huggingface.co/blog/how-to-generate) with GPT-2.
196
+ - A blog on [Training CodeParrot 🦜 from Scratch](https://huggingface.co/blog/codeparrot), a large GPT-2 model.
197
+ - A blog on [Faster Text Generation with TensorFlow and XLA](https://huggingface.co/blog/tf-xla-generate) with GPT-2.
198
+ - A blog on [How to train a Language Model with Megatron-LM](https://huggingface.co/blog/megatron-training) with a GPT-2 model.
199
+ - A notebook on how to [finetune GPT2 to generate lyrics in the style of your favorite artist](https://colab.research.google.com/github/AlekseyKorshuk/huggingartists/blob/master/huggingartists-demo.ipynb). 🌎
200
+ - A notebook on how to [finetune GPT2 to generate tweets in the style of your favorite Twitter user](https://colab.research.google.com/github/borisdayma/huggingtweets/blob/master/huggingtweets-demo.ipynb). 🌎
201
+ - [Causal language modeling](https://huggingface.co/course/en/chapter7/6?fw=pt#training-a-causal-language-model-from-scratch) chapter of the 🤗 Hugging Face Course.
202
+ - [`GPT2LMHeadModel`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language-modeling#gpt-2gpt-and-causal-language-modeling), [text generation example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/text-generation), and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling.ipynb).
203
+ - [`TFGPT2LMHeadModel`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/language-modeling#run_clmpy) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling-tf.ipynb).
204
+ - [`FlaxGPT2LMHeadModel`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/flax/language-modeling#causal-language-modeling) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/causal_language_modeling_flax.ipynb).
205
+ - [Text classification task guide](../tasks/sequence_classification)
206
+ - [Token classification task guide](../tasks/token_classification)
207
+ - [Causal language modeling task guide](../tasks/language_modeling)
208
+
209
+ ## GPT2Config
210
+
211
+ [[autodoc]] GPT2Config
212
+
213
+ ## GPT2Tokenizer
214
+
215
+ [[autodoc]] GPT2Tokenizer
216
+ - save_vocabulary
217
+
218
+ ## GPT2TokenizerFast
219
+
220
+ [[autodoc]] GPT2TokenizerFast
221
+
222
+ ## GPT2 specific outputs
223
+
224
+ [[autodoc]] models.gpt2.modeling_gpt2.GPT2DoubleHeadsModelOutput
225
+
226
+ [[autodoc]] models.gpt2.modeling_tf_gpt2.TFGPT2DoubleHeadsModelOutput
227
+
228
+ <frameworkcontent>
229
+ <pt>
230
+
231
+ ## GPT2Model
232
+
233
+ [[autodoc]] GPT2Model
234
+ - forward
235
+
236
+ ## GPT2LMHeadModel
237
+
238
+ [[autodoc]] GPT2LMHeadModel
239
+ - forward
240
+
241
+ ## GPT2DoubleHeadsModel
242
+
243
+ [[autodoc]] GPT2DoubleHeadsModel
244
+ - forward
245
+
246
+ ## GPT2ForQuestionAnswering
247
+
248
+ [[autodoc]] GPT2ForQuestionAnswering
249
+ - forward
250
+
251
+ ## GPT2ForSequenceClassification
252
+
253
+ [[autodoc]] GPT2ForSequenceClassification
254
+ - forward
255
+
256
+ ## GPT2ForTokenClassification
257
+
258
+ [[autodoc]] GPT2ForTokenClassification
259
+ - forward
260
+
261
+ </pt>
262
+ <tf>
263
+
264
+ ## TFGPT2Model
265
+
266
+ [[autodoc]] TFGPT2Model
267
+ - call
268
+
269
+ ## TFGPT2LMHeadModel
270
+
271
+ [[autodoc]] TFGPT2LMHeadModel
272
+ - call
273
+
274
+ ## TFGPT2DoubleHeadsModel
275
+
276
+ [[autodoc]] TFGPT2DoubleHeadsModel
277
+ - call
278
+
279
+ ## TFGPT2ForSequenceClassification
280
+
281
+ [[autodoc]] TFGPT2ForSequenceClassification
282
+ - call
283
+
284
+ ## TFSequenceClassifierOutputWithPast
285
+
286
+ [[autodoc]] modeling_tf_outputs.TFSequenceClassifierOutputWithPast
287
+
288
+ ## TFGPT2Tokenizer
289
+
290
+ [[autodoc]] TFGPT2Tokenizer
291
+
292
+ </tf>
293
+ <jax>
294
+
295
+ ## FlaxGPT2Model
296
+
297
+ [[autodoc]] FlaxGPT2Model
298
+ - __call__
299
+
300
+ ## FlaxGPT2LMHeadModel
301
+
302
+ [[autodoc]] FlaxGPT2LMHeadModel
303
+ - __call__
304
+
305
+ </jax>
306
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_bigcode.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPTBigCode
18
+
19
+ ## Overview
20
+
21
+ The GPTBigCode model was proposed in [SantaCoder: don't reach for the stars!](https://arxiv.org/abs/2301.03988) by BigCode. The listed authors are: Loubna Ben Allal, Raymond Li, Denis Kocetkov, Chenghao Mou, Christopher Akiki, Carlos Munoz Ferrandis, Niklas Muennighoff, Mayank Mishra, Alex Gu, Manan Dey, Logesh Kumar Umapathi, Carolyn Jane Anderson, Yangtian Zi, Joel Lamy Poirier, Hailey Schoelkopf, Sergey Troshin, Dmitry Abulkhanov, Manuel Romero, Michael Lappert, Francesco De Toni, Bernardo García del Río, Qian Liu, Shamik Bose, Urvashi Bhattacharyya, Terry Yue Zhuo, Ian Yu, Paulo Villegas, Marco Zocca, Sourab Mangrulkar, David Lansky, Huu Nguyen, Danish Contractor, Luis Villa, Jia Li, Dzmitry Bahdanau, Yacine Jernite, Sean Hughes, Daniel Fried, Arjun Guha, Harm de Vries, Leandro von Werra.
22
+
23
+ The abstract from the paper is the following:
24
+
25
+ *The BigCode project is an open-scientific collaboration working on the responsible development of large language models for code. This tech report describes the progress of the collaboration until December 2022, outlining the current state of the Personally Identifiable Information (PII) redaction pipeline, the experiments conducted to de-risk the model architecture, and the experiments investigating better preprocessing methods for the training data. We train 1.1B parameter models on the Java, JavaScript, and Python subsets of The Stack and evaluate them on the MultiPL-E text-to-code benchmark. We find that more aggressive filtering of near-duplicates can further boost performance and, surprisingly, that selecting files from repositories with 5+ GitHub stars deteriorates performance significantly. Our best model outperforms previous open-source multilingual code generation models (InCoder-6.7B and CodeGen-Multi-2.7B) in both left-to-right generation and infilling on the Java, JavaScript, and Python portions of MultiPL-E, despite being a substantially smaller model. All models are released under an OpenRAIL license at [this https URL.](https://huggingface.co/bigcode)*
26
+
27
+ The model is an optimized [GPT2 model](https://huggingface.co/docs/transformers/model_doc/gpt2) with support for Multi-Query Attention.
28
+
29
+ ## Implementation details
30
+
31
+ The main differences compared to GPT2.
32
+ - Added support for Multi-Query Attention.
33
+ - Use `gelu_pytorch_tanh` instead of classic `gelu`.
34
+ - Avoid unnecessary synchronizations (this has since been added to GPT2 in #20061, but wasn't in the reference codebase).
35
+ - Use Linear layers instead of Conv1D (good speedup but makes the checkpoints incompatible).
36
+ - Merge `_attn` and `_upcast_and_reordered_attn`. Always merge the matmul with scaling. Rename `reorder_and_upcast_attn`->`attention_softmax_in_fp32`
37
+ - Cache the attention mask value to avoid recreating it every time.
38
+ - Use jit to fuse the attention fp32 casting, masking, softmax, and scaling.
39
+ - Combine the attention and causal masks into a single one, pre-computed for the whole model instead of every layer.
40
+ - Merge the key and value caches into one (this changes the format of layer_past/ present, does it risk creating problems?)
41
+ - Use the memory layout (self.num_heads, 3, self.head_dim) instead of `(3, self.num_heads, self.head_dim)` for the QKV tensor with MHA. (prevents an overhead with the merged key and values, but makes the checkpoints incompatible with the original openai-community/gpt2 model).
42
+
43
+ You can read more about the optimizations in the [original pull request](https://github.com/huggingface/transformers/pull/22575)
44
+
45
+ ## Combining Starcoder and Flash Attention 2
46
+
47
+ First, make sure to install the latest version of Flash Attention 2 to include the sliding window attention feature.
48
+
49
+ ```bash
50
+ pip install -U flash-attn --no-build-isolation
51
+ ```
52
+
53
+ Make also sure that you have a hardware that is compatible with Flash-Attention 2. Read more about it in the official documentation of flash-attn repository. Make also sure to load your model in half-precision (e.g. `torch.float16``)
54
+
55
+ To load and run a model using Flash Attention 2, refer to the snippet below:
56
+
57
+ ```python
58
+ >>> import torch
59
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
60
+ >>> device = "cuda" # the device to load the model onto
61
+
62
+ >>> model = AutoModelForCausalLM.from_pretrained("bigcode/gpt_bigcode-santacoder", torch_dtype=torch.float16, attn_implementation="flash_attention_2")
63
+ >>> tokenizer = AutoTokenizer.from_pretrained("bigcode/gpt_bigcode-santacoder")
64
+
65
+ >>> prompt = "def hello_world():"
66
+
67
+ >>> model_inputs = tokenizer([prompt], return_tensors="pt").to(device)
68
+ >>> model.to(device)
69
+
70
+ >>> generated_ids = model.generate(**model_inputs, max_new_tokens=30, do_sample=False)
71
+ >>> tokenizer.batch_decode(generated_ids)[0]
72
+ 'def hello_world():\n print("hello world")\n\nif __name__ == "__main__":\n print("hello world")\n<|endoftext|>'
73
+ ```
74
+
75
+ ### Expected speedups
76
+
77
+ Below is a expected speedup diagram that compares pure inference time between the native implementation in transformers using `bigcode/starcoder` checkpoint and the Flash Attention 2 version of the model using two different sequence lengths.
78
+
79
+ <div style="text-align: center">
80
+ <img src="https://huggingface.co/datasets/ybelkada/documentation-images/resolve/main/starcoder-speedup.png">
81
+ </div>
82
+
83
+
84
+ ## GPTBigCodeConfig
85
+
86
+ [[autodoc]] GPTBigCodeConfig
87
+
88
+ ## GPTBigCodeModel
89
+
90
+ [[autodoc]] GPTBigCodeModel
91
+ - forward
92
+
93
+ ## GPTBigCodeForCausalLM
94
+
95
+ [[autodoc]] GPTBigCodeForCausalLM
96
+ - forward
97
+
98
+ ## GPTBigCodeForSequenceClassification
99
+
100
+ [[autodoc]] GPTBigCodeForSequenceClassification
101
+ - forward
102
+
103
+ ## GPTBigCodeForTokenClassification
104
+
105
+ [[autodoc]] GPTBigCodeForTokenClassification
106
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neo.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPT Neo
18
+
19
+ ## Overview
20
+
21
+ The GPTNeo model was released in the [EleutherAI/gpt-neo](https://github.com/EleutherAI/gpt-neo) repository by Sid
22
+ Black, Stella Biderman, Leo Gao, Phil Wang and Connor Leahy. It is a GPT2 like causal language model trained on the
23
+ [Pile](https://pile.eleuther.ai/) dataset.
24
+
25
+ The architecture is similar to GPT2 except that GPT Neo uses local attention in every other layer with a window size of
26
+ 256 tokens.
27
+
28
+ This model was contributed by [valhalla](https://huggingface.co/valhalla).
29
+
30
+ ## Usage example
31
+
32
+ The `generate()` method can be used to generate text using GPT Neo model.
33
+
34
+ ```python
35
+ >>> from transformers import GPTNeoForCausalLM, GPT2Tokenizer
36
+
37
+ >>> model = GPTNeoForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
38
+ >>> tokenizer = GPT2Tokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
39
+
40
+ >>> prompt = (
41
+ ... "In a shocking finding, scientists discovered a herd of unicorns living in a remote, "
42
+ ... "previously unexplored valley, in the Andes Mountains. Even more surprising to the "
43
+ ... "researchers was the fact that the unicorns spoke perfect English."
44
+ ... )
45
+
46
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids
47
+
48
+ >>> gen_tokens = model.generate(
49
+ ... input_ids,
50
+ ... do_sample=True,
51
+ ... temperature=0.9,
52
+ ... max_length=100,
53
+ ... )
54
+ >>> gen_text = tokenizer.batch_decode(gen_tokens)[0]
55
+ ```
56
+
57
+ ## Combining GPT-Neo and Flash Attention 2
58
+
59
+ First, make sure to install the latest version of Flash Attention 2 to include the sliding window attention feature, and make sure your hardware is compatible with Flash-Attention 2. More details are available [here](https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-2) concerning the installation.
60
+
61
+ Make sure as well to load your model in half-precision (e.g. `torch.float16`).
62
+
63
+ To load and run a model using Flash Attention 2, refer to the snippet below:
64
+
65
+ ```python
66
+ >>> import torch
67
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
68
+ >>> device = "cuda" # the device to load the model onto
69
+
70
+ >>> model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-2.7B", torch_dtype=torch.float16, attn_implementation="flash_attention_2")
71
+ >>> tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
72
+
73
+ >>> prompt = "def hello_world():"
74
+
75
+ >>> model_inputs = tokenizer([prompt], return_tensors="pt").to(device)
76
+ >>> model.to(device)
77
+
78
+ >>> generated_ids = model.generate(**model_inputs, max_new_tokens=100, do_sample=True)
79
+ >>> tokenizer.batch_decode(generated_ids)[0]
80
+ "def hello_world():\n >>> run_script("hello.py")\n >>> exit(0)\n<|endoftext|>"
81
+ ```
82
+
83
+ ### Expected speedups
84
+
85
+ Below is an expected speedup diagram that compares pure inference time between the native implementation in transformers using `EleutherAI/gpt-neo-2.7B` checkpoint and the Flash Attention 2 version of the model.
86
+ Note that for GPT-Neo it is not possible to train / run on very long context as the max [position embeddings](https://huggingface.co/EleutherAI/gpt-neo-2.7B/blob/main/config.json#L58 ) is limited to 2048 - but this is applicable to all gpt-neo models and not specific to FA-2
87
+
88
+ <div style="text-align: center">
89
+ <img src="https://user-images.githubusercontent.com/49240599/272241893-b1c66b75-3a48-4265-bc47-688448568b3d.png">
90
+ </div>
91
+
92
+
93
+ ## Resources
94
+
95
+ - [Text classification task guide](../tasks/sequence_classification)
96
+ - [Causal language modeling task guide](../tasks/language_modeling)
97
+
98
+ ## GPTNeoConfig
99
+
100
+ [[autodoc]] GPTNeoConfig
101
+
102
+
103
+ <frameworkcontent>
104
+ <pt>
105
+
106
+ ## GPTNeoModel
107
+
108
+ [[autodoc]] GPTNeoModel
109
+ - forward
110
+
111
+ ## GPTNeoForCausalLM
112
+
113
+ [[autodoc]] GPTNeoForCausalLM
114
+ - forward
115
+
116
+ ## GPTNeoForQuestionAnswering
117
+
118
+ [[autodoc]] GPTNeoForQuestionAnswering
119
+ - forward
120
+
121
+ ## GPTNeoForSequenceClassification
122
+
123
+ [[autodoc]] GPTNeoForSequenceClassification
124
+ - forward
125
+
126
+ ## GPTNeoForTokenClassification
127
+
128
+ [[autodoc]] GPTNeoForTokenClassification
129
+ - forward
130
+
131
+ </pt>
132
+ <jax>
133
+
134
+ ## FlaxGPTNeoModel
135
+
136
+ [[autodoc]] FlaxGPTNeoModel
137
+ - __call__
138
+
139
+ ## FlaxGPTNeoForCausalLM
140
+
141
+ [[autodoc]] FlaxGPTNeoForCausalLM
142
+ - __call__
143
+
144
+ </jax>
145
+ </frameworkcontent>
146
+
147
+
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neox.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPT-NeoX
18
+
19
+ ## Overview
20
+
21
+ We introduce GPT-NeoX-20B, a 20 billion parameter autoregressive language model trained on the Pile, whose weights will
22
+ be made freely and openly available to the public through a permissive license. It is, to the best of our knowledge,
23
+ the largest dense autoregressive model that has publicly available weights at the time of submission. In this work,
24
+ we describe GPT-NeoX-20B's architecture and training and evaluate its performance on a range of language-understanding,
25
+ mathematics, and knowledge-based tasks. We find that GPT-NeoX-20B is a particularly powerful few-shot reasoner and
26
+ gains far more in performance when evaluated five-shot than similarly sized GPT-3 and FairSeq models. We open-source
27
+ the training and evaluation code, as well as the model weights, at [https://github.com/EleutherAI/gpt-neox](https://github.com/EleutherAI/gpt-neox).
28
+
29
+ Development of the model was led by Sid Black, Stella Biderman and Eric Hallahan, and the model was trained with
30
+ generous the support of [CoreWeave](https://www.coreweave.com/).
31
+
32
+ GPT-NeoX-20B was trained with fp16, thus it is recommended to initialize the model as follows:
33
+
34
+ ```python
35
+ model = GPTNeoXForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b").half().cuda()
36
+ ```
37
+
38
+ GPT-NeoX-20B also has a different tokenizer from the one used in GPT-J-6B and GPT-Neo. The new tokenizer allocates
39
+ additional tokens to whitespace characters, making the model more suitable for certain tasks like code generation.
40
+
41
+ ## Usage example
42
+
43
+ The `generate()` method can be used to generate text using GPT Neo model.
44
+
45
+ ```python
46
+ >>> from transformers import GPTNeoXForCausalLM, GPTNeoXTokenizerFast
47
+
48
+ >>> model = GPTNeoXForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b")
49
+ >>> tokenizer = GPTNeoXTokenizerFast.from_pretrained("EleutherAI/gpt-neox-20b")
50
+
51
+ >>> prompt = "GPTNeoX20B is a 20B-parameter autoregressive Transformer model developed by EleutherAI."
52
+
53
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids
54
+
55
+ >>> gen_tokens = model.generate(
56
+ ... input_ids,
57
+ ... do_sample=True,
58
+ ... temperature=0.9,
59
+ ... max_length=100,
60
+ ... )
61
+ >>> gen_text = tokenizer.batch_decode(gen_tokens)[0]
62
+ ```
63
+
64
+ ## Using Flash Attention 2
65
+
66
+ Flash Attention 2 is an faster, optimized version of the model.
67
+
68
+ ### Installation
69
+
70
+ First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the [official documentation](https://github.com/Dao-AILab/flash-attention#installation-and-features). If your hardware is not compatible with Flash Attention 2, you can still benefit from attention kernel optimisations through Better Transformer support covered [above](https://huggingface.co/docs/transformers/main/en/model_doc/bark#using-better-transformer).
71
+
72
+ Next, [install](https://github.com/Dao-AILab/flash-attention#installation-and-features) the latest version of Flash Attention 2:
73
+
74
+ ```bash
75
+ pip install -U flash-attn --no-build-isolation
76
+ ```
77
+
78
+ ### Usage
79
+
80
+ To load a model using Flash Attention 2, we can pass the argument `attn_implementation="flash_attention_2"` to [`.from_pretrained`](https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained). We'll also load the model in half-precision (e.g. `torch.float16`), since it results in almost no degradation to audio quality but significantly lower memory usage and faster inference:
81
+
82
+ ```python
83
+ >>> from transformers import GPTNeoXForCausalLM, GPTNeoXTokenizerFast
84
+
85
+ model = GPTNeoXForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b", torch_dtype=torch.float16, attn_implementation="flash_attention_2").to(device)
86
+ ...
87
+ ```
88
+
89
+
90
+ ### Expected speedups
91
+
92
+ Below is an expected speedup diagram that compares pure inference time between the native implementation in transformers using `stockmark/gpt-neox-japanese-1.4b` checkpoint and the Flash Attention 2 version of the model using a sequence length of 2048.
93
+
94
+ <div style="text-align: center">
95
+ <img src="https://huggingface.co/datasets/ybelkada/documentation-images/resolve/main/gpt-neox-1.8b-speedup.jpg">
96
+ </div>
97
+
98
+
99
+ ## Using Scaled Dot Product Attention (SDPA)
100
+ PyTorch includes a native scaled dot-product attention (SDPA) operator as part of `torch.nn.functional`. This function
101
+ encompasses several implementations that can be applied depending on the inputs and the hardware in use. See the
102
+ [official documentation](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html)
103
+ or the [GPU Inference](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention)
104
+ page for more information.
105
+
106
+ SDPA is used by default for `torch>=2.1.1` when an implementation is available, but you may also set
107
+ `attn_implementation="sdpa"` in `from_pretrained()` to explicitly request SDPA to be used.
108
+
109
+ ```python
110
+ from transformers import GPTNeoXForCausalLM
111
+ model = GPTNeoXForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b", torch_dtype=torch.float16, attn_implementation="sdpa")
112
+ ...
113
+ ```
114
+
115
+ For the best speedups, we recommend loading the model in half-precision (e.g. `torch.float16` or `torch.bfloat16`).
116
+
117
+ On a local benchmark (rtx3080ti-16GB, PyTorch 2.2.1, OS Ubuntu 22.04) using `float16` with
118
+ [pythia-410m-deduped](https://huggingface.co/EleutherAI/pythia-410m-deduped), we saw the
119
+ following speedups during training and inference.
120
+
121
+ ### Training
122
+ | Batch size | Seq len | Time per batch (Eager - s) | Time per batch (SDPA - s) | Speedup (%) | Eager peak mem (MB) | SDPA peak mem (MB) | Mem saving (%) |
123
+ |-----------:|-----------:|---------------------------:|-----------------------------:|------------:|--------------------:|-------------------:|------------------:|
124
+ | 1 | 128 | 0.024 | 0.019 | 28.945 | 1789.95 | 1789.95 | 0 |
125
+ | 1 | 256 | 0.039 | 0.031 | 23.18 | 1845.83 | 1844.84 | 0.053 |
126
+ | 1 | 512 | 0.08 | 0.055 | 45.524 | 2278.38 | 1953.76 | 16.615 |
127
+ | 1 | 1024 | 0.19 | 0.102 | 86.777 | 4772.36 | 2408.35 | 98.159 |
128
+ | 1 | 2048 | 0.565 | 0.204 | 177.098 | 13484.1 | 3882.01 | 247.348 |
129
+ | 2 | 128 | 0.037 | 0.032 | 15.121 | 1843.86 | 1844.78 | -0.05 |
130
+ | 2 | 256 | 0.067 | 0.055 | 21.706 | 1999.72 | 1951.67 | 2.462 |
131
+ | 2 | 512 | 0.144 | 0.096 | 50.046 | 3613.16 | 2406.77 | 50.125 |
132
+ | 2 | 1024 | 0.366 | 0.193 | 89.666 | 8707.55 | 3878.86 | 124.487 |
133
+ | 2 | 2048 | OOM | 0.379 | / | OOM | 6825.13 | SDPA does not OOM |
134
+ | 4 | 128 | 0.06 | 0.054 | 11.539 | 1947.6 | 1952.06 | -0.228 |
135
+ | 4 | 256 | 0.119 | 0.093 | 28.072 | 3008.39 | 2405.99 | 25.038 |
136
+ | 4 | 512 | 0.275 | 0.187 | 47.145 | 6290.58 | 3877.29 | 62.242 |
137
+ | 4 | 1024 | OOM | 0.36 | / | OOM | 6821.98 | SDPA does not OOM |
138
+ | 4 | 2048 | OOM | 0.731 | / | OOM | 12705.1 | SDPA does not OOM |
139
+
140
+ ### Inference
141
+ | Batch size | Seq len | Per token latency Eager (ms) | Per token latency SDPA (ms) | Speedup (%) | Mem Eager (MB) | Mem SDPA (MB) | Mem saved (%) |
142
+ |--------------:|-------------:|--------------------------------:|-------------------------------:|---------------:|------------------:|----------------:|-----------------:|
143
+ | 1 | 128 | 6.569 | 5.858 | 12.14 | 974.831 | 974.826 | 0 |
144
+ | 1 | 256 | 7.009 | 5.863 | 19.542 | 1029.01 | 1028.08 | 0.09 |
145
+ | 1 | 512 | 7.157 | 5.965 | 19.983 | 1137.54 | 1137.52 | 0.001 |
146
+ | 1 | 1024 | 7.523 | 6.506 | 15.637 | 1329.3 | 1329.26 | 0.003 |
147
+ | 1 | 2048 | 9.271 | 9.205 | 0.713 | 1752.47 | 1734.51 | 1.036 |
148
+ | 2 | 128 | 7.239 | 5.959 | 21.493 | 1044.8 | 1028.37 | 1.597 |
149
+ | 2 | 256 | 7.228 | 6.036 | 19.757 | 1167.32 | 1137.73 | 2.601 |
150
+ | 2 | 512 | 7.538 | 6.693 | 12.628 | 1352.93 | 1329.55 | 1.758 |
151
+ | 2 | 1024 | 8.916 | 8.632 | 3.291 | 1752.56 | 1734.62 | 1.034 |
152
+ | 2 | 2048 | 12.628 | 12.606 | 0.181 | 2558.72 | 2545.8 | 0.508 |
153
+ | 4 | 128 | 7.278 | 6.046 | 20.373 | 1168.41 | 1137.79 | 2.691 |
154
+ | 4 | 256 | 7.614 | 6.588 | 15.574 | 1353.1 | 1329.79 | 1.753 |
155
+ | 4 | 512 | 8.798 | 8.144 | 8.028 | 1752.76 | 1734.85 | 1.032 |
156
+ | 4 | 1024 | 11.765 | 11.303 | 4.09 | 2558.96 | 2546.04 | 0.508 |
157
+ | 4 | 2048 | 19.568 | 17.735 | 10.33 | 4175.5 | 4165.26 | 0.246 |
158
+
159
+
160
+ ## Resources
161
+
162
+ - [Causal language modeling task guide](../tasks/language_modeling)
163
+
164
+ ## GPTNeoXConfig
165
+
166
+ [[autodoc]] GPTNeoXConfig
167
+
168
+ ## GPTNeoXTokenizerFast
169
+
170
+ [[autodoc]] GPTNeoXTokenizerFast
171
+
172
+ ## GPTNeoXModel
173
+
174
+ [[autodoc]] GPTNeoXModel
175
+ - forward
176
+
177
+ ## GPTNeoXForCausalLM
178
+
179
+ [[autodoc]] GPTNeoXForCausalLM
180
+ - forward
181
+
182
+ ## GPTNeoXForQuestionAnswering
183
+
184
+ [[autodoc]] GPTNeoXForQuestionAnswering
185
+ - forward
186
+
187
+ ## GPTNeoXForSequenceClassification
188
+
189
+ [[autodoc]] GPTNeoXForSequenceClassification
190
+ - forward
191
+
192
+ ## GPTNeoXForTokenClassification
193
+
194
+ [[autodoc]] GPTNeoXForTokenClassification
195
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gpt_neox_japanese.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPT-NeoX-Japanese
18
+
19
+ ## Overview
20
+
21
+ We introduce GPT-NeoX-Japanese, which is an autoregressive language model for Japanese, trained on top of [https://github.com/EleutherAI/gpt-neox](https://github.com/EleutherAI/gpt-neox).
22
+ Japanese is a unique language with its large vocabulary and a combination of hiragana, katakana, and kanji writing scripts.
23
+ To address this distinct structure of the Japanese language, we use a [special sub-word tokenizer](https://github.com/tanreinama/Japanese-BPEEncoder_V2). We are very grateful to *tanreinama* for open-sourcing this incredibly helpful tokenizer.
24
+ Following the recommendations from Google's research on [PaLM](https://ai.googleblog.com/2022/04/pathways-language-model-palm-scaling-to.html), we have removed bias parameters from transformer blocks, achieving better model performance. Please refer [this article](https://medium.com/ml-abeja/training-a-better-gpt-2-93b157662ae4) in detail.
25
+
26
+ Development of the model was led by [Shinya Otani](https://github.com/SO0529), [Takayoshi Makabe](https://github.com/spider-man-tm), [Anuj Arora](https://github.com/Anuj040), and [Kyo Hattori](https://github.com/go5paopao) from [ABEJA, Inc.](https://www.abejainc.com/). For more information on this model-building activity, please refer [here (ja)](https://tech-blog.abeja.asia/entry/abeja-gpt-project-202207).
27
+
28
+ ### Usage example
29
+
30
+ The `generate()` method can be used to generate text using GPT NeoX Japanese model.
31
+
32
+ ```python
33
+ >>> from transformers import GPTNeoXJapaneseForCausalLM, GPTNeoXJapaneseTokenizer
34
+
35
+ >>> model = GPTNeoXJapaneseForCausalLM.from_pretrained("abeja/gpt-neox-japanese-2.7b")
36
+ >>> tokenizer = GPTNeoXJapaneseTokenizer.from_pretrained("abeja/gpt-neox-japanese-2.7b")
37
+
38
+ >>> prompt = "人とAIが協調するためには、"
39
+
40
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids
41
+
42
+ >>> gen_tokens = model.generate(
43
+ ... input_ids,
44
+ ... do_sample=True,
45
+ ... temperature=0.9,
46
+ ... max_length=100,
47
+ ... )
48
+ >>> gen_text = tokenizer.batch_decode(gen_tokens, skip_special_tokens=True)[0]
49
+
50
+ >>> print(gen_text)
51
+ 人とAIが協調するためには、AIと人が共存し、AIを正しく理解する必要があります。
52
+ ```
53
+
54
+ ## Resources
55
+
56
+ - [Causal language modeling task guide](../tasks/language_modeling)
57
+
58
+ ## GPTNeoXJapaneseConfig
59
+
60
+ [[autodoc]] GPTNeoXJapaneseConfig
61
+
62
+ ## GPTNeoXJapaneseTokenizer
63
+
64
+ [[autodoc]] GPTNeoXJapaneseTokenizer
65
+
66
+ ## GPTNeoXJapaneseModel
67
+
68
+ [[autodoc]] GPTNeoXJapaneseModel
69
+ - forward
70
+
71
+ ## GPTNeoXJapaneseForCausalLM
72
+
73
+ [[autodoc]] GPTNeoXJapaneseForCausalLM
74
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gptj.md ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPT-J
18
+
19
+ ## Overview
20
+
21
+ The GPT-J model was released in the [kingoflolz/mesh-transformer-jax](https://github.com/kingoflolz/mesh-transformer-jax) repository by Ben Wang and Aran Komatsuzaki. It is a GPT-2-like
22
+ causal language model trained on [the Pile](https://pile.eleuther.ai/) dataset.
23
+
24
+ This model was contributed by [Stella Biderman](https://huggingface.co/stellaathena).
25
+
26
+ ## Usage tips
27
+
28
+ - To load [GPT-J](https://huggingface.co/EleutherAI/gpt-j-6B) in float32 one would need at least 2x model size
29
+ RAM: 1x for initial weights and another 1x to load the checkpoint. So for GPT-J it would take at least 48GB
30
+ RAM to just load the model. To reduce the RAM usage there are a few options. The `torch_dtype` argument can be
31
+ used to initialize the model in half-precision on a CUDA device only. There is also a fp16 branch which stores the fp16 weights,
32
+ which could be used to further minimize the RAM usage:
33
+
34
+ ```python
35
+ >>> from transformers import GPTJForCausalLM
36
+ >>> import torch
37
+
38
+ >>> device = "cuda"
39
+ >>> model = GPTJForCausalLM.from_pretrained(
40
+ ... "EleutherAI/gpt-j-6B",
41
+ ... revision="float16",
42
+ ... torch_dtype=torch.float16,
43
+ ... ).to(device)
44
+ ```
45
+
46
+ - The model should fit on 16GB GPU for inference. For training/fine-tuning it would take much more GPU RAM. Adam
47
+ optimizer for example makes four copies of the model: model, gradients, average and squared average of the gradients.
48
+ So it would need at least 4x model size GPU memory, even with mixed precision as gradient updates are in fp32. This
49
+ is not including the activations and data batches, which would again require some more GPU RAM. So one should explore
50
+ solutions such as DeepSpeed, to train/fine-tune the model. Another option is to use the original codebase to
51
+ train/fine-tune the model on TPU and then convert the model to Transformers format for inference. Instructions for
52
+ that could be found [here](https://github.com/kingoflolz/mesh-transformer-jax/blob/master/howto_finetune.md)
53
+
54
+ - Although the embedding matrix has a size of 50400, only 50257 entries are used by the GPT-2 tokenizer. These extra
55
+ tokens are added for the sake of efficiency on TPUs. To avoid the mismatch between embedding matrix size and vocab
56
+ size, the tokenizer for [GPT-J](https://huggingface.co/EleutherAI/gpt-j-6B) contains 143 extra tokens
57
+ `<|extratoken_1|>... <|extratoken_143|>`, so the `vocab_size` of tokenizer also becomes 50400.
58
+
59
+ ## Usage examples
60
+
61
+ The [`~generation.GenerationMixin.generate`] method can be used to generate text using GPT-J
62
+ model.
63
+
64
+ ```python
65
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
66
+
67
+ >>> model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-j-6B")
68
+ >>> tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B")
69
+
70
+ >>> prompt = (
71
+ ... "In a shocking finding, scientists discovered a herd of unicorns living in a remote, "
72
+ ... "previously unexplored valley, in the Andes Mountains. Even more surprising to the "
73
+ ... "researchers was the fact that the unicorns spoke perfect English."
74
+ ... )
75
+
76
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids
77
+
78
+ >>> gen_tokens = model.generate(
79
+ ... input_ids,
80
+ ... do_sample=True,
81
+ ... temperature=0.9,
82
+ ... max_length=100,
83
+ ... )
84
+ >>> gen_text = tokenizer.batch_decode(gen_tokens)[0]
85
+ ```
86
+
87
+ ...or in float16 precision:
88
+
89
+ ```python
90
+ >>> from transformers import GPTJForCausalLM, AutoTokenizer
91
+ >>> import torch
92
+
93
+ >>> device = "cuda"
94
+ >>> model = GPTJForCausalLM.from_pretrained("EleutherAI/gpt-j-6B", torch_dtype=torch.float16).to(device)
95
+ >>> tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B")
96
+
97
+ >>> prompt = (
98
+ ... "In a shocking finding, scientists discovered a herd of unicorns living in a remote, "
99
+ ... "previously unexplored valley, in the Andes Mountains. Even more surprising to the "
100
+ ... "researchers was the fact that the unicorns spoke perfect English."
101
+ ... )
102
+
103
+ >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
104
+
105
+ >>> gen_tokens = model.generate(
106
+ ... input_ids,
107
+ ... do_sample=True,
108
+ ... temperature=0.9,
109
+ ... max_length=100,
110
+ ... )
111
+ >>> gen_text = tokenizer.batch_decode(gen_tokens)[0]
112
+ ```
113
+
114
+ ## Resources
115
+
116
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with GPT-J. 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.
117
+
118
+ <PipelineTag pipeline="text-generation"/>
119
+
120
+ - Description of [GPT-J](https://huggingface.co/EleutherAI/gpt-j-6B).
121
+ - A blog on how to [Deploy GPT-J 6B for inference using Hugging Face Transformers and Amazon SageMaker](https://huggingface.co/blog/gptj-sagemaker).
122
+ - A blog on how to [Accelerate GPT-J inference with DeepSpeed-Inference on GPUs](https://www.philschmid.de/gptj-deepspeed-inference).
123
+ - A blog post introducing [GPT-J-6B: 6B JAX-Based Transformer](https://arankomatsuzaki.wordpress.com/2021/06/04/gpt-j/). 🌎
124
+ - A notebook for [GPT-J-6B Inference Demo](https://colab.research.google.com/github/kingoflolz/mesh-transformer-jax/blob/master/colab_demo.ipynb). 🌎
125
+ - Another notebook demonstrating [Inference with GPT-J-6B](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/GPT-J-6B/Inference_with_GPT_J_6B.ipynb).
126
+ - [Causal language modeling](https://huggingface.co/course/en/chapter7/6?fw=pt#training-a-causal-language-model-from-scratch) chapter of the 🤗 Hugging Face Course.
127
+ - [`GPTJForCausalLM`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language-modeling#gpt-2gpt-and-causal-language-modeling), [text generation example script](https://github.com/huggingface/transformers/tree/main/examples/pytorch/text-generation), and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling.ipynb).
128
+ - [`TFGPTJForCausalLM`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/language-modeling#run_clmpy) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/language_modeling-tf.ipynb).
129
+ - [`FlaxGPTJForCausalLM`] is supported by this [causal language modeling example script](https://github.com/huggingface/transformers/tree/main/examples/flax/language-modeling#causal-language-modeling) and [notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/causal_language_modeling_flax.ipynb).
130
+
131
+ **Documentation resources**
132
+ - [Text classification task guide](../tasks/sequence_classification)
133
+ - [Question answering task guide](../tasks/question_answering)
134
+ - [Causal language modeling task guide](../tasks/language_modeling)
135
+
136
+ ## GPTJConfig
137
+
138
+ [[autodoc]] GPTJConfig
139
+ - all
140
+
141
+ <frameworkcontent>
142
+ <pt>
143
+
144
+ ## GPTJModel
145
+
146
+ [[autodoc]] GPTJModel
147
+ - forward
148
+
149
+ ## GPTJForCausalLM
150
+
151
+ [[autodoc]] GPTJForCausalLM
152
+ - forward
153
+
154
+ ## GPTJForSequenceClassification
155
+
156
+ [[autodoc]] GPTJForSequenceClassification
157
+ - forward
158
+
159
+ ## GPTJForQuestionAnswering
160
+
161
+ [[autodoc]] GPTJForQuestionAnswering
162
+ - forward
163
+
164
+ </pt>
165
+ <tf>
166
+
167
+ ## TFGPTJModel
168
+
169
+ [[autodoc]] TFGPTJModel
170
+ - call
171
+
172
+ ## TFGPTJForCausalLM
173
+
174
+ [[autodoc]] TFGPTJForCausalLM
175
+ - call
176
+
177
+ ## TFGPTJForSequenceClassification
178
+
179
+ [[autodoc]] TFGPTJForSequenceClassification
180
+ - call
181
+
182
+ ## TFGPTJForQuestionAnswering
183
+
184
+ [[autodoc]] TFGPTJForQuestionAnswering
185
+ - call
186
+
187
+ </tf>
188
+ <jax>
189
+
190
+ ## FlaxGPTJModel
191
+
192
+ [[autodoc]] FlaxGPTJModel
193
+ - __call__
194
+
195
+ ## FlaxGPTJForCausalLM
196
+
197
+ [[autodoc]] FlaxGPTJForCausalLM
198
+ - __call__
199
+ </jax>
200
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/gptsan-japanese.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GPTSAN-japanese
18
+
19
+ <Tip warning={true}>
20
+
21
+ This model is in maintenance mode only, we don't accept any new PRs changing its code.
22
+ If you run into any issues running this model, please reinstall the last version that supported this model: v4.40.2.
23
+ You can do so by running the following command: `pip install -U transformers==4.40.2`.
24
+
25
+ </Tip>
26
+
27
+ ## Overview
28
+
29
+ The GPTSAN-japanese model was released in the repository by Toshiyuki Sakamoto (tanreinama).
30
+
31
+ GPTSAN is a Japanese language model using Switch Transformer. It has the same structure as the model introduced as Prefix LM
32
+ in the T5 paper, and support both Text Generation and Masked Language Modeling tasks. These basic tasks similarly can
33
+ fine-tune for translation or summarization.
34
+
35
+ ### Usage example
36
+
37
+ The `generate()` method can be used to generate text using GPTSAN-Japanese model.
38
+
39
+ ```python
40
+ >>> from transformers import AutoModel, AutoTokenizer
41
+ >>> import torch
42
+
43
+ >>> tokenizer = AutoTokenizer.from_pretrained("Tanrei/GPTSAN-japanese")
44
+ >>> model = AutoModel.from_pretrained("Tanrei/GPTSAN-japanese").cuda()
45
+ >>> x_tok = tokenizer("は、", prefix_text="織田信長", return_tensors="pt")
46
+ >>> torch.manual_seed(0)
47
+ >>> gen_tok = model.generate(x_tok.input_ids.cuda(), token_type_ids=x_tok.token_type_ids.cuda(), max_new_tokens=20)
48
+ >>> tokenizer.decode(gen_tok[0])
49
+ '織田信長は、2004年に『戦国BASARA』のために、豊臣秀吉'
50
+ ```
51
+
52
+ ## GPTSAN Features
53
+
54
+ GPTSAN has some unique features. It has a model structure of Prefix-LM. It works as a shifted Masked Language Model for Prefix Input tokens. Un-prefixed inputs behave like normal generative models.
55
+ The Spout vector is a GPTSAN specific input. Spout is pre-trained with random inputs, but you can specify a class of text or an arbitrary vector during fine-tuning. This allows you to indicate the tendency of the generated text.
56
+ GPTSAN has a sparse Feed Forward based on Switch-Transformer. You can also add other layers and train them partially. See the original GPTSAN repository for details.
57
+
58
+ ### Prefix-LM Model
59
+
60
+ GPTSAN has the structure of the model named Prefix-LM in the `T5` paper. (The original GPTSAN repository calls it `hybrid`)
61
+ In GPTSAN, the `Prefix` part of Prefix-LM, that is, the input position that can be referenced by both tokens, can be specified with any length.
62
+ Arbitrary lengths can also be specified differently for each batch.
63
+ This length applies to the text entered in `prefix_text` for the tokenizer.
64
+ The tokenizer returns the mask of the `Prefix` part of Prefix-LM as `token_type_ids`.
65
+ The model treats the part where `token_type_ids` is 1 as a `Prefix` part, that is, the input can refer to both tokens before and after.
66
+
67
+ ## Usage tips
68
+
69
+ Specifying the Prefix part is done with a mask passed to self-attention.
70
+ When token_type_ids=None or all zero, it is equivalent to regular causal mask
71
+
72
+ for example:
73
+
74
+ >>> x_token = tokenizer("アイウエ")
75
+ input_ids: | SOT | SEG | ア | イ | ウ | エ |
76
+ token_type_ids: | 1 | 0 | 0 | 0 | 0 | 0 |
77
+ prefix_lm_mask:
78
+ SOT | 1 0 0 0 0 0 |
79
+ SEG | 1 1 0 0 0 0 |
80
+ ア | 1 1 1 0 0 0 |
81
+ イ | 1 1 1 1 0 0 |
82
+ ウ | 1 1 1 1 1 0 |
83
+ エ | 1 1 1 1 1 1 |
84
+
85
+ >>> x_token = tokenizer("", prefix_text="アイウエ")
86
+ input_ids: | SOT | ア | イ | ウ | エ | SEG |
87
+ token_type_ids: | 1 | 1 | 1 | 1 | 1 | 0 |
88
+ prefix_lm_mask:
89
+ SOT | 1 1 1 1 1 0 |
90
+ ア | 1 1 1 1 1 0 |
91
+ イ | 1 1 1 1 1 0 |
92
+ ウ | 1 1 1 1 1 0 |
93
+ エ | 1 1 1 1 1 0 |
94
+ SEG | 1 1 1 1 1 1 |
95
+
96
+ >>> x_token = tokenizer("ウエ", prefix_text="アイ")
97
+ input_ids: | SOT | ア | イ | SEG | ウ | エ |
98
+ token_type_ids: | 1 | 1 | 1 | 0 | 0 | 0 |
99
+ prefix_lm_mask:
100
+ SOT | 1 1 1 0 0 0 |
101
+ ア | 1 1 1 0 0 0 |
102
+ イ | 1 1 1 0 0 0 |
103
+ SEG | 1 1 1 1 0 0 |
104
+ ウ | 1 1 1 1 1 0 |
105
+ エ | 1 1 1 1 1 1 |
106
+
107
+ ### Spout Vector
108
+
109
+ A Spout Vector is a special vector for controlling text generation.
110
+ This vector is treated as the first embedding in self-attention to bring extraneous attention to the generated tokens.
111
+ In the pre-trained model published from `Tanrei/GPTSAN-japanese`, the Spout Vector is a 128-dimensional vector that passes through 8 fully connected layers in the model and is projected into the space acting as external attention.
112
+ The Spout Vector projected by the fully connected layer is split to be passed to all self-attentions.
113
+
114
+ ## GPTSanJapaneseConfig
115
+
116
+ [[autodoc]] GPTSanJapaneseConfig
117
+
118
+ ## GPTSanJapaneseTokenizer
119
+
120
+ [[autodoc]] GPTSanJapaneseTokenizer
121
+
122
+ ## GPTSanJapaneseModel
123
+
124
+ [[autodoc]] GPTSanJapaneseModel
125
+
126
+ ## GPTSanJapaneseForConditionalGeneration
127
+
128
+ [[autodoc]] GPTSanJapaneseForConditionalGeneration
129
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/granite.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Granite
18
+
19
+ ## Overview
20
+
21
+ The Granite model was proposed in [Power Scheduler: A Batch Size and Token Number Agnostic Learning Rate Scheduler](https://arxiv.org/abs/2408.13359) by Yikang Shen, Matthew Stallone, Mayank Mishra, Gaoyuan Zhang, Shawn Tan, Aditya Prasad, Adriana Meza Soria, David D. Cox and Rameswar Panda.
22
+
23
+ PowerLM-3B is a 3B state-of-the-art small language model trained with the Power learning rate scheduler. It is trained on a wide range of open-source and synthetic datasets with permissive licenses. PowerLM-3B has shown promising results compared to other models in the size categories across various benchmarks, including natural language multi-choices, code generation, and math reasoning.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Finding the optimal learning rate for language model pretraining is a challenging task.
28
+ This is not only because there is a complicated correlation between learning rate, batch size, number of training tokens, model size, and other hyperparameters but also because it is prohibitively expensive to perform a hyperparameter search for large language models with Billions or Trillions of parameters. Recent studies propose using small proxy models and small corpus to perform hyperparameter searches and transposing the optimal parameters to large models and large corpus. While the zero-shot transferability is theoretically and empirically proven for model size related hyperparameters, like depth and width, the zero-shot transfer from small corpus to large corpus is underexplored.
29
+ In this paper, we study the correlation between optimal learning rate, batch size, and number of training tokens for the recently proposed WSD scheduler. After thousands of small experiments, we found a power-law relationship between variables and demonstrated its transferability across model sizes. Based on the observation, we propose a new learning rate scheduler, Power scheduler, that is agnostic about the number of training tokens and batch size. The experiment shows that combining the Power scheduler with Maximum Update Parameterization (\mup) can consistently achieve impressive performance with one set of hyperparameters regardless of the number of training tokens, batch size, model size, and even model architecture. Our 3B dense and MoE models trained with the Power scheduler achieve comparable performance as state-of-the-art small language models.
30
+ We [open source](https://huggingface.co/collections/ibm/power-lm-66be64ae647ddf11b9808000) these pretrained models.*
31
+
32
+ Tips:
33
+
34
+ ```python
35
+ import torch
36
+ from transformers import AutoModelForCausalLM, AutoTokenizer
37
+
38
+ model_path = "ibm/PowerLM-3b"
39
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
40
+
41
+ # drop device_map if running on CPU
42
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
43
+ model.eval()
44
+
45
+ # change input text as desired
46
+ prompt = "Write a code to find the maximum value in a list of numbers."
47
+
48
+ # tokenize the text
49
+ input_tokens = tokenizer(prompt, return_tensors="pt")
50
+ # generate output tokens
51
+ output = model.generate(**input_tokens, max_new_tokens=100)
52
+ # decode output tokens into text
53
+ output = tokenizer.batch_decode(output)
54
+ # loop over the batch to print, in this example the batch size is 1
55
+ for i in output:
56
+ print(i)
57
+ ```
58
+
59
+ This model was contributed by [mayank-mishra](https://huggingface.co/mayank-mishra).
60
+
61
+
62
+ ## GraniteConfig
63
+
64
+ [[autodoc]] GraniteConfig
65
+
66
+ ## GraniteModel
67
+
68
+ [[autodoc]] GraniteModel
69
+ - forward
70
+
71
+ ## GraniteForCausalLM
72
+
73
+ [[autodoc]] GraniteForCausalLM
74
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/granitemoe.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # GraniteMoe
18
+
19
+ ## Overview
20
+
21
+ The GraniteMoe model was proposed in [Power Scheduler: A Batch Size and Token Number Agnostic Learning Rate Scheduler](https://arxiv.org/abs/2408.13359) by Yikang Shen, Matthew Stallone, Mayank Mishra, Gaoyuan Zhang, Shawn Tan, Aditya Prasad, Adriana Meza Soria, David D. Cox and Rameswar Panda.
22
+
23
+ PowerMoE-3B is a 3B sparse Mixture-of-Experts (sMoE) language model trained with the Power learning rate scheduler. It sparsely activates 800M parameters for each token. It is trained on a mix of open-source and proprietary datasets. PowerMoE-3B has shown promising results compared to other dense models with 2x activate parameters across various benchmarks, including natural language multi-choices, code generation, and math reasoning.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Finding the optimal learning rate for language model pretraining is a challenging task.
28
+ This is not only because there is a complicated correlation between learning rate, batch size, number of training tokens, model size, and other hyperparameters but also because it is prohibitively expensive to perform a hyperparameter search for large language models with Billions or Trillions of parameters. Recent studies propose using small proxy models and small corpus to perform hyperparameter searches and transposing the optimal parameters to large models and large corpus. While the zero-shot transferability is theoretically and empirically proven for model size related hyperparameters, like depth and width, the zero-shot transfer from small corpus to large corpus is underexplored.
29
+ In this paper, we study the correlation between optimal learning rate, batch size, and number of training tokens for the recently proposed WSD scheduler. After thousands of small experiments, we found a power-law relationship between variables and demonstrated its transferability across model sizes. Based on the observation, we propose a new learning rate scheduler, Power scheduler, that is agnostic about the number of training tokens and batch size. The experiment shows that combining the Power scheduler with Maximum Update Parameterization (\mup) can consistently achieve impressive performance with one set of hyperparameters regardless of the number of training tokens, batch size, model size, and even model architecture. Our 3B dense and MoE models trained with the Power scheduler achieve comparable performance as state-of-the-art small language models.
30
+ We [open source](https://huggingface.co/collections/ibm/power-lm-66be64ae647ddf11b9808000) these pretrained models.*
31
+
32
+ Tips:
33
+
34
+ ```python
35
+ import torch
36
+ from transformers import AutoModelForCausalLM, AutoTokenizer
37
+
38
+ model_path = "ibm/PowerMoE-3b"
39
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
40
+
41
+ # drop device_map if running on CPU
42
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
43
+ model.eval()
44
+
45
+ # change input text as desired
46
+ prompt = "Write a code to find the maximum value in a list of numbers."
47
+
48
+ # tokenize the text
49
+ input_tokens = tokenizer(prompt, return_tensors="pt")
50
+ # generate output tokens
51
+ output = model.generate(**input_tokens, max_new_tokens=100)
52
+ # decode output tokens into text
53
+ output = tokenizer.batch_decode(output)
54
+ # loop over the batch to print, in this example the batch size is 1
55
+ for i in output:
56
+ print(i)
57
+ ```
58
+
59
+ This model was contributed by [mayank-mishra](https://huggingface.co/mayank-mishra).
60
+
61
+
62
+ ## GraniteMoeConfig
63
+
64
+ [[autodoc]] GraniteMoeConfig
65
+
66
+ ## GraniteMoeModel
67
+
68
+ [[autodoc]] GraniteMoeModel
69
+ - forward
70
+
71
+ ## GraniteMoeForCausalLM
72
+
73
+ [[autodoc]] GraniteMoeForCausalLM
74
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/graphormer.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team and Microsoft. All rights reserved.
2
+
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
+
15
+ # Graphormer
16
+
17
+ <Tip warning={true}>
18
+
19
+ This model is in maintenance mode only, we don't accept any new PRs changing its code.
20
+ If you run into any issues running this model, please reinstall the last version that supported this model: v4.40.2.
21
+ You can do so by running the following command: `pip install -U transformers==4.40.2`.
22
+
23
+ </Tip>
24
+
25
+ ## Overview
26
+
27
+ The Graphormer model was proposed in [Do Transformers Really Perform Bad for Graph Representation?](https://arxiv.org/abs/2106.05234) by
28
+ Chengxuan Ying, Tianle Cai, Shengjie Luo, Shuxin Zheng, Guolin Ke, Di He, Yanming Shen and Tie-Yan Liu. It is a Graph Transformer model, modified to allow computations on graphs instead of text sequences by generating embeddings and features of interest during preprocessing and collation, then using a modified attention.
29
+
30
+ The abstract from the paper is the following:
31
+
32
+ *The Transformer architecture has become a dominant choice in many domains, such as natural language processing and computer vision. Yet, it has not achieved competitive performance on popular leaderboards of graph-level prediction compared to mainstream GNN variants. Therefore, it remains a mystery how Transformers could perform well for graph representation learning. In this paper, we solve this mystery by presenting Graphormer, which is built upon the standard Transformer architecture, and could attain excellent results on a broad range of graph representation learning tasks, especially on the recent OGB Large-Scale Challenge. Our key insight to utilizing Transformer in the graph is the necessity of effectively encoding the structural information of a graph into the model. To this end, we propose several simple yet effective structural encoding methods to help Graphormer better model graph-structured data. Besides, we mathematically characterize the expressive power of Graphormer and exhibit that with our ways of encoding the structural information of graphs, many popular GNN variants could be covered as the special cases of Graphormer.*
33
+
34
+ This model was contributed by [clefourrier](https://huggingface.co/clefourrier). The original code can be found [here](https://github.com/microsoft/Graphormer).
35
+
36
+ ## Usage tips
37
+
38
+ This model will not work well on large graphs (more than 100 nodes/edges), as it will make the memory explode.
39
+ You can reduce the batch size, increase your RAM, or decrease the `UNREACHABLE_NODE_DISTANCE` parameter in algos_graphormer.pyx, but it will be hard to go above 700 nodes/edges.
40
+
41
+ This model does not use a tokenizer, but instead a special collator during training.
42
+
43
+ ## GraphormerConfig
44
+
45
+ [[autodoc]] GraphormerConfig
46
+
47
+ ## GraphormerModel
48
+
49
+ [[autodoc]] GraphormerModel
50
+ - forward
51
+
52
+ ## GraphormerForGraphClassification
53
+
54
+ [[autodoc]] GraphormerForGraphClassification
55
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/grounding-dino.md ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Grounding DINO
18
+
19
+ ## Overview
20
+
21
+ The Grounding DINO model was proposed in [Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection](https://arxiv.org/abs/2303.05499) by Shilong Liu, Zhaoyang Zeng, Tianhe Ren, Feng Li, Hao Zhang, Jie Yang, Chunyuan Li, Jianwei Yang, Hang Su, Jun Zhu, Lei Zhang. Grounding DINO extends a closed-set object detection model with a text encoder, enabling open-set object detection. The model achieves remarkable results, such as 52.5 AP on COCO zero-shot.
22
+
23
+ The abstract from the paper is the following:
24
+
25
+ *In this paper, we present an open-set object detector, called Grounding DINO, by marrying Transformer-based detector DINO with grounded pre-training, which can detect arbitrary objects with human inputs such as category names or referring expressions. The key solution of open-set object detection is introducing language to a closed-set detector for open-set concept generalization. To effectively fuse language and vision modalities, we conceptually divide a closed-set detector into three phases and propose a tight fusion solution, which includes a feature enhancer, a language-guided query selection, and a cross-modality decoder for cross-modality fusion. While previous works mainly evaluate open-set object detection on novel categories, we propose to also perform evaluations on referring expression comprehension for objects specified with attributes. Grounding DINO performs remarkably well on all three settings, including benchmarks on COCO, LVIS, ODinW, and RefCOCO/+/g. Grounding DINO achieves a 52.5 AP on the COCO detection zero-shot transfer benchmark, i.e., without any training data from COCO. It sets a new record on the ODinW zero-shot benchmark with a mean 26.1 AP.*
26
+
27
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/grouding_dino_architecture.png"
28
+ alt="drawing" width="600"/>
29
+
30
+ <small> Grounding DINO overview. Taken from the <a href="https://arxiv.org/abs/2303.05499">original paper</a>. </small>
31
+
32
+ This model was contributed by [EduardoPacheco](https://huggingface.co/EduardoPacheco) and [nielsr](https://huggingface.co/nielsr).
33
+ The original code can be found [here](https://github.com/IDEA-Research/GroundingDINO).
34
+
35
+ ## Usage tips
36
+
37
+ - One can use [`GroundingDinoProcessor`] to prepare image-text pairs for the model.
38
+ - To separate classes in the text use a period e.g. "a cat. a dog."
39
+ - When using multiple classes (e.g. `"a cat. a dog."`), use `post_process_grounded_object_detection` from [`GroundingDinoProcessor`] to post process outputs. Since, the labels returned from `post_process_object_detection` represent the indices from the model dimension where prob > threshold.
40
+
41
+ Here's how to use the model for zero-shot object detection:
42
+
43
+ ```python
44
+ >>> import requests
45
+
46
+ >>> import torch
47
+ >>> from PIL import Image
48
+ >>> from transformers import AutoProcessor, AutoModelForZeroShotObjectDetection
49
+
50
+ >>> model_id = "IDEA-Research/grounding-dino-tiny"
51
+ >>> device = "cuda"
52
+
53
+ >>> processor = AutoProcessor.from_pretrained(model_id)
54
+ >>> model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
55
+
56
+ >>> image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
57
+ >>> image = Image.open(requests.get(image_url, stream=True).raw)
58
+ >>> # Check for cats and remote controls
59
+ >>> text = "a cat. a remote control."
60
+
61
+ >>> inputs = processor(images=image, text=text, return_tensors="pt").to(device)
62
+ >>> with torch.no_grad():
63
+ ... outputs = model(**inputs)
64
+
65
+ >>> results = processor.post_process_grounded_object_detection(
66
+ ... outputs,
67
+ ... inputs.input_ids,
68
+ ... box_threshold=0.4,
69
+ ... text_threshold=0.3,
70
+ ... target_sizes=[image.size[::-1]]
71
+ ... )
72
+ >>> print(results)
73
+ [{'boxes': tensor([[344.6959, 23.1090, 637.1833, 374.2751],
74
+ [ 12.2666, 51.9145, 316.8582, 472.4392],
75
+ [ 38.5742, 70.0015, 176.7838, 118.1806]], device='cuda:0'),
76
+ 'labels': ['a cat', 'a cat', 'a remote control'],
77
+ 'scores': tensor([0.4785, 0.4381, 0.4776], device='cuda:0')}]
78
+ ```
79
+
80
+ ## Grounded SAM
81
+
82
+ One can combine Grounding DINO with the [Segment Anything](sam) model for text-based mask generation as introduced in [Grounded SAM: Assembling Open-World Models for Diverse Visual Tasks](https://arxiv.org/abs/2401.14159). You can refer to this [demo notebook](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/Grounding%20DINO/GroundingDINO_with_Segment_Anything.ipynb) 🌍 for details.
83
+
84
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/grounded_sam.png"
85
+ alt="drawing" width="900"/>
86
+
87
+ <small> Grounded SAM overview. Taken from the <a href="https://github.com/IDEA-Research/Grounded-Segment-Anything">original repository</a>. </small>
88
+
89
+ ## Resources
90
+
91
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Grounding DINO. 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.
92
+
93
+ - Demo notebooks regarding inference with Grounding DINO as well as combining it with [SAM](sam) can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/Grounding%20DINO). 🌎
94
+
95
+ ## GroundingDinoImageProcessor
96
+
97
+ [[autodoc]] GroundingDinoImageProcessor
98
+ - preprocess
99
+ - post_process_object_detection
100
+
101
+ ## GroundingDinoProcessor
102
+
103
+ [[autodoc]] GroundingDinoProcessor
104
+ - post_process_grounded_object_detection
105
+
106
+ ## GroundingDinoConfig
107
+
108
+ [[autodoc]] GroundingDinoConfig
109
+
110
+ ## GroundingDinoModel
111
+
112
+ [[autodoc]] GroundingDinoModel
113
+ - forward
114
+
115
+ ## GroundingDinoForObjectDetection
116
+
117
+ [[autodoc]] GroundingDinoForObjectDetection
118
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/groupvit.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 NVIDIA 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
+
17
+ # GroupViT
18
+
19
+ ## Overview
20
+
21
+ The GroupViT model was proposed in [GroupViT: Semantic Segmentation Emerges from Text Supervision](https://arxiv.org/abs/2202.11094) by Jiarui Xu, Shalini De Mello, Sifei Liu, Wonmin Byeon, Thomas Breuel, Jan Kautz, Xiaolong Wang.
22
+ Inspired by [CLIP](clip), GroupViT is a vision-language model that can perform zero-shot semantic segmentation on any given vocabulary categories.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ *Grouping and recognition are important components of visual scene understanding, e.g., for object detection and semantic segmentation. With end-to-end deep learning systems, grouping of image regions usually happens implicitly via top-down supervision from pixel-level recognition labels. Instead, in this paper, we propose to bring back the grouping mechanism into deep networks, which allows semantic segments to emerge automatically with only text supervision. We propose a hierarchical Grouping Vision Transformer (GroupViT), which goes beyond the regular grid structure representation and learns to group image regions into progressively larger arbitrary-shaped segments. We train GroupViT jointly with a text encoder on a large-scale image-text dataset via contrastive losses. With only text supervision and without any pixel-level annotations, GroupViT learns to group together semantic regions and successfully transfers to the task of semantic segmentation in a zero-shot manner, i.e., without any further fine-tuning. It achieves a zero-shot accuracy of 52.3% mIoU on the PASCAL VOC 2012 and 22.4% mIoU on PASCAL Context datasets, and performs competitively to state-of-the-art transfer-learning methods requiring greater levels of supervision.*
27
+
28
+ This model was contributed by [xvjiarui](https://huggingface.co/xvjiarui). The TensorFlow version was contributed by [ariG23498](https://huggingface.co/ariG23498) with the help of [Yih-Dar SHIEH](https://huggingface.co/ydshieh), [Amy Roberts](https://huggingface.co/amyeroberts), and [Joao Gante](https://huggingface.co/joaogante).
29
+ The original code can be found [here](https://github.com/NVlabs/GroupViT).
30
+
31
+ ## Usage tips
32
+
33
+ - You may specify `output_segmentation=True` in the forward of `GroupViTModel` to get the segmentation logits of input texts.
34
+
35
+ ## Resources
36
+
37
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with GroupViT.
38
+
39
+ - The quickest way to get started with GroupViT is by checking the [example notebooks](https://github.com/xvjiarui/GroupViT/blob/main/demo/GroupViT_hf_inference_notebook.ipynb) (which showcase zero-shot segmentation inference).
40
+ - One can also check out the [HuggingFace Spaces demo](https://huggingface.co/spaces/xvjiarui/GroupViT) to play with GroupViT.
41
+
42
+ ## GroupViTConfig
43
+
44
+ [[autodoc]] GroupViTConfig
45
+ - from_text_vision_configs
46
+
47
+ ## GroupViTTextConfig
48
+
49
+ [[autodoc]] GroupViTTextConfig
50
+
51
+ ## GroupViTVisionConfig
52
+
53
+ [[autodoc]] GroupViTVisionConfig
54
+
55
+ <frameworkcontent>
56
+ <pt>
57
+
58
+ ## GroupViTModel
59
+
60
+ [[autodoc]] GroupViTModel
61
+ - forward
62
+ - get_text_features
63
+ - get_image_features
64
+
65
+ ## GroupViTTextModel
66
+
67
+ [[autodoc]] GroupViTTextModel
68
+ - forward
69
+
70
+ ## GroupViTVisionModel
71
+
72
+ [[autodoc]] GroupViTVisionModel
73
+ - forward
74
+
75
+ </pt>
76
+ <tf>
77
+
78
+ ## TFGroupViTModel
79
+
80
+ [[autodoc]] TFGroupViTModel
81
+ - call
82
+ - get_text_features
83
+ - get_image_features
84
+
85
+ ## TFGroupViTTextModel
86
+
87
+ [[autodoc]] TFGroupViTTextModel
88
+ - call
89
+
90
+ ## TFGroupViTVisionModel
91
+
92
+ [[autodoc]] TFGroupViTVisionModel
93
+ - call
94
+
95
+ </tf>
96
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/herbert.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # HerBERT
18
+
19
+ ## Overview
20
+
21
+ The HerBERT model was proposed in [KLEJ: Comprehensive Benchmark for Polish Language Understanding](https://www.aclweb.org/anthology/2020.acl-main.111.pdf) by Piotr Rybak, Robert Mroczkowski, Janusz Tracz, and
22
+ Ireneusz Gawlik. It is a BERT-based Language Model trained on Polish Corpora using only MLM objective with dynamic
23
+ masking of whole words.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *In recent years, a series of Transformer-based models unlocked major improvements in general natural language
28
+ understanding (NLU) tasks. Such a fast pace of research would not be possible without general NLU benchmarks, which
29
+ allow for a fair comparison of the proposed methods. However, such benchmarks are available only for a handful of
30
+ languages. To alleviate this issue, we introduce a comprehensive multi-task benchmark for the Polish language
31
+ understanding, accompanied by an online leaderboard. It consists of a diverse set of tasks, adopted from existing
32
+ datasets for named entity recognition, question-answering, textual entailment, and others. We also introduce a new
33
+ sentiment analysis task for the e-commerce domain, named Allegro Reviews (AR). To ensure a common evaluation scheme and
34
+ promote models that generalize to different NLU tasks, the benchmark includes datasets from varying domains and
35
+ applications. Additionally, we release HerBERT, a Transformer-based model trained specifically for the Polish language,
36
+ which has the best average performance and obtains the best results for three out of nine tasks. Finally, we provide an
37
+ extensive evaluation, including several standard baselines and recently proposed, multilingual Transformer-based
38
+ models.*
39
+
40
+ This model was contributed by [rmroczkowski](https://huggingface.co/rmroczkowski). The original code can be found
41
+ [here](https://github.com/allegro/HerBERT).
42
+
43
+
44
+ ## Usage example
45
+
46
+ ```python
47
+ >>> from transformers import HerbertTokenizer, RobertaModel
48
+
49
+ >>> tokenizer = HerbertTokenizer.from_pretrained("allegro/herbert-klej-cased-tokenizer-v1")
50
+ >>> model = RobertaModel.from_pretrained("allegro/herbert-klej-cased-v1")
51
+
52
+ >>> encoded_input = tokenizer.encode("Kto ma lepszą sztukę, ma lepszy rząd – to jasne.", return_tensors="pt")
53
+ >>> outputs = model(encoded_input)
54
+
55
+ >>> # HerBERT can also be loaded using AutoTokenizer and AutoModel:
56
+ >>> import torch
57
+ >>> from transformers import AutoModel, AutoTokenizer
58
+
59
+ >>> tokenizer = AutoTokenizer.from_pretrained("allegro/herbert-klej-cased-tokenizer-v1")
60
+ >>> model = AutoModel.from_pretrained("allegro/herbert-klej-cased-v1")
61
+ ```
62
+
63
+ <Tip>
64
+
65
+ Herbert implementation is the same as `BERT` except for the tokenization method. Refer to [BERT documentation](bert)
66
+ for API reference and examples.
67
+
68
+ </Tip>
69
+
70
+ ## HerbertTokenizer
71
+
72
+ [[autodoc]] HerbertTokenizer
73
+
74
+ ## HerbertTokenizerFast
75
+
76
+ [[autodoc]] HerbertTokenizerFast
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/hiera.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Hiera
18
+
19
+ ## Overview
20
+
21
+ Hiera was proposed in [Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles](https://arxiv.org/abs/2306.00989) by Chaitanya Ryali, Yuan-Ting Hu, Daniel Bolya, Chen Wei, Haoqi Fan, Po-Yao Huang, Vaibhav Aggarwal, Arkabandhu Chowdhury, Omid Poursaeed, Judy Hoffman, Jitendra Malik, Yanghao Li, Christoph Feichtenhofer
22
+
23
+ The paper introduces "Hiera," a hierarchical Vision Transformer that simplifies the architecture of modern hierarchical vision transformers by removing unnecessary components without compromising on accuracy or efficiency. Unlike traditional transformers that add complex vision-specific components to improve supervised classification performance, Hiera demonstrates that such additions, often termed "bells-and-whistles," are not essential for high accuracy. By leveraging a strong visual pretext task (MAE) for pretraining, Hiera retains simplicity and achieves superior accuracy and speed both in inference and training across various image and video recognition tasks. The approach suggests that spatial biases required for vision tasks can be effectively learned through proper pretraining, eliminating the need for added architectural complexity.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Modern hierarchical vision transformers have added several vision-specific components in the pursuit of supervised classification performance. While these components lead to effective accuracies and attractive FLOP counts, the added complexity actually makes these transformers slower than their vanilla ViT counterparts. In this paper, we argue that this additional bulk is unnecessary. By pretraining with a strong visual pretext task (MAE), we can strip out all the bells-and-whistles from a state-of-the-art multi-stage vision transformer without losing accuracy. In the process, we create Hiera, an extremely simple hierarchical vision transformer that is more accurate than previous models while being significantly faster both at inference and during training. We evaluate Hiera on a variety of tasks for image and video recognition. Our code and models are available at https://github.com/facebookresearch/hiera.*
28
+
29
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/hiera_overview.png"
30
+ alt="drawing" width="600"/>
31
+
32
+ <small> Hiera architecture. Taken from the <a href="https://arxiv.org/abs/2306.00989">original paper.</a> </small>
33
+
34
+ This model was a joint contribution by [EduardoPacheco](https://huggingface.co/EduardoPacheco) and [namangarg110](https://huggingface.co/namangarg110). The original code can be found [here] (https://github.com/facebookresearch/hiera).
35
+
36
+ ## Resources
37
+
38
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Hiera. 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.
39
+
40
+ <PipelineTag pipeline="image-classification"/>
41
+
42
+ - [`HieraForImageClassification`] 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).
43
+ - See also: [Image classification task guide](../tasks/image_classification)
44
+
45
+ ## HieraConfig
46
+
47
+ [[autodoc]] HieraConfig
48
+
49
+ ## HieraModel
50
+
51
+ [[autodoc]] HieraModel
52
+ - forward
53
+
54
+ ## HieraForPreTraining
55
+
56
+ [[autodoc]] HieraForPreTraining
57
+ - forward
58
+
59
+ ## HieraForImageClassification
60
+
61
+ [[autodoc]] HieraForImageClassification
62
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/hubert.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Hubert
18
+
19
+ ## Overview
20
+
21
+ Hubert was proposed in [HuBERT: Self-Supervised Speech Representation Learning by Masked Prediction of Hidden Units](https://arxiv.org/abs/2106.07447) by Wei-Ning Hsu, Benjamin Bolte, Yao-Hung Hubert Tsai, Kushal Lakhotia, Ruslan
22
+ Salakhutdinov, Abdelrahman Mohamed.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ *Self-supervised approaches for speech representation learning are challenged by three unique problems: (1) there are
27
+ multiple sound units in each input utterance, (2) there is no lexicon of input sound units during the pre-training
28
+ phase, and (3) sound units have variable lengths with no explicit segmentation. To deal with these three problems, we
29
+ propose the Hidden-Unit BERT (HuBERT) approach for self-supervised speech representation learning, which utilizes an
30
+ offline clustering step to provide aligned target labels for a BERT-like prediction loss. A key ingredient of our
31
+ approach is applying the prediction loss over the masked regions only, which forces the model to learn a combined
32
+ acoustic and language model over the continuous inputs. HuBERT relies primarily on the consistency of the unsupervised
33
+ clustering step rather than the intrinsic quality of the assigned cluster labels. Starting with a simple k-means
34
+ teacher of 100 clusters, and using two iterations of clustering, the HuBERT model either matches or improves upon the
35
+ state-of-the-art wav2vec 2.0 performance on the Librispeech (960h) and Libri-light (60,000h) benchmarks with 10min, 1h,
36
+ 10h, 100h, and 960h fine-tuning subsets. Using a 1B parameter model, HuBERT shows up to 19% and 13% relative WER
37
+ reduction on the more challenging dev-other and test-other evaluation subsets.*
38
+
39
+ This model was contributed by [patrickvonplaten](https://huggingface.co/patrickvonplaten).
40
+
41
+ # Usage tips
42
+
43
+ - Hubert is a speech model that accepts a float array corresponding to the raw waveform of the speech signal.
44
+ - Hubert model was fine-tuned using connectionist temporal classification (CTC) so the model output has to be decoded
45
+ using [`Wav2Vec2CTCTokenizer`].
46
+
47
+
48
+ ## Using Flash Attention 2
49
+
50
+ Flash Attention 2 is an faster, optimized version of the model.
51
+
52
+ ### Installation
53
+
54
+ First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the [official documentation](https://github.com/Dao-AILab/flash-attention#installation-and-features). If your hardware is not compatible with Flash Attention 2, you can still benefit from attention kernel optimisations through Better Transformer support covered [above](https://huggingface.co/docs/transformers/main/en/model_doc/bark#using-better-transformer).
55
+
56
+ Next, [install](https://github.com/Dao-AILab/flash-attention#installation-and-features) the latest version of Flash Attention 2:
57
+
58
+ ```bash
59
+ pip install -U flash-attn --no-build-isolation
60
+ ```
61
+
62
+ ### Usage
63
+
64
+ Below is an expected speedup diagram comparing the pure inference time between the native implementation in transformers of `facebook/hubert-large-ls960-ft`, the flash-attention-2 and the sdpa (scale-dot-product-attention) version. We show the average speedup obtained on the `librispeech_asr` `clean` validation split:
65
+
66
+ ```python
67
+ >>> from transformers import Wav2Vec2Model
68
+
69
+ model = Wav2Vec2Model.from_pretrained("facebook/hubert-large-ls960-ft", torch_dtype=torch.float16, attn_implementation="flash_attention_2").to(device)
70
+ ...
71
+ ```
72
+
73
+ ### Expected speedups
74
+
75
+ Below is an expected speedup diagram comparing the pure inference time between the native implementation in transformers of the `facebook/hubert-large-ls960-ft` model and the flash-attention-2 and sdpa (scale-dot-product-attention) versions. . We show the average speedup obtained on the `librispeech_asr` `clean` validation split:
76
+
77
+
78
+ <div style="text-align: center">
79
+ <img src="https://huggingface.co/datasets/kamilakesbi/transformers_image_doc/resolve/main/data/Hubert_speedup.png">
80
+ </div>
81
+
82
+
83
+ ## Resources
84
+
85
+ - [Audio classification task guide](../tasks/audio_classification)
86
+ - [Automatic speech recognition task guide](../tasks/asr)
87
+
88
+ ## HubertConfig
89
+
90
+ [[autodoc]] HubertConfig
91
+
92
+ <frameworkcontent>
93
+ <pt>
94
+
95
+ ## HubertModel
96
+
97
+ [[autodoc]] HubertModel
98
+ - forward
99
+
100
+ ## HubertForCTC
101
+
102
+ [[autodoc]] HubertForCTC
103
+ - forward
104
+
105
+ ## HubertForSequenceClassification
106
+
107
+ [[autodoc]] HubertForSequenceClassification
108
+ - forward
109
+
110
+ </pt>
111
+ <tf>
112
+
113
+ ## TFHubertModel
114
+
115
+ [[autodoc]] TFHubertModel
116
+ - call
117
+
118
+ ## TFHubertForCTC
119
+
120
+ [[autodoc]] TFHubertForCTC
121
+ - call
122
+
123
+ </tf>
124
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/ibert.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # I-BERT
18
+
19
+ ## Overview
20
+
21
+ The I-BERT model was proposed in [I-BERT: Integer-only BERT Quantization](https://arxiv.org/abs/2101.01321) by
22
+ Sehoon Kim, Amir Gholami, Zhewei Yao, Michael W. Mahoney and Kurt Keutzer. It's a quantized version of RoBERTa running
23
+ inference up to four times faster.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Transformer based models, like BERT and RoBERTa, have achieved state-of-the-art results in many Natural Language
28
+ Processing tasks. However, their memory footprint, inference latency, and power consumption are prohibitive for
29
+ efficient inference at the edge, and even at the data center. While quantization can be a viable solution for this,
30
+ previous work on quantizing Transformer based models use floating-point arithmetic during inference, which cannot
31
+ efficiently utilize integer-only logical units such as the recent Turing Tensor Cores, or traditional integer-only ARM
32
+ processors. In this work, we propose I-BERT, a novel quantization scheme for Transformer based models that quantizes
33
+ the entire inference with integer-only arithmetic. Based on lightweight integer-only approximation methods for
34
+ nonlinear operations, e.g., GELU, Softmax, and Layer Normalization, I-BERT performs an end-to-end integer-only BERT
35
+ inference without any floating point calculation. We evaluate our approach on GLUE downstream tasks using
36
+ RoBERTa-Base/Large. We show that for both cases, I-BERT achieves similar (and slightly higher) accuracy as compared to
37
+ the full-precision baseline. Furthermore, our preliminary implementation of I-BERT shows a speedup of 2.4 - 4.0x for
38
+ INT8 inference on a T4 GPU system as compared to FP32 inference. The framework has been developed in PyTorch and has
39
+ been open-sourced.*
40
+
41
+ This model was contributed by [kssteven](https://huggingface.co/kssteven). The original code can be found [here](https://github.com/kssteven418/I-BERT).
42
+
43
+ ## Resources
44
+
45
+ - [Text classification task guide](../tasks/sequence_classification)
46
+ - [Token classification task guide](../tasks/token_classification)
47
+ - [Question answering task guide](../tasks/question_answering)
48
+ - [Masked language modeling task guide](../tasks/masked_language_modeling)
49
+ - [Multiple choice task guide](../tasks/masked_language_modeling)
50
+
51
+ ## IBertConfig
52
+
53
+ [[autodoc]] IBertConfig
54
+
55
+ ## IBertModel
56
+
57
+ [[autodoc]] IBertModel
58
+ - forward
59
+
60
+ ## IBertForMaskedLM
61
+
62
+ [[autodoc]] IBertForMaskedLM
63
+ - forward
64
+
65
+ ## IBertForSequenceClassification
66
+
67
+ [[autodoc]] IBertForSequenceClassification
68
+ - forward
69
+
70
+ ## IBertForMultipleChoice
71
+
72
+ [[autodoc]] IBertForMultipleChoice
73
+ - forward
74
+
75
+ ## IBertForTokenClassification
76
+
77
+ [[autodoc]] IBertForTokenClassification
78
+ - forward
79
+
80
+ ## IBertForQuestionAnswering
81
+
82
+ [[autodoc]] IBertForQuestionAnswering
83
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # IDEFICS
18
+
19
+ ## Overview
20
+
21
+ The IDEFICS model was proposed in [OBELICS: An Open Web-Scale Filtered Dataset of Interleaved Image-Text Documents
22
+ ](https://huggingface.co/papers/2306.16527
23
+ ) by Hugo Laurençon, Lucile Saulnier, Léo Tronchon, Stas Bekman, Amanpreet Singh, Anton Lozhkov, Thomas Wang, Siddharth Karamcheti, Alexander M. Rush, Douwe Kiela, Matthieu Cord, Victor Sanh
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Large multimodal models trained on natural documents, which interleave images and text, outperform models trained on image-text pairs on various multimodal benchmarks that require reasoning over one or multiple images to generate a text. However, the datasets used to train these models have not been released, and the collection process has not been fully specified. We introduce the OBELICS dataset, an open web-scale filtered dataset of interleaved image-text documents comprising 141 million web pages extracted from Common Crawl, 353 million associated images, and 115 billion text tokens. We describe the dataset creation process, present comprehensive filtering rules, and provide an analysis of the dataset's content. To show the viability of OBELISC, we train an 80 billion parameters vision and language model on the dataset and obtain competitive performance on various multimodal benchmarks. We release the code to reproduce the dataset along with the dataset itself.*
28
+
29
+ This model was contributed by [HuggingFaceM4](https://huggingface.co/HuggingFaceM4). The original code can be found [here](<INSERT LINK TO GITHUB REPO HERE>). (TODO: don't have a public link yet).
30
+
31
+
32
+ <Tip warning={true}>
33
+
34
+ IDEFICS modeling code in Transformers is for finetuning and inferencing the pre-trained IDEFICS models.
35
+
36
+ To train a new IDEFICS model from scratch use the m4 codebase (a link will be provided once it's made public)
37
+
38
+ </Tip>
39
+
40
+
41
+ ## IdeficsConfig
42
+
43
+ [[autodoc]] IdeficsConfig
44
+
45
+ ## IdeficsModel
46
+
47
+ [[autodoc]] IdeficsModel
48
+ - forward
49
+
50
+ ## IdeficsForVisionText2Text
51
+
52
+ [[autodoc]] IdeficsForVisionText2Text
53
+ - forward
54
+
55
+ ## TFIdeficsModel
56
+
57
+ [[autodoc]] TFIdeficsModel
58
+ - call
59
+
60
+ ## TFIdeficsForVisionText2Text
61
+
62
+ [[autodoc]] TFIdeficsForVisionText2Text
63
+ - call
64
+
65
+ ## IdeficsImageProcessor
66
+
67
+ [[autodoc]] IdeficsImageProcessor
68
+ - preprocess
69
+
70
+ ## IdeficsProcessor
71
+
72
+ [[autodoc]] IdeficsProcessor
73
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics2.md ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Idefics2
18
+
19
+ ## Overview
20
+
21
+ The Idefics2 model was proposed in [What matters when building vision-language models?](https://arxiv.org/abs/2405.02246) by Léo Tronchon, Hugo Laurencon, Victor Sanh. The accompanying blog post can be found [here](https://huggingface.co/blog/idefics2).
22
+
23
+ Idefics2 is an open multimodal model that accepts arbitrary sequences of image and text inputs and produces text
24
+ outputs. The model can answer questions about images, describe visual content, create stories grounded on multiple
25
+ images, or simply behave as a pure language model without visual inputs. It improves upon IDEFICS-1, notably on
26
+ document understanding, OCR, or visual reasoning. Idefics2 is lightweight (8 billion parameters) and treats
27
+ images in their native aspect ratio and resolution, which allows for varying inference efficiency.
28
+
29
+ The abstract from the paper is the following:
30
+
31
+ *The growing interest in vision-language models (VLMs) has been driven by improvements in large language models and vision transformers. Despite the abundance of literature on this subject, we observe that critical decisions regarding the design of VLMs are often not justified. We argue that these unsupported decisions impede progress in the field by making it difficult to identify which choices improve model performance. To address this issue, we conduct extensive experiments around pre-trained models, architecture choice, data, and training methods. Our consolidation of findings includes the development of Idefics2, an efficient foundational VLM of 8 billion parameters. Idefics2 achieves state-of-the-art performance within its size category across various multimodal benchmarks, and is often on par with models four times its size. We release the model (base, instructed, and chat) along with the datasets created for its training.*
32
+
33
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/idefics2_architecture.png"
34
+ alt="drawing" width="600"/>
35
+
36
+ <small> Idefics2 architecture. Taken from the <a href="https://arxiv.org/abs/2405.02246">original paper.</a> </small>
37
+
38
+ This model was contributed by [amyeroberts](https://huggingface.co/amyeroberts).
39
+ The original code can be found [here](https://huggingface.co/HuggingFaceM4/idefics2).
40
+
41
+ ## Usage tips
42
+
43
+ - Each sample can contain multiple images, and the number of images can vary between samples. The processor will pad the inputs to the maximum number of images in a batch for input to the model.
44
+ - The processor has a `do_image_splitting` option. If `True`, each input image will be split into 4 sub-images, and concatenated with the original to form 5 images. This is useful for increasing model performance. Make sure `processor.image_processor.do_image_splitting` is set to `False` if the model was not trained with this option.
45
+ - `text` passed to the processor should have the `<image>` tokens where the images should be inserted. And `<end_of_utterance>` at the end of each utterance if the text is a chat message.
46
+ - The processor has its own `apply_chat_template` method to convert chat messages to text that can then be passed as `text` to the processor.
47
+
48
+ Example of how to use the processor on chat messages:
49
+
50
+ ```python
51
+ import requests
52
+ from PIL import Image
53
+ from transformers import Idefics2Processor, Idefics2ForConditionalGeneration
54
+ import torch
55
+
56
+ device = "cuda" if torch.cuda.is_available() else "cpu"
57
+
58
+ url_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
59
+ url_2 = "http://images.cocodataset.org/val2017/000000219578.jpg"
60
+
61
+ image_1 = Image.open(requests.get(url_1, stream=True).raw)
62
+ image_2 = Image.open(requests.get(url_2, stream=True).raw)
63
+ images = [image_1, image_2]
64
+
65
+ messages = [{
66
+ "role": "user",
67
+ "content": [
68
+ {"type": "text", "text": "What’s the difference between these two images?"},
69
+ {"type": "image"},
70
+ {"type": "image"},
71
+ ],
72
+ }]
73
+
74
+ processor = Idefics2Processor.from_pretrained("HuggingFaceM4/idefics2-8b")
75
+ model = Idefics2ForConditionalGeneration.from_pretrained("HuggingFaceM4/idefics2-8b")
76
+ model.to(device)
77
+
78
+ # at inference time, one needs to pass `add_generation_prompt=True` in order to make sure the model completes the prompt
79
+ text = processor.apply_chat_template(messages, add_generation_prompt=True)
80
+ print(text)
81
+ # 'User: What’s the difference between these two images?<image><image><end_of_utterance>\nAssistant:'
82
+
83
+ inputs = processor(images=images, text=text, return_tensors="pt").to(device)
84
+
85
+ generated_text = model.generate(**inputs, max_new_tokens=500)
86
+ generated_text = processor.batch_decode(generated_text, skip_special_tokens=True)[0]
87
+ print("Generated text:", generated_text)
88
+ ```
89
+
90
+ - During training, it's important to determine which tokens the model should not learn. For Idefics2, this typically comes down to the image and padding tokens. This means that one can create the labels as follows:
91
+
92
+ ```python
93
+ import requests
94
+ from PIL import Image
95
+ from transformers import Idefics2Processor, Idefics2ForConditionalGeneration
96
+ import torch
97
+
98
+ url_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
99
+ url_2 = "http://images.cocodataset.org/val2017/000000219578.jpg"
100
+
101
+ image_1 = Image.open(requests.get(url_1, stream=True).raw)
102
+ image_2 = Image.open(requests.get(url_2, stream=True).raw)
103
+ images = [image_1, image_2]
104
+
105
+ messages = [{
106
+ "role": "user",
107
+ "content": [
108
+ {"type": "text", "text": "What’s the difference between these two images?"},
109
+ {"type": "image"},
110
+ {"type": "image"},
111
+ ],
112
+ },
113
+ {
114
+ "role": "assistant",
115
+ "content": [
116
+ {"type": "text", "text": "The difference is that one image is about dogs and the other one about cats."},
117
+ ],
118
+ }]
119
+
120
+ device = "cuda" if torch.cuda.is_available() else "cpu"
121
+
122
+ processor = Idefics2Processor.from_pretrained("HuggingFaceM4/idefics2-8b")
123
+ model = Idefics2ForConditionalGeneration.from_pretrained("HuggingFaceM4/idefics2-8b")
124
+ model.to(device)
125
+
126
+ text = processor.apply_chat_template(messages, add_generation_prompt=False)
127
+ inputs = processor(images=images, text=text, return_tensors="pt").to(device)
128
+
129
+ labels = inputs.input_ids.clone()
130
+ labels[labels == processor.tokenizer.pad_token_id] = -100
131
+ labels[labels == model.config.image_token_id] = -100
132
+
133
+ inputs["labels"] = labels
134
+
135
+ outputs = model(**inputs)
136
+ loss = outputs.loss
137
+ loss.backward()
138
+ ```
139
+
140
+ Do note that when training Idefics2 on multi-turn conversations between a user and an assistant, one typically also sets all the tokens corresponding to the user messages to -100.
141
+
142
+ ## Model optimizations: Flash Attention
143
+
144
+ The code snippets above showcase inference without any optimization tricks. However, one can drastically speed up the model by leveraging [Flash Attention](../perf_train_gpu_one#flash-attention-2), which is a faster implementation of the attention mechanism used inside the model.
145
+
146
+ First, make sure to install the latest version of Flash Attention 2 to include the sliding window attention feature.
147
+
148
+ ```bash
149
+ pip install -U flash-attn --no-build-isolation
150
+ ```
151
+
152
+ Make also sure that you have a hardware that is compatible with Flash-Attention 2. Read more about it in the official documentation of the [flash attention repository](https://github.com/Dao-AILab/flash-attention). Make also sure to load your model in half-precision (e.g. `torch.float16`)
153
+
154
+ To load and run a model using Flash Attention-2, simply change the code snippet above with the following change:
155
+
156
+ ```diff
157
+ model = Idefics2ForConditionalGeneration.from_pretrained(
158
+ "HuggingFaceM4/idefics2-8b",
159
+ + torch_dtype=torch.float16,
160
+ + attn_implementation="flash_attention_2",
161
+ ).to(device)
162
+ ```
163
+
164
+ ## Shrinking down Idefics2 using quantization
165
+
166
+ As the Idefics2 model has 8 billion parameters, that would require about 16GB of GPU RAM in half precision (float16), since each parameter is stored in 2 bytes. However, one can shrink down the size of the model using [quantization](../quantization.md). If the model is quantized to 4 bits (or half a byte per parameter), that requires only about 3.5GB of RAM.
167
+
168
+ Quantizing a model is as simple as passing a `quantization_config` to the model. One can change the code snippet above with the changes below. We'll leverage the BitsAndyBytes quantization (but refer to [this page](../quantization.md) for other quantization methods):
169
+
170
+ ```diff
171
+ + from transformers import BitsAndBytesConfig
172
+
173
+ + quantization_config = BitsAndBytesConfig(
174
+ + load_in_4bit=True,
175
+ + bnb_4bit_quant_type="nf4",
176
+ + bnb_4bit_use_double_quant=True,
177
+ + bnb_4bit_compute_dtype=torch.float16
178
+ + )
179
+ model = Idefics2ForConditionalGeneration.from_pretrained(
180
+ "HuggingFaceM4/idefics2-8b",
181
+ + torch_dtype=torch.float16,
182
+ + quantization_config=quantization_config,
183
+ ).to(device)
184
+ ```
185
+
186
+ ## Resources
187
+
188
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Idefics2. 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.
189
+
190
+ - A notebook on how to fine-tune Idefics2 on a custom dataset using the [Trainer](../main_classes/trainer.md) can be found [here](https://colab.research.google.com/drive/1NtcTgRbSBKN7pYD3Vdx1j9m8pt3fhFDB?usp=sharing). It supports both full fine-tuning as well as (quantized) LoRa.
191
+ - A script regarding how to fine-tune Idefics2 using the TRL library can be found [here](https://gist.github.com/edbeeching/228652fc6c2b29a1641be5a5778223cb).
192
+ - Demo notebook regarding fine-tuning Idefics2 for JSON extraction use cases can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/Idefics2). 🌎
193
+
194
+ ## Idefics2Config
195
+
196
+ [[autodoc]] Idefics2Config
197
+
198
+
199
+ ## Idefics2Model
200
+
201
+ [[autodoc]] Idefics2Model
202
+ - forward
203
+
204
+
205
+ ## Idefics2ForConditionalGeneration
206
+
207
+ [[autodoc]] Idefics2ForConditionalGeneration
208
+ - forward
209
+
210
+
211
+ ## Idefics2ImageProcessor
212
+ [[autodoc]] Idefics2ImageProcessor
213
+ - preprocess
214
+
215
+
216
+ ## Idefics2Processor
217
+ [[autodoc]] Idefics2Processor
218
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/idefics3.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Idefics3
18
+
19
+ ## Overview
20
+
21
+ The Idefics3 model was proposed in [Building and better understanding vision-language models: insights and future directions](https://huggingface.co/papers/2408.12637) by Hugo Laurençon, Andrés Marafioti, Victor Sanh, and Léo Tronchon.
22
+
23
+ Idefics3 is an adaptation of the Idefics2 model with three main differences:
24
+
25
+ - It uses Llama3 for the text model.
26
+ - It uses an updated processing logic for the images.
27
+ - It removes the perceiver.
28
+
29
+ The abstract from the paper is the following:
30
+
31
+ *The field of vision-language models (VLMs), which take images and texts as inputs and output texts, is rapidly evolving and has yet to reach consensus on several key aspects of the development pipeline, including data, architecture, and training methods. This paper can be seen as a tutorial for building a VLM. We begin by providing a comprehensive overview of the current state-of-the-art approaches, highlighting the strengths and weaknesses of each, addressing the major challenges in the field, and suggesting promising research directions for underexplored areas. We then walk through the practical steps to build Idefics3-8B, a powerful VLM that significantly outperforms its predecessor Idefics2-8B, while being trained efficiently, exclusively on open datasets, and using a straightforward pipeline. These steps include the creation of Docmatix, a dataset for improving document understanding capabilities, which is 240 times larger than previously available datasets. We release the model along with the datasets created for its training.*
32
+
33
+ ## Usage tips
34
+
35
+ Input images are processed either by upsampling (if resizing is enabled) or at their original resolution. The resizing behavior depends on two parameters: do_resize and size.
36
+
37
+ If `do_resize` is set to `True`, the model resizes images so that the longest edge is 4*364 pixels by default.
38
+ The default resizing behavior can be customized by passing a dictionary to the `size` parameter. For example, `{"longest_edge": 4 * 364}` is the default, but you can change it to a different value if needed.
39
+
40
+ Here’s how to control resizing and set a custom size:
41
+ ```python
42
+ image_processor = Idefics3ImageProcessor(do_resize=True, size={"longest_edge": 2 * 364}, max_image_size=364)
43
+ ```
44
+
45
+ Additionally, the `max_image_size` parameter, which controls the size of each square patch the image is decomposed into, is set to 364 by default but can be adjusted as needed. After resizing (if applicable), the image processor decomposes the images into square patches based on the `max_image_size` parameter.
46
+
47
+ This model was contributed by [amyeroberts](https://huggingface.co/amyeroberts) and [andimarafioti](https://huggingface.co/andito).
48
+
49
+
50
+ ## Idefics3Config
51
+
52
+ [[autodoc]] Idefics3Config
53
+
54
+ ## Idefics3VisionConfig
55
+
56
+ [[autodoc]] Idefics3VisionConfig
57
+
58
+ ## Idefics3VisionTransformer
59
+
60
+ [[autodoc]] Idefics3VisionTransformer
61
+
62
+ ## Idefics3Model
63
+
64
+ [[autodoc]] Idefics3Model
65
+ - forward
66
+
67
+ ## Idefics3ForConditionalGeneration
68
+
69
+ [[autodoc]] Idefics3ForConditionalGeneration
70
+ - forward
71
+
72
+
73
+ ## Idefics3ImageProcessor
74
+ [[autodoc]] Idefics3ImageProcessor
75
+ - preprocess
76
+
77
+
78
+ ## Idefics3Processor
79
+ [[autodoc]] Idefics3Processor
80
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/ijepa.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # I-JEPA
18
+
19
+ ## Overview
20
+
21
+ The I-JEPA model was proposed in [Image-based Joint-Embedding Predictive Architecture](https://arxiv.org/abs/2301.08243) by Mahmoud Assran, Quentin Duval, Ishan Misra, Piotr Bojanowski, Pascal Vincent, Michael Rabbat, Yann LeCun, Nicolas Ballas.
22
+ I-JEPA is a self-supervised learning method that predicts the representations of one part of an image based on other parts of the same image. This approach focuses on learning semantic features without relying on pre-defined invariances from hand-crafted data transformations, which can bias specific tasks, or on filling in pixel-level details, which often leads to less meaningful representations.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ This paper demonstrates an approach for learning highly semantic image representations without relying on hand-crafted data-augmentations. We introduce the Image- based Joint-Embedding Predictive Architecture (I-JEPA), a non-generative approach for self-supervised learning from images. The idea behind I-JEPA is simple: from a single context block, predict the representations of various target blocks in the same image. A core design choice to guide I-JEPA towards producing semantic representations is the masking strategy; specifically, it is crucial to (a) sample tar- get blocks with sufficiently large scale (semantic), and to (b) use a sufficiently informative (spatially distributed) context block. Empirically, when combined with Vision Transform- ers, we find I-JEPA to be highly scalable. For instance, we train a ViT-Huge/14 on ImageNet using 16 A100 GPUs in under 72 hours to achieve strong downstream performance across a wide range of tasks, from linear classification to object counting and depth prediction.
27
+
28
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/ijepa_architecture.jpg"
29
+ alt="drawing" width="600"/>
30
+
31
+ <small> I-JEPA architecture. Taken from the <a href="https://arxiv.org/abs/2301.08243">original paper.</a> </small>
32
+
33
+ This model was contributed by [jmtzt](https://huggingface.co/jmtzt).
34
+ The original code can be found [here](https://github.com/facebookresearch/ijepa).
35
+
36
+ ## How to use
37
+
38
+ Here is how to use this model for image feature extraction:
39
+
40
+ ```python
41
+ import requests
42
+ import torch
43
+ from PIL import Image
44
+ from torch.nn.functional import cosine_similarity
45
+
46
+ from transformers import AutoModel, AutoProcessor
47
+
48
+ url_1 = "http://images.cocodataset.org/val2017/000000039769.jpg"
49
+ url_2 = "http://images.cocodataset.org/val2017/000000219578.jpg"
50
+ image_1 = Image.open(requests.get(url_1, stream=True).raw)
51
+ image_2 = Image.open(requests.get(url_2, stream=True).raw)
52
+
53
+ model_id = "facebook/ijepa_vith14_1k"
54
+ processor = AutoProcessor.from_pretrained(model_id)
55
+ model = AutoModel.from_pretrained(model_id)
56
+
57
+ @torch.no_grad()
58
+ def infer(image):
59
+ inputs = processor(image, return_tensors="pt")
60
+ outputs = model(**inputs)
61
+ return outputs.last_hidden_state.mean(dim=1)
62
+
63
+
64
+ embed_1 = infer(image_1)
65
+ embed_2 = infer(image_2)
66
+
67
+ similarity = cosine_similarity(embed_1, embed_2)
68
+ print(similarity)
69
+ ```
70
+
71
+ ## Resources
72
+
73
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with I-JEPA.
74
+
75
+ <PipelineTag pipeline="image-classification"/>
76
+
77
+ - [`IJepaForImageClassification`] 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).
78
+ - See also: [Image classification task guide](../tasks/image_classification)
79
+
80
+ ## IJepaConfig
81
+
82
+ [[autodoc]] IJepaConfig
83
+
84
+ ## IJepaModel
85
+
86
+ [[autodoc]] IJepaModel
87
+ - forward
88
+
89
+ ## IJepaForImageClassification
90
+
91
+ [[autodoc]] IJepaForImageClassification
92
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/imagegpt.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
+
16
+ # ImageGPT
17
+
18
+ ## Overview
19
+
20
+ The ImageGPT model was proposed in [Generative Pretraining from Pixels](https://openai.com/blog/image-gpt) by Mark
21
+ Chen, Alec Radford, Rewon Child, Jeffrey Wu, Heewoo Jun, David Luan, Ilya Sutskever. ImageGPT (iGPT) is a GPT-2-like
22
+ model trained to predict the next pixel value, allowing for both unconditional and conditional image generation.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ *Inspired by progress in unsupervised representation learning for natural language, we examine whether similar models
27
+ can learn useful representations for images. We train a sequence Transformer to auto-regressively predict pixels,
28
+ without incorporating knowledge of the 2D input structure. Despite training on low-resolution ImageNet without labels,
29
+ we find that a GPT-2 scale model learns strong image representations as measured by linear probing, fine-tuning, and
30
+ low-data classification. On CIFAR-10, we achieve 96.3% accuracy with a linear probe, outperforming a supervised Wide
31
+ ResNet, and 99.0% accuracy with full fine-tuning, matching the top supervised pre-trained models. We are also
32
+ competitive with self-supervised benchmarks on ImageNet when substituting pixels for a VQVAE encoding, achieving 69.0%
33
+ top-1 accuracy on a linear probe of our features.*
34
+
35
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/imagegpt_architecture.png"
36
+ alt="drawing" width="600"/>
37
+
38
+ <small> Summary of the approach. Taken from the [original paper](https://cdn.openai.com/papers/Generative_Pretraining_from_Pixels_V2.pdf). </small>
39
+
40
+ This model was contributed by [nielsr](https://huggingface.co/nielsr), based on [this issue](https://github.com/openai/image-gpt/issues/7). The original code can be found
41
+ [here](https://github.com/openai/image-gpt).
42
+
43
+ ## Usage tips
44
+
45
+ - ImageGPT is almost exactly the same as [GPT-2](gpt2), with the exception that a different activation
46
+ function is used (namely "quick gelu"), and the layer normalization layers don't mean center the inputs. ImageGPT
47
+ also doesn't have tied input- and output embeddings.
48
+ - As the time- and memory requirements of the attention mechanism of Transformers scales quadratically in the sequence
49
+ length, the authors pre-trained ImageGPT on smaller input resolutions, such as 32x32 and 64x64. However, feeding a
50
+ sequence of 32x32x3=3072 tokens from 0..255 into a Transformer is still prohibitively large. Therefore, the authors
51
+ applied k-means clustering to the (R,G,B) pixel values with k=512. This way, we only have a 32*32 = 1024-long
52
+ sequence, but now of integers in the range 0..511. So we are shrinking the sequence length at the cost of a bigger
53
+ embedding matrix. In other words, the vocabulary size of ImageGPT is 512, + 1 for a special "start of sentence" (SOS)
54
+ token, used at the beginning of every sequence. One can use [`ImageGPTImageProcessor`] to prepare
55
+ images for the model.
56
+ - Despite being pre-trained entirely unsupervised (i.e. without the use of any labels), ImageGPT produces fairly
57
+ performant image features useful for downstream tasks, such as image classification. The authors showed that the
58
+ features in the middle of the network are the most performant, and can be used as-is to train a linear model (such as
59
+ a sklearn logistic regression model for example). This is also referred to as "linear probing". Features can be
60
+ easily obtained by first forwarding the image through the model, then specifying `output_hidden_states=True`, and
61
+ then average-pool the hidden states at whatever layer you like.
62
+ - Alternatively, one can further fine-tune the entire model on a downstream dataset, similar to BERT. For this, you can
63
+ use [`ImageGPTForImageClassification`].
64
+ - ImageGPT comes in different sizes: there's ImageGPT-small, ImageGPT-medium and ImageGPT-large. The authors did also
65
+ train an XL variant, which they didn't release. The differences in size are summarized in the following table:
66
+
67
+ | **Model variant** | **Depths** | **Hidden sizes** | **Decoder hidden size** | **Params (M)** | **ImageNet-1k Top 1** |
68
+ |---|---|---|---|---|---|
69
+ | MiT-b0 | [2, 2, 2, 2] | [32, 64, 160, 256] | 256 | 3.7 | 70.5 |
70
+ | MiT-b1 | [2, 2, 2, 2] | [64, 128, 320, 512] | 256 | 14.0 | 78.7 |
71
+ | MiT-b2 | [3, 4, 6, 3] | [64, 128, 320, 512] | 768 | 25.4 | 81.6 |
72
+ | MiT-b3 | [3, 4, 18, 3] | [64, 128, 320, 512] | 768 | 45.2 | 83.1 |
73
+ | MiT-b4 | [3, 8, 27, 3] | [64, 128, 320, 512] | 768 | 62.6 | 83.6 |
74
+ | MiT-b5 | [3, 6, 40, 3] | [64, 128, 320, 512] | 768 | 82.0 | 83.8 |
75
+
76
+ ## Resources
77
+
78
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with ImageGPT.
79
+
80
+ <PipelineTag pipeline="image-classification"/>
81
+
82
+ - Demo notebooks for ImageGPT can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/ImageGPT).
83
+ - [`ImageGPTForImageClassification`] 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).
84
+ - See also: [Image classification task guide](../tasks/image_classification)
85
+
86
+ 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.
87
+
88
+ ## ImageGPTConfig
89
+
90
+ [[autodoc]] ImageGPTConfig
91
+
92
+ ## ImageGPTFeatureExtractor
93
+
94
+ [[autodoc]] ImageGPTFeatureExtractor
95
+ - __call__
96
+
97
+ ## ImageGPTImageProcessor
98
+
99
+ [[autodoc]] ImageGPTImageProcessor
100
+ - preprocess
101
+
102
+ ## ImageGPTModel
103
+
104
+ [[autodoc]] ImageGPTModel
105
+ - forward
106
+
107
+ ## ImageGPTForCausalImageModeling
108
+
109
+ [[autodoc]] ImageGPTForCausalImageModeling
110
+ - forward
111
+
112
+ ## ImageGPTForImageClassification
113
+
114
+ [[autodoc]] ImageGPTForImageClassification
115
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/informer.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Informer
18
+
19
+ ## Overview
20
+
21
+ The Informer model was proposed in [Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting](https://arxiv.org/abs/2012.07436) by Haoyi Zhou, Shanghang Zhang, Jieqi Peng, Shuai Zhang, Jianxin Li, Hui Xiong, and Wancai Zhang.
22
+
23
+ This method introduces a Probabilistic Attention mechanism to select the "active" queries rather than the "lazy" queries and provides a sparse Transformer thus mitigating the quadratic compute and memory requirements of vanilla attention.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Many real-world applications require the prediction of long sequence time-series, such as electricity consumption planning. Long sequence time-series forecasting (LSTF) demands a high prediction capacity of the model, which is the ability to capture precise long-range dependency coupling between output and input efficiently. Recent studies have shown the potential of Transformer to increase the prediction capacity. However, there are several severe issues with Transformer that prevent it from being directly applicable to LSTF, including quadratic time complexity, high memory usage, and inherent limitation of the encoder-decoder architecture. To address these issues, we design an efficient transformer-based model for LSTF, named Informer, with three distinctive characteristics: (i) a ProbSparse self-attention mechanism, which achieves O(L logL) in time complexity and memory usage, and has comparable performance on sequences' dependency alignment. (ii) the self-attention distilling highlights dominating attention by halving cascading layer input, and efficiently handles extreme long input sequences. (iii) the generative style decoder, while conceptually simple, predicts the long time-series sequences at one forward operation rather than a step-by-step way, which drastically improves the inference speed of long-sequence predictions. Extensive experiments on four large-scale datasets demonstrate that Informer significantly outperforms existing methods and provides a new solution to the LSTF problem.*
28
+
29
+ This model was contributed by [elisim](https://huggingface.co/elisim) and [kashif](https://huggingface.co/kashif).
30
+ The original code can be found [here](https://github.com/zhouhaoyi/Informer2020).
31
+
32
+ ## Resources
33
+
34
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started. 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.
35
+
36
+ - Check out the Informer blog-post in HuggingFace blog: [Multivariate Probabilistic Time Series Forecasting with Informer](https://huggingface.co/blog/informer)
37
+
38
+ ## InformerConfig
39
+
40
+ [[autodoc]] InformerConfig
41
+
42
+ ## InformerModel
43
+
44
+ [[autodoc]] InformerModel
45
+ - forward
46
+
47
+ ## InformerForPrediction
48
+
49
+ [[autodoc]] InformerForPrediction
50
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/instructblip.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ # InstructBLIP
14
+
15
+ ## Overview
16
+
17
+ The InstructBLIP model was proposed in [InstructBLIP: Towards General-purpose Vision-Language Models with Instruction Tuning](https://arxiv.org/abs/2305.06500) by Wenliang Dai, Junnan Li, Dongxu Li, Anthony Meng Huat Tiong, Junqi Zhao, Weisheng Wang, Boyang Li, Pascale Fung, Steven Hoi.
18
+ InstructBLIP leverages the [BLIP-2](blip2) architecture for visual instruction tuning.
19
+
20
+ The abstract from the paper is the following:
21
+
22
+ *General-purpose language models that can solve various language-domain tasks have emerged driven by the pre-training and instruction-tuning pipeline. However, building general-purpose vision-language models is challenging due to the increased task discrepancy introduced by the additional visual input. Although vision-language pre-training has been widely studied, vision-language instruction tuning remains relatively less explored. In this paper, we conduct a systematic and comprehensive study on vision-language instruction tuning based on the pre-trained BLIP-2 models. We gather a wide variety of 26 publicly available datasets, transform them into instruction tuning format and categorize them into two clusters for held-in instruction tuning and held-out zero-shot evaluation. Additionally, we introduce instruction-aware visual feature extraction, a crucial method that enables the model to extract informative features tailored to the given instruction. The resulting InstructBLIP models achieve state-of-the-art zero-shot performance across all 13 held-out datasets, substantially outperforming BLIP-2 and the larger Flamingo. Our models also lead to state-of-the-art performance when finetuned on individual downstream tasks (e.g., 90.7% accuracy on ScienceQA IMG). Furthermore, we qualitatively demonstrate the advantages of InstructBLIP over concurrent multimodal models.*
23
+
24
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/instructblip_architecture.jpg"
25
+ alt="drawing" width="600"/>
26
+
27
+ <small> InstructBLIP architecture. Taken from the <a href="https://arxiv.org/abs/2305.06500">original paper.</a> </small>
28
+
29
+ This model was contributed by [nielsr](https://huggingface.co/nielsr).
30
+ The original code can be found [here](https://github.com/salesforce/LAVIS/tree/main/projects/instructblip).
31
+
32
+ ## Usage tips
33
+
34
+ InstructBLIP uses the same architecture as [BLIP-2](blip2) with a tiny but important difference: it also feeds the text prompt (instruction) to the Q-Former.
35
+
36
+ > [!NOTE]
37
+ > BLIP models after release v4.46 will raise warnings about adding `processor.num_query_tokens = {{num_query_tokens}}` and expand model embeddings layer to add special `<image>` token. It is strongly recommended to add the attributes to the processor if you own the model checkpoint, or open a PR if it is not owned by you. Adding these attributes means that BLIP will add the number of query tokens required per image and expand the text with as many `<image>` placeholders as there will be query tokens. Usually it is around 500 tokens per image, so make sure that the text is not truncated as otherwise there wil be failure when merging the embeddings.
38
+ The attributes can be obtained from model config, as `model.config.num_query_tokens` and model embeddings expansion can be done by following [this link](https://gist.github.com/zucchini-nlp/e9f20b054fa322f84ac9311d9ab67042).
39
+
40
+ ## InstructBlipConfig
41
+
42
+ [[autodoc]] InstructBlipConfig
43
+ - from_vision_qformer_text_configs
44
+
45
+ ## InstructBlipVisionConfig
46
+
47
+ [[autodoc]] InstructBlipVisionConfig
48
+
49
+ ## InstructBlipQFormerConfig
50
+
51
+ [[autodoc]] InstructBlipQFormerConfig
52
+
53
+ ## InstructBlipProcessor
54
+
55
+ [[autodoc]] InstructBlipProcessor
56
+
57
+
58
+ ## InstructBlipVisionModel
59
+
60
+ [[autodoc]] InstructBlipVisionModel
61
+ - forward
62
+
63
+ ## InstructBlipQFormerModel
64
+
65
+ [[autodoc]] InstructBlipQFormerModel
66
+ - forward
67
+
68
+ ## InstructBlipForConditionalGeneration
69
+
70
+ [[autodoc]] InstructBlipForConditionalGeneration
71
+ - forward
72
+ - generate
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/instructblipvideo.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ # InstructBlipVideo
14
+
15
+ ## Overview
16
+
17
+ ## Overview
18
+
19
+ The InstructBLIPVideo is an extension of the models proposed in [InstructBLIP: Towards General-purpose Vision-Language Models with Instruction Tuning](https://arxiv.org/abs/2305.06500) by Wenliang Dai, Junnan Li, Dongxu Li, Anthony Meng Huat Tiong, Junqi Zhao, Weisheng Wang, Boyang Li, Pascale Fung, Steven Hoi.
20
+ InstructBLIPVideo uses the same architecture as [InstructBLIP](instructblip) and works with the same checkpoints as [InstructBLIP](instructblip). The only difference is the ability to process videos.
21
+
22
+ The abstract from the paper is the following:
23
+
24
+ *General-purpose language models that can solve various language-domain tasks have emerged driven by the pre-training and instruction-tuning pipeline. However, building general-purpose vision-language models is challenging due to the increased task discrepancy introduced by the additional visual input. Although vision-language pre-training has been widely studied, vision-language instruction tuning remains relatively less explored. In this paper, we conduct a systematic and comprehensive study on vision-language instruction tuning based on the pre-trained BLIP-2 models. We gather a wide variety of 26 publicly available datasets, transform them into instruction tuning format and categorize them into two clusters for held-in instruction tuning and held-out zero-shot evaluation. Additionally, we introduce instruction-aware visual feature extraction, a crucial method that enables the model to extract informative features tailored to the given instruction. The resulting InstructBLIP models achieve state-of-the-art zero-shot performance across all 13 held-out datasets, substantially outperforming BLIP-2 and the larger Flamingo. Our models also lead to state-of-the-art performance when finetuned on individual downstream tasks (e.g., 90.7% accuracy on ScienceQA IMG). Furthermore, we qualitatively demonstrate the advantages of InstructBLIP over concurrent multimodal models.*
25
+
26
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/instructblip_architecture.jpg"
27
+ alt="drawing" width="600"/>
28
+
29
+ <small> InstructBLIPVideo architecture. Taken from the <a href="https://arxiv.org/abs/2305.06500">original paper.</a> </small>
30
+
31
+ This model was contributed by [RaushanTurganbay](https://huggingface.co/RaushanTurganbay).
32
+ The original code can be found [here](https://github.com/salesforce/LAVIS/tree/main/projects/instructblip).
33
+
34
+ ## Usage tips
35
+
36
+ - The model was trained by sampling 4 frames per video, so it's recommended to sample 4 frames
37
+
38
+ > [!NOTE]
39
+ > BLIP models after release v4.46 will raise warnings about adding `processor.num_query_tokens = {{num_query_tokens}}` and expand model embeddings layer to add special `<image>` token. It is strongly recommended to add the attributes to the processor if you own the model checkpoint, or open a PR if it is not owned by you. Adding these attributes means that BLIP will add the number of query tokens required per image and expand the text with as many `<image>` placeholders as there will be query tokens. Usually it is around 500 tokens per image, so make sure that the text is not truncated as otherwise there wil be failure when merging the embeddings.
40
+ The attributes can be obtained from model config, as `model.config.num_query_tokens` and model embeddings expansion can be done by following [this link](https://gist.github.com/zucchini-nlp/e9f20b054fa322f84ac9311d9ab67042).
41
+
42
+ ## InstructBlipVideoConfig
43
+
44
+ [[autodoc]] InstructBlipVideoConfig
45
+ - from_vision_qformer_text_configs
46
+
47
+ ## InstructBlipVideoVisionConfig
48
+
49
+ [[autodoc]] InstructBlipVideoVisionConfig
50
+
51
+ ## InstructBlipVideoQFormerConfig
52
+
53
+ [[autodoc]] InstructBlipVideoQFormerConfig
54
+
55
+ ## InstructBlipVideoProcessor
56
+
57
+ [[autodoc]] InstructBlipVideoProcessor
58
+
59
+ ## InstructBlipVideoImageProcessor
60
+
61
+ [[autodoc]] InstructBlipVideoImageProcessor
62
+ - preprocess
63
+
64
+ ## InstructBlipVideoVisionModel
65
+
66
+ [[autodoc]] InstructBlipVideoVisionModel
67
+ - forward
68
+
69
+ ## InstructBlipVideoQFormerModel
70
+
71
+ [[autodoc]] InstructBlipVideoQFormerModel
72
+ - forward
73
+
74
+ ## InstructBlipVideoForConditionalGeneration
75
+
76
+ [[autodoc]] InstructBlipVideoForConditionalGeneration
77
+ - forward
78
+ - generate
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jamba.md ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Jamba
18
+
19
+ ## Overview
20
+
21
+ Jamba is a state-of-the-art, hybrid SSM-Transformer LLM. It is the first production-scale Mamba implementation, which opens up interesting research and application opportunities. While this initial experimentation shows encouraging gains, we expect these to be further enhanced with future optimizations and explorations.
22
+
23
+ For full details of this model please read the [release blog post](https://www.ai21.com/blog/announcing-jamba).
24
+
25
+ ### Model Details
26
+
27
+ Jamba is a pretrained, mixture-of-experts (MoE) generative text model, with 12B active parameters and an overall of 52B parameters across all experts. It supports a 256K context length, and can fit up to 140K tokens on a single 80GB GPU.
28
+
29
+ As depicted in the diagram below, Jamba's architecture features a blocks-and-layers approach that allows Jamba to successfully integrate Transformer and Mamba architectures altogether. Each Jamba block contains either an attention or a Mamba layer, followed by a multi-layer perceptron (MLP), producing an overall ratio of one Transformer layer out of every eight total layers.
30
+
31
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/jamba_architecture.png"
32
+ alt="drawing" width="600"/>
33
+
34
+ ## Usage
35
+
36
+ ### Prerequisites
37
+
38
+ Jamba requires you use `transformers` version 4.39.0 or higher:
39
+ ```bash
40
+ pip install transformers>=4.39.0
41
+ ```
42
+
43
+ In order to run optimized Mamba implementations, you first need to install `mamba-ssm` and `causal-conv1d`:
44
+ ```bash
45
+ pip install mamba-ssm causal-conv1d>=1.2.0
46
+ ```
47
+ You also have to have the model on a CUDA device.
48
+
49
+ You can run the model not using the optimized Mamba kernels, but it is **not** recommended as it will result in significantly lower latencies. In order to do that, you'll need to specify `use_mamba_kernels=False` when loading the model.
50
+
51
+ ### Run the model
52
+ ```python
53
+ from transformers import AutoModelForCausalLM, AutoTokenizer
54
+
55
+ model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1")
56
+ tokenizer = AutoTokenizer.from_pretrained("ai21labs/Jamba-v0.1")
57
+
58
+ input_ids = tokenizer("In the recent Super Bowl LVIII,", return_tensors='pt').to(model.device)["input_ids"]
59
+
60
+ outputs = model.generate(input_ids, max_new_tokens=216)
61
+
62
+ print(tokenizer.batch_decode(outputs))
63
+ # ["<|startoftext|>In the recent Super Bowl LVIII, the Kansas City Chiefs emerged victorious, defeating the San Francisco 49ers in a thrilling overtime showdown. The game was a nail-biter, with both teams showcasing their skills and determination.\n\nThe Chiefs, led by their star quarterback Patrick Mahomes, displayed their offensive prowess, while the 49ers, led by their strong defense, put up a tough fight. The game went into overtime, with the Chiefs ultimately securing the win with a touchdown.\n\nThe victory marked the Chiefs' second Super Bowl win in four years, solidifying their status as one of the top teams in the NFL. The game was a testament to the skill and talent of both teams, and a thrilling end to the NFL season.\n\nThe Super Bowl is not just about the game itself, but also about the halftime show and the commercials. This year's halftime show featured a star-studded lineup, including Usher, Alicia Keys, and Lil Jon. The show was a spectacle of music and dance, with the performers delivering an energetic and entertaining performance.\n"]
64
+ ```
65
+
66
+ <details>
67
+ <summary><strong>Loading the model in half precision</strong></summary>
68
+
69
+ The published checkpoint is saved in BF16. In order to load it into RAM in BF16/FP16, you need to specify `torch_dtype`:
70
+
71
+ ```python
72
+ from transformers import AutoModelForCausalLM
73
+ import torch
74
+ model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1", torch_dtype=torch.bfloat16)
75
+ # you can also use torch_dtype=torch.float16
76
+ ```
77
+
78
+ When using half precision, you can enable the [FlashAttention2](https://github.com/Dao-AILab/flash-attention) implementation of the Attention blocks. In order to use it, you also need the model on a CUDA device. Since in this precision the model is to big to fit on a single 80GB GPU, you'll also need to parallelize it using [accelerate](https://huggingface.co/docs/accelerate/index):
79
+ ```python
80
+ from transformers import AutoModelForCausalLM
81
+ import torch
82
+ model = AutoModelForCausalLM.from_pretrained("ai21labs/Jamba-v0.1",
83
+ torch_dtype=torch.bfloat16,
84
+ attn_implementation="flash_attention_2",
85
+ device_map="auto")
86
+ ```
87
+
88
+ </details>
89
+ <details><summary><strong>Load the model in 8-bit</strong></summary>
90
+
91
+ **Using 8-bit precision, it is possible to fit up to 140K sequence lengths on a single 80GB GPU.** You can easily quantize the model to 8-bit using [bitsandbytes](https://huggingface.co/docs/bitsandbytes/index). In order to not degrade model quality, we recommend to exclude the Mamba blocks from the quantization:
92
+
93
+ ```python
94
+ from transformers import AutoModelForCausalLM, BitsAndBytesConfig
95
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True, llm_int8_skip_modules=["mamba"])
96
+ model = AutoModelForCausalLM.from_pretrained(
97
+ "ai21labs/Jamba-v0.1", torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2", quantization_config=quantization_config
98
+ )
99
+ ```
100
+ </details>
101
+
102
+ ## JambaConfig
103
+
104
+ [[autodoc]] JambaConfig
105
+
106
+
107
+ ## JambaModel
108
+
109
+ [[autodoc]] JambaModel
110
+ - forward
111
+
112
+
113
+ ## JambaForCausalLM
114
+
115
+ [[autodoc]] JambaForCausalLM
116
+ - forward
117
+
118
+
119
+ ## JambaForSequenceClassification
120
+
121
+ [[autodoc]] transformers.JambaForSequenceClassification
122
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jetmoe.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2024 JetMoe team 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
+
17
+ # JetMoe
18
+
19
+ ## Overview
20
+
21
+ **JetMoe-8B** is an 8B Mixture-of-Experts (MoE) language model developed by [Yikang Shen](https://scholar.google.com.hk/citations?user=qff5rRYAAAAJ) and [MyShell](https://myshell.ai/).
22
+ JetMoe project aims to provide a LLaMA2-level performance and efficient language model with a limited budget.
23
+ To achieve this goal, JetMoe uses a sparsely activated architecture inspired by the [ModuleFormer](https://arxiv.org/abs/2306.04640).
24
+ Each JetMoe block consists of two MoE layers: Mixture of Attention Heads and Mixture of MLP Experts.
25
+ Given the input tokens, it activates a subset of its experts to process them.
26
+ This sparse activation schema enables JetMoe to achieve much better training throughput than similar size dense models.
27
+ The training throughput of JetMoe-8B is around 100B tokens per day on a cluster of 96 H100 GPUs with a straightforward 3-way pipeline parallelism strategy.
28
+
29
+ This model was contributed by [Yikang Shen](https://huggingface.co/YikangS).
30
+
31
+
32
+ ## JetMoeConfig
33
+
34
+ [[autodoc]] JetMoeConfig
35
+
36
+ ## JetMoeModel
37
+
38
+ [[autodoc]] JetMoeModel
39
+ - forward
40
+
41
+ ## JetMoeForCausalLM
42
+
43
+ [[autodoc]] JetMoeForCausalLM
44
+ - forward
45
+
46
+ ## JetMoeForSequenceClassification
47
+
48
+ [[autodoc]] JetMoeForSequenceClassification
49
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/jukebox.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Jukebox
17
+
18
+ <Tip warning={true}>
19
+
20
+ This model is in maintenance mode only, we don't accept any new PRs changing its code.
21
+ If you run into any issues running this model, please reinstall the last version that supported this model: v4.40.2.
22
+ You can do so by running the following command: `pip install -U transformers==4.40.2`.
23
+
24
+ </Tip>
25
+
26
+ ## Overview
27
+
28
+ The Jukebox model was proposed in [Jukebox: A generative model for music](https://arxiv.org/pdf/2005.00341.pdf)
29
+ by Prafulla Dhariwal, Heewoo Jun, Christine Payne, Jong Wook Kim, Alec Radford,
30
+ Ilya Sutskever. It introduces a generative music model which can produce minute long samples that can be conditioned on
31
+ an artist, genres and lyrics.
32
+
33
+ The abstract from the paper is the following:
34
+
35
+ *We introduce Jukebox, a model that generates music with singing in the raw audio domain. We tackle the long context of raw audio using a multiscale VQ-VAE to compress it to discrete codes, and modeling those using autoregressive Transformers. We show that the combined model at scale can generate high-fidelity and diverse songs with coherence up to multiple minutes. We can condition on artist and genre to steer the musical and vocal style, and on unaligned lyrics to make the singing more controllable. We are releasing thousands of non cherry-picked samples, along with model weights and code.*
36
+
37
+ As shown on the following figure, Jukebox is made of 3 `priors` which are decoder only models. They follow the architecture described in [Generating Long Sequences with Sparse Transformers](https://arxiv.org/abs/1904.10509), modified to support longer context length.
38
+ First, a autoencoder is used to encode the text lyrics. Next, the first (also called `top_prior`) prior attends to the last hidden states extracted from the lyrics encoder. The priors are linked to the previous priors respectively via an `AudioConditioner` module. The`AudioConditioner` upsamples the outputs of the previous prior to raw tokens at a certain audio frame per second resolution.
39
+ The metadata such as *artist, genre and timing* are passed to each prior, in the form of a start token and positional embedding for the timing data. The hidden states are mapped to the closest codebook vector from the VQVAE in order to convert them to raw audio.
40
+
41
+ ![JukeboxModel](https://gist.githubusercontent.com/ArthurZucker/92c1acaae62ebf1b6a951710bdd8b6af/raw/c9c517bf4eff61393f6c7dec9366ef02bdd059a3/jukebox.svg)
42
+
43
+ This model was contributed by [Arthur Zucker](https://huggingface.co/ArthurZ).
44
+ The original code can be found [here](https://github.com/openai/jukebox).
45
+
46
+ ## Usage tips
47
+
48
+ - This model only supports inference. This is for a few reasons, mostly because it requires a crazy amount of memory to train. Feel free to open a PR and add what's missing to have a full integration with the hugging face trainer!
49
+ - This model is very slow, and takes 8h to generate a minute long audio using the 5b top prior on a V100 GPU. In order automaticallay handle the device on which the model should execute, use `accelerate`.
50
+ - Contrary to the paper, the order of the priors goes from `0` to `1` as it felt more intuitive : we sample starting from `0`.
51
+ - Primed sampling (conditioning the sampling on raw audio) requires more memory than ancestral sampling and should be used with `fp16` set to `True`.
52
+
53
+ This model was contributed by [Arthur Zucker](https://huggingface.co/ArthurZ).
54
+ The original code can be found [here](https://github.com/openai/jukebox).
55
+
56
+ ## JukeboxConfig
57
+
58
+ [[autodoc]] JukeboxConfig
59
+
60
+ ## JukeboxPriorConfig
61
+
62
+ [[autodoc]] JukeboxPriorConfig
63
+
64
+ ## JukeboxVQVAEConfig
65
+
66
+ [[autodoc]] JukeboxVQVAEConfig
67
+
68
+ ## JukeboxTokenizer
69
+
70
+ [[autodoc]] JukeboxTokenizer
71
+ - save_vocabulary
72
+
73
+ ## JukeboxModel
74
+
75
+ [[autodoc]] JukeboxModel
76
+ - ancestral_sample
77
+ - primed_sample
78
+ - continue_sample
79
+ - upsample
80
+ - _sample
81
+
82
+ ## JukeboxPrior
83
+
84
+ [[autodoc]] JukeboxPrior
85
+ - sample
86
+ - forward
87
+
88
+ ## JukeboxVQVAE
89
+
90
+ [[autodoc]] JukeboxVQVAE
91
+ - forward
92
+ - encode
93
+ - decode
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/kosmos-2.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # KOSMOS-2
18
+
19
+ ## Overview
20
+
21
+ The KOSMOS-2 model was proposed in [Kosmos-2: Grounding Multimodal Large Language Models to the World](https://arxiv.org/abs/2306.14824) by Zhiliang Peng, Wenhui Wang, Li Dong, Yaru Hao, Shaohan Huang, Shuming Ma, Furu Wei.
22
+
23
+ KOSMOS-2 is a Transformer-based causal language model and is trained using the next-word prediction task on a web-scale
24
+ dataset of grounded image-text pairs [GRIT](https://huggingface.co/datasets/zzliang/GRIT). The spatial coordinates of
25
+ the bounding boxes in the dataset are converted to a sequence of location tokens, which are appended to their respective
26
+ entity text spans (for example, `a snowman` followed by `<patch_index_0044><patch_index_0863>`). The data format is
27
+ similar to “hyperlinks” that connect the object regions in an image to their text span in the corresponding caption.
28
+
29
+ The abstract from the paper is the following:
30
+
31
+ *We introduce Kosmos-2, a Multimodal Large Language Model (MLLM), enabling new capabilities of perceiving object descriptions (e.g., bounding boxes) and grounding text to the visual world. Specifically, we represent refer expressions as links in Markdown, i.e., ``[text span](bounding boxes)'', where object descriptions are sequences of location tokens. Together with multimodal corpora, we construct large-scale data of grounded image-text pairs (called GrIT) to train the model. In addition to the existing capabilities of MLLMs (e.g., perceiving general modalities, following instructions, and performing in-context learning), Kosmos-2 integrates the grounding capability into downstream applications. We evaluate Kosmos-2 on a wide range of tasks, including (i) multimodal grounding, such as referring expression comprehension, and phrase grounding, (ii) multimodal referring, such as referring expression generation, (iii) perception-language tasks, and (iv) language understanding and generation. This work lays out the foundation for the development of Embodiment AI and sheds light on the big convergence of language, multimodal perception, action, and world modeling, which is a key step toward artificial general intelligence. Code and pretrained models are available at https://aka.ms/kosmos-2.*
32
+
33
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/kosmos_2_overview.jpg"
34
+ alt="drawing" width="600"/>
35
+
36
+ <small> Overview of tasks that KOSMOS-2 can handle. Taken from the <a href="https://arxiv.org/abs/2306.14824">original paper</a>. </small>
37
+
38
+ ## Example
39
+
40
+ ```python
41
+ >>> from PIL import Image
42
+ >>> import requests
43
+ >>> from transformers import AutoProcessor, Kosmos2ForConditionalGeneration
44
+
45
+ >>> model = Kosmos2ForConditionalGeneration.from_pretrained("microsoft/kosmos-2-patch14-224")
46
+ >>> processor = AutoProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
47
+
48
+ >>> url = "https://huggingface.co/microsoft/kosmos-2-patch14-224/resolve/main/snowman.jpg"
49
+ >>> image = Image.open(requests.get(url, stream=True).raw)
50
+
51
+ >>> prompt = "<grounding> An image of"
52
+
53
+ >>> inputs = processor(text=prompt, images=image, return_tensors="pt")
54
+
55
+ >>> generated_ids = model.generate(
56
+ ... pixel_values=inputs["pixel_values"],
57
+ ... input_ids=inputs["input_ids"],
58
+ ... attention_mask=inputs["attention_mask"],
59
+ ... image_embeds=None,
60
+ ... image_embeds_position_mask=inputs["image_embeds_position_mask"],
61
+ ... use_cache=True,
62
+ ... max_new_tokens=64,
63
+ ... )
64
+ >>> generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
65
+ >>> processed_text = processor.post_process_generation(generated_text, cleanup_and_extract=False)
66
+ >>> processed_text
67
+ '<grounding> An image of<phrase> a snowman</phrase><object><patch_index_0044><patch_index_0863></object> warming himself by<phrase> a fire</phrase><object><patch_index_0005><patch_index_0911></object>.'
68
+
69
+ >>> caption, entities = processor.post_process_generation(generated_text)
70
+ >>> caption
71
+ 'An image of a snowman warming himself by a fire.'
72
+
73
+ >>> entities
74
+ [('a snowman', (12, 21), [(0.390625, 0.046875, 0.984375, 0.828125)]), ('a fire', (41, 47), [(0.171875, 0.015625, 0.484375, 0.890625)])]
75
+ ```
76
+
77
+ This model was contributed by [Yih-Dar SHIEH](https://huggingface.co/ydshieh). The original code can be found [here](https://github.com/microsoft/unilm/tree/master/kosmos-2).
78
+
79
+ ## Kosmos2Config
80
+
81
+ [[autodoc]] Kosmos2Config
82
+
83
+ ## Kosmos2ImageProcessor
84
+
85
+ ## Kosmos2Processor
86
+
87
+ [[autodoc]] Kosmos2Processor
88
+ - __call__
89
+
90
+ ## Kosmos2Model
91
+
92
+ [[autodoc]] Kosmos2Model
93
+ - forward
94
+
95
+ ## Kosmos2ForConditionalGeneration
96
+
97
+ [[autodoc]] Kosmos2ForConditionalGeneration
98
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlm.md ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LayoutLM
18
+
19
+ <a id='Overview'></a>
20
+
21
+ ## Overview
22
+
23
+ The LayoutLM model was proposed in the paper [LayoutLM: Pre-training of Text and Layout for Document Image
24
+ Understanding](https://arxiv.org/abs/1912.13318) by Yiheng Xu, Minghao Li, Lei Cui, Shaohan Huang, Furu Wei, and
25
+ Ming Zhou. It's a simple but effective pretraining method of text and layout for document image understanding and
26
+ information extraction tasks, such as form understanding and receipt understanding. It obtains state-of-the-art results
27
+ on several downstream tasks:
28
+
29
+ - form understanding: the [FUNSD](https://guillaumejaume.github.io/FUNSD/) dataset (a collection of 199 annotated
30
+ forms comprising more than 30,000 words).
31
+ - receipt understanding: the [SROIE](https://rrc.cvc.uab.es/?ch=13) dataset (a collection of 626 receipts for
32
+ training and 347 receipts for testing).
33
+ - document image classification: the [RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/) dataset (a collection of
34
+ 400,000 images belonging to one of 16 classes).
35
+
36
+ The abstract from the paper is the following:
37
+
38
+ *Pre-training techniques have been verified successfully in a variety of NLP tasks in recent years. Despite the
39
+ widespread use of pretraining models for NLP applications, they almost exclusively focus on text-level manipulation,
40
+ while neglecting layout and style information that is vital for document image understanding. In this paper, we propose
41
+ the LayoutLM to jointly model interactions between text and layout information across scanned document images, which is
42
+ beneficial for a great number of real-world document image understanding tasks such as information extraction from
43
+ scanned documents. Furthermore, we also leverage image features to incorporate words' visual information into LayoutLM.
44
+ To the best of our knowledge, this is the first time that text and layout are jointly learned in a single framework for
45
+ document-level pretraining. It achieves new state-of-the-art results in several downstream tasks, including form
46
+ understanding (from 70.72 to 79.27), receipt understanding (from 94.02 to 95.24) and document image classification
47
+ (from 93.07 to 94.42).*
48
+
49
+ ## Usage tips
50
+
51
+ - In addition to *input_ids*, [`~transformers.LayoutLMModel.forward`] also expects the input `bbox`, which are
52
+ the bounding boxes (i.e. 2D-positions) of the input tokens. These can be obtained using an external OCR engine such
53
+ as Google's [Tesseract](https://github.com/tesseract-ocr/tesseract) (there's a [Python wrapper](https://pypi.org/project/pytesseract/) available). Each bounding box should be in (x0, y0, x1, y1) format, where
54
+ (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1, y1) represents the
55
+ position of the lower right corner. Note that one first needs to normalize the bounding boxes to be on a 0-1000
56
+ scale. To normalize, you can use the following function:
57
+
58
+ ```python
59
+ def normalize_bbox(bbox, width, height):
60
+ return [
61
+ int(1000 * (bbox[0] / width)),
62
+ int(1000 * (bbox[1] / height)),
63
+ int(1000 * (bbox[2] / width)),
64
+ int(1000 * (bbox[3] / height)),
65
+ ]
66
+ ```
67
+
68
+ Here, `width` and `height` correspond to the width and height of the original document in which the token
69
+ occurs. Those can be obtained using the Python Image Library (PIL) library for example, as follows:
70
+
71
+ ```python
72
+ from PIL import Image
73
+
74
+ # Document can be a png, jpg, etc. PDFs must be converted to images.
75
+ image = Image.open(name_of_your_document).convert("RGB")
76
+
77
+ width, height = image.size
78
+ ```
79
+
80
+ ## Resources
81
+
82
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LayoutLM. 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
+
85
+ <PipelineTag pipeline="document-question-answering" />
86
+
87
+ - A blog post on [fine-tuning
88
+ LayoutLM for document-understanding using Keras & Hugging Face
89
+ Transformers](https://www.philschmid.de/fine-tuning-layoutlm-keras).
90
+
91
+ - A blog post on how to [fine-tune LayoutLM for document-understanding using only Hugging Face Transformers](https://www.philschmid.de/fine-tuning-layoutlm).
92
+
93
+ - A notebook on how to [fine-tune LayoutLM on the FUNSD dataset with image embeddings](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLM/Add_image_embeddings_to_LayoutLM.ipynb).
94
+
95
+ - See also: [Document question answering task guide](../tasks/document_question_answering)
96
+
97
+ <PipelineTag pipeline="text-classification" />
98
+
99
+ - A notebook on how to [fine-tune LayoutLM for sequence classification on the RVL-CDIP dataset](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLM/Fine_tuning_LayoutLMForSequenceClassification_on_RVL_CDIP.ipynb).
100
+ - [Text classification task guide](../tasks/sequence_classification)
101
+
102
+ <PipelineTag pipeline="token-classification" />
103
+
104
+ - A notebook on how to [ fine-tune LayoutLM for token classification on the FUNSD dataset](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/LayoutLM/Fine_tuning_LayoutLMForTokenClassification_on_FUNSD.ipynb).
105
+ - [Token classification task guide](../tasks/token_classification)
106
+
107
+ **Other resources**
108
+ - [Masked language modeling task guide](../tasks/masked_language_modeling)
109
+
110
+ 🚀 Deploy
111
+
112
+ - A blog post on how to [Deploy LayoutLM with Hugging Face Inference Endpoints](https://www.philschmid.de/inference-endpoints-layoutlm).
113
+
114
+ ## LayoutLMConfig
115
+
116
+ [[autodoc]] LayoutLMConfig
117
+
118
+ ## LayoutLMTokenizer
119
+
120
+ [[autodoc]] LayoutLMTokenizer
121
+
122
+ ## LayoutLMTokenizerFast
123
+
124
+ [[autodoc]] LayoutLMTokenizerFast
125
+
126
+ <frameworkcontent>
127
+ <pt>
128
+
129
+ ## LayoutLMModel
130
+
131
+ [[autodoc]] LayoutLMModel
132
+
133
+ ## LayoutLMForMaskedLM
134
+
135
+ [[autodoc]] LayoutLMForMaskedLM
136
+
137
+ ## LayoutLMForSequenceClassification
138
+
139
+ [[autodoc]] LayoutLMForSequenceClassification
140
+
141
+ ## LayoutLMForTokenClassification
142
+
143
+ [[autodoc]] LayoutLMForTokenClassification
144
+
145
+ ## LayoutLMForQuestionAnswering
146
+
147
+ [[autodoc]] LayoutLMForQuestionAnswering
148
+
149
+ </pt>
150
+ <tf>
151
+
152
+ ## TFLayoutLMModel
153
+
154
+ [[autodoc]] TFLayoutLMModel
155
+
156
+ ## TFLayoutLMForMaskedLM
157
+
158
+ [[autodoc]] TFLayoutLMForMaskedLM
159
+
160
+ ## TFLayoutLMForSequenceClassification
161
+
162
+ [[autodoc]] TFLayoutLMForSequenceClassification
163
+
164
+ ## TFLayoutLMForTokenClassification
165
+
166
+ [[autodoc]] TFLayoutLMForTokenClassification
167
+
168
+ ## TFLayoutLMForQuestionAnswering
169
+
170
+ [[autodoc]] TFLayoutLMForQuestionAnswering
171
+
172
+ </tf>
173
+ </frameworkcontent>
174
+
175
+
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlmv2.md ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LayoutLMV2
18
+
19
+ ## Overview
20
+
21
+ The LayoutLMV2 model was proposed in [LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding](https://arxiv.org/abs/2012.14740) by Yang Xu, Yiheng Xu, Tengchao Lv, Lei Cui, Furu Wei, Guoxin Wang, Yijuan Lu,
22
+ Dinei Florencio, Cha Zhang, Wanxiang Che, Min Zhang, Lidong Zhou. LayoutLMV2 improves [LayoutLM](layoutlm) to obtain
23
+ state-of-the-art results across several document image understanding benchmarks:
24
+
25
+ - information extraction from scanned documents: the [FUNSD](https://guillaumejaume.github.io/FUNSD/) dataset (a
26
+ collection of 199 annotated forms comprising more than 30,000 words), the [CORD](https://github.com/clovaai/cord)
27
+ dataset (a collection of 800 receipts for training, 100 for validation and 100 for testing), the [SROIE](https://rrc.cvc.uab.es/?ch=13) dataset (a collection of 626 receipts for training and 347 receipts for testing)
28
+ and the [Kleister-NDA](https://github.com/applicaai/kleister-nda) dataset (a collection of non-disclosure
29
+ agreements from the EDGAR database, including 254 documents for training, 83 documents for validation, and 203
30
+ documents for testing).
31
+ - document image classification: the [RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/) dataset (a collection of
32
+ 400,000 images belonging to one of 16 classes).
33
+ - document visual question answering: the [DocVQA](https://arxiv.org/abs/2007.00398) dataset (a collection of 50,000
34
+ questions defined on 12,000+ document images).
35
+
36
+ The abstract from the paper is the following:
37
+
38
+ *Pre-training of text and layout has proved effective in a variety of visually-rich document understanding tasks due to
39
+ its effective model architecture and the advantage of large-scale unlabeled scanned/digital-born documents. In this
40
+ paper, we present LayoutLMv2 by pre-training text, layout and image in a multi-modal framework, where new model
41
+ architectures and pre-training tasks are leveraged. Specifically, LayoutLMv2 not only uses the existing masked
42
+ visual-language modeling task but also the new text-image alignment and text-image matching tasks in the pre-training
43
+ stage, where cross-modality interaction is better learned. Meanwhile, it also integrates a spatial-aware self-attention
44
+ mechanism into the Transformer architecture, so that the model can fully understand the relative positional
45
+ relationship among different text blocks. Experiment results show that LayoutLMv2 outperforms strong baselines and
46
+ achieves new state-of-the-art results on a wide variety of downstream visually-rich document understanding tasks,
47
+ including FUNSD (0.7895 -> 0.8420), CORD (0.9493 -> 0.9601), SROIE (0.9524 -> 0.9781), Kleister-NDA (0.834 -> 0.852),
48
+ RVL-CDIP (0.9443 -> 0.9564), and DocVQA (0.7295 -> 0.8672). The pre-trained LayoutLMv2 model is publicly available at
49
+ this https URL.*
50
+
51
+ LayoutLMv2 depends on `detectron2`, `torchvision` and `tesseract`. Run the
52
+ following to install them:
53
+ ```bash
54
+ python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
55
+ python -m pip install torchvision tesseract
56
+ ```
57
+ (If you are developing for LayoutLMv2, note that passing the doctests also requires the installation of these packages.)
58
+
59
+ ## Usage tips
60
+
61
+ - The main difference between LayoutLMv1 and LayoutLMv2 is that the latter incorporates visual embeddings during
62
+ pre-training (while LayoutLMv1 only adds visual embeddings during fine-tuning).
63
+ - LayoutLMv2 adds both a relative 1D attention bias as well as a spatial 2D attention bias to the attention scores in
64
+ the self-attention layers. Details can be found on page 5 of the [paper](https://arxiv.org/abs/2012.14740).
65
+ - Demo notebooks on how to use the LayoutLMv2 model on RVL-CDIP, FUNSD, DocVQA, CORD can be found [here](https://github.com/NielsRogge/Transformers-Tutorials).
66
+ - LayoutLMv2 uses Facebook AI's [Detectron2](https://github.com/facebookresearch/detectron2/) package for its visual
67
+ backbone. See [this link](https://detectron2.readthedocs.io/en/latest/tutorials/install.html) for installation
68
+ instructions.
69
+ - In addition to `input_ids`, [`~LayoutLMv2Model.forward`] expects 2 additional inputs, namely
70
+ `image` and `bbox`. The `image` input corresponds to the original document image in which the text
71
+ tokens occur. The model expects each document image to be of size 224x224. This means that if you have a batch of
72
+ document images, `image` should be a tensor of shape (batch_size, 3, 224, 224). This can be either a
73
+ `torch.Tensor` or a `Detectron2.structures.ImageList`. You don't need to normalize the channels, as this is
74
+ done by the model. Important to note is that the visual backbone expects BGR channels instead of RGB, as all models
75
+ in Detectron2 are pre-trained using the BGR format. The `bbox` input are the bounding boxes (i.e. 2D-positions)
76
+ of the input text tokens. This is identical to [`LayoutLMModel`]. These can be obtained using an
77
+ external OCR engine such as Google's [Tesseract](https://github.com/tesseract-ocr/tesseract) (there's a [Python
78
+ wrapper](https://pypi.org/project/pytesseract/) available). Each bounding box should be in (x0, y0, x1, y1)
79
+ format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1, y1)
80
+ represents the position of the lower right corner. Note that one first needs to normalize the bounding boxes to be on
81
+ a 0-1000 scale. To normalize, you can use the following function:
82
+
83
+ ```python
84
+ def normalize_bbox(bbox, width, height):
85
+ return [
86
+ int(1000 * (bbox[0] / width)),
87
+ int(1000 * (bbox[1] / height)),
88
+ int(1000 * (bbox[2] / width)),
89
+ int(1000 * (bbox[3] / height)),
90
+ ]
91
+ ```
92
+
93
+ Here, `width` and `height` correspond to the width and height of the original document in which the token
94
+ occurs (before resizing the image). Those can be obtained using the Python Image Library (PIL) library for example, as
95
+ follows:
96
+
97
+ ```python
98
+ from PIL import Image
99
+
100
+ image = Image.open(
101
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
102
+ )
103
+
104
+ width, height = image.size
105
+ ```
106
+
107
+ However, this model includes a brand new [`~transformers.LayoutLMv2Processor`] which can be used to directly
108
+ prepare data for the model (including applying OCR under the hood). More information can be found in the "Usage"
109
+ section below.
110
+
111
+ - Internally, [`~transformers.LayoutLMv2Model`] will send the `image` input through its visual backbone to
112
+ obtain a lower-resolution feature map, whose shape is equal to the `image_feature_pool_shape` attribute of
113
+ [`~transformers.LayoutLMv2Config`]. This feature map is then flattened to obtain a sequence of image tokens. As
114
+ the size of the feature map is 7x7 by default, one obtains 49 image tokens. These are then concatenated with the text
115
+ tokens, and send through the Transformer encoder. This means that the last hidden states of the model will have a
116
+ length of 512 + 49 = 561, if you pad the text tokens up to the max length. More generally, the last hidden states
117
+ will have a shape of `seq_length` + `image_feature_pool_shape[0]` *
118
+ `config.image_feature_pool_shape[1]`.
119
+ - When calling [`~transformers.LayoutLMv2Model.from_pretrained`], a warning will be printed with a long list of
120
+ parameter names that are not initialized. This is not a problem, as these parameters are batch normalization
121
+ statistics, which are going to have values when fine-tuning on a custom dataset.
122
+ - If you want to train the model in a distributed environment, make sure to call [`synchronize_batch_norm`] on the
123
+ model in order to properly synchronize the batch normalization layers of the visual backbone.
124
+
125
+ In addition, there's LayoutXLM, which is a multilingual version of LayoutLMv2. More information can be found on
126
+ [LayoutXLM's documentation page](layoutxlm).
127
+
128
+ ## Resources
129
+
130
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LayoutLMv2. 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.
131
+
132
+ <PipelineTag pipeline="text-classification"/>
133
+
134
+ - A notebook on how to [finetune LayoutLMv2 for text-classification on RVL-CDIP dataset](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/RVL-CDIP/Fine_tuning_LayoutLMv2ForSequenceClassification_on_RVL_CDIP.ipynb).
135
+ - See also: [Text classification task guide](../tasks/sequence_classification)
136
+
137
+ <PipelineTag pipeline="question-answering"/>
138
+
139
+ - A notebook on how to [finetune LayoutLMv2 for question-answering on DocVQA dataset](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/DocVQA/Fine_tuning_LayoutLMv2ForQuestionAnswering_on_DocVQA.ipynb).
140
+ - See also: [Question answering task guide](../tasks/question_answering)
141
+ - See also: [Document question answering task guide](../tasks/document_question_answering)
142
+
143
+
144
+ <PipelineTag pipeline="token-classification"/>
145
+
146
+ - A notebook on how to [finetune LayoutLMv2 for token-classification on CORD dataset](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/CORD/Fine_tuning_LayoutLMv2ForTokenClassification_on_CORD.ipynb).
147
+ - A notebook on how to [finetune LayoutLMv2 for token-classification on FUNSD dataset](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/FUNSD/Fine_tuning_LayoutLMv2ForTokenClassification_on_FUNSD_using_HuggingFace_Trainer.ipynb).
148
+ - See also: [Token classification task guide](../tasks/token_classification)
149
+
150
+ ## Usage: LayoutLMv2Processor
151
+
152
+ The easiest way to prepare data for the model is to use [`LayoutLMv2Processor`], which internally
153
+ combines a image processor ([`LayoutLMv2ImageProcessor`]) and a tokenizer
154
+ ([`LayoutLMv2Tokenizer`] or [`LayoutLMv2TokenizerFast`]). The image processor
155
+ handles the image modality, while the tokenizer handles the text modality. A processor combines both, which is ideal
156
+ for a multi-modal model like LayoutLMv2. Note that you can still use both separately, if you only want to handle one
157
+ modality.
158
+
159
+ ```python
160
+ from transformers import LayoutLMv2ImageProcessor, LayoutLMv2TokenizerFast, LayoutLMv2Processor
161
+
162
+ image_processor = LayoutLMv2ImageProcessor() # apply_ocr is set to True by default
163
+ tokenizer = LayoutLMv2TokenizerFast.from_pretrained("microsoft/layoutlmv2-base-uncased")
164
+ processor = LayoutLMv2Processor(image_processor, tokenizer)
165
+ ```
166
+
167
+ In short, one can provide a document image (and possibly additional data) to [`LayoutLMv2Processor`],
168
+ and it will create the inputs expected by the model. Internally, the processor first uses
169
+ [`LayoutLMv2ImageProcessor`] to apply OCR on the image to get a list of words and normalized
170
+ bounding boxes, as well to resize the image to a given size in order to get the `image` input. The words and
171
+ normalized bounding boxes are then provided to [`LayoutLMv2Tokenizer`] or
172
+ [`LayoutLMv2TokenizerFast`], which converts them to token-level `input_ids`,
173
+ `attention_mask`, `token_type_ids`, `bbox`. Optionally, one can provide word labels to the processor,
174
+ which are turned into token-level `labels`.
175
+
176
+ [`LayoutLMv2Processor`] uses [PyTesseract](https://pypi.org/project/pytesseract/), a Python
177
+ wrapper around Google's Tesseract OCR engine, under the hood. Note that you can still use your own OCR engine of
178
+ choice, and provide the words and normalized boxes yourself. This requires initializing
179
+ [`LayoutLMv2ImageProcessor`] with `apply_ocr` set to `False`.
180
+
181
+ In total, there are 5 use cases that are supported by the processor. Below, we list them all. Note that each of these
182
+ use cases work for both batched and non-batched inputs (we illustrate them for non-batched inputs).
183
+
184
+ **Use case 1: document image classification (training, inference) + token classification (inference), apply_ocr =
185
+ True**
186
+
187
+ This is the simplest case, in which the processor (actually the image processor) will perform OCR on the image to get
188
+ the words and normalized bounding boxes.
189
+
190
+ ```python
191
+ from transformers import LayoutLMv2Processor
192
+ from PIL import Image
193
+
194
+ processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased")
195
+
196
+ image = Image.open(
197
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
198
+ ).convert("RGB")
199
+ encoding = processor(
200
+ image, return_tensors="pt"
201
+ ) # you can also add all tokenizer parameters here such as padding, truncation
202
+ print(encoding.keys())
203
+ # dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'image'])
204
+ ```
205
+
206
+ **Use case 2: document image classification (training, inference) + token classification (inference), apply_ocr=False**
207
+
208
+ In case one wants to do OCR themselves, one can initialize the image processor with `apply_ocr` set to
209
+ `False`. In that case, one should provide the words and corresponding (normalized) bounding boxes themselves to
210
+ the processor.
211
+
212
+ ```python
213
+ from transformers import LayoutLMv2Processor
214
+ from PIL import Image
215
+
216
+ processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased", revision="no_ocr")
217
+
218
+ image = Image.open(
219
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
220
+ ).convert("RGB")
221
+ words = ["hello", "world"]
222
+ boxes = [[1, 2, 3, 4], [5, 6, 7, 8]] # make sure to normalize your bounding boxes
223
+ encoding = processor(image, words, boxes=boxes, return_tensors="pt")
224
+ print(encoding.keys())
225
+ # dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'image'])
226
+ ```
227
+
228
+ **Use case 3: token classification (training), apply_ocr=False**
229
+
230
+ For token classification tasks (such as FUNSD, CORD, SROIE, Kleister-NDA), one can also provide the corresponding word
231
+ labels in order to train a model. The processor will then convert these into token-level `labels`. By default, it
232
+ will only label the first wordpiece of a word, and label the remaining wordpieces with -100, which is the
233
+ `ignore_index` of PyTorch's CrossEntropyLoss. In case you want all wordpieces of a word to be labeled, you can
234
+ initialize the tokenizer with `only_label_first_subword` set to `False`.
235
+
236
+ ```python
237
+ from transformers import LayoutLMv2Processor
238
+ from PIL import Image
239
+
240
+ processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased", revision="no_ocr")
241
+
242
+ image = Image.open(
243
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
244
+ ).convert("RGB")
245
+ words = ["hello", "world"]
246
+ boxes = [[1, 2, 3, 4], [5, 6, 7, 8]] # make sure to normalize your bounding boxes
247
+ word_labels = [1, 2]
248
+ encoding = processor(image, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
249
+ print(encoding.keys())
250
+ # dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'labels', 'image'])
251
+ ```
252
+
253
+ **Use case 4: visual question answering (inference), apply_ocr=True**
254
+
255
+ For visual question answering tasks (such as DocVQA), you can provide a question to the processor. By default, the
256
+ processor will apply OCR on the image, and create [CLS] question tokens [SEP] word tokens [SEP].
257
+
258
+ ```python
259
+ from transformers import LayoutLMv2Processor
260
+ from PIL import Image
261
+
262
+ processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased")
263
+
264
+ image = Image.open(
265
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
266
+ ).convert("RGB")
267
+ question = "What's his name?"
268
+ encoding = processor(image, question, return_tensors="pt")
269
+ print(encoding.keys())
270
+ # dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'image'])
271
+ ```
272
+
273
+ **Use case 5: visual question answering (inference), apply_ocr=False**
274
+
275
+ For visual question answering tasks (such as DocVQA), you can provide a question to the processor. If you want to
276
+ perform OCR yourself, you can provide your own words and (normalized) bounding boxes to the processor.
277
+
278
+ ```python
279
+ from transformers import LayoutLMv2Processor
280
+ from PIL import Image
281
+
282
+ processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased", revision="no_ocr")
283
+
284
+ image = Image.open(
285
+ "name_of_your_document - can be a png, jpg, etc. of your documents (PDFs must be converted to images)."
286
+ ).convert("RGB")
287
+ question = "What's his name?"
288
+ words = ["hello", "world"]
289
+ boxes = [[1, 2, 3, 4], [5, 6, 7, 8]] # make sure to normalize your bounding boxes
290
+ encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
291
+ print(encoding.keys())
292
+ # dict_keys(['input_ids', 'token_type_ids', 'attention_mask', 'bbox', 'image'])
293
+ ```
294
+
295
+ ## LayoutLMv2Config
296
+
297
+ [[autodoc]] LayoutLMv2Config
298
+
299
+ ## LayoutLMv2FeatureExtractor
300
+
301
+ [[autodoc]] LayoutLMv2FeatureExtractor
302
+ - __call__
303
+
304
+ ## LayoutLMv2ImageProcessor
305
+
306
+ [[autodoc]] LayoutLMv2ImageProcessor
307
+ - preprocess
308
+
309
+ ## LayoutLMv2Tokenizer
310
+
311
+ [[autodoc]] LayoutLMv2Tokenizer
312
+ - __call__
313
+ - save_vocabulary
314
+
315
+ ## LayoutLMv2TokenizerFast
316
+
317
+ [[autodoc]] LayoutLMv2TokenizerFast
318
+ - __call__
319
+
320
+ ## LayoutLMv2Processor
321
+
322
+ [[autodoc]] LayoutLMv2Processor
323
+ - __call__
324
+
325
+ ## LayoutLMv2Model
326
+
327
+ [[autodoc]] LayoutLMv2Model
328
+ - forward
329
+
330
+ ## LayoutLMv2ForSequenceClassification
331
+
332
+ [[autodoc]] LayoutLMv2ForSequenceClassification
333
+
334
+ ## LayoutLMv2ForTokenClassification
335
+
336
+ [[autodoc]] LayoutLMv2ForTokenClassification
337
+
338
+ ## LayoutLMv2ForQuestionAnswering
339
+
340
+ [[autodoc]] LayoutLMv2ForQuestionAnswering
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutlmv3.md ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LayoutLMv3
18
+
19
+ ## Overview
20
+
21
+ The LayoutLMv3 model was proposed in [LayoutLMv3: Pre-training for Document AI with Unified Text and Image Masking](https://arxiv.org/abs/2204.08387) by Yupan Huang, Tengchao Lv, Lei Cui, Yutong Lu, Furu Wei.
22
+ LayoutLMv3 simplifies [LayoutLMv2](layoutlmv2) by using patch embeddings (as in [ViT](vit)) instead of leveraging a CNN backbone, and pre-trains the model on 3 objectives: masked language modeling (MLM), masked image modeling (MIM)
23
+ and word-patch alignment (WPA).
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Self-supervised pre-training techniques have achieved remarkable progress in Document AI. Most multimodal pre-trained models use a masked language modeling objective to learn bidirectional representations on the text modality, but they differ in pre-training objectives for the image modality. This discrepancy adds difficulty to multimodal representation learning. In this paper, we propose LayoutLMv3 to pre-train multimodal Transformers for Document AI with unified text and image masking. Additionally, LayoutLMv3 is pre-trained with a word-patch alignment objective to learn cross-modal alignment by predicting whether the corresponding image patch of a text word is masked. The simple unified architecture and training objectives make LayoutLMv3 a general-purpose pre-trained model for both text-centric and image-centric Document AI tasks. Experimental results show that LayoutLMv3 achieves state-of-the-art performance not only in text-centric tasks, including form understanding, receipt understanding, and document visual question answering, but also in image-centric tasks such as document image classification and document layout analysis.*
28
+
29
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/layoutlmv3_architecture.png"
30
+ alt="drawing" width="600"/>
31
+
32
+ <small> LayoutLMv3 architecture. Taken from the <a href="https://arxiv.org/abs/2204.08387">original paper</a>. </small>
33
+
34
+ This model was contributed by [nielsr](https://huggingface.co/nielsr). The TensorFlow version of this model was added by [chriskoo](https://huggingface.co/chriskoo), [tokec](https://huggingface.co/tokec), and [lre](https://huggingface.co/lre). The original code can be found [here](https://github.com/microsoft/unilm/tree/master/layoutlmv3).
35
+
36
+ ## Usage tips
37
+
38
+ - In terms of data processing, LayoutLMv3 is identical to its predecessor [LayoutLMv2](layoutlmv2), except that:
39
+ - images need to be resized and normalized with channels in regular RGB format. LayoutLMv2 on the other hand normalizes the images internally and expects the channels in BGR format.
40
+ - text is tokenized using byte-pair encoding (BPE), as opposed to WordPiece.
41
+ Due to these differences in data preprocessing, one can use [`LayoutLMv3Processor`] which internally combines a [`LayoutLMv3ImageProcessor`] (for the image modality) and a [`LayoutLMv3Tokenizer`]/[`LayoutLMv3TokenizerFast`] (for the text modality) to prepare all data for the model.
42
+ - Regarding usage of [`LayoutLMv3Processor`], we refer to the [usage guide](layoutlmv2#usage-layoutlmv2processor) of its predecessor.
43
+
44
+ ## Resources
45
+
46
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LayoutLMv3. 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.
47
+
48
+ <Tip>
49
+
50
+ LayoutLMv3 is nearly identical to LayoutLMv2, so we've also included LayoutLMv2 resources you can adapt for LayoutLMv3 tasks. For these notebooks, take care to use [`LayoutLMv2Processor`] instead when preparing data for the model!
51
+
52
+ </Tip>
53
+
54
+ - Demo notebooks for LayoutLMv3 can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LayoutLMv3).
55
+ - Demo scripts can be found [here](https://github.com/huggingface/transformers/tree/main/examples/research_projects/layoutlmv3).
56
+
57
+ <PipelineTag pipeline="text-classification"/>
58
+
59
+ - [`LayoutLMv2ForSequenceClassification`] is supported by this [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/RVL-CDIP/Fine_tuning_LayoutLMv2ForSequenceClassification_on_RVL_CDIP.ipynb).
60
+ - [Text classification task guide](../tasks/sequence_classification)
61
+
62
+ <PipelineTag pipeline="token-classification"/>
63
+
64
+ - [`LayoutLMv3ForTokenClassification`] is supported by this [example script](https://github.com/huggingface/transformers/tree/main/examples/research_projects/layoutlmv3) and [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv3/Fine_tune_LayoutLMv3_on_FUNSD_(HuggingFace_Trainer).ipynb).
65
+ - A [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/FUNSD/Inference_with_LayoutLMv2ForTokenClassification.ipynb) for how to perform inference with [`LayoutLMv2ForTokenClassification`] and a [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/FUNSD/True_inference_with_LayoutLMv2ForTokenClassification_%2B_Gradio_demo.ipynb) for how to perform inference when no labels are available with [`LayoutLMv2ForTokenClassification`].
66
+ - A [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/FUNSD/Fine_tuning_LayoutLMv2ForTokenClassification_on_FUNSD_using_HuggingFace_Trainer.ipynb) for how to finetune [`LayoutLMv2ForTokenClassification`] with the 🤗 Trainer.
67
+ - [Token classification task guide](../tasks/token_classification)
68
+
69
+ <PipelineTag pipeline="question-answering"/>
70
+
71
+ - [`LayoutLMv2ForQuestionAnswering`] is supported by this [notebook](https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/LayoutLMv2/DocVQA/Fine_tuning_LayoutLMv2ForQuestionAnswering_on_DocVQA.ipynb).
72
+ - [Question answering task guide](../tasks/question_answering)
73
+
74
+ **Document question answering**
75
+ - [Document question answering task guide](../tasks/document_question_answering)
76
+
77
+ ## LayoutLMv3Config
78
+
79
+ [[autodoc]] LayoutLMv3Config
80
+
81
+ ## LayoutLMv3FeatureExtractor
82
+
83
+ [[autodoc]] LayoutLMv3FeatureExtractor
84
+ - __call__
85
+
86
+ ## LayoutLMv3ImageProcessor
87
+
88
+ [[autodoc]] LayoutLMv3ImageProcessor
89
+ - preprocess
90
+
91
+ ## LayoutLMv3Tokenizer
92
+
93
+ [[autodoc]] LayoutLMv3Tokenizer
94
+ - __call__
95
+ - save_vocabulary
96
+
97
+ ## LayoutLMv3TokenizerFast
98
+
99
+ [[autodoc]] LayoutLMv3TokenizerFast
100
+ - __call__
101
+
102
+ ## LayoutLMv3Processor
103
+
104
+ [[autodoc]] LayoutLMv3Processor
105
+ - __call__
106
+
107
+ <frameworkcontent>
108
+ <pt>
109
+
110
+ ## LayoutLMv3Model
111
+
112
+ [[autodoc]] LayoutLMv3Model
113
+ - forward
114
+
115
+ ## LayoutLMv3ForSequenceClassification
116
+
117
+ [[autodoc]] LayoutLMv3ForSequenceClassification
118
+ - forward
119
+
120
+ ## LayoutLMv3ForTokenClassification
121
+
122
+ [[autodoc]] LayoutLMv3ForTokenClassification
123
+ - forward
124
+
125
+ ## LayoutLMv3ForQuestionAnswering
126
+
127
+ [[autodoc]] LayoutLMv3ForQuestionAnswering
128
+ - forward
129
+
130
+ </pt>
131
+ <tf>
132
+
133
+ ## TFLayoutLMv3Model
134
+
135
+ [[autodoc]] TFLayoutLMv3Model
136
+ - call
137
+
138
+ ## TFLayoutLMv3ForSequenceClassification
139
+
140
+ [[autodoc]] TFLayoutLMv3ForSequenceClassification
141
+ - call
142
+
143
+ ## TFLayoutLMv3ForTokenClassification
144
+
145
+ [[autodoc]] TFLayoutLMv3ForTokenClassification
146
+ - call
147
+
148
+ ## TFLayoutLMv3ForQuestionAnswering
149
+
150
+ [[autodoc]] TFLayoutLMv3ForQuestionAnswering
151
+ - call
152
+
153
+ </tf>
154
+ </frameworkcontent>
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/layoutxlm.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LayoutXLM
18
+
19
+ ## Overview
20
+
21
+ LayoutXLM was proposed in [LayoutXLM: Multimodal Pre-training for Multilingual Visually-rich Document Understanding](https://arxiv.org/abs/2104.08836) by Yiheng Xu, Tengchao Lv, Lei Cui, Guoxin Wang, Yijuan Lu, Dinei Florencio, Cha
22
+ Zhang, Furu Wei. It's a multilingual extension of the [LayoutLMv2 model](https://arxiv.org/abs/2012.14740) trained
23
+ on 53 languages.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Multimodal pre-training with text, layout, and image has achieved SOTA performance for visually-rich document
28
+ understanding tasks recently, which demonstrates the great potential for joint learning across different modalities. In
29
+ this paper, we present LayoutXLM, a multimodal pre-trained model for multilingual document understanding, which aims to
30
+ bridge the language barriers for visually-rich document understanding. To accurately evaluate LayoutXLM, we also
31
+ introduce a multilingual form understanding benchmark dataset named XFUN, which includes form understanding samples in
32
+ 7 languages (Chinese, Japanese, Spanish, French, Italian, German, Portuguese), and key-value pairs are manually labeled
33
+ for each language. Experiment results show that the LayoutXLM model has significantly outperformed the existing SOTA
34
+ cross-lingual pre-trained models on the XFUN dataset.*
35
+
36
+ This model was contributed by [nielsr](https://huggingface.co/nielsr). The original code can be found [here](https://github.com/microsoft/unilm).
37
+
38
+ ## Usage tips and examples
39
+
40
+ One can directly plug in the weights of LayoutXLM into a LayoutLMv2 model, like so:
41
+
42
+ ```python
43
+ from transformers import LayoutLMv2Model
44
+
45
+ model = LayoutLMv2Model.from_pretrained("microsoft/layoutxlm-base")
46
+ ```
47
+
48
+ Note that LayoutXLM has its own tokenizer, based on
49
+ [`LayoutXLMTokenizer`]/[`LayoutXLMTokenizerFast`]. You can initialize it as
50
+ follows:
51
+
52
+ ```python
53
+ from transformers import LayoutXLMTokenizer
54
+
55
+ tokenizer = LayoutXLMTokenizer.from_pretrained("microsoft/layoutxlm-base")
56
+ ```
57
+
58
+ Similar to LayoutLMv2, you can use [`LayoutXLMProcessor`] (which internally applies
59
+ [`LayoutLMv2ImageProcessor`] and
60
+ [`LayoutXLMTokenizer`]/[`LayoutXLMTokenizerFast`] in sequence) to prepare all
61
+ data for the model.
62
+
63
+ <Tip>
64
+
65
+ As LayoutXLM's architecture is equivalent to that of LayoutLMv2, one can refer to [LayoutLMv2's documentation page](layoutlmv2) for all tips, code examples and notebooks.
66
+ </Tip>
67
+
68
+ ## LayoutXLMTokenizer
69
+
70
+ [[autodoc]] LayoutXLMTokenizer
71
+ - __call__
72
+ - build_inputs_with_special_tokens
73
+ - get_special_tokens_mask
74
+ - create_token_type_ids_from_sequences
75
+ - save_vocabulary
76
+
77
+ ## LayoutXLMTokenizerFast
78
+
79
+ [[autodoc]] LayoutXLMTokenizerFast
80
+ - __call__
81
+
82
+ ## LayoutXLMProcessor
83
+
84
+ [[autodoc]] LayoutXLMProcessor
85
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/led.md ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LED
18
+
19
+ ## Overview
20
+
21
+ The LED model was proposed in [Longformer: The Long-Document Transformer](https://arxiv.org/abs/2004.05150) by Iz
22
+ Beltagy, Matthew E. Peters, Arman Cohan.
23
+
24
+ The abstract from the paper is the following:
25
+
26
+ *Transformer-based models are unable to process long sequences due to their self-attention operation, which scales
27
+ quadratically with the sequence length. To address this limitation, we introduce the Longformer with an attention
28
+ mechanism that scales linearly with sequence length, making it easy to process documents of thousands of tokens or
29
+ longer. Longformer's attention mechanism is a drop-in replacement for the standard self-attention and combines a local
30
+ windowed attention with a task motivated global attention. Following prior work on long-sequence transformers, we
31
+ evaluate Longformer on character-level language modeling and achieve state-of-the-art results on text8 and enwik8. In
32
+ contrast to most prior work, we also pretrain Longformer and finetune it on a variety of downstream tasks. Our
33
+ pretrained Longformer consistently outperforms RoBERTa on long document tasks and sets new state-of-the-art results on
34
+ WikiHop and TriviaQA. We finally introduce the Longformer-Encoder-Decoder (LED), a Longformer variant for supporting
35
+ long document generative sequence-to-sequence tasks, and demonstrate its effectiveness on the arXiv summarization
36
+ dataset.*
37
+
38
+ ## Usage tips
39
+
40
+ - [`LEDForConditionalGeneration`] is an extension of
41
+ [`BartForConditionalGeneration`] exchanging the traditional *self-attention* layer with
42
+ *Longformer*'s *chunked self-attention* layer. [`LEDTokenizer`] is an alias of
43
+ [`BartTokenizer`].
44
+ - LED works very well on long-range *sequence-to-sequence* tasks where the `input_ids` largely exceed a length of
45
+ 1024 tokens.
46
+ - LED pads the `input_ids` to be a multiple of `config.attention_window` if required. Therefore a small speed-up is
47
+ gained, when [`LEDTokenizer`] is used with the `pad_to_multiple_of` argument.
48
+ - LED makes use of *global attention* by means of the `global_attention_mask` (see
49
+ [`LongformerModel`]). For summarization, it is advised to put *global attention* only on the first
50
+ `<s>` token. For question answering, it is advised to put *global attention* on all tokens of the question.
51
+ - To fine-tune LED on all 16384, *gradient checkpointing* can be enabled in case training leads to out-of-memory (OOM)
52
+ errors. This can be done by executing `model.gradient_checkpointing_enable()`.
53
+ Moreover, the `use_cache=False`
54
+ flag can be used to disable the caching mechanism to save memory.
55
+ - LED is a model with absolute position embeddings so it's usually advised to pad the inputs on the right rather than
56
+ the left.
57
+
58
+ This model was contributed by [patrickvonplaten](https://huggingface.co/patrickvonplaten).
59
+
60
+ ## Resources
61
+
62
+ - [A notebook showing how to evaluate LED](https://colab.research.google.com/drive/12INTTR6n64TzS4RrXZxMSXfrOd9Xzamo?usp=sharing).
63
+ - [A notebook showing how to fine-tune LED](https://colab.research.google.com/drive/12LjJazBl7Gam0XBPy_y0CTOJZeZ34c2v?usp=sharing).
64
+ - [Text classification task guide](../tasks/sequence_classification)
65
+ - [Question answering task guide](../tasks/question_answering)
66
+ - [Translation task guide](../tasks/translation)
67
+ - [Summarization task guide](../tasks/summarization)
68
+
69
+ ## LEDConfig
70
+
71
+ [[autodoc]] LEDConfig
72
+
73
+ ## LEDTokenizer
74
+
75
+ [[autodoc]] LEDTokenizer
76
+ - build_inputs_with_special_tokens
77
+ - get_special_tokens_mask
78
+ - create_token_type_ids_from_sequences
79
+ - save_vocabulary
80
+
81
+ ## LEDTokenizerFast
82
+
83
+ [[autodoc]] LEDTokenizerFast
84
+
85
+ ## LED specific outputs
86
+
87
+ [[autodoc]] models.led.modeling_led.LEDEncoderBaseModelOutput
88
+
89
+ [[autodoc]] models.led.modeling_led.LEDSeq2SeqModelOutput
90
+
91
+ [[autodoc]] models.led.modeling_led.LEDSeq2SeqLMOutput
92
+
93
+ [[autodoc]] models.led.modeling_led.LEDSeq2SeqSequenceClassifierOutput
94
+
95
+ [[autodoc]] models.led.modeling_led.LEDSeq2SeqQuestionAnsweringModelOutput
96
+
97
+ [[autodoc]] models.led.modeling_tf_led.TFLEDEncoderBaseModelOutput
98
+
99
+ [[autodoc]] models.led.modeling_tf_led.TFLEDSeq2SeqModelOutput
100
+
101
+ [[autodoc]] models.led.modeling_tf_led.TFLEDSeq2SeqLMOutput
102
+
103
+ <frameworkcontent>
104
+ <pt>
105
+
106
+ ## LEDModel
107
+
108
+ [[autodoc]] LEDModel
109
+ - forward
110
+
111
+ ## LEDForConditionalGeneration
112
+
113
+ [[autodoc]] LEDForConditionalGeneration
114
+ - forward
115
+
116
+ ## LEDForSequenceClassification
117
+
118
+ [[autodoc]] LEDForSequenceClassification
119
+ - forward
120
+
121
+ ## LEDForQuestionAnswering
122
+
123
+ [[autodoc]] LEDForQuestionAnswering
124
+ - forward
125
+
126
+ </pt>
127
+ <tf>
128
+
129
+ ## TFLEDModel
130
+
131
+ [[autodoc]] TFLEDModel
132
+ - call
133
+
134
+ ## TFLEDForConditionalGeneration
135
+
136
+ [[autodoc]] TFLEDForConditionalGeneration
137
+ - call
138
+
139
+ </tf>
140
+ </frameworkcontent>
141
+
142
+
143
+
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/levit.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LeViT
18
+
19
+ ## Overview
20
+
21
+ The LeViT model was proposed in [LeViT: Introducing Convolutions to Vision Transformers](https://arxiv.org/abs/2104.01136) by Ben Graham, Alaaeldin El-Nouby, Hugo Touvron, Pierre Stock, Armand Joulin, Hervé Jégou, Matthijs Douze. LeViT improves the [Vision Transformer (ViT)](vit) in performance and efficiency by a few architectural differences such as activation maps with decreasing resolutions in Transformers and the introduction of an attention bias to integrate positional information.
22
+
23
+ The abstract from the paper is the following:
24
+
25
+ *We design a family of image classification architectures that optimize the trade-off between accuracy
26
+ and efficiency in a high-speed regime. Our work exploits recent findings in attention-based architectures,
27
+ which are competitive on highly parallel processing hardware. We revisit principles from the extensive
28
+ literature on convolutional neural networks to apply them to transformers, in particular activation maps
29
+ with decreasing resolutions. We also introduce the attention bias, a new way to integrate positional information
30
+ in vision transformers. As a result, we propose LeVIT: a hybrid neural network for fast inference image classification.
31
+ We consider different measures of efficiency on different hardware platforms, so as to best reflect a wide range of
32
+ application scenarios. Our extensive experiments empirically validate our technical choices and show they are suitable
33
+ to most architectures. Overall, LeViT significantly outperforms existing convnets and vision transformers with respect
34
+ to the speed/accuracy tradeoff. For example, at 80% ImageNet top-1 accuracy, LeViT is 5 times faster than EfficientNet on CPU. *
35
+
36
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/levit_architecture.png"
37
+ alt="drawing" width="600"/>
38
+
39
+ <small> LeViT Architecture. Taken from the <a href="https://arxiv.org/abs/2104.01136">original paper</a>.</small>
40
+
41
+ This model was contributed by [anugunj](https://huggingface.co/anugunj). The original code can be found [here](https://github.com/facebookresearch/LeViT).
42
+
43
+ ## Usage tips
44
+
45
+ - Compared to ViT, LeViT models use an additional distillation head to effectively learn from a teacher (which, in the LeViT paper, is a ResNet like-model). The distillation head is learned through backpropagation under supervision of a ResNet like-model. They also draw inspiration from convolution neural networks to use activation maps with decreasing resolutions to increase the efficiency.
46
+ - There are 2 ways to fine-tune distilled models, either (1) in a classic way, by only placing a prediction head on top
47
+ of the final hidden state and not using the distillation head, or (2) by placing both a prediction head and distillation
48
+ head on top of the final hidden state. In that case, the prediction head is trained using regular cross-entropy between
49
+ the prediction of the head and the ground-truth label, while the distillation prediction head is trained using hard distillation
50
+ (cross-entropy between the prediction of the distillation head and the label predicted by the teacher). At inference time,
51
+ one takes the average prediction between both heads as final prediction. (2) is also called "fine-tuning with distillation",
52
+ because one relies on a teacher that has already been fine-tuned on the downstream dataset. In terms of models, (1) corresponds
53
+ to [`LevitForImageClassification`] and (2) corresponds to [`LevitForImageClassificationWithTeacher`].
54
+ - All released checkpoints were pre-trained and fine-tuned on [ImageNet-1k](https://huggingface.co/datasets/imagenet-1k)
55
+ (also referred to as ILSVRC 2012, a collection of 1.3 million images and 1,000 classes). only. No external data was used. This is in
56
+ contrast with the original ViT model, which used external data like the JFT-300M dataset/Imagenet-21k for
57
+ pre-training.
58
+ - The authors of LeViT released 5 trained LeViT models, which you can directly plug into [`LevitModel`] or [`LevitForImageClassification`].
59
+ Techniques like data augmentation, optimization, and regularization were used in order to simulate training on a much larger dataset
60
+ (while only using ImageNet-1k for pre-training). The 5 variants available are (all trained on images of size 224x224):
61
+ *facebook/levit-128S*, *facebook/levit-128*, *facebook/levit-192*, *facebook/levit-256* and
62
+ *facebook/levit-384*. Note that one should use [`LevitImageProcessor`] in order to
63
+ prepare images for the model.
64
+ - [`LevitForImageClassificationWithTeacher`] currently supports only inference and not training or fine-tuning.
65
+ - You can check out demo notebooks regarding inference as well as fine-tuning on custom data [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/VisionTransformer)
66
+ (you can just replace [`ViTFeatureExtractor`] by [`LevitImageProcessor`] and [`ViTForImageClassification`] by [`LevitForImageClassification`] or [`LevitForImageClassificationWithTeacher`]).
67
+
68
+ ## Resources
69
+
70
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LeViT.
71
+
72
+ <PipelineTag pipeline="image-classification"/>
73
+
74
+ - [`LevitForImageClassification`] 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).
75
+ - See also: [Image classification task guide](../tasks/image_classification)
76
+
77
+ 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.
78
+
79
+ ## LevitConfig
80
+
81
+ [[autodoc]] LevitConfig
82
+
83
+ ## LevitFeatureExtractor
84
+
85
+ [[autodoc]] LevitFeatureExtractor
86
+ - __call__
87
+
88
+ ## LevitImageProcessor
89
+
90
+ [[autodoc]] LevitImageProcessor
91
+ - preprocess
92
+
93
+ ## LevitModel
94
+
95
+ [[autodoc]] LevitModel
96
+ - forward
97
+
98
+ ## LevitForImageClassification
99
+
100
+ [[autodoc]] LevitForImageClassification
101
+ - forward
102
+
103
+ ## LevitForImageClassificationWithTeacher
104
+
105
+ [[autodoc]] LevitForImageClassificationWithTeacher
106
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/lilt.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LiLT
18
+
19
+ ## Overview
20
+
21
+ The LiLT model was proposed in [LiLT: A Simple yet Effective Language-Independent Layout Transformer for Structured Document Understanding](https://arxiv.org/abs/2202.13669) by Jiapeng Wang, Lianwen Jin, Kai Ding.
22
+ LiLT allows to combine any pre-trained RoBERTa text encoder with a lightweight Layout Transformer, to enable [LayoutLM](layoutlm)-like document understanding for many
23
+ languages.
24
+
25
+ The abstract from the paper is the following:
26
+
27
+ *Structured document understanding has attracted considerable attention and made significant progress recently, owing to its crucial role in intelligent document processing. However, most existing related models can only deal with the document data of specific language(s) (typically English) included in the pre-training collection, which is extremely limited. To address this issue, we propose a simple yet effective Language-independent Layout Transformer (LiLT) for structured document understanding. LiLT can be pre-trained on the structured documents of a single language and then directly fine-tuned on other languages with the corresponding off-the-shelf monolingual/multilingual pre-trained textual models. Experimental results on eight languages have shown that LiLT can achieve competitive or even superior performance on diverse widely-used downstream benchmarks, which enables language-independent benefit from the pre-training of document layout structure.*
28
+
29
+ <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/lilt_architecture.jpg"
30
+ alt="drawing" width="600"/>
31
+
32
+ <small> LiLT architecture. Taken from the <a href="https://arxiv.org/abs/2202.13669">original paper</a>. </small>
33
+
34
+ This model was contributed by [nielsr](https://huggingface.co/nielsr).
35
+ The original code can be found [here](https://github.com/jpwang/lilt).
36
+
37
+ ## Usage tips
38
+
39
+ - To combine the Language-Independent Layout Transformer with a new RoBERTa checkpoint from the [hub](https://huggingface.co/models?search=roberta), refer to [this guide](https://github.com/jpWang/LiLT#or-generate-your-own-checkpoint-optional).
40
+ The script will result in `config.json` and `pytorch_model.bin` files being stored locally. After doing this, one can do the following (assuming you're logged in with your HuggingFace account):
41
+
42
+ ```python
43
+ from transformers import LiltModel
44
+
45
+ model = LiltModel.from_pretrained("path_to_your_files")
46
+ model.push_to_hub("name_of_repo_on_the_hub")
47
+ ```
48
+
49
+ - When preparing data for the model, make sure to use the token vocabulary that corresponds to the RoBERTa checkpoint you combined with the Layout Transformer.
50
+ - As [lilt-roberta-en-base](https://huggingface.co/SCUT-DLVCLab/lilt-roberta-en-base) uses the same vocabulary as [LayoutLMv3](layoutlmv3), one can use [`LayoutLMv3TokenizerFast`] to prepare data for the model.
51
+ The same is true for [lilt-roberta-en-base](https://huggingface.co/SCUT-DLVCLab/lilt-infoxlm-base): one can use [`LayoutXLMTokenizerFast`] for that model.
52
+
53
+ ## Resources
54
+
55
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LiLT.
56
+
57
+ - Demo notebooks for LiLT can be found [here](https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LiLT).
58
+
59
+ **Documentation resources**
60
+ - [Text classification task guide](../tasks/sequence_classification)
61
+ - [Token classification task guide](../tasks/token_classification)
62
+ - [Question answering task guide](../tasks/question_answering)
63
+
64
+ 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.
65
+
66
+ ## LiltConfig
67
+
68
+ [[autodoc]] LiltConfig
69
+
70
+ ## LiltModel
71
+
72
+ [[autodoc]] LiltModel
73
+ - forward
74
+
75
+ ## LiltForSequenceClassification
76
+
77
+ [[autodoc]] LiltForSequenceClassification
78
+ - forward
79
+
80
+ ## LiltForTokenClassification
81
+
82
+ [[autodoc]] LiltForTokenClassification
83
+ - forward
84
+
85
+ ## LiltForQuestionAnswering
86
+
87
+ [[autodoc]] LiltForQuestionAnswering
88
+ - forward
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # LLaMA
18
+
19
+ ## Overview
20
+
21
+ The LLaMA model was proposed in [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971) by Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample. It is a collection of foundation language models ranging from 7B to 65B parameters.
22
+
23
+ The abstract from the paper is the following:
24
+
25
+ *We introduce LLaMA, a collection of foundation language models ranging from 7B to 65B parameters. We train our models on trillions of tokens, and show that it is possible to train state-of-the-art models using publicly available datasets exclusively, without resorting to proprietary and inaccessible datasets. In particular, LLaMA-13B outperforms GPT-3 (175B) on most benchmarks, and LLaMA-65B is competitive with the best models, Chinchilla-70B and PaLM-540B. We release all our models to the research community. *
26
+
27
+ This model was contributed by [zphang](https://huggingface.co/zphang) with contributions from [BlackSamorez](https://huggingface.co/BlackSamorez). The code of the implementation in Hugging Face is based on GPT-NeoX [here](https://github.com/EleutherAI/gpt-neox). The original code of the authors can be found [here](https://github.com/facebookresearch/llama).
28
+
29
+ ## Usage tips
30
+
31
+ - Weights for the LLaMA models can be obtained from by filling out [this form](https://docs.google.com/forms/d/e/1FAIpQLSfqNECQnMkycAp2jP4Z9TFX0cGR4uf7b_fBxjY_OjhJILlKGA/viewform?usp=send_form)
32
+ - After downloading the weights, they will need to be converted to the Hugging Face Transformers format using the [conversion script](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py). The script can be called with the following (example) command:
33
+
34
+ ```bash
35
+ python src/transformers/models/llama/convert_llama_weights_to_hf.py \
36
+ --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path
37
+ ```
38
+
39
+ - After conversion, the model and tokenizer can be loaded via:
40
+
41
+ ```python
42
+ from transformers import LlamaForCausalLM, LlamaTokenizer
43
+
44
+ tokenizer = LlamaTokenizer.from_pretrained("/output/path")
45
+ model = LlamaForCausalLM.from_pretrained("/output/path")
46
+ ```
47
+
48
+ Note that executing the script requires enough CPU RAM to host the whole model in float16 precision (even if the biggest versions
49
+ come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM). For the 65B model, it's thus 130GB of RAM needed.
50
+
51
+ - The LLaMA tokenizer is a BPE model based on [sentencepiece](https://github.com/google/sentencepiece). One quirk of sentencepiece is that when decoding a sequence, if the first token is the start of the word (e.g. "Banana"), the tokenizer does not prepend the prefix space to the string.
52
+
53
+ This model was contributed by [zphang](https://huggingface.co/zphang) with contributions from [BlackSamorez](https://huggingface.co/BlackSamorez). The code of the implementation in Hugging Face is based on GPT-NeoX [here](https://github.com/EleutherAI/gpt-neox). The original code of the authors can be found [here](https://github.com/facebookresearch/llama). The Flax version of the implementation was contributed by [afmck](https://huggingface.co/afmck) with the code in the implementation based on Hugging Face's Flax GPT-Neo.
54
+
55
+
56
+ Based on the original LLaMA model, Meta AI has released some follow-up works:
57
+
58
+ - **Llama2**: Llama2 is an improved version of Llama with some architectural tweaks (Grouped Query Attention), and is pre-trained on 2Trillion tokens. Refer to the documentation of Llama2 which can be found [here](llama2).
59
+
60
+ ## Resources
61
+
62
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LLaMA. 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.
63
+
64
+ <PipelineTag pipeline="text-classification"/>
65
+
66
+ - A [notebook](https://colab.research.google.com/github/bigscience-workshop/petals/blob/main/examples/prompt-tuning-sst2.ipynb#scrollTo=f04ba4d2) on how to use prompt tuning to adapt the LLaMA model for text classification task. 🌎
67
+
68
+ <PipelineTag pipeline="question-answering"/>
69
+
70
+ - [StackLLaMA: A hands-on guide to train LLaMA with RLHF](https://huggingface.co/blog/stackllama#stackllama-a-hands-on-guide-to-train-llama-with-rlhf), a blog post about how to train LLaMA to answer questions on [Stack Exchange](https://stackexchange.com/) with RLHF.
71
+
72
+ ⚗️ Optimization
73
+ - A [notebook](https://colab.research.google.com/drive/1SQUXq1AMZPSLD4mk3A3swUIc6Y2dclme?usp=sharing) on how to fine-tune LLaMA model using xturing library on GPU which has limited memory. 🌎
74
+
75
+ ⚡️ Inference
76
+ - A [notebook](https://colab.research.google.com/github/DominguesM/alpaca-lora-ptbr-7b/blob/main/notebooks/02%20-%20Evaluate.ipynb) on how to run the LLaMA Model using PeftModel from the 🤗 PEFT library. 🌎
77
+ - A [notebook](https://colab.research.google.com/drive/1l2GiSSPbajVyp2Nk3CFT4t3uH6-5TiBe?usp=sharing) on how to load a PEFT adapter LLaMA model with LangChain. 🌎
78
+
79
+ 🚀 Deploy
80
+ - A [notebook](https://colab.research.google.com/github/lxe/simple-llama-finetuner/blob/master/Simple_LLaMA_FineTuner.ipynb#scrollTo=3PM_DilAZD8T) on how to fine-tune LLaMA model using LoRA method via the 🤗 PEFT library with intuitive UI. 🌎
81
+ - A [notebook](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart-foundation-models/text-generation-open-llama.ipynb) on how to deploy Open-LLaMA model for text generation on Amazon SageMaker. 🌎
82
+
83
+ ## LlamaConfig
84
+
85
+ [[autodoc]] LlamaConfig
86
+
87
+ ## LlamaTokenizer
88
+
89
+ [[autodoc]] LlamaTokenizer
90
+ - build_inputs_with_special_tokens
91
+ - get_special_tokens_mask
92
+ - create_token_type_ids_from_sequences
93
+ - save_vocabulary
94
+
95
+ ## LlamaTokenizerFast
96
+
97
+ [[autodoc]] LlamaTokenizerFast
98
+ - build_inputs_with_special_tokens
99
+ - get_special_tokens_mask
100
+ - create_token_type_ids_from_sequences
101
+ - update_post_processor
102
+ - save_vocabulary
103
+
104
+ ## LlamaModel
105
+
106
+ [[autodoc]] LlamaModel
107
+ - forward
108
+
109
+ ## LlamaForCausalLM
110
+
111
+ [[autodoc]] LlamaForCausalLM
112
+ - forward
113
+
114
+ ## LlamaForSequenceClassification
115
+
116
+ [[autodoc]] LlamaForSequenceClassification
117
+ - forward
118
+
119
+ ## LlamaForQuestionAnswering
120
+
121
+ [[autodoc]] LlamaForQuestionAnswering
122
+ - forward
123
+
124
+ ## LlamaForTokenClassification
125
+
126
+ [[autodoc]] LlamaForTokenClassification
127
+ - forward
128
+
129
+ ## FlaxLlamaModel
130
+
131
+ [[autodoc]] FlaxLlamaModel
132
+ - __call__
133
+
134
+ ## FlaxLlamaForCausalLM
135
+
136
+ [[autodoc]] FlaxLlamaForCausalLM
137
+ - __call__
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama2.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 contains specific syntax for our doc-builder (similar to MDX) that may not be
13
+ rendered properly in your Markdown viewer.
14
+
15
+ -->
16
+
17
+ # Llama2
18
+
19
+ ## Overview
20
+
21
+ The Llama2 model was proposed in [LLaMA: Open Foundation and Fine-Tuned Chat Models](https://ai.meta.com/research/publications/llama-2-open-foundation-and-fine-tuned-chat-models/) by Hugo Touvron, Louis Martin, Kevin Stone, Peter Albert, Amjad Almahairi, Yasmine Babaei, Nikolay Bashlykov, Soumya Batra, Prajjwal Bhargava, Shruti Bhosale, Dan Bikel, Lukas Blecher, Cristian Canton Ferrer, Moya Chen, Guillem Cucurull, David Esiobu, Jude Fernandes, Jeremy Fu, Wenyin Fu, Brian Fuller, Cynthia Gao, Vedanuj Goswami, Naman Goyal, Anthony Hartshorn, Saghar Hosseini, Rui Hou, Hakan Inan, Marcin Kardas, Viktor Kerkez Madian Khabsa, Isabel Kloumann, Artem Korenev, Punit Singh Koura, Marie-Anne Lachaux, Thibaut Lavril, Jenya Lee, Diana Liskovich, Yinghai Lu, Yuning Mao, Xavier Martinet, Todor Mihaylov, Pushka rMishra, Igor Molybog, Yixin Nie, Andrew Poulton, Jeremy Reizenstein, Rashi Rungta, Kalyan Saladi, Alan Schelten, Ruan Silva, Eric Michael Smith, Ranjan Subramanian, Xiaoqing EllenTan, Binh Tang, Ross Taylor, Adina Williams, Jian Xiang Kuan, Puxin Xu, Zheng Yan, Iliyan Zarov, Yuchen Zhang, Angela Fan, Melanie Kambadur, Sharan Narang, Aurelien Rodriguez, Robert Stojnic, Sergey Edunov, Thomas Scialom. It is a collection of foundation language models ranging from 7B to 70B parameters, with checkpoints finetuned for chat application!
22
+
23
+ The abstract from the paper is the following:
24
+
25
+ *In this work, we develop and release Llama 2, a collection of pretrained and fine-tuned large language models (LLMs) ranging in scale from 7 billion to 70 billion parameters. Our fine-tuned LLMs, called Llama 2-Chat, are optimized for dialogue use cases. Our models outperform open-source chat models on most benchmarks we tested, and based on our human evaluations for helpfulness and safety, may be a suitable substitute for closed-source models. We provide a detailed description of our approach to fine-tuning and safety improvements of Llama 2-Chat in order to enable the community to build on our work and contribute to the responsible development of LLMs.*
26
+
27
+ Checkout all Llama2 model checkpoints [here](https://huggingface.co/models?search=llama2).
28
+ This model was contributed by [Arthur Zucker](https://huggingface.co/ArthurZ) with contributions from [Lysandre Debut](https://huggingface.co/lysandre). The code of the implementation in Hugging Face is based on GPT-NeoX [here](https://github.com/EleutherAI/gpt-neox). The original code of the authors can be found [here](https://github.com/facebookresearch/llama).
29
+
30
+ ## Usage tips
31
+
32
+ <Tip warning={true}>
33
+
34
+ The `Llama2` models were trained using `bfloat16`, but the original inference uses `float16`. The checkpoints uploaded on the Hub use `torch_dtype = 'float16'`, which will be
35
+ used by the `AutoModel` API to cast the checkpoints from `torch.float32` to `torch.float16`.
36
+
37
+ The `dtype` of the online weights is mostly irrelevant unless you are using `torch_dtype="auto"` when initializing a model using `model = AutoModelForCausalLM.from_pretrained("path", torch_dtype = "auto")`. The reason is that the model will first be downloaded ( using the `dtype` of the checkpoints online), then it will be casted to the default `dtype` of `torch` (becomes `torch.float32`), and finally, if there is a `torch_dtype` provided in the config, it will be used.
38
+
39
+ Training the model in `float16` is not recommended and is known to produce `nan`; as such, the model should be trained in `bfloat16`.
40
+
41
+ </Tip>
42
+
43
+ Tips:
44
+
45
+ - Weights for the Llama2 models can be obtained by filling out [this form](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
46
+ - The architecture is very similar to the first Llama, with the addition of Grouped Query Attention (GQA) following this [paper](https://arxiv.org/pdf/2305.13245.pdf)
47
+ - Setting `config.pretraining_tp` to a value different than 1 will activate the more accurate but slower computation of the linear layers, which should better match the original logits.
48
+ - The original model uses `pad_id = -1` which means that there is no padding token. We can't have the same logic, make sure to add a padding token using `tokenizer.add_special_tokens({"pad_token":"<pad>"})` and resize the token embedding accordingly. You should also set the `model.config.pad_token_id`. The `embed_tokens` layer of the model is initialized with `self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.config.padding_idx)`, which makes sure that encoding the padding token will output zeros, so passing it when initializing is recommended.
49
+ - After filling out the form and gaining access to the model checkpoints, you should be able to use the already converted checkpoints. Otherwise, if you are converting your own model, feel free to use the [conversion script](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py). The script can be called with the following (example) command:
50
+
51
+ ```bash
52
+ python src/transformers/models/llama/convert_llama_weights_to_hf.py \
53
+ --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path
54
+ ```
55
+
56
+ - After conversion, the model and tokenizer can be loaded via:
57
+
58
+ ```python
59
+ from transformers import LlamaForCausalLM, LlamaTokenizer
60
+
61
+ tokenizer = LlamaTokenizer.from_pretrained("/output/path")
62
+ model = LlamaForCausalLM.from_pretrained("/output/path")
63
+ ```
64
+
65
+ Note that executing the script requires enough CPU RAM to host the whole model in float16 precision (even if the biggest versions
66
+ come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM). For the 75B model, it's thus 145GB of RAM needed.
67
+
68
+ - The LLaMA tokenizer is a BPE model based on [sentencepiece](https://github.com/google/sentencepiece). One quirk of sentencepiece is that when decoding a sequence, if the first token is the start of the word (e.g. "Banana"), the tokenizer does not prepend the prefix space to the string.
69
+
70
+ - When using Flash Attention 2 via `attn_implementation="flash_attention_2"`, don't pass `torch_dtype` to the `from_pretrained` class method and use Automatic Mixed-Precision training. When using `Trainer`, it is simply specifying either `fp16` or `bf16` to `True`. Otherwise, make sure you are using `torch.autocast`. This is required because the Flash Attention only support `fp16` and `bf16` data type.
71
+
72
+
73
+ ## Resources
74
+
75
+ A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with LLaMA2. 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.
76
+
77
+ - [Llama 2 is here - get it on Hugging Face](https://huggingface.co/blog/llama2), a blog post about Llama 2 and how to use it with 🤗 Transformers and 🤗 PEFT.
78
+ - [LLaMA 2 - Every Resource you need](https://www.philschmid.de/llama-2), a compilation of relevant resources to learn about LLaMA 2 and how to get started quickly.
79
+
80
+ <PipelineTag pipeline="text-generation"/>
81
+
82
+ - A [notebook](https://colab.research.google.com/drive/1PEQyJO1-f6j0S_XJ8DV50NkpzasXkrzd?usp=sharing) on how to fine-tune Llama 2 in Google Colab using QLoRA and 4-bit precision. 🌎
83
+ - A [notebook](https://colab.research.google.com/drive/134o_cXcMe_lsvl15ZE_4Y75Kstepsntu?usp=sharing) on how to fine-tune the "Llama-v2-7b-guanaco" model with 4-bit QLoRA and generate Q&A datasets from PDFs. 🌎
84
+
85
+ <PipelineTag pipeline="text-classification"/>
86
+
87
+ - A [notebook](https://colab.research.google.com/drive/1ggaa2oRFphdBmqIjSEbnb_HGkcIRC2ZB?usp=sharing) on how to fine-tune the Llama 2 model with QLoRa, TRL, and Korean text classification dataset. 🌎🇰🇷
88
+
89
+ ⚗️ Optimization
90
+ - [Fine-tune Llama 2 with DPO](https://huggingface.co/blog/dpo-trl), a guide to using the TRL library's DPO method to fine tune Llama 2 on a specific dataset.
91
+ - [Extended Guide: Instruction-tune Llama 2](https://www.philschmid.de/instruction-tune-llama-2), a guide to training Llama 2 to generate instructions from inputs, transforming the model from instruction-following to instruction-giving.
92
+ - A [notebook](https://colab.research.google.com/drive/1SYpgFpcmtIUzdE7pxqknrM4ArCASfkFQ?usp=sharing) on how to fine-tune the Llama 2 model on a personal computer using QLoRa and TRL. 🌎
93
+
94
+ ⚡️ Inference
95
+ - A [notebook](https://colab.research.google.com/drive/1TC56ArKerXUpbgRy5vM3woRsbTEVNq7h?usp=sharing) on how to quantize the Llama 2 model using GPTQ from the AutoGPTQ library. 🌎
96
+ - A [notebook](https://colab.research.google.com/drive/1X1z9Q6domMKl2CnEM0QGHNwidLfR4dW2?usp=sharing) on how to run the Llama 2 Chat Model with 4-bit quantization on a local computer or Google Colab. 🌎
97
+
98
+ 🚀 Deploy
99
+ - [Fine-tune LLaMA 2 (7-70B) on Amazon SageMaker](https://www.philschmid.de/sagemaker-llama2-qlora), a complete guide from setup to QLoRA fine-tuning and deployment on Amazon SageMaker.
100
+ - [Deploy Llama 2 7B/13B/70B on Amazon SageMaker](https://www.philschmid.de/sagemaker-llama-llm), a guide on using Hugging Face's LLM DLC container for secure and scalable deployment.
101
+
102
+
103
+ ## LlamaConfig
104
+
105
+ [[autodoc]] LlamaConfig
106
+
107
+
108
+ ## LlamaTokenizer
109
+
110
+ [[autodoc]] LlamaTokenizer
111
+ - build_inputs_with_special_tokens
112
+ - get_special_tokens_mask
113
+ - create_token_type_ids_from_sequences
114
+ - save_vocabulary
115
+
116
+ ## LlamaTokenizerFast
117
+
118
+ [[autodoc]] LlamaTokenizerFast
119
+ - build_inputs_with_special_tokens
120
+ - get_special_tokens_mask
121
+ - create_token_type_ids_from_sequences
122
+ - update_post_processor
123
+ - save_vocabulary
124
+
125
+ ## LlamaModel
126
+
127
+ [[autodoc]] LlamaModel
128
+ - forward
129
+
130
+
131
+ ## LlamaForCausalLM
132
+
133
+ [[autodoc]] LlamaForCausalLM
134
+ - forward
135
+
136
+ ## LlamaForSequenceClassification
137
+
138
+ [[autodoc]] LlamaForSequenceClassification
139
+ - forward
140
+
tasks/tasksmith-5dd11b34cce1/tests/source/docs/source/en/model_doc/llama3.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ # Llama3
18
+
19
+ ```py3
20
+ import transformers
21
+ import torch
22
+
23
+ model_id = "meta-llama/Meta-Llama-3-8B"
24
+
25
+ pipeline = transformers.pipeline("text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto")
26
+ pipeline("Hey how are you doing today?")
27
+ ```
28
+
29
+ ## Overview
30
+
31
+ The Llama3 model was proposed in [Introducing Meta Llama 3: The most capable openly available LLM to date](https://ai.meta.com/blog/meta-llama-3/) by the meta AI team.
32
+
33
+ The abstract from the blogpost is the following:
34
+
35
+ *Today, we’re excited to share the first two models of the next generation of Llama, Meta Llama 3, available for broad use. This release features pretrained and instruction-fine-tuned language models with 8B and 70B parameters that can support a broad range of use cases. This next generation of Llama demonstrates state-of-the-art performance on a wide range of industry benchmarks and offers new capabilities, including improved reasoning. We believe these are the best open source models of their class, period. In support of our longstanding open approach, we’re putting Llama 3 in the hands of the community. We want to kickstart the next wave of innovation in AI across the stack—from applications to developer tools to evals to inference optimizations and more. We can’t wait to see what you build and look forward to your feedback.*
36
+
37
+ Checkout all Llama3 model checkpoints [here](https://huggingface.co/models?search=llama3).
38
+ The original code of the authors can be found [here](https://github.com/meta-llama/llama3).
39
+
40
+ ## Usage tips
41
+
42
+ <Tip warning={true}>
43
+
44
+ The `Llama3` models were trained using `bfloat16`, but the original inference uses `float16`. The checkpoints uploaded on the Hub use `torch_dtype = 'float16'`, which will be
45
+ used by the `AutoModel` API to cast the checkpoints from `torch.float32` to `torch.float16`.
46
+
47
+ The `dtype` of the online weights is mostly irrelevant unless you are using `torch_dtype="auto"` when initializing a model using `model = AutoModelForCausalLM.from_pretrained("path", torch_dtype = "auto")`. The reason is that the model will first be downloaded ( using the `dtype` of the checkpoints online), then it will be casted to the default `dtype` of `torch` (becomes `torch.float32`), and finally, if there is a `torch_dtype` provided in the config, it will be used.
48
+
49
+ Training the model in `float16` is not recommended and is known to produce `nan`; as such, the model should be trained in `bfloat16`.
50
+
51
+ </Tip>
52
+
53
+ Tips:
54
+
55
+ - Weights for the Llama3 models can be obtained by filling out [this form](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
56
+ - The architecture is exactly the same as Llama2.
57
+ - The tokenizer is a BPE model based on [tiktoken](https://github.com/openai/tiktoken) (vs the one based on sentencepiece implementation for Llama2). The main difference that it ignores BPE merge rules when an input token is part of the vocab. This means that if no merge exist to produce `"hugging"`, instead of having the smallest units, like `["hug","ging"] form 2 tokens, if `"hugging"` is part of the vocab, it will be automatically returned as a token.
58
+ - The original model uses `pad_id = -1` which means that there is no padding token. We can't have the same logic, make sure to add a padding token using `tokenizer.add_special_tokens({"pad_token":"<pad>"})` and resize the token embedding accordingly. You should also set the `model.config.pad_token_id`. The `embed_tokens` layer of the model is initialized with `self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.config.padding_idx)`, which makes sure that encoding the padding token will output zeros, so passing it when initializing is recommended.
59
+ - The original checkpoint can be converted using the [conversion script](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py). The script can be called with the following (example) command:
60
+
61
+ ```bash
62
+ python src/transformers/models/llama/convert_llama_weights_to_hf.py \
63
+ --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path --llama_version 3
64
+ ```
65
+
66
+ - After conversion, the model and tokenizer can be loaded via:
67
+
68
+ ```python
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer
70
+
71
+ tokenizer = AutoTokenizer.from_pretrained("/output/path")
72
+ model = AutoModelForCausalLM.from_pretrained("/output/path")
73
+ ```
74
+
75
+ Note that executing the script requires enough CPU RAM to host the whole model in float16 precision (even if the biggest versions
76
+ come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM). For the 75B model, it's thus 145GB of RAM needed.
77
+
78
+ - When using Flash Attention 2 via `attn_implementation="flash_attention_2"`, don't pass `torch_dtype` to the `from_pretrained` class method and use Automatic Mixed-Precision training. When using `Trainer`, it is simply specifying either `fp16` or `bf16` to `True`. Otherwise, make sure you are using `torch.autocast`. This is required because the Flash Attention only support `fp16` and `bf16` data type.
79
+
80
+ ## Resources
81
+
82
+ A ton of cool resources are already available on the documentation page of [Llama2](./llama2), inviting contributors to add new resources curated for Llama3 here! 🤗