Skip to content

Allow downstream users to suppress Save Optimizer warnings #46405

Description

@jsrozner

🚀 Feature

Enable downstream users of this library to suppress lr_scheduler save_state_warning. (Propose to add an argument to LambdaLR [torch/optim/lr_scheduler.py])

If set to true, the warnings.warn(SAVE_STATE_WARNING, user_warning) that prints "Please also save or load the state of the optimizer when saving or loading the scheduler." will not be generated.

Motivation

Various bugs / discussions exist because users of various libraries are confused by this warning. Huggingface recently pushed a change to catch and suppress this warning.

Recent Pytorch discussion

Huggingface issue

Huggingface solution to deal with "the annoying warning"

Pitch

Propose to add an argument to LambdaLR torch/optim/lr_scheduler.py

  • state_dict(..., suppress_state_warning=False)
  • load_state_dict(..., suppress_state_warning=False)

Default false preserves the warning for everyone, except those who explicitly choose to set the flag, presumably because they have appropriately saved the optimizer.

Alternatives

Huggingface implemented a wrapper to catch and suppress the warning but this is fragile.

Concerns

Maybe there's some plumbing that should be updated to use this new flag, but once we provide the option to use the flag, others can begin implementing on their own.

cc @vincentqb

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: optimizerRelated to torch.optimtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions