@@ -5,55 +5,140 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
55
66FLUIDDOCDIR=${FLUIDDOCDIR:=/ FluidDoc}
77DOCROOT=${FLUIDDOCDIR} /docs
8-
9-
10- # # 1. 获取API映射文件
118APIMAPPING_ROOT=${DOCROOT} /guides/model_convert/convert_from_pytorch
129TOOLS_DIR=${APIMAPPING_ROOT} /tools
1310
14- # 确保tools目录存在
15- mkdir -p ${TOOLS_DIR}
11+ # Create tools directory if not exists
12+ if [ ! -d " ${TOOLS_DIR} " ]; then
13+ echo " INFO: Creating tools directory at ${TOOLS_DIR} "
14+ mkdir -p " ${TOOLS_DIR} "
15+ if [ $? -ne 0 ]; then
16+ echo " ERROR: Failed to create directory ${TOOLS_DIR} "
17+ exit 1
18+ fi
19+ else
20+ echo " INFO: Tools directory ${TOOLS_DIR} already exists"
21+ fi
1622
17- # 下载的文件URL
23+ # Define API mapping files URLs
1824API_ALIAS_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_alias_mapping.json"
1925API_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_mapping.json"
2026GLOBAL_VAR_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/global_var.py"
2127ATTRIBUTE_MAPPING_URL=" https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/attribute_mapping.json"
2228
23- # 下载文件
29+ # Define backup URLs
30+ BACKUP_API_ALIAS_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/api_alias_mapping.json"
31+ BACKUP_API_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/api_mapping.json"
32+ BACKUP_GLOBAL_VAR_URL=" https://paddle-paconvert.bj.bcebos.com/global_var.py"
33+ BACKUP_ATTRIBUTE_MAPPING_URL=" https://paddle-paconvert.bj.bcebos.com/attribute_mapping.json"
34+
35+ # Check for proxy settings
2436PROXY=" "
2537if [ -n " $https_proxy " ]; then
2638 PROXY=" $https_proxy "
39+ echo " INFO: find proxy"
2740elif [ -n " $http_proxy " ]; then
2841 PROXY=" $http_proxy "
42+ echo " INFO: find proxy"
43+ else
44+ echo " INFO: No proxy detected, downloading directly."
2945fi
3046
31- # 构建 curl 代理参数
32- CURL_PROXY_ARGS=" "
47+ # Build curl proxy arguments
3348if [ -n " $PROXY " ]; then
34- CURL_PROXY_ARGS=" --proxy $PROXY "
49+ CURL_PROXY_ARGS=" --proxy ${ PROXY} "
3550else
36- echo " No proxy detected, downloading directly."
51+ CURL_PROXY_ARGS=" "
52+ fi
53+
54+ # Download API mapping files with retry
55+ download_file () {
56+ local url=$1
57+ local dest=$2
58+ local filename=$( basename " $dest " )
59+ local max_retries=5
60+ local retry_count=0
61+
62+ echo " INFO: Starting download of ${filename} from ${url} "
63+
64+ while [ $retry_count -lt $max_retries ]; do
65+ retry_count=$(( retry_count + 1 ))
66+ echo " INFO: Attempt $retry_count of $max_retries to download ${filename} "
67+
68+ if curl $CURL_PROXY_ARGS -o " ${dest} " -s " ${url} " > /dev/null 2>&1 ; then
69+ echo " SUCCESS: Successfully downloaded ${filename} to ${dest} "
70+ return 0
71+ else
72+ echo " WARNING: Failed to download ${filename} from ${url} (attempt $retry_count )"
73+ sleep 2 # Wait for 2 seconds before next retry
74+ fi
75+ done
76+
77+ echo " ERROR: Failed to download ${filename} after $max_retries attempts"
78+ return 1
79+ }
80+
81+ # Download each file with detailed logging
82+ echo " INFO: Downloading API alias mapping file"
83+ if ! download_file " ${API_ALIAS_MAPPING_URL} " " ${TOOLS_DIR} /api_alias_mapping.json" ; then
84+ echo " INFO: Trying backup URL for API alias mapping file"
85+ if ! download_file " ${BACKUP_API_ALIAS_MAPPING_URL} " " ${TOOLS_DIR} /api_alias_mapping.json" ; then
86+ echo " ERROR: API alias mapping download failed (both main and backup URLs). Exiting."
87+ exit 1
88+ fi
89+ fi
90+
91+ echo " INFO: Downloading API mapping file"
92+ if ! download_file " ${API_MAPPING_URL} " " ${TOOLS_DIR} /api_mapping.json" ; then
93+ echo " INFO: Trying backup URL for API mapping file"
94+ if ! download_file " ${BACKUP_API_MAPPING_URL} " " ${TOOLS_DIR} /api_mapping.json" ; then
95+ echo " ERROR: API mapping download failed (both main and backup URLs). Exiting."
96+ exit 1
97+ fi
3798fi
3899
39- # 执行下载
40- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /api_alias_mapping.json" -s " ${API_ALIAS_MAPPING_URL} "
41- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /api_mapping.json" -s " ${API_MAPPING_URL} "
42- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /global_var.py" -s " ${GLOBAL_VAR_URL} "
43- curl $CURL_PROXY_ARGS -o " ${TOOLS_DIR} /attribute_mapping.json" -s " ${ATTRIBUTE_MAPPING_URL} "
100+ echo " INFO: Downloading global variable file"
101+ if ! download_file " ${GLOBAL_VAR_URL} " " ${TOOLS_DIR} /global_var.py" ; then
102+ echo " INFO: Trying backup URL for global variable file"
103+ if ! download_file " ${BACKUP_GLOBAL_VAR_URL} " " ${TOOLS_DIR} /global_var.py" ; then
104+ echo " ERROR: Global variable download failed (both main and backup URLs). Exiting."
105+ exit 1
106+ fi
107+ fi
108+
109+ echo " INFO: Downloading attribute mapping file"
110+ if ! download_file " ${ATTRIBUTE_MAPPING_URL} " " ${TOOLS_DIR} /attribute_mapping.json" ; then
111+ echo " INFO: Trying backup URL for attribute mapping file"
112+ if ! download_file " ${BACKUP_ATTRIBUTE_MAPPING_URL} " " ${TOOLS_DIR} /attribute_mapping.json" ; then
113+ echo " ERROR: Attribute mapping download failed (both main and backup URLs). Exiting."
114+ exit 1
115+ fi
116+ fi
44117
45- # 检查下载是否成功
46- if [ $? -ne 0 ]; then
47- echo " Error: Failed to download API mapping files"
118+ # Check if all files exist before proceeding
119+ if [ ! -f " ${TOOLS_DIR} /api_alias_mapping.json" ] || \
120+ [ ! -f " ${TOOLS_DIR} /api_mapping.json" ] || \
121+ [ ! -f " ${TOOLS_DIR} /global_var.py" ] || \
122+ [ ! -f " ${TOOLS_DIR} /attribute_mapping.json" ]; then
123+ echo " ERROR: One or more API mapping files are missing after download"
124+ echo " Missing files:"
125+ if [ ! -f " ${TOOLS_DIR} /api_alias_mapping.json" ]; then echo " - api_alias_mapping.json" ; fi
126+ if [ ! -f " ${TOOLS_DIR} /api_mapping.json" ]; then echo " - api_mapping.json" ; fi
127+ if [ ! -f " ${TOOLS_DIR} /global_var.py" ]; then echo " - global_var.py" ; fi
128+ if [ ! -f " ${TOOLS_DIR} /attribute_mapping.json" ]; then echo " - attribute_mapping.json" ; fi
48129 exit 1
49130fi
50131
51- # # 3. Apply PyTorch-PaddlePaddle mapping using the new API mapping files
52- python ${APIMAPPING_ROOT} /tools/get_api_difference_info.py
53- python ${APIMAPPING_ROOT} /tools/generate_pytorch_api_mapping.py
132+ echo " INFO: All API mapping files successfully downloaded"
54133
134+ echo " INFO: Running get_api_difference_info.py"
135+ if ! python " ${APIMAPPING_ROOT} /tools/get_api_difference_info.py" ; then
136+ echo " ERROR: get_api_difference_info.py failed. Please check the script."
137+ exit 1
138+ fi
55139
56- if [ $? -ne 0 ]; then
57- echo " Error: API mapping generate script failed, please check changes in ${APIMAPPING_ROOT} "
140+ echo " INFO: Running generate_pytorch_api_mapping.py"
141+ if ! python " ${APIMAPPING_ROOT} /tools/generate_pytorch_api_mapping.py" ; then
142+ echo " ERROR: generate_pytorch_api_mapping.py failed. Please check the script."
58143 exit 1
59144fi
0 commit comments