[BE]: TRY002 - Ban raising vanilla exceptions (#124570)

Adds a ruff lint rule to ban raising raw exceptions. Most of these should at the very least be runtime exception, value errors, type errors or some other errors. There are hundreds of instance of these bad exception types already in the codebase, so I have noqa'd most of them. Hopefully this error code will get commiters to rethink what exception type they should raise when they submit a PR.

I also encourage people to gradually go and fix all the existing noqas that have been added so they can be removed overtime and our exception typing can be improved.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/124570
Approved by: https://github.com/ezyang
This commit is contained in:
Aaron Gokaslan
2024-04-21 22:26:40 +00:00
committed by PyTorch MergeBot
parent fd90991790
commit c5fafe9f48
82 changed files with 263 additions and 210 deletions

View File

@ -46,7 +46,9 @@ def get_collective_type(node: ir.IRNode) -> NCCL_COLL:
elif "reduce_scatter" in kernel_name:
return NCCL_COLL.REDUCE_SCATTER
else:
raise Exception(f"Unsupported collective kernel: {kernel_name}")
raise Exception( # noqa: TRY002
f"Unsupported collective kernel: {kernel_name}"
) # noqa: TRY002
if isinstance(node, (ir.AllReduce, ir.AllReduceCoalesced)):
return NCCL_COLL.ALL_REDUCE
@ -55,7 +57,7 @@ def get_collective_type(node: ir.IRNode) -> NCCL_COLL:
elif isinstance(node, (ir.ReduceScatterTensor, ir.ReduceScatterTensorCoalesced)):
return NCCL_COLL.REDUCE_SCATTER
else:
raise Exception(f"Unsupported collective type: {node}")
raise Exception(f"Unsupported collective type: {node}") # noqa: TRY002
def get_collective_input_size_bytes(node: ir.IRNode) -> int: