mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Summary:
As this diff shows, currently there are a couple hundred instances of raw `noqa` in the codebase, which just ignore all errors on a given line. That isn't great, so this PR changes all existing instances of that antipattern to qualify the `noqa` with respect to a specific error code, and adds a lint to prevent more of this from happening in the future.
Interestingly, some of the examples the `noqa` lint catches are genuine attempts to qualify the `noqa` with a specific error code, such as these two:
```
test/jit/test_misc.py:27: print(f"{hello + ' ' + test}, I'm a {test}") # noqa E999
test/jit/test_misc.py:28: print(f"format blank") # noqa F541
```
However, those are still wrong because they are [missing a colon](https://flake8.pycqa.org/en/3.9.1/user/violations.html#in-line-ignoring-errors), which actually causes the error code to be completely ignored:
- If you change them to anything else, the warnings will still be suppressed.
- If you add the necessary colons then it is revealed that `E261` was also being suppressed, unintentionally:
```
test/jit/test_misc.py:27:57: E261 at least two spaces before inline comment
test/jit/test_misc.py:28:35: E261 at least two spaces before inline comment
```
I did try using [flake8-noqa](https://pypi.org/project/flake8-noqa/) instead of a custom `git grep` lint, but it didn't seem to work. This PR is definitely missing some of the functionality that flake8-noqa is supposed to provide, though, so if someone can figure out how to use it, we should do that instead.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56272
Test Plan:
CI should pass on the tip of this PR, and we know that the lint works because the following CI run (before this PR was finished) failed:
- https://github.com/pytorch/pytorch/runs/2365189927
Reviewed By: janeyx99
Differential Revision: D27830127
Pulled By: samestep
fbshipit-source-id: d6dcf4f945ebd18cd76c46a07f3b408296864fcb
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import benchmark_caffe2 as op_bench_c2
|
|
import operator_benchmark as op_bench
|
|
from benchmark_caffe2 import Caffe2BenchmarkBase # noqa: F401
|
|
from caffe2.python import core
|
|
|
|
|
|
"""Microbenchmarks for element-wise ReplaceNaN operator."""
|
|
|
|
# Configs for C2 ReplaceNaN operator
|
|
replace_nan_long_configs = op_bench.cross_product_configs(
|
|
M=[32, 64, 128], N=range(32, 128, 32), dtype=["float", "double"], tags=["long"]
|
|
)
|
|
|
|
|
|
replace_nan_short_configs = op_bench.config_list(
|
|
attrs=[
|
|
[16, 16, "float"],
|
|
[16, 16, "double"],
|
|
[64, 64, "float"],
|
|
[64, 64, "double"],
|
|
],
|
|
attr_names=["M", "N", "dtype"],
|
|
tags=["short"],
|
|
)
|
|
|
|
|
|
class ReplaceNaNBenchmark(op_bench_c2.Caffe2BenchmarkBase):
|
|
def init(self, M, N, dtype):
|
|
self.input = self.tensor([M, N], dtype)
|
|
self.set_module_name("replace_nan")
|
|
|
|
def forward(self):
|
|
op = core.CreateOperator("ReplaceNaN", self.input, self.input, value=1.0)
|
|
return op
|
|
|
|
|
|
op_bench_c2.generate_c2_test(
|
|
replace_nan_long_configs + replace_nan_short_configs, ReplaceNaNBenchmark
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
op_bench.benchmark_runner.main()
|