File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 1212import graph_net
1313import os
1414import ast
15+ import astor
1516import paddle
1617
1718
@@ -29,7 +30,7 @@ def _get_sha_hash(content):
2930 return m .hexdigest ()
3031
3132
32- def _extract_forward_source (model_path ):
33+ def _extract_forward_source (model_path , class_name ):
3334 source = None
3435 with open (f"{ model_path } /model.py" , "r" ) as f :
3536 source = f .read ()
@@ -38,18 +39,18 @@ def _extract_forward_source(model_path):
3839 forward_code = None
3940
4041 for node in tree .body :
41- if isinstance (node , ast .ClassDef ) and node .name == "GraphModule" :
42+ if isinstance (node , ast .ClassDef ) and node .name == class_name :
4243 for fn in node .body :
4344 if isinstance (fn , ast .FunctionDef ) and fn .name == "forward" :
44- return ast . unparse (fn )
45+ return astor . to_source (fn )
4546 return None
4647
4748
4849def check_graph_hash (args ):
4950 model_path = args .model_path
5051 file_path = f"{ model_path } /graph_hash.txt"
5152 if args .dump_graph_hash_key :
52- model_str = _extract_forward_source (model_path )
53+ model_str = _extract_forward_source (model_path , class_name = "GraphModule" )
5354 assert model_str is not None , f"model_str of { args .model_path } is None."
5455 new_hash_text = _get_sha_hash (model_str )
5556
Original file line number Diff line number Diff line change 11pre-commit
2+ astor
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ function prepare_torch_env() {
3737 LOG " [INFO] Update pip ..."
3838 env http_proxy=" " https_proxy=" " pip install -U pip > /dev/null
3939 [ $? -ne 0 ] && LOG " [FATAL] Update pip failed!" && exit -1
40+ pip install astor
4041 # install torch
4142 pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu118 > /dev/null
4243 [ $? -ne 0 ] && LOG " [FATAL] Install torch2.6.0 failed!" && exit -1
@@ -56,7 +57,7 @@ function prepare_paddle_env() {
5657 env http_proxy=" " https_proxy=" " pip install -U pip > /dev/null
5758 [ $? -ne 0 ] && LOG " [FATAL] Update pip failed!" && exit -1
5859 # install paddle
59- pip uninstall torch==2.7.0 --yes
60+ pip install astor
6061 LOG " [INFO] Install paddlepaddle-develop ..."
6162 python -m pip install --pre paddlepaddle-gpu -i https://www.paddlepaddle.org.cn/packages/nightly/cu118/ > /dev/null
6263 [ $? -ne 0 ] && LOG " [FATAL] Install paddlepaddle-develop failed!" && exit -1
You can’t perform that action at this time.
0 commit comments