-
Notifications
You must be signed in to change notification settings - Fork 3
Implement a fail save init function #804
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
Changes from all commits
3a8f7e2
3530cf5
e3e00f8
07daae3
bd190d6
bc18718
8754881
6163cca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -226,10 +226,14 @@ def _execute_multiple_tasks( | |||||||||||||||||||||||||||||||||||||||||||||||||
| log_obj_size=log_obj_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| worker_id=worker_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface_initialization_exception = None | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if init_function is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface.send_dict( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| input_dict={"init": True, "fn": init_function, "args": (), "kwargs": {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = interface.send_and_receive_dict( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| input_dict={"init": True, "fn": init_function, "args": (), "kwargs": {}} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as init_exception: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface_initialization_exception = init_exception | ||||||||||||||||||||||||||||||||||||||||||||||||||
| while True: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| task_dict = future_queue.get() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if "shutdown" in task_dict and task_dict["shutdown"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -240,12 +244,15 @@ def _execute_multiple_tasks( | |||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elif "fn" in task_dict and "future" in task_dict: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| f = task_dict.pop("future") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| execute_task_dict( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| task_dict=task_dict, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| future_obj=f, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface=interface, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cache_directory=cache_directory, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cache_key=cache_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| error_log_file=error_log_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if interface_initialization_exception is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| f.set_exception(exception=interface_initialization_exception) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| execute_task_dict( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| task_dict=task_dict, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| future_obj=f, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface=interface, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cache_directory=cache_directory, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cache_key=cache_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| error_log_file=error_log_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+247
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Respect cancellation before setting exception to avoid InvalidStateError Setting an exception on a cancelled Future can raise InvalidStateError and break the worker loop. Mirror execute_task_dict’s pattern. - if interface_initialization_exception is not None:
- f.set_exception(exception=interface_initialization_exception)
+ if interface_initialization_exception is not None:
+ if (not f.done()) and f.set_running_or_notify_cancel():
+ f.set_exception(interface_initialization_exception)
else:
execute_task_dict(
task_dict=task_dict,
future_obj=f,
interface=interface,
cache_directory=cache_directory,
cache_key=cache_key,
error_log_file=error_log_file,
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| task_done(future_queue=future_queue) | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: init failures on non-root ranks are ignored; client may receive success
If any non-root rank raises during init, rank 0 still sends {"result": True}. This leaves ranks with divergent memory and hides failures.
Aggregate errors across ranks and only acknowledge success if all ranks succeeded. Example patch:
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.12.2)
104-104: Do not catch blind exception:
Exception(BLE001)