Skip to content

Commit d31599f

Browse files
cyyeverpytorchmergebot
authored andcommitted
[7/N] Fix unused loop variables in tests (pytorch#167043)
This PR continues to fix or remove unused loop variables in tests. Pull Request resolved: pytorch#167043 Approved by: https://github.com/Lucaskabela
1 parent 85fab6c commit d31599f

File tree

7 files changed

+13
-19
lines changed

7 files changed

+13
-19
lines changed

test/dynamo/test_compiler_bisector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_fn():
283283
)
284284
def test_bisect_pre_grad_graph(self):
285285
def f(x):
286-
for i in range(5):
286+
for _ in range(5):
287287
x = x + 1
288288
return x.relu()
289289

test/functorch/test_control_flow.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,7 @@ def false_fn(x):
942942
b = torch.randn(4, requires_grad=True)
943943
c = torch.randn(4, requires_grad=True)
944944

945-
for pred, fn in zip(
946-
[torch.tensor(False), torch.tensor(True)], [false_fn, true_fn]
947-
):
945+
for pred in [torch.tensor(False), torch.tensor(True)]:
948946
with self.assertRaisesRegex(
949947
torch._dynamo.exc.UncapturedHigherOrderOpError,
950948
"Cond doesn't work unless it is captured completely with torch.compile",
@@ -3066,13 +3064,9 @@ def run_test_and_get_grads_loss(model, initial_hs, inputs):
30663064
).to(DEVICE)
30673065

30683066
# Test 3 models: RNNScanList, RNNScanTensor, RNNLoop
3069-
models = [
3070-
("ScanList", RNNScanList),
3071-
("ScanTensor", RNNScanTensor),
3072-
("Loop", RNNLoop),
3073-
]
3067+
models = [RNNScanList, RNNScanTensor, RNNLoop]
30743068

3075-
for model_name, model_class in models:
3069+
for model_class in models:
30763070
# Create uncompiled model
30773071
model_uc = model_class().to(DEVICE)
30783072
uncompiled_grads, uncompiled_loss = run_test_and_get_grads_loss(
@@ -7538,7 +7532,7 @@ def foo(x):
75387532

75397533
inps = (torch.ones(3, 4), torch.ones(3, 5), torch.ones(5, 4), torch.ones(5, 3))
75407534
for inp in inps:
7541-
gm = make_fx(foo, tracing_mode="symbolic")(torch.ones(3, 4))
7535+
gm = make_fx(foo, tracing_mode="symbolic")(inp)
75427536
self.assertExpectedInline(
75437537
gm.code.strip(),
75447538
"""\

test/inductor/test_flex_attention.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5807,11 +5807,11 @@ def causal_mask(b, h, q_idx, kv_idx):
58075807

58085808
from torch.utils._pytree import GetAttrKey
58095809

5810-
for key, tensor in tensors_with_keys:
5810+
for key, _tensor in tensors_with_keys:
58115811
self.assertIsInstance(key, GetAttrKey)
58125812
self.assertIsNotNone(key)
58135813

5814-
for key, value in context_with_keys:
5814+
for key, _value in context_with_keys:
58155815
self.assertIsInstance(key, GetAttrKey)
58165816
self.assertIsNotNone(key)
58175817

test/quantization/eager/test_bias_correction_eager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def correct_artificial_bias_quantize(self, float_model, img_data):
3939
torch.ao.quantization.convert(artificial_model, inplace=True)
4040

4141
# manually changing bias
42-
for name, submodule in artificial_model.named_modules():
42+
for submodule in artificial_model.modules():
4343
if type(submodule) in _supported_modules:
4444
x = get_param(submodule, "bias")
4545
weight = get_param(submodule, "weight")

test/quantization/fx/test_quantize_fx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9663,10 +9663,10 @@ def forward(self, input: torch.Tensor, offsets: Optional[torch.Tensor] = None,
96639663
.set_global(get_default_qat_qconfig(qengine)) \
96649664
.set_object_type(torch.nn.EmbeddingBag, default_embedding_qat_qconfig)
96659665

9666-
train_indices = [[torch.randint(0, 10, (12, 12)), torch.randn((12, 1))] for _ in range(2)]
9667-
eval_output = [[torch.randint(0, 10, (12, 1))]]
9666+
train_indices = [[torch.randint(0, 10, (12, 12), device=device), torch.randn((12, 1), device=device)] for _ in range(2)]
9667+
eval_output = [[torch.randint(0, 10, (12, 1), device=device)]]
96689668

9669-
model = EmbeddingBagLinear().train()
9669+
model = EmbeddingBagLinear().to(device).train()
96709670
prepared_fx_model = prepare_qat_fx(model, qconfig_dict, example_inputs=(train_indices[0][0],))
96719671
test_only_train_fn(prepared_fx_model, train_indices)
96729672
quant_model = convert_fx(prepared_fx_model,

test/test_nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13516,7 +13516,7 @@ def compare_scaling(grads):
1351613516

1351713517
# Should warning when parameters generator exhausted
1351813518
params = l.parameters()
13519-
for p in params:
13519+
for _p in params:
1352013520
pass
1352113521
with warnings.catch_warnings(record=True) as w:
1352213522
warnings.simplefilter("always")

test/test_transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,7 @@ def test_cudnn_attention_broken_166211(self):
28572857
# https://github.com/pytorch/pytorch/issues/166211#issue-3551350377
28582858
shape = (20, 4, 4, 32)
28592859
scale = 10
2860-
for i in range(100):
2860+
for _ in range(100):
28612861
q = torch.randn(*shape, device='cuda', dtype=torch.bfloat16) * scale
28622862
k = torch.randn(*shape, device='cuda', dtype=torch.bfloat16) * scale
28632863
v = torch.randn(*shape, device='cuda', dtype=torch.bfloat16) * scale

0 commit comments

Comments
 (0)