submit_local.sh.in 4.2 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/bin/bash

function usage(){
        echo "usage: paddle [--help] [<args>]"
        echo "These are common paddle commands used in various situations:"
        echo "    train             Start a paddle_trainer"
        echo "    merge_model       Start a paddle_merge_model"
        echo "    pserver           Start a paddle_pserver_main"
        echo "    version           Print paddle version"
        echo "    dump_config       Dump the trainer config as proto string"
        echo "    make_diagram      Make Diagram using Graphviz"
        echo ""
        echo "'paddle train --help' 'paddle merge_model --help', 'paddle pserver --help', list more detailed usage of each command"
}


function version(){
        echo "PaddlePaddle @PADDLE_VERSION@, compiled with"
        echo "    with_avx: @WITH_AVX@"
        echo "    with_gpu: @WITH_GPU@"
        echo "    with_double: @WITH_DOUBLE@"
        echo "    with_python: @WITH_PYTHON@"
        echo "    with_rdma: @WITH_RDMA@"
        echo "    with_timer: @WITH_TIMER@"
}

Y
Yu Yang 已提交
27
function ver2num() {
Y
Yu Yang 已提交
28
  set -e
Y
Yu Yang 已提交
29 30 31 32 33 34 35 36 37 38 39 40
  # convert version to number.
  if [ -z "$1" ]; then # empty argument
    printf "%03d%03d%03d%03d%03d" 0
  else
    local VERN=$(echo $1 | sed 's#v##g' | sed 's#\.# #g' \
        | sed 's#a# 0 #g' | sed 's#b# 1 #g' | sed 's#rc# 2 #g')
    if [ `echo $VERN | wc -w` -eq 3 ] ; then
      printf "%03d%03d%03d%03d%03d" $VERN 999 999
    else
      printf "%03d%03d%03d%03d%03d" $VERN
    fi
  fi
Y
Yu Yang 已提交
41
  set +e
Y
Yu Yang 已提交
42 43 44 45 46 47
}

PADDLE_CONF_HOME="$HOME/.config/paddle"
mkdir -p ${PADDLE_CONF_HOME}

if [ -z "${PADDLE_NO_STAT+x}" ]; then
Y
Yu Yang 已提交
48
    SERVER_VER=`curl -m 5 -X POST --data content="{ \"version\": \"@PADDLE_VERSION@\" }"\
Y
Yu Yang 已提交
49 50 51 52 53 54 55 56
        -b ${PADDLE_CONF_HOME}/paddle.cookie \
        -c ${PADDLE_CONF_HOME}/paddle.cookie \
        http://api.paddlepaddle.org/version 2>/dev/null`
    if [ $? -eq 0 ] && [ "$(ver2num @PADDLE_VERSION@)" -lt  $(ver2num $SERVER_VER) ]; then
      echo "Paddle release a new version ${SERVER_VER}, you can get the install package in http://www.paddlepaddle.org" 
    fi
fi

Z
zhangjinchao01 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ ! -z "${DEBUGGER}" ]; then
    echo "Using debug command ${DEBUGGER}"
fi

CUDNN_LIB_PATH="@CUDNN_LIB_PATH@"

if [ ! -z "${CUDNN_LIB_PATH}" ]; then
    export LD_LIBRARY_PATH=${CUDNN_LIB_PATH}:${LD_LIBRARY_PATH}
fi

export PYTHONPATH=${PWD}:${PYTHONPATH}

Y
Yu Yang 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

# Check python lib installed or not.
pip --help > /dev/null
if [ $? -ne 0 ]; then
    echo "pip should be installed to run paddle."
    exit 1
fi

INSTALLED_VERSION=`pip freeze 2>/dev/null | grep '^paddle' | sed 's/.*==//g'`

if [ -z ${INSTALLED_VERSION} ]; then
   INSTALLED_VERSION="0.0.0"  # not installed
fi
cat <<EOF | python -
from distutils.version import LooseVersion
import sys
if LooseVersion("${INSTALLED_VERSION}") < LooseVersion("@PADDLE_VERSION@"):
  sys.exit(1)
else:
  sys.exit(0)
EOF

if [ $? -eq 1 ]; then  # Older version installed, or not installed at all
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    echo "First time run paddle, need to install some python dependencies."
    # setuptools normalizes package version, so we need to use normalized
    # package version for paddle python package
    PYTHON_PADDLE_VERSION=$(python -c 'import packaging
import setuptools
print str(packaging.version.Version("@PADDLE_VERSION@"))
' 2>/dev/null)
    BASEDIR=$(dirname "$0")
    pip install ${BASEDIR}/../opt/paddle/share/wheels/*-${PYTHON_PADDLE_VERSION}-*.whl
    if [ $? -ne 0 ]; then
	echo "pip install wheels failed. "
	echo "Please use 'sudo paddle' at the first time you use PaddlePaddle"
	echo "PaddlePaddle will install some python dependencies automatically."
	exit 1
    fi
    echo "Python dependencies are installed."
Y
Yu Yang 已提交
111 112
fi

Z
zhangjinchao01 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
case "$1" in
    "train")
        ${DEBUGGER} $MYDIR/../opt/paddle/bin/paddle_trainer ${@:2}
        ;;
    "merge_model")
        ${DEBUGGER} $MYDIR/../opt/paddle/bin/paddle_merge_model ${@:2}
        ;;
    "pserver")
        ${DEBUGGER} $MYDIR/../opt/paddle/bin/paddle_pserver_main ${@:2}
        ;;
    "dump_config")
        python -m paddle.utils.dump_config ${@:2}
        ;;
    "make_diagram")
        python -m paddle.utils.make_model_diagram ${@:2}
        ;;
Z
zhouyingfeng 已提交
129
    "usage")
130
        $MYDIR/../opt/paddle/bin/paddle_usage ${@:2}
Z
zhouyingfeng 已提交
131
        ;;
Z
zhangjinchao01 已提交
132 133 134 135 136 137 138 139 140 141
    "version")
        version
        ;;
    "--help")
        usage
        ;;
    *)
        usage
        ;;
 esac