mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Fix unused Python variables in test/[e-z]* (#136964)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136964 Approved by: https://github.com/justinchuby, https://github.com/albanD
This commit is contained in:
parent
d298bd840f
commit
d8c8ba2440
|
|
@ -41,7 +41,7 @@ class PreDispatchSchemaCheckMode(SchemaCheckMode):
|
|||
if isinstance(e, torch.Tensor) and not type(e) == torch.Tensor:
|
||||
try:
|
||||
return e.elem
|
||||
except AttributeError as t:
|
||||
except AttributeError:
|
||||
return e
|
||||
return e
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class TestConverter(TestCase):
|
|||
init_torchbind_implementations()
|
||||
|
||||
@torch._library.register_fake_class("_TorchScriptTesting::_TensorQueue")
|
||||
class FakeTensorQueue:
|
||||
class _FakeTensorQueue:
|
||||
def __init__(self, queue):
|
||||
self.queue = queue
|
||||
|
||||
|
|
@ -1017,7 +1017,7 @@ class TestConverter(TestCase):
|
|||
torch.randn([2, 3, 4]).to(torch.float32),
|
||||
torch.randn([2, 3, 4]).to(torch.float64),
|
||||
)
|
||||
ep_list = self._check_equal_ts_ep_converter(func6, inp)
|
||||
self._check_equal_ts_ep_converter(func6, inp)
|
||||
|
||||
# TODO: Additional check once dynamic shape is supported.
|
||||
# for ep in ep_list:
|
||||
|
|
@ -1353,7 +1353,7 @@ class TestConverter(TestCase):
|
|||
def test_ts2ep_with_loop(self):
|
||||
def func1(x, x_list: List[torch.Tensor]):
|
||||
a, b, c = x, x, x
|
||||
for i in range(1, 5, 2):
|
||||
for _ in range(1, 5, 2):
|
||||
for k in range(5):
|
||||
a = a + a + k
|
||||
b = b + b - k
|
||||
|
|
@ -1364,12 +1364,12 @@ class TestConverter(TestCase):
|
|||
x_list.append(x_list[k] + x_list[k + 1] - x_list[k + 2])
|
||||
return x, x_list
|
||||
|
||||
def func2(x):
|
||||
def func2(x): # noqa: F841
|
||||
for i in range(x.size(0)):
|
||||
x = x * x * i
|
||||
return x
|
||||
|
||||
def func3(x):
|
||||
def func3(x): # noqa: F841
|
||||
while x.sum() < 10:
|
||||
x += x.sin()
|
||||
return x
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class TestDraftExport(TestCase):
|
|||
)
|
||||
|
||||
def test_missing_meta_kernel_custom_op(self):
|
||||
with torch.library._scoped_library("mylib", "FRAGMENT") as lib:
|
||||
with torch.library._scoped_library("mylib", "FRAGMENT"):
|
||||
|
||||
@torch.library.custom_op("mylib::foo2", mutates_args={})
|
||||
def foo2_impl(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
||||
|
|
@ -111,7 +111,7 @@ class TestDraftExport(TestCase):
|
|||
|
||||
@unittest.skipIf(not torch.cuda.is_available(), "Requires cuda")
|
||||
def test_missing_meta_kernel_guard(self):
|
||||
with torch.library._scoped_library("mylib", "FRAGMENT") as lib:
|
||||
with torch.library._scoped_library("mylib", "FRAGMENT"):
|
||||
|
||||
@torch.library.custom_op("mylib::foo4", mutates_args={})
|
||||
def foo4_impl(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
||||
|
|
@ -415,7 +415,7 @@ class TestDraftExport(TestCase):
|
|||
example_inputs = (torch.randn(3, 5), torch.randn(3))
|
||||
draft_ep, _ = draft_export(mod, example_inputs)
|
||||
with tempfile.NamedTemporaryFile(suffix=".pt2") as f:
|
||||
aoti_model_path = torch._inductor.aoti_compile_and_package(
|
||||
torch._inductor.aoti_compile_and_package(
|
||||
draft_ep,
|
||||
example_inputs,
|
||||
package_path=f.name,
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ def forward(self, p_linear_weight, p_linear_bias, c_lifted_tensor_0, x):
|
|||
ep = torch.export.export_for_training(
|
||||
m, example_inputs, dynamic_shapes={"x": {0: Dim("x0")}}
|
||||
)
|
||||
joint_ep = _export_forward_backward(ep)
|
||||
_export_forward_backward(ep)
|
||||
|
||||
def test_joint_cifar10_backwards(self) -> None:
|
||||
import torch.nn as nn
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: export"]
|
||||
# ruff: noqa: F841
|
||||
# flake8: noqa
|
||||
import copy
|
||||
import dataclasses
|
||||
|
|
|
|||
|
|
@ -643,7 +643,7 @@ def forward(self, token, obj_attr, x):
|
|||
allow_non_fake_inputs=True,
|
||||
)
|
||||
with _fakify_script_objects(m, (), {}, fake_mode) as (
|
||||
patched_mod,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
fake_constant_attrs,
|
||||
|
|
@ -657,17 +657,16 @@ def forward(self, token, obj_attr, x):
|
|||
@unittest.expectedFailure
|
||||
def test_fakify_script_objects_properly_handle_containers(self):
|
||||
m = ModelsWithScriptObjectAttr.SimpleWithAttrInContainer()
|
||||
constant_attrs = _gather_constant_attrs(m)
|
||||
fake_mode = FakeTensorMode(
|
||||
shape_env=ShapeEnv(tracked_fakes=[]),
|
||||
allow_non_fake_inputs=True,
|
||||
)
|
||||
with _fakify_script_objects(m, (), {}, fake_mode) as (
|
||||
patched_mod,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
fake_constant_attrs,
|
||||
fake_to_real,
|
||||
_,
|
||||
):
|
||||
self.assertTrue("attr" in fake_constant_attrs.values())
|
||||
self.assertTrue("pytree_attr2" in fake_constant_attrs.values())
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: export"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import copy
|
||||
import unittest
|
||||
|
|
|
|||
|
|
@ -498,7 +498,8 @@ class TestUnflatten(TestCase):
|
|||
|
||||
inp = (torch.randn(4, 4), [torch.randn(4, 4), torch.randn(4, 4)])
|
||||
mod = Foo()
|
||||
ep_strict = torch.export.export(mod, inp)
|
||||
|
||||
ep_strict = torch.export.export(mod, inp) # noqa: F841
|
||||
ep_non_strict = torch.export.export(mod, inp, strict=False)
|
||||
|
||||
gm_unflat_non_strict = unflatten(ep_non_strict)
|
||||
|
|
@ -610,7 +611,7 @@ class TestUnflatten(TestCase):
|
|||
init_torchbind_implementations()
|
||||
|
||||
@torch._library.register_fake_class("_TorchScriptTesting::_Foo")
|
||||
class FakeFoo:
|
||||
class FakeFoo: # noqa: F841
|
||||
def __init__(self, x: int, y: int):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
|
@ -687,7 +688,7 @@ class TestUnflatten(TestCase):
|
|||
# The call chain looks like this:
|
||||
# A -> B -> C -> A.d
|
||||
ep = torch.export.export(a, (torch.randn(3),), strict=False)
|
||||
unflattened = unflatten(ep)
|
||||
unflatten(ep)
|
||||
|
||||
def test_nested_leaf_non_strict(self):
|
||||
class Leaf(torch.nn.Module):
|
||||
|
|
|
|||
|
|
@ -413,14 +413,6 @@ def get_statuses(for_subset=None, invert=False):
|
|||
result.remove(decorator.test_name)
|
||||
return result
|
||||
|
||||
def get_all_aliases(op):
|
||||
opinfos = op_to_opinfo[op]
|
||||
result = []
|
||||
for opinfo in opinfos:
|
||||
result.append(opinfo.name)
|
||||
result.extend(opinfo.aliases)
|
||||
return set(result)
|
||||
|
||||
for name, op in get_covered_ops(overridable_outplace_we_care_about).items():
|
||||
successful_tests = get_covered_tests(op)
|
||||
failed_tests = tests - successful_tests
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class MemoryBudgetTest(TestCase):
|
|||
def call():
|
||||
return f(x, ws)
|
||||
|
||||
eager_mem, eager_flops = get_mem_and_flops(call)
|
||||
_, eager_flops = get_mem_and_flops(call)
|
||||
for budget in range(0, 11):
|
||||
mem, flops = get_mem_and_flops(call, memory_budget=budget / 10)
|
||||
if budget <= 5:
|
||||
|
|
@ -133,18 +133,10 @@ class MemoryBudgetTest(TestCase):
|
|||
|
||||
def make_weights(w_shapes):
|
||||
ws = []
|
||||
for idx, dim in enumerate(w_shapes):
|
||||
for dim in w_shapes:
|
||||
ws.append(torch.randn(512, dim * 512, requires_grad=True))
|
||||
return ws
|
||||
|
||||
def make_weights_chain(w_shapes):
|
||||
ws = []
|
||||
for idx, _ in enumerate(w_shapes):
|
||||
old_dim = 512 if idx == 0 else w_shapes[idx - 1] * 512
|
||||
new_dim = w_shapes[idx] * 512
|
||||
ws.append(torch.randn(old_dim, new_dim, requires_grad=True))
|
||||
return ws
|
||||
|
||||
weight_configs = [
|
||||
(
|
||||
[11, 3, 4, 2],
|
||||
|
|
@ -186,7 +178,7 @@ class MemoryBudgetTest(TestCase):
|
|||
def call():
|
||||
return f(x, ws)
|
||||
|
||||
eager_mem, eager_flops = get_mem_and_flops(call)
|
||||
eager_mem, _ = get_mem_and_flops(call)
|
||||
total_mem = sum(weight_shapes)
|
||||
self.assertEqual(eager_mem, sum(weight_shapes))
|
||||
for mem_achieved in exact_solves:
|
||||
|
|
@ -302,7 +294,7 @@ class MemoryBudgetTest(TestCase):
|
|||
def call():
|
||||
return f(x, ws)
|
||||
|
||||
eager_mem, eager_flops = get_mem_and_flops(call)
|
||||
_, eager_flops = get_mem_and_flops(call)
|
||||
mem, flops = get_mem_and_flops(call, memory_budget=0.2)
|
||||
# We start saving the matmuls
|
||||
self.assertEqual(mem, 2)
|
||||
|
|
|
|||
|
|
@ -697,7 +697,7 @@ def forward(self, primals_1, primals_2):
|
|||
with self.assertRaisesRegex(
|
||||
AssertionError, "but the input has other mutations that we cannot"
|
||||
):
|
||||
fw_graph = self.verify_aot_autograd(
|
||||
self.verify_aot_autograd(
|
||||
f, inp, test_mutation=True, keep_inp_mutations=True
|
||||
)
|
||||
|
||||
|
|
@ -756,8 +756,8 @@ def forward(self, primals_1):
|
|||
test = torch.ones(4, requires_grad=True) + 0
|
||||
test_view = test[0::2]
|
||||
|
||||
out_ref = f(ref_view)
|
||||
out_test = f_compiled(test_view)
|
||||
out_ref = f(ref_view) # noqa: F841
|
||||
out_test = f_compiled(test_view) # noqa: F841
|
||||
self.assertEqual(ref, test)
|
||||
|
||||
def test_input_mutation_modifies_autograd_meta_of_aliases(self):
|
||||
|
|
@ -1110,7 +1110,7 @@ def forward(self, arg0_1, arg1_1):
|
|||
keep_inference_input_mutations=True,
|
||||
dynamic=False,
|
||||
)
|
||||
out = compiled_f(inp)
|
||||
compiled_f(inp)
|
||||
# Final functionalized graph has two mutation ops:
|
||||
# (1) a resize_() to resize input tensor up
|
||||
# (2) a copy_() to fill in the resized input with valid data
|
||||
|
|
@ -1145,7 +1145,7 @@ def forward(self, primals_1):
|
|||
keep_inference_input_mutations=True,
|
||||
dynamic=False,
|
||||
)
|
||||
out = compiled_f(inp)
|
||||
compiled_f(inp)
|
||||
# Final functionalized graph has one mutation ops:
|
||||
# (1) a resize_() to resize input tensor down
|
||||
# Even though there was technically a "data mutation" on the input (from a.copy_()),
|
||||
|
|
@ -1217,7 +1217,7 @@ def forward(self, primals_1):
|
|||
with torch.no_grad():
|
||||
allgather_param = torch.cat([param_shard, param_shard])
|
||||
# simulate propagating grad state through dummy param, using data of allgather param
|
||||
dummy_param_with_grad_state = TracableCreateParameter.apply(
|
||||
dummy_param_with_grad_state = TracableCreateParameter.apply( # noqa: F841
|
||||
allgather_param, dummy_param
|
||||
)
|
||||
out = dummy_param.sin()
|
||||
|
|
@ -1242,7 +1242,7 @@ def forward(self, primals_1):
|
|||
keep_inference_input_mutations=True,
|
||||
dynamic=False,
|
||||
)
|
||||
out = compiled_f(dummy_param, param_shard)
|
||||
compiled_f(dummy_param, param_shard)
|
||||
# Important stuff to point out:
|
||||
# (1) We save cat for backward (input to the sin()).
|
||||
# While the original code was dummy_param.sin(),
|
||||
|
|
@ -1276,7 +1276,7 @@ def forward(self, primals_1, primals_2):
|
|||
keep_inference_input_mutations=True,
|
||||
dynamic=False,
|
||||
)
|
||||
out = compiled_f(inp)
|
||||
compiled_f(inp)
|
||||
|
||||
# def test_input_mutation_storage_resize_not_supported(self):
|
||||
# def f(a):
|
||||
|
|
@ -1412,7 +1412,7 @@ def forward(self, arg0_1):
|
|||
return a + 5
|
||||
|
||||
inp = [torch.ones(4, requires_grad=True)]
|
||||
fw_graph = self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
|
||||
def test_input_mutation_metadata2(self):
|
||||
def f(a):
|
||||
|
|
@ -1482,7 +1482,7 @@ def forward(self, arg0_1):
|
|||
)
|
||||
inp = torch.ones(4, 4, 4, 4)
|
||||
with torch.no_grad():
|
||||
out = compiled_m(inp)
|
||||
compiled_m(inp)
|
||||
# expectation: there are no copy_() calls in the decomposed batch norm when running under training=False (eval mode)
|
||||
code = fw_graph_cell[0].code.strip()
|
||||
self.assertTrue("copy_" not in str(code))
|
||||
|
|
@ -1670,16 +1670,16 @@ def forward(self, primals_1):
|
|||
inp2.mul_(2)
|
||||
# In eager mode, if we mutate a tensor, any multi-output-view aliases
|
||||
# get their grad_fn replaced with error nodes, so accessing grad_fn should error
|
||||
grad_fn = out_test2[0].grad_fn
|
||||
out_test2[0].grad_fn
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, "Such functions do not allow the output views"
|
||||
):
|
||||
out_test3 = f1_compiled(inp3)
|
||||
f1_compiled(inp3)
|
||||
out_test1[0].detach().mul_(2)
|
||||
# The above case also applies to detached aliases (they turn the multi-output-view
|
||||
# alias's grad_fns into error nodes)
|
||||
grad_fn = out_test2[0].grad_fn
|
||||
out_test2[0].grad_fn
|
||||
|
||||
def test_output_aliases_input_multi_output_view(self):
|
||||
# All aliased outs are from multi-output views, so AOTAutograd will hide the aliasing from autograd.
|
||||
|
|
@ -1890,7 +1890,7 @@ def forward(self, primals_1, primals_2):
|
|||
inp = [torch.ones(3, 3, requires_grad=False)]
|
||||
self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
inp = [torch.ones(3, 3, requires_grad=True)]
|
||||
fw_graph = self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
|
||||
def test_output_aliases_intermediate_multiple(self):
|
||||
def f(a):
|
||||
|
|
@ -1982,8 +1982,6 @@ def forward(self, primals_1):
|
|||
out.t_()
|
||||
return out
|
||||
|
||||
inp = [torch.ones(2, 4, requires_grad=True)]
|
||||
|
||||
# TODO: fix this test.
|
||||
# See https://github.com/pytorch/pytorch/issues/90507
|
||||
# self.verify_aot_autograd(f, inp, test_mutation=True)
|
||||
|
|
@ -2020,7 +2018,7 @@ def forward(self, primals_1):
|
|||
out_view2 = out.unsqueeze(0)
|
||||
return out_view, out, out_view2
|
||||
|
||||
inp = [torch.ones(2, 4, requires_grad=True)]
|
||||
inp = [torch.ones(2, 4, requires_grad=True)] # noqa: F841
|
||||
|
||||
# TODO: fix this test.
|
||||
# See <github issue link>
|
||||
|
|
@ -2355,7 +2353,7 @@ def forward(self, primals_1, primals_2):
|
|||
with self.assertRaisesRegex(
|
||||
AssertionError, "input to the backward that was mutated during the backward"
|
||||
):
|
||||
out = f_compiled(*inp_grad)
|
||||
f_compiled(*inp_grad)
|
||||
|
||||
def test_backward_mutation_forward_inputs(self):
|
||||
@torch.library.custom_op("_test::_clone", mutates_args={})
|
||||
|
|
@ -2954,7 +2952,7 @@ def forward(self, primals_1, primals_2, primals_3):
|
|||
# detach() so that none of the inputs have a ._base attribute.
|
||||
a = base[0].detach()
|
||||
b = base[1].detach()
|
||||
base2 = torch.ones(2, 2, requires_grad=True)
|
||||
base2 = torch.ones(2, 2, requires_grad=True) # noqa: F841
|
||||
return [base], [a, b]
|
||||
|
||||
self.verify_aot_autograd(f, inp_callable, test_mutation=True)
|
||||
|
|
@ -3499,7 +3497,6 @@ def forward(self, tangents_1):
|
|||
b.masked_fill_(c, 0) **also** mutates a (because b and a are aliased)
|
||||
The autograd engine yells at us if we save "a" for backward, and then try to mutate it.
|
||||
"""
|
||||
inp = torch.randn(2, 2, requires_grad=True)
|
||||
|
||||
def f(a):
|
||||
b = a[0]
|
||||
|
|
@ -3990,7 +3987,7 @@ def forward(self, arg0_1, arg1_1):
|
|||
fw_graph_cell = [None]
|
||||
bw_graph_cell = [None]
|
||||
|
||||
compiled_outs = aot_function(
|
||||
aot_function(
|
||||
fn,
|
||||
fw_compiler=partial(extract_graph, graph_cell=fw_graph_cell),
|
||||
bw_compiler=partial(extract_graph, graph_cell=bw_graph_cell),
|
||||
|
|
@ -3999,7 +3996,6 @@ def forward(self, arg0_1, arg1_1):
|
|||
dynamic=True,
|
||||
)(*inp)
|
||||
fw_graph = fw_graph_cell[0]
|
||||
bw_graph = bw_graph_cell[0]
|
||||
|
||||
self.assertExpectedInline(
|
||||
str(fw_graph.code).strip(),
|
||||
|
|
@ -4560,7 +4556,7 @@ def forward(self, arg0_1):
|
|||
mod = ConvBatchnormRelu()
|
||||
mod.train()
|
||||
inp = torch.randn(1, 1, 3, 3)
|
||||
o_ref = mod(inp)
|
||||
mod(inp)
|
||||
fx_g, signature = aot_export_module(
|
||||
mod, [inp], trace_joint=True, output_loss_index=0
|
||||
)
|
||||
|
|
@ -5265,7 +5261,7 @@ class TestPartitioning(AOTTestCase):
|
|||
aot_fn = aot_function(generate, nop, inference_compiler=inference_compiler)
|
||||
# Even though x requires grad, we should still get an inference graph
|
||||
x = torch.randn(4, requires_grad=True)
|
||||
res = aot_fn(x)
|
||||
aot_fn(x)
|
||||
self.assertTrue(inference_graph_cell[0] is not None)
|
||||
|
||||
@unittest.skipIf(not torch.cuda.is_available(), "CUDA is unavailable")
|
||||
|
|
@ -5914,7 +5910,7 @@ class TestAOTModuleSimplified(AOTTestCase):
|
|||
x = torch.randn(2, 512, 40, 59) # NB: must not require grad
|
||||
inputs = [x]
|
||||
fake_inputs = [fake_mode.from_tensor(x) for x in inputs]
|
||||
compiled_f = aot_module_simplified(mod, fake_inputs, nop)
|
||||
aot_module_simplified(mod, fake_inputs, nop)
|
||||
|
||||
def test_aot_module_simplified_preserves_stack_trace(self):
|
||||
class MockModule(torch.nn.Module):
|
||||
|
|
|
|||
|
|
@ -1202,15 +1202,15 @@ def forward(self, pred_1, x_1):
|
|||
with self.assertRaisesRegex(
|
||||
RuntimeError, r"Expect outputs of map only contains tensors or None\."
|
||||
):
|
||||
_ = control_flow.map(f, x, y)
|
||||
control_flow.map(f, x, y)
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, r"Expect outputs of map only contains tensors or None\."
|
||||
):
|
||||
out = control_flow.map(f1, x, y)
|
||||
control_flow.map(f1, x, y)
|
||||
|
||||
# return None is OK
|
||||
_ = control_flow.map(f2, x, y)
|
||||
control_flow.map(f2, x, y)
|
||||
|
||||
def test_map_list_in_out(self):
|
||||
def f(x, y):
|
||||
|
|
@ -1644,7 +1644,7 @@ def forward(self, pred_1, x_1):
|
|||
RuntimeError,
|
||||
"The number of leaves of the pytree of the new carry",
|
||||
):
|
||||
result = scan(fct_wrong_pytree, init, inp, dim=0)
|
||||
scan(fct_wrong_pytree, init, inp, dim=0)
|
||||
|
||||
@requires_cuda
|
||||
@parametrize("reverse", [False, True])
|
||||
|
|
@ -1975,7 +1975,7 @@ def forward(self, pred_1, x_1):
|
|||
RuntimeError,
|
||||
"xs leaves must have a scan dimension > 0",
|
||||
):
|
||||
result_init = scan_fct(
|
||||
scan_fct(
|
||||
get_scan_combine_fn("add", False),
|
||||
init,
|
||||
inp,
|
||||
|
|
@ -1987,7 +1987,7 @@ def forward(self, pred_1, x_1):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result_init = scan_fct(
|
||||
scan_fct(
|
||||
get_scan_combine_fn("add", False),
|
||||
init,
|
||||
inp,
|
||||
|
|
@ -2009,18 +2009,14 @@ def forward(self, pred_1, x_1):
|
|||
RuntimeError,
|
||||
"All init leaves must be a Tensor",
|
||||
):
|
||||
result_init = scan_fct(
|
||||
get_scan_combine_fn("add", False), init, x, dim=dim
|
||||
)
|
||||
scan_fct(get_scan_combine_fn("add", False), init, x, dim=dim)
|
||||
else:
|
||||
with self.assertRaisesRegex(
|
||||
# Should be: RuntimeError, "Init leaves must be a Tensor"
|
||||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result_init = scan_fct(
|
||||
get_scan_combine_fn("add", False), init, x, dim=dim
|
||||
)
|
||||
scan_fct(get_scan_combine_fn("add", False), init, x, dim=dim)
|
||||
|
||||
@requires_cuda
|
||||
@parametrize("compile_mode", ["none", "eager"])
|
||||
|
|
@ -2035,7 +2031,7 @@ def forward(self, pred_1, x_1):
|
|||
init = torch.randn(1, 2)
|
||||
if compile_mode == "none":
|
||||
with self.assertRaisesRegex(RuntimeError, "The shape of the new_carry"):
|
||||
result_init = scan_fct(
|
||||
scan_fct(
|
||||
get_scan_combine_fn("add", False),
|
||||
init,
|
||||
x,
|
||||
|
|
@ -2047,7 +2043,7 @@ def forward(self, pred_1, x_1):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result_init = scan_fct(
|
||||
scan_fct(
|
||||
get_scan_combine_fn("add", False),
|
||||
init,
|
||||
x,
|
||||
|
|
@ -2077,7 +2073,7 @@ def forward(self, pred_1, x_1):
|
|||
RuntimeError,
|
||||
"The number of leaves of the pytree of the new carry produced by the operator",
|
||||
):
|
||||
result_init = scan_fct(add_one_carry, init, x, dim=dim)
|
||||
scan_fct(add_one_carry, init, x, dim=dim)
|
||||
|
||||
else:
|
||||
with self.assertRaisesRegex(
|
||||
|
|
@ -2086,7 +2082,7 @@ def forward(self, pred_1, x_1):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result_init = scan_fct(add_one_carry, init, x, dim=dim)
|
||||
scan_fct(add_one_carry, init, x, dim=dim)
|
||||
|
||||
@requires_cuda
|
||||
@parametrize("reverse", [False, True])
|
||||
|
|
@ -2218,7 +2214,7 @@ def forward(self, pred_1, x_1):
|
|||
Exception,
|
||||
".*",
|
||||
):
|
||||
result = scan(
|
||||
scan(
|
||||
get_scan_combine_fn("complex_pointwise", False),
|
||||
init,
|
||||
inp,
|
||||
|
|
@ -3079,7 +3075,7 @@ class AssociativeScanTests(TestCase):
|
|||
device = torch.device("cuda")
|
||||
|
||||
def combine_fn(x, y):
|
||||
cnt = torch.zeros_like(y[0, :])
|
||||
_cnt = torch.zeros_like(y[0, :])
|
||||
if loop_type == "while":
|
||||
|
||||
def cond_fn(ind, loop_val):
|
||||
|
|
@ -3334,7 +3330,7 @@ class AssociativeScanTests(TestCase):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
out = associative_scan(
|
||||
associative_scan(
|
||||
get_scan_combine_fn("different_input_size_operator", True),
|
||||
elements,
|
||||
3,
|
||||
|
|
@ -3352,7 +3348,7 @@ class AssociativeScanTests(TestCase):
|
|||
RuntimeError,
|
||||
"torch.compile does not support sparse Tensors",
|
||||
):
|
||||
result = associative_scan(
|
||||
associative_scan(
|
||||
get_scan_combine_fn("add", True),
|
||||
x,
|
||||
0,
|
||||
|
|
@ -3383,7 +3379,7 @@ class AssociativeScanTests(TestCase):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result = associative_scan(fct, x, 0)
|
||||
associative_scan(fct, x, 0)
|
||||
|
||||
@unittest.skipIf(not SM70OrLater, "triton")
|
||||
@requires_cuda
|
||||
|
|
@ -3407,7 +3403,7 @@ class AssociativeScanTests(TestCase):
|
|||
torch._dynamo.exc.Unsupported,
|
||||
"Observed exception.*",
|
||||
):
|
||||
result = associative_scan(fct_wrong_pytree, inp, 0, combine_mode="generic")
|
||||
associative_scan(fct_wrong_pytree, inp, 0, combine_mode="generic")
|
||||
|
||||
@unittest.skipIf(not SM70OrLater, "triton")
|
||||
@requires_cuda
|
||||
|
|
@ -3418,7 +3414,7 @@ class AssociativeScanTests(TestCase):
|
|||
Exception,
|
||||
"For combine_mode='pointwise', the combine_fn needs to be pointwise",
|
||||
):
|
||||
out = associative_scan(
|
||||
associative_scan(
|
||||
get_scan_combine_fn("non_pointwise", True),
|
||||
x,
|
||||
0,
|
||||
|
|
@ -3875,7 +3871,6 @@ def forward(self, l_iter_, l_x_, l__self___dec_cond_fn, l__self___linear_bias_bo
|
|||
graphs = self._check_tracing(fn, inp)
|
||||
gm = graphs["symbolic"]
|
||||
outer_body = gm.while_loop_body_graph_0
|
||||
outer_cond = gm.while_loop_cond_graph_0
|
||||
inner_body = outer_body.while_loop_body_graph_0
|
||||
inner_cond = outer_body.while_loop_cond_graph_0
|
||||
self.assertExpectedInline(
|
||||
|
|
@ -5945,7 +5940,7 @@ def forward(self, s0 : torch.SymInt, L_a_ : torch.Tensor, L_b_ : torch.Tensor, L
|
|||
pass
|
||||
|
||||
with self.assertRaisesRegex(TypeError, "WrongHop"):
|
||||
wrong_hop = WrongHop("wrong_hop")
|
||||
WrongHop("wrong_hop")
|
||||
|
||||
def test_scan_functionalized(self):
|
||||
def f(init, xs):
|
||||
|
|
@ -6153,7 +6148,6 @@ class TestHopSchema(TestCase):
|
|||
|
||||
example_val = self._get_example_val(schema_type)
|
||||
li1 = [example_val]
|
||||
li2 = [example_val, example_val]
|
||||
ty1 = TypeGen.from_example(li1)
|
||||
ty2 = TypeGen.from_example(li1)
|
||||
self.assertEqual(ty1.parse(str(ty1)), ty1)
|
||||
|
|
@ -6166,7 +6160,6 @@ class TestHopSchema(TestCase):
|
|||
(schema_type + "_v", self._get_example_val(schema_type))
|
||||
for schema_type in _hop_schema_test_schema_types
|
||||
]
|
||||
op_name = "test_op"
|
||||
schema1 = FunctionSchemaGen.from_example("test_op1", inps, torch.ones(1))
|
||||
schema2 = FunctionSchemaGen.from_example(
|
||||
"test_op2",
|
||||
|
|
@ -6245,7 +6238,7 @@ class TestHopSchema(TestCase):
|
|||
x,
|
||||
)
|
||||
model = M()
|
||||
ep = torch.export.export(model, args)
|
||||
torch.export.export(model, args)
|
||||
graph_str = self._check_export(model, args, None)
|
||||
self.assertExpectedInline(
|
||||
graph_str,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# Owner(s): ["module: functorch"]
|
||||
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
|
|
@ -310,7 +309,7 @@ class TestMin(TestCase):
|
|||
def test_stack(self):
|
||||
i, j, d = dims()
|
||||
A = torch.rand(4, 5)
|
||||
r = stack([A[i, j]], d, j)
|
||||
_r = stack([A[i, j]], d, j)
|
||||
# a, b = r.unbind(d)
|
||||
# self.assertTrue(torch.allclose(a.order(i, j), i.expand(j).order(i, j)))
|
||||
# self.assertTrue(torch.allclose(b.order(i, j), j.expand(i).order(i, j)))
|
||||
|
|
@ -329,7 +328,7 @@ class TestMin(TestCase):
|
|||
a_ = a[i, k]
|
||||
b_ = b[k, j]
|
||||
q.size = 1
|
||||
r = (a_.expand(j, q) * b_.expand(i, q)).sum(k).order(q, i, j)
|
||||
_r = (a_.expand(j, q) * b_.expand(i, q)).sum(k).order(q, i, j)
|
||||
# r = (a_*b_).sum(k).order(q, i, j)
|
||||
# print(r)
|
||||
# print(a @ b)
|
||||
|
|
@ -362,15 +361,8 @@ class TestMin(TestCase):
|
|||
# XXX - chunk changes the size of a dimension, has to take a new dimension...
|
||||
# assert torch.allclose(A.chunk(2,1)[0], A[i, k].chunk(2, k)[0].order(i, k))
|
||||
assert torch.allclose(A[i].renorm(1, i, 7).order(i), A.renorm(1, 0, 7))
|
||||
kk = dims()
|
||||
# assert torch.allclose( torch.stack([A, A], 1), stack([A[i,k], A[i, k]], kk, k).order(i, kk, k))
|
||||
|
||||
k2 = dims()
|
||||
# r = cat((A[i, k], A[i,k]), k, k2)
|
||||
# assert torch.allclose(torch.cat([A, A], 1), r.order(i, k2))
|
||||
# assert k2.size == 2*k.size
|
||||
|
||||
assert torch.allclose(A.expand(5, -1, -1), A[i, k].expand(j).order(j, i, k))
|
||||
|
||||
z = dims()
|
||||
C = torch.arange(2)
|
||||
assert torch.allclose(A[:, 0:2], A[i, k].index(k, C[z]).order(i, z))
|
||||
|
|
@ -497,11 +489,10 @@ class TestMin(TestCase):
|
|||
_test_c()
|
||||
|
||||
def test_seg(self):
|
||||
A = torch.rand(3, 4)
|
||||
i, k = dims()
|
||||
i.size = 4
|
||||
k.size = 3
|
||||
r = i + k - 1
|
||||
i + k - 1
|
||||
|
||||
def test_expand(self):
|
||||
A = torch.rand(3, 4)
|
||||
|
|
@ -582,7 +573,6 @@ class TestMin(TestCase):
|
|||
|
||||
def test_index(self):
|
||||
A = torch.rand(3, 4)
|
||||
B = torch.rand(4, 5)
|
||||
i, j, k = dims()
|
||||
|
||||
o, l = dims()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# Owner(s): ["module: functorch"]
|
||||
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
|
|
@ -1302,8 +1301,6 @@ class TestAutogradFunction(TestCase):
|
|||
# https://github.com/pytorch/pytorch/issues/90224
|
||||
@unittest.expectedFailure
|
||||
def test_once_differentiable_grad_vjp(self, device):
|
||||
NumpyCubeNotComposable = self._get_NumpyCubeNotComposable()
|
||||
|
||||
# grad x vjp
|
||||
x = torch.randn([], device=device)
|
||||
grad_y = torch.randn_like(x)
|
||||
|
|
@ -1554,7 +1551,7 @@ class TestAutogradFunctionVmapAPI(TestCase):
|
|||
B = 2
|
||||
x = torch.randn(B, 3)
|
||||
with self.assertRaisesRegex(RuntimeError, "to have two returns"):
|
||||
result = vmap(Zeros.apply)(x)
|
||||
vmap(Zeros.apply)(x)
|
||||
|
||||
class TwoZeros(torch.autograd.Function):
|
||||
@staticmethod
|
||||
|
|
@ -1574,7 +1571,7 @@ class TestAutogradFunctionVmapAPI(TestCase):
|
|||
B = 2
|
||||
x = torch.randn(B, 3)
|
||||
with self.assertRaisesRegex(RuntimeError, "to have two returns"):
|
||||
result = vmap(Zeros.apply)(x)
|
||||
vmap(Zeros.apply)(x)
|
||||
|
||||
def test_incompatible_out_dims_error_msg(self, device):
|
||||
class Zeros(torch.autograd.Function):
|
||||
|
|
@ -1595,7 +1592,7 @@ class TestAutogradFunctionVmapAPI(TestCase):
|
|||
B = 2
|
||||
x = torch.randn(B, 3)
|
||||
with self.assertRaisesRegex(RuntimeError, "returned an incompatible"):
|
||||
result = vmap(Zeros.apply)(x)
|
||||
vmap(Zeros.apply)(x)
|
||||
|
||||
class Zeros(torch.autograd.Function):
|
||||
@staticmethod
|
||||
|
|
@ -1615,7 +1612,7 @@ class TestAutogradFunctionVmapAPI(TestCase):
|
|||
B = 2
|
||||
x = torch.randn(B, 3)
|
||||
with self.assertRaisesRegex(RuntimeError, "returned an incompatible"):
|
||||
result = vmap(Zeros.apply)(x)
|
||||
vmap(Zeros.apply)(x)
|
||||
|
||||
def test_kwarg_only_tensors(self, device):
|
||||
with self.assertRaisesRegex(NotImplementedError, "kwarg-only Tensor args"):
|
||||
|
|
@ -3154,7 +3151,7 @@ class TestHelpers(TestCase):
|
|||
|
||||
@staticmethod
|
||||
def backward(ctx, gy):
|
||||
wrapped = torch._functorch.autograd_function.CtxWithSavedTensors(
|
||||
wrapped = torch._functorch.autograd_function.CtxWithSavedTensors( # noqa: F841
|
||||
ctx, (y,)
|
||||
)
|
||||
return gy
|
||||
|
|
@ -3168,7 +3165,7 @@ class TestHelpers(TestCase):
|
|||
|
||||
@staticmethod
|
||||
def backward(ctx, gy):
|
||||
wrapped = torch._functorch.autograd_function.CtxWithSavedTensors(
|
||||
wrapped = torch._functorch.autograd_function.CtxWithSavedTensors( # noqa: F841
|
||||
ctx, (y,)
|
||||
)
|
||||
return gy
|
||||
|
|
@ -3307,8 +3304,6 @@ class TestHelpers(TestCase):
|
|||
@markDynamoStrictTest
|
||||
class TestComposability(TestCase):
|
||||
def test_deprecation_vmap(self, device):
|
||||
x = torch.randn(3, device=device)
|
||||
|
||||
# functorch version of the API is deprecated
|
||||
with self.assertWarnsRegex(FutureWarning, "Please use `torch.vmap`"):
|
||||
vmap(torch.sin)
|
||||
|
|
@ -4758,9 +4753,9 @@ def forward(self, x_1, indices_1) -> torch.Tensor:
|
|||
y = x.detach()
|
||||
return y + y
|
||||
|
||||
with FakeTensorMode() as mode:
|
||||
with FakeTensorMode():
|
||||
x = torch.ones(2, device=device, requires_grad=True)
|
||||
out = functionalize(f)(x)
|
||||
functionalize(f)(x)
|
||||
self.assertEqual(x.size(), (2,))
|
||||
|
||||
def test_functionalize_fx_simple(self, device):
|
||||
|
|
@ -5186,7 +5181,7 @@ class TestCompileTransforms(TestCase):
|
|||
|
||||
actual = wrapper_fn(x, y)
|
||||
expected = torch.compile(wrapper_fn, backend="eager", fullgraph=True)(x, y)
|
||||
fn = torch.compile(wrapper_fn, backend="eager", fullgraph=True)
|
||||
torch.compile(wrapper_fn, backend="eager", fullgraph=True)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def wrapper_fn(x, y):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: functorch"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
# All rights reserved.
|
||||
|
|
|
|||
|
|
@ -682,6 +682,8 @@ class TestVmapAPI(TestCase):
|
|||
vmap(torch.mul, (0, 0))(x, y)
|
||||
|
||||
def test_integer_in_dim_but_not_tensor_input_err_msg(self):
|
||||
# noqa: F841
|
||||
|
||||
def foo(xy):
|
||||
return xy[0] * xy[1]
|
||||
|
||||
|
|
@ -1246,7 +1248,7 @@ class TestVmapAPI(TestCase):
|
|||
|
||||
def test_data_attribute(self):
|
||||
def foo(x):
|
||||
y = x.data
|
||||
y = x.data # noqa: F841
|
||||
return x
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ rely on it for anything!**
|
|||
"""
|
||||
import operator
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
import torch
|
||||
from torch.fx import Graph, GraphModule, Node
|
||||
from torch.fx import Graph, GraphModule
|
||||
from torch.fx.graph import map_arg
|
||||
from torch.fx.proxy import Proxy
|
||||
from torch.nn.utils import fuse_conv_bn_weights
|
||||
|
|
@ -181,7 +180,7 @@ class ConvNormRelu(MinMaxObserver):
|
|||
parent_name, name = _parent_name(self.conv_node.target)
|
||||
setattr(quantizer.modules[parent_name], name, qconv)
|
||||
if self.bn_node is not None:
|
||||
parent_bn, bn_name = _parent_name(self.bn_node.target)
|
||||
_, bn_name = _parent_name(self.bn_node.target)
|
||||
# we can't just delete this because submodules's forwards (which are not longer use)
|
||||
# try to call it, so replace with something that does nothing.
|
||||
setattr(quantizer.modules[parent_name], bn_name, IdentityModule())
|
||||
|
|
@ -277,7 +276,6 @@ class Quantizer:
|
|||
def load_arg(a):
|
||||
return map_arg(a, lambda node: env[node.name])
|
||||
|
||||
output_node: Optional[Node] = None
|
||||
for node in self.graph.nodes:
|
||||
if node.op == "placeholder":
|
||||
result = next(args_iter)
|
||||
|
|
@ -322,12 +320,6 @@ class Quantizer:
|
|||
return quant_env[n.name]
|
||||
|
||||
def copy_recursive(node):
|
||||
def load_or_emit(n):
|
||||
if n.name in env or e.name in quant_env: # noqa: F821
|
||||
return load_arg(n, quantized=False)
|
||||
else:
|
||||
return copy_recursive(n)
|
||||
|
||||
r = env[node.name] = self.quantized_graph.node_copy(
|
||||
node, lambda n: load_arg(n, quantized=False)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class TestCSEPass(TestCase):
|
|||
return a + b
|
||||
|
||||
t = torch.randn(2, 2)
|
||||
P_ban_add = P = CSEPass(banned_ops=[torch.ops.aten.add])
|
||||
P_ban_add = CSEPass(banned_ops=[torch.ops.aten.add])
|
||||
check(self, f, t, 0, P=P_ban_add) # check that add is banned
|
||||
check(self, f, t, 1) # check that add is not banned by default
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# Owner(s): ["module: fx"]
|
||||
|
||||
import copy
|
||||
import unittest
|
||||
from typing import Optional, Set, Type
|
||||
|
|
@ -92,7 +91,7 @@ class TestDCE(TestCase):
|
|||
self.attr_1 = torch.nn.Parameter(torch.tensor([-0.9]))
|
||||
|
||||
def forward(self, x):
|
||||
a = x + 1
|
||||
a = x + 1 # noqa: F841
|
||||
return x + self.attr_1
|
||||
|
||||
self._run_dce_and_test(TestModule(), expect_dce_changes=True)
|
||||
|
|
@ -109,7 +108,7 @@ class TestDCE(TestCase):
|
|||
|
||||
def forward(self, x):
|
||||
a = x + 1
|
||||
b = a * 7
|
||||
b = a * 7 # noqa: F841
|
||||
return x + self.attr_1
|
||||
|
||||
self._run_dce_and_test(TestModule(), expect_dce_changes=True)
|
||||
|
|
@ -126,7 +125,7 @@ class TestDCE(TestCase):
|
|||
|
||||
def forward(self, x):
|
||||
a = x + 1
|
||||
b = a * self.attr_1
|
||||
b = a * self.attr_1 # noqa: F841
|
||||
return x + 11
|
||||
|
||||
self._run_dce_and_test(TestModule(), expect_dce_changes=True)
|
||||
|
|
@ -153,7 +152,7 @@ class TestDCE(TestCase):
|
|||
|
||||
class TestModule(torch.nn.Module):
|
||||
def forward(self, x, y):
|
||||
a = y + 2
|
||||
a = y + 2 # noqa: F841
|
||||
return x + 7
|
||||
|
||||
self._run_dce_and_test(TestModule(), expect_dce_changes=True)
|
||||
|
|
@ -172,7 +171,7 @@ class TestDCE(TestCase):
|
|||
self.relu = ReLUImpure()
|
||||
|
||||
def forward(self, a: torch.Tensor) -> torch.Tensor:
|
||||
r = self.relu(a)
|
||||
r = self.relu(a) # noqa: F841
|
||||
return a * 2
|
||||
|
||||
self._run_dce_and_test(
|
||||
|
|
@ -228,7 +227,7 @@ class TestDCE(TestCase):
|
|||
class TestModule(torch.nn.Module):
|
||||
def forward(self, a: torch.Tensor) -> torch.Tensor:
|
||||
b = a + 1
|
||||
c = torch._ops.ops.aten.add(b, b)
|
||||
c = torch._ops.ops.aten.add(b, b) # noqa: F841
|
||||
return a
|
||||
|
||||
# %add_out node should not be removed because it has side effects.
|
||||
|
|
@ -249,9 +248,7 @@ class TestDCE(TestCase):
|
|||
d = torch.ops.aten.mul.Tensor(a, b)
|
||||
e = torch.ops.aten.mul.Tensor(a, c)
|
||||
future = torch.ops._c10d_functional.all_reduce.default(e, "sum", "0")
|
||||
synced_e = torch.ops._c10d_functional.wait_tensor.default(
|
||||
future
|
||||
) # synced_e is not used
|
||||
torch.ops._c10d_functional.wait_tensor.default(future)
|
||||
return d
|
||||
|
||||
torch.distributed.init_process_group(
|
||||
|
|
@ -279,9 +276,7 @@ class TestDCE(TestCase):
|
|||
d = torch.ops.aten.mul(a, b)
|
||||
e = torch.ops.aten.mul(a, c)
|
||||
future = torch.ops._c10d_functional.all_reduce(e, "sum", "0")
|
||||
synced_e = torch.ops._c10d_functional.wait_tensor(
|
||||
future
|
||||
) # synced_e is not used
|
||||
torch.ops._c10d_functional.wait_tensor(future)
|
||||
return d
|
||||
|
||||
torch.distributed.init_process_group(
|
||||
|
|
|
|||
|
|
@ -214,10 +214,8 @@ class TestSplitOutputType(TestCase):
|
|||
|
||||
inputs = torch.randn((1, 3, 224, 224))
|
||||
|
||||
gm, tag_node = TestSplitOutputType.trace_and_tag(module, inputs, tags)
|
||||
split_gm, orig_to_split_fqn_mapping = split_by_tags(
|
||||
gm, tags, return_fqn_mapping=True
|
||||
)
|
||||
gm, _ = TestSplitOutputType.trace_and_tag(module, inputs, tags)
|
||||
split_gm, _ = split_by_tags(gm, tags, return_fqn_mapping=True)
|
||||
|
||||
gm_output = module(inputs)
|
||||
split_gm_output = split_gm(inputs)
|
||||
|
|
|
|||
|
|
@ -913,7 +913,7 @@ class TypeCheckerTest(TestCase):
|
|||
(2, 2, 10, 10),
|
||||
]
|
||||
|
||||
intermediate_list = [
|
||||
intermediate_list = [ # noqa: F841
|
||||
Dyn,
|
||||
(2, 5, 6, 9),
|
||||
(10, 15, 13, 14),
|
||||
|
|
@ -1139,7 +1139,7 @@ class TypeCheckerTest(TestCase):
|
|||
return out
|
||||
|
||||
B = BasicBlock()
|
||||
ast_rewriter = RewritingTracer()
|
||||
ast_rewriter = RewritingTracer() # noqa: F841
|
||||
traced = symbolic_trace(B)
|
||||
tc = GraphTypeChecker({}, traced)
|
||||
tc.type_check()
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ class TestMatcher(JitTestCase):
|
|||
WrapperModule(pattern), example_inputs
|
||||
).module()
|
||||
before_split_res = pattern_gm(*example_inputs)
|
||||
pattern_gm, name_node_map = _split_to_graph_and_name_node_map(pattern_gm)
|
||||
pattern_gm, _ = _split_to_graph_and_name_node_map(pattern_gm)
|
||||
after_split_res = pattern_gm(*example_inputs)
|
||||
self.assertEqual(before_split_res[0], after_split_res[0])
|
||||
self.assertEqual(before_split_res[1], after_split_res[1])
|
||||
|
|
|
|||
|
|
@ -342,10 +342,10 @@ class TestSubgraphRewriter(JitTestCase):
|
|||
):
|
||||
class M(torch.nn.Module):
|
||||
def forward(self, x, w1, w2, b1, b2):
|
||||
m0 = torch.cat([w1, w2])
|
||||
m0 = torch.cat([w1, w2]) # noqa: F841
|
||||
m1 = torch.cat([w1, w2])
|
||||
m2 = torch.cat([x, b2])
|
||||
t0 = torch.addmm(b1, m1, m2.t())
|
||||
t0 = torch.addmm(b1, m1, m2.t()) # noqa: F841
|
||||
t1 = torch.sum(w1, 1)
|
||||
t2 = torch.addmm(b1, m1, m2.t())
|
||||
return torch.sum(t1), torch.sum(t2)
|
||||
|
|
|
|||
|
|
@ -1011,8 +1011,7 @@ class HFOperations(unittest.TestCase):
|
|||
size = x.size()
|
||||
getitem = size[-1]
|
||||
view = x.view(-1, getitem)
|
||||
embed_tokens = self.embed_tokens(view)
|
||||
mul = embed_tokens * 32.0
|
||||
_embed_tokens = self.embed_tokens(view)
|
||||
getitem_1 = size[-1]
|
||||
gt = getitem_1 > 1
|
||||
return gt
|
||||
|
|
@ -1076,8 +1075,7 @@ class HFOperations(unittest.TestCase):
|
|||
size = x.size()
|
||||
getitem = size[-1]
|
||||
view = x.view(-1, getitem)
|
||||
embed_tokens = self.embed_tokens(view)
|
||||
mul = embed_tokens * 32.0
|
||||
_embed_tokens = self.embed_tokens(view)
|
||||
getitem_1 = size[-1]
|
||||
lt = getitem_1 < 1
|
||||
return lt
|
||||
|
|
@ -1558,7 +1556,7 @@ class TestSingleOperation(unittest.TestCase):
|
|||
self.relu = torch.nn.ReLU(inplace=True)
|
||||
|
||||
def forward(self, x: Dyn):
|
||||
y = self.relu(self.conv1(x))
|
||||
y = self.relu(self.conv1(x)) # noqa: F841
|
||||
z = self.relu(self.conv2(x))
|
||||
return z
|
||||
|
||||
|
|
@ -1667,12 +1665,7 @@ class TestSingleOperation(unittest.TestCase):
|
|||
def test_add(self):
|
||||
s1, s2, s3, s4 = z3.Ints("s1 s2 s3 s4")
|
||||
s11, s22, s33, s44 = z3.Ints("s11 s22 s33 s44")
|
||||
d1, d2, d3, d4 = (
|
||||
D(s11, s1),
|
||||
D(s22, s2),
|
||||
D(s33, s3),
|
||||
D(s44, s4),
|
||||
)
|
||||
d1, d2 = D(s11, s1), D(s22, s2)
|
||||
|
||||
class BasicBlock(torch.nn.Module):
|
||||
def forward(self, x: Dyn, y: Dyn):
|
||||
|
|
@ -2121,12 +2114,7 @@ class TestSingleOperation(unittest.TestCase):
|
|||
def test_reshape_annotated(self):
|
||||
s1, s2, s3, s4 = z3.Ints("s1 s2 s3 s4")
|
||||
s11, s22, s33, s44 = z3.Ints("s11 s22 s33 s44")
|
||||
d1, d2, d3, d4 = (
|
||||
D(s11, s1),
|
||||
D(s22, s2),
|
||||
D(s33, s3),
|
||||
D(s44, s4),
|
||||
)
|
||||
d1, d2 = D(s11, s1), D(s22, s2)
|
||||
|
||||
class BasicBlock(torch.nn.Module):
|
||||
def forward(self, x: TensorType([Dyn])):
|
||||
|
|
|
|||
|
|
@ -73,8 +73,6 @@ class TestInvokeSubgraph(TestCase):
|
|||
self.assertEqual(y.grad, y_clone.grad)
|
||||
|
||||
def test_multiple(self):
|
||||
n_layers = 2
|
||||
|
||||
@mark_compile_region
|
||||
def cos(x):
|
||||
return torch.cos(x)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: functorch"]
|
||||
# ruff: noqa: F841
|
||||
# flake8: noqa: B950
|
||||
import unittest
|
||||
from collections import deque
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# flake8: noqa
|
||||
# ruff: noqa: F841
|
||||
import torch
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ try:
|
|||
requires_multigpu,
|
||||
TestFailure,
|
||||
)
|
||||
except (unittest.SkipTest, ImportError) as e:
|
||||
except (unittest.SkipTest, ImportError):
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0)
|
||||
raise
|
||||
|
|
@ -2432,7 +2432,7 @@ class AOTInductorTestsTemplate:
|
|||
output_wo_y = torch.empty_like(x)
|
||||
output_with_y = torch.empty_like(x)
|
||||
|
||||
wo_kernel = add_kernel_with_optional_param[(1,)](
|
||||
add_kernel_with_optional_param[(1,)](
|
||||
x,
|
||||
None,
|
||||
output_wo_y,
|
||||
|
|
@ -2440,7 +2440,7 @@ class AOTInductorTestsTemplate:
|
|||
ARGS_PASSED="one",
|
||||
BLOCK_SIZE=BLOCK_SIZE,
|
||||
)
|
||||
with_kernel = add_kernel_with_optional_param[(1,)](
|
||||
add_kernel_with_optional_param[(1,)](
|
||||
x,
|
||||
y,
|
||||
output_with_y,
|
||||
|
|
@ -2870,8 +2870,6 @@ class AOTInductorTestsTemplate:
|
|||
x = self.bar(x)
|
||||
return x
|
||||
|
||||
orig_eager = MyModule()
|
||||
|
||||
self.check_model(MyModule(), (torch.randn(2, 3, device=self.device),))
|
||||
|
||||
def test_model_modified_weights(self):
|
||||
|
|
@ -2887,7 +2885,6 @@ class AOTInductorTestsTemplate:
|
|||
M = 16
|
||||
N = 10
|
||||
K = 128
|
||||
batch = 8
|
||||
example_inputs = (torch.randn(2, M, K, device=self.device),)
|
||||
model = Model(N, K, self.device)
|
||||
self.check_model(model, example_inputs)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ try:
|
|||
copy_tests,
|
||||
TestFailure,
|
||||
)
|
||||
except (unittest.SkipTest, ImportError) as e:
|
||||
except (unittest.SkipTest, ImportError):
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0)
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ try:
|
|||
copy_tests,
|
||||
TestFailure,
|
||||
)
|
||||
except (unittest.SkipTest, ImportError) as e:
|
||||
except (unittest.SkipTest, ImportError):
|
||||
if __name__ == "__main__":
|
||||
sys.exit(0)
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -225,7 +225,6 @@ class TestAOTInductorPackage(TestCase):
|
|||
def forward(self, a, b):
|
||||
return torch.cat([a, b], dim=0)
|
||||
|
||||
b = torch.randn(3, 4, device=self.device)
|
||||
dim0_a = Dim("dim0_a", min=1, max=10)
|
||||
dim0_b = Dim("dim0_b", min=1, max=20)
|
||||
dynamic_shapes = {"a": {0: dim0_a}, "b": {0: dim0_b}}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class AutoHeuristicTest(TestCase):
|
|||
|
||||
def assert_autoheuristic_collected_data(self):
|
||||
self.run_mm()
|
||||
device_name = AutoHeuristic.get_device_identifier()
|
||||
AutoHeuristic.get_device_identifier()
|
||||
path = self.get_path_to_autoheuristic_log("pad_mm")
|
||||
self.assertTrue(os.path.exists(path))
|
||||
num_lines = self.count_lines_in_file(path)
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@ class TestFxGraphCache(TestCase):
|
|||
compiled_fn = torch.compile(fn, dynamic=True, fullgraph=True)
|
||||
|
||||
x = torch.randn(4, 4, device=GPU_TYPE)
|
||||
result = compiled_fn(x)
|
||||
compiled_fn(x)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 0)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 0)
|
||||
|
|
@ -551,7 +551,7 @@ class TestFxGraphCache(TestCase):
|
|||
x = torch.randn(4, device=GPU_TYPE)
|
||||
y = torch.randn(4, device=GPU_TYPE)
|
||||
|
||||
result = compiled_fn(x, y)
|
||||
compiled_fn(x, y)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 0)
|
||||
|
|
@ -565,7 +565,7 @@ class TestFxGraphCache(TestCase):
|
|||
PyCodeCache.cache_clear()
|
||||
shutil.rmtree(os.path.join(cache_dir(), "triton"), ignore_errors=True)
|
||||
|
||||
result = compiled_fn(x, y)
|
||||
compiled_fn(x, y)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
|
||||
|
|
@ -579,7 +579,7 @@ class TestFxGraphCache(TestCase):
|
|||
PyCodeCache.cache_clear()
|
||||
shutil.rmtree(os.path.join(cache_dir(), "triton"), ignore_errors=True)
|
||||
|
||||
result = compiled_fn2(x, y)
|
||||
compiled_fn2(x, y)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 2)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
|
||||
|
|
@ -698,7 +698,7 @@ class TestFxGraphCache(TestCase):
|
|||
x = torch.randn(4, device=GPU_TYPE)
|
||||
y = torch.randn(4, device=GPU_TYPE)
|
||||
|
||||
result = compiled_fn(x, y)
|
||||
compiled_fn(x, y)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 0)
|
||||
|
|
@ -712,7 +712,7 @@ class TestFxGraphCache(TestCase):
|
|||
PyCodeCache.cache_clear()
|
||||
shutil.rmtree(os.path.join(cache_dir(), "triton"), ignore_errors=True)
|
||||
|
||||
result = compiled_fn(x, y)
|
||||
compiled_fn(x, y)
|
||||
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_miss"], 1)
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
|
||||
|
|
@ -768,7 +768,6 @@ class TestFxGraphCache(TestCase):
|
|||
|
||||
# Verify the "hit" case.
|
||||
self.reset()
|
||||
counter_val = 5
|
||||
self.assertEqual(fn(a, b), compiled_fn(a, b))
|
||||
self.assertEqual(counters["inductor"]["fxgraph_cache_hit"], 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import functools
|
||||
|
|
@ -800,7 +801,6 @@ main()
|
|||
|
||||
return torch.compile(gm, backend=inner_compiler)
|
||||
|
||||
fwd_compiler_fn = functools.partial(eager_with_check, is_bwd=False)
|
||||
bwd_compiler_fn = functools.partial(eager_with_check, is_bwd=True)
|
||||
|
||||
def fn(inputs):
|
||||
|
|
@ -941,7 +941,7 @@ main()
|
|||
torch._dynamo.reset()
|
||||
handle = torch._dynamo.convert_frame.register_bytecode_hook(bytecode_hook)
|
||||
try:
|
||||
out = compiled_fn(inputs)
|
||||
compiled_fn(inputs)
|
||||
self.assertTrue(len(inputs) == 0)
|
||||
finally:
|
||||
handle.remove()
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ def make_test(
|
|||
scheduler_eager.last_epoch = 1
|
||||
|
||||
with torch.set_grad_enabled(False):
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
compiled_step()
|
||||
opt_eager.step()
|
||||
if scheduler_cls:
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class CPUReproTests(TestCase):
|
|||
return func(*args, **kwargs)
|
||||
|
||||
with RecordFunctions():
|
||||
out = fn_compiled(inps)
|
||||
fn_compiled(inps)
|
||||
|
||||
self.assertTrue(conv_seen)
|
||||
|
||||
|
|
@ -2385,8 +2385,6 @@ class CPUReproTests(TestCase):
|
|||
x[0, 0] = torch.nan
|
||||
x[1, -1] = torch.nan
|
||||
|
||||
tol = 1e-2 if dtype == torch.bfloat16 else 1e-4
|
||||
|
||||
with config.patch({"cpp.simdlen": None}):
|
||||
for cpp_wrapper_flag in [True, False]:
|
||||
with config.patch({"cpp_wrapper": cpp_wrapper_flag}):
|
||||
|
|
@ -3121,7 +3119,6 @@ class CPUReproTests(TestCase):
|
|||
x1 = torch.randn((5, 20), dtype=dtype)
|
||||
x2 = torch.randn((5, 20), dtype=dtype)
|
||||
|
||||
tol = 1e-2 if dtype == torch.bfloat16 else 1e-4
|
||||
with config.patch({"cpp.simdlen": 1}):
|
||||
torch._dynamo.reset()
|
||||
metrics.reset()
|
||||
|
|
@ -3365,7 +3362,7 @@ class CPUReproTests(TestCase):
|
|||
permute_2, [16, 32], -1
|
||||
)
|
||||
getitem = split_with_sizes[0]
|
||||
getitem_1 = split_with_sizes[1]
|
||||
_getitem_1 = split_with_sizes[1]
|
||||
permute_3 = torch.ops.aten.permute.default(getitem, [0, 1, 3, 2])
|
||||
expand_1 = torch.ops.aten.expand.default(permute_3, [8, 4, 16, 144])
|
||||
clone_3 = torch.ops.aten.clone.default(
|
||||
|
|
@ -4615,7 +4612,7 @@ class CPUReproTests(TestCase):
|
|||
)
|
||||
)
|
||||
permute_default_8 = None
|
||||
permute_default_10 = torch.ops.aten.permute.default(
|
||||
_permute_default_10 = torch.ops.aten.permute.default(
|
||||
convert_element_type_default_19, [0, 2, 1, 3]
|
||||
)
|
||||
convert_element_type_default_19 = None
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import functools
|
||||
import gc
|
||||
import math
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class TestCUDACodeCache(InductorTestCase):
|
|||
y = torch.rand(10).float().cuda()
|
||||
a = 5.0
|
||||
expected_y = a * x + y
|
||||
res = dll_wrapper.saxpy(
|
||||
dll_wrapper.saxpy(
|
||||
ctypes.c_int(10),
|
||||
ctypes.c_float(a),
|
||||
ctypes.c_void_p(x.data_ptr()),
|
||||
|
|
@ -83,7 +83,7 @@ class TestCUDACodeCache(InductorTestCase):
|
|||
y = torch.rand(5).float().cuda()
|
||||
a = 2.0
|
||||
expected_y = a * x + y
|
||||
res = compiled_res.result().saxpy(
|
||||
compiled_res.result().saxpy(
|
||||
ctypes.c_int(5),
|
||||
ctypes.c_float(a),
|
||||
ctypes.c_void_p(x.data_ptr()),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
import contextlib
|
||||
import functools
|
||||
import gc
|
||||
|
|
|
|||
|
|
@ -825,7 +825,7 @@ class TestCutlassBackend(TestCase):
|
|||
wraps=select_no_algorithm,
|
||||
) as sa:
|
||||
torch.compile(my_addmm, dynamic=False)(x, a, b, 1.0, 2.0)
|
||||
args, kwargs = sa.call_args
|
||||
args, _ = sa.call_args
|
||||
op_name, choices, _, __ = args
|
||||
assert op_name == "addmm"
|
||||
cuda_template_count = 0
|
||||
|
|
@ -873,7 +873,7 @@ class TestCutlassBackend(TestCase):
|
|||
wraps=select_no_algorithm,
|
||||
) as sa:
|
||||
torch.compile(addmm, dynamic=False)(x, a, b, 1.0, 1.0)
|
||||
args, kwargs = sa.call_args
|
||||
args, _ = sa.call_args
|
||||
op_name, choices, _, __ = args
|
||||
assert op_name == "addmm"
|
||||
cuda_template_count = 0
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ class TestDecomposeMemMM(TestCase):
|
|||
def foo(x, y):
|
||||
return x.T.contiguous() @ y
|
||||
|
||||
out, code = run_and_get_code(foo, input1, input2)
|
||||
_, code = run_and_get_code(foo, input1, input2)
|
||||
|
||||
if GPU_TYPE == "xpu":
|
||||
# only 1 kernel generated on the XPU stack
|
||||
|
|
|
|||
|
|
@ -120,10 +120,6 @@ class TestDependencies(InductorTestCase):
|
|||
def test_normalize_with_stride_order_equal(self):
|
||||
x = sympy_index_symbol("x")
|
||||
y = sympy_index_symbol("y")
|
||||
var_ranges = {
|
||||
x: 1024,
|
||||
y: 2048,
|
||||
}
|
||||
|
||||
loop_order1 = MemoryDep(
|
||||
"access_the_same_buffer",
|
||||
|
|
@ -145,10 +141,6 @@ class TestDependencies(InductorTestCase):
|
|||
def test_normalize_with_stride_order_unequal(self):
|
||||
x = sympy_index_symbol("x")
|
||||
y = sympy_index_symbol("y")
|
||||
var_ranges = {
|
||||
x: 1024,
|
||||
y: 2048,
|
||||
}
|
||||
|
||||
loop_order1 = MemoryDep(
|
||||
"access_the_same_buffer",
|
||||
|
|
|
|||
|
|
@ -932,7 +932,6 @@ class TestFlexAttention(InductorTestCase):
|
|||
test_inference_only = True
|
||||
else:
|
||||
test_inference_only = False
|
||||
MAX_S = S
|
||||
block_mask1 = create_block_mask(noop_mask, 1, 1, S, S, device=self.device)
|
||||
sdpa_partial1 = create_attention(score_mod, block_mask=block_mask1)
|
||||
# The first eager batch, shape (B, H, S, D)
|
||||
|
|
@ -3357,7 +3356,7 @@ def forward(self, arg0_1, arg1_1, arg2_1, arg3_1, arg4_1):
|
|||
|
||||
# Run forward pass
|
||||
x = torch.randn(batch_shape, sequence_len, 512).cuda()
|
||||
y = model(x, block_mask=block_mask)
|
||||
model(x, block_mask=block_mask)
|
||||
|
||||
self.assertEqual(torch._dynamo.utils.counters["aot_autograd"]["ok"], 2)
|
||||
|
||||
|
|
@ -3925,8 +3924,6 @@ BlockMask(shape=(1,s1,s2048,s2048),ssparsity=46.88%,s
|
|||
@supported_platform
|
||||
@common_utils.parametrize("compile", [False, True])
|
||||
def test_no_q_info(self, compile: bool):
|
||||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
|
||||
def causal_mask(b, h, q_idx, kv_idx):
|
||||
return q_idx >= kv_idx
|
||||
|
||||
|
|
@ -4001,7 +3998,7 @@ BlockMask(shape=(1,s1,s2048,s2048),ssparsity=46.88%,s
|
|||
|
||||
device = "cuda"
|
||||
max_seq_len, doc_count = 128, 4
|
||||
B, H, SEQ_LEN, HEAD_DIM = 1, 1, max_seq_len, 8
|
||||
SEQ_LEN = max_seq_len
|
||||
|
||||
lengths = generate_random_lengths(max_seq_len, doc_count)
|
||||
offsets = length_to_offsets(lengths, device)
|
||||
|
|
@ -4031,7 +4028,6 @@ BlockMask(shape=(1,s1,s2048,s2048),ssparsity=46.88%,s
|
|||
lengths = generate_random_lengths(1024 + i, 5)
|
||||
offsets = length_to_offsets(lengths, "cuda")
|
||||
doc_ids = _offsets_to_doc_ids_tensor(offsets)
|
||||
total_seq_len = 1024 + i
|
||||
|
||||
def doc_mask_mod(b, h, q_idx, kv_idx):
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1554,7 +1554,7 @@ def forward(self, arg0_1, arg1_1, arg2_1, arg3_1, arg4_1):
|
|||
|
||||
return causal_offset_mask
|
||||
|
||||
def noop(score, b, h, q_idx, kv_idx):
|
||||
def noop(score, b, h, q_idx, kv_idx): # noqa: F841
|
||||
return score
|
||||
|
||||
mod = generate_causal_offset(
|
||||
|
|
|
|||
|
|
@ -147,11 +147,11 @@ class TestFP8Types(TestCase):
|
|||
|
||||
x_shape = (16, 16)
|
||||
x = torch.rand(*x_shape, device="cuda", dtype=dtype).to(e4m3_type)
|
||||
y_fp8 = compiled_fp8_matmul(x)
|
||||
y_fp8 = compiled_fp8_matmul(x) # noqa: F841
|
||||
|
||||
x_shape = (15, 16)
|
||||
x = torch.rand(*x_shape, device="cuda", dtype=dtype).to(e4m3_type)
|
||||
y_fp8 = compiled_fp8_matmul(x)
|
||||
y_fp8 = compiled_fp8_matmul(x) # noqa: F841
|
||||
|
||||
@unittest.skipIf(not PLATFORM_SUPPORTS_FP8, f8_msg)
|
||||
@parametrize("dtype", (torch.float16, torch.bfloat16, torch.float))
|
||||
|
|
@ -193,14 +193,14 @@ class TestFP8Types(TestCase):
|
|||
"Conversions between float8_e5m2 and float8_e4m3fn is not supported!",
|
||||
):
|
||||
x = torch.rand(*x_shape, device="cuda").to(dtype=torch.float8_e4m3fn)
|
||||
y = compiled_fp8_cast(x, torch.float8_e5m2)
|
||||
compiled_fp8_cast(x, torch.float8_e5m2)
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
torch._dynamo.exc.BackendCompilerFailed,
|
||||
"Conversions between float8_e5m2 and float8_e4m3fn is not supported!",
|
||||
):
|
||||
x = torch.rand(*x_shape, device="cuda").to(dtype=torch.float8_e5m2)
|
||||
y = compiled_fp8_cast(x, torch.float8_e4m3fn)
|
||||
compiled_fp8_cast(x, torch.float8_e4m3fn)
|
||||
|
||||
@unittest.skipIf(not PLATFORM_SUPPORTS_FP8, f8_msg)
|
||||
@parametrize("src_dtype", (torch.float16, torch.bfloat16, torch.float))
|
||||
|
|
@ -699,7 +699,7 @@ class TestFP8Lowering(TestCase):
|
|||
|
||||
linear_compiled = torch.compile(linear, backend="inductor", mode="max-autotune")
|
||||
with self.assertRaises(torch._dynamo.exc.TorchRuntimeError) as cm:
|
||||
y_compiled = linear_compiled(
|
||||
linear_compiled(
|
||||
x,
|
||||
w_t_fp8,
|
||||
w_inverse_scale,
|
||||
|
|
@ -738,7 +738,7 @@ class TestFP8Lowering(TestCase):
|
|||
|
||||
linear_compiled = torch.compile(linear, backend="inductor", mode="max-autotune")
|
||||
with self.assertRaises(torch._dynamo.exc.TorchRuntimeError) as cm:
|
||||
y_compiled = linear_compiled(
|
||||
linear_compiled(
|
||||
x,
|
||||
w_t_fp8,
|
||||
w_inverse_scale,
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ class TestFindIndependentSubsetGreedy(TestCase):
|
|||
return g, lookup
|
||||
|
||||
def verify(self, tree, subnodes, min_fuse, max_fuse, expected):
|
||||
g, lookup = self.build_graph(tree)
|
||||
_, lookup = self.build_graph(tree)
|
||||
subnodes = [lookup[n] for n in subnodes]
|
||||
expected = [[lookup[n] for n in sub] for sub in expected]
|
||||
opts = {
|
||||
|
|
|
|||
|
|
@ -251,7 +251,6 @@ class ExprPrinterTests(InductorTestCase):
|
|||
def test_print_pow(self):
|
||||
s1 = sympy.Symbol("foo", integer=True)
|
||||
s2 = sympy.Symbol("bar", integer=True)
|
||||
s3 = sympy.Symbol("baz", integer=True)
|
||||
|
||||
common_cases = [
|
||||
# expr, result
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
|
||||
from typing import List
|
||||
|
||||
import torch
|
||||
|
|
@ -198,7 +197,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
|
||||
def test_view_inplaced_functionalize_v2(self):
|
||||
def f(arg0_1):
|
||||
select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
auto_functionalized = auto_functionalized_v2(
|
||||
torch.ops.test_view.boo.default,
|
||||
_x_base_index=0,
|
||||
|
|
@ -208,7 +207,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
_all_bases=[arg0_1],
|
||||
)
|
||||
getitem_1 = auto_functionalized[1]
|
||||
copy_ = torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
return ()
|
||||
|
||||
x1 = torch.randn(3, device=device)
|
||||
|
|
@ -220,7 +219,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
# introduce a view another_view that is used `after` the copy
|
||||
def test_view_inplaced2_functionalize_v2(self):
|
||||
def f(arg0_1):
|
||||
select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
_select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
another_view = arg0_1[2]
|
||||
auto_functionalized = auto_functionalized_v2(
|
||||
torch.ops.test_view.boo.default,
|
||||
|
|
@ -231,7 +230,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
_all_bases=[arg0_1],
|
||||
)
|
||||
getitem_1 = auto_functionalized[1]
|
||||
copy_ = torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
_copy = torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
return another_view
|
||||
|
||||
x1 = torch.randn(3, device=device)
|
||||
|
|
@ -243,7 +242,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
# introduce a view another_view that is used `before` the copy
|
||||
def test_views_not_inplaced_functionalize_v2(self):
|
||||
def f(arg0_1):
|
||||
select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
_select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
another_view = arg0_1[2]
|
||||
auto_functionalized = auto_functionalized_v2(
|
||||
torch.ops.test_view.boo.default,
|
||||
|
|
@ -255,7 +254,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
)
|
||||
getitem_1 = auto_functionalized[1]
|
||||
use_another_view = another_view * 10
|
||||
copy_ = torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
_copy = torch.ops.aten.copy_.default(arg0_1, getitem_1)
|
||||
return use_another_view
|
||||
|
||||
x1 = torch.randn(3, device=device)
|
||||
|
|
@ -267,8 +266,8 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
# a view over input without copy node, inplace not allowed
|
||||
def test_views_not_inplaced2_functionalize_v2(self):
|
||||
def f(arg0_1):
|
||||
select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
another_view = arg0_1[2]
|
||||
_select = torch.ops.aten.select.int(arg0_1, 0, 0)
|
||||
_another_view = arg0_1[2]
|
||||
auto_functionalized = auto_functionalized_v2(
|
||||
torch.ops.test_view.boo.default,
|
||||
_x_base_index=0,
|
||||
|
|
@ -277,7 +276,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
_x_storage_offset=0,
|
||||
_all_bases=[arg0_1],
|
||||
)
|
||||
getitem_1 = auto_functionalized[1]
|
||||
_getitem_1 = auto_functionalized[1]
|
||||
return
|
||||
|
||||
x1 = torch.randn(3, device=device)
|
||||
|
|
@ -299,7 +298,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
_x_storage_offset=0,
|
||||
_all_bases=[a],
|
||||
)
|
||||
getitem_1 = auto_functionalized[1]
|
||||
_getitem_1 = auto_functionalized[1]
|
||||
return another_view
|
||||
|
||||
x1 = torch.randn(3, device=device)
|
||||
|
|
@ -450,7 +449,7 @@ class TestReinplacingPassCorrectness(InductorTestCase):
|
|||
return MySin.apply(x)
|
||||
|
||||
x = torch.randn(3, requires_grad=True, device=device)
|
||||
y = f(x)
|
||||
f(x)
|
||||
self.assertEqual(num_reinplacing_failures(), 0)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
import contextlib
|
||||
import os
|
||||
import subprocess
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class TestLayoutOptim(TestCase):
|
|||
x.sum().backward()
|
||||
|
||||
grads = []
|
||||
for name, param in m.named_parameters():
|
||||
for _, param in m.named_parameters():
|
||||
grad = param.grad
|
||||
if param.grad is None:
|
||||
grad = torch.zeros_like(param)
|
||||
|
|
@ -327,7 +327,7 @@ class TestLayoutOptim(TestCase):
|
|||
model = MyModel(input_dim, num_classes)
|
||||
model.to(device)
|
||||
|
||||
opt_model = torch.compile(model)
|
||||
opt_model = torch.compile(model) # noqa: F841
|
||||
|
||||
x = torch.ones((batch_size, 1, seq_len, input_dim), device=device)
|
||||
targets = torch.randint(
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class ImplDetailTest(TestCase):
|
|||
|
||||
def _create_computed_buffer():
|
||||
def inner_fn(index):
|
||||
i0, i1, i2, i3 = index
|
||||
i0, _, i2, i3 = index
|
||||
return ops.load(
|
||||
"primal", i3 + 49 * i2 + 2401 * ModularIndexing(i0, 1, 64)
|
||||
)
|
||||
|
|
@ -435,7 +435,6 @@ class LoopOrderingTest(TestCase):
|
|||
scale = torch.Tensor([10.0]).to("cuda")
|
||||
|
||||
E4M3_MAX_POS = torch.finfo(torch.float8_e4m3fn).max
|
||||
E5M2_MAX_POS = torch.finfo(torch.float8_e5m2).max
|
||||
|
||||
def test_pattern2(tensor_x_inp, scale_x):
|
||||
tensor_x = tensor_x_inp * scale_x
|
||||
|
|
|
|||
|
|
@ -1192,7 +1192,7 @@ class TestPrologueFusion(TestCase):
|
|||
self.check_code(code[0], num_kernels=1, num_allocs=1, num_deallocs=3)
|
||||
|
||||
# should be done in low precision
|
||||
f = (
|
||||
(
|
||||
FileCheck()
|
||||
.check("for k_idx")
|
||||
.check_not("to(tl.float32)")
|
||||
|
|
@ -1216,7 +1216,7 @@ class TestPrologueFusion(TestCase):
|
|||
self.check_code(code[0], num_kernels=1, num_allocs=1, num_deallocs=2)
|
||||
|
||||
# should be done in low precision, no arithmetic
|
||||
f = (
|
||||
(
|
||||
FileCheck()
|
||||
.check("for k_idx")
|
||||
.check_not("to(tl.float32)")
|
||||
|
|
@ -1232,7 +1232,7 @@ class TestPrologueFusion(TestCase):
|
|||
self.check_code(code[0], num_kernels=1, num_allocs=1, num_deallocs=2)
|
||||
|
||||
# should not be done in low precision
|
||||
f = (
|
||||
(
|
||||
FileCheck()
|
||||
.check("for k_idx")
|
||||
.check("to(tl.float32)")
|
||||
|
|
@ -1369,7 +1369,7 @@ class TestPrologueFusion(TestCase):
|
|||
@config.patch(realize_reads_threshold=1, realize_opcount_threshold=1)
|
||||
@parametrize("benchmark_fusion", (True, False))
|
||||
def test_prologue_read_into_both_inputs(self, benchmark_fusion):
|
||||
M = K = N = 256
|
||||
M = K = 256
|
||||
|
||||
# not supported today. it could be, but typically the pointwise nodes would get
|
||||
# inlined into separate nodes.
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class TestMoveConstructorsToCuda(TestCase):
|
|||
return x[c1 + c2], c2 - 4 * 2
|
||||
|
||||
inp = torch.rand([4]).cuda()
|
||||
out, code = run_and_get_code(foo, inp)
|
||||
_, code = run_and_get_code(foo, inp)
|
||||
FileCheck().check_not("triton.jit").run(code[0])
|
||||
|
||||
@torch.compile()
|
||||
|
|
@ -86,7 +86,7 @@ class TestMoveConstructorsToCuda(TestCase):
|
|||
c1 = torch.ones([4], dtype=torch.long)
|
||||
return x[c1 + c2], c2 - 4 * 2
|
||||
|
||||
out, code = run_and_get_code(foo, inp)
|
||||
_, code = run_and_get_code(foo, inp)
|
||||
FileCheck().check_not("triton.jit").run(code[0])
|
||||
|
||||
@requires_multigpu()
|
||||
|
|
|
|||
|
|
@ -225,8 +225,8 @@ class MultiKernelTest(TestCase):
|
|||
y = torch.randn(8, device=GPU_TYPE)
|
||||
y_ref = y.clone()
|
||||
|
||||
ref = f(x, y_ref)
|
||||
act = torch.compile(f)(x, y)
|
||||
ref = f(x, y_ref) # noqa: F841
|
||||
act = torch.compile(f)(x, y) # noqa: F841
|
||||
self.assertEqual(y_ref, y)
|
||||
|
||||
def test_reduction_scratch_buffer(self, force_multi_kernel=1):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# mypy: ignore-errors
|
||||
# ruff: noqa: F841
|
||||
# flake8: noqa
|
||||
import collections
|
||||
import collections.abc
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class PadMMTest(TestCase):
|
|||
):
|
||||
res1 = fn(a, b)
|
||||
compiled_fn = torch.compile(fn)
|
||||
res2, (code,) = run_and_get_code(compiled_fn, a, b)
|
||||
res2, (_,) = run_and_get_code(compiled_fn, a, b)
|
||||
self.assertEqual(res1, res2)
|
||||
|
||||
@inductor_config.patch(force_shape_pad=True)
|
||||
|
|
|
|||
|
|
@ -1268,7 +1268,7 @@ class TestPatternMatcher(TestCase):
|
|||
def fn(a, b):
|
||||
return torch.mm(a, b).clone()
|
||||
|
||||
result, (code) = run_and_get_code(fn, torch.randn(8, 8), torch.randn(8, 8))
|
||||
_, (code) = run_and_get_code(fn, torch.randn(8, 8), torch.randn(8, 8))
|
||||
# clone would create a buf1
|
||||
self.assertIn("return (buf0, )", code[0])
|
||||
self.assertNotIn("async_compile.cpp", code[0])
|
||||
|
|
@ -1679,7 +1679,7 @@ class TestPatternMatcher(TestCase):
|
|||
) -> None:
|
||||
print("vllm::fused_rms_norm_quant_static")
|
||||
result_rms = torch.mul(input, weight) + epsilon
|
||||
result = torch.mul(result_rms, scale).to(torch.int8)
|
||||
_result = torch.mul(result_rms, scale).to(torch.int8)
|
||||
scale.fill_(0.5)
|
||||
|
||||
@torch.library.custom_op("vllm::rms_norm", mutates_args=["result"])
|
||||
|
|
@ -1690,7 +1690,7 @@ class TestPatternMatcher(TestCase):
|
|||
epsilon: float,
|
||||
) -> None:
|
||||
# bogus implementation doesn't matter
|
||||
result = torch.mul(input, weight) + epsilon
|
||||
_result = torch.mul(input, weight) + epsilon
|
||||
|
||||
@torch.library.custom_op(
|
||||
"vllm::static_scaled_int8_quant", mutates_args=["result", "scale"]
|
||||
|
|
@ -1702,7 +1702,7 @@ class TestPatternMatcher(TestCase):
|
|||
azp: Optional[torch.Tensor] = None,
|
||||
) -> None:
|
||||
# bogus implementation doesn't matter
|
||||
result = torch.mul(input, scale).to(torch.int8)
|
||||
_result = torch.mul(input, scale).to(torch.int8)
|
||||
scale.fill_(0.5)
|
||||
|
||||
def rms_pattern_static(
|
||||
|
|
@ -1766,8 +1766,8 @@ class TestPatternMatcher(TestCase):
|
|||
)
|
||||
|
||||
def custom_pass(graph: torch.fx.Graph) -> torch.fx.Graph:
|
||||
count = my_patterns.apply(graph)
|
||||
# print(f"Count: {count}")
|
||||
_count = my_patterns.apply(graph)
|
||||
# print(f"Count: {_count}")
|
||||
graph.eliminate_dead_code()
|
||||
# graph.print_tabular()
|
||||
return graph
|
||||
|
|
|
|||
|
|
@ -1148,7 +1148,7 @@ class InplacingTests(TestCase):
|
|||
x = x + torch.ops.mylib.foo(q, k_cache, v_cache)
|
||||
return x
|
||||
|
||||
compiled_out, (code,) = run_and_get_code(
|
||||
_, (code,) = run_and_get_code(
|
||||
torch.compile(f, fullgraph=True),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class DynamoProfilerTests(torch._inductor.test_case.TestCase):
|
|||
|
||||
kernel_name = "hipModuleLaunchKernel" if torch.version.hip else "cuLaunchKernel"
|
||||
|
||||
def nameMatchesLaunchKernel(event_name):
|
||||
def nameMatchesLaunchKernel(event_name): # noqa: F841
|
||||
return kernel_name in event_name
|
||||
|
||||
self.assertTrue(
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class SmokeTest(TestCase):
|
|||
|
||||
def test_compile_invalid_options(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
opt_f = torch.compile(_test_f, mode="ha")
|
||||
torch.compile(_test_f, mode="ha")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -781,7 +781,7 @@ class TestSplitCatFxPasses(TestCase):
|
|||
def unbind_stack(x):
|
||||
return torch.stack(torch.unbind(x, 1), 1)
|
||||
|
||||
def unbind_cat(x):
|
||||
def unbind_cat(x): # noqa: F841
|
||||
return torch.cat(torch.unbind(x, dim=-3), 1)
|
||||
|
||||
def unbind_stack_argspec1(x):
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class TestStandaloneInductor(TestCase):
|
|||
mod = MyModule3().eval()
|
||||
inp = torch.randn(10)
|
||||
correct = mod(inp)
|
||||
gm, guards = dynamo.export(mod, inp, aten_graph=True)
|
||||
gm, _ = dynamo.export(mod, inp, aten_graph=True)
|
||||
mod_opt = inductor.compile(gm, [inp])
|
||||
actual = mod_opt(inp)
|
||||
self.assertEqual(actual, correct)
|
||||
|
|
@ -92,7 +92,7 @@ class TestStandaloneInductor(TestCase):
|
|||
mod = MyModule2().eval()
|
||||
inp = {"key": [torch.randn(10), torch.randn(10)]}
|
||||
correct = mod(inp)
|
||||
gm, guards = dynamo.export(mod, inp)
|
||||
gm, _ = dynamo.export(mod, inp)
|
||||
mod_opt = inductor.compile(gm, [inp])
|
||||
actual = mod_opt(inp)
|
||||
self.assertEqual(actual, correct)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
import contextlib
|
||||
import copy
|
||||
import dataclasses
|
||||
|
|
|
|||
|
|
@ -110,8 +110,8 @@ def print_seen():
|
|||
return "{" + r + "}"
|
||||
|
||||
def sort_key(kv):
|
||||
k, v = kv
|
||||
device_type, op = k
|
||||
k, _ = kv
|
||||
_, op = k
|
||||
if isinstance(op, tuple):
|
||||
return op
|
||||
else:
|
||||
|
|
@ -1015,7 +1015,7 @@ class TestInductorOpInfo(TestCase):
|
|||
# print(f"CONSIDERING OP {op_name} on {device_type} with {dtype} |
|
||||
# {inductor_skips[device_type].get(op_name, set())}", flush=True)
|
||||
if dtype in inductor_skips[device_type].get(op_name, set()):
|
||||
test_expect = ExpectedTestResult.SKIP
|
||||
test_expect = ExpectedTestResult.SKIP # noqa: F841
|
||||
# with open("test_output.txt", "a") as f:
|
||||
# print(f"SKIPPING OP {op_name} on {device_type}", flush=True, file=f)
|
||||
# print(f"SKIPPING OP {op_name} on {device_type}", flush=True)
|
||||
|
|
@ -1026,9 +1026,9 @@ class TestInductorOpInfo(TestCase):
|
|||
].get(
|
||||
op_name, set()
|
||||
):
|
||||
test_expect = ExpectedTestResult.XFAILURE
|
||||
test_expect = ExpectedTestResult.XFAILURE # noqa: F841
|
||||
else:
|
||||
test_expect = ExpectedTestResult.SUCCESS
|
||||
test_expect = ExpectedTestResult.SUCCESS # noqa: F841
|
||||
|
||||
overridden_kwargs = {}
|
||||
overridden_kwargs.update(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
import contextlib
|
||||
import importlib
|
||||
import unittest
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class TestTritonHeuristics(TestCase):
|
|||
cfg.pre_hook = pre_hook
|
||||
|
||||
with self.assertRaisesRegex(AssertionError, "pre_hook"):
|
||||
autotuner = CachingAutotuner(**args)
|
||||
CachingAutotuner(**args)
|
||||
|
||||
def test_autotune_hints_to_configs(self):
|
||||
device_props = DeviceProperties.create(torch.device(GPU_TYPE))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["module: inductor"]
|
||||
# ruff: noqa: F841
|
||||
# flake8: noqa: E731
|
||||
# Skip do not assign a lambda expression, use a def
|
||||
import functools
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TestTritonWrapper(TestCase):
|
|||
N = 10
|
||||
x = torch.rand(N).to(device=GPU_TYPE)
|
||||
y = torch.rand(N).to(device=GPU_TYPE)
|
||||
out = f(x, y)
|
||||
out = f(x, y) # noqa: F841
|
||||
compiled_module = self.get_compiled_module()
|
||||
# to make sure the subprocess runs on the exact same path as the parent process
|
||||
# we augment the PYTHONPATH env var
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class TestUnbackedSymints(InductorTestCase):
|
|||
return nz.expand([128, -1, 2])
|
||||
|
||||
x = make_tensor(32, 4, device=device, dtype=torch.float32, exclude_zero=True)
|
||||
actual = torch.compile(fn, fullgraph=True)(x)
|
||||
torch.compile(fn, fullgraph=True)(x)
|
||||
|
||||
@skipGPUIf(not HAS_GPU, "requires gpu and triton")
|
||||
@dynamo_config.patch({"capture_dynamic_output_shape_ops": True})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
from typing import List
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class TestAutodiffSubgraphSlicing(JitTestCase):
|
|||
input = torch.rand(6, 10).requires_grad_()
|
||||
with disable_autodiff_subgraph_inlining():
|
||||
with enable_profiling_mode_for_profiling_tests():
|
||||
output = func(input, profile_and_replay=True)
|
||||
func(input, profile_and_replay=True)
|
||||
FileCheck().check_not("prim::DifferentiableGraph").run(
|
||||
func.graph_for(input)
|
||||
)
|
||||
|
|
@ -225,7 +225,7 @@ class TestAutodiffSubgraphSlicing(JitTestCase):
|
|||
input0 = torch.randn((2,), requires_grad=True)
|
||||
input1 = torch.randn((2,))
|
||||
output_ref = func(input0, input1)
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
output = jit_f(input0, input1)
|
||||
assert output_ref[0].requires_grad == output[0].requires_grad
|
||||
assert output_ref[1][0].requires_grad == output[1][0].requires_grad
|
||||
|
|
@ -294,7 +294,7 @@ class TestAutodiffSubgraphSlicing(JitTestCase):
|
|||
NUM_PROFILED_RUNS = 1
|
||||
with num_profiled_runs(NUM_PROFILED_RUNS):
|
||||
WARMUP = 3 # 2 runs to reach backward + 1 to optimize it
|
||||
for x in range(WARMUP):
|
||||
for _ in range(WARMUP):
|
||||
o = t(input, bias)
|
||||
o.sum().backward()
|
||||
|
||||
|
|
@ -416,7 +416,6 @@ class TestAutodiffSubgraphSlicing(JitTestCase):
|
|||
|
||||
graph = self._perform_ad_subgraph_slicing(fn, 1, 1, 1, 1)
|
||||
|
||||
num_nodes = 4 if GRAPH_EXECUTOR == ProfilingMode.PROFILING else 3
|
||||
# add moved down
|
||||
g_str = str(graph)
|
||||
FileCheck().check_not("aten::add").run(g_str[0 : g_str.find("return")])
|
||||
|
|
|
|||
|
|
@ -193,14 +193,14 @@ class TestAwait(JitTestCase):
|
|||
def C_wait_impl(self: C) -> C:
|
||||
return C(self._a * 2, self._b * 3)
|
||||
|
||||
def fn_arg_C(x: C) -> Tensor:
|
||||
def fn_arg_C(x: C) -> Tensor: # noqa: F841
|
||||
return x._a + x._b
|
||||
|
||||
def fn(x: Tensor):
|
||||
aw: Await[C] = torch.jit._awaitable(C_wait_impl, C(x, x))
|
||||
_a = torch.eye(2)
|
||||
ai = aw._a
|
||||
awb = aw.b()
|
||||
awb = aw.b() # noqa: F841
|
||||
c = C(2 * x, 2 * x)
|
||||
return _a + ai + x + c._a + c.b()
|
||||
|
||||
|
|
@ -320,7 +320,7 @@ class TestAwait(JitTestCase):
|
|||
|
||||
def main(x: Tensor, y: Tensor) -> Tensor:
|
||||
aw = torch.jit._awaitable(delayed, x)
|
||||
z = gap(y)
|
||||
z = gap(y) # noqa: F841
|
||||
k = torch.jit._awaitable_wait(aw)
|
||||
return y + k
|
||||
|
||||
|
|
@ -371,7 +371,7 @@ class TestAwait(JitTestCase):
|
|||
|
||||
def main(x: Tensor) -> Tensor:
|
||||
aw = torch.jit._awaitable(delayed, x)
|
||||
z = gap(x)
|
||||
z = gap(x) # noqa: F841
|
||||
y = fn(aw)
|
||||
return y + x
|
||||
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ class BasicModuleUnavailableTest(JitBackendTestCase):
|
|||
'raise Exception("Backend is not available."',
|
||||
):
|
||||
backend_method = self.lowered_module.__getattr__("forward")
|
||||
backend_output = backend_method(*(input, input))
|
||||
backend_method(*(input, input))
|
||||
|
||||
@skipIfRocm
|
||||
def test_save_load(self):
|
||||
|
|
@ -220,7 +220,7 @@ class BasicModuleUnavailableTest(JitBackendTestCase):
|
|||
r"Backend is not available.",
|
||||
'raise Exception("Backend is not available."',
|
||||
):
|
||||
imported = torch.jit.load(buffer)
|
||||
torch.jit.load(buffer)
|
||||
|
||||
|
||||
class NestedModuleTest(JitBackendTestCase):
|
||||
|
|
@ -624,7 +624,7 @@ class ErrorMessagesWithCompiler(JitBackendTestCase):
|
|||
""",
|
||||
"",
|
||||
):
|
||||
lowered_module_n = torch._C._jit_to_backend(
|
||||
torch._C._jit_to_backend(
|
||||
"backend_with_compiler_demo", scripted_module_n, {"forward": {"": ""}}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -287,9 +287,9 @@ class TestTensorBuiltins(JitTestCase):
|
|||
def test_func(func, x, tensor):
|
||||
try:
|
||||
result = func(x, tensor)
|
||||
except RuntimeError as e:
|
||||
except RuntimeError:
|
||||
result = True
|
||||
except TypeError as e:
|
||||
except TypeError:
|
||||
result = True
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import io
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import gc
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class TestDtypeBase(JitTestCase):
|
|||
try:
|
||||
# Eager execution
|
||||
expected_res = fn(*args)
|
||||
except RuntimeError as e:
|
||||
except RuntimeError:
|
||||
return
|
||||
|
||||
expected_dtype = expected_res.dtype
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import io
|
||||
import unittest
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class TestFuserCommon(JitTestCase):
|
|||
|
||||
x = torch.randn(5, requires_grad=not rq)
|
||||
# cause optimization to be created
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
fn(x)
|
||||
# test fallback when optimization is not applicable
|
||||
y = fn(torch.randn(5, requires_grad=rq))
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class TestGenerator(JitTestCase):
|
|||
|
||||
# Run this 3 times to ensure that the generator is being manually seeded
|
||||
# each time the traced function is run
|
||||
for i in range(3):
|
||||
for _ in range(3):
|
||||
torch.manual_seed(1)
|
||||
|
||||
eager_tensor = f()
|
||||
|
|
@ -64,7 +64,7 @@ class TestGenerator(JitTestCase):
|
|||
|
||||
# Run this 3 times to ensure that the generator is being manually seeded
|
||||
# each time the traced function is run
|
||||
for i in range(3):
|
||||
for _ in range(3):
|
||||
torch.manual_seed(1)
|
||||
|
||||
eager_tensor = f()
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class SubmoduleForwardTupleInput(torch.nn.Module):
|
|||
self.name = name
|
||||
|
||||
def forward(self, input: Tuple[int]):
|
||||
input_access = input[0]
|
||||
input_access = input[0] # noqa: F841
|
||||
return (1,)
|
||||
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ class ModuleForwardTupleInput(torch.nn.Module):
|
|||
self.submodule = SubmoduleForwardTupleInput(submodule_name)
|
||||
|
||||
def forward(self, input: Tuple[int]):
|
||||
input_access = input[0]
|
||||
input_access = input[0] # noqa: F841
|
||||
return self.submodule((1,))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class TestIgnoreContextManager(JitTestCase):
|
|||
a: int = 4
|
||||
b: int = 5
|
||||
with torch.jit._IgnoreContextManager(a="inp:int", b="inp:int"):
|
||||
l = [2 + b for i in range(a) if i > 2]
|
||||
l = [2 + b for i in range(a) if i > 2] # noqa: F841
|
||||
return a
|
||||
|
||||
model = A()
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ class TestIsinstance(JitTestCase):
|
|||
hit = not hit
|
||||
for el in obj:
|
||||
# perform some tensor operation
|
||||
y = el.clamp(0, 0.5)
|
||||
y = el.clamp(0, 0.5) # noqa: F841
|
||||
if torch.jit.isinstance(obj, Dict[str, str]):
|
||||
hit = not hit
|
||||
str_cat = ""
|
||||
|
|
|
|||
|
|
@ -113,6 +113,6 @@ class TestJitUtils(JitTestCase):
|
|||
|
||||
def test_no_tracer_warn_context_manager(self):
|
||||
torch._C._jit_set_tracer_state_warn(True)
|
||||
with jit_utils.NoTracerWarnContextManager() as no_warn:
|
||||
with jit_utils.NoTracerWarnContextManager():
|
||||
self.assertEqual(False, torch._C._jit_get_tracer_state_warn())
|
||||
self.assertEqual(True, torch._C._jit_get_tracer_state_warn())
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import inspect
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -376,7 +376,7 @@ class TestModels(JitTestCase):
|
|||
batch_size = inputs.size()[1]
|
||||
state_shape = self.config.n_cells, batch_size, self.config.d_hidden
|
||||
h0 = c0 = inputs.new_zeros(state_shape)
|
||||
outputs, (ht, ct) = self.rnn(inputs, (h0, c0))
|
||||
_, (ht, _) = self.rnn(inputs, (h0, c0))
|
||||
return (
|
||||
ht[-1]
|
||||
if not self.config.birnn
|
||||
|
|
@ -593,7 +593,6 @@ class TestModels(JitTestCase):
|
|||
@slowTest
|
||||
@skipIfNoTorchVision
|
||||
def test_script_module_trace_resnet18(self):
|
||||
x = torch.ones(1, 3, 224, 224)
|
||||
m_orig = torch.jit.trace(
|
||||
torchvision.models.resnet18(), torch.ones(1, 3, 224, 224)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ class TestModuleContainers(JitTestCase):
|
|||
|
||||
m = MyModule()
|
||||
self.checkModule(m, [torch.randn(2, 2)])
|
||||
mm = torch.jit.script(m)
|
||||
torch.jit.script(m)
|
||||
|
||||
def test_moduledict_getitem(self):
|
||||
class MyModule(torch.nn.Module):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -105,9 +105,7 @@ class TestOptimizeForMobilePreserveDebugInfo(JitTestCase):
|
|||
bias=self.conv_transpose2d_bias,
|
||||
)
|
||||
|
||||
minibatch = 1
|
||||
in_channels = 6
|
||||
iH = 4
|
||||
iW = 5
|
||||
out_channels = 6
|
||||
kH = 2
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class TestPeephole(JitTestCase):
|
|||
return y + y
|
||||
|
||||
a = torch.ones(4, 4)
|
||||
j = self.checkScript(test_write, (a,))
|
||||
self.checkScript(test_write, (a,))
|
||||
|
||||
def test_peephole_no_output_aliasing(self):
|
||||
def test_peephole(x):
|
||||
|
|
@ -93,7 +93,7 @@ class TestPeephole(JitTestCase):
|
|||
@torch.jit.script
|
||||
def foo(x, y, z):
|
||||
li = [x, y, z]
|
||||
for i in range(len(x)):
|
||||
for _ in range(len(x)):
|
||||
li.append(x)
|
||||
return len([x, y, z])
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ class TestPeephole(JitTestCase):
|
|||
@torch.jit.script
|
||||
def foo(x, y, z):
|
||||
li = [x, y, z]
|
||||
for i in range(len(x)):
|
||||
for _ in range(len(x)):
|
||||
li.append(x)
|
||||
return li[-2]
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class TestProfiler(JitTestCase):
|
|||
x = torch.ones(1)
|
||||
y = torch.ones(1)
|
||||
foo(x, y)
|
||||
b = foo(x, y)
|
||||
b = foo(x, y) # noqa: F841
|
||||
g = torch.jit.last_executed_optimized_graph()
|
||||
self.assertEqual(len(list(g.findAllNodes("prim::TypeCheck"))), 2)
|
||||
FileCheck().check("TensorExpr").check("aten::add_").check("TensorExpr").run(g)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import os
|
||||
import re
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class TestRemoveMutation(JitTestCase):
|
|||
|
||||
def intermediary_use():
|
||||
a = [1, 2]
|
||||
b = len(a)
|
||||
b = len(a) # noqa: F841
|
||||
a.append(3)
|
||||
return a
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import io
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ class TestSymbolicShapeAnalysis(JitTestCase):
|
|||
# to make into a jit function cant have multiple outputs
|
||||
g.makeMultiOutputIntoTuple()
|
||||
func = torch._C._create_function_from_graph("partial_eval_graph", g)
|
||||
mapping = shape_compute_graph.graph_output_to_symbolic_shape_dim()
|
||||
mapping = shape_compute_graph.graph_output_to_symbolic_shape_dim() # noqa: F841
|
||||
output_shape = func(tensor.size())
|
||||
# the first 4 dims are input sym dimensions, then the ,
|
||||
self.assertEqual(list(output_shape[0:4]), list(tensor.size()))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import copy
|
||||
import io
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# Owner(s): ["oncall: jit"]
|
||||
# ruff: noqa: F841
|
||||
|
||||
import copy
|
||||
import io
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user