Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure checkpoint files are written immediately after evaluation completes. #376

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions langfun/core/eval/v2/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def save_state(example: Example):
)
)
writer.add(example)
del writer
writer.close()
runner.background_run(save_state, example)

def _file_prefix_and_ext(self, filename: str) -> tuple[str, str]:
Expand Down Expand Up @@ -128,6 +128,8 @@ def on_run_abort(
) -> None:
with self._lock:
if self._sequence_writer is not None:
for writer in self._sequence_writer.values():
writer.close()
self._sequence_writer.clear()

def on_run_complete(
Expand Down Expand Up @@ -174,6 +176,9 @@ def on_experiment_complete(
assert experiment.id in self._sequence_writer
with self._lock:
if self._sequence_writer is not None:
# Make sure the writer is closed without delay so the file will be
# available immediately.
self._sequence_writer[experiment.id].close()
del self._sequence_writer[experiment.id]

def on_example_complete(
Expand Down Expand Up @@ -207,9 +212,13 @@ def add(self, example: Example):
return
self._sequence_writer.add(example_blob)

def __del__(self):
def close(self):
# Make sure there is no write in progress.
with self._lock:
assert self._sequence_writer is not None
if self._sequence_writer is None:
return
self._sequence_writer.close()
self._sequence_writer = None

def __del__(self):
self.close()
Loading