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
79 changes: 43 additions & 36 deletions ci_scripts/hooks/pre-doc-compile.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
#! /bin/bash
set +x

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

FLUIDDOCDIR=${FLUIDDOCDIR:=/FluidDoc}
DOCROOT=${FLUIDDOCDIR}/docs


## 1 merge the pytorch to paddle api map tables
# FILES_ARRAY=("https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/README.md"
# "https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/ops/README.md"
#"https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/nn/README.md"
#"https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/loss/README.md"
#"https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/utils/README.md"
#"https://raw.githubusercontent.com/PaddlePaddle/X2Paddle/develop/docs/pytorch_project_convertor/API_docs/vision/README.md"
#)
#TARGET_FILE=${SCRIPT_DIR}/../../docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md
#TMP_FILE=/tmp/merge_pytorch_to_paddle_maptables.tmp
#
#echo -n > ${TARGET_FILE}
#for f in ${FILES_ARRAY[@]} ; do
# echo -n > ${TMP_FILE}
# echo "downloading ${f} ..."
# if [ "${https_proxy}" != "" ] ; then
# curl -o ${TMP_FILE} -s -x ${https_proxy} ${f}
# else
# curl -o ${TMP_FILE} -s ${f}
# fi
# echo >> ${TMP_FILE}
# cat ${TMP_FILE} >> $TARGET_FILE
#done


## 2 convert all ipynb files to markdown, and delete the ipynb files.
# ../practices/**/*.ipynb
for i in $(find ${SCRIPT_DIR}/../../docs/ -name '*.ipynb' -type f ) ; do
echo "convert $i to markdown and delete ipynb"
jupyter nbconvert --to markdown "$i"
rm "$i"
done


## 3 apply PyTorch-PaddlePaddle mapping
## 1. 获取API映射文件
APIMAPPING_ROOT=${DOCROOT}/guides/model_convert/convert_from_pytorch
TOOLS_DIR=${APIMAPPING_ROOT}/tools

# 确保tools目录存在
mkdir -p ${TOOLS_DIR}

#下载的文件URL
API_ALIAS_MAPPING_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_alias_mapping.json"
API_MAPPING_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/api_mapping.json"
GLOBAL_VAR_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/global_var.py"
ATTRIBUTE_MAPPING_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/attribute_mapping.json"

# 下载文件
PROXY=""
if [ -n "$https_proxy" ]; then
PROXY="$https_proxy"
elif [ -n "$http_proxy" ]; then
PROXY="$http_proxy"
fi

# 构建 curl 代理参数
CURL_PROXY_ARGS=""
if [ -n "$PROXY" ]; then
CURL_PROXY_ARGS="--proxy $PROXY"
else
echo "No proxy detected, downloading directly."
fi

# 执行下载
curl $CURL_PROXY_ARGS -o "${TOOLS_DIR}/api_alias_mapping.json" -s "${API_ALIAS_MAPPING_URL}"
curl $CURL_PROXY_ARGS -o "${TOOLS_DIR}/api_mapping.json" -s "${API_MAPPING_URL}"
curl $CURL_PROXY_ARGS -o "${TOOLS_DIR}/global_var.py" -s "${GLOBAL_VAR_URL}"
curl $CURL_PROXY_ARGS -o "${TOOLS_DIR}/attribute_mapping.json" -s "${ATTRIBUTE_MAPPING_URL}"

# 检查下载是否成功
if [ $? -ne 0 ]; then
echo "Error: Failed to download API mapping files"
exit 1
fi

# python ${APIMAPPING_ROOT}/tools/apply_references.py
## 3. Apply PyTorch-PaddlePaddle mapping using the new API mapping files
python ${APIMAPPING_ROOT}/tools/get_api_difference_info.py
python ${APIMAPPING_ROOT}/tools/generate_pytorch_api_mapping.py

if [ $? -ne 0 ]; then
echo "Error: API mapping generate script failed, please check changes in ${APIMAPPING_ROOT}"
Expand Down
Loading