Skip to content

Commit

Permalink
[subgraph_dumper] Fix defines and fails with const range
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Jun 26, 2024
1 parent f320c0b commit 05d7c7d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ list(APPEND LIBRARIES
openvino::core::dev
)

if(ENABLE_OV_IR_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_IR_FRONTEND)
endif()

if(ENABLE_OV_ONNX_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_ONNX_FRONTEND)
endif()

if(ENABLE_OV_PADDLE_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_PADDLE_FRONTEND)
endif()

if(ENABLE_OV_TF_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_TF_FRONTEND)
endif()

if(ENABLE_OV_TF_LITE_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_TF_LITE_FRONTEND)
endif()

if(ENABLE_OV_PYTORCH_FRONTEND)
list(APPEND COMPILE_DEFINITIONS ENABLE_OV_PYTORCH_FRONTEND)
endif()

# add subgraphs_dumpers tool
ov_add_test_target(
NAME ${TARGET_NAME}
Expand All @@ -24,6 +48,8 @@ ov_add_test_target(
DEPENDENCIES
ov_frontends
${LIBRARIES}
DEFINES
${COMPILE_DEFINITIONS}
ADD_CPPLINT
)

Expand All @@ -44,6 +70,8 @@ ov_add_target(
DEPENDENCIES
ov_frontends
${LIBRARIES}
DEFINES
${COMPILE_DEFINITIONS}
ADD_CPPLINT
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ get_input_info_by_model(const std::shared_ptr<ov::Model>& model) {
for (const auto& node : model->get_ordered_ops()) {
ov::conformance::InputInfo::Range ranges(ov::conformance::DEFAULT_MIN_VALUE, ov::conformance::DEFAULT_MAX_VALUE);
bool is_const = false;
if (ov::op::util::is_constant(node)) {
if (ov::op::util::is_constant(node) && ov::shape_size(node->get_output_shape(0)) != 0) {
std::shared_ptr<ov::op::v0::Constant> constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(node);
auto const_ranges = get_const_ranges(constant,
constant->get_default_output().get_element_type());
constant->get_default_output().get_element_type());
ranges = const_ranges;
} else if (!ov::op::util::is_parameter(node)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ get_input_info_by_node(const std::shared_ptr<ov::Node>& node) {
ov::conformance::InputInfo in_info(node->get_input_partial_shape(port_id));
std::string input_name = input_node->get_friendly_name();
if (std::dynamic_pointer_cast<ov::op::v0::Constant>(input_node)) {
if (ov::shape_size(input_node->get_output_shape(0)) == 0)
continue;
auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(input_node);
in_info.is_const = true;
in_info.ranges = get_const_ranges(const_node,
const_node->get_default_output().get_element_type());
if (ov::shape_size(input_node->get_output_shape(0)) == 0) {
auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(input_node);
in_info.is_const = true;
in_info.ranges = ov::conformance::InputInfo::Range(ov::conformance::DEFAULT_MIN_VALUE, ov::conformance::DEFAULT_MAX_VALUE);
} else {
auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(input_node);
in_info.is_const = true;
in_info.ranges = get_const_ranges(const_node,
const_node->get_default_output().get_element_type());
}
}
input_info.insert({input_name, in_info});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ def get_default_re_path(is_take_all_models = False):
SCRIPT_DIR_PATH, _ = os.path.split(os.path.abspath(__file__))
return os.path.join(SCRIPT_DIR_PATH, "..", "data", "custom_re_to_find_models.lst") if is_take_all_models else os.path.join(SCRIPT_DIR_PATH, "..", "data", "default_re_to_find_models.lst")

def get_default_re_exclude_model_path(is_take_all_models = False):
SCRIPT_DIR_PATH, _ = os.path.split(os.path.abspath(__file__))
return '' if is_take_all_models else os.path.join(SCRIPT_DIR_PATH, "..", "data", "default_re_to_exclude_modes.lst")

def parse_arguments():
parser = ArgumentParser()

model_help = "Path to model directories path file to prepare filelist. Separator is `,`"
output_help = "Path to output dir to save model list file"
filename_help = "Output filename to save model list file"
latest_only_help = "Use only latest directory matched reg exp. In other case all directories will be taken from the dir"
exclude_model_list = ""

parser.add_argument("-m", "--model_dirs", type=str, help=model_help, required=True)
parser.add_argument("-o", "--output_dir", type=str, help=output_help, required=False, default=".")
Expand Down Expand Up @@ -54,7 +59,7 @@ def str_to_dir_list(input_str: str):
return dir_path_list


def read_dir_re_exp(re_exp_file_path: str):
def read_re_exp(re_exp_file_path: str):
dir_re_exps = []
if os.path.isfile(re_exp_file_path):
with open(re_exp_file_path, "r") as re_exp_file:
Expand All @@ -64,14 +69,15 @@ def read_dir_re_exp(re_exp_file_path: str):
dir_re_exps.append(line.replace('\n', ''))
if len(dir_re_exps) == 0:
dir_re_exps.append('*')
logger.info(f"Model dir re exp list: {dir_re_exps}")
return dir_re_exps

import re

def generate_model_list_file(input_str: str, re_exp_file_path: str, output_file_path: os.path, is_latest_only: bool):
def generate_model_list_file(input_str: str, re_exp_file_path: str, output_file_path: os.path, is_latest_only: bool, re_exclude_model_file: str):
with open(output_file_path, 'w', newline='\n') as output_file:
model_dir_paths = str_to_dir_list(input_str)
dir_re_exps = read_dir_re_exp(re_exp_file_path)
dir_re_exps = read_re_exp(re_exp_file_path)
logger.info(f"Model dir re exp list: {dir_re_exps}")
model_list = list()
for model_dir_path in model_dir_paths:
for dir_re_exp in dir_re_exps:
Expand All @@ -92,9 +98,16 @@ def generate_model_list_file(input_str: str, re_exp_file_path: str, output_file_
break
except:
pass
exclude_re_exps = read_re_exp(re_exclude_model_file) if re_exclude_model_file else []
logger.info(f"Model exclude re exp list: {dir_re_exps}")
for line in model_list:
str_line = str(line)
if "tfhub_module.pb" in str_line or "_metadata.pb" in str_line:
exclude = False
for r in exclude_re_exps:
print('aa', r)
if re.match(r, str_line):
exclude = True
if "tfhub_module.pb" in str_line or "_metadata.pb" in str_line or exclude:
continue
output_file.write(f"{line}\n")
output_file.close()
Expand All @@ -107,8 +120,9 @@ def generate_model_list_file(input_str: str, re_exp_file_path: str, output_file_
logger.info(f"[ ARGUMENTS ] --filename={args.filename}")
logger.info(f"[ ARGUMENTS ] --latest_only={args.latest_only}")
re_file = get_default_re_path(not args.latest_only)
re_exclude_model_file = get_default_re_exclude_model_path(not args.latest_only)
if not args.latest_only:
logger.warning(f"{re_file} will be taken to get all models from the dirs")
output_model_list_file = os.path.join(args.output_dir, f"{args.filename}.lst")
generate_model_list_file(args.model_dirs, re_file, output_model_list_file, args.latest_only)
generate_model_list_file(args.model_dirs, re_file, output_model_list_file, args.latest_only, re_exclude_model_file)
logger.info(f"Model file list is saved to {output_model_list_file}")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*onnx.*torchvision_swin3d_b.*

0 comments on commit 05d7c7d

Please sign in to comment.