Skip to content

Commit

Permalink
Wrap server generated yaml files inside et_operator_library (pytorch#…
Browse files Browse the repository at this point in the history
…5778)

Summary:
Pull Request resolved: pytorch#5778

## 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.

Reviewed By: larryliu0820

Differential Revision: D63305843

fbshipit-source-id: 18ceea47b4de81f1a52eb58ce43a4307b5f3cfee
  • Loading branch information
Olivia-liu authored and facebook-github-bot committed Oct 1, 2024
1 parent 6923ae5 commit 8ddb846
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions shim/xplat/executorch/codegen/codegen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,43 @@ def et_operator_library(
model = None,
include_all_operators = False,
ops_schema_yaml_target = None,
server_generated_yaml_target = None,
**kwargs):
genrule_cmd = [
"$(exe //executorch/codegen/tools:gen_oplist)",
"--output_path=${OUT}",
]
if ops_schema_yaml_target:
genrule_cmd.append(
"--ops_schema_yaml_path=$(location {})".format(ops_schema_yaml_target),
)
if ops:
genrule_cmd.append(
"--root_ops=" + ",".join(ops),
)
if ops_dict:
ops_dict_json = struct_to_json(ops_dict)
genrule_cmd.append(
"--ops_dict='{}'".format(ops_dict_json),
)
if model:
genrule_cmd.append(
"--model_file_path=$(location {})".format(model),
)
if include_all_operators:
genrule_cmd.append(
"--include_all_operators",
)
# do a dummy copy if server_generated_yaml_target is set
if server_generated_yaml_target:
if include_all_operators or ops_schema_yaml_target or model or ops or ops_dict:
fail("Since server_generated_yaml_target is set, ops, ops_dict, include_all_operators and ops_schema_yaml_target shouldn't be set.")
genrule_cmd = [
"cp",
"$(location {})".format(server_generated_yaml_target),
"$OUT",
]
else:
genrule_cmd = [
"$(exe //executorch/codegen/tools:gen_oplist)",
"--output_path=${OUT}",
]
if ops_schema_yaml_target:
genrule_cmd.append(
"--ops_schema_yaml_path=$(location {})".format(ops_schema_yaml_target),
)
if ops:
genrule_cmd.append(
"--root_ops=" + ",".join(ops),
)
if ops_dict:
ops_dict_json = struct_to_json(ops_dict)
genrule_cmd.append(
"--ops_dict='{}'".format(ops_dict_json),
)
if model:
genrule_cmd.append(
"--model_file_path=$(location {})".format(model),
)
if include_all_operators:
genrule_cmd.append(
"--include_all_operators",
)

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

0 comments on commit 8ddb846

Please sign in to comment.