Skip to content

Commit a69004e

Browse files
authored
[Core][Channel] Fix the exception type for accelerator ID visibility check in accelerator_context.py (ray-project#58269)
## Description - Change the caught exception type from IndexError to TypeError - This modification ensures that the correct exception is raised when the expected accelerator ID is not included in the accelerator_visible_list `list.index` will raise a [ValueError](https://docs.python.org/3/library/exceptions.html#ValueError) if there is no such item. https://docs.python.org/3/tutorial/datastructures.html <img width="797" height="79" alt="image" src="https://github.com/user-attachments/assets/830cf4aa-d9cb-44d3-9363-8e5cd576bae9" /> Now, the error logs will be correctly captured and printed. <img width="1454" height="143" alt="image" src="https://github.com/user-attachments/assets/2b0ed0aa-60c7-49c3-84b0-7f0d4f1ebe48" /> Signed-off-by: daiping8 <dai.ping88@zte.com.cn>
1 parent 966cc94 commit a69004e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

python/ray/experimental/channel/accelerator_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get_accelerator_devices(self) -> List["torch.device"]:
135135
for accelerator_id in accelerator_ids:
136136
try:
137137
device_ids.append(accelerator_visible_list.index(accelerator_id))
138-
except IndexError:
138+
except ValueError:
139139
raise RuntimeError(
140140
f"{accelerator_manager.get_visible_accelerator_ids_env_var()} set incorrectly. "
141141
f"expected to include {accelerator_id}. "

0 commit comments

Comments
 (0)