cluster.py 1.5 KB
Newer Older
T
tangwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

from __future__ import print_function
from __future__ import unicode_literals
T
tangwei 已提交
17

T
tangwei 已提交
18 19 20 21 22
import subprocess
import sys
import os
import copy

T
rename  
tangwei 已提交
23
from fleetrec.core.engine.engine import Engine
T
tangwei 已提交
24 25


T
tangwei 已提交
26
class ClusterEngine(Engine):
T
tangwei 已提交
27 28 29 30
    def __init_impl__(self):
        abs_dir = os.path.dirname(os.path.abspath(__file__))
        self.submit_script = os.path.join(abs_dir, "submit.sh")
        self.job_script = os.path.join(abs_dir, "job.sh")
T
tangwei 已提交
31

T
tangwei 已提交
32
    def start_procs(self):
T
tangwei 已提交
33 34 35 36
        default_env = os.environ.copy()
        current_env = copy.copy(default_env)
        current_env.pop("http_proxy", None)
        current_env.pop("https_proxy", None)
T
tangwei 已提交
37 38 39 40 41

        cmd = ("bash {}".format(self.submit_script)).split(" ")
        proc = subprocess.Popen(cmd, env=current_env, cwd=os.getcwd())
        proc.wait()

T
tangwei 已提交
42 43 44 45
        print("all workers and parameter servers already completed", file=sys.stderr)

    def run(self):
        self.start_procs()