Skip to content
Merged
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
11 changes: 5 additions & 6 deletions ignite/handlers/ema_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import warnings
from copy import deepcopy
from typing import Optional, Union

import torch.nn as nn

Expand Down Expand Up @@ -152,16 +151,16 @@ def __init__(
self,
model: nn.Module,
momentum: float = 0.0002,
momentum_warmup: Optional[float] = None,
warmup_iters: Optional[int] = None,
momentum_warmup: float | None = None,
warmup_iters: int | None = None,
handle_buffers: str = "copy",
) -> None:
if not 0 < momentum < 1:
raise ValueError(f"Invalid momentum: {momentum}")
self.momentum = momentum
self._momentum_lambda_obj: Optional[EMAWarmUp] = None
self._momentum_lambda_obj: EMAWarmUp | None = None
if momentum_warmup is not None and warmup_iters is not None:
self.momentum_scheduler: Optional[BaseParamScheduler] = None
self.momentum_scheduler: BaseParamScheduler | None = None
self._momentum_lambda_obj = EMAWarmUp(momentum_warmup, warmup_iters, momentum)

if not isinstance(model, nn.Module):
Expand Down Expand Up @@ -216,7 +215,7 @@ def attach(
engine: Engine,
name: str = "ema_momentum",
warn_if_exists: bool = True,
event: Union[str, Events, CallableEventWithFilter, EventsList] = Events.ITERATION_COMPLETED,
event: str | Events | CallableEventWithFilter | EventsList = Events.ITERATION_COMPLETED,
) -> None:
"""Attach the handler to engine. After the handler is attached, the ``Engine.state`` will add an new attribute
with name ``name`` if the attribute does not exist. Then, the current momentum can be retrieved from
Expand Down
Loading