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

update 2.0 public api in all left files #33313

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions python/paddle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@
from .framework import load # noqa: F401
from .framework import DataParallel # noqa: F401

from .framework import set_default_dtype #DEFINE_ALIAS
from .framework import get_default_dtype #DEFINE_ALIAS
from .framework import set_grad_enabled #DEFINE_ALIAS
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是否要改成 from .framework import set_grad_enabled # noqa: F401
或者说set_grad_enabled 如果不公开了,那下面的__all__列表中也要删除set_grad_enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里的set_grad_enabled是重复导入,跟242行重复了。

from .framework import set_default_dtype # noqa: F401
from .framework import get_default_dtype # noqa: F401

from .tensor.search import index_sample # noqa: F401
from .tensor.stat import mean # noqa: F401
Expand Down Expand Up @@ -484,7 +483,6 @@
'logical_not',
'add_n',
'minimum',
'ComplexTensor',
'scatter',
'scatter_',
'floor',
Expand All @@ -493,5 +491,6 @@
'log2',
'log10',
'concat',
'check_shape'
'check_shape',
'standard_normal'
]
4 changes: 2 additions & 2 deletions python/paddle/amp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .auto_cast import auto_cast
from .grad_scaler import GradScaler
from .auto_cast import auto_cast # noqa: F401
from .grad_scaler import GradScaler # noqa: F401

__all__ = ['auto_cast', 'GradScaler']
2 changes: 1 addition & 1 deletion python/paddle/amp/auto_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from paddle.fluid.dygraph.amp import amp_guard

__all__ = ['auto_cast']
__all__ = []


def auto_cast(enable=True, custom_white_list=None, custom_black_list=None):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/amp/grad_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from paddle.fluid.dygraph.amp import AmpScaler

__all__ = ['GradScaler']
__all__ = []


class GradScaler(AmpScaler):
Expand Down
9 changes: 4 additions & 5 deletions python/paddle/autograd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ..fluid.dygraph.base import grad #DEFINE_ALIAS

from . import backward_mode
from .backward_mode import backward
from .py_layer import PyLayer, PyLayerContext
from ..fluid.dygraph.base import grad # noqa: F401
from . import backward_mode # noqa: F401
from .backward_mode import backward # noqa: F401
from .py_layer import PyLayer, PyLayerContext # noqa: F401

__all__ = ['grad', 'backward', 'PyLayer', 'PyLayerContext']
2 changes: 1 addition & 1 deletion python/paddle/autograd/backward_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from paddle.fluid import core
from paddle.fluid import framework
import paddle
__all__ = ['backward']
__all__ = []


@framework.dygraph_only
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/autograd/py_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import paddle
from paddle.fluid.framework import dygraph_only
from paddle.fluid import core
__all__ = ['PyLayer', 'PyLayerContext']
__all__ = []


class PyLayerContext(object):
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = ['batch']
__all__ = []


def batch(reader, batch_size, drop_last=False):
Expand All @@ -35,11 +35,11 @@ def batch(reader, batch_size, drop_last=False):
Examples:
.. code-block:: python

import paddle.fluid as fluid
import paddle
def reader():
for i in range(10):
yield i
batch_reader = fluid.io.batch(reader, batch_size=2)
batch_reader = paddle.batch(reader, batch_size=2)

for data in batch_reader():
print(data)
Expand Down
9 changes: 1 addition & 8 deletions python/paddle/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
import six
import math

__all__ = [
'long_type',
'to_text',
'to_bytes',
'round',
'floor_division',
'get_exception_message',
]
__all__ = []

if six.PY2:
int_type = int
Expand Down
30 changes: 8 additions & 22 deletions python/paddle/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,10 @@
from paddle.fluid import core
from paddle.fluid import framework
from paddle.fluid.dygraph.parallel import ParallelEnv
from paddle.fluid.framework import is_compiled_with_cuda #DEFINE_ALIAS
from paddle.fluid.framework import is_compiled_with_rocm #DEFINE_ALIAS

__all__ = [
'get_cudnn_version',
'set_device',
'get_device',
'XPUPlace',
'is_compiled_with_xpu',
Copy link
Collaborator

Choose a reason for hiding this comment

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

注意后面Examples: .. code-block:: python里的写法要和最终推荐路径都保持一致,现在比较杂乱,比如有:support_xpu = paddle.device.is_compiled_with_xpu()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done,已经进行修改

# 'cpu_places',
# 'CPUPlace',
# 'cuda_pinned_places',
# 'cuda_places',
# 'CUDAPinnedPlace',
# 'CUDAPlace',
'is_compiled_with_cuda',
'is_compiled_with_rocm',
'is_compiled_with_npu'
]
from paddle.fluid.framework import is_compiled_with_cuda # noqa: F401
from paddle.fluid.framework import is_compiled_with_rocm # noqa: F401

__all__ = []

_cudnn_version = None

Expand Down Expand Up @@ -68,7 +53,7 @@ def is_compiled_with_xpu():
.. code-block:: python

import paddle
support_xpu = paddle.device.is_compiled_with_xpu()
support_xpu = paddle.is_compiled_with_xpu()
Copy link
Contributor

Choose a reason for hiding this comment

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

这几个API,考虑到接下来还会增加device相关的api,我建议保留paddle.device层级更好些。
如果全都移到根目录下的话,当前还好,未来这类api会比较分散。
兼容性考虑,根目录下的api需要保留别名,但不用加到all列表。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"""
return core.is_compiled_with_xpu()

Expand All @@ -82,9 +67,10 @@ def XPUPlace(dev_id):

Examples:
.. code-block:: python

# required: xpu

import paddle
place = paddle.device.XPUPlace(0)
place = paddle.XPUPlace(0)
"""
return core.XPUPlace(dev_id)

Expand Down
4 changes: 1 addition & 3 deletions python/paddle/distributed/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
from paddle.fluid.dygraph.parallel import ParallelEnv
from paddle.distributed.fleet.base.private_helper_function import wait_server_ready # noqa: F401

__all__ = [ #noqa
"init_parallel_env"
]
__all__ = []

ParallelStrategy = core.ParallelStrategy

Expand Down
13 changes: 7 additions & 6 deletions python/paddle/incubate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import optimizer
from . import checkpoint
from ..fluid.layer_helper import LayerHelper
from .optimizer import LookAhead # noqa: F401
from .optimizer import ModelAverage # noqa: F401
from .checkpoint import auto_checkpoint # noqa: F401
from ..fluid.layer_helper import LayerHelper # noqa: F401

__all__ = []
__all__ += optimizer.__all__
__all__ += checkpoint.__all__
__all__ = [ # noqa
'LookAhead', 'ModelAverage'
]
4 changes: 2 additions & 2 deletions python/paddle/incubate/checkpoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ...fluid.incubate.checkpoint import auto_checkpoint
from ...fluid.incubate.checkpoint import auto_checkpoint # noqa: F401

__all__ = ["auto_checkpoint"]
__all__ = []
6 changes: 3 additions & 3 deletions python/paddle/incubate/optimizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .lookahead import LookAhead
from .modelaverage import ModelAverage
from .lookahead import LookAhead # noqa: F401
from .modelaverage import ModelAverage # noqa: F401

__all__ = ['LookAhead', 'ModelAverage']
__all__ = []
8 changes: 4 additions & 4 deletions python/paddle/incubate/optimizer/lookahead.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
from paddle.fluid.dygraph import base as imperative_base

__all__ = ["LookAhead"]
__all__ = []


class LookAhead(Optimizer):
Expand Down Expand Up @@ -99,7 +99,7 @@ def train(layer, loader, loss_fn, opt):
layer = LinearNet()
loss_fn = nn.CrossEntropyLoss()
optimizer = paddle.optimizer.SGD(learning_rate=0.1, parameters=layer.parameters())
lookahead = paddle.incubate.optimizer.LookAhead(optimizer, alpha=0.2, k=5)
lookahead = paddle.incubate.LookAhead(optimizer, alpha=0.2, k=5)

# create data loader
dataset = RandomDataset(BATCH_NUM * BATCH_SIZE)
Expand Down Expand Up @@ -163,7 +163,7 @@ def step(self):
out = linear(inp)
loss = paddle.mean(out)
sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())
lookahead = paddle.incubate.optimizer.LookAhead(sgd, alpha=0.2, k=5)
lookahead = paddle.incubate.LookAhead(sgd, alpha=0.2, k=5)
loss.backward()
lookahead.step()
lookahead.clear_grad()
Expand Down Expand Up @@ -274,7 +274,7 @@ def minimize(self,
out = linear(inp)
loss = paddle.mean(out)
sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())
lookahead = paddle.incubate.optimizer.LookAhead(sgd, alpha=0.2, k=5)
lookahead = paddle.incubate.LookAhead(sgd, alpha=0.2, k=5)
loss.backward()
lookahead.minimize(loss)
lookahead.clear_grad()
Expand Down
12 changes: 6 additions & 6 deletions python/paddle/incubate/optimizer/modelaverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from paddle.fluid.dygraph import base as imperative_base
from paddle.fluid.wrapped_decorator import signature_safe_contextmanager

__all__ = ["ModelAverage"]
__all__ = []


class ModelAverage(Optimizer):
Expand Down Expand Up @@ -129,7 +129,7 @@ def evaluate(layer, loader, loss_fn):
layer = LinearNet()
loss_fn = nn.CrossEntropyLoss()
optimizer = opt.Momentum(learning_rate=0.2, momentum=0.1, parameters=layer.parameters())
model_average = paddle.incubate.optimizer.ModelAverage(0.15,
model_average = paddle.incubate.ModelAverage(0.15,
parameters=layer.parameters(),
min_average_window=2,
max_average_window=10)
Expand Down Expand Up @@ -313,7 +313,7 @@ def minimize(self,
sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())
sgd.minimize(loss)

modelaverage = paddle.incubate.optimizer.ModelAverage(0.15,
modelaverage = paddle.incubate.ModelAverage(0.15,
parameters=linear.parameters(),
min_average_window=2,
max_average_window=4)
Expand Down Expand Up @@ -345,7 +345,7 @@ def step(self):
out = linear(inp)
loss = paddle.mean(out)
sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())
modelaverage = paddle.incubate.optimizer.ModelAverage(0.15,
modelaverage = paddle.incubate.ModelAverage(0.15,
parameters=linear.parameters(),
min_average_window=2,
max_average_window=4)
Expand Down Expand Up @@ -395,7 +395,7 @@ def apply(self, executor=None, need_restore=True):

sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())

modelaverage = paddle.incubate.optimizer.ModelAverage(0.15,
modelaverage = paddle.incubate.ModelAverage(0.15,
parameters=linear.parameters(),
min_average_window=2,
max_average_window=4)
Expand Down Expand Up @@ -467,7 +467,7 @@ def restore(self, executor=None):

sgd = paddle.optimizer.SGD(learning_rate=0.1,parameters=linear.parameters())

modelaverage = paddle.incubate.optimizer.ModelAverage(0.15,
modelaverage = paddle.incubate.ModelAverage(0.15,
parameters=linear.parameters(),
min_average_window=2,
max_average_window=4)
Expand Down
25 changes: 23 additions & 2 deletions python/paddle/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ..fluid.inference import Config, DataType, PlaceType, PrecisionType, Tensor, \
Predictor, create_predictor, get_version, get_num_bytes_of_data_type, PredictorPool
from ..fluid.inference import Config # noqa: F401
from ..fluid.inference import DataType # noqa: F401
from ..fluid.inference import PlaceType # noqa: F401
from ..fluid.inference import PrecisionType # noqa: F401
from ..fluid.inference import Tensor # noqa: F401
from ..fluid.inference import Predictor # noqa: F401
from ..fluid.inference import create_predictor # noqa: F401
from ..fluid.inference import get_version # noqa: F401
from ..fluid.inference import get_num_bytes_of_data_type # noqa: F401
from ..fluid.inference import PredictorPool # noqa: F401

__all__ = [ # noqa
'Config',
'DataType',
'PlaceType',
'PrecisionType',
'Tensor',
'Predictor',
'create_predictor',
'get_version',
'get_num_bytes_of_data_type',
'PredictorPool'
]
33 changes: 20 additions & 13 deletions python/paddle/jit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@

from __future__ import print_function

from ..fluid.dygraph.jit import save #DEFINE_ALIAS
from ..fluid.dygraph.jit import load #DEFINE_ALIAS
from ..fluid.dygraph.jit import TracedLayer #DEFINE_ALIAS
from ..fluid.dygraph.jit import set_code_level #DEFINE_ALIAS
from ..fluid.dygraph.jit import set_verbosity #DEFINE_ALIAS
from ..fluid.dygraph.jit import declarative as to_static #DEFINE_ALIAS
from ..fluid.dygraph.jit import not_to_static #DEFINE_ALIAS
from ..fluid.dygraph import ProgramTranslator #DEFINE_ALIAS
from ..fluid.dygraph.io import TranslatedLayer #DEFINE_ALIAS
from ..fluid.dygraph.jit import save # noqa: F401
from ..fluid.dygraph.jit import load # noqa: F401
from ..fluid.dygraph.jit import TracedLayer # noqa: F401
from ..fluid.dygraph.jit import set_code_level # noqa: F401
from ..fluid.dygraph.jit import set_verbosity # noqa: F401
from ..fluid.dygraph.jit import declarative as to_static # noqa: F401
from ..fluid.dygraph.jit import not_to_static # noqa: F401
from ..fluid.dygraph import ProgramTranslator # noqa: F401
from ..fluid.dygraph.io import TranslatedLayer # noqa: F401

from . import dy2static
from . import dy2static # noqa: F401

__all__ = [
'save', 'load', 'TracedLayer', 'to_static', 'ProgramTranslator',
'TranslatedLayer', 'set_code_level', 'set_verbosity', 'not_to_static'
__all__ = [ # noqa
'save',
'load',
'TracedLayer',
'to_static',
'ProgramTranslator',
'TranslatedLayer',
'set_code_level',
'set_verbosity',
'not_to_static'
]
Loading