Skip to content

Commit 56c3cf5

Browse files
committed
Revert "Remove all deprecated args, kwargs for v0.5.0 (#1396) (#1397)"
This reverts commit a85da62.
1 parent b5d215e commit 56c3cf5

File tree

8 files changed

+90
-6
lines changed

8 files changed

+90
-6
lines changed

ignite/contrib/engines/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def setup_common_training_handlers(
4949
with_pbars: bool = True,
5050
with_pbar_on_iters: bool = True,
5151
log_every_iters: int = 100,
52+
device: Optional[Union[str, torch.device]] = None,
5253
stop_on_nan: bool = True,
5354
clear_cuda_cache: bool = True,
5455
save_handler: Optional[Union[Callable, BaseSaveHandler]] = None,
@@ -92,7 +93,10 @@ def setup_common_training_handlers(
9293
class to use to store ``to_save``. See :class:`~ignite.handlers.checkpoint.Checkpoint` for more details.
9394
Argument is mutually exclusive with ``output_path``.
9495
kwargs: optional keyword args to be passed to construct :class:`~ignite.handlers.checkpoint.Checkpoint`.
96+
device: deprecated argument, it will be removed in v0.5.0.
9597
"""
98+
if device is not None:
99+
warnings.warn("Argument device is unused and deprecated. It will be removed in v0.5.0")
96100

97101
if idist.get_world_size() > 1:
98102
_setup_common_distrib_training_handlers(

ignite/engine/engine.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def state_dict_user_keys(self) -> List:
649649
return self._state_dict_user_keys
650650

651651
def state_dict(self) -> OrderedDict:
652-
"""Returns a dictionary containing engine's state: "epoch_length", "max_epochs" and "iteration" and
652+
"""Returns a dictionary containing engine's state: "seed", "epoch_length", "max_epochs" and "iteration" and
653653
other state values defined by `engine.state_dict_user_keys`
654654
655655
.. code-block:: python
@@ -682,8 +682,8 @@ def save_engine(_):
682682
def load_state_dict(self, state_dict: Mapping) -> None:
683683
"""Setups engine from `state_dict`.
684684
685-
State dictionary should contain keys: `iteration` or `epoch`, `max_epochs` and `epoch_length`.
686-
If `engine.state_dict_user_keys` contains keys, they should be also present in the state dictionary.
685+
State dictionary should contain keys: `iteration` or `epoch` and `max_epochs`, `epoch_length` and
686+
`seed`. If `engine.state_dict_user_keys` contains keys, they should be also present in the state dictionary.
687687
Iteration and epoch values are 0-based: the first iteration or epoch is zero.
688688
689689
This method does not remove any custom attributes added by user.
@@ -782,12 +782,13 @@ def run(
782782
max_epochs: Optional[int] = None,
783783
max_iters: Optional[int] = None,
784784
epoch_length: Optional[int] = None,
785+
seed: Optional[int] = None,
785786
) -> State:
786787
"""Runs the ``process_function`` over the passed data.
787788
788789
Engine has a state and the following logic is applied in this function:
789790
790-
- At the first call, new state is defined by `max_epochs`, `max_iters`, `epoch_length`, if provided.
791+
- At the first call, new state is defined by `max_epochs`, `max_iters`, `epoch_length`, `seed`, if provided.
791792
A timer for total and per-epoch time is initialized when Events.STARTED is handled.
792793
- If state is already defined such that there are iterations to run until `max_epochs` and no input arguments
793794
provided, state is kept and used in the function.
@@ -807,6 +808,7 @@ def run(
807808
This argument should not change if run is resuming from a state.
808809
max_iters: Number of iterations to run for.
809810
`max_iters` and `max_epochs` are mutually exclusive; only one of the two arguments should be provided.
811+
seed: Deprecated argument. Please, use `torch.manual_seed` or :meth:`~ignite.utils.manual_seed`.
810812
811813
Returns:
812814
State: output state.
@@ -835,6 +837,12 @@ def switch_batch(engine):
835837
trainer.run(train_loader, max_epochs=2)
836838
837839
"""
840+
if seed is not None:
841+
warnings.warn(
842+
"Argument seed is deprecated. It will be removed in 0.5.0. "
843+
"Please, use torch.manual_seed or ignite.utils.manual_seed"
844+
)
845+
838846
if data is not None and not isinstance(data, Iterable):
839847
raise TypeError("Argument data should be iterable")
840848

ignite/engine/events.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,18 @@ def __or__(self, other: Any) -> "EventsList":
203203
return EventsList() | self | other
204204

205205

206-
class EventEnum(CallableEventWithFilter, Enum):
206+
class CallableEvents(CallableEventWithFilter):
207+
# For backward compatibility
208+
def __init__(self, *args: Any, **kwargs: Any) -> None:
209+
super(CallableEvents, self).__init__(*args, **kwargs)
210+
warnings.warn(
211+
"Class ignite.engine.events.CallableEvents is deprecated. It will be removed in 0.5.0. "
212+
"Please, use ignite.engine.EventEnum instead",
213+
DeprecationWarning,
214+
)
215+
216+
217+
class EventEnum(CallableEventWithFilter, Enum): # type: ignore[misc]
207218
"""Base class for all :class:`~ignite.engine.events.Events`. User defined custom events should also inherit
208219
this class.
209220

ignite/handlers/checkpoint.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Checkpoint(Serializable):
102102
Input of the function is ``(engine, event_name)``. Output of function should be an integer.
103103
Default is None, global_step based on attached engine. If provided, uses function output as global_step.
104104
To setup global step from another engine, please use :meth:`~ignite.handlers.global_step_from_engine`.
105+
archived: Deprecated argument as models saved by ``torch.save`` are already compressed.
105106
filename_pattern: If ``filename_pattern`` is provided, this pattern will be used to render
106107
checkpoint filenames. If the pattern is not defined, the default pattern would be used. See Note for
107108
details.
@@ -288,6 +289,7 @@ def __init__(
288289
score_name: Optional[str] = None,
289290
n_saved: Union[int, None] = 1,
290291
global_step_transform: Optional[Callable] = None,
292+
archived: bool = False,
291293
filename_pattern: Optional[str] = None,
292294
include_self: bool = False,
293295
greater_or_equal: bool = False,
@@ -319,6 +321,8 @@ def __init__(
319321

320322
if global_step_transform is not None and not callable(global_step_transform):
321323
raise TypeError(f"global_step_transform should be a function, got {type(global_step_transform)} instead.")
324+
if archived:
325+
warnings.warn("Argument archived is deprecated and will be removed in 0.5.0")
322326

323327
self.to_save = to_save
324328
self.filename_prefix = filename_prefix
@@ -880,6 +884,11 @@ class ModelCheckpoint(Checkpoint):
880884
881885
Behaviour of this class has been changed since v0.3.0.
882886
887+
Argument ``save_as_state_dict`` is deprecated and should not be used. It is considered as True.
888+
889+
Argument ``save_interval`` is deprecated and should not be used. Please, use events filtering instead, e.g.
890+
:attr:`~ignite.engine.events.Events.ITERATION_STARTED(every=1000)`
891+
883892
There is no more internal counter that has been used to indicate the number of save actions. User could
884893
see its value `step_number` in the filename, e.g. `{filename_prefix}_{name}_{step_number}.pt`. Actually,
885894
`step_number` is replaced by current engine's epoch if `score_function` is specified and current iteration
@@ -908,6 +917,7 @@ class ModelCheckpoint(Checkpoint):
908917
Input of the function is `(engine, event_name)`. Output of function should be an integer.
909918
Default is None, global_step based on attached engine. If provided, uses function output as global_step.
910919
To setup global step from another engine, please use :meth:`~ignite.handlers.global_step_from_engine`.
920+
archived: Deprecated argument as models saved by `torch.save` are already compressed.
911921
filename_pattern: If ``filename_pattern`` is provided, this pattern will be used to render
912922
checkpoint filenames. If the pattern is not defined, the default pattern would be used.
913923
See :class:`~ignite.handlers.checkpoint.Checkpoint` for details.
@@ -954,19 +964,39 @@ def __init__(
954964
self,
955965
dirname: Union[str, Path],
956966
filename_prefix: str = "",
967+
save_interval: Optional[Callable] = None,
957968
score_function: Optional[Callable] = None,
958969
score_name: Optional[str] = None,
959970
n_saved: Union[int, None] = 1,
960971
atomic: bool = True,
961972
require_empty: bool = True,
962973
create_dir: bool = True,
974+
save_as_state_dict: bool = True,
963975
global_step_transform: Optional[Callable] = None,
976+
archived: bool = False,
964977
filename_pattern: Optional[str] = None,
965978
include_self: bool = False,
966979
greater_or_equal: bool = False,
967980
save_on_rank: int = 0,
968981
**kwargs: Any,
969982
):
983+
if not save_as_state_dict:
984+
raise ValueError(
985+
"Argument save_as_state_dict is deprecated and should be True."
986+
"This argument will be removed in 0.5.0."
987+
)
988+
if save_interval is not None:
989+
msg = (
990+
"Argument save_interval is deprecated and should be None. This argument will be removed in 0.5.0."
991+
"Please, use events filtering instead, e.g. Events.ITERATION_STARTED(every=1000)"
992+
)
993+
if save_interval == 1:
994+
# Do not break for old version who used `save_interval=1`
995+
warnings.warn(msg)
996+
else:
997+
# No choice
998+
raise ValueError(msg)
999+
9701000
disk_saver = DiskSaver(
9711001
dirname,
9721002
atomic=atomic,
@@ -985,6 +1015,7 @@ def __init__(
9851015
n_saved=n_saved,
9861016
global_step_transform=global_step_transform,
9871017
filename_pattern=filename_pattern,
1018+
archived=archived,
9881019
include_self=include_self,
9891020
greater_or_equal=greater_or_equal,
9901021
save_on_rank=save_on_rank,

tests/ignite/contrib/engines/test_common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def test_asserts_setup_common_training_handlers():
164164
)
165165
trainer.run([1])
166166

167+
with pytest.warns(UserWarning, match=r"Argument device is unused and deprecated"):
168+
setup_common_training_handlers(trainer, device="cpu")
169+
167170

168171
def test_no_warning_with_train_sampler(recwarn):
169172
from torch.utils.data import RandomSampler

tests/ignite/engine/test_custom_events.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66

77
import ignite.distributed as idist
88
from ignite.engine import Engine, Events
9-
from ignite.engine.events import CallableEventWithFilter, EventEnum, EventsList
9+
from ignite.engine.events import CallableEvents, CallableEventWithFilter, EventEnum, EventsList
10+
11+
12+
def test_deprecated_callable_events_class():
13+
engine = Engine(lambda engine, batch: 0)
14+
15+
with pytest.warns(DeprecationWarning, match=r"Class ignite\.engine\.events\.CallableEvents is deprecated"):
16+
17+
class CustomEvents(CallableEvents, Enum):
18+
TEST_EVENT = "test_event"
19+
20+
with pytest.raises(TypeError, match=r"Value at \d of event_names should be a str or EventEnum"):
21+
engine.register_events(*CustomEvents)
1022

1123

1224
def test_custom_events():

tests/ignite/engine/test_engine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ def test_run_asserts(self):
518518
with pytest.raises(ValueError, match=r"Input data has zero size. Please provide non-empty data"):
519519
engine.run([])
520520

521+
with pytest.warns(UserWarning, match="Argument seed is deprecated"):
522+
engine.run([0, 1, 2, 3, 4], seed=1234)
523+
521524
def test_state_get_event_attrib_value(self):
522525
state = State()
523526
state.iteration = 10

tests/ignite/handlers/test_checkpoint.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def test_checkpoint_wrong_input():
6565
with pytest.raises(TypeError, match=r"global_step_transform should be a function."):
6666
Checkpoint(to_save, lambda x: x, score_function=lambda e: 123, score_name="acc", global_step_transform=123)
6767

68+
with pytest.warns(UserWarning, match=r"Argument archived is deprecated"):
69+
Checkpoint(to_save, lambda x: x, score_function=lambda e: 123, score_name="acc", archived=True)
70+
6871
with pytest.raises(ValueError, match=r"Cannot have key 'checkpointer' if `include_self` is True"):
6972
Checkpoint({"checkpointer": model}, lambda x: x, include_self=True)
7073

@@ -556,12 +559,21 @@ def test_model_checkpoint_args_validation(dirname):
556559
with pytest.raises(ValueError, match=r"with extension '.pt' are already present "):
557560
ModelCheckpoint(nonempty, _PREFIX)
558561

562+
with pytest.raises(ValueError, match=r"Argument save_interval is deprecated and should be None"):
563+
ModelCheckpoint(existing, _PREFIX, save_interval=42)
564+
559565
with pytest.raises(ValueError, match=r"Directory path '\S+' is not found"):
560566
ModelCheckpoint(dirname / "non_existing_dir", _PREFIX, create_dir=False)
561567

568+
with pytest.raises(ValueError, match=r"Argument save_as_state_dict is deprecated and should be True"):
569+
ModelCheckpoint(existing, _PREFIX, create_dir=False, save_as_state_dict=False)
570+
562571
with pytest.raises(TypeError, match=r"global_step_transform should be a function"):
563572
ModelCheckpoint(existing, _PREFIX, create_dir=False, global_step_transform=1234)
564573

574+
with pytest.warns(UserWarning, match=r"Argument archived is deprecated"):
575+
ModelCheckpoint(existing, _PREFIX, create_dir=False, archived=True)
576+
565577
h = ModelCheckpoint(dirname, _PREFIX, create_dir=False)
566578
assert h.last_checkpoint is None
567579
with pytest.raises(RuntimeError, match=r"No objects to checkpoint found."):

0 commit comments

Comments
 (0)