Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions ignite/contrib/handlers/base_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class BaseWeightsScalarHandler(BaseHandler):
Helper handler to log model's weights as scalars.
"""

def __init__(self, model: nn.Module, reduction: Callable = torch.norm, tag: Optional[str] = None) -> None:
def __init__(self, model: nn.Module, reduction: Callable = torch.norm, tag: Optional[str] = None):
if not isinstance(model, torch.nn.Module):
raise TypeError(f"Argument model should be of type torch.nn.Module, but given {type(model)}")

Expand Down Expand Up @@ -152,14 +152,14 @@ def attach(
"""Attach the logger to the engine and execute `log_handler` function at `event_name` events.

Args:
engine (Engine): engine object.
log_handler (callable): a logging handler to execute
engine: engine object.
log_handler: a logging handler to execute
event_name: event to attach the logging handler to. Valid events are from
:class:`~ignite.engine.events.Events` or class:`~ignite.engine.events.EventsList` or any `event_name`
:class:`~ignite.engine.events.Events` or :class:`~ignite.engine.events.EventsList` or any `event_name`
added by :meth:`~ignite.engine.engine.Engine.register_events`.

Returns:
:class:`~ignite.engine.RemovableEventHandle`, which can be used to remove the handler.
:class:`~ignite.engine.events.RemovableEventHandle`, which can be used to remove the handler.
"""
if isinstance(event_name, EventsList):
for name in event_name:
Expand All @@ -180,15 +180,15 @@ def attach_output_handler(self, engine: Engine, event_name: Any, *args: Any, **k
"""Shortcut method to attach `OutputHandler` to the logger.

Args:
engine (Engine): engine object.
engine: engine object.
event_name: event to attach the logging handler to. Valid events are from
:class:`~ignite.engine.events.Events` or any `event_name` added by
:meth:`~ignite.engine.engine.Engine.register_events`.
*args: args to initialize `OutputHandler`
**kwargs: kwargs to initialize `OutputHandler`
args: args to initialize `OutputHandler`
kwargs: kwargs to initialize `OutputHandler`

Returns:
:class:`~ignite.engine.RemovableEventHandle`, which can be used to remove the handler.
:class:`~ignite.engine.events.RemovableEventHandle`, which can be used to remove the handler.
"""
return self.attach(engine, self._create_output_handler(*args, **kwargs), event_name=event_name)

Expand All @@ -198,15 +198,15 @@ def attach_opt_params_handler(
"""Shortcut method to attach `OptimizerParamsHandler` to the logger.

Args:
engine (Engine): engine object.
engine: engine object.
event_name: event to attach the logging handler to. Valid events are from
:class:`~ignite.engine.events.Events` or any `event_name` added by
:meth:`~ignite.engine.engine.Engine.register_events`.
*args: args to initialize `OptimizerParamsHandler`
**kwargs: kwargs to initialize `OptimizerParamsHandler`
args: args to initialize `OptimizerParamsHandler`
kwargs: kwargs to initialize `OptimizerParamsHandler`

Returns:
:class:`~ignite.engine.RemovableEventHandle`, which can be used to remove the handler.
:class:`~ignite.engine.events.RemovableEventHandle`, which can be used to remove the handler.

.. versionchanged:: 0.4.3
Added missing return statement.
Expand Down
64 changes: 32 additions & 32 deletions ignite/contrib/handlers/clearml_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class ClearMLLogger(BaseLogger):
clearml-init

Args:
project_name (str): The name of the project in which the experiment will be created. If the project
project_name: The name of the project in which the experiment will be created. If the project
does not exist, it is created. If ``project_name`` is ``None``, the repository name is used. (Optional)
task_name (str): The name of Task (experiment). If ``task_name`` is ``None``, the Python experiment
task_name: The name of Task (experiment). If ``task_name`` is ``None``, the Python experiment
script's file name is used. (Optional)
task_type (str): Optional. The task type. Valid values are:
task_type: Optional. The task type. Valid values are:
- ``TaskTypes.training`` (Default)
- ``TaskTypes.train``
- ``TaskTypes.testing``
Expand Down Expand Up @@ -119,7 +119,7 @@ class ClearMLLogger(BaseLogger):

"""

def __init__(self, *_: Any, **kwargs: Any) -> None:
def __init__(self, *_: Any, **kwargs: Any):
try:
from clearml import Task
from clearml.binding.frameworks.tensorflow_bind import WeightsGradientHistHelper
Expand Down Expand Up @@ -270,14 +270,14 @@ def global_step_transform(*args, **kwargs):
)

Args:
tag (str): common title for all produced plots. For example, "training"
metric_names (list of str, optional): list of metric names to plot or a string "all" to plot all available
tag: common title for all produced plots. For example, "training"
metric_names: list of metric names to plot or a string "all" to plot all available
metrics.
output_transform (callable, optional): output transform function to prepare `engine.state.output` as a number.
output_transform: output transform function to prepare `engine.state.output` as a number.
For example, `output_transform = lambda output: output`
This function can also return a dictionary, e.g `{"loss": loss1, "another_loss": loss2}` to label the plot
with corresponding keys.
global_step_transform (callable, optional): global step transform function to output a desired global step.
global_step_transform: global step transform function to output a desired global step.
Input of the function is `(engine, event_name)`. Output of function should be an integer.
Default is None, global_step based on attached engine. If provided,
uses function output as global_step. To setup global step from another engine, please use
Expand All @@ -299,7 +299,7 @@ def __init__(
metric_names: Optional[List[str]] = None,
output_transform: Optional[Callable] = None,
global_step_transform: Optional[Callable] = None,
) -> None:
):
super(OutputHandler, self).__init__(tag, metric_names, output_transform, global_step_transform)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -359,13 +359,13 @@ class OptimizerParamsHandler(BaseOptimizerParamsHandler):
)

Args:
optimizer (torch.optim.Optimizer or object): torch optimizer or any object with attribute ``param_groups``
optimizer: torch optimizer or any object with attribute ``param_groups``
as a sequence.
param_name (str): parameter name
tag (str, optional): common title for all produced plots. For example, "generator"
param_name: parameter name
tag: common title for all produced plots. For example, "generator"
"""

def __init__(self, optimizer: Optimizer, param_name: str = "lr", tag: Optional[str] = None) -> None:
def __init__(self, optimizer: Optimizer, param_name: str = "lr", tag: Optional[str] = None):
super(OptimizerParamsHandler, self).__init__(optimizer, param_name, tag)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -410,13 +410,13 @@ class WeightsScalarHandler(BaseWeightsScalarHandler):
)

Args:
model (torch.nn.Module): model to log weights
reduction (callable): function to reduce parameters into scalar
tag (str, optional): common title for all produced plots. For example, "generator"
model: model to log weights
reduction: function to reduce parameters into scalar
tag: common title for all produced plots. For example, "generator"

"""

def __init__(self, model: Module, reduction: Callable = torch.norm, tag: Optional[str] = None) -> None:
def __init__(self, model: Module, reduction: Callable = torch.norm, tag: Optional[str] = None):
super(WeightsScalarHandler, self).__init__(model, reduction, tag=tag)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -463,12 +463,12 @@ class WeightsHistHandler(BaseWeightsHistHandler):
)

Args:
model (torch.nn.Module): model to log weights
tag (str, optional): common title for all produced plots. For example, 'generator'
model: model to log weights
tag: common title for all produced plots. For example, 'generator'

"""

def __init__(self, model: Module, tag: Optional[str] = None) -> None:
def __init__(self, model: Module, tag: Optional[str] = None):
super(WeightsHistHandler, self).__init__(model, tag=tag)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -517,13 +517,13 @@ class GradsScalarHandler(BaseWeightsScalarHandler):
)

Args:
model (torch.nn.Module): model to log weights
reduction (callable): function to reduce parameters into scalar
tag (str, optional): common title for all produced plots. For example, "generator"
model: model to log weights
reduction: function to reduce parameters into scalar
tag: common title for all produced plots. For example, "generator"

"""

def __init__(self, model: Module, reduction: Callable = torch.norm, tag: Optional[str] = None) -> None:
def __init__(self, model: Module, reduction: Callable = torch.norm, tag: Optional[str] = None):
super(GradsScalarHandler, self).__init__(model, reduction, tag=tag)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -569,12 +569,12 @@ class GradsHistHandler(BaseWeightsHistHandler):
)

Args:
model (torch.nn.Module): model to log weights
tag (str, optional): common title for all produced plots. For example, 'generator'
model: model to log weights
tag: common title for all produced plots. For example, 'generator'

"""

def __init__(self, model: Module, tag: Optional[str] = None) -> None:
def __init__(self, model: Module, tag: Optional[str] = None):
super(GradsHistHandler, self).__init__(model, tag=tag)

def __call__(self, engine: Engine, logger: ClearMLLogger, event_name: Union[str, Events]) -> None:
Expand Down Expand Up @@ -602,12 +602,12 @@ class ClearMLSaver(DiskSaver):
Handler that saves input checkpoint as ClearML artifacts

Args:
logger (ClearMLLogger, optional): An instance of :class:`~ignite.contrib.handlers.clearml_logger.ClearMLLogger`,
logger: An instance of :class:`~ignite.contrib.handlers.clearml_logger.ClearMLLogger`,
ensuring a valid ClearML ``Task`` has been initialized. If not provided, and a ClearML Task
has not been manually initialized, a runtime error will be raised.
output_uri (str, optional): The default location for output models and other artifacts uploaded by ClearML. For
output_uri: The default location for output models and other artifacts uploaded by ClearML. For
more information, see ``clearml.Task.init``.
dirname (str, optional): Directory path where the checkpoint will be saved. If not provided, a temporary
dirname: Directory path where the checkpoint will be saved. If not provided, a temporary
directory will be created.

Examples:
Expand Down Expand Up @@ -645,7 +645,7 @@ def __init__(
dirname: Optional[str] = None,
*args: Any,
**kwargs: Any,
) -> None:
):

self._setup_check_clearml(logger, output_uri)

Expand Down Expand Up @@ -793,7 +793,7 @@ def get_local_copy(self, filename: str) -> Optional[str]:
In distributed configuration this method should be called on rank 0 process.

Args:
filename (str): artifact name.
filename: artifact name.

Returns:
a local path to a downloaded copy of the artifact
Expand Down
38 changes: 19 additions & 19 deletions ignite/contrib/handlers/lr_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def plot(self, skip_start: int = 10, skip_end: int = 5, log_lr: bool = True) ->
pip install matplotlib

Args:
skip_start (int, optional): number of batches to trim from the start.
skip_start: number of batches to trim from the start.
Default: 10.
skip_end (int, optional): number of batches to trim from the start.
skip_end: number of batches to trim from the start.
Default: 5.
log_lr (bool, optional): True to plot the learning rate in a logarithmic
log_lr: True to plot the learning rate in a logarithmic
scale; otherwise, plotted in a linear scale. Default: True.
"""
try:
Expand Down Expand Up @@ -273,27 +273,27 @@ def attach(
trainer_with_lr_finder.run(dataloader)`

Args:
trainer (Engine): lr_finder is attached to this trainer. Please, keep in mind that all attached handlers
trainer: lr_finder is attached to this trainer. Please, keep in mind that all attached handlers
will be executed.
to_save (Mapping): dictionary with optimizer and other objects that needs to be restored after running
to_save: dictionary with optimizer and other objects that needs to be restored after running
the LR finder. For example, `to_save={'optimizer': optimizer, 'model': model}`. All objects should
implement `state_dict` and `load_state_dict` methods.
output_transform (callable, optional): function that transforms the trainer's `state.output` after each
output_transform: function that transforms the trainer's `state.output` after each
iteration. It must return the loss of that iteration.
num_iter (int, optional): number of iterations for lr schedule between base lr and end_lr. Default, it will
num_iter: number of iterations for lr schedule between base lr and end_lr. Default, it will
run for `trainer.state.epoch_length * trainer.state.max_epochs`.
end_lr (float, optional): upper bound for lr search. Default, 10.0.
step_mode (str, optional): "exp" or "linear", which way should the lr be increased from optimizer's initial
end_lr: upper bound for lr search. Default, 10.0.
step_mode: "exp" or "linear", which way should the lr be increased from optimizer's initial
lr to `end_lr`. Default, "exp".
smooth_f (float, optional): loss smoothing factor in range `[0, 1)`. Default, 0.05
diverge_th (float, optional): Used for stopping the search when `current loss > diverge_th * best_loss`.
smooth_f: loss smoothing factor in range `[0, 1)`. Default, 0.05
diverge_th: Used for stopping the search when `current loss > diverge_th * best_loss`.
Default, 5.0.

Returns:
trainer_with_lr_finder (trainer used for finding the lr)

Note:
lr_finder cannot be attached to more than one trainer at a time.

Returns:
trainer_with_lr_finder: trainer used for finding the lr
"""
if not isinstance(to_save, Mapping):
raise TypeError(f"Argument to_save should be a mapping, but given {type(to_save)}")
Expand Down Expand Up @@ -363,16 +363,16 @@ class _ExponentialLR(_LRScheduler):
iterations.

Args:
optimizer (torch.optim.Optimizer): wrapped optimizer.
end_lr (float, optional): the initial learning rate which is the lower
optimizer: wrapped optimizer.
end_lr: the initial learning rate which is the lower
boundary of the test. Default: 10.
num_iter (int, optional): the number of iterations over which the test
num_iter: the number of iterations over which the test
occurs. Default: 100.
last_epoch (int): the index of last epoch. Default: -1.
last_epoch: the index of last epoch. Default: -1.

"""

def __init__(self, optimizer: Optimizer, end_lr: float, num_iter: int, last_epoch: int = -1) -> None:
def __init__(self, optimizer: Optimizer, end_lr: float, num_iter: int, last_epoch: int = -1):
self.end_lr = end_lr
self.num_iter = num_iter
super(_ExponentialLR, self).__init__(optimizer, last_epoch)
Expand Down
20 changes: 10 additions & 10 deletions ignite/contrib/handlers/mlflow_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MLflowLogger(BaseLogger):
pip install mlflow

Args:
tracking_uri (str): MLflow tracking uri. See MLflow docs for more details
tracking_uri: MLflow tracking uri. See MLflow docs for more details

Examples:

Expand Down Expand Up @@ -86,7 +86,7 @@ class MLflowLogger(BaseLogger):
)
"""

def __init__(self, tracking_uri: Optional[str] = None) -> None:
def __init__(self, tracking_uri: Optional[str] = None):
try:
import mlflow
except ImportError:
Expand Down Expand Up @@ -182,14 +182,14 @@ def global_step_transform(*args, **kwargs):
)

Args:
tag (str): common title for all produced plots. For example, 'training'
metric_names (list of str, optional): list of metric names to plot or a string "all" to plot all available
tag: common title for all produced plots. For example, 'training'
metric_names: list of metric names to plot or a string "all" to plot all available
metrics.
output_transform (callable, optional): output transform function to prepare `engine.state.output` as a number.
output_transform: output transform function to prepare `engine.state.output` as a number.
For example, `output_transform = lambda output: output`
This function can also return a dictionary, e.g `{'loss': loss1, 'another_loss': loss2}` to label the plot
with corresponding keys.
global_step_transform (callable, optional): global step transform function to output a desired global step.
global_step_transform: global step transform function to output a desired global step.
Input of the function is `(engine, event_name)`. Output of function should be an integer.
Default is None, global_step based on attached engine. If provided,
uses function output as global_step. To setup global step from another engine, please use
Expand Down Expand Up @@ -284,13 +284,13 @@ class OptimizerParamsHandler(BaseOptimizerParamsHandler):
)

Args:
optimizer (torch.optim.Optimizer or object): torch optimizer or any object with attribute ``param_groups``
optimizer: torch optimizer or any object with attribute ``param_groups``
as a sequence.
param_name (str): parameter name
tag (str, optional): common title for all produced plots. For example, 'generator'
param_name: parameter name
tag: common title for all produced plots. For example, 'generator'
"""

def __init__(self, optimizer: Optimizer, param_name: str = "lr", tag: Optional[str] = None) -> None:
def __init__(self, optimizer: Optimizer, param_name: str = "lr", tag: Optional[str] = None):
super(OptimizerParamsHandler, self).__init__(optimizer, param_name, tag)

def __call__(self, engine: Engine, logger: MLflowLogger, event_name: Union[str, Events]) -> None:
Expand Down
Loading