From b6d5c74f698f0c9fdcbe7d910c77387edd8bb2bc Mon Sep 17 00:00:00 2001 From: lujun Date: Wed, 10 Jul 2019 15:32:42 +0800 Subject: [PATCH] update dygraph api doc for web (#18550) remove dygraph.enable from __all__ hidden dygraph. profiler add doc to dygraph. no_grad --- paddle/fluid/API.spec | 5 +---- python/paddle/fluid/dygraph/__init__.py | 4 ---- python/paddle/fluid/dygraph/base.py | 10 ++++++---- .../fluid/tests/unittests/test_imperative_decorator.py | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 5a43001747..900a81ced0 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -528,8 +528,7 @@ paddle.fluid.dygraph.Layer.parameters (ArgSpec(args=['self', 'include_sublayers' paddle.fluid.dygraph.Layer.state_dict (ArgSpec(args=['self', 'destination', 'include_sublayers'], varargs=None, keywords=None, defaults=(None, True)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.Layer.sublayers (ArgSpec(args=['self', 'include_sublayers'], varargs=None, keywords=None, defaults=(True,)), ('document', '00a881005ecbc96578faf94513bf0d62')) paddle.fluid.dygraph.Layer.train (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) -paddle.fluid.dygraph.enabled (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) -paddle.fluid.dygraph.__impl__ (ArgSpec(args=['func'], varargs=None, keywords=None, defaults=()), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) +paddle.fluid.dygraph.__impl__ (ArgSpec(args=['func'], varargs=None, keywords=None, defaults=()), ('document', 'fa71ad4e6c2b5bf2b5258bd1959f9b2a')) paddle.fluid.dygraph.guard (ArgSpec(args=['place'], varargs=None, keywords=None, defaults=(None,)), ('document', '7071320ffe2eec9aacdae574951278c6')) paddle.fluid.dygraph.to_variable (ArgSpec(args=['value', 'block', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', '9a65d87163a2c6b00fb78f4e61fb3300')) paddle.fluid.dygraph.Conv2D ('paddle.fluid.dygraph.nn.Conv2D', ('document', 'baafe7ae0d3a61ae79cf4c7443e2c37c')) @@ -796,8 +795,6 @@ paddle.fluid.dygraph.Tracer.trace 1. trace(self: paddle.fluid.core_avx.Tracer, a paddle.fluid.dygraph.Tracer.trace_op (ArgSpec(args=['self', 'op', 'inputs', 'outputs', 'stop_gradient'], varargs=None, keywords=None, defaults=(False,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.Tracer.trace_var (ArgSpec(args=['self', 'name', 'var'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.Tracer.train_mode (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) -paddle.fluid.dygraph.start_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) -paddle.fluid.dygraph.stop_gperf_profiler (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.prepare_context (ArgSpec(args=['strategy'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.save_persistables (ArgSpec(args=['model_dict', 'dirname', 'optimizers'], varargs=None, keywords=None, defaults=('save_dir', None)), ('document', '7f526f879139a14cda8e0b5a9171f264')) paddle.fluid.dygraph.load_persistables (ArgSpec(args=['dirname'], varargs=None, keywords=None, defaults=('save_dir',)), ('document', '2574d50a7a9f89fb0d74ddf73d8128f0')) diff --git a/python/paddle/fluid/dygraph/__init__.py b/python/paddle/fluid/dygraph/__init__.py index 7ab1dfdf76..3d81db53ec 100644 --- a/python/paddle/fluid/dygraph/__init__.py +++ b/python/paddle/fluid/dygraph/__init__.py @@ -26,9 +26,6 @@ from .nn import * from . import tracer from .tracer import * -from . import profiler -from .profiler import * - from . import parallel from .parallel import * @@ -46,7 +43,6 @@ __all__ += layers.__all__ __all__ += base.__all__ __all__ += nn.__all__ __all__ += tracer.__all__ -__all__ += profiler.__all__ __all__ += parallel.__all__ __all__ += checkpoint.__all__ __all__ += learning_rate_scheduler.__all__ diff --git a/python/paddle/fluid/dygraph/base.py b/python/paddle/fluid/dygraph/base.py index 1c19fcb3eb..89aca5178f 100644 --- a/python/paddle/fluid/dygraph/base.py +++ b/python/paddle/fluid/dygraph/base.py @@ -14,22 +14,21 @@ from ..wrapped_decorator import signature_safe_contextmanager, wrap_decorator import contextlib import numpy as np -import os - from paddle.fluid import core from paddle.fluid import framework from .tracer import Tracer import logging __all__ = [ - 'enabled', 'no_grad', 'guard', 'to_variable', ] +# This function should be removed in V1.6, because it can easily lead to cyclic dependencies. def enabled(): + # Internal use only return framework.in_dygraph_mode() @@ -90,6 +89,8 @@ def _no_grad_(func): no_grad = wrap_decorator(_no_grad_) +# for fluidDoc +no_grad.__doc__ = _no_grad_.__doc__ _not_support = wrap_decorator(_dygraph_not_support_) @@ -177,7 +178,8 @@ def to_variable(value, block=None, name=None): """ if isinstance(value, np.ndarray): - assert enabled(), "to_variable could only be called in dygraph mode" + assert framework.in_dygraph_mode( + ), "to_variable could only be called in dygraph mode" if not block: block = framework.default_main_program().current_block() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_decorator.py b/python/paddle/fluid/tests/unittests/test_imperative_decorator.py index c821a2e4bc..f55f36c00f 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_decorator.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_decorator.py @@ -23,7 +23,7 @@ class TestTracerMode(unittest.TestCase): self.init_mode = True def get_tracer_mode(self): - assert fluid.dygraph.enabled(), "Dygraph mode must be enabled" + assert fluid.in_dygraph_mode(), "Dygraph mode must be enabled" @fluid.dygraph.no_grad def no_grad_func(self, a): -- GitLab