Implement Roberta PreLayerNorm (#20305)
* Copy RoBERTa * formatting * implement RoBERTa with prelayer normalization * update test expectations * add documentation * add convertion script for DinkyTrain weights * update checkpoint repo Unfortunately the original checkpoints assumes a hacked roberta model * add to RoBERTa-PreLayerNorm docs to toc * run utils/check_copies.py * lint files * remove unused import * fix check_repo reporting wrongly a test is missing * fix import error, caused by rebase * run make fix-copies * add RobertaPreLayerNormConfig to ROBERTA_EMBEDDING_ADJUSMENT_CONFIGS * Fix documentation <Facebook> -> Facebook Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * fixup: Fix documentation <Facebook> -> Facebook Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Add missing Flax header Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * expected_slice -> EXPECTED_SLICE Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * update copies after rebase * add missing copied from statements * make fix-copies * make prelayernorm explicit in code * fix checkpoint path for the original implementation * add flax integration tests * improve docs * update utils/documentation_tests.txt * lint files * Remove Copyright notice Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * make fix-copies * Remove EXPECTED_SLICE calculation comments Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
This commit is contained in:
@@ -349,6 +349,8 @@
|
||||
title: RetriBERT
|
||||
- local: model_doc/roberta
|
||||
title: RoBERTa
|
||||
- local: model_doc/roberta-prelayernorm
|
||||
title: RoBERTa-PreLayerNorm
|
||||
- local: model_doc/roc_bert
|
||||
title: RoCBert
|
||||
- local: model_doc/roformer
|
||||
|
||||
@@ -164,6 +164,7 @@ The documentation is organized into five sections:
|
||||
1. **[RemBERT](model_doc/rembert)** (from Google Research) released with the paper [Rethinking embedding coupling in pre-trained language models](https://arxiv.org/abs/2010.12821) by Hyung Won Chung, Thibault Févry, Henry Tsai, M. Johnson, Sebastian Ruder.
|
||||
1. **[ResNet](model_doc/resnet)** (from Microsoft Research) released with the paper [Deep Residual Learning for Image Recognition](https://arxiv.org/abs/1512.03385) by Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun.
|
||||
1. **[RoBERTa](model_doc/roberta)** (from Facebook), released together with the paper [RoBERTa: A Robustly Optimized BERT Pretraining Approach](https://arxiv.org/abs/1907.11692) by Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, Veselin Stoyanov.
|
||||
1. **[RoBERTa-PreLayerNorm](model_doc/roberta-prelayernorm)** (from Facebook) released with the paper [fairseq: A Fast, Extensible Toolkit for Sequence Modeling](https://arxiv.org/abs/1904.01038) by Myle Ott, Sergey Edunov, Alexei Baevski, Angela Fan, Sam Gross, Nathan Ng, David Grangier, Michael Auli.
|
||||
1. **[RoCBert](model_doc/roc_bert)** (from WeChatAI) released with the paper [RoCBert: Robust Chinese Bert with Multimodal Contrastive Pretraining](https://aclanthology.org/2022.acl-long.65.pdf) by HuiSu, WeiweiShi, XiaoyuShen, XiaoZhou, TuoJi, JiaruiFang, JieZhou.
|
||||
1. **[RoFormer](model_doc/roformer)** (from ZhuiyiTechnology), released together with the paper [RoFormer: Enhanced Transformer with Rotary Position Embedding](https://arxiv.org/abs/2104.09864) by Jianlin Su and Yu Lu and Shengfeng Pan and Bo Wen and Yunfeng Liu.
|
||||
1. **[SegFormer](model_doc/segformer)** (from NVIDIA) released with the paper [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers](https://arxiv.org/abs/2105.15203) by Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, Jose M. Alvarez, Ping Luo.
|
||||
@@ -331,6 +332,7 @@ Flax), PyTorch, and/or TensorFlow.
|
||||
| ResNet | ❌ | ❌ | ✅ | ✅ | ❌ |
|
||||
| RetriBERT | ✅ | ✅ | ✅ | ❌ | ❌ |
|
||||
| RoBERTa | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| RoBERTa-PreLayerNorm | ❌ | ❌ | ✅ | ✅ | ✅ |
|
||||
| RoCBert | ✅ | ❌ | ✅ | ❌ | ❌ |
|
||||
| RoFormer | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| SegFormer | ❌ | ❌ | ✅ | ✅ | ❌ |
|
||||
|
||||
140
docs/source/en/model_doc/roberta-prelayernorm.mdx
Normal file
140
docs/source/en/model_doc/roberta-prelayernorm.mdx
Normal file
@@ -0,0 +1,140 @@
|
||||
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations under the License.
|
||||
-->
|
||||
|
||||
# RoBERTa-PreLayerNorm
|
||||
|
||||
## Overview
|
||||
|
||||
The RoBERTa-PreLayerNorm model was proposed in [fairseq: A Fast, Extensible Toolkit for Sequence Modeling](https://arxiv.org/abs/1904.01038) by Myle Ott, Sergey Edunov, Alexei Baevski, Angela Fan, Sam Gross, Nathan Ng, David Grangier, Michael Auli.
|
||||
It is identical to using the `--encoder-normalize-before` flag in [fairseq](https://fairseq.readthedocs.io/).
|
||||
|
||||
The abstract from the paper is the following:
|
||||
|
||||
*fairseq is an open-source sequence modeling toolkit that allows researchers and developers to train custom models for translation, summarization, language modeling, and other text generation tasks. The toolkit is based on PyTorch and supports distributed training across multiple GPUs and machines. We also support fast mixed-precision training and inference on modern GPUs.*
|
||||
|
||||
Tips:
|
||||
|
||||
- The implementation is the same as [Roberta](roberta) except instead of using _Add and Norm_ it does _Norm and Add_. _Add_ and _Norm_ refers to the Addition and LayerNormalization as described in [Attention Is All You Need](https://arxiv.org/abs/1706.03762).
|
||||
- This is identical to using the `--encoder-normalize-before` flag in [fairseq](https://fairseq.readthedocs.io/).
|
||||
|
||||
This model was contributed by [andreasmaden](https://huggingface.co/andreasmaden).
|
||||
The original code can be found [here](https://github.com/princeton-nlp/DinkyTrain).
|
||||
|
||||
|
||||
## RobertaPreLayerNormConfig
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormConfig
|
||||
|
||||
## RobertaPreLayerNormModel
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormModel
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForCausalLM
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForCausalLM
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForMaskedLM
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForMaskedLM
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForSequenceClassification
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForSequenceClassification
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForMultipleChoice
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForMultipleChoice
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForTokenClassification
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForTokenClassification
|
||||
- forward
|
||||
|
||||
## RobertaPreLayerNormForQuestionAnswering
|
||||
|
||||
[[autodoc]] RobertaPreLayerNormForQuestionAnswering
|
||||
- forward
|
||||
|
||||
## TFRobertaPreLayerNormModel
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormModel
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForCausalLM
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForCausalLM
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForMaskedLM
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForMaskedLM
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForSequenceClassification
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForSequenceClassification
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForMultipleChoice
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForMultipleChoice
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForTokenClassification
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForTokenClassification
|
||||
- call
|
||||
|
||||
## TFRobertaPreLayerNormForQuestionAnswering
|
||||
|
||||
[[autodoc]] TFRobertaPreLayerNormForQuestionAnswering
|
||||
- call
|
||||
|
||||
## FlaxRobertaPreLayerNormModel
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormModel
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForCausalLM
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForCausalLM
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForMaskedLM
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForMaskedLM
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForSequenceClassification
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForSequenceClassification
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForMultipleChoice
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForMultipleChoice
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForTokenClassification
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForTokenClassification
|
||||
- __call__
|
||||
|
||||
## FlaxRobertaPreLayerNormForQuestionAnswering
|
||||
|
||||
[[autodoc]] FlaxRobertaPreLayerNormForQuestionAnswering
|
||||
- __call__
|
||||
@@ -105,6 +105,7 @@ Ready-made configurations include the following architectures:
|
||||
- RemBERT
|
||||
- ResNet
|
||||
- RoBERTa
|
||||
- RoBERTa-PreLayerNorm
|
||||
- RoFormer
|
||||
- SegFormer
|
||||
- SqueezeBERT
|
||||
|
||||
Reference in New Issue
Block a user