sample_trainer_config_parallel.conf 2.9 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#edit-mode: -*- python -*-
# Copyright (c) 2016 Baidu, Inc. 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.

16
from paddle.trainer_config_helpers import *
Z
zhangjinchao01 已提交
17

18 19 20 21 22
TrainData(SimpleData(
            files = "trainer/tests/sample_filelist.txt",
            feat_dim = 3,
            context_len = 0,
            buffer_capacity = 1000000))
Z
zhangjinchao01 已提交
23

24 25 26 27 28
TestData(SimpleData(
           files = "trainer/tests/sample_filelist.txt",
           feat_dim = 3,
           context_len = 0,
           buffer_capacity = 1000000))
Z
zhangjinchao01 已提交
29

30
settings(batch_size = 100)
Z
zhangjinchao01 已提交
31 32 33 34 35

# Output layer, label layer, cost layer, preferably set to the same environment.
output_device = 0

# Input Layer does not need to specify the device number.
36
data = data_layer(name='input', size=3)
Z
zhangjinchao01 已提交
37 38

# Calculate in the CPU.
39 40 41 42
fc1 = fc_layer(input=data, size=5,
               bias_attr=True,
               layer_attr=ExtraAttr(device=-1),
               act=SigmoidActivation())
Z
zhangjinchao01 已提交
43 44

# Calculate in the GPU 0.
45 46 47 48
fc2 = fc_layer(input=fc1, size=10,
               bias_attr=True,
               layer_attr=ExtraAttr(device=0),
               act=SigmoidActivation())
Z
zhangjinchao01 已提交
49 50

# Calculate in the GPU 1.
51 52 53 54
fc3 = fc_layer(input=fc1, size=10,
               bias_attr=True,
               layer_attr=ExtraAttr(device=1),
               act=SigmoidActivation())
Z
zhangjinchao01 已提交
55 56

# Calculate in the GPU 0.
57 58 59 60
fc4 = fc_layer(input=[fc2,fc3], size=10,
               bias_attr=True,
               layer_attr=ExtraAttr(device=0),
               act=SigmoidActivation())
Z
zhangjinchao01 已提交
61 62

# Calculate in the GPU 1.
63 64 65 66
fc5 = fc_layer(input=[fc2,fc3], size=10,
               bias_attr=True,
               layer_attr=ExtraAttr(device=1),
               act=SigmoidActivation())
Z
zhangjinchao01 已提交
67

68 69 70 71
output = fc_layer(input=[fc4,fc5], size=10,
                  bias_attr=True,
                  layer_attr=ExtraAttr(device=output_device),
                  act=SoftmaxActivation())
Z
zhangjinchao01 已提交
72 73 74 75 76

if get_config_arg('with_cost', bool, True):
    # This is for training the neural network.
    # We need to have another data layer for label
    # and a layer for calculating cost
77 78 79 80 81 82
    lbl = data_layer(name='label', size=1,
                    layer_attr=ExtraAttr(device=output_device))
                    
    outputs(classification_cost(input=output, 
                                label=lbl,
                                layer_attr=ExtraAttr(device=output_device)))
Z
zhangjinchao01 已提交
83 84 85
else:
    # This is for prediction where we don't have label
    # and don't need to calculate cost
86
    outputs(output)