Repository navigation
Conversation
Signed-off-by: rangelml <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request prevents potential errors during teardown by checking if the ray module is not None before calling ray.is_initialized() in WandbLoggerCallback.__del__. It also adds a corresponding unit test and refactors the ray_start_2_cpus fixture to be used explicitly. The reviewer suggested a valuable improvement to also check for the existence of _trial_logging_actors using hasattr to avoid AttributeErrors if the object is only partially initialized due to an exception in __init__.
|
|
||
| def __del__(self): | ||
| if ray.is_initialized(): | ||
| if ray is not None and ray.is_initialized(): |
There was a problem hiding this comment.
If WandbLoggerCallback.__init__ raises an exception (for example, if wandb is not installed, which raises a RuntimeError at the very beginning of __init__), the object is only partially initialized. When the garbage collector subsequently calls __del__, accessing self._trial_logging_actors or calling self._cleanup_logging_actors will raise an AttributeError if Ray is initialized. Adding a check for hasattr(self, "_trial_logging_actors") prevents this unraisable exception during cleanup.
| if ray is not None and ray.is_initialized(): | |
| if ray is not None and ray.is_initialized() and hasattr(self, "_trial_logging_actors"): |
Address review feedback: if __init__ raises (e.g. wandb is not installed), __del__ would hit AttributeError on missing attributes. Signed-off-by: rangelml <[email protected]>
Description
Why are these changes needed?
Python can clear the W&B integration's
raymodule reference before finalizingWandbLoggerCallback. This currently raises an unraisableAttributeErrorand skips clearing the callback's bookkeeping. Guard access to the Ray runtime so the callback can finish local cleanup.Related issues
Related issue number
Closes #39332
The issue is unassigned. Searches for the issue number and W&B teardown keywords found no competing open PR.
Additional information
The focused regression failed on
upstream/masterwith the reportedAttributeErrorand passed with the fix.The W&B integration test file passed (22 tests). From the checkout, with the matching Ray wheel and the
airandtestspackages linked to source, the command was:../.venv/bin/python -c 'import sys; import ray; import pytest; sys.exit(pytest.main(sys.argv[1:]))' -q python/ray/air/tests/test_integration_wandb.pyRuff, Black, and the applicable pre-commit hooks passed.
AI assistance was used for triage, implementation, and testing.