Skip to content

Commit

Permalink
move test_custom_op to TestUtilScript
Browse files Browse the repository at this point in the history
  • Loading branch information
shewu-quic committed Feb 26, 2025
1 parent 846f3ab commit 064d12f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 72 deletions.
106 changes: 34 additions & 72 deletions backends/qualcomm/tests/test_qnn_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3107,16 +3107,6 @@ def test_qnn_backend_draw_graph(self):


class TestExampleLLMScript(TestQNN):
def required_envs(self, conditions=None) -> bool:
conditions = [] if conditions is None else conditions
return all(
[
self.executorch_root,
self.artifact_dir,
*conditions,
]
)

def test_llama3_2_1b(self):
if not self.required_envs():
self.skipTest("missing required envs")
Expand Down Expand Up @@ -3274,16 +3264,6 @@ def test_llama_stories_110m(self):


class TestExampleOssScript(TestQNN):
def required_envs(self, conditions=None) -> bool:
conditions = [] if conditions is None else conditions
return all(
[
self.executorch_root,
self.artifact_dir,
*conditions,
]
)

def test_conv_former(self):
if not self.required_envs([self.image_dataset]):
self.skipTest("missing required envs")
Expand Down Expand Up @@ -3655,16 +3635,6 @@ def test_ssd300_vgg16(self):


class TestExampleQaihubScript(TestQNN):
def required_envs(self, conditions=None) -> bool:
conditions = [] if conditions is None else conditions
return all(
[
self.executorch_root,
self.artifact_dir,
*conditions,
]
)

def test_utils_export(self):
with tempfile.TemporaryDirectory() as tmp_dir:
module = ContextBinaryExample() # noqa: F405
Expand Down Expand Up @@ -3893,16 +3863,6 @@ def test_stable_diffusion(self):


class TestExampleScript(TestQNN):
def required_envs(self, conditions=None) -> bool:
conditions = [] if conditions is None else conditions
return all(
[
self.executorch_root,
self.artifact_dir,
*conditions,
]
)

def test_mobilenet_v2(self):
if not self.required_envs([self.image_dataset]):
self.skipTest("missing required envs")
Expand Down Expand Up @@ -4168,38 +4128,6 @@ def test_deeplab_v3(self):
self.assertGreaterEqual(msg["MPA"], 0.70)
self.assertGreaterEqual(msg["MIoU"], 0.55)

def test_custom_op(self):
if not self.required_envs([self.op_package_dir]):
self.skipTest("missing required envs")
cmds = [
"python",
f"{self.executorch_root}/examples/qualcomm/custom_op/custom_ops_1.py",
"--artifact",
self.artifact_dir,
"--build_folder",
self.build_folder,
"--device",
self.device,
"--model",
self.model,
"--ip",
self.ip,
"--port",
str(self.port),
"--op_package_dir",
self.op_package_dir,
"--build_op_package",
]
if self.host:
cmds.extend(["--host", self.host])

p = subprocess.Popen(cmds, stdout=subprocess.DEVNULL)
with Listener((self.ip, self.port)) as listener:
conn = listener.accept()
p.communicate()
msg = json.loads(conn.recv())
self.assertTrue(msg["is_close"])

@unittest.skip("dynamic shape inputs appear in recent torch.export.export")
def test_mobilebert(self):
if not self.required_envs([self.pretrained_weight]):
Expand Down Expand Up @@ -4346,6 +4274,40 @@ def test_export_example(self):
)


class TestUtilScript(TestQNN):
def test_custom_op(self):
if not self.required_envs([self.op_package_dir]):
self.skipTest("missing required envs")
cmds = [
"python",
f"{self.executorch_root}/examples/qualcomm/custom_op/custom_ops_1.py",
"--artifact",
self.artifact_dir,
"--build_folder",
self.build_folder,
"--device",
self.device,
"--model",
self.model,
"--ip",
self.ip,
"--port",
str(self.port),
"--op_package_dir",
self.op_package_dir,
"--build_op_package",
]
if self.host:
cmds.extend(["--host", self.host])

p = subprocess.Popen(cmds, stdout=subprocess.DEVNULL)
with Listener((self.ip, self.port)) as listener:
conn = listener.accept()
p.communicate()
msg = json.loads(conn.recv())
self.assertTrue(msg["is_close"])


def setup_environment():
parser = setup_common_args_and_variables()

Expand Down
10 changes: 10 additions & 0 deletions backends/qualcomm/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ def _save_model_and_expected_output(

return input_list, ref_outputs, pte_fname

def required_envs(self, conditions=None) -> bool:
conditions = [] if conditions is None else conditions
return all(
[
self.executorch_root,
self.artifact_dir,
*conditions,
]
)

def verify_output( # noqa: C901
self,
module: torch.nn.Module,
Expand Down

0 comments on commit 064d12f

Please sign in to comment.