diff --git a/benchmarks/transformer/score_mod.py b/benchmarks/transformer/score_mod.py index 7881cfedad4..96ea4d2e655 100644 --- a/benchmarks/transformer/score_mod.py +++ b/benchmarks/transformer/score_mod.py @@ -221,7 +221,7 @@ def run_single_backend_sdpa( ) -> ExperimentResults: backend_context = get_backend_context(backend) with backend_context: - device = torch.device("cuda") + _device = torch.device("cuda") eager_sdpa = generate_eager_sdpa( config.attn_type, config.shape, config.dtype, block_mask, score_mod ) @@ -372,8 +372,6 @@ def run_single_experiment( requires_grad=config.calculate_bwd_time, nested_tensors=config.attn_type == "document_mask", ) - is_decoding = q_seq_len == 1 - score_mod = generate_score_mod(config.attn_type, config.shape) block_mask, mask_kwargs = generate_block_mask(config.attn_type, config.shape) kernel_options = get_kernel_options(config.attn_type, config.shape) diff --git a/pyproject.toml b/pyproject.toml index 81b2b2cbc19..1f9844eabbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,6 @@ ignore = [ "E741", "EXE001", "F405", - "F841", # these ignores are from flake8-logging-format; please fix! "G101", # these ignores are from ruff NPY; please fix! diff --git a/test/dynamo/test_ctx_manager.py b/test/dynamo/test_ctx_manager.py index 306d793d032..c39bd74364d 100644 --- a/test/dynamo/test_ctx_manager.py +++ b/test/dynamo/test_ctx_manager.py @@ -2696,7 +2696,7 @@ class CPythonContextManagerTestCase(torch._dynamo.test_case.TestCase): @torch.compile(backend="eager", fullgraph=True) def fn(t): - y = t.sum() + _y = t.sum() with self.assertRaises(ZeroDivisionError): with woohoo() as x: self.assertEqual(state, [1]) @@ -2718,7 +2718,7 @@ class CPythonContextManagerTestCase(torch._dynamo.test_case.TestCase): @torch.compile(backend="eager", fullgraph=True) def fn(t): nonlocal frames - y = t.sum() + _y = t.sum() try: with f(): 1 / 0 @@ -2745,7 +2745,7 @@ class CPythonContextManagerTestCase(torch._dynamo.test_case.TestCase): @torch.compile(backend="eager", fullgraph=True) def fn(t): nonlocal frames - y = t.sum() + _y = t.sum() try: with f(): raise RuntimeErrorSubclass(42) @@ -2777,7 +2777,7 @@ class CPythonContextManagerTestCase(torch._dynamo.test_case.TestCase): @torch.compile(backend="eager", fullgraph=True) def fn(t): nonlocal frames - y = t.sum() + _y = t.sum() try: with f(): raise stop_exc diff --git a/test/higher_order_ops/test_invoke_subgraph.py b/test/higher_order_ops/test_invoke_subgraph.py index 69ccce21602..cf6de8200e3 100644 --- a/test/higher_order_ops/test_invoke_subgraph.py +++ b/test/higher_order_ops/test_invoke_subgraph.py @@ -612,7 +612,7 @@ class GraphModule(torch.nn.Module): r1 = run(ones, train=False) r1.sum().backward() - g1 = weight.grad.clone() + weight.grad.clone() def test_dynamic(self): @mark_compile_region diff --git a/test/inductor/test_unbacked_symints.py b/test/inductor/test_unbacked_symints.py index 609efe71c57..3de13a6703b 100644 --- a/test/inductor/test_unbacked_symints.py +++ b/test/inductor/test_unbacked_symints.py @@ -376,7 +376,6 @@ class TestUnbackedSymints(InductorTestCase): sub = CustomSliceSubclass(t, slice_bounds=torch.tensor([2, 5], device=t.device)) start = 2 length = 3 - ragged_idx = 1 example_inputs = (sub, start, length) actual = torch.compile(fn, dynamic=dynamic, fullgraph=True)(*example_inputs) diff --git a/test/test_torch.py b/test/test_torch.py index 5630fa4acf1..a3cc9555fdf 100644 --- a/test/test_torch.py +++ b/test/test_torch.py @@ -952,7 +952,7 @@ class TestTorchDeviceType(TestCase): def test_dtypetensor_warnings(self, device): msg = 'The torch.cuda.*DtypeTensor constructors are no longer recommended' with self.assertWarnsOnceRegex(UserWarning, msg): - t = torch.cuda.FloatTensor([0]) + torch.cuda.FloatTensor([0]) with self.assertWarnsOnceRegex(UserWarning, msg): torch.cuda.DoubleTensor([0]) diff --git a/test/test_transformers.py b/test/test_transformers.py index 7c94db29cbd..e291a6c7956 100644 --- a/test/test_transformers.py +++ b/test/test_transformers.py @@ -326,7 +326,7 @@ class TestTransformers(NNTestCase): e = None try: encoder(test, src_key_padding_mask=pad_mask.to(torch.uint8)) - except AssertionError as e: + except AssertionError: continue self.assertFalse(e, "Failed to catch unsupported uint8 type exception") # noqa: F821 diff --git a/tools/linter/adapters/docstring_linter.py b/tools/linter/adapters/docstring_linter.py index 0ca505132f3..97a9517b337 100644 --- a/tools/linter/adapters/docstring_linter.py +++ b/tools/linter/adapters/docstring_linter.py @@ -84,7 +84,7 @@ class DocstringLinter(_linter.FileLinter): def next_token(start: int, token_type: int, error: str) -> int: # type: ignore[return] for i in range(start, len(tokens)): - if (t := tokens[i]).type == token_type: + if tokens[i].type == token_type: return i _linter.ParseError.check(False, tokens[-1], error) @@ -137,12 +137,12 @@ class DocstringLinter(_linter.FileLinter): print() top = sorted(v, reverse=True)[:REPORT_TOP_RESULTS] if len(top) == 1: - s = "s" - t = "" - else: s = "" t = f"{len(top)} " - print(f"Top {t}undocumented {k}s:") + else: + s = "es" if k.endswith("s") else "s" + t = "" + print(f"Top {t}undocumented {k}{s}:") for lines, path, tname in top: print(f" {lines} lines: {path}:{tname}") diff --git a/tools/test/docstring_linter_testdata/python_code.py.txt.lintrunner b/tools/test/docstring_linter_testdata/python_code.py.txt.lintrunner index 73e13eb7c9c..07adffee6d8 100644 --- a/tools/test/docstring_linter_testdata/python_code.py.txt.lintrunner +++ b/tools/test/docstring_linter_testdata/python_code.py.txt.lintrunner @@ -46,11 +46,11 @@ tools/test/docstring_linter_testdata/python_code.py.txt:84: No docstring found f 85 | def short1(self): 86 | pass -Top 3 undocumented classs: +Top undocumented classes: 12 lines: tools/test/docstring_linter_testdata/python_code.py.txt:NotDocstring 6 lines: tools/test/docstring_linter_testdata/python_code.py.txt:LongWithShortDocstring 6 lines: tools/test/docstring_linter_testdata/python_code.py.txt:Long -Top 2 undocumented functions: +Top undocumented functions: 12 lines: tools/test/docstring_linter_testdata/python_code.py.txt:needs_docs 11 lines: tools/test/docstring_linter_testdata/python_code.py.txt:not_short diff --git a/torch/_dynamo/symbolic_convert.py b/torch/_dynamo/symbolic_convert.py index b7faec4793f..7f355bcb036 100644 --- a/torch/_dynamo/symbolic_convert.py +++ b/torch/_dynamo/symbolic_convert.py @@ -3229,7 +3229,6 @@ class InliningInstructionTranslator(InstructionTranslatorBase): def inline_call_(self): parent = self.parent code = self.f_code - func = self.funcvar strict_ctx: Any = contextlib.nullcontext() if parent.strict_checks_fn: diff --git a/torch/_inductor/codegen/cuda/cuda_template.py b/torch/_inductor/codegen/cuda/cuda_template.py index 5022b2d1ff8..1f41e11c3ac 100644 --- a/torch/_inductor/codegen/cuda/cuda_template.py +++ b/torch/_inductor/codegen/cuda/cuda_template.py @@ -90,9 +90,7 @@ class CUDATemplate(KernelTemplate): call_args, expected_args, ) - extra_args = V.graph.sizevars.size_hints( - map(sympy.expand, call_args[len(expected_args) :]) - ) + V.graph.sizevars.size_hints(map(sympy.expand, call_args[len(expected_args) :])) size_args = V.graph.sizevars.size_hints(kernel.get_layout_args()) kernel_hash_name = f"cuda_{self.name}_{next(self.index_counter)}" diff --git a/torch/_inductor/codegen/wrapper.py b/torch/_inductor/codegen/wrapper.py index b40fbb69b9e..4ab06805430 100644 --- a/torch/_inductor/codegen/wrapper.py +++ b/torch/_inductor/codegen/wrapper.py @@ -1270,7 +1270,8 @@ class PythonWrapperCodegen(CodeGen): # conservatively use the sum of all allocated buffer sizes # in potentially nested scopes as the total allocated size - total_allocated_buffer_size = sum( + # FIXME(rec): not used + _total_allocated_buffer_size = sum( s.total_allocated_buffer_size for s in past_planning_states ) diff --git a/torch/_inductor/compile_worker/subproc_pool.py b/torch/_inductor/compile_worker/subproc_pool.py index 3f888e8a85f..68fd9640c68 100644 --- a/torch/_inductor/compile_worker/subproc_pool.py +++ b/torch/_inductor/compile_worker/subproc_pool.py @@ -189,7 +189,7 @@ class SubprocPool: data = b"" try: job_id, data = _recv_msg(self.read_pipe) - except Exception as e: + except Exception: # Something went wrong during the read. There's no way we have a # valid job_id. log.exception("failure in subproc_pool._recv_msg") diff --git a/torch/_inductor/kernel/mm_scaled.py b/torch/_inductor/kernel/mm_scaled.py index 5f774714649..73b9fe9c472 100644 --- a/torch/_inductor/kernel/mm_scaled.py +++ b/torch/_inductor/kernel/mm_scaled.py @@ -438,7 +438,6 @@ def scaled_mm_options_device_tma( # type: ignore[no-untyped-def] "Expect scale_a and scale_b to be either both scalars (including single-element tensors) " f"or 1-dimensional tensors with the same size. Got scale_a: {len(size_a)} and scale_b: {len(size_b)}." ) - NUM_SMS = torch.cuda.get_device_properties("cuda").multi_processor_count return dict( GROUP_M=8, EVEN_K=even_k_symbolic, diff --git a/torch/_inductor/select_algorithm.py b/torch/_inductor/select_algorithm.py index 07bfd3a78dd..971513b1b08 100644 --- a/torch/_inductor/select_algorithm.py +++ b/torch/_inductor/select_algorithm.py @@ -695,8 +695,6 @@ class TritonTemplateKernel(TritonKernel): lengths = [V.graph.sizevars.simplify(s) for s in input_node.get_size()] assert len(indices) == len(lengths) - stride = self.named_input_nodes[input_name].get_stride() - index_symbols = [sympy.Symbol(x, integer=True) for x in indices] assert len(indices) == len(lengths) @@ -722,7 +720,6 @@ class TritonTemplateKernel(TritonKernel): sympy.Integer(1), sympy_product(lengths) ) xindex_range_root.set_name("xindex") - xindex_expr = xindex_range_root.expr # Note - ["None" override_mask] # MM Templates work by taking out of bounds index values and wrapping them around to 0 diff --git a/torch/ao/quantization/fx/convert.py b/torch/ao/quantization/fx/convert.py index 99873cd1539..65616e940ad 100644 --- a/torch/ao/quantization/fx/convert.py +++ b/torch/ao/quantization/fx/convert.py @@ -1123,10 +1123,6 @@ def convert( # for dynamic quant ops or weight only quant ops _run_weight_observers(model, backend_config) - graph_inputs: List[str] = [ - node.name for node in model.graph.nodes if node.op == "placeholder" - ] - # additional state to override inputs to be quantized, if specified # by the user placeholder_node_seen_cnt = 0 diff --git a/torch/distributed/elastic/timer/file_based_local_timer.py b/torch/distributed/elastic/timer/file_based_local_timer.py index 671a412bd9d..e69ae9fe863 100644 --- a/torch/distributed/elastic/timer/file_based_local_timer.py +++ b/torch/distributed/elastic/timer/file_based_local_timer.py @@ -41,7 +41,7 @@ def _retry(max_retries: int, sleep_time: float) -> Callable: for i in range(max_retries): try: return func(*args, **kwargs) - except Exception as e: + except Exception: logger.exception("Error running %s. Retrying...", func.__name__) if i < max_retries - 1: time.sleep(sleep_time) @@ -277,7 +277,7 @@ class FileTimerServer: # thread, which will not block the process to stop. try: fd = open(self._file_path) - except Exception as e: + except Exception: logger.exception("Could not open the FileTimerServer pipe") raise diff --git a/torch/distributed/tensor/experimental/_attention.py b/torch/distributed/tensor/experimental/_attention.py index 67b958b7016..2c4ef12d475 100644 --- a/torch/distributed/tensor/experimental/_attention.py +++ b/torch/distributed/tensor/experimental/_attention.py @@ -319,7 +319,6 @@ class _AllGatherRotater(_RingRotater): ) def next_buffer(self) -> torch.Tensor: - size = dist.get_world_size(self._pg) rank = dist.get_rank(self._pg) idx = rank - self._idx diff --git a/torch/export/_trace.py b/torch/export/_trace.py index ebaba4c14d8..8bd4375d0ca 100644 --- a/torch/export/_trace.py +++ b/torch/export/_trace.py @@ -1548,10 +1548,6 @@ def _export_to_aten_ir_make_fx( strict=True, stack_weights=True, ), _ignore_backend_decomps(), _compiling_state_context(): # type: ignore[attr-defined] - param_len = len(dict(mod.named_parameters(remove_duplicate=False))) - buffer_len = len(dict(mod.named_buffers(remove_duplicate=False))) - params_len = param_len + buffer_len - gm, graph_signature = transform(_make_fx_helper)( mod, fake_args, diff --git a/torch/fx/experimental/symbolic_shapes.py b/torch/fx/experimental/symbolic_shapes.py index 1eadc9a4ffd..7741c28d5eb 100644 --- a/torch/fx/experimental/symbolic_shapes.py +++ b/torch/fx/experimental/symbolic_shapes.py @@ -2900,7 +2900,7 @@ class DimConstraints: assert op == "==", t try: results[left]["eq"] = sympy.sympify(right) - except TypeError as e: # rhs source is not linked to Dim name + except TypeError: # rhs source is not linked to Dim name pass # order forced specializations based on name diff --git a/torch/nested/_internal/ops.py b/torch/nested/_internal/ops.py index 871334b7795..42906124926 100644 --- a/torch/nested/_internal/ops.py +++ b/torch/nested/_internal/ops.py @@ -917,8 +917,6 @@ def chunk_default(func, *args, **kwargs): if operating_on_batch: chunks = new_kwargs["chunks"] - dim0_size = inp._size[0] - chunk_size = math.ceil(dim0_size / chunks) # get _offsets of the chunks lengths = inp._offsets.diff() diff --git a/torch/testing/_internal/common_methods_invocations.py b/torch/testing/_internal/common_methods_invocations.py index 4e13549f67d..4063c2dc1fe 100644 --- a/torch/testing/_internal/common_methods_invocations.py +++ b/torch/testing/_internal/common_methods_invocations.py @@ -8752,7 +8752,6 @@ def sample_inputs_scaled_mm(op_info, device, dtype, requires_grad, **kwargs): def sample_inputs_scaled_dot_product_attention(op_info, device, dtype, requires_grad, **kwargs): make = partial(make_tensor, device=device, dtype=dtype, requires_grad=requires_grad) batch, seq_q, seq_kv, num_heads, head_dim = 4, 3, 6, 4, 8 - num_heads_q_gqa, num_heads_kv_gqa = 32, 8 dim_3_q_shape = (batch, seq_q, head_dim) dim_3_kv_shape = (batch, seq_kv, head_dim) diff --git a/torch/testing/_internal/distributed/rpc/rpc_test.py b/torch/testing/_internal/distributed/rpc/rpc_test.py index a461c3a86bf..6c63ed5e0f5 100644 --- a/torch/testing/_internal/distributed/rpc/rpc_test.py +++ b/torch/testing/_internal/distributed/rpc/rpc_test.py @@ -1452,7 +1452,7 @@ class RpcTest(RpcAgentTestFixture, RpcTestCommon): model = torch.nn.parallel.DistributedDataParallel(model) with self.assertRaisesRegex(RuntimeError, 'Current RPC agent is not set! Did you initialize the RPC framework'): - params = [RRef(param) for param in model.parameters()] + [RRef(param) for param in model.parameters()] def test_world_size_one(self): self._world_size_one( diff --git a/torch/testing/_internal/opinfo/definitions/nested.py b/torch/testing/_internal/opinfo/definitions/nested.py index dd46d754da8..90e016d0e3a 100644 --- a/torch/testing/_internal/opinfo/definitions/nested.py +++ b/torch/testing/_internal/opinfo/definitions/nested.py @@ -447,7 +447,6 @@ def reduction_reference(op, sample): assert op._extra_op_data.dim_args is not None single_dim_argname, dimlist_argname = op._extra_op_data.get_dim_argnames() assert single_dim_argname is not None - supports_dimlist = dimlist_argname is not None dim = sample.kwargs.get( dimlist_argname, sample.kwargs.get(single_dim_argname, None) @@ -814,7 +813,6 @@ def sample_inputs_unary_dimwise( def batchwise_reference_chunk(op, sample): # reference for chunk() over dim=0 - kwargs = sample.kwargs B = sample.input.size(0) num_chunks = sample.kwargs["chunks"] chunk_size = math.ceil(B / num_chunks)