fix: Gracefully shutdown multiprocessing.Manager and fix proxy resource leaks#83
fix: Gracefully shutdown multiprocessing.Manager and fix proxy resource leaks#83Leahlijuan wants to merge 6 commits intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical resource management issues that led to 'Finalize object, dead' errors and Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces teardown methods across several classes to gracefully shut down multiprocessing resources, addressing resource leaks by reusing proxy objects from the multiprocessing manager. The changes are logical and well-supported by new and updated tests. My review includes a few suggestions to enhance code clarity and robustness, primarily by making attribute existence checks more explicit and readable.
| self._storage_writer = MemoryStorageWriter( | ||
| checkpoint_saver=self._checkpoint_saver, | ||
| mp_manager_future=self._storage_writer._main_process_torchmp_manager_future, | ||
| thread_count=self._storage_writer._thread_count, | ||
| ) |
There was a problem hiding this comment.
For improved readability, consider using the old_storage_writer variable when creating the new MemoryStorageWriter instance. While the current code is functionally correct because self._storage_writer still refers to the old instance at that point, explicitly using old_storage_writer makes the intent clearer and less prone to misinterpretation during future maintenance.
| self._storage_writer = MemoryStorageWriter( | |
| checkpoint_saver=self._checkpoint_saver, | |
| mp_manager_future=self._storage_writer._main_process_torchmp_manager_future, | |
| thread_count=self._storage_writer._thread_count, | |
| ) | |
| self._storage_writer = MemoryStorageWriter( | |
| checkpoint_saver=self._checkpoint_saver, | |
| mp_manager_future=old_storage_writer._main_process_torchmp_manager_future, | |
| thread_count=old_storage_writer._thread_count, | |
| ) |
| self.fallback_checkpoint_io.remove_checkpoint(path) | ||
|
|
||
| @log_execution_time(logger=_LOGGER, name="MLFlashpointCheckpointIO.teardown", level=logging.INFO) | ||
| def teardown(self) -> None: |
There was a problem hiding this comment.
where is this invoked btw?
There was a problem hiding this comment.
inside the teardown of MLFlashpointAsyncFinalizableCheckpointIO
| try: | ||
| manager = self._main_process_torchmp_manager_future.result(timeout=1.0) | ||
| _LOGGER.info("Shutting down torch_mp Manager...") | ||
| manager.shutdown() |
There was a problem hiding this comment.
what if the call above times out, this will fail right? what value will manager hold
There was a problem hiding this comment.
if it timeout, will get timeout exception and caught by line 403, then the manager.shutdown() would be skipped
Python Code Coverage Summary
Minimum allowed line rate is |
C++ Code Coverage Summary
Minimum allowed line rate is |
This change resolves a "Finalize object, dead" error and FileNotFoundError that occurred during the teardown phase of training, particularly after many steps.
_write_events_per_checkpoint_idand_write_results_per_checkpoint_idproxy dictionaries across MemoryStorageWriterpop()forEventobjects inMemoryStorageWriter.finish_checkpointto allow them to be properly garbage collected.