Description
🚀 The feature, motivation and pitch
Type annotations make new development and maintenance easier, and sometimes find bugs.
And torch/_inductor
is tricky, and under constant modification by disparate developers.
How?
Adding annotations occasionally finds latent bugs, but the real payoff is in faster and more accurate maintenance and new development that using that annotated code.
If we knew which files, classes and functions were going to be used in future development, we could prioritize annotating those.
What we can measure is what gets imported in existing code.
This little script gives the following sorted counts of imports from _inductor
over all of torch/
:
.pattern_matcher
: 486.utils
: 324.ir
: 137.codegen.common
: 131.virtualized
: 111.codecache
: 59.lowering
: 54.scheduler
: 52- ... a lot more
So there is an import for either torch._inductor.pattern_maker
, or a symbol contained within it, 486 times within torch/
.
Deliverable (per file)
- Removal of
# mypy: allow-untyped-defs
andignore-errors
statements - Evaluate
:# mypy: allow-untyped-decorators
(possibly keep, typing decorators correctly is arduous) - For already-typed files, quickly check typing on the most imported symbols
That script above also drills down into individual symbols, for example:
"torch._inductor.pattern_matcher": {
"CallFunction": 32,
"KeywordArg": 30,
"Arg": 29,
"CallFunctionVarArgs": 27,
"Ignored": 26,
"ListOf": 26,
Tracking
-
utils.py
: [inductor] Add type annotations to _inductor/utils.py #144108 -
pattern_matcher.py
: [inductor] Improve type annotations in _inductor/pattern_matcher.py #146626 -
ir.py
: [inductor] Improve type annotations in _inductor/ir.py #148358 -
ir.py
: [inductor] Add typing to _inductor/ir.py #149958 - More
ir.py
: [inductor] Add more typing to _inductor/ir.py #149959 -
codegen/common.py
: [inductor] Clean typing in codegen/common.py and codecache.py #150767 -
virtualized.py
: (in progress @zeshengzong) -
code_cache.py
: also [inductor] Clean typing in codegen/common.py and codecache.py #150767 -
lowering.py
: the first line disables all type checking: removing that reveals a hefty 395 errors; removingtype: ignores
adds another 25 errors
Alternatives
Fumbling ahead with an ongoing ignorance of type information. 😁
cc @ezyang @malfet @xuzhao9 @gramster @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @amjames @desertfire @chauhang @aakhundov