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
9 changes: 5 additions & 4 deletions graph_net/paddle/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import graph_net
import os
import ast
import astor
import paddle


Expand All @@ -29,7 +30,7 @@ def _get_sha_hash(content):
return m.hexdigest()


def _extract_forward_source(model_path):
def _extract_forward_source(model_path, class_name):
source = None
with open(f"{model_path}/model.py", "r") as f:
source = f.read()
Expand All @@ -38,18 +39,18 @@ def _extract_forward_source(model_path):
forward_code = None

for node in tree.body:
if isinstance(node, ast.ClassDef) and node.name == "GraphModule":
if isinstance(node, ast.ClassDef) and node.name == class_name:
for fn in node.body:
if isinstance(fn, ast.FunctionDef) and fn.name == "forward":
return ast.unparse(fn)
return astor.to_source(fn)
return None


def check_graph_hash(args):
model_path = args.model_path
file_path = f"{model_path}/graph_hash.txt"
if args.dump_graph_hash_key:
model_str = _extract_forward_source(model_path)
model_str = _extract_forward_source(model_path, class_name="GraphModule")
assert model_str is not None, f"model_str of {args.model_path} is None."
new_hash_text = _get_sha_hash(model_str)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pre-commit
astor
2 changes: 1 addition & 1 deletion tools/ci/check_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function prepare_paddle_env() {
env http_proxy="" https_proxy="" pip install -U pip > /dev/null
[ $? -ne 0 ] && LOG "[FATAL] Update pip failed!" && exit -1
# install paddle
pip uninstall torch==2.7.0 --yes
pip install astor
LOG "[INFO] Install paddlepaddle-develop ..."
python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu118/ > /dev/null
[ $? -ne 0 ] && LOG "[FATAL] Install paddlepaddle-develop failed!" && exit -1
Expand Down