mirror of
https://github.com/clearml/clearml-docs
synced 2025-03-09 13:42:26 +00:00
Rewrite PyTorch Ignite integration page (#622)
This commit is contained in:
parent
161283761f
commit
b890e552ed
@ -1,6 +1,5 @@
|
||||
---
|
||||
title: PyTorch Ignite TensorboardLogger
|
||||
displayed_sidebar: mainSidebar
|
||||
---
|
||||
|
||||
The [cifar_ignite.py](https://github.com/allegroai/clearml/blob/master/examples/frameworks/ignite/cifar_ignite.py) example
|
||||
|
@ -1,6 +1,5 @@
|
||||
---
|
||||
title: PyTorch Ignite ClearMLLogger
|
||||
displayed_sidebar: mainSidebar
|
||||
---
|
||||
|
||||
The `ignite` repository contains the [mnist_with_clearml_logger.py](https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_clearml_logger.py)
|
||||
|
146
docs/integrations/ignite.md
Normal file
146
docs/integrations/ignite.md
Normal file
@ -0,0 +1,146 @@
|
||||
---
|
||||
title: PyTorch Ignite
|
||||
---
|
||||
|
||||
[PyTorch Ignite](https://pytorch.org/ignite/index.html) is a library for training and evaluating neural networks in
|
||||
PyTorch. You can integrate ClearML into your code using Ignite’s built-in loggers: [TensorboardLogger](#tensorboardlogger)
|
||||
and [ClearMLLogger](#clearmllogger).
|
||||
|
||||
## TensorboardLogger
|
||||
|
||||
ClearML integrates seamlessly with TensorboardLogger, and automatically captures all information logged through the
|
||||
handler: metrics, parameters, images, and gradients.
|
||||
|
||||
All you have to do is add two lines of code to your script:
|
||||
|
||||
```python
|
||||
from clearml import Task
|
||||
task = Task.init(task_name="<task_name>", project_name="<project_name>")
|
||||
```
|
||||
|
||||
This will create a [ClearML Task](../fundamentals/task.md) that captures your script's information, including Git details,
|
||||
uncommitted code, python environment, all information logged through `TensorboardLogger`, and more.
|
||||
|
||||
Visualize all the captured information in the experiment's page in ClearML's [WebApp](#webapp)
|
||||
|
||||
See a code example [here](https://github.com/allegroai/clearml/blob/master/examples/frameworks/ignite/cifar_ignite.py).
|
||||
|
||||
## ClearMLLogger
|
||||
PyTorch Ignite supports a ClearML Logger to log metrics, text, model/optimizer parameters, plots, and model checkpoints
|
||||
during training and validation.
|
||||
|
||||
Integrate ClearML with the following steps:
|
||||
1. Create a `ClearMLLogger` object:
|
||||
|
||||
```python
|
||||
from ignite.contrib.handlers.clearml_logger import *
|
||||
|
||||
clearml_logger = ClearMLLogger(task_name="ignite", project_name="examples")
|
||||
```
|
||||
|
||||
This creates a [ClearML Task](../fundamentals/task.md) called `ignite` in the `examples` project, which captures your
|
||||
script's information, including Git details, uncommitted code, python environment.
|
||||
|
||||
You can also pass the following parameters to the `ClearMLLogger` object:
|
||||
* `task_type` – The type of experiment (see [task types](../fundamentals/task.md#task-types)).
|
||||
* `report_freq` – The histogram processing frequency (handles histogram values every X calls to the handler). Affects
|
||||
`GradsHistHandler` and `WeightsHistHandler` (default: 100).
|
||||
* `histogram_update_freq_multiplier` – The histogram report frequency (report first X histograms and once every X
|
||||
reports afterwards) (default: 10).
|
||||
* `histogram_granularity` - Histogram sampling granularity (default: 50).
|
||||
|
||||
1. Attach the C`learMLLogger` to output handlers to log metrics:
|
||||
|
||||
```python
|
||||
# Attach the logger to the trainer to log training loss
|
||||
clearml_logger.attach_output_handler(
|
||||
trainer,
|
||||
event_name=Events.ITERATION_COMPLETED(every=100),
|
||||
tag="training",
|
||||
output_transform=lambda loss: {"batchloss": loss},
|
||||
)
|
||||
|
||||
# Attach the logger to log loss and accuracy for both training and validation
|
||||
for tag, evaluator in [("training metrics", train_evaluator), ("validation metrics", validation_evaluator)]:
|
||||
clearml_logger.attach_output_handler(
|
||||
evaluator,
|
||||
event_name=Events.EPOCH_COMPLETED,
|
||||
tag=tag,
|
||||
metric_names=["loss", "accuracy"],
|
||||
global_step_transform=global_step_from_engine(trainer),
|
||||
)
|
||||
```
|
||||
|
||||
1. Attach the ClearMLLogger object to helper handlers to log experiment outputs. Ignite supports the following helper handlers for ClearML:
|
||||
|
||||
* **ClearMLSaver** - Saves input snapshots as ClearML artifacts.
|
||||
* **GradsHistHandler** and **WeightsHistHandler** - Logs the model's gradients and weights respectively as histograms.
|
||||
* **GradsScalarHandler** and **WeightsScalarHandler** - Logs gradients and weights respectively as scalars.
|
||||
* **OptimizerParamsHandler** - Logs optimizer parameters
|
||||
|
||||
```python
|
||||
# Attach the logger to the trainer to log model's weights norm
|
||||
clearml_logger.attach(
|
||||
trainer, log_handler=WeightsScalarHandler(model), event_name=Events.ITERATION_COMPLETED(every=100)
|
||||
)
|
||||
|
||||
# Attach the logger to the trainer to log model's weights as a histogram
|
||||
clearml_logger.attach(trainer, log_handler=WeightsHistHandler(model), event_name=Events.EPOCH_COMPLETED(every=100))
|
||||
|
||||
# Attach the logger to the trainer to log model’s gradients as scalars
|
||||
clearml_logger.attach(
|
||||
trainer, log_handler=GradsScalarHandler(model), event_name=Events.ITERATION_COMPLETED(every=100)
|
||||
)
|
||||
|
||||
#Attach the logger to the trainer to log model's gradients as a histogram
|
||||
clearml_logger.attach(trainer, log_handler=GradsHistHandler(model), event_name=Events.EPOCH_COMPLETED(every=100))
|
||||
|
||||
handler = Checkpoint(
|
||||
{"model": model},
|
||||
ClearMLSaver(),
|
||||
n_saved=1,
|
||||
score_function=lambda e: e.state.metrics["accuracy"],
|
||||
score_name="val_acc",
|
||||
filename_prefix="best",
|
||||
global_step_transform=global_step_from_engine(trainer),
|
||||
)
|
||||
validation_evaluator.add_event_handler(Events.EPOCH_COMPLETED, handler)
|
||||
|
||||
# Attach the logger to the trainer to log optimizer's parameters, e.g. learning rate at each iteration
|
||||
clearml_logger.attach(
|
||||
trainer,
|
||||
log_handler=OptimizerParamsHandler(optimizer),
|
||||
event_name=Events.ITERATION_STARTED
|
||||
)
|
||||
```
|
||||
|
||||
Visualize all the captured information in the experiment's page in ClearML's [WebApp](#webapp).
|
||||
|
||||
For more information, see the [ignite documentation](https://pytorch.org/ignite/generated/ignite.contrib.handlers.clearml_logger.html).
|
||||
|
||||
See code example [here](https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_clearml_logger.py)
|
||||
|
||||
## WebApp
|
||||
|
||||
All the experiment information that ClearML captures can be viewed in the [WebApp](../webapp/webapp_overview.md):
|
||||
|
||||
### Models
|
||||
|
||||
View saved model snapshots in the **ARTIFACTS** tab.
|
||||
|
||||

|
||||
|
||||
### Scalars
|
||||
|
||||
View the scalars in the experiment's **SCALARS** tab.
|
||||
|
||||

|
||||
|
||||
|
||||
### Debug Samples
|
||||
|
||||
ClearML automatically tracks images logged to `TensorboardLogger`. They appear in the experiment's **DEBUG SAMPLES**.
|
||||
|
||||
|
||||

|
||||
|
@ -66,7 +66,7 @@ module.exports = {
|
||||
'guides/frameworks/lightgbm/lightgbm_example', 'guides/frameworks/matplotlib/matplotlib_example',
|
||||
'guides/frameworks/megengine/megengine_mnist', 'integrations/openmmv', 'integrations/optuna',
|
||||
'integrations/python_fire', 'guides/frameworks/pytorch/pytorch_mnist',
|
||||
{'PyTorch Ignite':['guides/frameworks/pytorch_ignite/integration_pytorch_ignite', 'guides/frameworks/pytorch_ignite/pytorch_ignite_mnist']},
|
||||
'integrations/ignite',
|
||||
'guides/frameworks/pytorch_lightning/pytorch_lightning_example', 'guides/frameworks/scikit-learn/sklearn_joblib_example',
|
||||
'guides/frameworks/pytorch/pytorch_tensorboard', 'guides/frameworks/tensorboardx/tensorboardx', 'guides/frameworks/tensorflow/tensorflow_mnist',
|
||||
'integrations/seaborn', 'integrations/xgboost', 'integrations/yolov5', 'integrations/yolov8'
|
||||
|
Loading…
Reference in New Issue
Block a user