Skip to content

Commit fdea2a1

Browse files
Lucaskabelafacebook-github-bot
authored andcommitted
Add typing annotations to guard and source
Summary: X-link: pytorch/executorch#12986 As part of better engineering week, we would like to improve out type support to improve dev experience in dynamo This PR adds strict typing support to a critical set of files for dynamo, `source.py` and the base `_guards.py` Running ``` mypy torch/_dynamo/source.py torch/_guards.py --linecount-report /tmp/coverage_log ``` | -------- | Lines Unannotated | Lines Total | % lines covered | Funcs Unannotated | Funcs Total | % funcs covered | | -------- | ------- | -------- | ------- | ------- | ------- | ------- | | Main | 1227 | 2208 | 55.57% | 207 | 362 | 57.18% | | This PR | 2217 | 2217 | 100.00% | 362 | 362 | 100.00% | | Delta | +990 | +9 | +44.43% | +155 | 0 | +42.82% | cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 jerryzh168 voznesenskym penguinwu EikanWang Guobing-Chen zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben X-link: pytorch/pytorch#158397 Reviewed By: JacobSzwejbka, yangw-dev Differential Revision: D79199389 Pulled By: Lucaskabela fbshipit-source-id: 10b5d9d6ddb4b0797ea795ac8a1f1eaaa512b2ae
1 parent 28b27b9 commit fdea2a1

File tree

1 file changed

+4
-2
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+4
-2
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,9 @@ def set_example_value(node, example_value):
26442644
# this to accurately reflect what the state of the value was at the time
26452645
# the program was traced).
26462646
node.meta["example_value"] = example_value
2647-
shape_env = TracingContext.get().fake_mode.shape_env
2647+
fake_mode = TracingContext.get().fake_mode
2648+
assert fake_mode is not None
2649+
shape_env = fake_mode.shape_env
26482650
if (
26492651
symbol_to_path
26502652
:= torch.fx.experimental.symbolic_shapes.compute_unbacked_bindings(
@@ -4765,7 +4767,7 @@ def record_pregraph_bytecode_exit(cm: AbstractContextManager[None]) -> None:
47654767

47664768
# Returns a set of code objects present traced in the current TracingContext, or None
47674769
# if there is no current TracingContext.
4768-
def get_traced_code() -> list[CodeType]:
4770+
def get_traced_code() -> Optional[list[CodeType]]:
47694771
from torch._guards import TracingContext
47704772

47714773
return TracingContext.get_traced_code()

0 commit comments

Comments
 (0)