mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
More ruff SIM fixes (#164695)
This PR applies ruff `SIM` rules to more files. Most changes are about simplifying `dict.get` because `None` is already the default value. Pull Request resolved: https://github.com/pytorch/pytorch/pull/164695 Approved by: https://github.com/ezyang
This commit is contained in:
committed by
PyTorch MergeBot
parent
54ae61c573
commit
a029675f6f
@ -190,12 +190,12 @@ def map_job_data(jobNames: Any, shaGrid: Any) -> dict[str, Any]:
|
||||
|
||||
|
||||
def is_job_failed(job: Any) -> bool:
|
||||
conclusion = job["conclusion"] if "conclusion" in job else None
|
||||
conclusion = job.get("conclusion", None)
|
||||
return conclusion is not None and conclusion != SUCCESS and conclusion != PENDING
|
||||
|
||||
|
||||
def is_job_skipped(job: Any) -> bool:
|
||||
conclusion = job["conclusion"] if "conclusion" in job else None
|
||||
conclusion = job.get("conclusion", None)
|
||||
return conclusion in (NEUTRAL, SKIPPED) or conclusion is None
|
||||
|
||||
|
||||
|
@ -340,7 +340,7 @@ def get_base_name(f: NativeFunction) -> str:
|
||||
|
||||
def get_view_info(f: NativeFunction) -> str | None:
|
||||
base_name = get_base_name(f)
|
||||
view_info = VIEW_FUNCTIONS.get(base_name, None)
|
||||
view_info = VIEW_FUNCTIONS.get(base_name)
|
||||
if view_info is None and base_name in RETURNS_VIEWS_OF_INPUT:
|
||||
view_info = "self"
|
||||
return view_info
|
||||
|
@ -30,7 +30,7 @@ cov_data = CoverageData(basename=f".coverage.jit.{time()}")
|
||||
|
||||
|
||||
def is_not_builtin_class(obj: Any) -> bool:
|
||||
return isclass(obj) and not type(obj).__module__ == "builtins"
|
||||
return isclass(obj) and type(obj).__module__ != "builtins"
|
||||
|
||||
|
||||
class JitPlugin(CoveragePlugin): # type: ignore[misc, no-any-unimported]
|
||||
|
@ -554,26 +554,30 @@ class Op:
|
||||
MatchState.SIZE_OR_SYNTAX_MISMATCH,
|
||||
f"Expected input sizes: '{self.input_sizes}' does not match found output sizes: '{other.output_sizes}'",
|
||||
)
|
||||
if self.type in [
|
||||
"all_gather",
|
||||
"all_gather_base",
|
||||
"all_gather_into_tensor_coalesced",
|
||||
] and not (
|
||||
math.prod(other.output_sizes[0])
|
||||
== math.prod(self.input_sizes[0]) * self.pg_size
|
||||
if (
|
||||
self.type
|
||||
in [
|
||||
"all_gather",
|
||||
"all_gather_base",
|
||||
"all_gather_into_tensor_coalesced",
|
||||
]
|
||||
and math.prod(other.output_sizes[0])
|
||||
!= math.prod(self.input_sizes[0]) * self.pg_size
|
||||
):
|
||||
return MatchInfo(
|
||||
MatchState.SIZE_OR_SYNTAX_MISMATCH,
|
||||
f"Found input numel '{math.prod(other.input_sizes[0])} * pg size {self.pg_size}' "
|
||||
f"does not match output numel '{math.prod(other.output_sizes[0])}'",
|
||||
)
|
||||
if self.type in [
|
||||
"reduce_scatter",
|
||||
"_reduce_scatter_base",
|
||||
"reduce_scatter_tensor_coalesced",
|
||||
] and not (
|
||||
math.prod(other.input_sizes[0])
|
||||
== math.prod(self.output_sizes[0]) * self.pg_size
|
||||
if (
|
||||
self.type
|
||||
in [
|
||||
"reduce_scatter",
|
||||
"_reduce_scatter_base",
|
||||
"reduce_scatter_tensor_coalesced",
|
||||
]
|
||||
and math.prod(other.input_sizes[0])
|
||||
!= math.prod(self.output_sizes[0]) * self.pg_size
|
||||
):
|
||||
return MatchInfo(
|
||||
MatchState.SIZE_OR_SYNTAX_MISMATCH,
|
||||
|
@ -326,7 +326,7 @@ class CMake:
|
||||
|
||||
# The default value cannot be easily obtained in CMakeLists.txt. We set it here.
|
||||
py_lib_path = sysconfig.get_path("purelib")
|
||||
cmake_prefix_path = build_options.get("CMAKE_PREFIX_PATH", None)
|
||||
cmake_prefix_path = build_options.get("CMAKE_PREFIX_PATH")
|
||||
if cmake_prefix_path:
|
||||
build_options["CMAKE_PREFIX_PATH"] = (
|
||||
py_lib_path + ";" + cast(str, cmake_prefix_path)
|
||||
|
@ -43,7 +43,7 @@ def add_job(
|
||||
if workflow_name not in workflows:
|
||||
workflows[workflow_name] = {"when": "always", "jobs": []}
|
||||
|
||||
requires = job.get("requires", None)
|
||||
requires = job.get("requires")
|
||||
if requires is not None:
|
||||
for requirement in requires:
|
||||
dependency = past_jobs[requirement]
|
||||
|
Reference in New Issue
Block a user