(self, mlmodel_as_input)
| 1681 | [True, False], |
| 1682 | ) |
| 1683 | def test_basic(self, mlmodel_as_input): |
| 1684 | def check_spec_version(model_path, expected_spec_version): |
| 1685 | spec = load_spec(model_path) |
| 1686 | assert spec.specificationVersion == expected_spec_version |
| 1687 | |
| 1688 | def check_output_dtype(model_path, expected_output_dtype): |
| 1689 | spec = load_spec(model_path) |
| 1690 | assert_spec_output_type(spec, str_to_proto_feature_type(expected_output_dtype)) |
| 1691 | |
| 1692 | def check_input_dtype(model_path, expected_input_dtype): |
| 1693 | spec = load_spec(model_path) |
| 1694 | assert_spec_input_type(spec, str_to_proto_feature_type(expected_input_dtype)) |
| 1695 | |
| 1696 | |
| 1697 | model = self.get_test_model_path(ct.target.iOS17, return_as_mlmodel=mlmodel_as_input) |
| 1698 | output_dir = str(tempfile.TemporaryDirectory()) |
| 1699 | |
| 1700 | # By bisecting the model into half, there will be two new mlpackages, with suffix `_chunk1.mlpackage` and `_chunk2.mlpackage` |
| 1701 | # in the target `output_dir`. |
| 1702 | bisect_model( |
| 1703 | model, |
| 1704 | output_dir, |
| 1705 | ) |
| 1706 | |
| 1707 | # check the API doesn't delete the original mlpackage |
| 1708 | if not mlmodel_as_input: |
| 1709 | assert os.path.isdir(model) |
| 1710 | |
| 1711 | # check the file names are correct |
| 1712 | if mlmodel_as_input: |
| 1713 | name = "" |
| 1714 | else: |
| 1715 | mlpackage_name = os.path.basename(model) |
| 1716 | name, _ = os.path.splitext(mlpackage_name) |
| 1717 | name += "_" |
| 1718 | |
| 1719 | chunk1_path = os.path.join(output_dir, f"{name}chunk1.mlpackage") |
| 1720 | chunk2_path = os.path.join(output_dir, f"{name}chunk2.mlpackage") |
| 1721 | assert os.path.isdir(chunk1_path) |
| 1722 | assert os.path.isdir(chunk2_path) |
| 1723 | |
| 1724 | # check the model op type |
| 1725 | self.check_spec_op_type( |
| 1726 | chunk1_path, |
| 1727 | [ |
| 1728 | "const", |
| 1729 | "const", |
| 1730 | "linear", |
| 1731 | "const", |
| 1732 | "cast", |
| 1733 | ] |
| 1734 | ) |
| 1735 | self.check_spec_op_type( |
| 1736 | chunk2_path, |
| 1737 | [ |
| 1738 | "const", |
| 1739 | "cast", |
| 1740 | "relu", |
nothing calls this directly
no test coverage detected