huggingface--transformers
e06fe8e8c6
Secret Leaks / trufflehog (push) Failing after 1s
Build documentation / build (push) Failing after 1s
Build documentation / build_other_lang (push) Failing after 0s
CodeQL Security Analysis / CodeQL Analysis (push) Failing after 0s
PR CI / pr-ci (push) Failing after 1s
Slow tests on important models (on Push - A10) / Get all modified files (push) Failing after 1s
Slow tests on important models (on Push - A10) / Model CI (push) Has been skipped
Self-hosted runner (benchmark) / Benchmark (aws-g5-4xlarge-cache) (push) Has been cancelled
New model PR merged notification / Notify new model (push) Has been cancelled
Update Transformers metadata / build_and_package (push) Has been cancelled
195 ่ก
12 KiB
Markdown
195 ่ก
12 KiB
Markdown
<!---
|
|
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 check-repo
|
|
```
|
|
|
|
์ด ๋ช
๋ น์ ํ์ฌ ๋ธ๋์น์์ ์์ ํ ํ์ผ์ ๋ํ ๋ชจ๋ ์ถ๊ฐ์ ์ธ ๊ฒ์ฌ๋ ์คํํฉ๋๋ค. ์ด์ ์ด๋ค์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
|
|
|
|
## ์ ์ฅ์ ์ผ๊ด์ฑ [[repository-consistency]]
|
|
|
|
์ด๋ PR์ด ์ ์ฅ์๋ฅผ ์ ์์ ์ธ ์ํ๋ก ์ ์งํ๋์ง ํ์ธํ๋ ๋ชจ๋ ํ
์คํธ๋ฅผ ๋ชจ์ ๊ฒ์ด๋ฉฐ, `ci/circleci: check_repository_consistency` ๊ฒ์ฌ์์ ์ํ๋ฉ๋๋ค. ๋ค์์ ์คํํจ์ผ๋ก์จ ๋ก์ปฌ์์ ์ด ๊ฒ์ฌ๋ฅผ ์คํํ ์ ์์ต๋๋ค.
|
|
|
|
```bash
|
|
make check-repo
|
|
```
|
|
|
|
์ด ๊ฒ์ฌ๋ ๋ค์์ ํ์ธํฉ๋๋ค.
|
|
|
|
- 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-repo
|
|
```
|
|
|
|
์ถ๊ฐ์ ์ธ ๊ฒ์ฌ๋ ์๋ก์ด ๋ชจ๋ธ์ ์ถ๊ฐํ๋ 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` ์์์์)
|