Skip to content

Commit de74961

Browse files
authored
Remove none_throws usage from bundled_program
Differential Revision: D67123067 Pull Request resolved: #7296
1 parent 957259e commit de74961

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

devtools/bundled_program/core.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import Dict, List, Optional, Sequence, Type, Union
1010

1111
import executorch.devtools.bundled_program.schema as bp_schema
12-
from pyre_extensions import none_throws
1312

1413
import executorch.exir.schema as core_schema
1514

@@ -44,10 +43,12 @@ class BundledProgram:
4443

4544
def __init__(
4645
self,
47-
executorch_program: Optional[Union[
48-
ExecutorchProgram,
49-
ExecutorchProgramManager,
50-
]],
46+
executorch_program: Optional[
47+
Union[
48+
ExecutorchProgram,
49+
ExecutorchProgramManager,
50+
]
51+
],
5152
method_test_suites: Sequence[MethodTestSuite],
5253
pte_file_path: Optional[str] = None,
5354
):
@@ -59,18 +60,24 @@ def __init__(
5960
pte_file_path: The path to pte file to deserialize program if executorch_program is not provided.
6061
"""
6162
if not executorch_program and not pte_file_path:
62-
raise RuntimeError("Either executorch_program or pte_file_path must be provided")
63+
raise RuntimeError(
64+
"Either executorch_program or pte_file_path must be provided"
65+
)
6366

6467
if executorch_program and pte_file_path:
65-
raise RuntimeError("Only one of executorch_program or pte_file_path can be used")
68+
raise RuntimeError(
69+
"Only one of executorch_program or pte_file_path can be used"
70+
)
6671

6772
method_test_suites = sorted(method_test_suites, key=lambda x: x.method_name)
6873
if executorch_program:
6974
self._assert_valid_bundle(executorch_program, method_test_suites)
70-
self.executorch_program: Optional[Union[
71-
ExecutorchProgram,
72-
ExecutorchProgramManager,
73-
]] = executorch_program
75+
self.executorch_program: Optional[
76+
Union[
77+
ExecutorchProgram,
78+
ExecutorchProgramManager,
79+
]
80+
] = executorch_program
7481
self._pte_file_path: Optional[str] = pte_file_path
7582

7683
self.method_test_suites = method_test_suites
@@ -88,7 +95,8 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
8895
if self.executorch_program:
8996
program = self._extract_program(self.executorch_program)
9097
else:
91-
with open(none_throws(self._pte_file_path), "rb") as f:
98+
assert self._pte_file_path is not None
99+
with open(self._pte_file_path, "rb") as f:
92100
p_bytes = f.read()
93101
program = _deserialize_pte_binary(p_bytes)
94102

devtools/bundled_program/test/test_bundle_data.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
# pyre-strict
88

9+
import tempfile
910
import unittest
1011
from typing import List
11-
import tempfile
12+
1213
import executorch.devtools.bundled_program.schema as bp_schema
1314

1415
import torch
@@ -73,7 +74,7 @@ def test_bundled_program(self) -> None:
7374
bundled_program.serialize_to_schema().program,
7475
bytes(_serialize_pte_binary(executorch_program.executorch_program)),
7576
)
76-
77+
7778
def test_bundled_program_from_pte(self) -> None:
7879
executorch_program, method_test_suites = get_common_executorch_program()
7980

@@ -82,11 +83,17 @@ def test_bundled_program_from_pte(self) -> None:
8283
with open(executorch_model_path, "wb") as f:
8384
f.write(executorch_program.buffer)
8485

85-
bundled_program = BundledProgram(executorch_program=None, method_test_suites=method_test_suites, pte_file_path=executorch_model_path)
86+
bundled_program = BundledProgram(
87+
executorch_program=None,
88+
method_test_suites=method_test_suites,
89+
pte_file_path=executorch_model_path,
90+
)
8691

8792
method_test_suites = sorted(method_test_suites, key=lambda t: t.method_name)
8893

89-
for plan_id in range(len(executorch_program.executorch_program.execution_plan)):
94+
for plan_id in range(
95+
len(executorch_program.executorch_program.execution_plan)
96+
):
9097
bundled_plan_test = (
9198
bundled_program.serialize_to_schema().method_test_suites[plan_id]
9299
)

0 commit comments

Comments
 (0)