Repository navigation
Fix checkpoint history saving to file-like objects - #1179
Closed
mottopanikeiku wants to merge 1 commit into
Closed
mottopanikeiku wants to merge 1 commit into
mottopanikeiku wants to merge 1 commit into
Conversation
I found that checkpoint history saving treated file-like objects as filename strings and raised a TypeError. I now preserve non-string history targets so both Checkpoint and TrainEndCheckpoint can write to them. I added regression tests for both callbacks with and without filename prefixes. Assisted-by: Claude Assisted-by: GPT-6 Astra Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
Collaborator
|
Thanks for the PR. As maintainers of skorch, we decided to update the status of the skorch project. As a consequence, we will close this PR. Your effort is still appreciated. |
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.
Checkpoint'sf_historyis documented to accept a file-like object, butCheckpoint.f_history_only special-casesNoneand otherwise doesos.path.join(self.dirname, self.fn_prefix + self.f_history). With an open file this raisesTypeError: can only concatenate str (not "_io.TextIOWrapper") to strduringfit;TrainEndCheckpointfails the same way at the end of training. I found this by reading and testing the checkpoint code.I return non-string targets unchanged, the same way
_format_targetalready treatsf_params,f_optimizerand the other targets. String names still getdirnameandfn_prefix, andNonestill means no history file.Checkpoint(f_history=<open file>)TypeErrorduringfitTrainEndCheckpoint(f_history=<open file>)TypeErrorat train endTests:
test_save_history_to_file_likefor bothTestCheckpointandTestTrainEndCheckpoint, with and withoutfn_prefix. They fit a small net, check the callback keeps the given file object, and reload the saved history withload_params. All 4 fail on master and pass with the fix; the wholeskorch/tests/callbacks/test_training.pypasses (88). flake8 reports nothing on the changed lines. I also added an entry to CHANGES.md.Related: #870 touches the same property (callable directory names) but doesn't handle file-like targets.
I made this PR and directed its development, with AI assistance from Claude and GPT-6 Astra.