Spaces:
Paused
Paused
File size: 12,905 Bytes
ee6e328 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
<!---
Copyright 2020 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.
β οΈ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# Pull Requestμ λν κ²μ¬ [[checks-on-a-pull-request]]
π€ Transformersμμ Pull Requestλ₯Ό μ΄ λ, κΈ°μ‘΄μ μλ κ²μ λ§κ°λ¨λ¦¬μ§ μλμ§ νμΈνκΈ° μν΄ μλΉν μμ κ²μ¬κ° μ€νλ©λλ€. μ΄λ¬ν κ²μ¬λ λ€μκ³Ό κ°μ λ€ κ°μ§ μ νμΌλ‘ ꡬμ±λ©λλ€:
- μΌλ°μ μΈ ν
μ€νΈ
- λ¬Έμ λΉλ
- μ½λ λ° λ¬Έμ μ€νμΌ
- μΌλ° μ μ₯μ μΌκ΄μ±
μ΄ λ¬Έμμμλ μ΄λ¬ν λ€μν κ²μ¬μ κ·Έ μ΄μ λ₯Ό μ€λͺ
νκ³ , PRμμ νλ μ΄μμ κ²μ¬κ° μ€ν¨ν κ²½μ° λ‘컬μμ μ΄λ»κ² λλ²κ·Ένλμ§ μμλ³΄κ² μ΅λλ€.
μ°Έκ³ λ‘, μ΄λ¬ν κ²μ¬λ₯Ό μ¬μ©νλ €λ©΄ κ°λ° μ€μΉκ° νμν©λλ€:
```bash
pip install transformers[dev]
```
λλ Transformers μ μ₯μ λ΄μ νΈμ§ κ°λ₯ν μ€μΉκ° νμν©λλ€:
```bash
pip install -e .[dev]
```
Transformersμ μ νμ μ’
μμ± μκ° λ§μ΄ λμ΄λ¬κΈ° λλ¬Έμ κ°λ° μ€μΉλ₯Ό μ€ν¨ν μλ μμ΅λλ€. κ°λ° μ€μΉκ° μ€ν¨νλ κ²½μ°, μμ
μ€μΈ Deep Learning νλ μμν¬ (PyTorch, TensorFlow λ°/λλ Flax)λ₯Ό μ€μΉνκ³ λ€μ λͺ
λ Ήμ μ€ννμΈμ.
```bash
pip install transformers[quality]
```
νΈμ§ κ°λ₯ν μ€μΉμ κ²½μ°λ λ€μ λͺ
λ Ήμ μ€ννμΈμ.
```bash
pip install -e .[quality]
```
## ν
μ€νΈ [[tests]]
`ci/circleci: run_tests_`λ‘ μμνλ λͺ¨λ μμ
μ Transformers ν
μ€νΈ λͺ¨μμ μΌλΆλ₯Ό μ€νν©λλ€. μ΄λ¬ν μμ
μ νΉμ νκ²½μμ μΌλΆ λΌμ΄λΈλ¬λ¦¬μ μ€μ μ λ‘λλ€. μλ₯Ό λ€μ΄ `ci/circleci: run_tests_pipelines_tf`λ TensorFlowλ§ μ€μΉλ νκ²½μμ νμ΄νλΌμΈ ν
μ€νΈλ₯Ό μ€νν©λλ€.
ν
μ€νΈ λͺ¨λμμ μ€μ λ‘ λ³κ²½ μ¬νμ΄ μμ λ ν
μ€νΈλ₯Ό μ€ννμ§ μκΈ° μν΄, ν
μ€νΈ λͺ¨μμ μΌλΆλ§ μ€νλ©λλ€. λΌμ΄λΈλ¬λ¦¬μ λ³κ²½ μ νμ λν μ°¨μ΄λ₯Ό νμΈνκΈ° μν΄ μ νΈλ¦¬ν°κ° μ€νλκ³ , ν΄λΉ μ°¨μ΄μ μν₯μ λ°λ ν
μ€νΈκ° μ νλ©λλ€. μ΄ μ νΈλ¦¬ν°λ λ‘컬μμ λ€μκ³Ό κ°μ΄ μ€νν μ μμ΅λλ€:
```bash
python utils/tests_fetcher.py
```
Transformers μ μ₯μμ μ΅μλ¨μμ μ€νν©λλ€. μ΄ μ νΈλ¦¬ν°λ λ€μκ³Ό κ°μ μμ
μ μνν©λλ€:
1. λ³κ²½ μ¬νμ΄ μλ νμΌλ§λ€ λ³κ²½ μ¬νμ΄ μ½λμΈμ§ μ£Όμ λλ λ¬Έμ λ¬Έμμ΄μΈμ§ νμΈν©λλ€. μ€μ μ½λ λ³κ²½μ΄ μλ νμΌλ§ μ μ§λ©λλ€.
2. μμ€ μ½λ νμΌμ κ° νμΌμ λν΄ μ¬κ·μ μΌλ‘ μν₯μ μ£Όλ λͺ¨λ νμΌμ μ 곡νλ λ΄λΆ λ§΅μ μμ±ν©λλ€. λͺ¨λ Bκ° λͺ¨λ Aλ₯Ό κ°μ Έμ€λ©΄ λͺ¨λ Aλ λͺ¨λ Bμ μν₯μ μ€λλ€. μ¬κ·μ μΈ μν₯μλ κ° λͺ¨λμ΄ μ΄μ λͺ¨λμ κ°μ Έμ€λ λͺ¨λ 체μΈμ΄ νμν©λλ€.
3. λ¨κ³ 1μμ μμ§ν νμΌμ μ΄ λ§΅μ μ μ©νμ¬ PRμ μν₯μ λ°λ λͺ¨λΈ νμΌ λͺ©λ‘μ μ»μ΅λλ€.
4. κ° νμΌμ ν΄λΉνλ ν
μ€νΈ νμΌμ λ§€ννκ³ μ€νν ν
μ€νΈ λͺ©λ‘μ κ°μ Έμ΅λλ€.
λ‘컬μμ μ€ν¬λ¦½νΈλ₯Ό μ€ννλ©΄ λ¨κ³ 1, 3 λ° 4μ κ²°κ³Όλ₯Ό μΆλ ₯νμ¬ μ€νλλ ν
μ€νΈλ₯Ό μ μ μμ΅λλ€. μ€ν¬λ¦½νΈλ λν `test_list.txt`λΌλ νμΌμ μμ±νμ¬ μ€νν ν
μ€νΈ λͺ©λ‘μ ν¬ν¨νλ©°, λ€μ λͺ
λ ΉμΌλ‘ ν΄λΉ ν
μ€νΈλ₯Ό λ‘컬μμ μ€νν μ μμ΅λλ€:
```bash
python -m pytest -n 8 --dist=loadfile -rA -s $(cat test_list.txt)
```
μλͺ»λ μ¬νμ΄ λλ½λμμ κ²½μ°, μ 체 ν
μ€νΈ λͺ¨μλ λ§€μΌ μ€νλ©λλ€.
## λ¬Έμ λΉλ [[documentation-build]]
`build_pr_documentation` μμ
μ λ¬Έμλ₯Ό λΉλνκ³ λ―Έλ¦¬ 보기λ₯Ό μμ±νμ¬ PRμ΄ λ³ν©λ ν λͺ¨λ κ²μ΄ μ λλ‘ λ³΄μ΄λμ§ νμΈν©λλ€. λ‘λ΄μ PRμ λ¬Έμ 미리보기 λ§ν¬λ₯Ό μΆκ°ν©λλ€. PRμμ λ§λ λ³κ²½ μ¬νμ μλμΌλ‘ 미리보기μ μ
λ°μ΄νΈλ©λλ€. λ¬Έμ λΉλμ μ€ν¨ν κ²½μ° **μΈλΆ μ 보**λ₯Ό ν΄λ¦νμ¬ μ΄λμμ λ¬Έμ κ° λ°μνλμ§ νμΈν μ μμ΅λλ€. μ€λ₯λ μ£Όλ‘ `toctree`μ λλ½λ νμΌκ³Ό κ°μ΄ κ°λ¨ν μ€λ₯μ
λλ€.
λ‘컬μμ λ¬Έμλ₯Ό λΉλνκ±°λ 미리 λ³Ό κ²½μ°, docs ν΄λμ [`README.md`](https://github.com/huggingface/transformers/tree/main/docs)λ₯Ό μ°Έμ‘°νμΈμ.
## μ½λ λ° λ¬Έμ μ€νμΌ [[code-and-documentation-style]]
`black`κ³Ό `ruff`λ₯Ό μ¬μ©νμ¬ λͺ¨λ μμ€ νμΌ, μμ λ° ν
μ€νΈμ μ½λ νμμ μ μ©ν©λλ€. λν, `utils/style_doc.py`μμ λ¬Έμ λ¬Έμμ΄κ³Ό `rst` νμΌμ νμ, κ·Έλ¦¬κ³ Transformersμ `__init__.py` νμΌμμ μ€νλλ μ§μ°λ μν¬νΈμ μμμ λν μ¬μ©μ μ μ λκ΅¬κ° μμ΅λλ€. μ΄ λͺ¨λ κ²μ λ€μμ μ€νν¨μΌλ‘μ¨ μ€νν μ μμ΅λλ€:
```bash
make style
```
CIλ μ΄λ¬ν μ¬νμ΄ `ci/circleci: check_code_quality` κ²μ¬ λ΄μμ μ μ©λμλμ§ νμΈν©λλ€. λν `ruff`λ μ€νλλ©°, μ μλμ§ μμ λ³μλ μ¬μ©λμ§ μμ λ³μλ₯Ό λ°κ²¬νλ©΄ κ²½κ³ ν©λλ€. μ΄ κ²μ¬λ₯Ό λ‘컬μμ μ€ννλ €λ©΄ λ€μμ μ¬μ©νμΈμ:
```bash
make quality
```
μ΄ μμ
μ λ§μ μκ°μ΄ μμλ μ μμΌλ―λ‘ νμ¬ λΈλμΉμμ μμ ν νμΌμ λν΄μλ§ λμΌν μμ
μ μ€ννλ €λ©΄ λ€μμ μ€ννμΈμ.
```bash
make fixup
```
μ΄ λͺ
λ Ήμ νμ¬ λΈλμΉμμ μμ ν νμΌμ λν λͺ¨λ μΆκ°μ μΈ κ²μ¬λ μ€νν©λλ€. μ΄μ μ΄λ€μ μ΄ν΄λ³΄κ² μ΅λλ€.
## μ μ₯μ μΌκ΄μ± [[repository-consistency]]
μ΄λ PRμ΄ μ μ₯μλ₯Ό μ μμ μΈ μνλ‘ μ μ§νλμ§ νμΈνλ λͺ¨λ ν
μ€νΈλ₯Ό λͺ¨μ κ²μ΄λ©°, `ci/circleci: check_repository_consistency` κ²μ¬μμ μνλ©λλ€. λ€μμ μ€νν¨μΌλ‘μ¨ λ‘컬μμ μ΄ κ²μ¬λ₯Ό μ€νν μ μμ΅λλ€.
```bash
make repo-consistency
```
μ΄ κ²μ¬λ λ€μμ νμΈν©λλ€.
- initμ μΆκ°λ λͺ¨λ κ°μ²΄κ° λ¬Έμνλμλμ§ (`utils/check_repo.py`μμ μν)
- `__init__.py` νμΌμ λ μΉμ
μ λμΌν λ΄μ©μ΄ μλμ§ (`utils/check_inits.py`μμ μν)
- λ€λ₯Έ λͺ¨λμμ 볡μ¬λ μ½λκ° μλ³Έκ³Ό μΌμΉνλμ§ (`utils/check_copies.py`μμ μν)
- λͺ¨λ κ΅¬μ± ν΄λμ€μ docstringμ μΈκΈλ μ ν¨ν 체ν¬ν¬μΈνΈκ° μ μ΄λ νλ μλμ§ (`utils/check_config_docstrings.py`μμ μν)
- λͺ¨λ κ΅¬μ± ν΄λμ€κ° ν΄λΉνλ λͺ¨λΈλ§ νμΌμμ μ¬μ©λλ μμ±λ§ ν¬ν¨νκ³ μλμ§ (`utils/check_config_attributes.py`μμ μν)
- READMEμ λ¬Έμ μΈλ±μ€μ λ²μμ΄ λ©μΈ READMEμ λμΌν λͺ¨λΈ λͺ©λ‘μ κ°μ§κ³ μλμ§ (`utils/check_copies.py`μμ μν)
- λ¬Έμμ μλ μμ±λ ν
μ΄λΈμ΄ μ΅μ μνμΈμ§ (`utils/check_table.py`μμ μν)
- λΌμ΄λΈλ¬λ¦¬μλ μ νμ μ’
μμ±μ΄ μ€μΉλμ§ μμλλΌλ λͺ¨λ κ°μ²΄κ° μ¬μ© κ°λ₯νμ§ (`utils/check_dummies.py`μμ μν)
μ΄λ¬ν κ²μ¬κ° μ€ν¨νλ κ²½μ°, μ²μ λ κ°μ§ νλͺ©μ μλμΌλ‘ μμ ν΄μΌ νλ©°, λλ¨Έμ§ λ€ κ°μ§ νλͺ©μ λ€μ λͺ
λ Ήμ μ€ννμ¬ μλμΌλ‘ μμ ν μ μμ΅λλ€.
```bash
make fix-copies
```
μΆκ°μ μΈ κ²μ¬λ μλ‘μ΄ λͺ¨λΈμ μΆκ°νλ PRμ λν κ²μΌλ‘, μ£Όλ‘ λ€μκ³Ό κ°μ΅λλ€:
- μΆκ°λ λͺ¨λ λͺ¨λΈμ΄ Auto-mappingμ μλμ§ (`utils/check_repo.py`μμ μν)
<!-- TODO Sylvain, add a check that makes sure the common tests are implemented.-->
- λͺ¨λ λͺ¨λΈμ΄ μ¬λ°λ₯΄κ² ν
μ€νΈλμλμ§ (`utils/check_repo.py`μμ μν)
<!-- TODO Sylvain, add the following
- λͺ¨λ λͺ¨λΈμ΄ λ©μΈ README, μ£Όμ λ¬Έμμ μΆκ°λμλμ§
- μ¬μ©λ λͺ¨λ 체ν¬ν¬μΈνΈκ° μ€μ λ‘ Hubμ μ‘΄μ¬νλμ§
-->
### 볡μ¬λ³Έ νμΈ [[check-copies]]
Transformers λΌμ΄λΈλ¬λ¦¬λ λͺ¨λΈ μ½λμ λν΄ λ§€μ° μκ³ νλ©°, κ° λͺ¨λΈμ λ€λ₯Έ λͺ¨λΈμ μμ‘΄νμ§ μκ³ μμ ν λ¨μΌ νμΌλ‘ ꡬνλμ΄μΌ ν©λλ€. μ΄λ κ² νκΈ° μν΄ νΉμ λͺ¨λΈμ μ½λ 볡μ¬λ³Έμ΄ μλ³Έκ³Ό μΌκ΄λ μνλ‘ μ μ§λλμ§ νμΈνλ λ©μ»€λμ¦μ μΆκ°νμ΅λλ€. λ°λΌμ λ²κ·Έ μμ μ΄ νμν κ²½μ° λ€λ₯Έ λͺ¨λΈμ μν₯μ μ£Όλ λͺ¨λ λͺ¨λΈμ λ³Ό μ μμΌλ©° μμ μ μ μ©ν μ§ μμ λ μ¬λ³Έμ μμ ν μ§ μ νν μ μμ΅λλ€.
<Tip>
νμΌμ΄ λ€λ₯Έ νμΌμ μμ ν μ¬λ³ΈμΈ κ²½μ° ν΄λΉ νμΌμ `utils/check_copies.py`μ `FULL_COPIES` μμμ λ±λ‘ν΄μΌ ν©λλ€.
</Tip>
μ΄ λ©μ»€λμ¦μ `# Copied from xxx` νμμ μ£Όμμ κΈ°λ°μΌλ‘ ν©λλ€. `xxx`μλ μλμ 볡μ¬λλ ν΄λμ€ λλ ν¨μμ μ 체 κ²½λ‘κ° ν¬ν¨λμ΄μΌ ν©λλ€. μλ₯Ό λ€μ΄ `RobertaSelfOutput`μ `BertSelfOutput` ν΄λμ€μ 볡μ¬λ³Έμ
λλ€. λ°λΌμ [μ¬κΈ°](https://github.com/huggingface/transformers/blob/2bd7a27a671fd1d98059124024f580f8f5c0f3b5/src/transformers/models/roberta/modeling_roberta.py#L289)μμ μ£Όμμ΄ μμ΅λλ€:
```py
# Copied from transformers.models.bert.modeling_bert.BertSelfOutput
```
ν΄λμ€ μ 체μ μμ μ μ μ©νλ λμ μ 볡μ¬λ³Έκ³Ό κ΄λ ¨μλ λ©μλμ μ μ©ν μλ μμ΅λλ€. μλ₯Ό λ€μ΄ [μ¬κΈ°](https://github.com/huggingface/transformers/blob/2bd7a27a671fd1d98059124024f580f8f5c0f3b5/src/transformers/models/roberta/modeling_roberta.py#L598)μμ `RobertaPreTrainedModel._init_weights`κ° `BertPreTrainedModel`μ λμΌν λ©μλμμ 볡μ¬λ κ²μ λ³Ό μ μμΌλ©° ν΄λΉ μ£Όμμ΄ μμ΅λλ€:
```py
# Copied from transformers.models.bert.modeling_bert.BertPreTrainedModel._init_weights
```
볡μ¬λ³Έμ΄ μ΄λ¦λ§ λ€λ₯Έ κ²½μ°κ° μμ΅λλ€: μλ₯Ό λ€μ΄ `RobertaAttention`μμ `BertSelfAttention` λμ `RobertaSelfAttention`μ μ¬μ©νμ§λ§ κ·Έ μΈμλ μ½λκ° μμ ν λμΌν©λλ€: μ΄ λ `# Copied from`μ `Copied from xxx with foo->bar`μ κ°μ κ°λ¨ν λ¬Έμμ΄ λ체λ₯Ό μ§μν©λλ€. μ΄λ λͺ¨λ `foo` μΈμ€ν΄μ€λ₯Ό `bar`λ‘ λ°κΏμ μ½λλ₯Ό 볡μ¬ν©λλ€. [μ¬κΈ°](https://github.com/huggingface/transformers/blob/2bd7a27a671fd1d98059124024f580f8f5c0f3b5/src/transformers/models/roberta/modeling_roberta.py#L304C1-L304C86)μμ μ΄λ»κ² μ¬μ©λλμ§ λ³Ό μ μμ΅λλ€:
```py
# Copied from transformers.models.bert.modeling_bert.BertAttention with Bert->Roberta
```
νμ΄ν μ£Όλ³μλ κ³΅λ°±μ΄ μμ΄μΌ ν©λλ€(κ³΅λ°±μ΄ λ체 ν¨ν΄μ μΌλΆμΈ κ²½μ°λ μμΈμ
λλ€).
λ체 ν¨ν΄μ μΌνλ‘ κ΅¬λΆνμ¬ μ¬λ¬ ν¨ν΄μ μΆκ°ν μ μμ΅λλ€. μλ₯Ό λ€μ΄ `CamemberForMaskedLM`μ λ κ°μ§ λ체 μ¬νμ κ°μ§ `RobertaForMaskedLM`μ 볡μ¬λ³Έμ
λλ€: `Roberta`λ₯Ό `Camembert`λ‘ λ체νκ³ `ROBERTA`λ₯Ό `CAMEMBERT`λ‘ λ체ν©λλ€. [μ¬κΈ°](https://github.com/huggingface/transformers/blob/15082a9dc6950ecae63a0d3e5060b2fc7f15050a/src/transformers/models/camembert/modeling_camembert.py#L929)μμ μ΄κ²μ΄ μ£ΌμμΌλ‘ μ΄λ»κ² ꡬνλμλμ§ νμΈν μ μμ΅λλ€:
```py
# Copied from transformers.models.roberta.modeling_roberta.RobertaForMaskedLM with Roberta->Camembert, ROBERTA->CAMEMBERT
```
μμκ° μ€μν κ²½μ°(μ΄μ μμ κ³Ό μΆ©λν μ μλ κ²½μ°) μμ μ μΌμͺ½μμ μ€λ₯Έμͺ½μΌλ‘ μ€νλ©λλ€.
<Tip>
μ λ³κ²½μ΄ μμμ λ³κ²½νλ κ²½μ°(μ§§μ μ΄λ¦μ λ§€μ° κΈ΄ μ΄λ¦μΌλ‘ λ°κΎΈλ κ²½μ°) μλ μμ μ§μ κΈ°λ₯Ό μ μ©ν ν 볡μ¬λ³Έμ΄ κ²μ¬λ©λλ€.
</Tip>
ν¨ν΄μ λμλ¬Έμκ° λ€λ₯Έ κ²½μ°(λλ¬Έμμ μλ¬Έμκ° νΌμ©λ λ체 μμ) `all-casing` μ΅μ
μ μΆκ°νλ λ°©λ²λ μμ΅λλ€. [μ¬κΈ°](https://github.com/huggingface/transformers/blob/15082a9dc6950ecae63a0d3e5060b2fc7f15050a/src/transformers/models/mobilebert/modeling_mobilebert.py#L1237)μμ `MobileBertForSequenceClassification`μμ μ¬μ©λ μμλ₯Ό λ³Ό μ μμ΅λλ€:
```py
# Copied from transformers.models.bert.modeling_bert.BertForSequenceClassification with Bert->MobileBert all-casing
```
μ΄ κ²½μ°, μ½λλ λ€μκ³Ό κ°μ΄ 볡μ¬λ©λλ€:
- `MobileBert`μμ `Bert`λ‘(μ: `MobileBertModel`μ initμμ μ¬μ©ν λ)
- `mobilebert`μμ `bert`λ‘(μ: `self.mobilebert`λ₯Ό μ μν λ)
- `MOBILEBERT`μμ `BERT`λ‘(`MOBILEBERT_INPUTS_DOCSTRING` μμμμ)
|