[BE] Enable ruff's UP rules and autoformat dynamo / functorch and refs (#105432)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/105432
Approved by: https://github.com/ezyang
This commit is contained in:
Justin Chu
2023-07-18 22:34:37 -07:00
committed by PyTorch MergeBot
parent 88f119775d
commit 8a688277a2
47 changed files with 188 additions and 242 deletions

View File

@ -108,18 +108,16 @@ def _create_rearrange_callable(
custom_rearrange_callable_name = "do_rearrange"
custom_rearrange_callable_code = (
(
f"def {custom_rearrange_callable_name}(tensor):\n"
f" {comma_separate(first_class_dims)} = dims({n_dims})\n"
+ (
"".join(f" {dim}.size = {length}\n" for (dim, length) in specified_lengths)
if specified_lengths else ""
)
+ f" tensor = tensor[{comma_separate(left_dims)}].order({comma_separate(right_dims)})\n"
+ (
f" return tensor.sum({comma_separate([anon_dims])}, keepdim=False)\n"
if anon_dims else " return tensor\n"
)
f"def {custom_rearrange_callable_name}(tensor):\n"
f" {comma_separate(first_class_dims)} = dims({n_dims})\n"
+ (
"".join(f" {dim}.size = {length}\n" for (dim, length) in specified_lengths)
if specified_lengths else ""
)
+ f" tensor = tensor[{comma_separate(left_dims)}].order({comma_separate(right_dims)})\n"
+ (
f" return tensor.sum({comma_separate([anon_dims])}, keepdim=False)\n"
if anon_dims else " return tensor\n"
)
)