[BE]: Apply PERF401 autofixes from ruff (#140980)

* Automatically applies ruff rule 401. Turns loops into equivalent list comprehensions which are faster and do not leak the scope of the loop variables.
* list comprehensions not only often have better typing, but are 50+% faster than for loops on overhead. They also preserve length information etc and are better for the interpreter to optimize.
* Manually went back and made mypy happy after the change.
* Also fixed style lints in files covered by flake8 but not by pyfmt

Pull Request resolved: https://github.com/pytorch/pytorch/pull/140980
Approved by: https://github.com/justinchuby, https://github.com/malfet
This commit is contained in:
Aaron Gokaslan
2024-11-20 17:52:07 +00:00
committed by PyTorch MergeBot
parent 8d708090c0
commit 12e95aa4ee
133 changed files with 611 additions and 761 deletions

View File

@ -2102,13 +2102,14 @@ class AotCodeCompiler:
aot_constants = struct.pack("qq", consts_size + 8, magic_number)
consts_o = _compile_consts(aot_constants, sys.platform)
kernels_o = []
gpu_codecache: Union[ROCmCodeCache, CUDACodeCache] = (
ROCmCodeCache() if torch.version.hip else CUDACodeCache()
)
for entry in gpu_codecache.cache.values():
if entry.output_path.endswith(".o"):
kernels_o.append(entry.output_path)
kernels_o = [
entry.output_path
for entry in gpu_codecache.cache.values()
if entry.output_path.endswith(".o")
]
kernels_o = " ".join(kernels_o)
output_name, output_dir = get_name_and_dir_from_output_file_path(output_so)