Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions graph_net/paddle/check_redundant_incrementally.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,62 @@ def is_single_model_dir(model_dir):


def main(args):
assert os.path.isdir(args.model_path)
assert os.path.isdir(args.graph_net_samples_path)
current_model_graph_hash_pathes = set(
graph_hash_path
for model_path in get_recursively_model_pathes(args.model_path)
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
assert os.path.isdir(
args.graph_net_samples_path
), f"args.graph_net_samples_path ({args.graph_net_samples_path}) is not a directory!"
find_redundant = False
graph_hash2graph_net_model_path = {}
for model_path in get_recursively_model_pathes(args.graph_net_samples_path):
graph_hash_path = f"{model_path}/graph_hash.txt"
if os.path.isfile(graph_hash_path):
graph_hash = open(graph_hash_path).read()
if graph_hash not in graph_hash2graph_net_model_path.keys():
graph_hash2graph_net_model_path[graph_hash] = [graph_hash_path]
else:
find_redundant = True
graph_hash2graph_net_model_path[graph_hash].append(graph_hash_path)
print(
f"Totally {len(graph_hash2graph_net_model_path)} unique samples under {args.graph_net_samples_path}."
)
graph_hash2graph_net_model_path = {
graph_hash: graph_hash_path
for model_path in get_recursively_model_pathes(args.graph_net_samples_path)
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
if os.path.isfile(graph_hash_path)
if graph_hash_path not in current_model_graph_hash_pathes
for graph_hash in [open(graph_hash_path).read()]
}
for current_model_graph_hash_path in current_model_graph_hash_pathes:
graph_hash = open(current_model_graph_hash_path).read()
assert (
graph_hash not in graph_hash2graph_net_model_path
), f"Redundant models detected. old-model-path:{current_model_graph_hash_path}, new-model-path:{graph_hash2graph_net_model_path[graph_hash]}."
for graph_hash, graph_paths in graph_hash2graph_net_model_path.items():
if len(graph_paths) > 1:
print(f"Redundant models detected for grap_hash {graph_hash}:")
for model_path in graph_paths:
print(f" {model_path}")
assert (
not find_redundant
), f"Redundant models detected under {args.graph_net_samples_path}."

if args.model_path:
assert os.path.isdir(
args.model_path
), f"args.model_path {args.model_path} is not a directory!"
current_model_graph_hash_pathes = set(
graph_hash_path
for model_path in get_recursively_model_pathes(args.model_path)
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
)
for current_model_graph_hash_path in current_model_graph_hash_pathes:
graph_hash = open(current_model_graph_hash_path).read()
assert (
graph_hash not in graph_hash2graph_net_model_path
), f"Redundant models detected. old-model-path:{current_model_graph_hash_path}, new-model-path:{graph_hash2graph_net_model_path[graph_hash]}."


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Test compiler performance.")
parser.add_argument(
"--model-path",
type=str,
required=True,
required=False,
help="Path to model file(s), each subdirectory containing graph_net.json will be regarded as a model",
)
parser.add_argument(
"--graph-net-samples-path",
type=str,
required=False,
default="default",
required=True,
help="Path to GraphNet samples",
)
args = parser.parse_args()
print(args)
main(args=args)
1 change: 0 additions & 1 deletion paddle_samples/PaddleNLP/bert-base-chinese/graph_hash.txt

This file was deleted.

6 changes: 0 additions & 6 deletions paddle_samples/PaddleNLP/bert-base-chinese/graph_net.json

This file was deleted.

Loading