Skip to content

Commit

Permalink
[Fluid Clean] Migrate program_translate.py/jit.py into paddle.jit dir (
Browse files Browse the repository at this point in the history
…#48240)

* [Fluid Clean] Migrate program_translate.py/jit.py into paddle.jit dir
  • Loading branch information
Aurelius84 authored Nov 28, 2022
1 parent fd9c91c commit ea830d4
Show file tree
Hide file tree
Showing 76 changed files with 179 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ paddle/fluid/operators/generated_op.cc
paddle/fluid/operators/generated_sparse_op.cc
paddle/phi/ops/compat/generated_sig.cc
paddle/phi/ops/compat/generated_sparse_sig.cc
paddle/phi/api/yaml/parsed_apis/
paddle/fluid/operators/generator/parsed_ops/
paddle/fluid/pybind/tmp_eager_op_function_impl.h
paddle/fluid/pybind/eager_op_function_impl.h
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/distributed/auto_parallel/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from paddle.fluid.framework import Parameter
from paddle.fluid.framework import program_guard
from paddle.fluid.executor import global_scope
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.dy2static.program_translator import (
StaticFunction,
)

Expand Down
10 changes: 3 additions & 7 deletions python/paddle/fluid/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,12 @@ def patch_program_cache(ipu_strategy):
Returns:
None
"""
from ..fluid.dygraph.dygraph_to_static.program_translator import (
ProgramCache,
)
from ..fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.dy2static.program_translator import (
CacheKey,
)
from ..fluid.dygraph.dygraph_to_static import logging_utils
from ..fluid.dygraph.dygraph_to_static.program_translator import (
ProgramCache,
MAX_TRACED_PROGRAM_COUNT,
)
from ..fluid.dygraph.dygraph_to_static import logging_utils
from ..fluid.dygraph.dygraph_to_static.partial_program import (
partial_program_from,
)
Expand Down
5 changes: 0 additions & 5 deletions python/paddle/fluid/dygraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
from . import learning_rate_scheduler
from .learning_rate_scheduler import *

from . import jit
from .jit import *

from . import io
from .io import *
Expand All @@ -46,7 +44,6 @@
from .static_runner import StaticModelRunner

from . import dygraph_to_static
from .dygraph_to_static import ProgramTranslator

from . import rnn
from .rnn import *
Expand All @@ -66,8 +63,6 @@
__all__ += parallel.__all__
__all__ += checkpoint.__all__
__all__ += learning_rate_scheduler.__all__
__all__ += jit.__all__
__all__ += io.__all__
__all__ += rnn.__all__
__all__ += ['ProgramTranslator']
__all__ += amp.__all__
2 changes: 1 addition & 1 deletion python/paddle/fluid/dygraph/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import warnings
from .. import core
from .base import guard
from paddle.fluid.dygraph.jit import _SaveLoadConfig
from paddle.jit.api import _SaveLoadConfig
from paddle.fluid.dygraph.io import (
_construct_program_holders,
_construct_params_and_buffers,
Expand Down
8 changes: 0 additions & 8 deletions python/paddle/fluid/dygraph/dygraph_to_static/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import ast_transformer
from .ast_transformer import *

from . import static_analysis
from .static_analysis import *

Expand All @@ -24,9 +21,6 @@
from . import variable_trans_func
from .variable_trans_func import *

from . import program_translator
from .program_translator import *

from . import convert_call_func
from .convert_call_func import *

Expand All @@ -36,10 +30,8 @@
from .logging_utils import *

__all__ = []
__all__ += ast_transformer.__all__
__all__ += loop_transformer.__all__
__all__ += static_analysis.__all__
__all__ += variable_trans_func.__all__
__all__ += program_translator.__all__
__all__ += convert_call_func.__all__
__all__ += logging_utils.__all__
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@
from paddle.fluid.dygraph.dygraph_to_static.logging_utils import (
TranslatorLogger,
)
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
StaticFunction,
)
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
convert_to_static,
)
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
unwrap_decorators,
)

from paddle.fluid.dygraph.dygraph_to_static.utils import is_paddle_func, unwrap
from paddle.fluid.dygraph.layers import Layer

Expand Down Expand Up @@ -185,6 +177,13 @@ def dyfunc(x):
# [1. 1. 1.]]
"""
# NOTE(Aurelius84): Fix it after all files migrating into jit.
from paddle.jit.dy2static.program_translator import (
convert_to_static,
unwrap_decorators,
StaticFunction,
)

translator_logger.log(
1, "Convert callable object: convert {}.".format(func)
)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/dygraph/static_runner.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 paddle.fluid.dygraph.jit import _SaveLoadConfig
from paddle.jit.api import _SaveLoadConfig
from paddle.fluid.dygraph.io import TranslatedLayer


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import Embedding, Layer, Linear
from paddle.fluid.dygraph.jit import declarative
from paddle.jit.api import declarative

from transformer_dygraph_model import MultiHeadAttention, PrePostProcessLayer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from paddle.fluid import layers
from paddle.fluid.dygraph import Layer
from paddle.fluid.dygraph.base import to_variable
from paddle.fluid.dygraph.jit import declarative
from paddle.jit.api import declarative
from paddle.fluid.dygraph.nn import Embedding
from seq2seq_utils import Seq2SeqModelHyperParams as args

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import paddle.fluid.param_attr as attr

from functools import reduce
from paddle.fluid.dygraph import declarative
from paddle.jit.api import declarative
from paddle.fluid.dygraph import Embedding, Layer, Linear
from paddle.static import Variable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator
from paddle.fluid.dygraph.jit import declarative
from paddle.jit import ProgramTranslator
from paddle.jit.api import declarative


@paddle.jit.to_static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from paddle import to_tensor
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph.jit import dygraph_to_static_func
from paddle.jit.api import dygraph_to_static_func
from paddle.fluid.dygraph.dygraph_to_static.utils import is_dygraph_api

SEED = 2020
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator
from paddle.jit import ProgramTranslator
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX

from bert_dygraph_model import PretrainModelLayer
Expand Down Expand Up @@ -118,7 +118,7 @@ def train(self, bert_config, data_reader, to_static):
step_idx += 1
if step_idx == STEP_NUM:
if to_static:
fluid.dygraph.jit.save(bert, self.model_save_prefix)
paddle.jit.save(bert, self.model_save_prefix)
else:
fluid.dygraph.save_dygraph(
bert.state_dict(), self.dy_state_dict_save_path
Expand Down Expand Up @@ -194,7 +194,7 @@ def predict_dygraph(self, bert_config, data):

def predict_dygraph_jit(self, data):
with fluid.dygraph.guard(place):
bert = fluid.dygraph.jit.load(self.model_save_prefix)
bert = paddle.jit.load(self.model_save_prefix)
bert.eval()

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import paddle.fluid as fluid
from paddle.fluid import ParamAttr
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph import ProgramTranslator
from paddle.jit import ProgramTranslator
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX

from predictor_utils import PredictorTools
Expand Down Expand Up @@ -751,7 +751,7 @@ def train_bmn(self, args, place, to_static):

if batch_id == args.train_batch_num:
if to_static:
fluid.dygraph.jit.save(bmn, self.model_save_prefix)
paddle.jit.save(bmn, self.model_save_prefix)
else:
fluid.dygraph.save_dygraph(
bmn.state_dict(), self.dy_param_path
Expand Down Expand Up @@ -865,7 +865,7 @@ def predict_static(self, data):

def predict_dygraph_jit(self, data):
with fluid.dygraph.guard(self.place):
bmn = fluid.dygraph.jit.load(self.model_save_prefix)
bmn = paddle.jit.load(self.model_save_prefix)
bmn.eval()

x = to_variable(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.jit import declarative
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.api import declarative
from paddle.jit.dy2static.program_translator import (
ProgramTranslator,
)
from paddle.fluid.dygraph.dygraph_to_static.utils import Dygraph2StaticException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import paddle
import paddle.fluid as fluid

from paddle.fluid.dygraph.jit import declarative
from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator
from paddle.fluid.dygraph.dygraph_to_static import convert_to_static
from paddle.jit.api import declarative
from paddle.jit import ProgramTranslator
from paddle.jit.dy2static import convert_to_static

from test_fetch_feed import Pool2D, Linear

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest
import numpy as np
import paddle.fluid as fluid
from paddle.fluid.dygraph import declarative
from paddle.jit.api import declarative

SEED = 2020
np.random.seed(SEED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import ProgramTranslator
from paddle.jit import ProgramTranslator
from paddle.fluid.dygraph.dygraph_to_static.convert_call_func import (
CONVERSION_OPTIONS,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import to_variable, declarative, ProgramTranslator
from paddle.fluid.dygraph import to_variable
from paddle.jit.api import declarative
from paddle.jit import ProgramTranslator
from paddle.fluid.dygraph.nn import Conv2DTranspose, BatchNorm

# Note: Set True to eliminate randomness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
from paddle.static import InputSpec
from paddle.fluid.dygraph import (
to_variable,
declarative,
ProgramTranslator,
Layer,
jit,
)
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.api import declarative
from paddle.jit import ProgramTranslator
from paddle.jit.dy2static.program_translator import (
ConcreteProgram,
StaticFunction,
)
Expand Down Expand Up @@ -131,8 +130,8 @@ def test_with_input_spec(self):

# 2. test save load
net.inner_function(x)
jit.save(net, self.model_path)
infer_net = fluid.dygraph.jit.load(self.model_path)
paddle.jit.save(net, self.model_path)
infer_net = paddle.jit.load(self.model_path)
pred = infer_net(x)
np.testing.assert_allclose(out.numpy(), pred.numpy(), rtol=1e-05)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest
import paddle
import numpy as np
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.dy2static.program_translator import (
StaticFunction,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import paddle
import paddle.fluid as fluid
from paddle.jit import to_static
from paddle.fluid.dygraph.dygraph_to_static.program_translator import (
from paddle.jit.dy2static.program_translator import (
ProgramTranslator,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import unittest
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.jit import declarative
from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator
from paddle.jit.api import declarative
from paddle.jit import ProgramTranslator

SEED = 2020

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator
from paddle.jit import ProgramTranslator
from paddle.static import InputSpec

program_translator = ProgramTranslator()
Expand Down
Loading

0 comments on commit ea830d4

Please sign in to comment.