Skip to content

Commit 00d60e4

Browse files
committed
Enable mypy lintrunner, Part 4 (util/*)
1 parent 4575e1c commit 00d60e4

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

.lintrunner.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ include_patterns = [
303303
'runtime/**/*.py',
304304
'scripts/**/*.py',
305305
# 'test/**/*.py',
306-
# 'util/**/*.py',
306+
'util/**/*.py',
307307
'*.py',
308308
]
309309
exclude_patterns = [

.mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ ignore_missing_imports = True
8080
ignore_missing_imports = True
8181

8282
[mypy-zstd]
83-
ignore_missing_imports = True
83+
ignore_missing_imports = True

util/activation_memory_profiler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import json
1010
import typing
1111
from dataclasses import dataclass, field
12-
from typing import List
12+
from typing import Any, Dict, List, Optional
1313

1414
import executorch.exir.memory as memory
1515
import torch
@@ -52,7 +52,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
5252
allocations at that timestep.
5353
"""
5454
nodes = graph.nodes
55-
memory_timeline = [None] * len(nodes)
55+
memory_timeline: List[Optional[MemoryTimeline]] = [None] * len(nodes)
5656
for _, node in enumerate(nodes):
5757
if node.op == "output":
5858
continue
@@ -73,9 +73,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
7373
fqn = _get_module_hierarchy(node)
7474
for j in range(start, end + 1):
7575
if memory_timeline[j] is None:
76-
# pyre-ignore
7776
memory_timeline[j] = MemoryTimeline()
78-
# pyre-ignore
7977
memory_timeline[j].allocations.append(
8078
Allocation(
8179
node.name,
@@ -87,8 +85,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
8785
stack_trace,
8886
)
8987
)
90-
# pyre-ignore
91-
return memory_timeline
88+
return memory_timeline # type: ignore[return-value]
9289

9390

9491
def _validate_memory_planning_is_done(exported_program: ExportedProgram):
@@ -129,7 +126,7 @@ def generate_memory_trace(
129126

130127
memory_timeline = create_tensor_allocation_info(exported_program.graph)
131128
root = {}
132-
trace_events = []
129+
trace_events: List[Dict[str, Any]] = []
133130
root["traceEvents"] = trace_events
134131

135132
tid = 0
@@ -138,7 +135,7 @@ def generate_memory_trace(
138135
if memory_timeline_event is None:
139136
continue
140137
for allocation in memory_timeline_event.allocations:
141-
e = {}
138+
e: Dict[str, Any] = {}
142139
e["name"] = allocation.name
143140
e["cat"] = "memory_allocation"
144141
e["ph"] = "X"

util/python_profiler.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
import re
1313
from pstats import Stats
1414

15-
from snakeviz.stats import json_stats, table_rows
16-
from tornado import template
15+
from snakeviz.stats import json_stats, table_rows # type: ignore[import-not-found]
16+
from tornado import template # type: ignore[import-not-found]
1717

1818
module_found = True
19+
snakeviz_templates_dir: str = ""
20+
1921
try:
20-
import snakeviz
22+
import snakeviz # type: ignore[import-not-found]
23+
24+
snakeviz_dir = os.path.dirname(os.path.abspath(snakeviz.__file__))
25+
snakeviz_templates_dir = os.path.join(snakeviz_dir, "templates")
2126
except ImportError:
2227
module_found = False
2328

24-
snakeviz_dir = os.path.dirname(os.path.abspath(snakeviz.__file__))
25-
snakeviz_templates_dir = os.path.join(snakeviz_dir, "templates")
26-
2729

2830
def _from_pstat_to_static_html(stats: Stats, html_filename: str):
2931
"""

0 commit comments

Comments
 (0)