Skip to content

Commit 34ef81c

Browse files
Olivia-liufacebook-github-bot
authored andcommitted
Wrap server generated yaml files inside et_operator_library (#5777)
Summary: Pull Request resolved: #5777 ## This diff This diff is to make the model config codegen flow work on Edge MLHub by enabling the `et_operator_library` API to take a .yaml file. - The code changes in `fbcode/executorch/codegen/codegen.bzl` was copied from a stale diff D61824614 made by Mengwei. That one didn't landed because the owner of SceneX/v5002 model didn't have time to test it. ## Context By design, this is the codegen flow: 1. Use click the "Generate ET model config" button on Edge ML Hub; 2. Two files will be generated, one is a .yaml with a list of kernels, the other is a BUCK file under path `xplat/executorch_model/build/...` that calls `et_operator_library` and pass in the .yaml as a parameter. See D63667456 for an example; 3. A bot would accept and land the diff if CI passes; 4. User can run inference. Differential Revision: D63305843
1 parent b60fa71 commit 34ef81c

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

shim/xplat/executorch/codegen/codegen.bzl

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,43 @@ def et_operator_library(
4949
model = None,
5050
include_all_operators = False,
5151
ops_schema_yaml_target = None,
52+
server_generated_yaml_target = None,
5253
**kwargs):
53-
genrule_cmd = [
54-
"$(exe //executorch/codegen/tools:gen_oplist)",
55-
"--output_path=${OUT}",
56-
]
57-
if ops_schema_yaml_target:
58-
genrule_cmd.append(
59-
"--ops_schema_yaml_path=$(location {})".format(ops_schema_yaml_target),
60-
)
61-
if ops:
62-
genrule_cmd.append(
63-
"--root_ops=" + ",".join(ops),
64-
)
65-
if ops_dict:
66-
ops_dict_json = struct_to_json(ops_dict)
67-
genrule_cmd.append(
68-
"--ops_dict='{}'".format(ops_dict_json),
69-
)
70-
if model:
71-
genrule_cmd.append(
72-
"--model_file_path=$(location {})".format(model),
73-
)
74-
if include_all_operators:
75-
genrule_cmd.append(
76-
"--include_all_operators",
77-
)
54+
# do a dummy copy if server_generated_yaml_target is set
55+
if server_generated_yaml_target:
56+
if include_all_operators or ops_schema_yaml_target or model or ops or ops_dict:
57+
fail("Since server_generated_yaml_target is set, ops, ops_dict, include_all_operators and ops_schema_yaml_target shouldn't be set.")
58+
genrule_cmd = [
59+
"cp",
60+
"$(location {})".format(server_generated_yaml_target),
61+
"$OUT",
62+
]
63+
else:
64+
genrule_cmd = [
65+
"$(exe //executorch/codegen/tools:gen_oplist)",
66+
"--output_path=${OUT}",
67+
]
68+
if ops_schema_yaml_target:
69+
genrule_cmd.append(
70+
"--ops_schema_yaml_path=$(location {})".format(ops_schema_yaml_target),
71+
)
72+
if ops:
73+
genrule_cmd.append(
74+
"--root_ops=" + ",".join(ops),
75+
)
76+
if ops_dict:
77+
ops_dict_json = struct_to_json(ops_dict)
78+
genrule_cmd.append(
79+
"--ops_dict='{}'".format(ops_dict_json),
80+
)
81+
if model:
82+
genrule_cmd.append(
83+
"--model_file_path=$(location {})".format(model),
84+
)
85+
if include_all_operators:
86+
genrule_cmd.append(
87+
"--include_all_operators",
88+
)
7889

7990
# TODO(larryliu0820): Remove usages of this flag.
8091
if "define_static_targets" in kwargs:

0 commit comments

Comments
 (0)