mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[BE]: Apply ruff PERF fixes to torch (#104917)
Applies automated ruff fixes in the PERF modules and enables all automatic ones. I also updated ruff which applied some additional fixes. Pull Request resolved: https://github.com/pytorch/pytorch/pull/104917 Approved by: https://github.com/ezyang, https://github.com/albanD
This commit is contained in:
committed by
PyTorch MergeBot
parent
c9a806be28
commit
2f95a3d0fc
2
.github/scripts/filter_test_configs.py
vendored
2
.github/scripts/filter_test_configs.py
vendored
@ -324,7 +324,7 @@ def process_jobs(
|
||||
warnings.warn(f"Invalid job name {job_name}, returning")
|
||||
return test_matrix
|
||||
|
||||
for _, record in download_json(url=url, headers={}).items():
|
||||
for record in download_json(url=url, headers={}).values():
|
||||
(
|
||||
author,
|
||||
_,
|
||||
|
@ -1021,6 +1021,6 @@ init_command = [
|
||||
'python3',
|
||||
'tools/linter/adapters/pip_init.py',
|
||||
'--dry-run={{DRYRUN}}',
|
||||
'ruff==0.0.269',
|
||||
'ruff==0.0.277',
|
||||
]
|
||||
is_formatter = true
|
||||
|
@ -306,7 +306,7 @@ class OperatorInputsLoader:
|
||||
), f"Could not find {op}, must provide overload"
|
||||
|
||||
count = 0
|
||||
for _, counter in self.operator_db[str(op)].items():
|
||||
for counter in self.operator_db[str(op)].values():
|
||||
count += counter
|
||||
return count
|
||||
|
||||
|
@ -121,7 +121,7 @@ def _build_test(configs, bench_op, OperatorTestCase, run_backward, op_name_funct
|
||||
op.extract_inputs_tuple()
|
||||
|
||||
if not run_backward:
|
||||
for _, attr in vars(op).items():
|
||||
for attr in vars(op).values():
|
||||
if isinstance(attr, torch.nn.Module):
|
||||
for param in attr.parameters():
|
||||
param.requires_grad = False
|
||||
|
@ -45,6 +45,8 @@ ignore = [
|
||||
"F841",
|
||||
# these ignores are from flake8-logging-format; please fix!
|
||||
"G101", "G201", "G202",
|
||||
# these ignores are from RUFF perf; please fix!
|
||||
"PERF203", "PERF4",
|
||||
"SIM102", "SIM103", "SIM112", # flake8-simplify code styles
|
||||
"SIM105", # these ignores are from flake8-simplify. please fix or ignore with commented reason
|
||||
"SIM108",
|
||||
@ -65,6 +67,7 @@ select = [
|
||||
"SIM1",
|
||||
"W",
|
||||
# Not included in flake8
|
||||
"PERF",
|
||||
"PLE",
|
||||
"TRY302",
|
||||
]
|
||||
|
@ -156,7 +156,7 @@ class TestActivationSparsifier(TestCase):
|
||||
|
||||
assert torch.all(mask_model == mask_actual)
|
||||
|
||||
for _, config in activation_sparsifier.data_groups.items():
|
||||
for config in activation_sparsifier.data_groups.values():
|
||||
assert 'data' not in config
|
||||
|
||||
|
||||
@ -238,7 +238,7 @@ class TestActivationSparsifier(TestCase):
|
||||
assert torch.all(mask1 == mask2)
|
||||
|
||||
# make sure that the state dict is stored as torch sparse
|
||||
for _, state in state_dict['state'].items():
|
||||
for state in state_dict['state'].values():
|
||||
mask = state['mask']
|
||||
if mask is not None:
|
||||
if isinstance(mask, List):
|
||||
|
@ -315,7 +315,7 @@ class TestFSDPMixedPrecision(FSDPTest):
|
||||
for x in args:
|
||||
if isinstance(x, torch.Tensor):
|
||||
tensors.append(x)
|
||||
for _, x in kwargs.items():
|
||||
for x in kwargs.values():
|
||||
if isinstance(x, torch.Tensor):
|
||||
tensors.append(x)
|
||||
|
||||
|
@ -915,7 +915,7 @@ class ModuleGuardNameIsValid(torch.nn.ModuleDict):
|
||||
self.add_module("l@yer-%d" % (i + 1), BasicModule())
|
||||
|
||||
def forward(self, x):
|
||||
for _, layer in self.items():
|
||||
for layer in self.values():
|
||||
x = layer(x)
|
||||
return x
|
||||
|
||||
|
@ -84,7 +84,7 @@ denylist = {
|
||||
def get_method_only_ops_we_care_about():
|
||||
apis = get_public_overridable_apis()
|
||||
result = []
|
||||
for key, _ in apis.items():
|
||||
for key in apis.keys():
|
||||
if not key.startswith('torch.Tensor'):
|
||||
continue
|
||||
if key in denylist:
|
||||
@ -103,7 +103,7 @@ def get_method_only_ops_we_care_about():
|
||||
def get_public_overridable_ops():
|
||||
results = get_public_overridable_apis()
|
||||
cpy = copy.deepcopy(results)
|
||||
for key, _ in cpy.items():
|
||||
for key in cpy.keys():
|
||||
if not key.startswith('torch.Tensor'):
|
||||
continue
|
||||
api = key.split('.')[2]
|
||||
@ -115,7 +115,7 @@ def get_public_overridable_ops():
|
||||
def get_public_overridable_outplace_ops():
|
||||
results = get_public_overridable_ops()
|
||||
cpy = copy.deepcopy(results)
|
||||
for key, _ in cpy.items():
|
||||
for key in cpy.keys():
|
||||
# NB: there are no dunder methods bcs we don't document those
|
||||
if key.endswith('_'):
|
||||
del results[key]
|
||||
@ -125,7 +125,7 @@ def get_public_overridable_outplace_ops():
|
||||
def get_public_overridable_outplace_we_care_about():
|
||||
results = get_public_overridable_outplace_ops()
|
||||
cpy = copy.deepcopy(results)
|
||||
for key, _ in cpy.items():
|
||||
for key in cpy.keys():
|
||||
# quantization
|
||||
if 'quant' in key or '.q_' in key:
|
||||
del results[key]
|
||||
@ -178,7 +178,7 @@ def get_ops_covered_by_opinfos():
|
||||
factory_fns = {
|
||||
'tensor', 'zeros', 'ones', 'randn', 'arange', 'rand', 'empty', 'randperm',
|
||||
'linspace', 'logspace', 'hann_window', 'full', 'eye', 'blackman_window',
|
||||
'barlett_window', 'randint', 'range', 'arange',
|
||||
'barlett_window', 'randint', 'range',
|
||||
}
|
||||
|
||||
|
||||
|
@ -584,7 +584,7 @@ class TestVmapAPI(TestCase):
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, [0, 0])(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, set({0, 0}))(x, y)
|
||||
vmap(torch.mul, set({0}))(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, 'lol')(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
|
@ -52,7 +52,6 @@ custom_rules_works_list = {
|
||||
"max_pool3d",
|
||||
"nn.functional.prelu",
|
||||
"batch_norm",
|
||||
"batch_norm",
|
||||
}
|
||||
|
||||
custom_rules_expected_failure_list = {
|
||||
|
@ -48,7 +48,7 @@ class PackedSequenceTest(TestCase):
|
||||
|
||||
def test_type_casts(self):
|
||||
"""Test type casting of `PackedSequence` against type casting of tensor"""
|
||||
for _, (input_type, _) in self._type_by_name.items():
|
||||
for (input_type, _) in self._type_by_name.values():
|
||||
for expected_type_str, (_, cast_str) in self._type_by_name.items():
|
||||
for enforce_sorted in [True, False]:
|
||||
padded, lengths = self._padded_sequence(input_type)
|
||||
|
@ -13,7 +13,7 @@ from torch.testing._internal.common_utils import retry, IS_SANDCASTLE, TestCase
|
||||
|
||||
def sum_of_state_dict(state_dict):
|
||||
s = 0
|
||||
for _, v in state_dict.items():
|
||||
for v in state_dict.values():
|
||||
s += v.sum()
|
||||
return s
|
||||
|
||||
|
@ -406,7 +406,7 @@ class TestVmapAPI(TestCase):
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, [0, 0])(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, set({0, 0}))(x, y)
|
||||
vmap(torch.mul, set({0}))(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
vmap(torch.mul, 'lol')(x, y)
|
||||
with self.assertRaisesRegex(ValueError, msg):
|
||||
|
@ -1367,7 +1367,7 @@ class TestMkldnn(TestCase):
|
||||
}
|
||||
|
||||
params_list = []
|
||||
for _, value in params_dict.items():
|
||||
for value in params_dict.values():
|
||||
params_list.append(value)
|
||||
return params_list
|
||||
|
||||
|
@ -72,26 +72,16 @@ class TestPublicBindings(TestCase):
|
||||
"ConcreteModuleTypeBuilder",
|
||||
"cpp",
|
||||
"CudaBFloat16TensorBase",
|
||||
"CudaBFloat16TensorBase",
|
||||
"CudaBoolTensorBase",
|
||||
"CudaBoolTensorBase",
|
||||
"CudaByteTensorBase",
|
||||
"CudaByteTensorBase",
|
||||
"CudaCharTensorBase",
|
||||
"CudaCharTensorBase",
|
||||
"CudaComplexDoubleTensorBase",
|
||||
"CudaComplexDoubleTensorBase",
|
||||
"CudaComplexFloatTensorBase",
|
||||
"CudaComplexFloatTensorBase",
|
||||
"CudaDoubleTensorBase",
|
||||
"CudaDoubleTensorBase",
|
||||
"CudaFloatTensorBase",
|
||||
"CudaHalfTensorBase",
|
||||
"CudaIntTensorBase",
|
||||
"CudaIntTensorBase",
|
||||
"CudaLongTensorBase",
|
||||
"CudaLongTensorBase",
|
||||
"CudaShortTensorBase",
|
||||
"CudaShortTensorBase",
|
||||
"DeepCopyMemoTable",
|
||||
"default_generator",
|
||||
@ -219,48 +209,8 @@ class TestPublicBindings(TestCase):
|
||||
"UnionType",
|
||||
"Use",
|
||||
"Value",
|
||||
"autocast_decrement_nesting",
|
||||
"autocast_increment_nesting",
|
||||
"clear_autocast_cache",
|
||||
"cpp",
|
||||
"default_generator",
|
||||
"device",
|
||||
"dtype",
|
||||
"finfo",
|
||||
"fork",
|
||||
"get_default_dtype",
|
||||
"get_num_interop_threads",
|
||||
"get_num_threads",
|
||||
"has_cuda",
|
||||
"has_cudnn",
|
||||
"has_lapack",
|
||||
"has_mkl",
|
||||
"has_mkldnn",
|
||||
"has_mps",
|
||||
"has_openmp",
|
||||
"iinfo",
|
||||
"import_ir_module",
|
||||
"import_ir_module_from_buffer",
|
||||
"init_num_threads",
|
||||
"is_anomaly_enabled",
|
||||
"is_anomaly_check_nan_enabled",
|
||||
"is_autocast_enabled",
|
||||
"is_grad_enabled",
|
||||
"layout",
|
||||
"memory_format",
|
||||
"merge_type_from_type_comment",
|
||||
"parse_ir",
|
||||
"parse_schema",
|
||||
"parse_type_comment",
|
||||
"qscheme",
|
||||
"set_anomaly_enabled",
|
||||
"set_autocast_enabled",
|
||||
'set_autocast_gpu_dtype',
|
||||
'get_autocast_gpu_dtype',
|
||||
"set_flush_denormal",
|
||||
"set_num_interop_threads",
|
||||
"set_num_threads",
|
||||
"unify_type_list",
|
||||
"vitals_enabled",
|
||||
"wait",
|
||||
"Tag",
|
||||
|
@ -142,7 +142,7 @@ class TestSubclass(TestCase):
|
||||
nn.init.normal_(self.p1)
|
||||
for p in self.p_list:
|
||||
nn.init.uniform_(p)
|
||||
for _, p in self.p_dict.items():
|
||||
for p in self.p_dict.values():
|
||||
nn.init.uniform_(p)
|
||||
|
||||
def forward(self, x):
|
||||
@ -150,7 +150,7 @@ class TestSubclass(TestCase):
|
||||
for p in self.p_list:
|
||||
out = p + out
|
||||
|
||||
for _, v in self.p_dict.items():
|
||||
for v in self.p_dict.values():
|
||||
out = v + out
|
||||
|
||||
return out
|
||||
|
@ -8553,7 +8553,7 @@ tensor([[[1.+1.j, 1.+1.j, 1.+1.j, ..., 1.+1.j, 1.+1.j, 1.+1.j],
|
||||
|
||||
device_set = {'cpu', 'cpu:0', 'cuda', 'cuda:0', 'cuda:1', 'cuda:10', 'cuda:100'}
|
||||
device_hash_set = set()
|
||||
for device in list(device_set):
|
||||
for device in device_set:
|
||||
device_hash_set.add(hash(torch.device(device)))
|
||||
self.assertEqual(len(device_set), len(device_hash_set))
|
||||
|
||||
|
@ -298,7 +298,6 @@ GRADIENT_IMPLEMENTED_FOR_COMPLEX = {
|
||||
"addr",
|
||||
"linalg_householder_product",
|
||||
"ormqr",
|
||||
"constant_pad_nd",
|
||||
"reflection_pad1d",
|
||||
"reflection_pad2d",
|
||||
"reflection_pad3d",
|
||||
@ -316,7 +315,6 @@ GRADIENT_IMPLEMENTED_FOR_COMPLEX = {
|
||||
"replication_pad1d",
|
||||
"replication_pad2d",
|
||||
"replication_pad3d",
|
||||
"take",
|
||||
"put",
|
||||
"put_",
|
||||
"_to_copy",
|
||||
@ -963,7 +961,7 @@ def gen_variable_type_func(
|
||||
result[f"type_derived_method_definitions_{key}"] = [type_definition]
|
||||
result[f"wrapper_registrations_{key}"] = [wrapper_registration]
|
||||
else:
|
||||
for key, _ in fn.info.items():
|
||||
for key in fn.info.keys():
|
||||
type_definition = METHOD_DEFINITION.substitute(
|
||||
return_type=cpp.returns_type(
|
||||
f.func.returns, symint=True
|
||||
|
@ -69,7 +69,7 @@ def add_view_copy_derivatives(
|
||||
|
||||
view_infos = {}
|
||||
|
||||
for _, info_dispatch_dict in infos.items():
|
||||
for info_dispatch_dict in infos.values():
|
||||
# maybe_view_group only needs to be calculated once per info_dispatch_dict
|
||||
maybe_view_group = None
|
||||
view_copy_differentiability_infos = {}
|
||||
|
@ -81,7 +81,7 @@ DOCUMENTED_IN_FLAKE8RULES: Set[str] = {
|
||||
DOCUMENTED_IN_FLAKE8COMPREHENSIONS: Set[str] = {
|
||||
"C400", "C401", "C402", "C403", "C404", "C405", "C406", "C407", "C408", "C409",
|
||||
"C410",
|
||||
"C411", "C412", "C413", "C413", "C414", "C415", "C416",
|
||||
"C411", "C412", "C413", "C414", "C415", "C416",
|
||||
}
|
||||
|
||||
# https://github.com/PyCQA/flake8-bugbear#list-of-warnings
|
||||
|
@ -96,18 +96,18 @@ class DebugLevel(Enum):
|
||||
DETAIL = ...
|
||||
|
||||
class ReduceOp:
|
||||
def __init__(self, op: "RedOpType"): ...
|
||||
def __init__(self, op: RedOpType): ...
|
||||
|
||||
SUM: "RedOpType" = ...
|
||||
AVG: "RedOpType" = ...
|
||||
PRODUCT: "RedOpType" = ...
|
||||
MIN: "RedOpType" = ...
|
||||
MAX: "RedOpType" = ...
|
||||
BAND: "RedOpType" = ...
|
||||
BOR: "RedOpType" = ...
|
||||
BXOR: "RedOpType" = ...
|
||||
PREMUL_SUM: "RedOpType" = ...
|
||||
UNUSED: "RedOpType" = ...
|
||||
SUM: RedOpType = ...
|
||||
AVG: RedOpType = ...
|
||||
PRODUCT: RedOpType = ...
|
||||
MIN: RedOpType = ...
|
||||
MAX: RedOpType = ...
|
||||
BAND: RedOpType = ...
|
||||
BOR: RedOpType = ...
|
||||
BXOR: RedOpType = ...
|
||||
PREMUL_SUM: RedOpType = ...
|
||||
UNUSED: RedOpType = ...
|
||||
|
||||
class RedOpType(Enum): ...
|
||||
|
||||
@ -200,7 +200,7 @@ class Work:
|
||||
def is_completed(self) -> bool: ...
|
||||
def is_success(self) -> bool: ...
|
||||
def exception(self) -> Any: ...
|
||||
def wait(self, timeout: timedelta = _DEFAULT_NO_TIMEOUT) -> bool: ...
|
||||
def wait(self, timeout: timedelta = ...) -> bool: ...
|
||||
def source_rank(self) -> int: ...
|
||||
def _source_rank(self) -> int: ...
|
||||
def result(self) -> List[Tensor]: ...
|
||||
@ -216,7 +216,7 @@ class ProcessGroup:
|
||||
def broadcast(
|
||||
self,
|
||||
tensors: List[Tensor],
|
||||
opts=BroadcastOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def broadcast(
|
||||
@ -228,44 +228,44 @@ class ProcessGroup:
|
||||
def allreduce(
|
||||
self,
|
||||
tensors: List[Tensor],
|
||||
opts: AllreduceOptions = AllreduceOptions(),
|
||||
opts: AllreduceOptions = ...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def allreduce(
|
||||
self,
|
||||
tensors: List[Tensor],
|
||||
op=ReduceOp.SUM,
|
||||
op=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def allreduce(
|
||||
self,
|
||||
tensor: Tensor,
|
||||
op=ReduceOp.SUM,
|
||||
op=...,
|
||||
) -> Work: ...
|
||||
def allreduce_coalesced(
|
||||
self,
|
||||
tensors: List[Tensor],
|
||||
opts=AllreduceCoalescedOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def reduce(
|
||||
self,
|
||||
tensors: List[Tensor],
|
||||
opts=ReduceOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def reduce(
|
||||
self,
|
||||
tensor: Tensor,
|
||||
root: int,
|
||||
op=ReduceOp.SUM,
|
||||
op=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def allgather(
|
||||
self,
|
||||
output_tensors: List[List[Tensor]],
|
||||
input_tensors: List[Tensor],
|
||||
opts=AllGatherOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def allgather(
|
||||
@ -277,20 +277,20 @@ class ProcessGroup:
|
||||
self,
|
||||
output: Tensor,
|
||||
input: Tensor,
|
||||
opts=AllGatherOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
def allgather_coalesced(
|
||||
self,
|
||||
output_lists: List[List[Tensor]],
|
||||
input_list: List[Tensor],
|
||||
opts=AllGatherOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def gather(
|
||||
self,
|
||||
output_tensors: List[List[Tensor]],
|
||||
input_tensors: List[Tensor],
|
||||
opts=GatherOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def gather(
|
||||
@ -304,7 +304,7 @@ class ProcessGroup:
|
||||
self,
|
||||
output_tensors: List[Tensor],
|
||||
input_tensors: List[List[Tensor]],
|
||||
opts=ScatterOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def scatter(
|
||||
@ -318,7 +318,7 @@ class ProcessGroup:
|
||||
self,
|
||||
output_tensors: List[Tensor],
|
||||
input_tensors: List[List[Tensor]],
|
||||
opts=ReduceScatterOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def reduce_scatter(
|
||||
@ -338,7 +338,7 @@ class ProcessGroup:
|
||||
input_tensor: Tensor,
|
||||
output_split_sizes: List[int],
|
||||
input_split_sizes: List[int],
|
||||
opts=AllToAllOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def alltoall_base(
|
||||
@ -353,7 +353,7 @@ class ProcessGroup:
|
||||
self,
|
||||
output_tensor: List[Tensor],
|
||||
input_tensor: List[Tensor],
|
||||
opts=AllToAllOptions(),
|
||||
opts=...,
|
||||
) -> Work: ...
|
||||
@overload
|
||||
def alltoall(
|
||||
@ -374,7 +374,7 @@ class ProcessGroup:
|
||||
tag: int,
|
||||
) -> Work: ...
|
||||
def recv_anysource(self, tensors: List[Tensor], tag: int) -> Work: ...
|
||||
def barrier(self, opts=BarrierOptions()) -> Work: ...
|
||||
def barrier(self, opts=...) -> Work: ...
|
||||
|
||||
class ProcessGroupRoundRobin(ProcessGroup): ...
|
||||
|
||||
|
@ -5,8 +5,8 @@ import torch
|
||||
|
||||
from . import Future
|
||||
from ._autograd import ProfilerEvent
|
||||
from ._distributed_c10d import ProcessGroup, Store
|
||||
from ._profiler import ActiveProfilerType, ProfilerConfig, ProfilerState
|
||||
from ._distributed_c10d import Store
|
||||
from ._profiler import ProfilerConfig
|
||||
|
||||
# This module is defined in torch/csrc/distributed/rpc/init.cpp
|
||||
|
||||
@ -20,8 +20,8 @@ class RpcBackendOptions:
|
||||
init_method: str
|
||||
def __init__(
|
||||
self,
|
||||
rpc_timeout: float = _DEFAULT_RPC_TIMEOUT_SEC,
|
||||
init_method: str = _DEFAULT_INIT_METHOD,
|
||||
rpc_timeout: float = ...,
|
||||
init_method: str = ...,
|
||||
): ...
|
||||
|
||||
class WorkerInfo:
|
||||
@ -31,7 +31,6 @@ class WorkerInfo:
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
def __eq__(self, other: object) -> bool: ...
|
||||
def __repr__(self) -> str: ...
|
||||
|
||||
class RpcAgent:
|
||||
def join(self, shutdown: bool = False, timeout: float = 0): ...
|
||||
@ -52,19 +51,18 @@ class PyRRef:
|
||||
def confirmed_by_owner(self) -> bool: ...
|
||||
def owner(self) -> WorkerInfo: ...
|
||||
def owner_name(self) -> str: ...
|
||||
def to_here(self, timeout: float = _UNSET_RPC_TIMEOUT) -> Any: ...
|
||||
def to_here(self, timeout: float = ...) -> Any: ...
|
||||
def local_value(self) -> Any: ...
|
||||
def rpc_sync(self, timeout: float = _UNSET_RPC_TIMEOUT) -> Any: ...
|
||||
def rpc_async(self, timeout: float = _UNSET_RPC_TIMEOUT) -> Any: ...
|
||||
def remote(self, timeout: float = _UNSET_RPC_TIMEOUT) -> Any: ...
|
||||
def rpc_sync(self, timeout: float = ...) -> Any: ...
|
||||
def rpc_async(self, timeout: float = ...) -> Any: ...
|
||||
def remote(self, timeout: float = ...) -> Any: ...
|
||||
def _serialize(self) -> Tuple: ...
|
||||
@staticmethod
|
||||
def _deserialize(tp: Tuple) -> "PyRRef": ...
|
||||
def _deserialize(tp: Tuple) -> PyRRef: ...
|
||||
def _get_type(self) -> Any: ...
|
||||
def _get_future(self) -> Future: ...
|
||||
def _get_profiling_future(self) -> Future: ...
|
||||
def _set_profiling_future(self, profilingFuture: Future): ...
|
||||
def __repr__(self) -> str: ...
|
||||
|
||||
class _TensorPipeRpcBackendOptionsBase(RpcBackendOptions):
|
||||
num_worker_threads: int
|
||||
@ -75,8 +73,8 @@ class _TensorPipeRpcBackendOptionsBase(RpcBackendOptions):
|
||||
num_worker_threads: int,
|
||||
_transports: Optional[List],
|
||||
_channels: Optional[List],
|
||||
rpc_timeout: float = _DEFAULT_RPC_TIMEOUT_SEC,
|
||||
init_method: str = _DEFAULT_INIT_METHOD,
|
||||
rpc_timeout: float = ...,
|
||||
init_method: str = ...,
|
||||
device_maps: Dict[str, Dict[torch.device, torch.device]] = {},
|
||||
devices: List[torch.device] = [],
|
||||
): ...
|
||||
|
@ -2,12 +2,8 @@ from typing import Dict, List
|
||||
|
||||
import torch
|
||||
|
||||
from ._distributed_c10d import ProcessGroup, Store
|
||||
from ._distributed_rpc import (
|
||||
_TensorPipeRpcBackendOptionsBase,
|
||||
TensorPipeAgent,
|
||||
WorkerInfo,
|
||||
)
|
||||
from ._distributed_c10d import Store
|
||||
from ._distributed_rpc import _TensorPipeRpcBackendOptionsBase, TensorPipeAgent
|
||||
|
||||
# This module is defined in torch/csrc/distributed/rpc/testing/init.cpp
|
||||
|
||||
|
@ -62,8 +62,7 @@ class CVmapInterpreterPtr:
|
||||
def batchSize(self) -> int: ...
|
||||
def randomness(self) -> RandomnessType: ...
|
||||
|
||||
class DynamicLayer:
|
||||
pass
|
||||
class DynamicLayer: ...
|
||||
|
||||
def peek_interpreter_stack() -> CInterpreter: ...
|
||||
def pop_dynamic_layer_stack() -> DynamicLayer: ...
|
||||
|
@ -154,7 +154,7 @@ class ExportedProgram:
|
||||
)
|
||||
finally:
|
||||
ix = 0
|
||||
for _, buffer in self.graph_signature.buffers_to_mutate.items():
|
||||
for buffer in self.graph_signature.buffers_to_mutate.values():
|
||||
self.state_dict[buffer] = mutated_buffers[ix]
|
||||
ix += 1
|
||||
return res
|
||||
|
@ -1884,7 +1884,7 @@ def create_synthetic_base_metadata(
|
||||
# generate the requires_grad info on those same mutated inputs, but after constructing synthetic bases.
|
||||
input_infos = []
|
||||
mutated_inp_require_grad_info = []
|
||||
for _, outer_indices in synthetic_base_to_indices.items():
|
||||
for outer_indices in synthetic_base_to_indices.values():
|
||||
# leaf-ness should be all-or-nothing for aliased tensor.
|
||||
# (aka if "a" and "b" are views, then a.is_leaf == b.is_leaf)
|
||||
any_leaf = any(m.input_info[x].is_leaf for x in outer_indices)
|
||||
|
@ -786,7 +786,7 @@ class GraphLowering(torch.fx.Interpreter):
|
||||
self.disable_cpp_wrapper("platform not linux")
|
||||
|
||||
def check_input_for_cpp_buffer(self):
|
||||
for _, value in self.graph_inputs.items():
|
||||
for value in self.graph_inputs.values():
|
||||
dtype = None
|
||||
if isinstance(value, TensorBox):
|
||||
dtype = value.get_dtype()
|
||||
|
@ -732,8 +732,8 @@ def extend_logger_results_with_comparison(
|
||||
comparison_name: string name of model to use for
|
||||
layer names in the output
|
||||
"""
|
||||
for _, results_type_to_results in results.items():
|
||||
for _, model_name_to_results in results_type_to_results.items():
|
||||
for results_type_to_results in results.values():
|
||||
for model_name_to_results in results_type_to_results.values():
|
||||
assert model_name_1 in model_name_to_results, \
|
||||
f"{model_name_1} not found in results"
|
||||
assert model_name_2 in model_name_to_results, \
|
||||
|
@ -331,7 +331,7 @@ class ActivationSparsifier:
|
||||
If `sparse_coo=True`, then the mask is stored as sparse coo else dense tensor
|
||||
"""
|
||||
states = copy.deepcopy(states_dict)
|
||||
for _, state in states.items():
|
||||
for state in states.values():
|
||||
if state['mask'] is not None:
|
||||
if isinstance(state['mask'], List):
|
||||
for idx in range(len(state['mask'])):
|
||||
|
@ -144,7 +144,7 @@ class BaseDataSparsifier(base_sparsifier.BaseSparsifier):
|
||||
r"""Converts the mask to sparse coo or dense tensors depending on the `sparse_coo` argument.
|
||||
"""
|
||||
states = copy.deepcopy(states)
|
||||
for _, state in states.items():
|
||||
for state in states.values():
|
||||
if sparse_coo:
|
||||
state['mask'] = state['mask'].to_sparse_coo()
|
||||
else:
|
||||
|
@ -310,7 +310,7 @@ def _has_conv_bias_filter(
|
||||
Match filter for the subgraph rewriter that returns True if the conv node in
|
||||
the original graph has bias.
|
||||
"""
|
||||
for _, n in match.nodes_map.items():
|
||||
for n in match.nodes_map.values():
|
||||
if n.target == torch.ops.aten.convolution.default:
|
||||
return n.args[2] is not None
|
||||
raise ValueError("Could not find conv node in matched conv + bn pattern")
|
||||
@ -723,7 +723,7 @@ def _fold_conv_bn_qat(m: GraphModule) -> GraphModule:
|
||||
_fold_bn_weights_into_conv_node(conv_node, conv_weight, conv_bias, bn_node, m)
|
||||
|
||||
# Copy over literal args for conv
|
||||
for _, original_node in _filter_nodes_map(r.nodes_map).items():
|
||||
for original_node in _filter_nodes_map(r.nodes_map).values():
|
||||
if original_node.target == torch.ops.aten.convolution.default:
|
||||
_copy_over_literal_conv_args(original_node, conv_node)
|
||||
|
||||
|
@ -572,7 +572,7 @@ def _maybe_get_observer_for_node(
|
||||
If the node is observed, return the observer
|
||||
instance. Otherwise, return None.
|
||||
"""
|
||||
for maybe_obs_node, _ in node.users.items():
|
||||
for maybe_obs_node in node.users.keys():
|
||||
if maybe_obs_node.op == 'call_module':
|
||||
maybe_obs = modules[str(maybe_obs_node.target)]
|
||||
if _is_activation_post_process(maybe_obs):
|
||||
|
@ -822,7 +822,7 @@ def _maybe_insert_input_observer_for_arg_or_kwarg(
|
||||
# we should remove this
|
||||
# removing this means we insert one observer for each use, even if they
|
||||
# have the same dtype, we can have an extra pass that removes the extra observers
|
||||
for maybe_obs_node, _ in arg.users.items():
|
||||
for maybe_obs_node in arg.users.keys():
|
||||
if maybe_obs_node.op == 'call_module':
|
||||
maybe_obs_mod = named_modules[maybe_obs_node.target] # type: ignore[index]
|
||||
if (
|
||||
@ -1245,7 +1245,7 @@ def _maybe_make_input_output_share_observers(
|
||||
setattr(named_modules[parent_name], name, obs_mod_to_use)
|
||||
|
||||
# set the output observer node to use that module
|
||||
for output_obs_node, _ in node.users.items():
|
||||
for output_obs_node in node.users.keys():
|
||||
assert _is_activation_post_process_node(output_obs_node, named_modules)
|
||||
parent_name, name = _parent_name(output_obs_node.target)
|
||||
setattr(named_modules[parent_name], name, obs_mod_to_use)
|
||||
|
@ -410,7 +410,7 @@ def maybe_get_next_module(
|
||||
target_functional_type: Functional type that we want to check
|
||||
"""
|
||||
|
||||
for user, _ in node.users.items():
|
||||
for user in node.users.keys():
|
||||
if user.op == 'call_module' and target_module_type is not None and \
|
||||
isinstance(modules[str(user.target)], target_module_type):
|
||||
return user
|
||||
|
@ -164,7 +164,7 @@ class LocalElasticAgent(SimpleElasticAgent):
|
||||
log.info("Environment variable '%s' not found. Do not start FileTimerServer.", enable_watchdog_env_name)
|
||||
# Propagate the watchdog file env to worker processes
|
||||
if watchdog_file_path is not None:
|
||||
for _, worker_env in envs.items():
|
||||
for worker_env in envs.values():
|
||||
worker_env[watchdog_file_env_name] = watchdog_file_path
|
||||
|
||||
|
||||
|
@ -303,7 +303,7 @@ class _NamedOptimizer(optim.Optimizer):
|
||||
|
||||
This allows doing in-place loading of optimizer state from a checkpoint.
|
||||
"""
|
||||
for _, param in self.named_parameters.items():
|
||||
for param in self.named_parameters.values():
|
||||
if param.requires_grad:
|
||||
t = torch.zeros_like(param)
|
||||
param.grad = torch.autograd.Variable(t)
|
||||
|
@ -242,9 +242,9 @@ def _validate_device_maps(all_names, all_device_counts, all_device_maps, all_dev
|
||||
def _create_device_list(my_devices, my_device_maps, reverse_device_maps):
|
||||
if not my_devices:
|
||||
devices_set: Set[torch.device] = set()
|
||||
for _, map_ in my_device_maps.items():
|
||||
for map_ in my_device_maps.values():
|
||||
devices_set.update(map_.keys())
|
||||
for _, map_ in reverse_device_maps.items():
|
||||
for map_ in reverse_device_maps.values():
|
||||
devices_set.update(map_.keys())
|
||||
devices_set.discard(torch.device("cpu"))
|
||||
my_devices = list(devices_set)
|
||||
|
@ -1218,7 +1218,7 @@ def is_pruned(module):
|
||||
True
|
||||
"""
|
||||
for _, submodule in module.named_modules():
|
||||
for _, hook in submodule._forward_pre_hooks.items():
|
||||
for hook in submodule._forward_pre_hooks.values():
|
||||
if isinstance(hook, BasePruningMethod):
|
||||
return True
|
||||
return False
|
||||
|
@ -108,7 +108,6 @@ def get_conda_packages(run_lambda):
|
||||
"soumith",
|
||||
"mkl",
|
||||
"magma",
|
||||
"mkl",
|
||||
"triton",
|
||||
}
|
||||
)
|
||||
|
@ -37,7 +37,7 @@ def _generate_input_args_string(obj):
|
||||
"""
|
||||
signature = inspect.signature(obj.__class__)
|
||||
input_param_names = set()
|
||||
for param_name, _ in signature.parameters.items():
|
||||
for param_name in signature.parameters.keys():
|
||||
input_param_names.add(param_name)
|
||||
result = []
|
||||
for name, obj in inspect.getmembers(obj):
|
||||
|
@ -54,7 +54,7 @@ def apply_sharding(datapipe: DataPipe,
|
||||
graph = traverse_dps(datapipe)
|
||||
|
||||
def _helper(graph, prev_applied=None):
|
||||
for _, (dp, sub_graph) in graph.items():
|
||||
for (dp, sub_graph) in graph.values():
|
||||
applied = None
|
||||
if _is_sharding_datapipe(dp):
|
||||
if prev_applied is not None:
|
||||
|
Reference in New Issue
Block a user