From ded3539ba6d71514438e68a01f257fdf724ff59e Mon Sep 17 00:00:00 2001 From: SigureMo Date: Sun, 24 Sep 2023 21:54:30 +0800 Subject: [PATCH 1/2] [xdoctest][task skip_no_reason 8-11] add skip reason for jit sample code --- python/paddle/jit/api.py | 8 ++++---- python/paddle/jit/dy2static/convert_call_func.py | 2 +- python/paddle/jit/dy2static/program_translator.py | 14 +++++++------- python/paddle/jit/translated_layer.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/paddle/jit/api.py b/python/paddle/jit/api.py index a0ca693ccfcd0..ab96099406be5 100644 --- a/python/paddle/jit/api.py +++ b/python/paddle/jit/api.py @@ -264,7 +264,7 @@ def to_static( Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> from paddle.jit import to_static @@ -361,7 +361,7 @@ def not_to_static(func=None): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> @paddle.jit.not_to_static @@ -876,7 +876,7 @@ def save(layer, path, input_spec=None, **configs): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> # example 1: save layer >>> import numpy as np >>> import paddle @@ -1368,7 +1368,7 @@ def load(path, **configs): .. code-block:: python :name: code-example1 - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import numpy as np >>> import paddle >>> import paddle.nn as nn diff --git a/python/paddle/jit/dy2static/convert_call_func.py b/python/paddle/jit/dy2static/convert_call_func.py index c6b8169b7c545..22ca5e756568a 100644 --- a/python/paddle/jit/dy2static/convert_call_func.py +++ b/python/paddle/jit/dy2static/convert_call_func.py @@ -162,7 +162,7 @@ def convert_call(func): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> from paddle.jit.dy2static import Call diff --git a/python/paddle/jit/dy2static/program_translator.py b/python/paddle/jit/dy2static/program_translator.py index 5f8756ce7f150..55667080e6d1b 100644 --- a/python/paddle/jit/dy2static/program_translator.py +++ b/python/paddle/jit/dy2static/program_translator.py @@ -559,7 +559,7 @@ def rollback(self): Example:: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> class Net(paddle.nn.Layer): @@ -906,7 +906,7 @@ def concrete_program(self): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> from paddle.jit import to_static >>> from paddle.static import InputSpec @@ -1778,7 +1778,7 @@ def enable(self, enable_to_static): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> def func(x): ... if paddle.mean(x) > 0: @@ -1821,7 +1821,7 @@ def get_output(self, dygraph_func, *args, **kwargs): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> def func(x): ... if paddle.mean(x) > 0: @@ -1904,7 +1904,7 @@ def get_func(self, dygraph_func): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> def func(x): ... if paddle.mean(x) > 0: @@ -1953,7 +1953,7 @@ def get_program(self, dygraph_func, *args, **kwargs): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> def func(x): ... if paddle.mean(x) > 0: @@ -2020,7 +2020,7 @@ def get_code(self, dygraph_func): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import paddle >>> def func(x): ... if paddle.mean(x) > 0: diff --git a/python/paddle/jit/translated_layer.py b/python/paddle/jit/translated_layer.py index fce3211f23878..766e72e0553e8 100644 --- a/python/paddle/jit/translated_layer.py +++ b/python/paddle/jit/translated_layer.py @@ -1316,7 +1316,7 @@ class TranslatedLayer(layers.Layer): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import numpy as np >>> import paddle >>> import paddle.nn as nn @@ -1526,7 +1526,7 @@ def program(self, method_name='forward'): Examples: .. code-block:: python - >>> # doctest: +SKIP + >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest') >>> import numpy as np >>> import paddle >>> from paddle import nn From 16d896cdd4a0ffbc3ab7146510a3f912a1d1337d Mon Sep 17 00:00:00 2001 From: SigureMo Date: Mon, 25 Sep 2023 04:12:04 +0800 Subject: [PATCH 2/2] fix some api name --- python/paddle/jit/api.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/python/paddle/jit/api.py b/python/paddle/jit/api.py index ab96099406be5..98f1f8bb95b4f 100644 --- a/python/paddle/jit/api.py +++ b/python/paddle/jit/api.py @@ -94,7 +94,7 @@ def _extract_vars(inputs, result_list, err_tag='inputs'): _extract_vars(var, result_list, err_tag) else: raise TypeError( - "The type of 'each element of {}' in paddle.jit.TracedLayer.trace must be base.Variable, but received {}.".format( + "The type of 'each element of {}' in paddle.jit.api.TracedLayer.trace must be base.Variable, but received {}.".format( err_tag, type(inputs) ) ) @@ -129,6 +129,7 @@ def _dygraph_to_static_func_(dygraph_func): Examples: .. code-block:: python + >>> # doctest: +SKIP('`paddle.jit.dygraph_to_static_func` can not run in xdoctest') >>> import paddle >>> from paddle.jit.api import dygraph_to_static_func @@ -647,7 +648,6 @@ def _get_output_vars(outputs, output_spec, with_hook=False): # 1. Expected cases: # - paddle.jit.save # - paddle.static.save_inference_model -# - paddle.base.io.save_inference_model # 2. Error cases: # - paddle.save: no .pdmodel for prefix # - paddle.static.save: no .pdiparams but .pdparams exists @@ -729,6 +729,7 @@ def _register_save_pre_hook(hook): Examples: .. code-block:: python + >>> # doctest: +SKIP('`paddle.jit.api.to_static` can not run in xdoctest') >>> import numpy as np >>> import paddle @@ -1335,7 +1336,7 @@ def load(path, **configs): :api_attr: imperative Load model saved by ``paddle.jit.save`` or ``paddle.static.save_inference_model`` or - paddle 1.x API ``paddle.base.io.save_inference_model`` as ``paddle.jit.TranslatedLayer``, + paddle 1.x API ``paddle.static.save_inference_model`` as ``paddle.jit.TranslatedLayer``, then performing inference or fine-tune training. .. note:: @@ -1454,7 +1455,7 @@ def load(path, **configs): >>> train(loaded_layer, loader, loss_fn, adam) - 2. Load model saved by ``paddle.base.io.save_inference_model`` then performing and fine-tune training. + 2. Load model saved by ``paddle.static.save_inference_model`` then performing and fine-tune training. .. code-block:: python :name: code-example2 @@ -1522,8 +1523,12 @@ def load(path, **configs): ... ) >>> model_path = "fc.example.model" - >>> paddle.base.io.save_inference_model( - >>> model_path, ["image"], [pred], exe) + >>> paddle.static.save_inference_model( + ... model_path, + ... [image], + ... [pred], + ... exe + ... ) >>> # 2. load model @@ -1689,7 +1694,7 @@ def trace(layer, inputs): >>> layer = ExampleLayer() >>> in_var = paddle.uniform(shape=[2, 3], dtype='float32') - >>> out_dygraph, static_layer = paddle.jit.TracedLayer.trace(layer, inputs=[in_var]) + >>> out_dygraph, static_layer = paddle.jit.api.TracedLayer.trace(layer, inputs=[in_var]) >>> # run the static graph model using Executor inside >>> out_static_graph = static_layer([in_var]) @@ -1703,7 +1708,7 @@ def trace(layer, inputs): """ assert isinstance( layer, Layer - ), "The type of 'layer' in paddle.jit.TracedLayer.trace must be paddle.nn.Layer, but received {}.".format( + ), "The type of 'layer' in paddle.jit.api.TracedLayer.trace must be paddle.nn.Layer, but received {}.".format( type(layer) ) outs, prog, feed, fetch, parameters = _trace(layer, inputs) @@ -1739,7 +1744,7 @@ def set_strategy(self, build_strategy=None, exec_strategy=None): >>> layer = ExampleLayer() >>> in_var = paddle.uniform(shape=[2, 3], dtype='float32') - >>> out_dygraph, static_layer = paddle.jit.TracedLayer.trace(layer, inputs=[in_var]) + >>> out_dygraph, static_layer = paddle.jit.api.TracedLayer.trace(layer, inputs=[in_var]) >>> build_strategy = paddle.static.BuildStrategy() >>> build_strategy.enable_inplace = True @@ -1754,12 +1759,12 @@ def set_strategy(self, build_strategy=None, exec_strategy=None): assert self._compiled_program is None, "Cannot set strategy after run" assert isinstance( build_strategy, (type(None), BuildStrategy) - ), "The type of 'build_strategy' in paddle.jit.TracedLayer.set_strategy must be base.BuildStrategy, but received {}.".format( + ), "The type of 'build_strategy' in paddle.jit.api.TracedLayer.set_strategy must be base.BuildStrategy, but received {}.".format( type(build_strategy) ) assert isinstance( exec_strategy, (type(None), ExecutionStrategy) - ), "The type of 'exec_strategy' in paddle.jit.TracedLayer.set_strategy must be base.ExecutionStrategy, but received {}.".format( + ), "The type of 'exec_strategy' in paddle.jit.api.TracedLayer.set_strategy must be base.ExecutionStrategy, but received {}.".format( type(exec_strategy) ) self._build_strategy = build_strategy @@ -1845,7 +1850,7 @@ def save_inference_model(self, path, feed=None, fetch=None, **kwargs): >>> in_var = paddle.to_tensor(in_np) >>> layer = ExampleLayer() - >>> out_dygraph, static_layer = paddle.jit.TracedLayer.trace(layer, inputs=[in_var]) + >>> out_dygraph, static_layer = paddle.jit.api.TracedLayer.trace(layer, inputs=[in_var]) >>> static_layer.save_inference_model(save_dirname, feed=[0], fetch=[0]) >>> paddle.enable_static() @@ -1864,13 +1869,13 @@ def save_inference_model(self, path, feed=None, fetch=None, **kwargs): path, "path", str, - "paddle.jit.TracedLayer.save_inference_model", + "paddle.jit.api.TracedLayer.save_inference_model", ) check_type( feed, "feed", (type(None), list), - "paddle.jit.TracedLayer.save_inference_model", + "paddle.jit.api.TracedLayer.save_inference_model", ) if isinstance(feed, list): for f in feed: @@ -1878,13 +1883,13 @@ def save_inference_model(self, path, feed=None, fetch=None, **kwargs): f, "each element of feed", int, - "paddle.jit.TracedLayer.save_inference_model", + "paddle.jit.api.TracedLayer.save_inference_model", ) check_type( fetch, "fetch", (type(None), list), - "paddle.jit.TracedLayer.save_inference_model", + "paddle.jit.api.TracedLayer.save_inference_model", ) if isinstance(fetch, list): for f in fetch: @@ -1892,7 +1897,7 @@ def save_inference_model(self, path, feed=None, fetch=None, **kwargs): f, "each element of fetch", int, - "paddle.jit.TracedLayer.save_inference_model", + "paddle.jit.api.TracedLayer.save_inference_model", ) clip_extra = kwargs.get('clip_extra', True) # path check