[Edge] Add an option to avoid adding base ops to static op library (#84360)

Summary: We use a static op library in a test for PyTorch C++ usages, but don't want to introduce all base ops. Because the goal is to check if a given model can run on the exact op collection (i.e., fbios ops, fb4a ops), and these base ops are not present in real apps. So add an option to disable this feature.

Test Plan: Build. Expect no change to existing targets.

Differential Revision: D39164021

Pull Request resolved: https://github.com/pytorch/pytorch/pull/84360
Approved by: https://github.com/kit1980
This commit is contained in:
Linbin Yu
2022-09-01 22:32:55 +00:00
committed by PyTorch MergeBot
parent ff56f1c30d
commit a563a4880f

View File

@ -19,6 +19,7 @@ def pt_operator_library(
train = False, train = False,
model = None, model = None,
include_all_operators = False, include_all_operators = False,
include_base_operators = True,
**kwargs): **kwargs):
(model_name, model_versions, model_assets, model_traced_backends) = validate_and_extract_model_information( (model_name, model_versions, model_assets, model_traced_backends) = validate_and_extract_model_information(
name, name,
@ -28,8 +29,9 @@ def pt_operator_library(
ops = [op.strip() for op in ops] ops = [op.strip() for op in ops]
# If ops are specified, then we are in static selective build mode, so we append # If ops are specified, then we are in static selective build mode, so we append
# base ops to this list to avoid additional special case logic in subsequent code. # base ops to this list to avoid additional special case logic in subsequent code,
if len(ops) > 0: # unless include_base_operators is explicitly set to False (the default is True)
if len(ops) > 0 and include_base_operators:
ops.extend(PT_BASE_OPS) ops.extend(PT_BASE_OPS)
labels = kwargs.pop("labels", []) labels = kwargs.pop("labels", [])