Skip to content

Commit 2b6d004

Browse files
authored
Api move 20a (#24559)
* add base name alias; test=develop * fix embedding bug; test=develop * fix io error; test=develop * add metric; test=develop * add import palce; test=develop * add setup; test=develop * fix incubate reader; test=develop * fix initializer error; test=develop
1 parent ca29abc commit 2b6d004

File tree

16 files changed

+194
-120
lines changed

16 files changed

+194
-120
lines changed

python/paddle/__init__.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import paddle.nn
3939
import paddle.framework
4040
import paddle.imperative
41+
import paddle.optimizer
42+
import paddle.metric
4143
import paddle.incubate.complex as complex
4244

4345
# TODO: define alias in tensor and framework directory
@@ -194,20 +196,42 @@
194196
from .tensor.search import nonzero #DEFINE_ALIAS
195197
from .tensor.search import sort #DEFINE_ALIAS
196198
from .framework.random import manual_seed #DEFINE_ALIAS
199+
from .framework import append_backward #DEFINE_ALIAS
200+
from .framework import gradients #DEFINE_ALIAS
201+
from .framework import Executor #DEFINE_ALIAS
202+
from .framework import global_scope #DEFINE_ALIAS
203+
from .framework import scope_guard #DEFINE_ALIAS
204+
from .framework import BuildStrategy #DEFINE_ALIAS
205+
from .framework import CompiledProgram #DEFINE_ALIAS
206+
from .framework import default_main_program #DEFINE_ALIAS
207+
from .framework import default_startup_program #DEFINE_ALIAS
208+
from .framework import create_global_var #DEFINE_ALIAS
209+
from .framework import create_parameter #DEFINE_ALIAS
210+
from .framework import Print #DEFINE_ALIAS
211+
from .framework import py_func #DEFINE_ALIAS
212+
from .framework import ExecutionStrategy #DEFINE_ALIAS
213+
from .framework import name_scope #DEFINE_ALIAS
214+
from .framework import ParallelExecutor #DEFINE_ALIAS
215+
from .framework import ParamAttr #DEFINE_ALIAS
216+
from .framework import Program #DEFINE_ALIAS
217+
from .framework import program_guard #DEFINE_ALIAS
218+
from .framework import Variable #DEFINE_ALIAS
219+
from .framework import WeightNormParamAttr #DEFINE_ALIAS
220+
from .framework import CPUPlace #DEFINE_ALIAS
221+
from .framework import CUDAPlace #DEFINE_ALIAS
222+
from .framework import CUDAPinnedPlace #DEFINE_ALIAS
197223
from .tensor.search import index_sample #DEFINE_ALIAS
198224
from .tensor.stat import mean #DEFINE_ALIAS
199225
from .tensor.stat import reduce_mean #DEFINE_ALIAS
200226
from .tensor.stat import std #DEFINE_ALIAS
201227
from .tensor.stat import var #DEFINE_ALIAS
228+
from .fluid.data import data
202229
# from .tensor.tensor import Tensor #DEFINE_ALIAS
203230
# from .tensor.tensor import LoDTensor #DEFINE_ALIAS
204231
# from .tensor.tensor import LoDTensorArray #DEFINE_ALIAS
205232

206233
from . import incubate
207234
from .incubate import hapi
208-
from .fluid.dygraph.base import enable_dygraph #DEFINE_ALIAS
209-
from .fluid.dygraph.base import disable_dygraph #DEFINE_ALIAS
210-
from .fluid.framework import in_dygraph_mode #DEFINE_ALIAS
211-
enable_imperative = enable_dygraph #DEFINE_ALIAS
212-
disable_imperative = disable_dygraph #DEFINE_ALIAS
213-
in_imperative_mode = in_dygraph_mode
235+
from .fluid.dygraph.base import enable_dygraph as enable_imperative #DEFINE_ALIAS
236+
from .fluid.dygraph.base import disable_dygraph as disable_imperative #DEFINE_ALIAS
237+
from .fluid.framework import in_dygraph_mode as in_imperative_mode #DEFINE_ALIAS

python/paddle/declarative/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__all__ = [
16+
'fc',
17+
'batch_norm',
18+
'embedding',
19+
'bilinear_tensor_product'
20+
'conv2d'
21+
'conv2d_transpose'
22+
'conv3d'
23+
'conv3d_transpose'
24+
'create_parameter'
25+
'crf_decoding'
26+
'data_norm'
27+
'deformable_conv'
28+
'group_norm'
29+
'hsigmoid'
30+
'instance_norm'
31+
'layer_norm'
32+
'multi_box_head'
33+
'nce'
34+
'prelu'
35+
'row_conv'
36+
'spectral_norm',
37+
]
38+
39+
from ..fluid.layers import fc, batch_norm, bilinear_tensor_product, \
40+
conv2d, conv2d_transpose, conv3d, conv3d_transpose, create_parameter, \
41+
crf_decoding, data_norm, deformable_conv, group_norm, hsigmoid, instance_norm, \
42+
layer_norm, multi_box_head, nce, prelu, row_conv, spectral_norm
43+
44+
from ..fluid.input import embedding

python/paddle/fluid/tests/unittests/test_imperative_container_layerlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def fluid_dygraph_list(self):
3737
[fluid.dygraph.Linear(2**i, 2**(i + 1)) for i in range(6)])
3838

3939
def paddle_imperative_list(self):
40-
return paddle.imperative.LayerList(
40+
return paddle.nn.LayerList(
4141
[fluid.dygraph.Linear(2**i, 2**(i + 1)) for i in range(6)])
4242

4343
def layer_list(self, use_fluid_api):

python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def fluid_dygraph_ParameterList(self, num_stacked_param):
3535
shape=[2, 2], dtype='float32')] * num_stacked_param)
3636

3737
def paddle_imperative_ParameterList(self, num_stacked_param):
38-
return paddle.imperative.ParameterList(
38+
return paddle.nn.ParameterList(
3939
[fluid.layers.create_parameter(
4040
shape=[2, 2], dtype='float32')] * num_stacked_param)
4141

python/paddle/fluid/tests/unittests/test_imperative_named_members.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_named_parameters(self):
6767
fc1 = fluid.Linear(10, 3)
6868
fc2 = fluid.Linear(3, 10, bias_attr=False)
6969
custom = MyLayer(3, 10)
70-
model = paddle.imperative.Sequential(fc1, fc2, custom)
70+
model = paddle.nn.Sequential(fc1, fc2, custom)
7171

7272
named_parameters = list(model.named_parameters())
7373
expected_named_parameters = list()

python/paddle/framework/__init__.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,24 @@
1313
# limitations under the License.
1414

1515
# TODO: import framework api under this directory
16-
# __all__ = ['append_backward',
17-
# 'gradients',
18-
# 'Executor',
19-
# 'global_scope',
20-
# 'scope_guard',
21-
# 'BuildStrategy',
22-
# 'CompiledProgram',
23-
# 'default_main_program',
24-
# 'default_startup_program',
25-
# 'create_global_var',
26-
# 'create_parameter',
27-
# 'create_py_reader_by_data',
28-
# 'Print',
29-
# 'py_func',
30-
# 'ExecutionStrategy',
31-
# 'in_dygraph_mode',
32-
# 'name_scope',
33-
# 'ParallelExecutor',
34-
# 'ParamAttr',
35-
# 'Program',
36-
# 'program_guard',
37-
# 'Variable',
38-
# 'WeightNormParamAttr',
39-
# 'Model',
40-
# 'Sequential']
16+
__all__ = [
17+
'append_backward', 'gradients', 'Executor', 'global_scope', 'scope_guard',
18+
'BuildStrategy', 'CompiledProgram', 'default_main_program',
19+
'default_startup_program', 'create_global_var', 'create_parameter', 'Print',
20+
'py_func', 'ExecutionStrategy', 'name_scope', 'ParallelExecutor',
21+
'ParamAttr', 'Program', 'program_guard', 'Variable', 'WeightNormParamAttr',
22+
'CPUPlace', 'CUDAPlace', 'CUDAPinnedPlace'
23+
]
4124

4225
from . import random
4326
from .random import manual_seed
27+
from ..fluid.executor import Executor, global_scope, scope_guard
28+
from ..fluid.backward import append_backward, gradients
29+
from ..fluid.compiler import BuildStrategy, CompiledProgram, ExecutionStrategy
30+
from ..fluid.framework import default_main_program, default_startup_program, name_scope, Program, program_guard, Variable
31+
from ..fluid.layers.control_flow import Print
32+
from ..fluid.layers.nn import py_func
33+
from ..fluid.parallel_executor import ParallelExecutor
34+
from ..fluid.param_attr import ParamAttr, WeightNormParamAttr
35+
from ..fluid.layers.tensor import create_global_var, create_parameter
36+
from ..fluid.core import CPUPlace, CUDAPlace, CUDAPinnedPlace

python/paddle/imperative/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
# define api used to run in imperative mode
1616
__all__ = [
1717
'BackwardStrategy', 'enabled', 'grad', 'guard', 'LayerList', 'load', 'save',
18-
'prepare_context', 'to_variable', 'TracedLayer', 'no_grad', 'ParameterList',
19-
'Sequential'
18+
'prepare_context', 'to_variable', 'TracedLayer', 'no_grad', 'ParallelEnv',
19+
'ProgramTranslator', 'declarative', 'DataParallel'
20+
]
21+
22+
__all__ += [
23+
'NoamDecay', 'PiecewiseDecay', 'NaturalExpDecay', 'ExponentialDecay',
24+
'InverseTimeDecay', 'PolynomialDecay', 'CosineDecay'
2025
]
2126

2227
from paddle.fluid import core
2328
from ..fluid.dygraph.base import enabled, guard, no_grad, to_variable, grad
24-
from ..fluid.dygraph.container import LayerList, ParameterList, Sequential
2529
from ..fluid.dygraph.checkpoint import load_dygraph as load
2630
from ..fluid.dygraph.checkpoint import save_dygraph as save
27-
from ..fluid.dygraph.parallel import prepare_context
28-
from ..fluid.dygraph.jit import TracedLayer
31+
from ..fluid.dygraph.parallel import prepare_context, ParallelEnv, DataParallel
32+
from ..fluid.dygraph.jit import TracedLayer, declarative
33+
from ..fluid.dygraph import ProgramTranslator
34+
35+
from ..fluid.dygraph.learning_rate_scheduler import NoamDecay, PiecewiseDecay, NaturalExpDecay, ExponentialDecay, \
36+
InverseTimeDecay, PolynomialDecay, CosineDecay
2937

3038
BackwardStrategy = core.BackwardStrategy

python/paddle/incubate/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
__all__ = []
1818
__all__ += hapi.__all__
19+
__all__ += ["reader"]
20+
21+
from ..fluid.contrib import reader

python/paddle/io/__init__.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@
1818
'BatchSampler',
1919
# 'Transform',
2020
'DataLoader',
21-
# 'load',
22-
# 'save',
23-
# 'load_program_state',
24-
# 'set_program_state',
25-
# 'load_inference_model',
26-
# 'save_inference_model',
27-
# 'batch',
28-
# 'shuffle',
29-
# 'buffered',
30-
# 'cache',
31-
# 'chain',
32-
# 'firstn',
33-
# 'compose',
34-
# 'map_readers',
35-
# 'xmap_readers'
21+
'load',
22+
'save',
23+
'load_program_state',
24+
'set_program_state',
25+
'load_inference_model',
26+
'save_inference_model',
27+
'batch',
28+
'shuffle',
29+
'buffered',
30+
'cache',
31+
'chain',
32+
'firstn',
33+
'compose',
34+
'map_readers',
35+
'xmap_readers'
3636
]
3737

3838
from ..fluid.io import DataLoader
3939
from ..fluid.dataloader import Dataset, BatchSampler
40+
from ..fluid.io import load, save, load_program_state, set_program_state, \
41+
load_inference_model, save_inference_model, batch
42+
from ..reader import shuffle, buffered, cache, chain, firstn, compose, map_readers, xmap_readers

python/paddle/metric/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# limitations under the License.
1414

1515
# TODO: define the functions to calculate metric in this directory
16-
# __all__ = ['Accuracy',
17-
# 'Auc',
18-
# 'ChunkEvaluator',
19-
# 'CompositeMetric',
20-
# 'DetectionMAP',
21-
# 'EditDistance',
22-
# 'Precesion',
23-
# 'Recall',
24-
# 'accuracy',
25-
# 'auc',
26-
# 'chunk_eval',
27-
# 'cos_sim',
28-
# 'mean_iou']
16+
__all__ = [
17+
'Accuracy', 'Auc', 'ChunkEvaluator', 'CompositeMetric', 'DetectionMAP',
18+
'EditDistance', 'Precision', 'Recall', 'accuracy', 'auc', 'chunk_eval',
19+
'cos_sim', 'mean_iou'
20+
]
21+
22+
23+
24+
from ..fluid.metrics import Accuracy, Auc, ChunkEvaluator, CompositeMetric, DetectionMAP, EditDistance, \
25+
Precision, Recall
26+
27+
from ..fluid.layers.metric_op import accuracy, auc
28+
from ..fluid.layers.nn import chunk_eval, cos_sim, mean_iou

0 commit comments

Comments
 (0)