forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lintrunner.toml
1688 lines (1644 loc) · 51.6 KB
/
.lintrunner.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[[linter]]
code = 'FLAKE8'
include_patterns = ['**/*.py']
exclude_patterns = [
'.git/**',
'build_test_custom_build/**',
'build/**',
'caffe2/**',
'docs/caffe2/**',
'docs/cpp/src/**',
'docs/src/**',
'fb/**',
'**/fb/**',
'functorch/docs/**',
'functorch/examples/**',
'functorch/notebooks/**',
'torch/_inductor/fx_passes/serialized_patterns/**',
'torch/_inductor/autoheuristic/artifacts/**',
'scripts/**',
'test/generated_type_hints_smoketest.py',
# Tests from the NumPy test suite
'test/torch_np/numpy_test/**/*.py',
'third_party/**',
'torch/include/**',
'torch/lib/**',
'venv/**',
'**/*.pyi',
'tools/test/test_selective_build.py',
]
command = [
'python3',
'tools/linter/adapters/flake8_linter.py',
'--',
'@{{PATHSFILE}}'
]
init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'flake8==6.1.0',
'flake8-bugbear==23.3.23',
'flake8-comprehensions==3.15.0',
'flake8-executable==2.1.3',
'flake8-logging-format==0.9.0',
'flake8-pyi==23.3.1',
'flake8-simplify==0.19.3',
'mccabe==0.7.0',
'pycodestyle==2.11.1',
'pyflakes==3.1.0',
'torchfix==0.4.0 ; python_version >= "3.9" and python_version < "3.13"',
]
[[linter]]
code = 'CLANGFORMAT'
include_patterns = [
'aten/src/ATen/*.h',
'aten/src/ATen/mps/**/*.mm',
'aten/src/ATen/mps/**/*.h',
'aten/src/ATen/xpu/**/*.h',
'aten/src/ATen/xpu/**/*.cpp',
'aten/src/ATen/native/mps/**/*.metal',
'aten/src/ATen/native/mps/**/*.mm',
'aten/src/ATen/native/mps/**/*.h',
'aten/src/ATen/native/vulkan/**/*.h',
'aten/src/ATen/native/vulkan/**/*.cpp',
'aten/src/ATen/native/cuda/MultiTensorApply.cuh',
'aten/src/ATen/native/**/Foreach*.*',
'aten/src/ATen/native/cuda/fused*.*',
'aten/src/ATen/native/cuda/Fused*.cu',
'aten/src/ATen/native/cudnn/*.h',
'aten/src/ATen/native/cudnn/*.cpp',
'aten/src/ATen/native/mkldnn/xpu/**/*.h',
'aten/src/ATen/native/mkldnn/xpu/**/*.cpp',
'c10/**/*.h',
'c10/**/*.cpp',
'torch/csrc/**/*.h',
'torch/csrc/**/*.hpp',
'torch/csrc/**/*.cpp',
'test/cpp/**/*.h',
'test/cpp/**/*.cpp',
]
exclude_patterns = [
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'aten/src/ATen/native/mps/kernels/Quantized.metal',
'c10/util/strong_type.h',
'**/fb/**',
'torch/csrc/inductor/aoti_torch/generated/**',
'torch/csrc/jit/serialization/mobile_bytecode_generated.h',
'torch/csrc/utils/pythoncapi_compat.h',
'aten/src/ATen/dlpack.h',
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=clang-format',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=clang-format',
]
command = [
'python3',
'tools/linter/adapters/clangformat_linter.py',
'--binary=.lintbin/clang-format',
'--',
'@{{PATHSFILE}}'
]
is_formatter = true
[[linter]]
code = 'MYPY'
include_patterns = [
'torch/**/*.py',
'torch/**/*.pyi',
'caffe2/**/*.py',
'caffe2/**/*.pyi',
'test/test_bundled_images.py',
'test/test_bundled_inputs.py',
'test/test_complex.py',
'test/test_datapipe.py',
'test/test_futures.py',
# 'test/test_numpy_interop.py',
'test/test_torch.py',
'test/test_type_hints.py',
'test/test_type_info.py',
'test/test_utils.py',
]
exclude_patterns = [
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/mypy_linter.py',
'--config=mypy.ini',
'--',
'@{{PATHSFILE}}'
]
init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'numpy==1.26.4 ; python_version >= "3.9" and python_version <= "3.11"',
'numpy==2.1.0 ; python_version >= "3.12"',
'expecttest==0.2.1',
'mypy==1.11.2',
'sympy==1.13.0 ; python_version >= "3.9"',
'types-requests==2.27.25',
'types-PyYAML==6.0.7',
'types-tabulate==0.8.8',
'types-protobuf==3.19.18',
'types-pkg-resources==0.1.3',
'types-Jinja2==2.11.9',
'types-colorama==0.4.6',
'filelock==3.13.1',
'junitparser==2.1.1',
'rich==10.9.0',
'pyyaml==6.0.1',
'optree==0.13.0',
]
[[linter]]
code = 'MYPYSTRICT'
include_patterns = [
'.github/**/*.py',
'benchmarks/instruction_counts/**/*.py',
'tools/**/*.py',
'torchgen/**/*.py',
'torch/utils/_pytree.py',
'torch/utils/_cxx_pytree.py',
'torch/utils/benchmark/utils/common.py',
'torch/utils/benchmark/utils/timer.py',
'torch/utils/benchmark/utils/valgrind_wrapper/**/*.py',
]
exclude_patterns = [
# (linbinyu) copied from internal repo
'**/fb/**',
'tools/code_analyzer/gen_operators_yaml.py',
'tools/dynamo/verify_dynamo.py',
'tools/gen_vulkan_spv.py',
'tools/test/gen_operators_yaml_test.py',
'tools/test/gen_oplist_test.py',
'tools/test/test_selective_build.py',
]
command = [
'python3',
'tools/linter/adapters/mypy_linter.py',
'--config=mypy-strict.ini',
'--code=MYPYSTRICT',
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'CLANGTIDY'
include_patterns = [
# Enable coverage of headers in aten/src/ATen
# and excluding most sub-directories for now.
'aten/src/ATen/*.h',
'aten/src/ATen/*.cpp',
'aten/src/ATen/cuda/*.cpp',
'aten/src/ATen/cpu/*.h',
'aten/src/ATen/cpu/*.cpp',
'aten/src/ATen/core/*.h',
'aten/src/ATen/core/*.cpp',
'aten/src/ATen/cudnn/*.h',
'aten/src/ATen/cudnn/*.cpp',
'aten/src/ATen/native/mkldnn/xpu/**/*.h',
'aten/src/ATen/native/mkldnn/xpu/**/*.cpp',
'aten/src/ATen/detail/*',
'aten/src/ATen/functorch/*.h',
'aten/src/ATen/functorch/*.cpp',
'aten/src/ATen/native/nested/cuda/*.cpp',
'aten/src/ATen/native/nested/cuda/*.h',
'aten/src/ATen/native/nested/*.cpp',
'aten/src/ATen/native/nested/*.h',
'c10/**/*.cpp',
'c10/**/*.h',
'torch/*.h',
'torch/csrc/*.h',
'torch/csrc/*.cpp',
'torch/csrc/**/*.h',
'torch/csrc/**/*.cpp',
'torch/csrc/jit/serialization/*.h',
'torch/csrc/jit/serialization/*.cpp',
]
exclude_patterns = [
# The negative filters below are to exclude files that include onnx_pb.h or
# caffe2_pb.h, otherwise we'd have to build protos as part of this CI job.
# CUDA files are also excluded.
'**/fb/**',
'**/generated/**',
'**/*pb.h',
'**/*inl.h',
'aten/src/ATen/cpu/FlushDenormal.cpp',
'aten/src/ATen/cpu/Utils.cpp',
'aten/src/ATen/cpu/vml.h',
'aten/src/ATen/CPUFixedAllocator.h',
'aten/src/ATen/Parallel*.h',
'c10/xpu/**/*.h',
'c10/xpu/**/*.cpp',
'c10/benchmark/intrusive_ptr_benchmark.cpp',
'c10/cuda/CUDAAlgorithm.h',
'c10/util/complex_math.h',
'c10/util/complex_utils.h',
'c10/util/flat_hash_map.h',
'c10/util/logging*.h',
'c10/util/hash.h',
'c10/util/strong_type.h',
'c10/util/SmallVector.h',
'c10/util/win32-headers.h',
'c10/test/**/*.h',
'third_party/**/*',
'torch/csrc/api/include/torch/nn/modules/common.h',
'torch/csrc/api/include/torch/linalg.h',
'torch/csrc/autograd/generated/**',
'torch/csrc/distributed/**/*.cu',
'torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp',
'torch/csrc/distributed/c10d/WinSockUtils.hpp',
'torch/csrc/distributed/c10d/quantization/quantization_gpu.h',
'torch/csrc/dynamo/eval_frame.h',
'torch/csrc/inductor/aoti_torch/c/shim.h',
'torch/csrc/jit/**/*',
'torch/csrc/jit/serialization/mobile_bytecode_generated.h',
'torch/csrc/utils/pythoncapi_compat.h',
'torch/csrc/inductor/aoti_runtime/sycl_runtime_wrappers.h',
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=clang-tidy',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=clang-tidy',
]
command = [
'python3',
'tools/linter/adapters/clangtidy_linter.py',
'--binary=.lintbin/clang-tidy',
'--build_dir=./build',
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'TYPEIGNORE'
include_patterns = ['**/*.py', '**/*.pyi']
exclude_patterns = [
'fb/**',
'**/fb/**',
'test/test_jit.py',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=# type:\s*ignore([^\[]|$)',
'--linter-name=TYPEIGNORE',
'--error-name=unqualified type: ignore',
"""--error-description=\
This line has an unqualified `type: ignore`; \
please convert it to `type: ignore[xxxx]`\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'TYPENOSKIP'
include_patterns = ['mypy.ini']
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=follow_imports\s*=\s*skip',
'--linter-name=TYPENOSKIP',
'--error-name=use of follow_imports = skip',
"""--error-description=\
follow_imports = skip is forbidden from mypy.ini configuration as it \
is extremely easy to accidentally turn off type checking unintentionally. If \
you need to suppress type errors, use a top level # mypy: ignore-errors. \
Do not rely on automatic Any substitution; instead, manually # type: ignore \
at use sites or define a pyi type stub with more relaxed types. \
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'NOQA'
include_patterns = ['**/*.py', '**/*.pyi']
exclude_patterns = [
'caffe2/**',
'fb/**',
'**/fb/**'
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=# noqa([^:]|$)',
'--linter-name=NOQA',
'--error-name=unqualified noqa',
"""--error-description=\
This line has an unqualified `noqa`; \
please convert it to `noqa: XXXX`\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'NATIVEFUNCTIONS'
include_patterns=['aten/src/ATen/native/native_functions.yaml']
command = [
'python3',
'tools/linter/adapters/nativefunctions_linter.py',
'--native-functions-yml=aten/src/ATen/native/native_functions.yaml',
]
init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'ruamel.yaml==0.17.4',
]
is_formatter = true
[[linter]]
code = 'NEWLINE'
include_patterns=['**']
exclude_patterns=[
'**/contrib/**',
'third_party/**',
'**/*.bat',
'**/*.expect',
'**/*.ipynb',
'**/*.ps1',
'**/*.ptl',
'fb/**',
'**/fb/**',
'tools/clang_format_hash/**',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
'**/*.png',
'**/*.gz',
]
command = [
'python3',
'tools/linter/adapters/newlines_linter.py',
'--',
'@{{PATHSFILE}}',
]
is_formatter = true
[[linter]]
code = 'SPACES'
include_patterns = ['**']
exclude_patterns = [
'**/contrib/**',
'**/*.diff',
'**/*.patch',
'third_party/**',
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'fb/**',
'**/fb/**',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=[[:blank:]]$',
'--linter-name=SPACES',
'--error-name=trailing spaces',
'--replace-pattern=s/[[:blank:]]+$//',
"""--error-description=\
This line has trailing spaces; please remove them.\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'TABS'
include_patterns = ['**']
exclude_patterns = [
'**/*.svg',
'**/*Makefile',
'**/contrib/**',
'third_party/**',
'**/.gitattributes',
'**/.gitmodules',
'fb/**',
'**/fb/**',
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'test/cpp/jit/upgrader_models/*.ptl',
'test/cpp/jit/upgrader_models/*.ptl.ff',
'.ci/docker/common/install_rocm_drm.sh',
'.lintrunner.toml',
'.ci/magma/package_files/*.patch',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
# @lint-ignore TXT2
'--pattern= ',
'--linter-name=TABS',
'--error-name=saw some tabs',
'--replace-pattern=s/\t/ /',
"""--error-description=\
This line has tabs; please replace them with spaces.\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'C10_UNUSED'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
'c10/macros/Macros.h',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=C10_UNUSED',
'--linter-name=C10_UNUSED',
'--error-name=deprecated C10_UNUSED macro',
'--replace-pattern=s/C10_UNUSED/[[maybe_unused]]/',
"""--error-description=\
Deprecated macro, use [[maybe_unused]] directly\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'C10_NODISCARD'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
'c10/macros/Macros.h',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=C10_NODISCARD',
'--linter-name=C10_NODISCARD',
'--error-name=deprecated C10_NODISCARD macro',
'--replace-pattern=s/C10_NODISCARD/[[nodiscard]]/',
"""--error-description=\
Deprecated macro, use [[nodiscard]] directly\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'INCLUDE'
include_patterns = [
'c10/**',
'aten/**',
'torch/csrc/**',
]
exclude_patterns = [
'aten/src/ATen/native/quantized/cpu/qnnpack/**',
'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h',
'aten/src/ATen/native/vulkan/glsl/**',
'**/fb/**',
'torch/csrc/jit/serialization/mobile_bytecode_generated.h',
'torch/csrc/utils/pythoncapi_compat.h',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=#include "',
'--linter-name=INCLUDE',
'--error-name=quoted include',
'--replace-pattern=s/#include "(.*)"$/#include <\1>/',
"""--error-description=\
This #include uses quotes; please convert it to #include <xxxx>\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'PYBIND11_INCLUDE'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
'torch/csrc/utils/pybind.h',
'torch/utils/benchmark/utils/valgrind_wrapper/compat_bindings.cpp',
'caffe2/**/*',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=#include <pybind11\/',
'--allowlist-pattern=#include <torch\/csrc\/utils\/pybind.h>',
'--linter-name=PYBIND11_INCLUDE',
'--match-first-only',
'--error-name=direct include of pybind11',
# https://stackoverflow.com/a/33416489/23845
# NB: this won't work if the pybind11 include is on the first line;
# but that's fine because it will just mean the lint will still fail
# after applying the change and you will have to fix it manually
'--replace-pattern=1,/(#include <pybind11\/)/ s/(#include <pybind11\/)/#include <torch\/csrc\/utils\/pybind.h>\n\1/',
"""--error-description=\
This #include directly includes pybind11 without also including \
#include <torch/csrc/utils/pybind.h>; this means some important \
specializations may not be included.\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'ERROR_PRONE_ISINSTANCE'
include_patterns = [
'torch/_refs/**/*.py',
'torch/_prims/**/*.py',
'torch/_prims_common/**/*.py',
'torch/_decomp/**/*.py',
'torch/_meta_registrations.py',
]
exclude_patterns = [
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=isinstance\([^)]+(int|float)\)',
'--linter-name=ERROR_PRONE_ISINSTANCE',
'--error-name=error prone isinstance',
"""--error-description=\
This line has an isinstance call that directly refers to \
int or float. This is error-prone because you may also \
have wanted to allow SymInt or SymFloat in your test. \
To suppress this lint, use an appropriate type alias defined \
in torch._prims_common; use IntLike/FloatLike when you would accept \
both regular and symbolic numbers, Dim for ints representing \
dimensions, or IntWithoutSymInt/FloatWithoutSymFloat if you really \
meant to exclude symbolic numbers.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'PYBIND11_SPECIALIZATION'
include_patterns = [
'**/*.cpp',
'**/*.h',
]
exclude_patterns = [
# The place for all orphan specializations
'torch/csrc/utils/pybind.h',
# These specializations are non-orphan
'torch/csrc/distributed/c10d/init.cpp',
'torch/csrc/jit/python/pybind.h',
'fb/**',
'**/fb/**',
# These are safe to exclude as they do not have Python
'c10/**/*',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=PYBIND11_DECLARE_HOLDER_TYPE',
'--linter-name=PYBIND11_SPECIALIZATION',
'--error-name=pybind11 specialization in non-standard location',
"""--error-description=\
This pybind11 specialization (PYBIND11_DECLARE_HOLDER_TYPE) should \
be placed in torch/csrc/utils/pybind.h so that it is guaranteed to be \
included at any site that may potentially make use of it via py::cast. \
If your specialization is in the same header file as the definition \
of the holder type, you can ignore this lint by adding your header to \
the exclude_patterns for this lint in .lintrunner.toml. For more \
information see https://github.com/pybind/pybind11/issues/4099 \
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'PYPIDEP'
include_patterns = ['.github/**']
exclude_patterns = [
'**/*.rst',
'**/*.py',
'**/*.md',
'**/*.diff',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
"""--pattern=\
(pip|pip3|python -m pip|python3 -m pip|python3 -mpip|python -mpip) \
install ([a-zA-Z0-9][A-Za-z0-9\\._\\-]+)([^/=<>~!]+)[A-Za-z0-9\\._\\-\\*\\+\\!]*$\
""",
'--linter-name=PYPIDEP',
'--error-name=unpinned PyPI install',
"""--error-description=\
This line has unpinned PyPi installs; \
please pin them to a specific version: e.g. 'thepackage==1.2'\
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'EXEC'
include_patterns = ['**']
exclude_patterns = [
'third_party/**',
'torch/bin/**',
'**/*.so',
'**/*.py',
'**/*.sh',
'**/*.bash',
'**/git-pre-commit',
'**/git-clang-format',
'**/gradlew',
'fb/**',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/exec_linter.py',
'--',
'@{{PATHSFILE}}',
]
[[linter]]
code = 'CUBINCLUDE'
include_patterns = ['aten/**']
exclude_patterns = [
'aten/src/ATen/cuda/cub*.cuh',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=#include <cub/',
'--linter-name=CUBINCLUDE',
'--error-name=direct cub include',
"""--error-description=\
This line has a direct cub include; please include \
ATen/cuda/cub.cuh instead and wrap your cub calls in \
at::native namespace if necessary.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'RAWCUDA'
include_patterns = [
'aten/**',
'c10/**',
]
exclude_patterns = [
'aten/src/ATen/test/**',
'c10/cuda/CUDAFunctions.h',
'c10/cuda/CUDACachingAllocator.cpp',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=cudaStreamSynchronize',
'--linter-name=RAWCUDA',
'--error-name=raw CUDA API usage',
"""--error-description=\
This line calls raw CUDA APIs directly; please use at::cuda wrappers instead.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'RAWCUDADEVICE'
include_patterns = [
'aten/**',
'c10/**',
'torch/csrc/**',
]
exclude_patterns = [
'aten/src/ATen/cuda/CUDAContext.cpp',
'aten/src/ATen/cuda/CUDAGeneratorImpl.cpp',
'aten/src/ATen/test/**',
'c10/core/impl/InlineDeviceGuard.h',
'c10/cuda/CUDAFunctions.cpp',
'c10/cuda/CUDAGuard.h',
'c10/cuda/impl/CUDATest.cpp',
'torch/csrc/cuda/nccl.cpp',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=cudaSetDevice(',
'--pattern=cudaGetDevice(',
'--linter-name=RAWCUDADEVICE',
'--error-name=raw CUDA API usage',
"""--error-description=\
This line calls raw CUDA APIs directly; please use c10::cuda wrappers instead.
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'ROOT_LOGGING'
include_patterns = [
'**/*.py',
]
# These are not library code, but scripts in their own right, and so
# therefore are permitted to use logging
exclude_patterns = [
'tools/**',
'test/**',
'benchmarks/**',
'torch/distributed/run.py',
'functorch/benchmarks/**',
# Grandfathered in
'caffe2/**',
'fb/**',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=logging\.(debug|info|warn|warning|error|critical|log|exception)\(',
'--replace-pattern=s/logging\.(debug|info|warn|warning|error|critical|log|exception)\(/log.\1(/',
'--linter-name=ROOT_LOGGING',
'--error-name=use of root logger',
"""--error-description=\
Do not use root logger (logging.info, etc) directly; instead \
define 'log = logging.getLogger(__name__)' and call, e.g., log.info().
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'DEPLOY_DETECTION'
include_patterns = [
'**/*.py',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=sys\.executable == .torch_deploy.',
'--replace-pattern=s/sys\.executable == .torch_deploy./torch._running_with_deploy\(\)/',
'--linter-name=DEPLOY_DETECTION',
'--error-name=properly detect deploy runner',
"""--error-description=\
Do not use sys.executable to detect if running within deploy/multipy, use torch._running_with_deploy().
""",
'--',
'@{{PATHSFILE}}'
]
[[linter]]
code = 'CMAKE'
include_patterns = [
"**/*.cmake",
"**/*.cmake.in",
"**/CMakeLists.txt",
]
exclude_patterns = [
'cmake/Modules/**',
'cmake/Modules_CUDA_fix/**',
'cmake/Caffe2Config.cmake.in',
'aten/src/ATen/ATenConfig.cmake.in',
'cmake/TorchConfig.cmake.in',
'cmake/TorchConfigVersion.cmake.in',
'cmake/cmake_uninstall.cmake.i',
'fb/**',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/cmake_linter.py',
'--config=.cmakelintrc',
'--',
'@{{PATHSFILE}}',
]
init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'cmakelint==1.4.1',
]
[[linter]]
code = 'SHELLCHECK'
include_patterns = [
'.ci/pytorch/**/*.sh'
]
exclude_patterns = [
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/shellcheck_linter.py',
'--',
'@{{PATHSFILE}}',
]
init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'shellcheck-py==0.7.2.1',
]
[[linter]]
code = 'ACTIONLINT'
include_patterns = [
'.github/workflows/*.yml',
'.github/workflows/*.yaml',
# actionlint does not support composite actions yet
# '.github/actions/**/*.yml',
# '.github/actions/**/*.yaml',
]
exclude_patterns = [
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/actionlint_linter.py',
'--binary=.lintbin/actionlint',
'--',
'@{{PATHSFILE}}',
]
init_command = [
'python3',
'tools/linter/adapters/s3_init.py',
'--config-json=tools/linter/adapters/s3_init_config.json',
'--linter=actionlint',
'--dry-run={{DRYRUN}}',
'--output-dir=.lintbin',
'--output-name=actionlint',
]
[[linter]]
code = 'TESTOWNERS'
include_patterns = [
'test/**/test_*.py',
'test/**/*_test.py',
]
exclude_patterns = [
'test/run_test.py',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/testowners_linter.py',
'--',
'@{{PATHSFILE}}',
]
[[linter]]
code = 'TEST_HAS_MAIN'
include_patterns = [
'test/**/test_*.py',
]
exclude_patterns = [
'test/run_test.py',
'**/fb/**',
'test/quantization/**', # should be run through test/test_quantization.py
'test/jit/**', # should be run through test/test_jit.py
'test/ao/sparsity/**', # should be run through test/test_ao_sparsity.py
'test/fx/**', # should be run through test/test_fx.py
'test/bottleneck_test/**', # excluded by test/run_test.py
'test/package/**', # excluded by test/run_test.py
'test/distributed/argparse_util_test.py',
'test/distributed/bin/test_script.py',
'test/distributed/elastic/agent/server/test/local_elastic_agent_test.py',
'test/distributed/elastic/multiprocessing/bin/test_script.py',
'test/distributed/elastic/multiprocessing/bin/zombie_test.py',
'test/distributed/elastic/multiprocessing/errors/api_test.py',
'test/distributed/elastic/multiprocessing/errors/error_handler_test.py',
'test/distributed/elastic/multiprocessing/redirects_test.py',
'test/distributed/elastic/multiprocessing/tail_log_test.py',
'test/distributed/elastic/rendezvous/api_test.py',
'test/distributed/elastic/rendezvous/c10d_rendezvous_backend_test.py',
'test/distributed/elastic/rendezvous/dynamic_rendezvous_test.py',
'test/distributed/elastic/rendezvous/etcd_rendezvous_backend_test.py',
'test/distributed/elastic/rendezvous/etcd_rendezvous_test.py',
'test/distributed/elastic/rendezvous/etcd_server_test.py',
'test/distributed/elastic/rendezvous/rendezvous_backend_test.py',
'test/distributed/elastic/rendezvous/static_rendezvous_test.py',
'test/distributed/elastic/rendezvous/utils_test.py',
'test/distributed/elastic/timer/api_test.py',
'test/distributed/elastic/utils/data/cycling_iterator_test.py',
'test/distributed/launcher/api_test.py',
'test/distributed/launcher/bin/test_script.py',
'test/distributed/launcher/bin/test_script_init_method.py',
'test/distributed/launcher/bin/test_script_is_torchelastic_launched.py',
'test/distributed/launcher/bin/test_script_local_rank.py',
'test/distributed/launcher/launch_test.py',
'test/distributed/launcher/run_test.py',
'test/distributed/optim/test_apply_optimizer_in_backward.py',
'test/distributed/optim/test_named_optimizer.py',
'test/distributed/test_c10d_spawn.py',
'test/distributed/test_collective_utils.py',
'test/distributions/test_distributions.py',
'test/inductor/test_aot_inductor_utils.py',
'test/lazy/test_bindings.py',
'test/lazy/test_extract_compiled_graph.py',
'test/lazy/test_meta_kernel.py',
'test/nn/test_init.py',
'test/onnx/model_defs/op_test.py',
'test/onnx/test_models_quantized_onnxruntime.py',
'test/onnx/test_onnxscript_no_runtime.py',
'test/onnx_caffe2/test_caffe2_common.py',
'test/optim/test_lrscheduler.py',
'test/optim/test_optim.py',
'test/optim/test_swa_utils.py',
'test/run_test.py',
'test/test_bundled_images.py',
'test/test_cuda_expandable_segments.py',
'test/test_hub.py',
]
command = [
'python3',
'tools/linter/adapters/test_has_main_linter.py',
'--',
'@{{PATHSFILE}}',
]
[[linter]]
code = 'CALL_ONCE'
include_patterns = [
'c10/**',
'aten/**',
'torch/csrc/**',
]
exclude_patterns = [
'c10/util/CallOnce.h',
'**/fb/**',
]
command = [
'python3',
'tools/linter/adapters/grep_linter.py',
'--pattern=std::call_once',
'--linter-name=CALL_ONCE',
'--error-name=invalid call_once',
'--replace-pattern=s/std::call_once/c10::call_once/',
"""--error-description=\
Use of std::call_once is forbidden and should be replaced with c10::call_once\