File size: 5,861 Bytes
17c6d62 |
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 |
<!--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.
-->
# μ½λ°± [[callbacks]]
μ½λ°±μ PyTorch [`Trainer`]μ λ°λ³΅ νμ΅ λμμ μ¬μ©μ μ μν μ μλ κ°μ²΄μ
λλ€
(μ΄ κΈ°λ₯μ TensorFlowμμλ μμ§ κ΅¬νλμ§ μμμ΅λλ€). μ½λ°±μ λ°λ³΅ νμ΅μ μνλ₯Ό
κ²μ¬νμ¬ (μ§ν μν© λ³΄κ³ , TensorBoard λλ κΈ°ν λ¨Έμ λ¬λ νλ«νΌμ λ‘κ·Έ λ¨κΈ°κΈ° λ±)
κ²°μ (μ: μ‘°κΈ° μ’
λ£)μ λ΄λ¦΄ μ μμ΅λλ€.
μ½λ°±μ [`TrainerControl`] κ°μ²΄λ₯Ό λ°ννλ κ² μΈμλ λ°λ³΅ νμ΅μμ μ΄λ€ κ²λ λ³κ²½ν μ μλ
"μ½κΈ° μ μ©" μ½λ μ‘°κ°μ
λλ€. λ°λ³΅ νμ΅μ λ³κ²½μ΄ νμν μ¬μ©μ μ μ μμ
μ΄ νμν κ²½μ°,
[`Trainer`]λ₯Ό μλΈν΄λμ€λ‘ λ§λ€μ΄ νμν λ©μλλ€μ μ€λ²λΌμ΄λν΄μΌ ν©λλ€ (μμλ [trainer](trainer)λ₯Ό μ°Έμ‘°νμΈμ).
κΈ°λ³Έμ μΌλ‘ `TrainingArguments.report_to`λ `"all"`λ‘ μ€μ λμ΄ μμΌλ―λ‘, [`Trainer`]λ λ€μ μ½λ°±μ μ¬μ©ν©λλ€.
- [`DefaultFlowCallback`]λ λ‘κ·Έ, μ μ₯, νκ°μ λν κΈ°λ³Έ λμμ μ²λ¦¬ν©λλ€.
- [`PrinterCallback`] λλ [`ProgressCallback`]λ μ§ν μν©μ νμνκ³ λ‘κ·Έλ₯Ό μΆλ ₯ν©λλ€
([`TrainingArguments`]λ₯Ό ν΅ν΄ tqdmμ λΉνμ±ννλ©΄ 첫 λ²μ§Έ μ½λ°±μ΄ μ¬μ©λκ³ , κ·Έλ μ§ μμΌλ©΄ λ λ²μ§Έκ° μ¬μ©λ©λλ€).
- [`~integrations.TensorBoardCallback`]λ TensorBoardκ° (PyTorch >= 1.4
λλ tensorboardXλ₯Ό ν΅ν΄) μ κ·Ό κ°λ₯νλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.WandbCallback`]λ [wandb](https://www.wandb.com/)κ° μ€μΉλμ΄ μμΌλ©΄
μ¬μ©λ©λλ€.
- [`~integrations.CometCallback`]λ [comet_ml](https://www.comet.com/site/)μ΄ μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.MLflowCallback`]λ [mlflow](https://www.mlflow.org/)κ° μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.NeptuneCallback`]λ [neptune](https://neptune.ai/)μ΄ μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.AzureMLCallback`]λ [azureml-sdk](https://pypi.org/project/azureml-sdk/)κ° μ€μΉλμ΄
μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.CodeCarbonCallback`]λ [codecarbon](https://pypi.org/project/codecarbon/)μ΄ μ€μΉλμ΄
μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.ClearMLCallback`]λ [clearml](https://github.com/allegroai/clearml)μ΄ μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.DagsHubCallback`]λ [dagshub](https://dagshub.com/)μ΄ μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.FlyteCallback`]λ [flyte](https://flyte.org/)κ° μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
- [`~integrations.DVCLiveCallback`]λ [dvclive](https://dvc.org/doc/dvclive)κ° μ€μΉλμ΄ μμΌλ©΄ μ¬μ©λ©λλ€.
ν¨ν€μ§κ° μ€μΉλμ΄ μμ§λ§ ν΄λΉ ν΅ν© κΈ°λ₯μ μ¬μ©νκ³ μΆμ§ μλ€λ©΄, `TrainingArguments.report_to`λ₯Ό μ¬μ©νκ³ μ νλ ν΅ν© κΈ°λ₯ λͺ©λ‘μΌλ‘ λ³κ²½ν μ μμ΅λλ€ (μ: `["azure_ml", "wandb"]`).
μ½λ°±μ ꡬννλ μ£Όμ ν΄λμ€λ [`TrainerCallback`]μ
λλ€. μ΄ ν΄λμ€λ [`Trainer`]λ₯Ό
μΈμ€ν΄μ€ννλ λ° μ¬μ©λ [`TrainingArguments`]λ₯Ό κ°μ Έμ€κ³ , ν΄λΉ Trainerμ λ΄λΆ μνλ₯Ό
[`TrainerState`]λ₯Ό ν΅ν΄ μ κ·Όν μ μμΌλ©°, [`TrainerControl`]μ ν΅ν΄ λ°λ³΅ νμ΅μμ μΌλΆ
μμ
μ μνν μ μμ΅λλ€.
## μ¬μ© κ°λ₯ν μ½λ°± [[available-callbacks]]
λΌμ΄λΈλ¬λ¦¬μμ μ¬μ© κ°λ₯ν [`TrainerCallback`] λͺ©λ‘μ λ€μκ³Ό κ°μ΅λλ€:
[[autodoc]] integrations.CometCallback
- setup
[[autodoc]] DefaultFlowCallback
[[autodoc]] PrinterCallback
[[autodoc]] ProgressCallback
[[autodoc]] EarlyStoppingCallback
[[autodoc]] integrations.TensorBoardCallback
[[autodoc]] integrations.WandbCallback
- setup
[[autodoc]] integrations.MLflowCallback
- setup
[[autodoc]] integrations.AzureMLCallback
[[autodoc]] integrations.CodeCarbonCallback
[[autodoc]] integrations.NeptuneCallback
[[autodoc]] integrations.ClearMLCallback
[[autodoc]] integrations.DagsHubCallback
[[autodoc]] integrations.FlyteCallback
[[autodoc]] integrations.DVCLiveCallback
- setup
## TrainerCallback [[trainercallback]]
[[autodoc]] TrainerCallback
μ¬κΈ° PyTorch [`Trainer`]μ ν¨κ» μ¬μ©μ μ μ μ½λ°±μ λ±λ‘νλ μμκ° μμ΅λλ€:
```python
class MyCallback(TrainerCallback):
"A callback that prints a message at the beginning of training"
def on_train_begin(self, args, state, control, **kwargs):
print("Starting training")
trainer = Trainer(
model,
args,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
callbacks=[MyCallback], # μ°λ¦¬λ μ½λ°± ν΄λμ€λ₯Ό μ΄ λ°©μμΌλ‘ μ λ¬νκ±°λ κ·Έκ²μ μΈμ€ν΄μ€(MyCallback())λ₯Ό μ λ¬ν μ μμ΅λλ€
)
```
λ λ€λ₯Έ μ½λ°±μ λ±λ‘νλ λ°©λ²μ `trainer.add_callback()`μ νΈμΆνλ κ²μ
λλ€:
```python
trainer = Trainer(...)
trainer.add_callback(MyCallback)
# λ€λ₯Έ λ°©λ²μΌλ‘λ μ½λ°± ν΄λμ€μ μΈμ€ν΄μ€λ₯Ό μ λ¬ν μ μμ΅λλ€
trainer.add_callback(MyCallback())
```
## TrainerState [[trainerstate]]
[[autodoc]] TrainerState
## TrainerControl [[trainercontrol]]
[[autodoc]] TrainerControl
|