未验证 提交 958b9f07 编写于 作者: C Charles-hit 提交者: GitHub

move fc api to paddle2.0 (#49379)

* move fc from fluid to paddle2.0

* fix unit test

* fix some examples

* fix some examples
上级 7ff66973
......@@ -1550,8 +1550,6 @@ def fused_bn_add_act(
import paddle
import paddle.fluid as fluid
import paddle
paddle.enable_static()
paddle.enable_static()
# required: gpu
......@@ -1582,7 +1580,7 @@ def fused_bn_add_act(
act=None,
data_layout='NHWC')
fused_bn_add_act = fluid.contrib.layers.fused_bn_add_act(conv1_2, bn)
prediction = fluid.layers.fc(input=fused_bn_add_act, size=10, act='softmax')
prediction = paddle.static.nn.fc(x=fused_bn_add_act, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=y,
reduction='none', use_softmax=False
......
......@@ -94,10 +94,10 @@ def vgg16_bn_drop(input):
conv5 = conv_block(conv4, 512, 3, [0.4, 0.4, 0])
drop = paddle.nn.functional.dropout(x=conv5, p=0.5)
fc1 = fluid.layers.fc(input=drop, size=4096, act=None)
fc1 = paddle.static.nn.fc(x=drop, size=4096, activation=None)
bn = paddle.static.nn.batch_norm(input=fc1, act='relu')
drop2 = paddle.nn.functional.dropout(x=bn, p=0.5)
fc2 = fluid.layers.fc(input=drop2, size=4096, act=None)
fc2 = paddle.static.nn.fc(x=drop2, size=4096, activation=None)
return fc2
......@@ -124,7 +124,7 @@ def train(net_type, use_cuda, save_dirname, is_local):
else:
raise ValueError("%s network is not supported" % net_type)
logits = fluid.layers.fc(input=net, size=classdim, act="softmax")
logits = paddle.static.nn.fc(x=net, size=classdim, activation="softmax")
cost, predict = paddle.nn.functional.softmax_with_cross_entropy(
logits, label, return_softmax=True
)
......@@ -506,7 +506,9 @@ class TestAmpWithNonIterableDataLoader(unittest.TestCase):
)
net = vgg16_bn_drop(image)
logits = fluid.layers.fc(input=net, size=10, act="softmax")
logits = paddle.static.nn.fc(
x=net, size=10, activation="softmax"
)
cost, predict = paddle.nn.functional.softmax_with_cross_entropy(
logits, label, return_softmax=True
)
......
......@@ -107,7 +107,7 @@ def train(use_pure_fp16=True, use_nesterov=False, optimizer=""):
)
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
net = resnet_cifar10(images)
logits = fluid.layers.fc(input=net, size=classdim, act="softmax")
logits = paddle.static.nn.fc(x=net, size=classdim, activation="softmax")
cost = paddle.nn.functional.softmax_with_cross_entropy(
logits, label, return_softmax=False
)
......@@ -300,7 +300,9 @@ class TestAmpWithNonIterableDataLoader(unittest.TestCase):
fluid.layers.assign(input=one_var, output=label)
net = resnet_cifar10(image)
logits = fluid.layers.fc(input=net, size=10, act="softmax")
logits = paddle.static.nn.fc(
x=net, size=10, activation="softmax"
)
block = main_prog.global_block()
for op in block.ops:
......
......@@ -83,9 +83,11 @@ def bow_net(
)
bow = fluid.layers.sequence_pool(input=emb, pool_type='sum')
bow_tanh = paddle.tanh(bow)
fc_1 = fluid.layers.fc(input=bow_tanh, size=hid_dim, act="tanh")
fc_2 = fluid.layers.fc(input=fc_1, size=hid_dim2, act="tanh")
prediction = fluid.layers.fc(input=[fc_2], size=class_dim, act="softmax")
fc_1 = paddle.static.nn.fc(x=bow_tanh, size=hid_dim, activation="tanh")
fc_2 = paddle.static.nn.fc(x=fc_1, size=hid_dim2, activation="tanh")
prediction = paddle.static.nn.fc(
x=[fc_2], size=class_dim, activation="softmax"
)
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
......
......@@ -349,7 +349,7 @@ class DataFeeder:
with fluid.program_guard(main_program, startup_program):
data_1 = fluid.data(name='data_1', shape=[None, 2, 2], dtype='float32')
data_2 = fluid.data(name='data_2', shape=[None, 1, 3], dtype='float32')
out = fluid.layers.fc(input=[data_1, data_2], size=2)
out = paddle.static.nn.fc(x=[data_1, data_2], size=2)
# ...
feeder = fluid.DataFeeder([data_1, data_2], place)
......@@ -584,7 +584,7 @@ class DataFeeder:
# a simple network sample
data = fluid.data(name='data', shape=[None, 4, 4], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
feeder = fluid.DataFeeder(place=places[0], feed_list=[data, label])
reader = feeder.decorate_reader(reader, multi_devices=True, num_places=3, drop_last=True)
......
......@@ -119,11 +119,11 @@ def model():
dnn_pool = fluid.layers.sequence_pool(input=dnn_embedding, pool_type="sum")
dnn_out = dnn_pool
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -145,7 +145,7 @@ def model():
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(x=merge_layer, size=2, activation='softmax')
acc = paddle.static.accuracy(input=predict, label=label)
auc_var, batch_auc_var, auc_states = paddle.static.auc(
input=predict, label=label
......
......@@ -150,10 +150,10 @@ class ConstantInitializer(Initializer):
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name="data", shape=[8, 32, 32], dtype="float32")
fc = fluid.layers.fc(
input=x,
fc = paddle.static.nn.fc(
x,
size=10,
param_attr=fluid.initializer.Constant(value=2.0))
weight_attr=fluid.initializer.Constant(value=2.0))
"""
......@@ -224,10 +224,12 @@ class UniformInitializer(Initializer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name='x', shape=[None, 1], dtype='float32')
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Uniform(low=-0.5, high=0.5))
fc = paddle.static.nn.fc(x, size=10,
weight_attr=fluid.initializer.Uniform(low=-0.5, high=0.5))
"""
def __init__(
......@@ -346,10 +348,12 @@ class NormalInitializer(Initializer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name="data", shape=[None, 32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
fc = paddle.static.nn.fc(x, size=10,
weight_attr=fluid.initializer.Normal(loc=0.0, scale=2.0))
"""
......@@ -429,10 +433,12 @@ class TruncatedNormalInitializer(Initializer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name='x', shape=[None, 1], dtype='float32')
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.TruncatedNormal(loc=0.0, scale=2.0))
fc = paddle.static.nn.fc(x, size=10,
weight_attr=fluid.initializer.TruncatedNormal(loc=0.0, scale=2.0))
"""
def __init__(self, loc=0.0, scale=1.0, seed=0):
......@@ -557,11 +563,13 @@ class XavierInitializer(Initializer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
queries = fluid.data(name='x', shape=[None,1], dtype='float32')
fc = fluid.layers.fc(
input=queries, size=10,
param_attr=fluid.initializer.Xavier(uniform=False))
fc = paddle.static.nn.fc(
x=queries, size=10,
weight_attr=fluid.initializer.Xavier(uniform=False))
"""
......@@ -732,8 +740,8 @@ class MSRAInitializer(Initializer):
import paddle.fluid as fluid
paddle.enable_static()
x = fluid.data(name="data", shape=[8, 32, 32], dtype="float32")
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.MSRA(uniform=False))
fc = paddle.static.nn.fc(x, size=10,
weight_attr=fluid.initializer.MSRA(uniform=False))
"""
......@@ -1044,11 +1052,13 @@ class NumpyArrayInitializer(Initializer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy
paddle.enable_static()
x = fluid.data(name="x", shape=[2, 1], dtype='float32')
fc = fluid.layers.fc(input=x, size=10,
param_attr=fluid.initializer.NumpyArrayInitializer(numpy.array([1,2])))
fc = paddle.static.nn.fc(x, size=10,
weight_attr=fluid.initializer.NumpyArrayInitializer(numpy.array([1,2])))
"""
def __init__(self, value):
......@@ -1282,10 +1292,11 @@ def calculate_gain(nonlinearity, param=None):
# We short the class name, since users will use the initializer with the package
# name. The sample code:
#
# import paddle
# import paddle.fluid as fluid
#
# hidden = fluid.layers.fc(...,
# param_attr=ParamAttr(fluid.initializer.Xavier()))
# hidden = paddle.static.nn.fc(...,
# weight_attr=ParamAttr(fluid.initializer.Xavier()))
#
# It is no need to add an `Initializer` as the class suffix
Constant = ConstantInitializer
......
......@@ -511,7 +511,7 @@ def save_params(executor, dirname, main_program=None, filename=None):
image = fluid.data(name='img', shape=[None, 28, 28], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace())
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=predict, label=label,
......@@ -750,7 +750,7 @@ def save_persistables(executor, dirname, main_program=None, filename=None):
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace())
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......@@ -1384,7 +1384,7 @@ def save_inference_model(
image = fluid.data(name='img', shape=[None, 28, 28], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace())
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=predict, label=label,
......
......@@ -353,7 +353,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# create prev memory parameter, batch size comes from word
prev = rnn.memory(shape=[-1, hidden_size], batch_ref = word)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# use hidden to update prev
rnn.update_memory(prev, hidden)
# mark hidden as output
......@@ -444,7 +444,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# create prev memory parameter, batch size comes from word
prev = rnn.memory(shape=[-1, hidden_size], batch_ref = word)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# use hidden to update prev
rnn.update_memory(prev, hidden)
......@@ -473,7 +473,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# init memory
prev = rnn.memory(init=boot_memory)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# update hidden with prev
rnn.update_memory(prev, hidden)
......@@ -576,7 +576,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# create prev memory parameter, batch size comes from word
prev = rnn.memory(shape=[-1, hidden_size], batch_ref = word)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# use hidden to update prev
rnn.update_memory(prev, hidden)
......@@ -629,7 +629,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# create prev memory parameter, batch size comes from word
prev = rnn.memory(shape=[-1, hidden_size], batch_ref = word)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# use hidden to update prev
rnn.update_memory(prev, hidden)
rnn.step_output(hidden)
......@@ -691,7 +691,7 @@ class StaticRNN:
word = rnn.step_input(x_emb)
# create prev memory parameter, batch size comes from word
prev = rnn.memory(shape=[-1, hidden_size], batch_ref = word)
hidden = fluid.layers.fc(input=[word, prev], size=hidden_size, act='relu')
hidden = paddle.static.nn.fc(x=[word, prev], size=hidden_size, activation='relu')
# use hidden to update prev
rnn.update_memory(prev, hidden)
# mark each step's hidden and word as output
......
......@@ -45,7 +45,6 @@ from .layer_function_generator import (
from .tensor import concat, assign, fill_constant, zeros
from . import utils
from .. import unique_name
from functools import reduce
from .. import core
from ...utils import deprecated
from ..data_feeder import (
......@@ -60,7 +59,6 @@ from collections.abc import Iterable
__all__ = [
'fc',
'embedding',
'autoincreased_step_counter',
]
......@@ -126,172 +124,6 @@ def _elementwise_op_in_dygraph(
)
def fc(
input,
size,
num_flatten_dims=1,
param_attr=None,
bias_attr=None,
act=None,
name=None,
):
r"""
:api_attr: Static Graph
**Fully Connected Layer**
This operator creates a fully connected layer in the network. It can take
a Tensor(or LoDTensor) or a list of Tensor(or LoDTensor) as its inputs(see
Args in detail). It creates a variable called weight for each input Tensor,
which represents a fully connected weight matrix from each input unit to
each output unit. The fully connected layer multiplies each input Tensor
with its corresponding weight to produce an output Tensor with shape :math:`[M, size]` ,
where M is batch size. If a list of Tensor is given, the results of
multiple output Tensors with shape :math:`[M, size]` will be summed up. If :attr:`bias_attr`
is not None, a bias variable will be created and added to the output.
Finally, if :attr:`act` is not None, it will be applied to the output as well.
When the input is a single Tensor(or LoDTensor):
.. math::
Out = Act({XW + b})
When the input is a list of Tensor(or LoDTensor):
.. math::
Out = Act({\sum_{i=0}^{N-1}X_iW_i + b})
In the above equation:
* :math:`N`: Number of the input. N equals to len(input) if input is list of Variable.
* :math:`X_i`: The i-th input tensor.
* :math:`W_i`: The i-th weights matrix corresponding i-th input tensor.
* :math:`b`: The bias parameter created by this layer (if needed).
* :math:`Act`: The activation function.
* :math:`Out`: The output Tensor.
.. code-block:: text
Case 1:
Given a single Tensor data_1, and num_flatten_dims = 2:
data_1.data = [[[0.1, 0.2],
[0.3, 0.4]]]
data_1.shape = (1, 2, 2) # 1 is batch_size
out = fluid.layers.fc(input=data_1, size=1, num_flatten_dims=2)
Then output is:
out.data = [[0.83234344], [0.34936576]]
out.shape = (1, 2, 1)
Case 2:
Given a list of Tensor:
data_1.data = [[[0.1, 0.2],
[0.3, 0.4]]]
data_1.shape = (1, 2, 2) # 1 is batch_size
data_2 = [[[0.1, 0.2, 0.3]]]
data_2.shape = (1, 1, 3)
out = fluid.layers.fc(input=[data_1, data_2], size=2)
Then:
out.data = [[0.18669507, 0.1893476]]
out.shape = (1, 2)
Args:
input (Variable|list of Variable): A Tensor(or LoDTensor) with shape :math:`[N_1, N_2,..., N_k]` or
a list of Tensor(or LoDTensor). The dimensions of the input Tensor is at least 2 and the data
type should be float32 or float64.
size(int): The number of output units in this layer, which also means the feature size of output
Tensor(or LoDTensor).
num_flatten_dims (int): The fc layer can accept an input Tensor with more than
two dimensions. If this happens, the multidimensional tensor will first be flattened
into a 2-D matrix. The parameter :attr:`num_flatten_dims` determines how the input
Tensor is flattened: the first :attr:`num_flatten_dims` (inclusive, index starts from 1)
dimensions will be flatten to form the first dimension of the final matrix (height of
the matrix), and the rest :math:`rank(X) - num\_flatten\_dims` dimensions are flattened to
form the second dimension of the final matrix (width of the matrix). For example, assuming that
X is a 5-dimensional Tensor with a shape [2, 3, 4, 5, 6], and :attr:`num_flatten_dims` = 3.
Then, the flattened matrix will have a shape [2 x 3 x 4, 5 x 6] = [24, 30]. Default: 1.
param_attr (ParamAttr): To specify the weight parameter property. Default: None, which means the
default weight parameter property is used. See usage for details in :ref:`api_fluid_ParamAttr` .
bias_attr (ParamAttr): To specify the bias parameter property. Default: None, which means the
default bias parameter property is used. See usage for details in :ref:`api_fluid_ParamAttr` .
act (str): Activation to be applied to the output of this layer, such as tanh, softmax,
sigmoid, relu. For more information, please refer to :ref:`api_guide_activations_en` . Default: None.
name (str, optional): The default value is None. Normally there is no need for user to set this property.
For more information, please refer to :ref:`api_guide_Name` .
Returns:
Variable: Tensor or LoDTensor calculated by fc layer. The data type is same with input.
Raises:
ValueError: If dimensions of the input Tensor is less than 2.
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
paddle.enable_static()
# when input is single tensor
data = fluid.data(name="data", shape=[-1, 32], dtype="float32")
fc = fluid.layers.fc(input=data, size=1000, act="tanh")
# when input are multiple tensors
data_1 = fluid.data(name="data_1", shape=[-1, 32], dtype="float32")
data_2 = fluid.data(name="data_2", shape=[-1, 36], dtype="float32")
fc = fluid.layers.fc(input=[data_1, data_2], size=1000, act="tanh")
"""
helper = LayerHelper("fc", **locals())
check_type(input, 'input', (list, tuple, Variable), 'fc')
if isinstance(input, (list, tuple)):
for i, input_x in enumerate(input):
check_type(input_x, 'input[' + str(i) + ']', Variable, 'fc')
dtype = helper.input_dtype()
check_dtype(
dtype, 'input', ['float16', 'uint16', 'float32', 'float64'], 'fc'
)
mul_results = []
for input_var, param_attr in helper.iter_inputs_and_params():
input_shape = input_var.shape
if num_flatten_dims == -1:
num_flatten_dims = len(input_shape) - 1
param_shape = [
reduce(lambda a, b: a * b, input_shape[num_flatten_dims:], 1)
] + [size]
w = helper.create_parameter(
attr=param_attr, shape=param_shape, dtype=dtype, is_bias=False
)
tmp = helper.create_variable_for_type_inference(dtype)
helper.append_op(
type="mul",
inputs={"X": input_var, "Y": w},
outputs={"Out": tmp},
attrs={"x_num_col_dims": num_flatten_dims, "y_num_col_dims": 1},
)
mul_results.append(tmp)
if len(mul_results) == 1:
pre_bias = mul_results[0]
else:
pre_bias = helper.create_variable_for_type_inference(dtype)
helper.append_op(
type="sum",
inputs={"X": mul_results},
outputs={"Out": pre_bias},
attrs={"use_mkldnn": False},
)
# add bias
pre_activation = helper.append_bias_op(pre_bias, dim_start=num_flatten_dims)
# add activation
return helper.append_activation(pre_activation)
@deprecated(since="2.0.0", update_to="paddle.nn.functional.embedding")
def embedding(
input,
......
......@@ -554,9 +554,13 @@ def scaled_dot_product_attention(
if num_heads == 1:
return queries, keys, values
q = layers.fc(input=queries, size=queries.shape[-1], num_flatten_dims=2)
k = layers.fc(input=keys, size=keys.shape[-1], num_flatten_dims=2)
v = layers.fc(input=values, size=values.shape[-1], num_flatten_dims=2)
q = paddle.static.nn.fc(
x=queries, size=queries.shape[-1], num_flatten_dims=2
)
k = paddle.static.nn.fc(x=keys, size=keys.shape[-1], num_flatten_dims=2)
v = paddle.static.nn.fc(
x=values, size=values.shape[-1], num_flatten_dims=2
)
return q, k, v
def __split_heads(x, num_heads):
......
......@@ -1433,7 +1433,7 @@ class SGDOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -1625,7 +1625,7 @@ class MomentumOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -1774,7 +1774,7 @@ class LarsMomentumOptimizer(Optimizer):
np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
inp = fluid.layers.data(
name="inp", shape=[2, 2], append_batch_size=False)
out = fluid.layers.fc(inp, size=3)
out = paddle.static.nn.fc(inp, size=3)
out = paddle.sum(out)
optimizer = fluid.optimizer.LarsMomentumOptimizer(learning_rate=0.001, momentum=0.9)
optimizer.minimize(out)
......@@ -2033,7 +2033,7 @@ class AdagradOptimizer(Optimizer):
paddle.enable_static()
np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
inp = fluid.data(name="inp", shape=[2, 2])
out = fluid.layers.fc(inp, size=3)
out = paddle.static.nn.fc(inp, size=3)
out = paddle.sum(out)
optimizer = fluid.optimizer.AdagradOptimizer(learning_rate=0.2)
optimizer.minimize(out)
......@@ -2191,7 +2191,7 @@ class AdamOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.data(name='x', shape=[None, 13], dtype='float32')
y = fluid.data(name='y', shape=[None, 1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -2220,7 +2220,7 @@ class AdamOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.data(name='x', shape=[None, 13], dtype='float32')
y = fluid.data(name='y', shape=[None, 1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -2613,7 +2613,7 @@ class AdamaxOptimizer(Optimizer):
startup_program = fluid.Program()
with fluid.program_guard(train_program, startup_program):
data = fluid.data(name='X', shape=[None, 1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
loss = paddle.mean(hidden)
adam = fluid.optimizer.AdamaxOptimizer(learning_rate=0.2)
adam.minimize(loss)
......@@ -2765,7 +2765,7 @@ class DpsgdOptimizer(Optimizer):
startup_program = fluid.Program()
with fluid.program_guard(train_program, startup_program):
data = fluid.layers.data(name='X', shape=[1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
loss = paddle.mean(hidden)
optimizer = fluid.optimizer.Dpsgd(learning_rate=0.01, clip=10.0, batch_size=16.0, sigma=1.0)
optimizer.minimize(loss)
......@@ -2909,11 +2909,13 @@ class DecayedAdagradOptimizer(Optimizer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.data( name='x', shape=[None, 10], dtype='float32' )
trans = fluid.layers.fc( x, 100 )
cost = fluid.layers.reduce_mean( trans )
paddle.enable_static()
x = fluid.data(name='x', shape=[None, 10], dtype='float32')
trans = paddle.static.nn.fc(x, 100)
cost = paddle.mean(trans)
optimizer = fluid.optimizer.DecayedAdagradOptimizer(learning_rate=0.2)
optimizer.minimize(cost)
"""
......@@ -3031,11 +3033,13 @@ class AdadeltaOptimizer(Optimizer):
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
image = fluid.data(name='image', shape=[None, 28], dtype='float32')
fc = fluid.layers.fc(image, size=10)
cost = fluid.layers.reduce_mean(fc)
fc = paddle.static.nn.fc(image, size=10)
cost = paddle.mean(fc)
optimizer = fluid.optimizer.Adadelta(
learning_rate=0.0003, epsilon=1.0e-6, rho=0.95)
......@@ -3215,7 +3219,7 @@ class RMSPropOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -3413,7 +3417,7 @@ class FtrlOptimizer(Optimizer):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -3589,7 +3593,7 @@ class LambOptimizer(AdamOptimizer):
paddle.enable_static()
data = fluid.data(name='x', shape=[-1, 5], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
cost = paddle.mean(hidden)
def exclude_fn(param):
......@@ -3806,7 +3810,7 @@ class ModelAverage(Optimizer):
with fluid.program_guard(train_program, startup_program):
# build net
data = fluid.data(name='X', shape=[None, 1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
loss = paddle.mean(hidden)
optimizer = fluid.optimizer.Momentum(learning_rate=0.2, momentum=0.1)
optimizer.minimize(loss)
......@@ -3985,7 +3989,7 @@ class ModelAverage(Optimizer):
with fluid.program_guard(train_program, startup_program):
# build net
data = fluid.data(name='X', shape=[None, 1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
loss = paddle.mean(hidden)
optimizer = fluid.optimizer.Momentum(learning_rate=0.2, momentum=0.1)
optimizer.minimize(loss)
......@@ -4041,7 +4045,7 @@ class ModelAverage(Optimizer):
with fluid.program_guard(train_program, startup_program):
# build net
data = fluid.data(name='X', shape=[None, 1], dtype='float32')
hidden = fluid.layers.fc(input=data, size=10)
hidden = paddle.static.nn.fc(x=data, size=10)
loss = paddle.mean(hidden)
optimizer = fluid.optimizer.Momentum(learning_rate=0.2, momentum=0.1)
optimizer.minimize(loss)
......@@ -4347,9 +4351,11 @@ class PipelineOptimizer:
Examples:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import paddle.fluid.layers as layers
paddle.enable_static()
with fluid.device_guard("gpu:0"):
x = fluid.layers.data(name='x', shape=[1], dtype='int64', lod_level=0)
y = fluid.layers.data(name='y', shape=[1], dtype='int64', lod_level=0)
......@@ -4364,8 +4370,8 @@ class PipelineOptimizer:
with fluid.device_guard("gpu:1"):
concat = layers.concat([emb_x, emb_y], axis=1)
fc = layers.fc(input=concat, name="fc", size=1, num_flatten_dims=1, bias_attr=False)
loss = layers.reduce_mean(fc)
fc = paddle.static.nn.fc(x=concat, name="fc", size=1, num_flatten_dims=1, bias_attr=False)
loss = paddle.mean(fc)
optimizer = fluid.optimizer.SGD(learning_rate=0.5)
optimizer = fluid.optimizer.PipelineOptimizer(optimizer)
optimizer.minimize(loss)
......@@ -6318,8 +6324,8 @@ class RecomputeOptimizer(Optimizer):
"y": np.random.randint(2, size=(32, 1)).astype('int64')}
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
print(input_x)
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......@@ -6395,8 +6401,8 @@ class RecomputeOptimizer(Optimizer):
paddle.enable_static()
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......@@ -6442,8 +6448,8 @@ class RecomputeOptimizer(Optimizer):
paddle.enable_static()
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......@@ -6936,8 +6942,8 @@ class RecomputeOptimizer(Optimizer):
paddle.enable_static()
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......@@ -7018,8 +7024,8 @@ class RecomputeOptimizer(Optimizer):
paddle.enable_static()
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......@@ -7116,7 +7122,7 @@ class LookaheadOptimizer:
x = fluid.layers.data(name='x', shape=[2], dtype='float32')
label = fluid.layers.data(name="label", shape=[1], dtype="int64")
y = fluid.layers.fc(input=[x], size=2, act="softmax")
y = paddle.static.nn.fc(x=[x], size=2, activation="softmax")
loss = paddle.nn.functional.cross_entropy(
input=y, label=label,
reduction='none', use_softmax=False
......@@ -7296,8 +7302,8 @@ class GradientMergeOptimizer:
"y": np.random.random(size=(batch_size, 1)).astype('int64')}
def mlp(input_x, input_y, hid_dim=128, label_dim=2):
fc_1 = fluid.layers.fc(input=input_x, size=hid_dim)
prediction = fluid.layers.fc(input=[fc_1], size=label_dim, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=hid_dim)
prediction = paddle.static.nn.fc(x=[fc_1], size=label_dim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y,
reduction='none', use_softmax=False
......
......@@ -1691,7 +1691,7 @@ class PyReader(DataLoaderBase):
def network(image, label):
# User-defined network, here is an example of softmax regression.
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
return paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......@@ -1750,7 +1750,7 @@ class PyReader(DataLoaderBase):
def network(image, label):
# User-defined network, here is an example of softmax regression.
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
return paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......@@ -1938,6 +1938,7 @@ class PyReader(DataLoaderBase):
Example:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
......@@ -1947,7 +1948,7 @@ class PyReader(DataLoaderBase):
def network(image, label):
# User-defined network, here is an example of softmax regression.
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
return paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......@@ -2014,7 +2015,7 @@ class PyReader(DataLoaderBase):
def network(image, label):
# User-defined network, here is an example of softmax regression.
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
return paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......@@ -2080,7 +2081,7 @@ class PyReader(DataLoaderBase):
def network(image, label):
# User-defined network, here is an example of softmax regression.
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
return paddle.nn.functional.cross_entropy(
input=predict, label=label,
reduction='none', use_softmax=False
......
......@@ -76,8 +76,8 @@ class L2DecayRegularizer(WeightDecayRegularizer):
with fluid.program_guard(main_prog, startup_prog):
data = fluid.layers.data(name='image', shape=[3, 28, 28], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=128, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
hidden = paddle.static.nn.fc(x=data, size=128, activation='relu')
prediction = paddle.static.nn.fc(x=hidden, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label,
reduction='none', use_softmax=False
......@@ -101,9 +101,9 @@ class L2DecayRegularizer(WeightDecayRegularizer):
# set L1 regularization in fluid.ParamAttr
w_param = fluid.ParamAttr(regularizer=l1)
hidden1 = fluid.layers.fc(x, 8, param_attr=w_param) # fc_0.w_0(L1), fc_0.b_0
hidden2 = fluid.layers.fc(hidden1, 16, param_attr=w_param) # fc_1.w_0(L1), fc_1.b_0
predict = fluid.layers.fc(hidden2, 32) # fc_3.w_0, fc_3.b_0
hidden1 = paddle.static.nn.fc(x, 8, weight_attr=w_param) # fc_0.w_0(L1), fc_0.b_0
hidden2 = paddle.static.nn.fc(hidden1, 16, weight_attr=w_param) # fc_1.w_0(L1), fc_1.b_0
predict = paddle.static.nn.fc(hidden2, 32) # fc_3.w_0, fc_3.b_0
avg_loss = paddle.mean(predict)
# set L2 regularization in optimizer
......@@ -195,8 +195,8 @@ class L1DecayRegularizer(WeightDecayRegularizer):
with fluid.program_guard(main_prog, startup_prog):
data = fluid.layers.data(name='image', shape=[3, 28, 28], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
hidden = fluid.layers.fc(input=data, size=128, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
hidden = paddle.static.nn.fc(x=data, size=128, activation='relu')
prediction = paddle.static.nn.fc(x=hidden, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label,
reduction='none', use_softmax=False
......@@ -219,9 +219,9 @@ class L1DecayRegularizer(WeightDecayRegularizer):
# set L1 regularization in fluid.ParamAttr
w_param = fluid.ParamAttr(regularizer=l1)
hidden1 = fluid.layers.fc(x, 8, param_attr=w_param) # fc_0.w_0(L1), fc_0.b_0
hidden2 = fluid.layers.fc(hidden1, 16, param_attr=w_param) # fc_1.w_0(L1), fc_1.b_0
predict = fluid.layers.fc(hidden2, 32) # fc_3.w_0, fc_3.b_0
hidden1 = paddle.static.nn.fc(x, 8, weight_attr=w_param) # fc_0.w_0(L1), fc_0.b_0
hidden2 = paddle.static.nn.fc(hidden1, 16, weight_attr=w_param) # fc_1.w_0(L1), fc_1.b_0
predict = paddle.static.nn.fc(hidden2, 32) # fc_3.w_0, fc_3.b_0
avg_loss = paddle.mean(predict)
# set L2 regularization in optimizer
......@@ -289,10 +289,11 @@ class L1DecayRegularizer(WeightDecayRegularizer):
# We short the class name, since users will use the regulaizer with the package
# name. The sample code:
#
# import paddle
# import paddle.fluid as fluid
#
# hidden = fluid.layers.fc(...,
# param_attr=fluid.regularizer.Xavier())
# hidden = paddle.static.nn.fc(...,
# weight_attr=fluid.regularizer.Xavier())
#
# It is no need to add a `Regularizer` as the class suffix
L1Decay = L1DecayRegularizer
......
......@@ -44,8 +44,8 @@ def convolution_net(
act="tanh",
pool_type="sqrt",
)
prediction = fluid.layers.fc(
input=[conv_3, conv_4], size=class_dim, act="softmax"
prediction = paddle.static.nn.fc(
x=[conv_3, conv_4], size=class_dim, activation="softmax"
)
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
......
......@@ -55,20 +55,20 @@ def train(use_cuda, save_dirname, is_local, use_bf16, pure_bf16):
if use_bf16:
if not pure_bf16:
with amp.bf16.bf16_guard():
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x=x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(
input=y_predict, label=y
)
avg_cost = paddle.mean(cost)
else:
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x=x, size=1, activation=None)
with amp.bf16.bf16_guard():
cost = paddle.nn.functional.square_error_cost(
input=y_predict, label=y
)
avg_cost = paddle.mean(cost)
else:
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x=x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......
......@@ -93,10 +93,10 @@ def vgg16_bn_drop(input):
conv5 = conv_block(conv4, 512, 3, [0.4, 0.4, 0])
drop = paddle.nn.functional.dropout(x=conv5, p=0.5)
fc1 = fluid.layers.fc(input=drop, size=4096, act=None)
fc1 = paddle.static.nn.fc(x=drop, size=4096)
bn = paddle.static.nn.batch_norm(input=fc1, act='relu')
drop2 = paddle.nn.functional.dropout(x=bn, p=0.5)
fc2 = fluid.layers.fc(input=drop2, size=4096, act=None)
fc2 = paddle.static.nn.fc(x=drop2, size=4096)
return fc2
......@@ -116,7 +116,7 @@ def train(net_type, use_cuda, save_dirname, is_local):
else:
raise ValueError("%s network is not supported" % net_type)
predict = fluid.layers.fc(input=net, size=classdim, act='softmax')
predict = paddle.static.nn.fc(x=net, size=classdim, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
......
......@@ -29,7 +29,7 @@ BATCH_SIZE = 64
def loss_net(hidden, label):
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
prediction = paddle.static.nn.fc(x=hidden, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=prediction, label=label, reduction='none', use_softmax=False
)
......@@ -39,8 +39,8 @@ def loss_net(hidden, label):
def mlp(img, label):
hidden = fluid.layers.fc(input=img, size=200, act='tanh')
hidden = fluid.layers.fc(input=hidden, size=200, act='tanh')
hidden = paddle.static.nn.fc(x=img, size=200, activation='tanh')
hidden = paddle.static.nn.fc(x=hidden, size=200, activation='tanh')
return loss_net(hidden, label)
......
......@@ -50,7 +50,7 @@ def get_usr_combined_features():
is_sparse=IS_SPARSE,
)
usr_fc = layers.fc(input=usr_emb, size=32)
usr_fc = paddle.static.nn.fc(x=usr_emb, size=32)
USR_GENDER_DICT_SIZE = 2
......@@ -63,7 +63,7 @@ def get_usr_combined_features():
is_sparse=IS_SPARSE,
)
usr_gender_fc = layers.fc(input=usr_gender_emb, size=16)
usr_gender_fc = paddle.static.nn.fc(x=usr_gender_emb, size=16)
USR_AGE_DICT_SIZE = len(paddle.dataset.movielens.age_table)
usr_age_id = layers.data(name='age_id', shape=[1], dtype="int64")
......@@ -75,7 +75,7 @@ def get_usr_combined_features():
param_attr='age_table',
)
usr_age_fc = layers.fc(input=usr_age_emb, size=16)
usr_age_fc = paddle.static.nn.fc(x=usr_age_emb, size=16)
USR_JOB_DICT_SIZE = paddle.dataset.movielens.max_job_id() + 1
usr_job_id = layers.data(name='job_id', shape=[1], dtype="int64")
......@@ -87,13 +87,15 @@ def get_usr_combined_features():
is_sparse=IS_SPARSE,
)
usr_job_fc = layers.fc(input=usr_job_emb, size=16)
usr_job_fc = paddle.static.nn.fc(x=usr_job_emb, size=16)
concat_embed = layers.concat(
input=[usr_fc, usr_gender_fc, usr_age_fc, usr_job_fc], axis=1
)
usr_combined_features = layers.fc(input=concat_embed, size=200, act="tanh")
usr_combined_features = paddle.static.nn.fc(
x=concat_embed, size=200, activation="tanh"
)
return usr_combined_features
......@@ -112,7 +114,7 @@ def get_mov_combined_features():
is_sparse=IS_SPARSE,
)
mov_fc = layers.fc(input=mov_emb, size=32)
mov_fc = paddle.static.nn.fc(x=mov_emb, size=32)
CATEGORY_DICT_SIZE = len(paddle.dataset.movielens.movie_categories())
......@@ -151,7 +153,9 @@ def get_mov_combined_features():
)
# FIXME(dzh) : need tanh operator
mov_combined_features = layers.fc(input=concat_embed, size=200, act="tanh")
mov_combined_features = paddle.static.nn.fc(
x=concat_embed, size=200, activation="tanh"
)
return mov_combined_features
......
......@@ -90,11 +90,11 @@ def train(
concat_embed = fluid.layers.concat(
input=[embed_first, embed_second, embed_third, embed_forth], axis=1
)
hidden1 = fluid.layers.fc(
input=concat_embed, size=HIDDEN_SIZE, act='sigmoid'
hidden1 = paddle.static.nn.fc(
x=concat_embed, size=HIDDEN_SIZE, activation='sigmoid'
)
predict_word = fluid.layers.fc(
input=hidden1, size=dict_size, act='softmax'
predict_word = paddle.static.nn.fc(
x=hidden1, size=dict_size, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=predict_word,
......
......@@ -25,9 +25,9 @@ prog = fluid.framework.Program()
with fluid.program_guard(main_program=prog):
image = fluid.layers.data(name='x', shape=[784], dtype='float32')
hidden1 = fluid.layers.fc(input=image, size=128, act='relu')
hidden2 = fluid.layers.fc(input=hidden1, size=64, act='relu')
predict = fluid.layers.fc(input=hidden2, size=10, act='softmax')
hidden1 = paddle.static.nn.fc(x=image, size=128, activation='relu')
hidden2 = paddle.static.nn.fc(x=hidden1, size=64, activation='relu')
predict = paddle.static.nn.fc(x=hidden2, size=10, activation='softmax')
label = fluid.layers.data(name='y', shape=[1], dtype='int64')
......
......@@ -38,8 +38,10 @@ class TestASPHelperPruningBase(unittest.TestCase):
hidden = paddle.static.nn.conv2d(
input=img, num_filters=4, filter_size=3, padding=2, act="relu"
)
hidden = fluid.layers.fc(input=hidden, size=32, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
hidden = paddle.static.nn.fc(x=hidden, size=32, activation='relu')
prediction = paddle.static.nn.fc(
x=hidden, size=10, activation='softmax'
)
return img, label, prediction
with fluid.program_guard(self.main_program, self.startup_program):
......
......@@ -205,14 +205,16 @@ class TestASPStaticCustomerizedPruneFunc(unittest.TestCase):
hidden = paddle.static.nn.conv2d(
input=img, num_filters=4, filter_size=3, padding=2, act="relu"
)
hidden = fluid.layers.fc(
input=hidden, size=32, act='relu', name=self.customer_prefix
hidden = paddle.static.nn.fc(
x=hidden, size=32, activation='relu', name=self.customer_prefix
)
hidden = fluid.layers.fc(
input=hidden, size=32, act='relu', name=self.customer_prefix
hidden = paddle.static.nn.fc(
x=hidden, size=32, activation='relu', name=self.customer_prefix
)
hidden = paddle.static.nn.fc(x=hidden, size=32, activation='relu')
prediction = paddle.static.nn.fc(
x=hidden, size=10, activation='softmax'
)
hidden = fluid.layers.fc(input=hidden, size=32, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
return img, label, prediction
with fluid.program_guard(self.main_program, self.startup_program):
......
......@@ -38,8 +38,10 @@ class TestASPStaticOptimize(unittest.TestCase):
hidden = paddle.static.nn.conv2d(
input=img, num_filters=4, filter_size=3, padding=2, act="relu"
)
hidden = fluid.layers.fc(input=hidden, size=32, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
hidden = paddle.static.nn.fc(x=hidden, size=32, activation='relu')
prediction = paddle.static.nn.fc(
x=hidden, size=10, activation='softmax'
)
return img, label, prediction
with fluid.program_guard(self.main_program, self.startup_program):
......
......@@ -38,9 +38,13 @@ class TestASPStaticPruningBase(unittest.TestCase):
hidden = paddle.static.nn.conv2d(
input=img, num_filters=2, filter_size=3, padding=2, act="relu"
)
hidden = fluid.layers.fc(input=hidden, size=32, act='softmax')
hidden = fluid.layers.fc(input=hidden, size=3, act='softmax')
prediction = fluid.layers.fc(input=hidden, size=3, act='softmax')
hidden = paddle.static.nn.fc(
x=hidden, size=32, activation='softmax'
)
hidden = paddle.static.nn.fc(x=hidden, size=3, activation='softmax')
prediction = paddle.static.nn.fc(
x=hidden, size=3, activation='softmax'
)
return img, label, prediction
with fluid.program_guard(self.main_program, self.startup_program):
......
......@@ -135,8 +135,10 @@ class TestASPStaticOptimize(unittest.TestCase):
hidden = paddle.static.nn.conv2d(
input=img, num_filters=4, filter_size=3, padding=2, act="relu"
)
hidden = fluid.layers.fc(input=hidden, size=32, act='relu')
prediction = fluid.layers.fc(input=hidden, size=10, act='softmax')
hidden = paddle.static.nn.fc(x=hidden, size=32, activation='relu')
prediction = paddle.static.nn.fc(
x=hidden, size=10, activation='softmax'
)
return img, label, prediction
with fluid.program_guard(self.main_program, self.startup_program):
......
......@@ -55,11 +55,13 @@ class TestFleetWithASPSharding(unittest.TestCase):
)
input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64')
fc_1 = fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = fluid.layers.fc(input=fc_1, size=64, act='tanh')
fc_3 = fluid.layers.fc(input=fc_2, size=64, act='tanh')
fc_4 = fluid.layers.fc(input=fc_3, size=64, act='tanh')
prediction = fluid.layers.fc(input=fc_4, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
fc_3 = paddle.static.nn.fc(x=fc_2, size=64, activation='tanh')
fc_4 = paddle.static.nn.fc(x=fc_3, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=fc_4, size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
label=input_y,
......
......@@ -47,8 +47,10 @@ class TestFleetWithASPStatic(unittest.TestCase):
)
input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64')
fc_1 = fluid.layers.fc(input=input_x, size=64, act='tanh')
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=fc_1, size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
label=input_y,
......@@ -121,8 +123,10 @@ class TestFleetWithASPAMPStatic(unittest.TestCase):
)
input_y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64')
fc_1 = fluid.layers.fc(input=input_x, size=64, act='tanh')
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=fc_1, size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
label=input_y,
......
......@@ -68,7 +68,7 @@ class AutoCheckpointBase(unittest.TestCase):
image = fluid.data(name='image', shape=[-1, 4, 4], dtype='float32')
label = fluid.data(name='label', shape=[-1, 1], dtype='int64')
fc_tmp = fluid.layers.fc(image, size=CLASS_NUM)
fc_tmp = paddle.static.nn.fc(image, size=CLASS_NUM)
cross_entropy = paddle.nn.functional.softmax_with_cross_entropy(
fc_tmp, label
)
......
......@@ -60,9 +60,9 @@ def net():
hidden = x
for i in range(2):
hidden = fluid.layers.fc(input=hidden, size=400, act="sigmoid")
hidden = paddle.static.nn.fc(x=hidden, size=400, activation="sigmoid")
hidden = fluid.layers.fc(input=hidden, size=3, act=None)
hidden = paddle.static.nn.fc(x=hidden, size=3)
cost, y_predict = paddle.nn.functional.softmax_with_cross_entropy(
hidden, y, return_softmax=True
)
......
......@@ -60,20 +60,20 @@ def cnn_model(data):
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
with fluid.device_guard("gpu:1"):
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
# To cover @RENAMED@GRADIENT
predict2 = fluid.layers.fc(
input=conv_pool_1,
predict2 = paddle.static.nn.fc(
x=conv_pool_1,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -60,20 +60,20 @@ def cnn_model(data):
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
with fluid.device_guard("gpu:1"):
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
# To cover @RENAMED@GRADIENT
predict2 = fluid.layers.fc(
input=conv_pool_1,
predict2 = paddle.static.nn.fc(
x=conv_pool_1,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -59,11 +59,11 @@ def cnn_model(data):
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -62,8 +62,8 @@ def create_model(data, rank):
)
else:
weight_attr, bias_attr = get_param_attr(np_weight, np_bias)
result = fluid.layers.fc(
data, size=OUT_SIZE, param_attr=weight_attr, bias_attr=bias_attr
result = paddle.static.nn.fc(
data, size=OUT_SIZE, weight_attr=weight_attr, bias_attr=bias_attr
)
predict = paddle.sum(result)
......
......@@ -61,10 +61,10 @@ def create_model(data, rank):
)
else:
weight_attr, bias_attr = get_param_attr(np_weight, np_bias)
result = fluid.layers.fc(
result = paddle.static.nn.fc(
data,
size=OUT_SIZE,
param_attr=paddle.ParamAttr(
weight_attr=paddle.ParamAttr(
initializer=fluid.initializer.NumpyArrayInitializer(np_weight)
),
bias_attr=bias_attr,
......
......@@ -51,10 +51,10 @@ def create_model(data, rank):
bias_attr=False,
)
else:
result = fluid.layers.fc(
result = paddle.static.nn.fc(
data,
size=OUT_SIZE,
param_attr=paddle.ParamAttr(
weight_attr=paddle.ParamAttr(
initializer=fluid.initializer.NumpyArrayInitializer(np_weight)
),
bias_attr=False,
......
......@@ -30,7 +30,7 @@ paddle.enable_static()
class TestCommunicatorHalfAsyncEnd2End(unittest.TestCase):
def net(self):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
......
......@@ -272,7 +272,7 @@ class TestDebugInfo(unittest.TestCase):
def test_debug_info(self):
x = fluid.layers.data(name='x', shape=[1], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost = paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......
......@@ -40,7 +40,7 @@ class FleetTest(unittest.TestCase):
feeder = fluid.DataFeeder(
feed_list=[image, label], place=fluid.CPUPlace()
)
predict = fluid.layers.fc(input=image, size=10, act='softmax')
predict = paddle.static.nn.fc(x=image, size=10, activation='softmax')
loss = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
)
......
......@@ -37,10 +37,10 @@ class TestFleetFP16CompressOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -67,10 +67,10 @@ class TestFleetGraphExecutionMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -133,10 +133,10 @@ class TestFleetGraphExecutionMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -211,10 +211,10 @@ class TestFleetGraphExecutionMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -276,10 +276,10 @@ class TestFleetGraphExecutionMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -54,10 +54,10 @@ class TestFleetGraphExecutionMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -40,12 +40,12 @@ class TestFleetLambMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(
input=input_x, size=64, act='tanh'
fc_1 = paddle.static.nn.fc(
x=input_x, size=64, activation='tanh'
)
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=256, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_2 = paddle.static.nn.fc(x=fc_1, size=256, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -122,9 +122,9 @@ class TestFleetLambMetaOptimizer(unittest.TestCase):
)
input_y = paddle.fluid.layers.data(name="y", shape=[1], dtype='int64')
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(input=[fc_2], size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y, reduction='none', use_softmax=False
)
......
......@@ -40,12 +40,12 @@ class TestFleetLarsMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(
input=input_x, size=64, act='tanh'
fc_1 = paddle.static.nn.fc(
x=input_x, size=64, activation='tanh'
)
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=256, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_2 = paddle.static.nn.fc(x=fc_1, size=256, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -127,9 +127,9 @@ class TestFleetLarsMetaOptimizer(unittest.TestCase):
)
input_y = paddle.fluid.layers.data(name="y", shape=[1], dtype='int64')
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(input=[fc_2], size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y, reduction='none', use_softmax=False
)
......
......@@ -36,12 +36,12 @@ class TestFleetMetaOptimizerBase(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(
input=input_x, size=64, act='tanh'
fc_1 = paddle.static.nn.fc(
x=input_x, size=64, activation='tanh'
)
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=256, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_2 = paddle.static.nn.fc(x=fc_1, size=256, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -45,16 +45,16 @@ class TestFleetMetaOptimizer(unittest.TestCase):
with static.device_guard("gpu:all"):
input_z = input_z * 1.0
input_z.stop_gradient = True
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_1 = fc_1 * input_z
with static.device_guard("gpu:1"):
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
# for pipeline check_pipeline_persist_var coverage
fc_2.persistable = True
fc_2 = fc_2 * input_z
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -40,17 +40,17 @@ class TestFleetMetaOptimizer(unittest.TestCase):
input_y = paddle.fluid.layers.data(
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
fc_3 = paddle.fluid.layers.fc(input=fc_2, size=64, act='tanh')
fc_4 = paddle.fluid.layers.fc(input=fc_3, size=64, act='tanh')
fc_5 = paddle.fluid.layers.fc(input=fc_4, size=64, act='tanh')
fc_6 = paddle.fluid.layers.fc(input=fc_5, size=64, act='tanh')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
fc_3 = paddle.static.nn.fc(x=fc_2, size=64, activation='tanh')
fc_4 = paddle.static.nn.fc(x=fc_3, size=64, activation='tanh')
fc_5 = paddle.static.nn.fc(x=fc_4, size=64, activation='tanh')
fc_6 = paddle.static.nn.fc(x=fc_5, size=64, activation='tanh')
with paddle.fluid.device_guard("gpu:1"):
fc_7 = paddle.fluid.layers.fc(input=fc_6, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_7], size=2, act='softmax'
fc_7 = paddle.static.nn.fc(x=fc_6, size=64, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_7], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -37,10 +37,10 @@ class TestFleetMetaOptimizer(unittest.TestCase):
name="x", shape=[32], dtype='float32'
)
input_y = paddle.fluid.layers.data(name="y", shape=[1], dtype='int64')
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
prediction = paddle.fluid.layers.fc(input=[fc_2], size=2, act='softmax')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
prediction = paddle.static.nn.fc(x=[fc_2], size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(
input=prediction, label=input_y, reduction='none', use_softmax=False
)
......
......@@ -444,7 +444,7 @@ class TestGlooWithCloudRoleMaker(unittest.TestCase):
def net():
x = paddle.fluid.layers.data(name='x', shape=[13], dtype='float32')
y_predict = paddle.fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
y = paddle.fluid.layers.data(name='y', shape=[1], dtype='float32')
cost = paddle.nn.functional.square_error_cost(
input=y_predict, label=y
......
......@@ -58,11 +58,11 @@ def cnn_model(data):
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -72,11 +72,11 @@ class TestDistCTR2x2(TestDistRunnerBase):
)
dnn_out = dnn_pool
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -98,7 +98,9 @@ class TestDistCTR2x2(TestDistRunnerBase):
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(
x=merge_layer, size=2, activation='softmax'
)
acc = paddle.static.accuracy(input=predict, label=label)
auc_var, batch_auc_var, auc_states = paddle.static.auc(
input=predict, label=label
......
......@@ -120,11 +120,11 @@ class TestDistCTR2x2(FleetDistRunnerBase):
)
dnn_out = dnn_pool
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -147,7 +147,9 @@ class TestDistCTR2x2(FleetDistRunnerBase):
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(
x=merge_layer, size=2, activation='softmax'
)
acc = paddle.static.accuracy(input=predict, label=label)
auc_var, batch_auc_var, auc_states = paddle.static.auc(
......
......@@ -107,11 +107,11 @@ class TestHeterPipelinePsCTR2x2(FleetDistHeterRunnerBase):
with fluid.device_guard("gpu"):
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -121,7 +121,9 @@ class TestHeterPipelinePsCTR2x2(FleetDistHeterRunnerBase):
with fluid.device_guard("cpu"):
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
label = fluid.layers.cast(label, dtype="int64")
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(
x=merge_layer, size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
......
......@@ -60,11 +60,11 @@ def cnn_model(data):
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -60,11 +60,11 @@ def cnn_model(data):
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -133,10 +133,10 @@ def train_network(
q_sum = fluid.layers.sequence_pool(input=q_emb, pool_type='sum')
q_ss = paddle.nn.functional.softsign(q_sum)
# fc layer after conv
q_fc = fluid.layers.fc(
input=q_ss,
q_fc = paddle.static.nn.fc(
x=q_ss,
size=hid_dim,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01),
name="__q_fc__",
learning_rate=base_lr,
......@@ -160,10 +160,10 @@ def train_network(
pt_sum = fluid.layers.sequence_pool(input=pt_emb, pool_type='sum')
pt_ss = paddle.nn.functional.softsign(pt_sum)
# fc layer
pt_fc = fluid.layers.fc(
input=pt_ss,
pt_fc = paddle.static.nn.fc(
x=pt_ss,
size=hid_dim,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01), name="__fc__"
),
bias_attr=fluid.ParamAttr(name="__fc_b__"),
......@@ -184,10 +184,10 @@ def train_network(
nt_sum = fluid.layers.sequence_pool(input=nt_emb, pool_type='sum')
nt_ss = paddle.nn.functional.softsign(nt_sum)
# fc layer
nt_fc = fluid.layers.fc(
input=nt_ss,
nt_fc = paddle.static.nn.fc(
x=nt_ss,
size=hid_dim,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01), name="__fc__"
),
bias_attr=fluid.ParamAttr(name="__fc_b__"),
......
......@@ -111,11 +111,11 @@ class TestDistCTR2x2(FleetDistRunnerBase):
)
dnn_out = dnn_pool
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -136,7 +136,9 @@ class TestDistCTR2x2(FleetDistRunnerBase):
lr_pool = fluid.layers.sequence_pool(input=lr_embbding, pool_type="sum")
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(
x=merge_layer, size=2, activation='softmax'
)
acc = paddle.static.accuracy(input=predict, label=label)
auc_var, _, _ = paddle.static.auc(input=predict, label=label)
......
......@@ -59,11 +59,11 @@ def cnn_model(data):
param_shape = [reduce(lambda a, b: a * b, input_shape[1:], 1)] + [SIZE]
scale = (2.0 / (param_shape[0] ** 2 * SIZE)) ** 0.5
predict = fluid.layers.fc(
input=conv_pool_2,
predict = paddle.static.nn.fc(
x=conv_pool_2,
size=SIZE,
act="softmax",
param_attr=fluid.param_attr.ParamAttr(
activation="softmax",
weight_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -116,11 +116,11 @@ class SE_ResNeXt:
drop = paddle.nn.functional.dropout(x=pool, p=0.2)
stdv = 1.0 / math.sqrt(drop.shape[1] * 1.0)
out = fluid.layers.fc(
input=drop,
out = paddle.static.nn.fc(
x=drop,
size=class_dim,
act='softmax',
param_attr=fluid.ParamAttr(
activation='softmax',
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.05)
),
)
......@@ -183,22 +183,22 @@ class SE_ResNeXt:
def squeeze_excitation(self, input, num_channels, reduction_ratio):
pool = paddle.nn.functional.adaptive_avg_pool2d(x=input, output_size=1)
stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0)
squeeze = fluid.layers.fc(
input=pool,
squeeze = paddle.static.nn.fc(
x=pool,
size=num_channels // reduction_ratio,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.05)
),
act='relu',
activation='relu',
)
stdv = 1.0 / math.sqrt(squeeze.shape[1] * 1.0)
excitation = fluid.layers.fc(
input=squeeze,
excitation = paddle.static.nn.fc(
x=squeeze,
size=num_channels,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.05)
),
act='sigmoid',
activation='sigmoid',
)
scale = paddle.tensor.math._multiply_with_axis(
x=input, y=excitation, axis=0
......
......@@ -45,10 +45,10 @@ def runtime_main():
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=256, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=256, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -74,19 +74,19 @@ def conv_net(
),
)
fc_0 = fluid.layers.fc(
input=[conv_3],
fc_0 = paddle.static.nn.fc(
x=[conv_3],
size=fc0_dim,
param_attr=fluid.ParamAttr(
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
prediction = fluid.layers.fc(
input=[fc_0],
prediction = paddle.static.nn.fc(
x=[fc_0],
size=class_dim,
act="softmax",
param_attr=fluid.ParamAttr(
activation="softmax",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
)
......
......@@ -289,7 +289,7 @@ class LearningRateScheduler:
self.warmup_steps = warmup_steps
self.d_model = d_model
self.static_lr = learning_rate
self.learning_rate = paddle.static.create_global_var(
self.learning_rate = layers.create_global_var(
name=name,
shape=[1],
value=float(learning_rate),
......@@ -1107,25 +1107,25 @@ def multi_head_attention(
"""
Add linear projection to queries, keys, and values.
"""
q = layers.fc(
input=queries,
q = paddle.static.nn.fc(
x=queries,
size=d_key * n_head,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
k = layers.fc(
input=keys,
k = paddle.static.nn.fc(
x=keys,
size=d_key * n_head,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
v = layers.fc(
input=values,
v = paddle.static.nn.fc(
x=values,
size=d_value * n_head,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
return q, k, v
......@@ -1174,16 +1174,18 @@ def multi_head_attention(
Scaled Dot-Product Attention
"""
scaled_q = paddle.scale(x=q, scale=d_model**-0.5)
product = paddle.matmul(x=scaled_q, y=k, transpose_y=True)
product = layers.matmul(x=scaled_q, y=k, transpose_y=True)
if attn_bias:
product += attn_bias
weights = paddle.nn.functional.softmax(product)
if dropout_rate:
weights = paddle.nn.functional.dropout(
weights = layers.dropout(
weights,
p=dropout_rate,
dropout_prob=dropout_rate,
seed=ModelHyperParams.dropout_seed,
is_test=False,
)
out = paddle.matmul(weights, v)
out = layers.matmul(weights, v)
return out
q, k, v = __compute_qkv(queries, keys, values, n_head, d_key, d_value)
......@@ -1203,11 +1205,11 @@ def multi_head_attention(
out = __combine_heads(ctx_multiheads)
# Project back to the model size.
proj_out = layers.fc(
input=out,
proj_out = paddle.static.nn.fc(
x=out,
size=d_model,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
return proj_out
......@@ -1219,19 +1221,19 @@ def positionwise_feed_forward(x, d_inner_hid, d_hid):
This module consists of two linear transformations with a ReLU activation
in between, which is applied to each position separately and identically.
"""
hidden = layers.fc(
input=x,
hidden = paddle.static.nn.fc(
x=x,
size=d_inner_hid,
num_flatten_dims=2,
act="relu",
param_attr=const_para_attr,
activation="relu",
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
out = layers.fc(
input=hidden,
out = paddle.static.nn.fc(
x=hidden,
size=d_hid,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
return out
......@@ -1248,7 +1250,7 @@ def pre_post_process_layer(prev_out, out, process_cmd, dropout_rate=0.0):
if cmd == "a": # add residual connection
out = out + prev_out if prev_out else out
elif cmd == "n": # add layer normalization
out = paddle.static.nn.layer_norm(
out = layers.layer_norm(
out,
begin_norm_axis=len(out.shape) - 1,
param_attr=fluid.initializer.Constant(1.0),
......@@ -1256,9 +1258,11 @@ def pre_post_process_layer(prev_out, out, process_cmd, dropout_rate=0.0):
)
elif cmd == "d": # add dropout
if dropout_rate:
out = paddle.nn.functional.dropout(
out = layers.dropout(
out,
p=dropout_rate,
dropout_prob=dropout_rate,
seed=ModelHyperParams.dropout_seed,
is_test=False,
)
return out
......@@ -1314,9 +1318,11 @@ def prepare_encoder(
src_pos_enc.stop_gradient = True
enc_input = src_word_emb + src_pos_enc
return (
paddle.nn.functional.dropout(
layers.dropout(
enc_input,
p=dropout_rate,
dropout_prob=dropout_rate,
seed=ModelHyperParams.dropout_seed,
is_test=False,
)
if dropout_rate
else enc_input
......@@ -1575,7 +1581,7 @@ def transformer(
label, weights = make_all_inputs(label_data_input_fields)
if label_smooth_eps:
label = F.label_smooth(
label=paddle.nn.functional.one_hot(label, trg_vocab_size),
label=layers.one_hot(input=label, depth=trg_vocab_size),
epsilon=label_smooth_eps,
)
......@@ -1695,17 +1701,17 @@ def wrap_decoder(
)
# Return logits for training and probs for inference.
if weight_sharing:
predict = paddle.matmul(
predict = layers.matmul(
x=dec_output,
y=fluid.framework._get_var(word_emb_param_names[0]),
transpose_y=True,
)
else:
predict = layers.fc(
input=dec_output,
predict = paddle.static.nn.fc(
x=dec_output,
size=trg_vocab_size,
num_flatten_dims=2,
param_attr=const_para_attr,
weight_attr=const_para_attr,
bias_attr=const_bias_attr,
)
if dec_inputs is None:
......@@ -1713,6 +1719,160 @@ def wrap_decoder(
return predict
def fast_decode(
src_vocab_size,
trg_vocab_size,
max_in_len,
n_layer,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
dropout_rate,
weight_sharing,
beam_size,
max_out_len,
eos_idx,
):
"""
Use beam search to decode. Caches will be used to store states of history
steps which can make the decoding faster.
"""
enc_output = wrap_encoder(
src_vocab_size,
max_in_len,
n_layer,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
dropout_rate,
weight_sharing,
)
start_tokens, init_scores, trg_src_attn_bias = make_all_inputs(
fast_decoder_data_input_fields
)
def beam_search():
max_len = layers.fill_constant(
shape=[1], dtype=start_tokens.dtype, value=max_out_len
)
step_idx = layers.fill_constant(
shape=[1], dtype=start_tokens.dtype, value=0
)
cond = paddle.less_than(x=step_idx, y=max_len)
while_op = layers.While(cond)
# array states will be stored for each step.
ids = layers.array_write(
paddle.reshape(start_tokens, (-1, 1)), step_idx
)
scores = layers.array_write(init_scores, step_idx)
# cell states will be overwrited at each step.
# caches contains states of history steps to reduce redundant
# computation in decoder.
caches = [
{
"k": layers.fill_constant_batch_size_like(
input=start_tokens,
shape=[-1, 0, d_model],
dtype=enc_output.dtype,
value=0,
),
"v": layers.fill_constant_batch_size_like(
input=start_tokens,
shape=[-1, 0, d_model],
dtype=enc_output.dtype,
value=0,
),
}
for i in range(n_layer)
]
with while_op.block():
pre_ids = layers.array_read(array=ids, i=step_idx)
pre_ids = paddle.reshape(pre_ids, (-1, 1, 1))
pre_scores = layers.array_read(array=scores, i=step_idx)
# sequence_expand can gather sequences according to lod thus can be
# used in beam search to sift states corresponding to selected ids.
pre_src_attn_bias = layers.sequence_expand(
x=trg_src_attn_bias, y=pre_scores
)
pre_enc_output = layers.sequence_expand(x=enc_output, y=pre_scores)
pre_caches = [
{
"k": layers.sequence_expand(x=cache["k"], y=pre_scores),
"v": layers.sequence_expand(x=cache["v"], y=pre_scores),
}
for cache in caches
]
pre_pos = layers.elementwise_mul(
x=layers.fill_constant_batch_size_like(
input=pre_enc_output, # can't use pre_ids here since it has lod
value=1,
shape=[-1, 1, 1],
dtype=pre_ids.dtype,
),
y=layers.increment(x=step_idx, value=1.0, in_place=False),
axis=0,
)
logits = wrap_decoder(
trg_vocab_size,
max_in_len,
n_layer,
n_head,
d_key,
d_value,
d_model,
d_inner_hid,
dropout_rate,
weight_sharing,
dec_inputs=(pre_ids, pre_pos, None, pre_src_attn_bias),
enc_output=pre_enc_output,
caches=pre_caches,
)
logits = paddle.reshape(logits, (-1, trg_vocab_size))
topk_scores, topk_indices = paddle.topk(
x=paddle.nn.functional.softmax(logits), k=beam_size
)
accu_scores = layers.elementwise_add(
x=paddle.log(topk_scores),
y=paddle.reshape(pre_scores, shape=[-1]),
axis=0,
)
# beam_search op uses lod to distinguish branches.
topk_indices = layers.lod_reset(topk_indices, pre_ids)
selected_ids, selected_scores = layers.beam_search(
pre_ids=pre_ids,
pre_scores=pre_scores,
ids=topk_indices,
scores=accu_scores,
beam_size=beam_size,
end_id=eos_idx,
)
layers.increment(x=step_idx, value=1.0, in_place=True)
# update states
layers.array_write(selected_ids, i=step_idx, array=ids)
layers.array_write(selected_scores, i=step_idx, array=scores)
layers.assign(pre_src_attn_bias, trg_src_attn_bias)
layers.assign(pre_enc_output, enc_output)
for i in range(n_layer):
layers.assign(pre_caches[i]["k"], caches[i]["k"])
layers.assign(pre_caches[i]["v"], caches[i]["v"])
length_cond = paddle.less_than(x=step_idx, y=max_len)
finish_cond = paddle.logical_not(layers.is_empty(x=selected_ids))
paddle.logical_and(x=length_cond, y=finish_cond, out=cond)
finished_ids, finished_scores = layers.beam_search_decode(
ids, scores, beam_size=beam_size, end_id=eos_idx
)
return finished_ids, finished_scores
finished_ids, finished_scores = beam_search()
return finished_ids, finished_scores
def get_model(is_dist, is_async):
sum_cost, avg_cost, predict, token_num = transformer(
ModelHyperParams.src_vocab_size,
......
......@@ -79,19 +79,19 @@ class TestDistWord2vec2x2(TestDistRunnerBase):
input=[embed_first, embed_second, embed_third, embed_forth],
axis=1,
)
hidden1 = fluid.layers.fc(
input=concat_embed,
hidden1 = paddle.static.nn.fc(
x=concat_embed,
size=HIDDEN_SIZE,
act='sigmoid',
param_attr=fluid.ParamAttr(
activation='sigmoid',
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.1)
),
)
predict_word = fluid.layers.fc(
input=hidden1,
predict_word = paddle.static.nn.fc(
x=hidden1,
size=dict_size,
act='softmax',
param_attr=fluid.ParamAttr(
activation='softmax',
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.1)
),
)
......
......@@ -97,11 +97,11 @@ def net(batch_size=4, lr=0.01):
with fluid.device_guard("gpu"):
for i, dim in enumerate(dnn_layer_dims[1:]):
fc = fluid.layers.fc(
input=dnn_out,
fc = paddle.static.nn.fc(
x=dnn_out,
size=dim,
act="relu",
param_attr=fluid.ParamAttr(
activation="relu",
weight_attr=fluid.ParamAttr(
initializer=fluid.initializer.Constant(value=0.01)
),
name='dnn-fc-%d' % i,
......@@ -110,7 +110,9 @@ def net(batch_size=4, lr=0.01):
merge_layer = fluid.layers.concat(input=[dnn_out, lr_pool], axis=1)
label = fluid.layers.cast(label, dtype="int64")
predict = fluid.layers.fc(input=merge_layer, size=2, act='softmax')
predict = paddle.static.nn.fc(
x=merge_layer, size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=predict, label=label, reduction='none', use_softmax=False
......
......@@ -62,12 +62,12 @@ class TestFleetMetaOptimizer(unittest.TestCase):
name="y", shape=[1], dtype='int64'
)
fc_1 = paddle.fluid.layers.fc(
input=input_x, size=64, act='tanh'
fc_1 = paddle.static.nn.fc(
x=input_x, size=64, activation='tanh'
)
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=256, act='tanh')
prediction = paddle.fluid.layers.fc(
input=[fc_2], size=2, act='softmax'
fc_2 = paddle.static.nn.fc(x=fc_1, size=256, activation='tanh')
prediction = paddle.static.nn.fc(
x=[fc_2], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......@@ -82,9 +82,9 @@ class TestFleetMetaOptimizer(unittest.TestCase):
def pp_net(self, main_prog, startup_prog, pp_degree=2):
def fc_block(input_x):
fc_1 = paddle.fluid.layers.fc(input=input_x, size=64, act='tanh')
fc_2 = paddle.fluid.layers.fc(input=fc_1, size=64, act='tanh')
fc_3 = paddle.fluid.layers.fc(input=fc_2, size=64, act='tanh')
fc_1 = paddle.static.nn.fc(x=input_x, size=64, activation='tanh')
fc_2 = paddle.static.nn.fc(x=fc_1, size=64, activation='tanh')
fc_3 = paddle.static.nn.fc(x=fc_2, size=64, activation='tanh')
return fc_3
with fluid.program_guard(main_prog, startup_prog):
......@@ -104,8 +104,8 @@ class TestFleetMetaOptimizer(unittest.TestCase):
input_x = fc_block(input_x)
with fluid.device_guard("gpu:" + str(pp_degree - 1)):
prediction = paddle.fluid.layers.fc(
input=[input_x], size=2, act='softmax'
prediction = paddle.static.nn.fc(
x=[input_x], size=2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(
input=prediction,
......
......@@ -63,8 +63,8 @@ class TestWeightSharing(IPUOpTest):
is_sparse=False,
)
with paddle.static.ipu_shard_guard(index=1, stage=1):
z = paddle.fluid.layers.fc(
input=y, size=768, param_attr=paddle.fluid.ParamAttr(name="fc")
z = paddle.static.nn.fc(
x=y, size=768, weight_attr=paddle.fluid.ParamAttr(name="fc")
)
with paddle.static.ipu_shard_guard(index=0, stage=2):
out = paddle.matmul(
......
......@@ -33,7 +33,7 @@ class TestMKLDNNCpuBfloat16Pass(InferencePassTest):
out = paddle.transpose(x, perm=[0, 1, 2, 3])
out = paddle.reshape(out, [0, 0, 0, 0])
out = fluid.layers.fc(out, size=1)
out = paddle.static.nn.fc(out, size=1)
self.feeds = {
"x": np.random.random([self.bs] + self.shape_x).astype(
......
......@@ -83,7 +83,7 @@ class TestMKLDNNMatmulOpNotFusedWrongTransposeAxis(TestMKLDNNMatmulFuseOp):
out = paddle.matmul(x, y)
out = paddle.transpose(out, perm=[0, 1, 2, 3])
out = paddle.reshape(out, [0, 0, 0, 0])
out = fluid.layers.fc(out, size=1)
out = paddle.static.nn.fc(out, size=1)
return out
......
......@@ -29,8 +29,8 @@ class FCFusePassTRTTest(InferencePassTest):
data = fluid.data(
name="data", shape=[32, 128, 2, 2], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=128, num_flatten_dims=1, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=128, num_flatten_dims=1, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -59,8 +59,8 @@ class FCFusePassTRTStaticDims4Cols1Test(InferencePassTest):
data = fluid.data(
name="data", shape=[32, 128, 32, 8], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=1, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=1, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -87,8 +87,8 @@ class FCFusePassTRTStaticDims4Cols2Test(InferencePassTest):
data = fluid.data(
name="data", shape=[3, 24, 16, 16], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=32, num_flatten_dims=2, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=32, num_flatten_dims=2, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -113,8 +113,8 @@ class FCFusePassTRTDynamicDims2Test(InferencePassTest):
def setUp(self):
with fluid.program_guard(self.main_program, self.startup_program):
data = fluid.data(name="data", shape=[32, 128], dtype="float32")
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=1, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=1, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -145,8 +145,8 @@ class FCFusePassTRTDynamicDims3Cols1Test(InferencePassTest):
def setUp(self):
with fluid.program_guard(self.main_program, self.startup_program):
data = fluid.data(name="data", shape=[32, 128, 32], dtype="float32")
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=1, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=1, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -177,8 +177,8 @@ class FCFusePassTRTDynamicDims3Cols2Test(InferencePassTest):
def setUp(self):
with fluid.program_guard(self.main_program, self.startup_program):
data = fluid.data(name="data", shape=[32, 128, 32], dtype="float32")
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=2, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=2, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -211,8 +211,8 @@ class FCFusePassTRTDynamicDims4Cols1Test(InferencePassTest):
data = fluid.data(
name="data", shape=[32, 12, 4, 6], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=1, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=1, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -247,8 +247,8 @@ class FCFusePassTRTDynamicDims4Cols2Test(InferencePassTest):
data = fluid.data(
name="data", shape=[32, 128, 32, 32], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=2, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=2, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......@@ -283,8 +283,8 @@ class FCFusePassTRTDynamicDims4Cols3Test(InferencePassTest):
data = fluid.data(
name="data", shape=[32, 128, 32, 32], dtype="float32"
)
fc_out1 = fluid.layers.fc(
input=data, size=64, num_flatten_dims=3, act="relu"
fc_out1 = paddle.static.nn.fc(
x=data, size=64, num_flatten_dims=3, activation="relu"
)
out = paddle.nn.functional.softmax(fc_out1)
......
......@@ -31,12 +31,12 @@ class FCQuantDequantFusePassTRTDims3Cols1Test(QuantDequantTest):
name='data', shape=[1, 28, 28], dtype='float32'
)
self.label = fluid.data(name='label', shape=[1, 1], dtype='int64')
fc_out = fluid.layers.fc(
input=self.data,
fc_out = paddle.static.nn.fc(
x=self.data,
size=10,
num_flatten_dims=1,
bias_attr=False,
act="relu",
activation="relu",
)
result = F.relu(fc_out)
loss = paddle.nn.functional.cross_entropy(
......@@ -102,12 +102,12 @@ class FCQuantDequantFusePassTRTDims3Cols2Test(QuantDequantTest):
name='data', shape=[1, 28, 28], dtype='float32'
)
self.label = fluid.data(name='label', shape=[1, 1], dtype='int64')
fc_out = fluid.layers.fc(
input=self.data,
fc_out = paddle.static.nn.fc(
x=self.data,
size=28,
num_flatten_dims=2,
bias_attr=False,
act=None,
activation=None,
)
c_out = paddle.reshape(fc_out, shape=[0, 784])
result = F.relu(c_out)
......@@ -176,12 +176,12 @@ class FCQuantDequantFusePassTRTDims3Cols3Test(QuantDequantTest):
self.label = fluid.data(name='label', shape=[1, 1], dtype='int64')
label_shape = paddle.reshape(self.label, shape=[1, 1, 1])
reshape_out = paddle.reshape(self.data, shape=[1, 14, 14, 4])
fc_out = fluid.layers.fc(
input=reshape_out,
fc_out = paddle.static.nn.fc(
x=reshape_out,
size=14,
num_flatten_dims=3,
bias_attr=False,
act=None,
activation=None,
)
c_out = paddle.reshape(fc_out, shape=[1, 1, 2744])
result = F.relu(c_out)
......
......@@ -40,12 +40,12 @@ class TensorRTMatMulQuantDequantDims3Test(QuantDequantTest):
transpose_y=self.transpose_y,
)
matmul_out = paddle.scale(matmul_out, scale=self.alpha)
fc_out = fluid.layers.fc(
input=matmul_out,
fc_out = paddle.static.nn.fc(
x=matmul_out,
size=10,
num_flatten_dims=1,
bias_attr=False,
act=None,
activation=None,
)
result = F.relu(fc_out)
loss = paddle.nn.functional.cross_entropy(
......@@ -142,12 +142,12 @@ class TensorRTMatMulQuantDequantDims4Test(QuantDequantTest):
)
matmul_out = paddle.scale(matmul_out, scale=self.alpha)
out = paddle.static.nn.batch_norm(matmul_out, is_test=True)
fc_out = fluid.layers.fc(
input=matmul_out,
fc_out = paddle.static.nn.fc(
x=matmul_out,
size=10,
num_flatten_dims=1,
bias_attr=False,
act=None,
activation=None,
)
result = F.relu(fc_out)
loss = paddle.nn.functional.cross_entropy(
......@@ -243,12 +243,12 @@ class TensorRTMatMulQuantDequantDims3DynamicTest(QuantDequantTest):
)
matmul_out = paddle.scale(matmul_out, scale=self.alpha)
out = paddle.static.nn.batch_norm(matmul_out, is_test=True)
fc_out = fluid.layers.fc(
input=matmul_out,
fc_out = paddle.static.nn.fc(
x=matmul_out,
size=10,
num_flatten_dims=1,
bias_attr=False,
act=None,
activation=None,
)
result = F.relu(fc_out)
loss = paddle.nn.functional.cross_entropy(
......
......@@ -31,7 +31,7 @@ class TensorRTSubgraphPassFcTest(InferencePassTest):
data = fluid.data(
name="data", shape=[-1, 6, 64, 64], dtype="float32"
)
fc_out = fluid.layers.fc(input=[data], act=None, size=1000)
fc_out = paddle.static.nn.fc(x=[data], activation=None, size=1000)
reshape_out = paddle.reshape(x=fc_out, shape=[1, 1000])
self.feeds = {
"data": np.random.random([1, 6, 64, 64]).astype("float32"),
......
......@@ -28,10 +28,10 @@ class FCFusePassTest(PassTest):
data = fluid.data(
name="data", shape=[32, 128], dtype="float32", lod_level=0
)
tmp_0 = fluid.layers.fc(
input=data, size=128, num_flatten_dims=1, act="relu"
tmp_0 = paddle.static.nn.fc(
x=data, size=128, num_flatten_dims=1, activation="relu"
)
tmp_1 = fluid.layers.fc(input=tmp_0, size=32, num_flatten_dims=1)
tmp_1 = paddle.static.nn.fc(x=tmp_0, size=32, num_flatten_dims=1)
tmp_2 = paddle.nn.functional.softmax(tmp_1)
self.feeds = {"data": np.random.random((32, 128)).astype("float32")}
......
......@@ -34,7 +34,9 @@ class TestQuantizationSubGraph(unittest.TestCase):
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
hidden = data
for _ in range(num):
hidden = fluid.layers.fc(hidden, size=128, act='relu')
hidden = paddle.static.nn.fc(
hidden, size=128, activation='relu'
)
loss = paddle.nn.functional.cross_entropy(
input=hidden, label=label, reduction='none', use_softmax=False
)
......
......@@ -260,8 +260,8 @@ class TestNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -211,8 +211,8 @@ class TestNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -340,8 +340,8 @@ class TestElementwiseMaxNet(unittest.TestCase):
c = paddle.maximum(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=c, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -186,8 +186,8 @@ class TestElementwiseMinOpNet(unittest.TestCase):
c = paddle.minimum(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=c, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -108,9 +108,9 @@ class TestGeluNet(unittest.TestCase):
c = paddle.multiply(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
fc_1 = paddle.static.nn.fc(x=c, size=128)
fc_1_gelu = paddle.nn.functional.gelu(fc_1)
prediction = fluid.layers.fc(input=fc_1_gelu, size=2, act='softmax')
prediction = paddle.static.nn.fc(x=fc_1_gelu, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -103,8 +103,8 @@ class TestLeakyReluNet(unittest.TestCase):
y = paddle.nn.functional.leaky_relu(x)
fc_1 = fluid.layers.fc(input=y, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=y, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -142,7 +142,7 @@ class TestMomentumV2(unittest.TestCase):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1)
cost =paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -267,7 +267,7 @@ class TestMomentumOpWithDecayAPI(unittest.TestCase):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1)
cost =paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......
......@@ -122,8 +122,8 @@ class TestRelu6Net(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.nn.functional.relu6(sum)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -123,8 +123,8 @@ class TestReluNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.nn.functional.relu(sum)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -123,8 +123,8 @@ class TestPowNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2)
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2)
cost = paddle.nn.functional.softmax_with_cross_entropy(prediction, label)
loss = paddle.mean(cost)
......
......@@ -104,8 +104,8 @@ class TestTanhNet(unittest.TestCase):
c = paddle.multiply(a, b)
d = paddle.tanh(c)
fc_1 = fluid.layers.fc(input=d, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=d, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -260,8 +260,8 @@ class TestNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......@@ -343,9 +343,9 @@ class TestNetWithEpsilonTensor(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=2, param_attr=weight_attr1)
prediction = fluid.layers.fc(
input=fc_1, size=2, param_attr=weight_attr2, act='softmax'
fc_1 = paddle.static.nn.fc(x=z, size=2, weight_attr=weight_attr1)
prediction = paddle.static.nn.fc(
x=fc_1, size=2, weight_attr=weight_attr2, activation='softmax'
)
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
......
......@@ -211,8 +211,8 @@ class TestNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -101,8 +101,8 @@ class TestCosNet(unittest.TestCase):
c = paddle.multiply(a, b)
d = paddle.cos(c)
fc_1 = fluid.layers.fc(input=d, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=d, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -135,8 +135,8 @@ class TestElementwiseDivNet(unittest.TestCase):
f.stop_gradient = True
g = paddle.divide(e, f)
fc_1 = fluid.layers.fc(input=g, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=g, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -299,8 +299,8 @@ class TestElementwiseMaxNet(unittest.TestCase):
c = paddle.maximum(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=c, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -186,8 +186,8 @@ class TestElementwiseMinOpNet(unittest.TestCase):
c = paddle.minimum(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=c, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -310,8 +310,8 @@ class TestElementwisePowNet(unittest.TestCase):
c = paddle.pow(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=c, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -191,8 +191,8 @@ class TestSubtractNet(unittest.TestCase):
c = paddle.assign(b)
z = paddle.subtract(sum, c)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -108,9 +108,9 @@ class TestGeluNet(unittest.TestCase):
c = paddle.multiply(a, b)
fc_1 = fluid.layers.fc(input=c, size=128)
fc_1 = paddle.static.nn.fc(x=c, size=128)
fc_1_gelu = paddle.nn.functional.gelu(fc_1)
prediction = fluid.layers.fc(input=fc_1_gelu, size=2, act='softmax')
prediction = paddle.static.nn.fc(x=fc_1_gelu, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -103,8 +103,8 @@ class TestLeakyReluNet(unittest.TestCase):
y = paddle.nn.functional.leaky_relu(x)
fc_1 = fluid.layers.fc(input=y, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=y, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -101,8 +101,8 @@ class TestLogNet(unittest.TestCase):
c = paddle.multiply(a, b)
d = paddle.log(c)
fc_1 = fluid.layers.fc(input=d, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=d, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -110,7 +110,7 @@ class TestMomentumV2(unittest.TestCase):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost =paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......@@ -238,7 +238,7 @@ class TestMomentumOpWithDecayAPI(unittest.TestCase):
with fluid.program_guard(main):
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, act=None)
y_predict = paddle.static.nn.fc(x, size=1, activation=None)
cost =paddle.nn.functional.square_error_cost(input=y_predict, label=y)
avg_cost = paddle.mean(cost)
......
......@@ -101,8 +101,8 @@ class TestPowNet(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.pow(sum, 2.0)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -105,12 +105,12 @@ class TestReduceSumNet(unittest.TestCase):
name="label", shape=[2, 1], dtype='int64'
)
a_1 = fluid.layers.fc(input=a, size=4, num_flatten_dims=2, act=None)
b_1 = fluid.layers.fc(input=b, size=4, num_flatten_dims=2, act=None)
a_1 = paddle.static.nn.fc(x=a, size=4, num_flatten_dims=2, activation=None)
b_1 = paddle.static.nn.fc(x=b, size=4, num_flatten_dims=2, activation=None)
z = paddle.add(a_1, b_1)
z_1 = self.set_reduce_sum_function(z)
prediction = fluid.layers.fc(input=z_1, size=2, act='softmax')
prediction = paddle.static.nn.fc(x=z_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
......@@ -122,8 +122,8 @@ class TestRelu6Net(unittest.TestCase):
sum = paddle.add(a, b)
z = paddle.nn.functional.relu6(sum)
fc_1 = fluid.layers.fc(input=z, size=128)
prediction = fluid.layers.fc(input=fc_1, size=2, act='softmax')
fc_1 = paddle.static.nn.fc(x=z, size=128)
prediction = paddle.static.nn.fc(x=fc_1, size=2, activation='softmax')
cost = paddle.nn.functional.cross_entropy(input=prediction, label=label, reduction='none', use_softmax=False)
loss = paddle.mean(cost)
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册