Skip to content

Commit

Permalink
Updated code formatting tools verions and reformatted the code (pytor…
Browse files Browse the repository at this point in the history
  • Loading branch information
vfdev-5 authored Mar 20, 2024
1 parent fd9db82 commit 5fe7443
Show file tree
Hide file tree
Showing 33 changed files with 45 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ repos:
exclude_types: ["python", "jupyter", "shell", "gitignore"]

- repo: https://github.com/omnilib/ufmt
rev: v2.2.0
rev: v2.5.1
hooks:
- id: ufmt
additional_dependencies:
- black == 23.9.1
- usort == 1.0.7
- black == 24.3.0
- usort == 1.0.8.post1

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
args: ["--config", "setup.cfg"]
2 changes: 1 addition & 1 deletion examples/gan/dcgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, z_dim, nf, nc):
nn.ReLU(inplace=True),
# state size. (nf) x 32 x 32
nn.ConvTranspose2d(in_channels=nf, out_channels=nc, kernel_size=4, stride=2, padding=1, bias=False),
nn.Tanh()
nn.Tanh(),
# state size. (nc) x 64 x 64
)

Expand Down
1 change: 1 addition & 0 deletions examples/mnist/mnist_with_clearml_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
python mnist_with_clearml_logger.py
```
"""

from argparse import ArgumentParser

import torch
Expand Down
1 change: 1 addition & 0 deletions examples/mnist/mnist_with_neptune_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
You can view example runs here:
https://app.neptune.ai/o/common/org/pytorch-ignite-integration/
"""

from argparse import ArgumentParser

import torch
Expand Down
1 change: 1 addition & 0 deletions examples/mnist/mnist_with_tensorboard_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
python mnist_with_tensorboard_logger.py --log_dir=/tmp/tensorboard_logs
```
"""

import sys
from argparse import ArgumentParser

Expand Down
1 change: 1 addition & 0 deletions examples/mnist/mnist_with_visdom_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
python mnist_with_visdom_logger.py
```
"""

from argparse import ArgumentParser

import torch
Expand Down
1 change: 1 addition & 0 deletions examples/mnist/mnist_with_wandb_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Go to https://wandb.com and explore your experiment.
"""

from argparse import ArgumentParser

import torch
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/base_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base logger and its helper handlers."""

import numbers
import warnings
from abc import ABCMeta, abstractmethod
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/clearml_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ClearML logger and its helper handlers."""

import os
import tempfile
import warnings
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/lr_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
``ignite.contrib.handlers.lr_finder`` was moved to ``ignite.handlers.lr_finder``.
Please refer to :mod:`~ignite.handlers.lr_finder`.
"""

import warnings

removed_in = "0.6.0"
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/mlflow_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""MLflow logger and its helper handlers."""

import warnings
from typing import Any, Callable, List, Optional, Union

Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/neptune_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Neptune logger and its helper handlers."""

import tempfile
import warnings
from typing import Any, Callable, List, Mapping, Optional, Union
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/param_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
``ignite.contrib.handlers.param_scheduler`` was moved to ``ignite.handlers.param_scheduler``.
Please refer to :mod:`~ignite.handlers.param_scheduler`.
"""

import warnings

removed_in = "0.6.0"
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/polyaxon_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Polyaxon logger and its helper handlers."""

from typing import Any, Callable, List, Optional, Union

from torch.optim import Optimizer
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/tensorboard_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TensorBoard logger and its helper handlers."""

from typing import Any, Callable, List, Optional, Union

from torch.optim import Optimizer
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/time_profilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
``ignite.contrib.handlers.time_profilers`` was moved to ``ignite.handlers.time_profilers``.
Please refer to :mod:`~ignite.handlers.time_profilers`.
"""

import warnings

removed_in = "0.6.0"
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/visdom_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Visdom logger and its helper handlers."""

import os
from typing import Any, Callable, cast, Dict, List, Optional, Union

Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/handlers/wandb_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""WandB logger and its helper handlers."""

from typing import Any, Callable, List, Optional, Union

from torch.optim import Optimizer
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/canberra_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class CanberraMetric(_BaseRegression):
- Fixed implementation: ``abs`` in denominator.
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors",)

@reinit__is_reduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FractionalAbsoluteError(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors", "_num_examples")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/fractional_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FractionalBias(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors", "_num_examples")

@reinit__is_reduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class GeometricMeanAbsoluteError(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors", "_num_examples")

@reinit__is_reduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GeometricMeanRelativeAbsoluteError(_BaseRegression):
0.0...
"""

_state_dict_all_req_keys = ("_predictions", "_targets")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/manhattan_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ManhattanDistance(_BaseRegression):
- Fixed sklearn compatibility.
- Workes with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors",)

@reinit__is_reduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MaximumAbsoluteError(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_max_of_absolute_errors",)

@reinit__is_reduced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MeanAbsoluteRelativeError(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_absolute_relative_errors", "_num_samples")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/mean_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MeanError(_BaseRegression):
0.625...
"""

_state_dict_all_req_keys = ("_sum_of_errors", "_num_examples")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/mean_normalized_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MeanNormalizedBias(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors", "_num_examples")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/r2_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class R2Score(_BaseRegression):
.. versionchanged:: 0.4.3
Works with DDP.
"""

_state_dict_all_req_keys = ("_num_examples", "_sum_of_errors", "_y_sq_sum", "_y_sum")

@reinit__is_reduced
Expand Down
1 change: 1 addition & 0 deletions ignite/contrib/metrics/regression/wave_hedges_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class WaveHedgesDistance(_BaseRegression):
.. versionchanged:: 0.4.5
- Works with DDP.
"""

_state_dict_all_req_keys = ("_sum_of_errors",)

@reinit__is_reduced
Expand Down
16 changes: 10 additions & 6 deletions tests/ignite/engine/test_create_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def get_first_element(output):
scaler=scaler,
gradient_accumulation_steps=gradient_accumulation_steps,
model_transform=model_transform if model_transform is not None else lambda x: x,
model_fn=(lambda model, x: model(x, torch.tensor([0.01], device=model_device)))
if with_model_fn
else (lambda model, x: model(x)),
model_fn=(
(lambda model, x: model(x, torch.tensor([0.01], device=model_device)))
if with_model_fn
else (lambda model, x: model(x))
),
)
assert model.fc.weight.data[0, 0].item() == approx(0.0)
return trainer, model
Expand Down Expand Up @@ -259,9 +261,11 @@ def get_first_element(output):
device=evaluator_device,
amp_mode=amp_mode,
model_transform=model_transform if model_transform is not None else lambda x: x,
model_fn=(lambda model, x: model(x, torch.tensor([0.01], device=model_device)))
if with_model_fn
else (lambda model, x: model(x)),
model_fn=(
(lambda model, x: model(x, torch.tensor([0.01], device=model_device)))
if with_model_fn
else (lambda model, x: model(x))
),
)

assert model.fc.weight.data[0, 0].item() == approx(0.0)
Expand Down
2 changes: 1 addition & 1 deletion tests/run_code_style.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mypy --config-file mypy.ini
goto end

:install
pip install --upgrade flake8 "black==23.9.1" "usort==1.0.7" "ufmt==2.2.0" "mypy"
pip install --upgrade flake8 "black==24.3.0" "usort==1.0.8.post1" "ufmt==2.5.1" "mypy"
goto end

:end
Expand Down
2 changes: 1 addition & 1 deletion tests/run_code_style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ elif [ $1 = "fmt" ]; then
elif [ $1 = "mypy" ]; then
mypy --config-file mypy.ini
elif [ $1 = "install" ]; then
pip install --upgrade flake8 "black==23.9.1" "usort==1.0.7" "ufmt==2.2.0" "mypy"
pip install --upgrade flake8 "black==24.3.0" "usort==1.0.8.post1" "ufmt==2.5.1" "mypy"
fi

0 comments on commit 5fe7443

Please sign in to comment.