Skip to content

[Dy2St] Add ignore_module API #49485

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

Merged
merged 5 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 2 additions & 0 deletions python/paddle/jit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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
Expand All @@ -27,6 +28,7 @@
'save',
'load',
'to_static',
'ignore_module',
'ProgramTranslator',
'TranslatedLayer',
'set_code_level',
Expand Down
31 changes: 30 additions & 1 deletion python/paddle/jit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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
Expand All @@ -43,6 +43,7 @@
from .dy2static.convert_call_func import (
ConversionOptions,
CONVERSION_OPTIONS,
add_ignore_module,
)
from .dy2static.program_translator import (
ProgramTranslator,
Expand Down Expand Up @@ -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
):
Expand Down
11 changes: 11 additions & 0 deletions python/paddle/jit/dy2static/convert_call_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pdb
import re
import types
from typing import Any, List

import numpy

Expand Down Expand Up @@ -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.
Expand Down