From e5a6bb1da0da6621cb2ed7d2b9551add555b0308 Mon Sep 17 00:00:00 2001 From: danleifeng <52735331+danleifeng@users.noreply.github.com> Date: Tue, 22 Jun 2021 20:24:12 +0800 Subject: [PATCH] adaptive for py3 for ps util;test=develop (#33727) --- python/paddle/fluid/distributed/node.py | 2 ++ python/paddle/fluid/incubate/fleet/base/fleet_base.py | 2 +- python/paddle/fluid/incubate/fleet/utils/fleet_util.py | 8 ++++---- python/paddle/fluid/incubate/fleet/utils/http_server.py | 7 ++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/python/paddle/fluid/distributed/node.py b/python/paddle/fluid/distributed/node.py index a15f94f4d17..5a1e9362c2f 100644 --- a/python/paddle/fluid/distributed/node.py +++ b/python/paddle/fluid/distributed/node.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and import ps_pb2 as pslib +# NOTE: reduce removed in fuctools in python3 +from functools import reduce class Server(object): diff --git a/python/paddle/fluid/incubate/fleet/base/fleet_base.py b/python/paddle/fluid/incubate/fleet/base/fleet_base.py index 77a20231791..105180030ac 100644 --- a/python/paddle/fluid/incubate/fleet/base/fleet_base.py +++ b/python/paddle/fluid/incubate/fleet/base/fleet_base.py @@ -181,7 +181,7 @@ class Fleet(object): trainers = self.worker_num() remainder = len(files) % trainers - blocksize = len(files) / trainers + blocksize = len(files) // trainers blocks = [blocksize] * trainers for i in range(remainder): diff --git a/python/paddle/fluid/incubate/fleet/utils/fleet_util.py b/python/paddle/fluid/incubate/fleet/utils/fleet_util.py index 979334ed2ea..d02be8af4b1 100644 --- a/python/paddle/fluid/incubate/fleet/utils/fleet_util.py +++ b/python/paddle/fluid/incubate/fleet/utils/fleet_util.py @@ -244,7 +244,7 @@ class FleetUtil(object): new_pos = 0.0 new_neg = 0.0 total_ins_num = 0 - for i in xrange(num_bucket): + for i in range(num_bucket): index = num_bucket - 1 - i new_pos = pos + global_pos[0][index] total_ins_num += global_pos[0][index] @@ -1240,8 +1240,8 @@ class FleetUtil(object): hours = os.popen("echo -n " + hours).read().split(" ") split_interval = int(split_interval) split_per_pass = int(split_per_pass) - splits_per_day = 24 * 60 / split_interval - pass_per_day = splits_per_day / split_per_pass + splits_per_day = 24 * 60 // split_interval + pass_per_day = splits_per_day // split_per_pass left_train_hour = int(hours[0]) right_train_hour = int(hours[-1]) @@ -1425,7 +1425,7 @@ class FleetUtil(object): relative_ctr_error = 0.0 k_max_span = 0.01 k_relative_error_bound = 0.05 - for i in xrange(num_bucket): + for i in range(num_bucket): click = global_pos[0][i] show = global_pos[0][i] + global_neg[0][i] ctr = float(i) / num_bucket diff --git a/python/paddle/fluid/incubate/fleet/utils/http_server.py b/python/paddle/fluid/incubate/fleet/utils/http_server.py index 50933ce5d1b..b4ee29a065a 100644 --- a/python/paddle/fluid/incubate/fleet/utils/http_server.py +++ b/python/paddle/fluid/incubate/fleet/utils/http_server.py @@ -14,8 +14,9 @@ """Http Server.""" import logging -import BaseHTTPServer -import SimpleHTTPServer +# NOTE: HTTPServer has a different name in python2 and python3 +from http.server import HTTPServer +import http.server as SimpleHTTPServer import time import threading import socket @@ -123,7 +124,7 @@ class KVHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.end_headers() -class KVHTTPServer(BaseHTTPServer.HTTPServer, object): +class KVHTTPServer(HTTPServer, object): """ it is a http server storing kv pairs. """ -- GitLab