Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove nets.py in fluid #51717

Merged
merged 35 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
37076c6
remove function sequence_conv_pool
longranger2 Mar 15, 2023
c188174
fix test_glu.py
longranger2 Mar 15, 2023
f4a399b
remove function scaled_dot_product_attention
longranger2 Mar 15, 2023
09950a7
remove function img_conv_group
longranger2 Mar 15, 2023
050f926
remove function simple_img_conv_pool
longranger2 Mar 15, 2023
d461807
delete the nets.py
longranger2 Mar 15, 2023
22a7f00
fix bug
longranger2 Mar 15, 2023
c3ab29a
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Mar 15, 2023
69fa7cc
fix bug
longranger2 Mar 16, 2023
091a1de
fix bug
longranger2 Mar 16, 2023
a70792a
fix bug
longranger2 Mar 17, 2023
b2dc097
fix bug
longranger2 Mar 18, 2023
26ab5a9
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Mar 18, 2023
30f8f0d
fix bug
longranger2 Mar 18, 2023
1845822
Merge branch 'fluid_net' of https://github.com/longranger2/Paddle int…
longranger2 Mar 18, 2023
f6df32a
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Mar 20, 2023
e6242f6
Update test_image_classification.py
longranger2 Mar 21, 2023
64d1490
Update test_recognize_digits.py
longranger2 Mar 21, 2023
a845abb
Update test_recommender_system.py
longranger2 Mar 21, 2023
01c85b4
Update test_image_classification_fp16.py
longranger2 Mar 21, 2023
783000f
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Mar 21, 2023
3c26078
fix bug
longranger2 Apr 5, 2023
847c19e
fix bug
longranger2 Apr 5, 2023
3b90121
fix bug
longranger2 Apr 6, 2023
fad07ef
fix bug
longranger2 Apr 7, 2023
ebcce78
fix conflicts
longranger2 Jun 5, 2023
5f83bea
remove the nets.py in fluid
longranger2 Jun 5, 2023
f784428
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Jun 5, 2023
ce723f5
fix bug
longranger2 Jun 5, 2023
eceae44
fix the codestyle
longranger2 Jun 5, 2023
316f736
Merge branch 'PaddlePaddle:develop' into fluid_net
longranger2 Jun 20, 2023
03f3a31
fix conflict
longranger2 Jun 25, 2023
54be8ec
fix conflict
longranger2 Jun 25, 2023
37c8cd4
fix bug
longranger2 Jun 27, 2023
11daecf
Fix TODO
longranger2 Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/paddle/fluid/tests/book/notest_understand_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
import paddle
import paddle.fluid as fluid

from ..unittests import nets


def convolution_net(
data, label, input_dim, class_dim=2, emb_dim=32, hid_dim=32
):
emb = fluid.layers.embedding(
input=data, size=[input_dim, emb_dim], is_sparse=True
)
conv_3 = fluid.nets.sequence_conv_pool(
conv_3 = nets.sequence_conv_pool(
input=emb,
num_filters=hid_dim,
filter_size=3,
act="tanh",
pool_type="sqrt",
)
conv_4 = fluid.nets.sequence_conv_pool(
conv_4 = nets.sequence_conv_pool(
input=emb,
num_filters=hid_dim,
filter_size=4,
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/fluid/tests/book/test_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand Down Expand Up @@ -74,7 +75,7 @@ def layer_warp(block_func, input, ch_in, ch_out, count, stride):

def vgg16_bn_drop(input):
def conv_block(input, num_filter, groups, dropouts):
return fluid.nets.img_conv_group(
return nets.img_conv_group(
input=input,
pool_size=2,
pool_stride=2,
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/book/test_recognize_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand All @@ -45,7 +46,7 @@ def mlp(img, label):


def conv_net(img, label):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=img,
filter_size=5,
num_filters=20,
Expand All @@ -54,7 +55,7 @@ def conv_net(img, label):
act="relu",
)
conv_pool_1 = paddle.static.nn.batch_norm(conv_pool_1)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
3 changes: 2 additions & 1 deletion python/paddle/fluid/tests/book/test_recommender_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import paddle.fluid as fluid
import paddle.fluid.framework as framework
import paddle.fluid.layers as layers
import paddle.fluid.nets as nets
from paddle.fluid.executor import Executor
from paddle.fluid.optimizer import SGDOptimizer

from ..unittests import nets

paddle.enable_static()

IS_SPARSE = True
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/unittests/dist_allreduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import paddle
import paddle.distributed.fleet as fleet
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand All @@ -31,7 +32,7 @@


def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
Expand All @@ -42,7 +43,7 @@ def cnn_model(data):
initializer=paddle.nn.initializer.Constant(value=0.01)
),
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import paddle.distributed.fleet as fleet
import paddle.distributed.fleet.base.role_maker as role_maker
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand All @@ -32,7 +33,7 @@


def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
Expand All @@ -43,7 +44,7 @@ def cnn_model(data):
initializer=paddle.nn.initializer.Constant(value=0.01)
),
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import paddle.distributed.fleet as fleet
import paddle.distributed.fleet.base.role_maker as role_maker
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand All @@ -32,7 +33,7 @@


def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
Expand All @@ -43,7 +44,7 @@ def cnn_model(data):
initializer=paddle.nn.initializer.Constant(value=0.01)
),
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/unittests/dist_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets
from paddle.incubate.distributed.fleet.collective import fleet

paddle.enable_static()
Expand All @@ -31,7 +32,7 @@


def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
Expand All @@ -42,7 +43,7 @@ def cnn_model(data):
initializer=paddle.nn.initializer.Constant(value=0.01)
),
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/unittests/dist_mnist_dgc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

paddle.enable_static()

Expand All @@ -30,7 +31,7 @@


def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
Expand All @@ -41,7 +42,7 @@ def cnn_model(data):
initializer=paddle.nn.initializer.Constant(value=0.01)
),
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import paddle
import paddle.fluid as fluid

from . import nets

DTYPE = "float32"
VOCAB_URL = 'http://paddle-dist-ce-data.bj.bcebos.com/imdb.vocab'
VOCAB_MD5 = '23c86a0533c0151b6f12fa52b106dcc2'
Expand Down Expand Up @@ -63,7 +65,7 @@ def conv_net(
),
)

conv_3 = fluid.nets.sequence_conv_pool(
conv_3 = nets.sequence_conv_pool(
input=emb,
num_filters=num_filters,
filter_size=window_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
# limitations under the License.

import paddle
from . import layers
from .data_feeder import check_variable_and_dtype, convert_dtype
from ..utils import deprecated
import paddle

from ...data_feeder import check_variable_and_dtype, convert_dtype

__all__ = [
"simple_img_conv_pool",
"sequence_conv_pool",
"glu",
"scaled_dot_product_attention",
"img_conv_group",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__all__没必要保留了

Expand Down Expand Up @@ -356,60 +353,11 @@ def sequence_conv_pool(
return pool_out


@deprecated(since="2.0.0", update_to="paddle.nn.functional.glu")
def glu(input, dim=-1):
r"""
:api_attr: Static Graph

The Gated Linear Units(GLU) composed by :ref:`api_fluid_layers_split` ,
:ref:`api_fluid_layers_sigmoid` and :ref:`api_fluid_layers_elementwise_mul` .
Specifically, GLU will plit the input into two equal-sized parts,
:math:`a` and :math:`b`, along the given dimension and then compute as
following:

.. math::

{GLU}(a, b)= a \otimes \sigma(b)

Refer to `Language Modeling with Gated Convolutional Networks
<https://arxiv.org/pdf/1612.08083.pdf>`_.

Args:
input (Variable): The input variable which is a Tensor or LoDTensor.
The supported data types include float32, float64
and float16 (only for GPU).
dim (int, optional): The dimension along which to split. If :math:`dim < 0`, the
dimension to split along is :math:`rank(input) + dim`. Default -1.

Returns:
Variable: Variable with half the size and same data type of input.

Examples:
.. code-block:: python

import paddle.fluid as fluid
import paddle
paddle.enable_static()

data = fluid.data(
name="words", shape=[-1, 6, 3, 9], dtype="float32")
# shape of output: [-1, 3, 3, 9]
output = fluid.nets.glu(input=data, dim=1)
"""
check_variable_and_dtype(
input, 'input', ['float16', 'float32', 'float64'], "glu"
)
a, b = paddle.split(input, num_or_sections=2, axis=dim)
act_b = paddle.nn.functional.sigmoid(x=b)
out = paddle.multiply(x=a, y=act_b)
return out


def scaled_dot_product_attention(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要明确每条单测的作用,进而确定单测使用到的函数的作用,原则上我们不为某个单测保留函数:

  1. 如果某个单测核心目的是测试某个其他功能,只是借助到这里的某个函数组网,那么这个函数可以作为依赖保留。例如simple_img_conv_pool
  2. 如果某个单测的核心目的就是测试这个函数,那么如果函数可以移除的话,单测也相应移除即可。例如scaled_dot_product_attention

queries, keys, values, num_heads=1, dropout_rate=0.0
):
r"""
:api_attr: Static Graph
:api_attr: Static Graph

This interface Multi-Head Attention using scaled dot product.
Attention mechanism can be seen as mapping a query and a set of key-value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets

BATCH_SIZE = 64

Expand All @@ -40,7 +41,7 @@ def convolutional_neural_network(use_py_reader):
use_double_buffer=False,
)

conv_pool_1 = fluid.nets.simple_img_conv_pool(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个单测,从文件名看是测试执行器的,不应当在这个PR里移除

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我刚提交PR的时候发生冲突,发现这个文件test_async_ssa_graph_executor_mnist.py已经整个被删除了,所以才把这个文件删了来解决冲突的

conv_pool_1 = nets.simple_img_conv_pool(
input=img,
filter_size=5,
num_filters=20,
Expand All @@ -49,7 +50,7 @@ def convolutional_neural_network(use_py_reader):
act="relu",
)
conv_pool_1 = paddle.static.nn.batch_norm(conv_pool_1)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
5 changes: 3 additions & 2 deletions python/paddle/fluid/tests/unittests/test_desc_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.tests.unittests.nets as nets
from paddle.fluid import core

SEED = 1
Expand All @@ -29,15 +30,15 @@
# random seed must set before configuring the network.
# fluid.default_startup_program().random_seed = SEED
def cnn_model(data):
conv_pool_1 = fluid.nets.simple_img_conv_pool(
conv_pool_1 = nets.simple_img_conv_pool(
input=data,
filter_size=5,
num_filters=20,
pool_size=2,
pool_stride=2,
act="relu",
)
conv_pool_2 = fluid.nets.simple_img_conv_pool(
conv_pool_2 = nets.simple_img_conv_pool(
input=conv_pool_1,
filter_size=5,
num_filters=50,
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_glu.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setUp(self):
def check_identity(self, place):
with dg.guard(place):
x_var = dg.to_variable(self.x)
y_var = fluid.nets.glu(x_var, self.dim)
y_var = paddle.nn.functional.glu(x_var, self.dim)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下面已有一个测试nn.functional.glu 的单测TestGLUV2,这个单测可直接移除

y_np = y_var.numpy()

np.testing.assert_allclose(y_np, self.out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import paddle
import paddle.fluid as fluid
import paddle.fluid.nets as nets
import paddle.fluid.tests.unittests.nets as nets
from paddle.fluid.framework import Program


Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import paddle
import paddle.fluid as fluid
import paddle.fluid.layers as layers
import paddle.fluid.nets as nets
import paddle.fluid.tests.unittests.nets as nets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里能否直接用.nets,这样使用会有类似API的感觉,下同。

import paddle.nn.functional as F
from paddle.fluid import core
from paddle.fluid.dygraph import base, to_variable
Expand Down
Loading