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