-
-
Notifications
You must be signed in to change notification settings - Fork 692
Make work EMAHandler with state parameter scheduler #2295
Copy link
Copy link
Closed
Labels
Description
🚀 Feature
I'd like to make custom EMA decay scheduling with, for example, PiecewiseLinearStateScheduler. Here is failing code:
import ignite
from ignite.engine import Engine, Events
from ignite.handlers import PiecewiseLinearStateScheduler, EMAHandler
import torch
import torch.nn as nn
import matplotlib.pyplot as plt
%matplotlib inline
print(ignite.__version__)
model = nn.Linear(2, 1)
trainer = Engine(lambda e, b: model(b))
data = torch.rand(100, 2)
param_name = "ema_decay"
ema_handler = EMAHandler(model)
ema_handler.attach(trainer, name=param_name, event=Events.ITERATION_COMPLETED)
ema_decay_scheduler = PiecewiseLinearStateScheduler(
param_name=param_name,
milestones_values=[(0, 0.0), (10 * len(data), 0.999)]
)
ema_decay_scheduler.attach(trainer, Events.ITERATION_COMPLETED)
ema_decay_history = []
engine.add_event_handler(Events.EPOCH_COMPLETED, lambda _ : ema_decay_history.append(engine.state.ema_decay))
engine.run(data, max_epochs=20)it gives:
ValueError: Attribute: 'ema_decay' is already defined in the Engine.state.This may be a conflict between multiple StateParameterScheduler handlers.Please choose another name.By the way, error message is missing spaces between sentences.
cc @sandylaker
Reactions are currently unavailable