Fix state_dict handling for max_iters in Engine#3729
Open
TahaZahid05 wants to merge 8 commits intopytorch:masterfrom
Open
Fix state_dict handling for max_iters in Engine#3729TahaZahid05 wants to merge 8 commits intopytorch:masterfrom
TahaZahid05 wants to merge 8 commits intopytorch:masterfrom
Conversation
a0cac99 to
4fefdb6
Compare
5ce98fc to
6e60bfc
Compare
vfdev-5
reviewed
Apr 10, 2026
Collaborator
Author
|
@vfdev-5 done! |
vfdev-5
reviewed
Apr 10, 2026
vfdev-5
reviewed
Apr 10, 2026
vfdev-5
reviewed
Apr 10, 2026
vfdev-5
reviewed
Apr 10, 2026
vfdev-5
reviewed
Apr 10, 2026
vfdev-5
reviewed
Apr 10, 2026
More descriptive way to show tuple of tuples Co-authored-by: vfdev <vfdev.5@gmail.com>
Collaborator
|
Yes, it is fine, let's provide appropriate type hint for the structure
…On Sat, Apr 11, 2026, 21:49 Taha Zahid ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In tests/ignite/base/test_mixins.py
<#3729 (comment)>:
> + s.load_state_dict({"a": 1, "b": 2})
+
+ # Test one-of optional keys - having all from one group
+ with pytest.raises(ValueError, match=r"should contain only one of '\('c', 'd'\)'"):
+ s.load_state_dict({"a": 1, "b": 2, "c": 3, "d": 4, "e": 5})
+
+ # Test one-of optional keys - having all from another group
+ with pytest.raises(ValueError, match=r"should contain only one of '\('e', 'f'\)'"):
+ s.load_state_dict({"a": 1, "b": 2, "c": 3, "e": 5, "f": 6})
+
+ # Valid state dict
+ s.load_state_dict({"a": 1, "b": 2, "c": 3, "e": 5})
+ print("Valid state dict loaded successfully")
+
+
+def test_empty_optional_groups():
@vfdev-5 <https://github.com/vfdev-5> If we raise error for
_state_dict_one_of_opt_keys containing empty tuples then we should also
change its initialization to a single tuple as well for it to pass the
test? Is that fine?
# _state_dict_one_of_opt_keys: tuple = ((),)
_state_dict_one_of_opt_keys: tuple = ()
—
Reply to this email directly, view it on GitHub
<#3729 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASYOH7G6AKEJFLSUMD2POL4VKOTNAVCNFSM6AAAAACXTJ6XTKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DAOJUGE2TIMZUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1521
Description:
This PR builds up on #3439 to implement
max_itershandling in state serialization and deserialization duringEngineruns.Key Changes:
Engine.state_dict()now correctly exports exactly one ofmax_itersormax_epochsdepending on which condition theEnginerun was configured with._state_dict_one_of_opt_keysto accept groups of mutually exclusive requirements, enablingEngine.load_state_dict()to cleanly accept eitheriteration/max_itersorepoch/max_epochsand correctly continue the engine's resume state from either.Engineto prevent loading impossible future iterations while safely resuming training.Check list: