docs: add warmup scheduler mixed-events example#3753
Conversation
|
|
||
| epoch_length = 8 | ||
| combined_events = Events.ITERATION_STARTED( | ||
| event_filter=lambda engine, event: engine.state.iteration <= 5 |
There was a problem hiding this comment.
| event_filter=lambda engine, event: engine.state.iteration <= 5 | |
| event_filter=lambda engine, event: event <= 5 |
We already have the count inside event
|
@vfdev-5 This PR solves the documentation issue. However, I think I agree with #2441 pushback on maybe this needs an API fix. Currently, we are teaching the user to do the math on when to switch. It would be better if this logic can be internal to improve user experience. Something like: scheduler = create_lr_scheduler_with_warmup(
torch_lr_scheduler,
warmup_duration=5,
warmup_event=Events.ITERATION_STARTED,
post_warmup_event=Events.EPOCH_STARTED
)
# The scheduler would internally handle the event-switching logic.
trainer.add_event_handler(Events.ITERATION_STARTED | Events.EPOCH_STARTED, scheduler) |
|
Thanks for calling that out. I agree the more ergonomic long-term answer is probably an API improvement so users do not need to manually compute the switch point. I kept this PR narrowly scoped to the current docs issue because it only documents the behavior that exists today, but I’m happy for maintainers to treat the API direction separately if that’s preferred. |
| optimizer = SGD([torch.zeros(1, requires_grad=True)], lr=0.1) | ||
| torch_lr_scheduler = ExponentialLR(optimizer, gamma=0.5) | ||
| scheduler = create_lr_scheduler_with_warmup( | ||
| torch_lr_scheduler, warmup_start_value=0.0, warmup_duration=5 |
There was a problem hiding this comment.
let's first define the variable warmup_duration=5 and then use it rather than the raw values themselves.
There was a problem hiding this comment.
Thanks for the review — updated this to keep the change docs-only, define warmup_duration = 5, and reuse it in the scheduler and event filters.
|
@nightcityblade let us keep this PR to update the docs for now. if you feel that this needs an API change in the future you can also give your reasoning on the original issue and the maintainer can decide if we need it or not. Kindly update the PR with the changes requested. |
|
Thanks again. I re-checked the open review threads and the current branch keeps this docs-only while addressing the requested changes: it defines |
vfdev-5
left a comment
There was a problem hiding this comment.
Looks good to me
@TahaZahid05 I let you approve and merge it if good to you as well
Fixes #2441
Description:
Adds a docstring example showing how to combine Ignite event filters so warm-up runs on iteration starts and the wrapped scheduler runs on later epoch starts.
Check list: