paddle.py 2.4 KB
Newer Older
Z
zhangjinchao01 已提交
1
#!/usr/bin/python
2
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
Z
zhangjinchao01 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" module for launching cluster job """

import os
import argparse
import socket
import copy
import time
import signal

24
from fabric.api import run, put, settings, env, prefix
Z
zhangjinchao01 已提交
25 26 27 28 29
from fabric.tasks import execute

#configuration for cluster
import conf

30

Z
zhangjinchao01 已提交
31 32 33 34 35 36 37
def refine_unknown_args(cmd_args):
    '''
    refine unknown parameters to handle some special parameters
    '''
    new_args = []
    for arg in cmd_args:
        if arg.startswith("--") and arg.find("=") != -1:
38
            equal_pos = arg.find("=")  #find first = pos
Z
zhangjinchao01 已提交
39 40 41 42 43 44 45 46 47 48 49 50
            arglist = list(arg)
            arglist[equal_pos] = " "
            arg = "".join(arglist)
            arg = arg.lstrip("-")
            new_args += arg.split(" ")
        elif arg.startswith("--") and arg.find("=") == -1:
            arg = arg.lstrip("-")
            new_args.append(arg)
        else:
            new_args.append(arg)
    return new_args

51

Z
zhangjinchao01 已提交
52 53 54 55 56 57 58 59 60 61
def kill_process():
    '''
    kill comments threads
    '''
    run("ps aux \
         | grep paddle_process_by_paddle \
         | grep -v grep  \
         | awk '{print $2}' \
         | xargs kill > /dev/null 2>&1")

62

Z
zhangjinchao01 已提交
63 64 65 66
def job_prepare(jobdir, data=None):
    '''
    prepare job related workspace data

L
lipeng17 已提交
67 68
    Assuming you already installed PaddlePaddle in all nodes which means
    PaddlePaddle related bins and dependencies libraries.
Z
zhangjinchao01 已提交
69 70 71 72
    Assuming the train/test data have already been installed.
    This function just prepare all related model and other resources
    needed at runtime.
    '''
73

Z
zhangjinchao01 已提交
74 75 76 77 78 79 80 81 82
    def job_create_workspace(jobdir, data=None):
        '''
        prepare job workspace, common file, etc.
        '''
        log = os.path.join(jobdir, "log")
        if data is not None:
            #create job dir
            run('rm ' + jobdir + ' -fr && ' + 'mkdir -p ' + jobdir)
            #push data and paddle bin