From d6b062e8910a735068eff30c89abb83127012920 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Thu, 15 Dec 2022 20:30:20 +0800 Subject: [PATCH] Add validity check for config in yaml (#49049) * add validity check for config in yaml * delete debug log --- .../fluid/operators/generator/parse_utils.py | 40 +++++++++++++++++++ paddle/phi/api/yaml/legacy_ops.yaml | 4 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/generator/parse_utils.py b/paddle/fluid/operators/generator/parse_utils.py index 419f6bc3c9..8e80cdecf3 100644 --- a/paddle/fluid/operators/generator/parse_utils.py +++ b/paddle/fluid/operators/generator/parse_utils.py @@ -276,11 +276,51 @@ def parse_forward(op_name: str, forward_config: str) -> Dict[str, Any]: return forward_cfg +def check_op_config(op_entry, op_name): + base_key_set = ( + 'op', + 'backward_op', + 'forward', + 'args', + 'output', + 'infer_meta', + 'kernel', + 'backward', + 'invoke', + 'inplace', + 'view', + 'optional', + 'intermediate', + 'no_need_buffer', + 'data_transform', + ) + infer_meta_key_set = ('func', 'param') + kernel_key_set = ('func', 'param', 'data_type', 'layout', 'backend') + for key in op_entry.keys(): + assert ( + key in base_key_set + ), f"Op ({op_name}) : invalid key ({key}) in Yaml." + + if 'infer_meta' in op_entry: + for infer_meta_key in op_entry['infer_meta'].keys(): + assert ( + infer_meta_key in infer_meta_key_set + ), f"Op ({op_name}) : invalid key (infer_meta.{infer_meta_key}) in Yaml." + + if 'kernel' in op_entry: + for kernel_key in op_entry['kernel'].keys(): + assert ( + kernel_key in kernel_key_set + ), f"Op ({op_name}) : invalid key (kernel.{kernel_key}) in Yaml." + + def parse_op_entry(op_entry: Dict[str, Any], name_field="op"): op_name = op_entry[name_field] inputs, attrs = parse_input_and_attr(op_name, op_entry["args"]) outputs = parse_outputs(op_name, op_entry["output"]) + check_op_config(op_entry, op_name) + # validate default value of DataType and DataLayout for attr in attrs: if "default_value" in attr: diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index ba446289f7..53e272d1c3 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -17,7 +17,7 @@ func : AccuracyInferMeta kernel : func : accuracy - dtype : x + data_type : x - op : adadelta_ args : (Tensor param, Tensor grad, Tensor avg_squared_grad, Tensor avg_squared_update, float rho, float epsilon) @@ -1132,9 +1132,9 @@ output : Tensor(solution), Tensor(residuals), Tensor(rank), Tensor(singular_values) infer_meta : func : LstsqInferMeta - dtype : x kernel : func : lstsq + data_type : x - op : lu args : (Tensor x, bool pivot) -- GitLab