未验证 提交 b55f7326 编写于 作者: Y YuanRisheng 提交者: GitHub

[Remove Fluid]move TranslatedLayer from fluid dir to jit dir (#49065)

* move translated layer

* fix build bugs

* fix unittest bug

* trigger ci
上级 930b209e
......@@ -20,7 +20,7 @@ import numpy as np
import paddle
import paddle.nn.quant.quant_layers as quant_layers
from paddle.fluid.log_helper import get_logger
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from . import fuse_utils
from . import utils
......
......@@ -27,7 +27,7 @@ from paddle.fluid.framework import IrGraph
from paddle.fluid.executor import Executor, global_scope
from paddle.fluid.param_attr import ParamAttr
from paddle.fluid.initializer import Constant
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.fluid.io import load_inference_model, save_inference_model
from ..quantization_pass import ReplaceFakeQuantDequantPass, QuantWeightPass
from paddle.fluid.log_helper import get_logger
......
......@@ -28,7 +28,7 @@ from paddle.fluid.optimizer import AdamOptimizer
from paddle.fluid.framework import IrGraph, _test_eager_guard
from paddle.fluid.contrib.slim.quantization import ImperativeQuantAware
from paddle.nn import Sequential
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn.layer import ReLU, LeakyReLU, Sigmoid, Softmax, PReLU
from paddle.nn import Linear, Conv2D, Softmax, BatchNorm2D, MaxPool2D
from paddle.fluid.log_helper import get_logger
......
......@@ -28,7 +28,7 @@ from paddle.fluid.contrib.slim.quantization import ImperativeQuantAware
from paddle.nn import Sequential
from paddle.nn import Linear, Conv2D, Softmax, Conv2DTranspose
from paddle.fluid.log_helper import get_logger
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn.quant.quant_layers import (
QuantizedConv2D,
QuantizedConv2DTranspose,
......
......@@ -33,7 +33,7 @@ from paddle.nn import Sequential
from paddle.nn import ReLU, ReLU6, LeakyReLU, Sigmoid, Softmax, PReLU
from paddle.nn import Linear, Conv2D, Softmax, BatchNorm2D, MaxPool2D
from paddle.fluid.log_helper import get_logger
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn.quant.quant_layers import (
QuantizedConv2D,
QuantizedConv2DTranspose,
......
......@@ -33,7 +33,7 @@ from paddle.nn import Sequential
from paddle.nn import ReLU, ReLU6, LeakyReLU, Sigmoid, Softmax, PReLU
from paddle.nn import Linear, Conv2D, Softmax, BatchNorm2D, MaxPool2D
from paddle.fluid.log_helper import get_logger
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn.quant.quant_layers import (
QuantizedConv2D,
QuantizedMatmul,
......
......@@ -23,7 +23,7 @@ import paddle.fluid.layers as layers
from paddle.fluid import core
from paddle.fluid.optimizer import AdamOptimizer
from paddle.fluid.contrib.slim.quantization import ImperativeQuantAware
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn.layer import ReLU, LeakyReLU, Sigmoid, Softmax, ReLU6
from paddle.nn import Linear, Conv2D, Softmax, BatchNorm
from paddle.fluid.log_helper import get_logger
......
......@@ -36,10 +36,6 @@ from .checkpoint import *
from . import learning_rate_scheduler
from .learning_rate_scheduler import *
from . import io
from .io import *
from . import static_runner
from .static_runner import StaticModelRunner
......@@ -56,5 +52,4 @@ __all__ += nn.__all__
__all__ += parallel.__all__
__all__ += checkpoint.__all__
__all__ += learning_rate_scheduler.__all__
__all__ += io.__all__
__all__ += amp.__all__
......@@ -32,7 +32,7 @@ import warnings
from .. import core
from .base import guard
from paddle.jit.api import _SaveLoadConfig
from paddle.fluid.dygraph.io import (
from paddle.jit.translated_layer import (
_construct_program_holders,
_construct_params_and_buffers,
)
......
......@@ -13,7 +13,7 @@
# limitations under the License.
from paddle.jit.api import _SaveLoadConfig
from paddle.fluid.dygraph.io import TranslatedLayer
from paddle.jit.translated_layer import TranslatedLayer
# NOTE: This class will be deprecated later.
......
......@@ -24,8 +24,8 @@ from predictor_utils import PredictorTools
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit import ProgramTranslator
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
program_translator = ProgramTranslator()
place = (
......
......@@ -24,8 +24,8 @@ import paddle
import paddle.fluid as fluid
from paddle.fluid import ParamAttr
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit import ProgramTranslator, to_static
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
SEED = 2000
DATATYPE = 'float32'
......
......@@ -26,10 +26,10 @@ import paddle
import paddle.fluid as fluid
from paddle import _legacy_C_ops
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.fluid.framework import _non_static_mode
from paddle.jit import ProgramTranslator
from paddle.jit.api import declarative
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
SEED = 2020
......
......@@ -24,8 +24,8 @@ import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph import to_variable
from paddle.fluid.dygraph.base import switch_to_static_graph
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.fluid.optimizer import AdamOptimizer
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn import Linear
SEED = 2020
......
......@@ -22,11 +22,11 @@ from predictor_utils import PredictorTools
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.fluid.initializer import MSRA
from paddle.fluid.param_attr import ParamAttr
from paddle.jit import ProgramTranslator
from paddle.jit.api import declarative
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn import BatchNorm, Linear
# Note: Set True to eliminate randomness.
......
......@@ -23,8 +23,8 @@ from predictor_utils import PredictorTools
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit import ProgramTranslator
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn import BatchNorm
SEED = 2020
......
......@@ -231,10 +231,10 @@ class TestResnet(unittest.TestCase):
self.temp_dir.name, "./inference/resnet_v2"
)
self.model_filename = (
"resnet_v2" + paddle.fluid.dygraph.io.INFER_MODEL_SUFFIX
"resnet_v2" + paddle.jit.translated_layer.INFER_MODEL_SUFFIX
)
self.params_filename = (
"resnet_v2" + paddle.fluid.dygraph.io.INFER_PARAMS_SUFFIX
"resnet_v2" + paddle.jit.translated_layer.INFER_PARAMS_SUFFIX
)
self.dy_state_dict_save_path = os.path.join(
self.temp_dir.name, "./resnet_v2.dygraph"
......
......@@ -20,10 +20,10 @@ import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit import ProgramTranslator
from paddle.jit.api import declarative
from paddle.jit.dy2static.partial_program import partial_program_from
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
SEED = 2020
......
......@@ -25,9 +25,9 @@ from predictor_utils import PredictorTools
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.base import to_variable
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.jit import ProgramTranslator
from paddle.jit.api import declarative
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.nn import BatchNorm, Linear
SEED = 2020
......
......@@ -24,9 +24,9 @@ import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.fluid import unique_name
from paddle.fluid.dygraph.io import INFER_PARAMS_INFO_SUFFIX
from paddle.fluid.layers.utils import flatten
from paddle.jit.api import declarative
from paddle.jit.translated_layer import INFER_PARAMS_INFO_SUFFIX
from paddle.nn import Linear
from paddle.static import InputSpec
......
......@@ -27,12 +27,6 @@ import paddle
# deprecated module import
from paddle import fluid
from paddle.fluid import core
from paddle.fluid.dygraph.io import (
INFER_MODEL_SUFFIX,
INFER_PARAMS_SUFFIX,
_construct_params_and_buffers,
_construct_program_holders,
)
from paddle.fluid.framework import (
EagerParamBase,
ParamBase,
......@@ -52,6 +46,12 @@ from paddle.fluid.io import (
_unpack_saved_dict,
)
from paddle.jit.api import _SaveLoadConfig
from paddle.jit.translated_layer import (
INFER_MODEL_SUFFIX,
INFER_PARAMS_SUFFIX,
_construct_params_and_buffers,
_construct_program_holders,
)
__all__ = []
......
......@@ -30,7 +30,6 @@ from paddle.autograd import no_grad
from paddle.distributed.fleet.base import role_maker
from paddle.fluid import core
from paddle.fluid.dygraph.base import to_variable
from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.fluid.dygraph.parallel import ParallelEnv
from paddle.fluid.executor import global_scope
from paddle.fluid.framework import Variable
......@@ -40,6 +39,7 @@ from paddle.fluid.io import is_belong_to_optimizer
from paddle.fluid.layers import collective
from paddle.fluid.layers.utils import flatten
from paddle.io import DataLoader, Dataset, DistributedBatchSampler
from paddle.jit.translated_layer import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX
from paddle.metric import Metric
from paddle.static import InputSpec as Input
......
......@@ -17,11 +17,11 @@ from .api import save
from .api import load
from .api import declarative as to_static
from .api import not_to_static
from .api import TranslatedLayer
from .dy2static.logging_utils import set_code_level, set_verbosity
from . import dy2static
from .dy2static.program_translator import ProgramTranslator
from .translated_layer import TranslatedLayer
__all__ = [ # noqa
'save',
......
......@@ -47,7 +47,7 @@ from .dy2static.program_translator import (
StaticFunction,
unwrap_decorators,
)
from paddle.fluid.dygraph.io import (
from paddle.jit.translated_layer import (
TranslatedLayer,
INFER_MODEL_SUFFIX,
INFER_PARAMS_SUFFIX,
......
......@@ -21,8 +21,8 @@ import paddle
from paddle.fluid import core
from paddle.fluid.dygraph import layers
from paddle.fluid.dygraph.base import switch_to_static_graph
from paddle.fluid.dygraph.io import TranslatedLayer
from paddle.fluid.layers.utils import flatten, pack_sequence_as
from paddle.jit.translated_layer import TranslatedLayer
from . import logging_utils
from .utils import (
......
......@@ -14,27 +14,24 @@
import os
import pickle
import numpy as np
import paddle
from paddle.fluid import core
from paddle.fluid import framework
from paddle.fluid import backward
from paddle.fluid import unique_name
from paddle import _legacy_C_ops
from paddle.fluid import backward, core, framework, unique_name
from paddle.fluid.dygraph import layers
from paddle.fluid.layers import nn
from paddle.fluid.layers.utils import _hash_with_id
from paddle.fluid.dygraph.base import switch_to_static_graph
from paddle.fluid.framework import _non_static_mode, OpProtoHolder
from paddle.fluid.executor import (
_is_enable_standalone_executor,
_is_dy2st_enable_standalone_executor,
_is_enable_standalone_executor,
)
from paddle.fluid.framework import OpProtoHolder, _non_static_mode
from paddle.fluid.layers.utils import _hash_with_id
from paddle.jit.dy2static.partial_program import (
add_build_strategy_for,
LazyInitialized,
add_build_strategy_for,
)
from paddle import _C_ops, _legacy_C_ops
__all__ = ['TranslatedLayer']
......@@ -58,7 +55,6 @@ def _load_program_desc(model_file_path):
raise ValueError(
"Unsupported program version: %d\n" % program_desc._version()
)
return program_desc
......@@ -1193,7 +1189,7 @@ def _append_block(
dest_program._sync_with_cpp()
offset_block_idx = dest_program.num_blocks - 1
parent_idx = 0
if src_program_desc.num_blocks() > 1:
for src_block_idx in range(1, src_program_desc.num_blocks()):
src_block = src_program_desc.block(src_block_idx)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册