|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +import unittest |
| 8 | + |
| 9 | +from executorch.devtools.backend_debug import get_delegation_info |
| 10 | +from executorch.examples.models.llama.export_llama_lib import ( |
| 11 | + _export_llama, |
| 12 | + build_args_parser, |
| 13 | +) |
| 14 | + |
| 15 | +UNWANTED_OPS = [ |
| 16 | + "aten_permute_copy_default", |
| 17 | + "aten_transpose_copy_default", |
| 18 | +] |
| 19 | + |
| 20 | + |
| 21 | +class ExportLlamaLibTest(unittest.TestCase): |
| 22 | + def test_has_expected_ops_and_op_counts(self): |
| 23 | + """ |
| 24 | + Checks the presence of unwanted expensive ops. |
| 25 | +
|
| 26 | + Serves as a proxy for a performance regression test, as performance |
| 27 | + is directly tied to which and how many of each ops are in the graph. |
| 28 | +
|
| 29 | + If this test breaks, please ensure that the difference in ops |
| 30 | + is intentional before updating the expected ops. |
| 31 | + """ |
| 32 | + # Since we aren't loading a checkpoint, it doesn't |
| 33 | + # matter what model we specify. Note that |
| 34 | + # we cannot test quantization args in this way |
| 35 | + # since quantization requires promoting meta tensors |
| 36 | + # to device=cpu, which requires real weights. |
| 37 | + parser = build_args_parser() |
| 38 | + args = parser.parse_args([]) |
| 39 | + args.use_sdpa_with_kv_cache = True |
| 40 | + args.use_kv_cache = True |
| 41 | + args.verbose = True |
| 42 | + |
| 43 | + builder = _export_llama(args) |
| 44 | + graph_module = builder.edge_manager.exported_program().graph_module |
| 45 | + delegation_info = get_delegation_info(graph_module) |
| 46 | + |
| 47 | + for op, _op_info in delegation_info.delegation_by_operator.items(): |
| 48 | + self.assertTrue(op not in UNWANTED_OPS) |
0 commit comments