Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

add_subdirectory(mnist)
add_subdirectory(cifar)
add_subdirectory(machine_translation)
22 changes: 11 additions & 11 deletions src/example/cifar/test_cifar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ using paddle::tape::ResetReader;

TEST(Cifar, TestGPU) {
// auto place = paddle::platform::CPUPlace();
auto place = paddle::platform::CUDAPlace(0);
auto place = paddle::platform::CUDAPlace(1);
reset_global_tape(place);

const int batch_size = 128;
const int batch_size = 64;
LOG(INFO) << "Batch size is " << batch_size << std::endl;

std::string save_model_path = "/tmp/cifar_model/";
Expand Down Expand Up @@ -119,10 +119,10 @@ TEST(Cifar, TestGPU) {
BatchNorm bn5_3(512, "relu");

// Input dim 512x1x1 = 512
Linear fc1(512, 512);
Linear fc1({512}, 512);
BatchNorm bn6(512, "relu");
Linear fc2(512, 512);
Linear fc3(512, 10, "softmax");
Linear fc2({512}, 512);
Linear fc3({512}, 10, "softmax");

Adam adam(0.001);

Expand Down Expand Up @@ -153,19 +153,19 @@ TEST(Cifar, TestGPU) {
auto pool5 = pool2d(bn5_3(conv5_3(temp5_2), bn_attrs));

d_attrs["dropout_prob"] = 0.5f;
auto temp6 = bn6(fc1(dropout(pool5, d_attrs)), bn_attrs);
return fc3(fc2(dropout(temp6, d_attrs)));
auto temp6 = bn6(fc1({dropout(pool5, d_attrs)}), bn_attrs);
return fc3({fc2({dropout(temp6, d_attrs)})});
};

int total_steps = 100000;
int test_steps = 1000;
int print_step = 100;
float threshold = 0.8f;
float threshold = 0.3f;

int iter_num = 1050;
int skip_batch_num = 50;
bool model_saved = false;
bool do_benchmark = true;
bool do_benchmark = false;

auto start = std::chrono::system_clock::now();
int num_samples = 0;
Expand Down Expand Up @@ -332,8 +332,8 @@ TEST(Cifar, TestGPU) {
auto pool5 = pool2d(inf_bn5_3(inf_conv5_3(temp5_2), bn_attrs));

d_attrs["dropout_prob"] = 0.5f;
auto temp6 = inf_bn6(inf_fc1(dropout(pool5, d_attrs)), bn_attrs);
return inf_fc3(inf_fc2(dropout(temp6, d_attrs)));
auto temp6 = inf_bn6(inf_fc1({dropout(pool5, d_attrs)}), bn_attrs);
return inf_fc3({inf_fc2({dropout(temp6, d_attrs)})});
};

std::vector<float> losses;
Expand Down
18 changes: 18 additions & 0 deletions src/example/machine_translation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2016 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.
#

cc_test(test_machine_translation
SRCS test_machine_translation.cc
DEPS tape tape_function tape_optimizer)
63 changes: 63 additions & 0 deletions src/example/machine_translation/create_wmt14_recordio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2018 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.

import paddle
import paddle.fluid as fluid
import paddle.dataset.wmt14 as wmt14


def create_wmt14_recordio_files():
with fluid.program_guard(fluid.Program(), fluid.Program()):
reader = paddle.batch(wmt14.train(30000), batch_size=1)
feeder = fluid.DataFeeder(
feed_list=[
fluid.layers.data(
name='src_word_id', shape=[1], dtype='int64', lod_level=1),
fluid.layers.data(
name='target_language_word',
shape=[1],
dtype='int64',
lod_level=1), fluid.layers.data(
name='target_language_next_word',
shape=[1],
dtype='int64',
lod_level=1)
],
place=fluid.CPUPlace())
fluid.recordio_writer.convert_reader_to_recordio_file(
'/tmp/wmt14_train.recordio', reader, feeder)

with fluid.program_guard(fluid.Program(), fluid.Program()):
reader = paddle.batch(wmt14.test(30000), batch_size=1)
feeder = fluid.DataFeeder(
feed_list=[
fluid.layers.data(
name='src_word_id', shape=[1], dtype='int64', lod_level=1),
fluid.layers.data(
name='target_language_word',
shape=[1],
dtype='int64',
lod_level=1), fluid.layers.data(
name='target_language_next_word',
shape=[1],
dtype='int64',
lod_level=1)
],
place=fluid.CPUPlace())
fluid.recordio_writer.convert_reader_to_recordio_file(
'/tmp/wmt14_test.recordio', reader, feeder)


if __name__ == "__main__":
create_wmt14_recordio_files()
Loading