Skip to content

Commit 2cb2c8b

Browse files
author
Hongsheng Zeng
authored
support windows system (#215)
* first version; unittest in parl/remote is passed * add windows local unittest shell; fix some incompatible problem * fix save api * refine comments and remove log of xparl stop * fix bug * Update scripts.py * Update utils.py * Update agent_base_test.py
1 parent 117b1c3 commit 2cb2c8b

29 files changed

+261
-131
lines changed

.teamcity/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ paddlepaddle-gpu==1.6.1.post97
33
gym
44
details
55
parameterized
6-
timeout_decorator

.teamcity/requirements_torch.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
gym
33
details
44
parameterized
5-
timeout_decorator

.teamcity/windows_test.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# NOTE: You need install mingw-cmake.
18+
19+
function init() {
20+
RED='\033[0;31m'
21+
BLUE='\033[0;34m'
22+
BOLD='\033[1m'
23+
NONE='\033[0m'
24+
25+
REPO_ROOT=`pwd`
26+
}
27+
28+
29+
function abort(){
30+
echo "Your change doesn't follow PaddlePaddle's code style." 1>&2
31+
echo "Please use pre-commit to check what is wrong." 1>&2
32+
exit 1
33+
}
34+
35+
function run_test_with_cpu() {
36+
export CUDA_VISIBLE_DEVICES="-1"
37+
38+
mkdir -p ${REPO_ROOT}/build
39+
cd ${REPO_ROOT}/build
40+
if [ $# -eq 1 ];then
41+
cmake -G "MinGW Makefiles" ..
42+
else
43+
cmake -G "MinGW Makefiles" .. -$2=ON
44+
fi
45+
cat <<EOF
46+
=====================================================
47+
Running unit tests with CPU in the environment: $1
48+
=====================================================
49+
EOF
50+
if [ $# -eq 1 ];then
51+
ctest --output-on-failure -j10
52+
else
53+
ctest --output-on-failure
54+
fi
55+
cd ${REPO_ROOT}
56+
rm -rf ${REPO_ROOT}/build
57+
}
58+
59+
function main() {
60+
set -e
61+
local CMD=$1
62+
63+
init
64+
env="unused_variable"
65+
# run unittest in windows (used in local machine)
66+
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple .
67+
pip uninstall -y torch torchvision
68+
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddlepaddle==1.6.1 gym details parameterized
69+
run_test_with_cpu $env
70+
run_test_with_cpu $env "DIS_TESTING_SERIALLY"
71+
pip uninstall -y paddlepaddle
72+
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
73+
run_test_with_cpu $env "DIS_TESTING_TORCH"
74+
}
75+
76+
main $@

parl/core/fluid/agent.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import warnings
1616
warnings.simplefilter('default')
1717

18+
import os
1819
import paddle.fluid as fluid
1920
from parl.core.fluid import layers
2021
from parl.core.agent_base import AgentBase
@@ -152,8 +153,8 @@ def save(self, save_path, program=None):
152153
"""
153154
if program is None:
154155
program = self.learn_program
155-
dirname = '/'.join(save_path.split('/')[:-1])
156-
filename = save_path.split('/')[-1]
156+
dirname = os.sep.join(save_path.split(os.sep)[:-1])
157+
filename = save_path.split(os.sep)[-1]
157158
fluid.io.save_params(
158159
executor=self.fluid_executor,
159160
dirname=dirname,
@@ -186,8 +187,8 @@ def restore(self, save_path, program=None):
186187
program = self.learn_program
187188
if type(program) is fluid.compiler.CompiledProgram:
188189
program = program._init_program
189-
dirname = '/'.join(save_path.split('/')[:-1])
190-
filename = save_path.split('/')[-1]
190+
dirname = os.sep.join(save_path.split(os.sep)[:-1])
191+
filename = save_path.split(os.sep)[-1]
191192
fluid.io.load_params(
192193
executor=self.fluid_executor,
193194
dirname=dirname,

parl/core/fluid/layers/tests/param_sharing_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_param_sharing(self):
4545
dict_size = 100
4646
input_cx = np.random.uniform(0, 1, [batch_size, 100]).astype("float32")
4747
input_x = np.random.randint(
48-
dict_size, size=(batch_size, 1)).astype("int")
48+
dict_size, size=(batch_size, 1)).astype("int64")
4949
#################################
5050

5151
main_program1 = fluid.Program()
@@ -59,7 +59,7 @@ def test_param_sharing(self):
5959

6060
main_program2 = fluid.Program()
6161
with fluid.program_guard(main_program2):
62-
x_ = layers.data(name='x', shape=[1], dtype="int")
62+
x_ = layers.data(name='x', shape=[1], dtype="int64")
6363
cx_ = layers.cast(
6464
x=layers.one_hot(input=x_, depth=dict_size), dtype="float32")
6565
y1_ = net.fc1(input=cx_)

parl/core/fluid/tests/agent_base_test_.py renamed to parl/core/fluid/tests/agent_base_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def learn(self, obs, label):
4646

4747

4848
class TestAgent(parl.Agent):
49-
def __init__(self, algorithm, gpu_id=None):
50-
super(TestAgent, self).__init__(algorithm, gpu_id)
49+
def __init__(self, algorithm):
50+
super(TestAgent, self).__init__(algorithm)
5151

5252
def build_program(self):
5353
self.predict_program = fluid.Program()
@@ -92,8 +92,8 @@ def test_save(self):
9292
agent = TestAgent(self.algorithm)
9393
obs = np.random.random([3, 10]).astype('float32')
9494
output_np = agent.predict(obs)
95-
save_path1 = './model.ckpt'
96-
save_path2 = './my_model/model-2.ckpt'
95+
save_path1 = 'model.ckpt'
96+
save_path2 = os.path.join('my_model', 'model-2.ckpt')
9797
agent.save(save_path1)
9898
agent.save(save_path2)
9999
self.assertTrue(os.path.exists(save_path1))
@@ -103,7 +103,7 @@ def test_restore(self):
103103
agent = TestAgent(self.algorithm)
104104
obs = np.random.random([3, 10]).astype('float32')
105105
output_np = agent.predict(obs)
106-
save_path1 = './model.ckpt'
106+
save_path1 = 'model.ckpt'
107107
previous_output = agent.predict(obs)
108108
agent.save(save_path1)
109109
agent.restore(save_path1)
@@ -121,7 +121,7 @@ def test_compiled_restore(self):
121121
agent.learn_program = parl.compile(agent.learn_program)
122122
obs = np.random.random([3, 10]).astype('float32')
123123
previous_output = agent.predict(obs)
124-
save_path1 = './model.ckpt'
124+
save_path1 = 'model.ckpt'
125125
agent.save(save_path1)
126126
agent.restore(save_path1)
127127

File renamed without changes.
File renamed without changes.

parl/core/torch/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def save(self, save_path, model=None):
113113
"""
114114
if model is None:
115115
model = self.algorithm.model
116-
dirname = '/'.join(save_path.split('/')[:-1])
117-
if not os.path.exists(dirname):
116+
sep = os.sep
117+
dirname = sep.join(save_path.split(sep)[:-1])
118+
if dirname != '' and not os.path.exists(dirname):
118119
os.makedirs(dirname)
119120
torch.save(model.state_dict(), save_path)
120121

parl/core/torch/tests/agent_base_test_torch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def test_agent(self):
7777
def test_save(self):
7878
agent = TestAgent(self.alg)
7979
obs = torch.randn(3, 10)
80-
save_path1 = './model.ckpt'
81-
save_path2 = './my_model/model-2.ckpt'
80+
save_path1 = 'model.ckpt'
81+
save_path2 = os.path.join('my_model', 'model-2.ckpt')
8282
agent.save(save_path1)
8383
agent.save(save_path2)
8484
self.assertTrue(os.path.exists(save_path1))
@@ -88,7 +88,7 @@ def test_restore(self):
8888
agent = TestAgent(self.alg)
8989
obs = torch.randn(3, 10)
9090
output = agent.predict(obs)
91-
save_path1 = './model.ckpt'
91+
save_path1 = 'model.ckpt'
9292
previous_output = agent.predict(obs).detach().cpu().numpy()
9393
agent.save(save_path1)
9494
agent.restore(save_path1)

0 commit comments

Comments
 (0)