Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
daea892c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
daea892c
编写于
1月 10, 2023
作者:
H
hjyp
提交者:
GitHub
1月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2St] Add ignore_module API (#49485)
* Add ignore_module API * fix type of parameter * Add test case of ignore-module
上级
451756fb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
1 deletion
+79
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_ignore_module.py
...d/tests/unittests/dygraph_to_static/test_ignore_module.py
+36
-0
python/paddle/jit/__init__.py
python/paddle/jit/__init__.py
+2
-0
python/paddle/jit/api.py
python/paddle/jit/api.py
+30
-1
python/paddle/jit/dy2static/convert_call_func.py
python/paddle/jit/dy2static/convert_call_func.py
+11
-0
未找到文件。
python/paddle/fluid/tests/unittests/dygraph_to_static/test_ignore_module.py
0 → 100644
浏览文件 @
daea892c
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
astor
import
scipy
from
paddle.jit
import
ignore_module
from
paddle.jit.dy2static.convert_call_func
import
BUILTIN_LIKELY_MODULES
class
TestIgnoreModule
(
unittest
.
TestCase
):
def
test_ignore_module
(
self
):
modules
=
[
scipy
,
astor
]
ignore_module
(
modules
)
self
.
assertEquals
(
[
scipy
,
astor
],
BUILTIN_LIKELY_MODULES
[
-
2
:],
'Failed to add modules that ignore transcription'
,
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/jit/__init__.py
浏览文件 @
daea892c
...
...
@@ -17,6 +17,7 @@ from .api import save
from
.api
import
load
from
.api
import
to_static
from
.api
import
not_to_static
from
.api
import
ignore_module
from
.dy2static.logging_utils
import
set_code_level
,
set_verbosity
from
.
import
dy2static
...
...
@@ -27,6 +28,7 @@ __all__ = [ # noqa
'save'
,
'load'
,
'to_static'
,
'ignore_module'
,
'ProgramTranslator'
,
'TranslatedLayer'
,
'set_code_level'
,
...
...
python/paddle/jit/api.py
浏览文件 @
daea892c
...
...
@@ -24,7 +24,7 @@ import warnings
from
collections
import
OrderedDict
import
inspect
import
threading
from
typing
import
Any
from
typing
import
Any
,
List
import
paddle
from
paddle.fluid
import
core
,
dygraph
...
...
@@ -43,6 +43,7 @@ from .dy2static import logging_utils
from
.dy2static.convert_call_func
import
(
ConversionOptions
,
CONVERSION_OPTIONS
,
add_ignore_module
,
)
from
.dy2static.program_translator
import
(
ProgramTranslator
,
...
...
@@ -192,6 +193,34 @@ def copy_decorator_attrs(original_func, decorated_obj):
return
decorated_obj
def
ignore_module
(
modules
:
List
[
Any
]):
"""
Adds modules that ignore transcription.
Builtin modules that have been ignored are collections, pdb, copy, inspect, re, numpy, logging, six
Args:
modules (List[Any]): Ignored modules that you want to add
Examples:
.. code-block:: python
import scipy
import astor
import paddle
from paddle.jit import ignore_module
modules = [
scipy,
astor
]
ignore_module(modules)
"""
add_ignore_module
(
modules
)
def
to_static
(
function
=
None
,
input_spec
=
None
,
build_strategy
=
None
,
property
=
False
):
...
...
python/paddle/jit/dy2static/convert_call_func.py
浏览文件 @
daea892c
...
...
@@ -21,6 +21,7 @@ import logging
import
pdb
import
re
import
types
from
typing
import
Any
,
List
import
numpy
...
...
@@ -100,6 +101,16 @@ def builtin_modules():
BUILTIN_LIKELY_MODULES
=
builtin_modules
()
def
add_ignore_module
(
modules
:
List
[
Any
]):
"""
Adds modules that ignore transcription
"""
global
BUILTIN_LIKELY_MODULES
for
module
in
modules
:
if
module
not
in
BUILTIN_LIKELY_MODULES
:
BUILTIN_LIKELY_MODULES
.
append
(
module
)
def
is_unsupported
(
func
):
"""
Checks whether the func is supported by dygraph to static graph.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录