Skip to content

Commit 939015a

Browse files
Add unit tests to consolidate selective build APIs (pytorch#23176)
### Summary This PR officially resolves the selective build API consolidation requested in the original issue. The CMake and Python logic (`gen_oplist.py`) already support parsing `--root_ops` and `--model_file_path` simultaneously, naturally merging the resulting operator sets. However, this behavior was previously untested, leaving it vulnerable to regression. This PR adds the missing unit test `test_gen_op_list_with_model_and_root_ops` to officially lock in and prove this behavior. Fixes pytorch#11921 ### Testing Plan Manually verified that the new unit test correctly mocks the operator lists and asserts the merged set without throwing a mutual exclusivity error. ```bash # Activated virtual environment source .venv/bin/activate # Ran the codegen test suite to verify the new test passes pytest codegen/tools/test/test_gen_oplist.py ``` cc @larryliu0820 @GregoryComer @nil-is-all
1 parent fc9a1c6 commit 939015a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎codegen/tools/test/test_gen_oplist.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,42 @@ def test_get_kernel_metadata_from_ops_yaml(self) -> None:
255255
"default",
256256
)
257257

258+
@patch("executorch.codegen.tools.gen_oplist._get_kernel_metadata_for_model")
259+
@patch("executorch.codegen.tools.gen_oplist._get_operators")
260+
@patch("executorch.codegen.tools.gen_oplist._dump_yaml")
261+
def test_gen_op_list_with_model_and_root_ops(
262+
self,
263+
mock_dump_yaml,
264+
mock_get_operators,
265+
mock_get_kernel_metadata_for_model,
266+
) -> None:
267+
mock_get_operators.return_value = ["aten::sub"]
268+
mock_get_kernel_metadata_for_model.return_value = {"aten::sub": ["v1/6;"]}
269+
270+
output_path = os.path.join(self.temp_dir.name, "output.yaml")
271+
temp_file = tempfile.NamedTemporaryFile()
272+
273+
args = [
274+
f"--output_path={output_path}",
275+
"--root_ops=aten::add",
276+
f"--model_file_path={temp_file.name}",
277+
]
278+
279+
gen_oplist.main(args)
280+
281+
# Verify that gen_oplist combined BOTH operators into the final output
282+
mock_dump_yaml.assert_called_once_with(
283+
["aten::add", "aten::sub"],
284+
Path(output_path),
285+
temp_file.name,
286+
{
287+
"aten::add": ["default"],
288+
"aten::sub": ["v1/6;"],
289+
},
290+
False,
291+
)
292+
temp_file.close()
293+
258294
def tearDown(self):
259295
self.temp_dir.cleanup()
260296

0 commit comments

Comments
 (0)