diff --git a/python/paddle/amp/auto_cast.py b/python/paddle/amp/auto_cast.py index bcba245178d429460509d7b073f28c003a313178..9f0b6ac26927f68cc637e8dc5230c59fbe20aa37 100644 --- a/python/paddle/amp/auto_cast.py +++ b/python/paddle/amp/auto_cast.py @@ -59,6 +59,7 @@ BLACK_LIST = { 'trilinear_interp_v2', } + AMP_RELATED_FLAGS = [ 'FLAGS_cudnn_exhaustive_search', 'FLAGS_conv_workspace_size_limit', @@ -127,7 +128,7 @@ def amp_state(): return _g_amp_state_ -# NOTE(zhiqiu): similar as paddle.fluid.contrib.mixed_precision.fp16_lists.AutoMixedPrecisionLists._update_list +# NOTE(zhiqiu): similar as paddle.static.amp.fp16_lists.AutoMixedPrecisionLists._update_list # The reason why not use AutoMixedPrecisionLists is that custom_black_varnames is not suitable for imperative mode. def _update_list( custom_white_list, custom_black_list, level='O1', dtype='float16' diff --git a/python/paddle/distributed/fleet/meta_optimizers/amp_optimizer.py b/python/paddle/distributed/fleet/meta_optimizers/amp_optimizer.py index 2c0dbce0556de1805579463edf9d5c1fdf146246..de0aca0aea648f459a0d46903a54db969e7579d0 100755 --- a/python/paddle/distributed/fleet/meta_optimizers/amp_optimizer.py +++ b/python/paddle/distributed/fleet/meta_optimizers/amp_optimizer.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -import paddle.fluid.contrib.mixed_precision as mixed_precision +import paddle.static.amp as mixed_precision from .meta_optimizer_base import MetaOptimizerBase diff --git a/python/paddle/distributed/passes/auto_parallel_amp.py b/python/paddle/distributed/passes/auto_parallel_amp.py index 8f965bdd9502500eb7d364627ca445840a7862a6..c2e5933dbf965701689eb197b5974f37d4c92695 100644 --- a/python/paddle/distributed/passes/auto_parallel_amp.py +++ b/python/paddle/distributed/passes/auto_parallel_amp.py @@ -23,7 +23,9 @@ from paddle.distributed.auto_parallel.utils import ( set_var_dist_attr, ) from paddle.distributed.fleet.meta_optimizers.common import OpRole -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( +from paddle.fluid.data_feeder import check_type, check_variable_and_dtype +from paddle.framework import core +from paddle.static.amp.fp16_utils import ( AutoMixedPrecisionLists, _dtype_to_str, _is_in_black_varnames, @@ -35,8 +37,6 @@ from paddle.fluid.contrib.mixed_precision.fp16_utils import ( find_true_post_op, find_true_prev_op, ) -from paddle.fluid.data_feeder import check_type, check_variable_and_dtype -from paddle.framework import core from paddle.utils import unique_name from ..auto_parallel.process_mesh import ProcessMesh @@ -83,7 +83,7 @@ class AMPState: def _mark_black_white_ops(self, amp_lists): """ - this function is modified from paddle.fluid.contrib.mixed_precision + this function is modified from paddle.static.amp """ self._block._sync_with_cpp() ops = self._block.ops @@ -179,7 +179,7 @@ class AMPState: ): """ only for forward cast - modified from paddle.fluid.contrib.mixed_precision + modified from paddle.static.amp """ num_cast_ops = 0 var_name_dict = {} diff --git a/python/paddle/distributed/passes/auto_parallel_bf16.py b/python/paddle/distributed/passes/auto_parallel_bf16.py index 3344c6482446439b96bacb07ee1cd5997059773c..b733ab38ad742631cdcb61bb6c7095d3949abe88 100644 --- a/python/paddle/distributed/passes/auto_parallel_bf16.py +++ b/python/paddle/distributed/passes/auto_parallel_bf16.py @@ -26,22 +26,20 @@ from paddle.distributed.auto_parallel.utils import ( from paddle.distributed.fleet.meta_optimizers.common import OpRole from paddle.distributed.passes.pass_base import PassBase, register_pass from paddle.fluid import unique_name -from paddle.fluid.contrib.mixed_precision.bf16 import ( - AutoMixedPrecisionListsBF16, -) -from paddle.fluid.contrib.mixed_precision.bf16.amp_utils import ( +from paddle.fluid.framework import Block +from paddle.framework import core +from paddle.static.amp.bf16 import AutoMixedPrecisionListsBF16 +from paddle.static.amp.bf16.amp_utils import ( _dtype_to_str, _is_in_fp32_varnames, _valid_types, - find_op_index, find_true_post_op, ) -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( +from paddle.static.amp.fp16_utils import ( _rename_arg, + find_op_index, find_true_prev_op, ) -from paddle.fluid.framework import Block -from paddle.framework import core from ..auto_parallel.utils import is_backward_op, is_forward_op, is_loss_op diff --git a/python/paddle/distributed/passes/auto_parallel_fp16.py b/python/paddle/distributed/passes/auto_parallel_fp16.py index 53aba19b98fdf2b97bcab57024e60e69c070e504..1d61100b72f775c70e819a56d9fc7c83c706a869 100644 --- a/python/paddle/distributed/passes/auto_parallel_fp16.py +++ b/python/paddle/distributed/passes/auto_parallel_fp16.py @@ -26,16 +26,16 @@ from paddle.distributed.auto_parallel.utils import ( set_var_dist_attr, ) from paddle.distributed.fleet.meta_optimizers.common import OP_ROLE_KEY, OpRole -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( +from paddle.fluid.data_feeder import check_type, check_variable_and_dtype +from paddle.framework import core +from paddle.static import default_main_program, default_startup_program +from paddle.static.amp.fp16_utils import ( AutoMixedPrecisionLists, _dtype_to_str, _keep_layer_norm_scale_bias_to_fp32, _need_keep_fp32, _valid_types, ) -from paddle.fluid.data_feeder import check_type, check_variable_and_dtype -from paddle.framework import core -from paddle.static import default_main_program, default_startup_program from paddle.utils import unique_name from ..auto_parallel.process_mesh import ProcessMesh diff --git a/python/paddle/fluid/contrib/__init__.py b/python/paddle/fluid/contrib/__init__.py index 5ad924b49f215761e58f123e9b172cafbefac3c7..c001b87570ff76842495080767e36e83786e5795 100644 --- a/python/paddle/fluid/contrib/__init__.py +++ b/python/paddle/fluid/contrib/__init__.py @@ -22,8 +22,6 @@ from . import extend_optimizer from .extend_optimizer import * from . import model_stat from .model_stat import * -from . import mixed_precision -from .mixed_precision import * from . import layers from .layers import * from . import optimizer @@ -34,6 +32,5 @@ __all__ = [] __all__ += memory_usage_calc.__all__ __all__ += op_frequence.__all__ __all__ += extend_optimizer.__all__ -__all__ += ['mixed_precision'] __all__ += layers.__all__ __all__ += optimizer.__all__ diff --git a/python/paddle/fluid/contrib/layers/nn.py b/python/paddle/fluid/contrib/layers/nn.py index e9ff925fd8def6ba60d9afcbb82bc63c69d4448f..7ab225c8c9f825d60c7e910be92f0190106f3860 100644 --- a/python/paddle/fluid/contrib/layers/nn.py +++ b/python/paddle/fluid/contrib/layers/nn.py @@ -1587,7 +1587,7 @@ def fused_bn_add_act( ) loss = paddle.mean(loss) sgd = fluid.optimizer.SGD(learning_rate=0.001) - sgd = fluid.contrib.mixed_precision.decorate( + sgd = paddle.static.amp.decorate( sgd, use_dynamic_loss_scaling=True, init_loss_scaling=128.0) sgd.minimize(loss) diff --git a/python/paddle/fluid/contrib/mixed_precision/__init__.py b/python/paddle/fluid/contrib/mixed_precision/__init__.py deleted file mode 100644 index 07b507d61549a5bbefc12fd0f910357dbad3cbf4..0000000000000000000000000000000000000000 --- a/python/paddle/fluid/contrib/mixed_precision/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. -# -# 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. - -from . import decorator -from .decorator import * -from . import fp16_lists -from .fp16_lists import * -from . import fp16_utils -from .fp16_utils import * -from . import bf16 - -__all__ = [] -__all__ += decorator.__all__ -__all__ += fp16_lists.__all__ -__all__ += fp16_utils.__all__ diff --git a/python/paddle/fluid/contrib/tests/test_amp_list.py b/python/paddle/fluid/contrib/tests/test_amp_list.py index 4a30185229a9765787d5f8c2315c2a5ad86fdfc7..eb7860b9cfab7f5a3c80eb8e14c83bdee9bc03d6 100644 --- a/python/paddle/fluid/contrib/tests/test_amp_list.py +++ b/python/paddle/fluid/contrib/tests/test_amp_list.py @@ -14,7 +14,7 @@ import paddle import unittest -from paddle.fluid.contrib.mixed_precision.fp16_lists import ( +from paddle.static.amp.fp16_lists import ( AutoMixedPrecisionLists, ) diff --git a/python/paddle/fluid/contrib/tests/test_bf16_utils.py b/python/paddle/fluid/contrib/tests/test_bf16_utils.py index 5d528f226596ce65097eb0c4b7a71a17778c03c7..e3f36ca5b29658cbe3049ba4b07b64ca22aa1368 100644 --- a/python/paddle/fluid/contrib/tests/test_bf16_utils.py +++ b/python/paddle/fluid/contrib/tests/test_bf16_utils.py @@ -110,7 +110,7 @@ class AMPTest2(unittest.TestCase): def test_find_op_index(self): block = fluid.default_main_program().global_block() op_desc = core.OpDesc() - idx = amp.bf16.amp_utils.find_op_index(block.desc, op_desc) + idx = amp.fp16_utils.find_op_index(block.desc, op_desc) assert idx == -1 def test_is_in_fp32_varnames(self): diff --git a/python/paddle/fluid/contrib/tests/test_fp16_utils.py b/python/paddle/fluid/contrib/tests/test_fp16_utils.py index af245a30fed43b95a1b1658f1aefe9e645903152..83500adb426880377eb1399028cf2f0e44d4385c 100644 --- a/python/paddle/fluid/contrib/tests/test_fp16_utils.py +++ b/python/paddle/fluid/contrib/tests/test_fp16_utils.py @@ -15,7 +15,7 @@ import unittest import paddle.fluid as fluid from paddle.fluid import core -from paddle.fluid.contrib.mixed_precision import fp16_utils +from paddle.static.amp import fp16_utils import paddle paddle.enable_static() diff --git a/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py b/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py index a17495fde947737cc27250edba12fd4237762c1c..f99d640799764af631d02a2faef170a46de971e6 100644 --- a/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py +++ b/python/paddle/fluid/contrib/tests/test_image_classification_fp16.py @@ -136,7 +136,7 @@ def train(net_type, use_cuda, save_dirname, is_local): optimizer = fluid.optimizer.Lamb(learning_rate=0.001) - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( + amp_lists = paddle.static.amp.AutoMixedPrecisionLists( custom_black_varnames={"loss", "conv2d_0.w_0"} ) mp_optimizer = decorate( @@ -313,102 +313,66 @@ class TestImageClassification(unittest.TestCase): # infer(use_cuda, save_dirname) def test_amp_lists(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists() + amp_lists = paddle.static.amp.AutoMixedPrecisionLists() self.assertEqual(amp_lists.white_list, white_list) self.assertEqual(amp_lists.black_list, black_list) self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_1(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 1. w={'exp}, b=None white_list.add('exp') black_list.remove('exp') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( - {'exp'} - ) + amp_lists = paddle.static.amp.AutoMixedPrecisionLists({'exp'}) self.assertEqual(amp_lists.white_list, white_list) self.assertEqual(amp_lists.black_list, black_list) self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_2(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 2. w={'tanh'}, b=None white_list.add('tanh') gray_list.remove('tanh') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( - {'tanh'} - ) + amp_lists = paddle.static.amp.AutoMixedPrecisionLists({'tanh'}) self.assertEqual(amp_lists.white_list, white_list) self.assertEqual(amp_lists.black_list, black_list) self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_3(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 3. w={'lstm'}, b=None white_list.add('lstm') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( - {'lstm'} - ) + amp_lists = paddle.static.amp.AutoMixedPrecisionLists({'lstm'}) self.assertEqual(amp_lists.white_list, white_list) self.assertEqual(amp_lists.black_list, black_list) self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_4(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 4. w=None, b={'conv2d'} white_list.remove('conv2d') black_list.add('conv2d') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( + amp_lists = paddle.static.amp.AutoMixedPrecisionLists( custom_black_list={'conv2d'} ) self.assertEqual(amp_lists.white_list, white_list) @@ -416,21 +380,15 @@ class TestImageClassification(unittest.TestCase): self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_5(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 5. w=None, b={'tanh'} black_list.add('tanh') gray_list.remove('tanh') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( + amp_lists = paddle.static.amp.AutoMixedPrecisionLists( custom_black_list={'tanh'} ) self.assertEqual(amp_lists.white_list, white_list) @@ -438,20 +396,14 @@ class TestImageClassification(unittest.TestCase): self.assertEqual(amp_lists.gray_list, gray_list) def test_amp_lists_6(self): - white_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.white_list - ) - black_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.black_list - ) - gray_list = copy.copy( - fluid.contrib.mixed_precision.fp16_lists.gray_list - ) + white_list = copy.copy(paddle.static.amp.fp16_lists.white_list) + black_list = copy.copy(paddle.static.amp.fp16_lists.black_list) + gray_list = copy.copy(paddle.static.amp.fp16_lists.gray_list) # 6. w=None, b={'lstm'} black_list.add('lstm') - amp_lists = fluid.contrib.mixed_precision.AutoMixedPrecisionLists( + amp_lists = paddle.static.amp.AutoMixedPrecisionLists( custom_black_list={'lstm'} ) self.assertEqual(amp_lists.white_list, white_list) @@ -463,7 +415,7 @@ class TestImageClassification(unittest.TestCase): # raise ValueError self.assertRaises( ValueError, - fluid.contrib.mixed_precision.AutoMixedPrecisionLists, + paddle.static.amp.AutoMixedPrecisionLists, {'lstm'}, {'lstm'}, ) @@ -515,10 +467,8 @@ class TestAmpWithNonIterableDataLoader(unittest.TestCase): avg_cost = paddle.mean(cost) optimizer = fluid.optimizer.Lamb(learning_rate=0.001) - amp_lists = ( - fluid.contrib.mixed_precision.AutoMixedPrecisionLists( - custom_black_varnames={"loss", "conv2d_0.w_0"} - ) + amp_lists = paddle.static.amp.AutoMixedPrecisionLists( + custom_black_varnames={"loss", "conv2d_0.w_0"} ) mp_optimizer = decorate( optimizer=optimizer, diff --git a/python/paddle/fluid/contrib/tests/test_multi_precision_fp16_train.py b/python/paddle/fluid/contrib/tests/test_multi_precision_fp16_train.py index 7c6cf13bec5e92ec3774045be0e3a6831e081ca0..1d4873817ab3a2b1613dea3ec578fc0cf48e9ab5 100644 --- a/python/paddle/fluid/contrib/tests/test_multi_precision_fp16_train.py +++ b/python/paddle/fluid/contrib/tests/test_multi_precision_fp16_train.py @@ -18,7 +18,7 @@ import contextlib import unittest import numpy as np from paddle.io import Dataset -from paddle.fluid.contrib.mixed_precision.fp16_utils import cast_model_to_fp16 +from paddle.static.amp.fp16_utils import cast_model_to_fp16 paddle.enable_static() diff --git a/python/paddle/fluid/incubate/fleet/base/fleet_base.py b/python/paddle/fluid/incubate/fleet/base/fleet_base.py index c53090a52bde2a351d5659095ce4ca577a7c09db..2781c505cb3676fec13ba9056ca7973829dba096 100644 --- a/python/paddle/fluid/incubate/fleet/base/fleet_base.py +++ b/python/paddle/fluid/incubate/fleet/base/fleet_base.py @@ -21,7 +21,7 @@ from paddle.optimizer import SGD as SGD_v2 from paddle.fluid.incubate.fleet.base.mode import Mode from paddle.distributed.fleet.base.role_maker import RoleMakerBase -from paddle.fluid.contrib.mixed_precision.decorator import ( +from paddle.static.amp.decorator import ( OptimizerWithMixedPrecision, ) from . import mode diff --git a/python/paddle/fluid/incubate/fleet/collective/__init__.py b/python/paddle/fluid/incubate/fleet/collective/__init__.py index c18e77b29c2b256c90379e93641be2516f62b6a6..e0668bddc9b597d02e9ee0f3037d726be97ce448 100644 --- a/python/paddle/fluid/incubate/fleet/collective/__init__.py +++ b/python/paddle/fluid/incubate/fleet/collective/__init__.py @@ -555,7 +555,7 @@ class CollectiveOptimizer(DistributedOptimizer): self.raiseOptimizeError( "mixed_precision", self._optimizer.__class__.__name__ ) - self._optimizer = fluid.contrib.mixed_precision.decorate( + self._optimizer = paddle.static.amp.decorate( self._optimizer, init_loss_scaling=self._amp_loss_scaling, use_dynamic_loss_scaling=True, diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index 3b251d5be3e5e07acda5fd018b7d209388d84d17..1bab4f34317719ae4d806a5ca73bd4ac7ae86ed8 100755 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -4404,7 +4404,7 @@ class PipelineOptimizer: valid_optimizers = ( Optimizer, paddle.optimizer.Optimizer, - paddle.fluid.contrib.mixed_precision.decorator.OptimizerWithMixedPrecision, + paddle.static.amp.decorator.OptimizerWithMixedPrecision, ) if not isinstance(optimizer, valid_optimizers): raise ValueError( diff --git a/python/paddle/fluid/tests/unittests/asp/test_asp_optimize_static.py b/python/paddle/fluid/tests/unittests/asp/test_asp_optimize_static.py index 81d6bd86ee466bf411677a1f4801c67fcbbeba7a..67b14cc549c9f932bed8b8ca459a34cbf8d61a36 100644 --- a/python/paddle/fluid/tests/unittests/asp/test_asp_optimize_static.py +++ b/python/paddle/fluid/tests/unittests/asp/test_asp_optimize_static.py @@ -215,11 +215,7 @@ class TestASPStaticOptimize(unittest.TestCase): if core.is_compiled_with_cuda(): place = paddle.CUDAPlace(0) with fluid.program_guard(self.main_program, self.startup_program): - self.optimizer = ( - fluid.contrib.mixed_precision.decorator.decorate( - self.optimizer - ) - ) + self.optimizer = paddle.static.amp.decorate(self.optimizer) self.optimizer = paddle.incubate.asp.decorate(self.optimizer) self.optimizer.minimize(self.loss, self.startup_program) diff --git a/python/paddle/fluid/tests/unittests/auto_parallel/test_pass_bf16.py b/python/paddle/fluid/tests/unittests/auto_parallel/test_pass_bf16.py index f26908df2cf029b00c44b9feb389ffc0bfdcbbf2..2c72ccd9386c1546f208c2ec3be90c41d8853395 100644 --- a/python/paddle/fluid/tests/unittests/auto_parallel/test_pass_bf16.py +++ b/python/paddle/fluid/tests/unittests/auto_parallel/test_pass_bf16.py @@ -21,10 +21,10 @@ import paddle import paddle.fluid.core as core import paddle.nn as nn from paddle.distributed.fleet import auto -from paddle.fluid.contrib.mixed_precision.bf16.amp_utils import _valid_types -from paddle.fluid.contrib.mixed_precision.fp16_utils import find_true_prev_op from paddle.fluid.dygraph.parallel import ParallelEnv from paddle.static import InputSpec +from paddle.static.amp.bf16.amp_utils import _valid_types +from paddle.static.amp.fp16_utils import find_true_prev_op from paddle.vision.datasets import MNIST paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/collective/test_collective_optimizer.py b/python/paddle/fluid/tests/unittests/collective/test_collective_optimizer.py index 50664ac09ea0eb53773b2d2dc4cfc3e7da9b86bd..7f4bcbe34be9fc3e6002ca06ecde36957d0c22a9 100644 --- a/python/paddle/fluid/tests/unittests/collective/test_collective_optimizer.py +++ b/python/paddle/fluid/tests/unittests/collective/test_collective_optimizer.py @@ -26,6 +26,7 @@ import unittest +import paddle import paddle.fluid as fluid from paddle.fluid.incubate.fleet.collective import ( CollectiveOptimizer, @@ -61,7 +62,7 @@ class CollectiveOptimizerTest(unittest.TestCase): def test_amp_strategy(self): optimizer = fluid.optimizer.AdamOptimizer() - optimizer = fluid.contrib.mixed_precision.decorate( + optimizer = paddle.static.amp.decorate( optimizer, init_loss_scaling=1.0, use_dynamic_loss_scaling=True ) dist_strategy = DistributedStrategy() diff --git a/python/paddle/fluid/tests/unittests/mlu/test_layer_norm_op_mlu.py b/python/paddle/fluid/tests/unittests/mlu/test_layer_norm_op_mlu.py index dc0aa1d7d2b8eafdd83f7b1ffa276f309294249b..6e095c9b85144c7b61f3bebf8b4269f6df80489b 100644 --- a/python/paddle/fluid/tests/unittests/mlu/test_layer_norm_op_mlu.py +++ b/python/paddle/fluid/tests/unittests/mlu/test_layer_norm_op_mlu.py @@ -25,7 +25,7 @@ import sys sys.path.append('..') from op_test import _set_use_system_allocator from paddle.fluid import Program, program_guard -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( +from paddle.static.amp.fp16_utils import ( _keep_layer_norm_scale_bias_to_fp32, ) from test_layer_norm_op import ( diff --git a/python/paddle/fluid/tests/unittests/npu/test_amp_check_finite_and_scale_op_npu.py b/python/paddle/fluid/tests/unittests/npu/test_amp_check_finite_and_scale_op_npu.py index 43e3c44182de08ff1f967da38bc1e55fffcdcc91..d61e6ed9500858abf757d91dec46f035819ee63a 100644 --- a/python/paddle/fluid/tests/unittests/npu/test_amp_check_finite_and_scale_op_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_amp_check_finite_and_scale_op_npu.py @@ -21,7 +21,7 @@ from op_test import OpTest, skip_check_grad_ci import paddle import paddle.fluid as fluid from paddle.fluid import compiler, Program, program_guard -from paddle.fluid.contrib.mixed_precision.amp_nn import check_finite_and_unscale +from paddle.static.amp.amp_nn import check_finite_and_unscale paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/npu/test_mixed_precision_npu.py b/python/paddle/fluid/tests/unittests/npu/test_mixed_precision_npu.py index de85b7eefdf08f1dab73feb6ad383eefef4c1ce5..d5d048771f043ff6483b809657ea520cdb7a0ff6 100644 --- a/python/paddle/fluid/tests/unittests/npu/test_mixed_precision_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_mixed_precision_npu.py @@ -17,7 +17,7 @@ import sys import paddle import paddle.fluid as fluid from paddle.fluid import core -from paddle.fluid.contrib.mixed_precision import fp16_utils +from paddle.static.amp import fp16_utils import paddle.nn as nn import paddle.static as static import numpy as np diff --git a/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_min_op_npu.py b/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_min_op_npu.py index 48edac9ab331fc6981925708a4cda1d87c53be98..862a69e19ac2e059f388b4371d6ee47dff4378d6 100644 --- a/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_min_op_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_min_op_npu.py @@ -21,7 +21,7 @@ sys.path.append("..") from op_test import OpTest import paddle import paddle.fluid as fluid -import paddle.fluid.contrib.mixed_precision.amp_nn as amp_nn +import paddle.static.amp.amp_nn as amp_nn from test_update_loss_scaling_op_npu import TestUpdateLossScalingOpBad paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_op_npu.py b/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_op_npu.py index 8d364af89e3cb5a5b1d02cd59e6a370dc9859e93..07fb19031c0764012f45804a355e4f9fb84b125c 100644 --- a/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_op_npu.py +++ b/python/paddle/fluid/tests/unittests/npu/test_update_loss_scaling_op_npu.py @@ -20,7 +20,7 @@ sys.path.append("..") from op_test import OpTest import paddle import paddle.fluid as fluid -import paddle.fluid.contrib.mixed_precision.amp_nn as amp_nn +import paddle.static.amp.amp_nn as amp_nn paddle.enable_static() SEED = 2021 diff --git a/python/paddle/fluid/tests/unittests/test_amp_check_finite_and_scale_op.py b/python/paddle/fluid/tests/unittests/test_amp_check_finite_and_scale_op.py index a840b582474f3448b0fe308c3571c88a55970736..e63c2846f3215ef27b29e9b781a8da43ae7358a9 100644 --- a/python/paddle/fluid/tests/unittests/test_amp_check_finite_and_scale_op.py +++ b/python/paddle/fluid/tests/unittests/test_amp_check_finite_and_scale_op.py @@ -17,7 +17,7 @@ import unittest import numpy as np from op_test import OpTest -import paddle.fluid.contrib.mixed_precision.amp_nn as amp_nn +import paddle.static.amp.amp_nn as amp_nn def check_finite_and_unscale_wrapper(x, scale): diff --git a/python/paddle/fluid/tests/unittests/test_fuse_bn_act_pass.py b/python/paddle/fluid/tests/unittests/test_fuse_bn_act_pass.py index ccb397fc19c74d10f115b9b6d5e0ca9e71c1d9b7..9e067454482d79b8292a35fd79d357c4d0ab0f78 100644 --- a/python/paddle/fluid/tests/unittests/test_fuse_bn_act_pass.py +++ b/python/paddle/fluid/tests/unittests/test_fuse_bn_act_pass.py @@ -61,7 +61,7 @@ class TestFuseBatchNormActPass(unittest.TestCase): loss = paddle.mean(loss) sgd = fluid.optimizer.SGD(learning_rate=0.001) if use_cuda: - sgd = fluid.contrib.mixed_precision.decorate( + sgd = paddle.static.amp.decorate( sgd, use_dynamic_loss_scaling=True, init_loss_scaling=128.0 ) sgd.minimize(loss) diff --git a/python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py b/python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py index 43578016e90ac987b9da86b591d87009c5fa6b2d..a8d0f89c86649d3e823b7c1f18d348b2fa9d105b 100644 --- a/python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py +++ b/python/paddle/fluid/tests/unittests/test_fuse_bn_add_act_pass.py @@ -112,7 +112,7 @@ class TestFusedBnAddActAPI(unittest.TestCase): ) loss = paddle.mean(loss) sgd = fluid.optimizer.SGD(learning_rate=0.001) - sgd = fluid.contrib.mixed_precision.decorate( + sgd = paddle.static.amp.decorate( sgd, use_dynamic_loss_scaling=True, init_loss_scaling=128.0 ) sgd.minimize(loss) @@ -173,7 +173,7 @@ class TestFusedBnAddActAPI(unittest.TestCase): ) loss = paddle.mean(loss) sgd = fluid.optimizer.SGD(learning_rate=0.001) - sgd = fluid.contrib.mixed_precision.decorate( + sgd = paddle.static.amp.decorate( sgd, use_dynamic_loss_scaling=True, init_loss_scaling=128.0 ) sgd.minimize(loss) diff --git a/python/paddle/fluid/tests/unittests/test_layer_norm_op.py b/python/paddle/fluid/tests/unittests/test_layer_norm_op.py index 35921c7e7033ec35c482e8a6604547ffdaca09a0..0240b411b047897514e18fc65119464619075ad2 100644 --- a/python/paddle/fluid/tests/unittests/test_layer_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_layer_norm_op.py @@ -24,9 +24,7 @@ import paddle.fluid as fluid import paddle.fluid.core as core import paddle.nn.functional as F from paddle.fluid import Program, program_guard -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( - _keep_layer_norm_scale_bias_to_fp32, -) +from paddle.static.amp.fp16_utils import _keep_layer_norm_scale_bias_to_fp32 paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/test_update_loss_scaling_op.py b/python/paddle/fluid/tests/unittests/test_update_loss_scaling_op.py index 2d945496294e40f055e6acdbcbea440046000e08..00b943df85dc9fd6be34650b4b94e9f3b6a4796f 100644 --- a/python/paddle/fluid/tests/unittests/test_update_loss_scaling_op.py +++ b/python/paddle/fluid/tests/unittests/test_update_loss_scaling_op.py @@ -18,7 +18,7 @@ import numpy as np from op_test import OpTest import paddle.fluid as fluid -import paddle.fluid.contrib.mixed_precision.amp_nn as amp_nn +import paddle.static.amp.amp_nn as amp_nn def update_loss_scaling_wrapper( diff --git a/python/paddle/fluid/tests/unittests/xpu/test_update_loss_scaling_op_xpu.py b/python/paddle/fluid/tests/unittests/xpu/test_update_loss_scaling_op_xpu.py index ad1cf1a5192b22783f29f1620ee6dbe50049557e..44d79efc97bfd1c66ce3cbaaa53b8354cd65712b 100644 --- a/python/paddle/fluid/tests/unittests/xpu/test_update_loss_scaling_op_xpu.py +++ b/python/paddle/fluid/tests/unittests/xpu/test_update_loss_scaling_op_xpu.py @@ -26,7 +26,7 @@ from xpu.get_test_cover_info import ( import paddle import paddle.fluid as fluid -import paddle.fluid.contrib.mixed_precision.amp_nn as amp_nn +import paddle.static.amp.amp_nn as amp_nn paddle.enable_static() diff --git a/python/paddle/jit/dy2static/partial_program.py b/python/paddle/jit/dy2static/partial_program.py index 1b9908a6608a715f324afc8d827f85a3e3454686..040ef36854f3fb9db4d0684cd861fd3febba26f0 100644 --- a/python/paddle/jit/dy2static/partial_program.py +++ b/python/paddle/jit/dy2static/partial_program.py @@ -21,13 +21,6 @@ from paddle import _legacy_C_ops from paddle.amp.auto_cast import _in_amp_guard, _in_pure_fp16_guard from paddle.fluid import backward, core, framework, program_guard from paddle.fluid.compiler import BuildStrategy -from paddle.fluid.contrib.mixed_precision.decorator import ( - AutoMixedPrecisionLists, -) -from paddle.fluid.contrib.mixed_precision.fp16_utils import ( - cast_model_to_fp16, - rewrite_program, -) from paddle.fluid.dygraph import layers from paddle.fluid.dygraph.base import switch_to_static_graph from paddle.fluid.executor import ( @@ -189,7 +182,7 @@ class PartialProgramLayer: if tracer: custom_white_list, custom_black_list = tracer._get_amp_op_list() # For AMP training - self._amp_list = AutoMixedPrecisionLists( + self._amp_list = paddle.static.amp.fp16_lists.AutoMixedPrecisionLists( custom_white_list=custom_white_list, custom_black_list=custom_black_list, ) @@ -238,7 +231,9 @@ class PartialProgramLayer: def _create_amp_program(self, is_infer_mode=False): amp_program = self._origin_main_program.clone(for_test=is_infer_mode) with program_guard(amp_program): - rewrite_program(amp_program, self._amp_list) + paddle.static.amp.fp16_utils.rewrite_program( + amp_program, self._amp_list + ) if is_infer_mode: return amp_program else: @@ -252,7 +247,7 @@ class PartialProgramLayer: for_test=is_infer_mode ) with program_guard(pure_fp16_program): - cast_model_to_fp16( + paddle.static.amp.fp16_utils.cast_model_to_fp16( pure_fp16_program, self._amp_list, use_fp16_guard=False ) if is_infer_mode: diff --git a/python/paddle/static/amp/__init__.py b/python/paddle/static/amp/__init__.py index ffcfa404cd3567e1f6784f274f90f0f436f0f9da..01832fd536769bff0b5613d399d35d61131cad5c 100644 --- a/python/paddle/static/amp/__init__.py +++ b/python/paddle/static/amp/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2020 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. @@ -12,14 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ...fluid.contrib.mixed_precision import decorate # noqa: F401 -from ...fluid.contrib.mixed_precision import CustomOpLists # noqa: F401 -from ...fluid.contrib.mixed_precision import ( - AutoMixedPrecisionLists, -) # noqa: F401 -from ...fluid.contrib.mixed_precision import fp16_guard # noqa: F401 -from ...fluid.contrib.mixed_precision import cast_model_to_fp16 # noqa: F401 -from ...fluid.contrib.mixed_precision import ( - cast_parameters_to_fp16, -) # noqa: F401 -from ...fluid.contrib.mixed_precision import bf16 # noqa: F401 +from . import decorator +from .decorator import decorate +from . import fp16_lists +from .fp16_lists import CustomOpLists, AutoMixedPrecisionLists +from . import fp16_utils +from .fp16_utils import fp16_guard, cast_model_to_fp16, cast_parameters_to_fp16 +from . import bf16 +from .bf16 import bf16_guard + +__all__ = [] +__all__ += decorator.__all__ +__all__ += fp16_lists.__all__ +__all__ += fp16_utils.__all__ diff --git a/python/paddle/fluid/contrib/mixed_precision/amp_nn.py b/python/paddle/static/amp/amp_nn.py similarity index 98% rename from python/paddle/fluid/contrib/mixed_precision/amp_nn.py rename to python/paddle/static/amp/amp_nn.py index f336c87a11e10a8fb3b710c933c62d35c2ea80ee..b20f702b44f79c9117409051ee3d86cd555ce97d 100644 --- a/python/paddle/fluid/contrib/mixed_precision/amp_nn.py +++ b/python/paddle/static/amp/amp_nn.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from paddle.fluid.data_feeder import check_variable_and_dtype, check_type -from paddle.fluid.layer_helper import LayerHelper -from paddle.fluid.framework import Variable, in_dygraph_mode -from paddle.fluid import core from paddle import _C_ops +from paddle.fluid import core +from paddle.fluid.data_feeder import check_type, check_variable_and_dtype +from paddle.fluid.framework import Variable, in_dygraph_mode +from paddle.fluid.layer_helper import LayerHelper __all__ = ['check_finite_and_unscale', 'update_loss_scaling'] diff --git a/python/paddle/fluid/contrib/mixed_precision/bf16/__init__.py b/python/paddle/static/amp/bf16/__init__.py similarity index 76% rename from python/paddle/fluid/contrib/mixed_precision/bf16/__init__.py rename to python/paddle/static/amp/bf16/__init__.py index 2e5e8451d6e181710dd711038f1c63b009e36899..82b616b299447c2a297d2dd5e718e8ef4a09b085 100644 --- a/python/paddle/fluid/contrib/mixed_precision/bf16/__init__.py +++ b/python/paddle/static/amp/bf16/__init__.py @@ -13,11 +13,17 @@ # limitations under the License. from . import amp_lists -from .amp_lists import * +from .amp_lists import AutoMixedPrecisionListsBF16 from . import amp_utils -from .amp_utils import * +from .amp_utils import ( + bf16_guard, + rewrite_program_bf16, + cast_model_to_bf16, + cast_parameters_to_bf16, + convert_float_to_uint16, +) from . import decorator -from .decorator import * +from .decorator import decorate_bf16 __all__ = [] __all__ += decorator.__all__ diff --git a/python/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py b/python/paddle/static/amp/bf16/amp_lists.py similarity index 93% rename from python/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py rename to python/paddle/static/amp/bf16/amp_lists.py index 180e28ddab351499f7e3ecf65a8384a32bd29454..d1878a3367fbc7a72a9cc90cea7028a6893ce37d 100644 --- a/python/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py +++ b/python/paddle/static/amp/bf16/amp_lists.py @@ -13,13 +13,12 @@ # limitations under the License. import copy + from paddle.fluid import core -from ..fp16_lists import ( - white_list as white_list_fp16, - black_list as black_list_fp16, - gray_list as gray_list_fp16, -) +from ..fp16_lists import black_list as black_list_fp16 +from ..fp16_lists import gray_list as gray_list_fp16 +from ..fp16_lists import white_list as white_list_fp16 __all__ = ["AutoMixedPrecisionListsBF16"] @@ -40,7 +39,7 @@ class AutoMixedPrecisionListsBF16: import paddle paddle.enable_static() with paddle.static.amp.bf16_guard(): - paddle.static.amp.AutoMixedPrecisionListsBF16(custom_fp32_list={'lstm'}) + paddle.static.amp.bf16.AutoMixedPrecisionListsBF16(custom_fp32_list={'lstm'}) """ def __init__( diff --git a/python/paddle/fluid/contrib/mixed_precision/bf16/amp_utils.py b/python/paddle/static/amp/bf16/amp_utils.py similarity index 99% rename from python/paddle/fluid/contrib/mixed_precision/bf16/amp_utils.py rename to python/paddle/static/amp/bf16/amp_utils.py index 25468b563aa1280a5c700fd370d755bd394b01ac..cf8c82127b3b45f29559444a65bf9847124ccaf3 100644 --- a/python/paddle/fluid/contrib/mixed_precision/bf16/amp_utils.py +++ b/python/paddle/static/amp/bf16/amp_utils.py @@ -13,24 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .... import core -from .... import framework -from .... import global_scope -from ....log_helper import get_logger -from ....wrapped_decorator import signature_safe_contextmanager -from .amp_lists import AutoMixedPrecisionListsBF16 +import collections +import logging +import struct + +import numpy as np + +from paddle.fluid import core, framework, global_scope +from paddle.fluid.log_helper import get_logger +from paddle.fluid.wrapped_decorator import signature_safe_contextmanager + from ..fp16_utils import ( - find_true_prev_op, - find_true_post_op, _rename_arg, - find_op_index, _rename_op_input, + find_true_post_op, + find_true_prev_op, ) - -import collections -import struct -import logging -import numpy as np +from .amp_lists import AutoMixedPrecisionListsBF16 __all__ = [ "bf16_guard", diff --git a/python/paddle/fluid/contrib/mixed_precision/bf16/decorator.py b/python/paddle/static/amp/bf16/decorator.py similarity index 99% rename from python/paddle/fluid/contrib/mixed_precision/bf16/decorator.py rename to python/paddle/static/amp/bf16/decorator.py index d1648e81082638a0b734aeaf8ae90bce930b247e..20286d3eebca5fead08b8e0e1f291478e0bb2080 100644 --- a/python/paddle/fluid/contrib/mixed_precision/bf16/decorator.py +++ b/python/paddle/static/amp/bf16/decorator.py @@ -12,22 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +import types +import warnings + import paddle -from paddle.fluid import ( - core, - default_main_program, - layers, - program_guard, - unique_name, -) +from paddle.fluid import core, default_main_program, program_guard, unique_name + +from .amp_lists import AutoMixedPrecisionListsBF16 from .amp_utils import ( - rewrite_program_bf16, cast_model_to_bf16, cast_parameters_to_bf16, + rewrite_program_bf16, ) -from .amp_lists import AutoMixedPrecisionListsBF16 -import types -import warnings __all__ = ["decorate_bf16"] diff --git a/python/paddle/fluid/contrib/mixed_precision/decorator.py b/python/paddle/static/amp/decorator.py similarity index 98% rename from python/paddle/fluid/contrib/mixed_precision/decorator.py rename to python/paddle/static/amp/decorator.py index 68b3e7472d9647627ab2ed32f5b7a9e1662ac89e..ba33f6b391b0b825ad87ae6ecbf1a14778cf4b2e 100644 --- a/python/paddle/fluid/contrib/mixed_precision/decorator.py +++ b/python/paddle/static/amp/decorator.py @@ -12,24 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ... import core -from ... import default_main_program -from ... import default_startup_program -from ... import framework -from ... import layers -from ... import program_guard -from ... import unique_name -from . import fp16_utils -from .fp16_utils import rewrite_program -from .fp16_utils import cast_model_to_fp16 -from .fp16_utils import cast_parameters_to_fp16 -from .fp16_utils import update_role_var_grad -from .fp16_lists import AutoMixedPrecisionLists -from .amp_nn import check_finite_and_unscale -from .amp_nn import update_loss_scaling import types import warnings + import paddle +from paddle.fluid import ( + core, + default_main_program, + default_startup_program, + layers, + program_guard, + unique_name, +) + +from .amp_nn import check_finite_and_unscale, update_loss_scaling +from .fp16_lists import AutoMixedPrecisionLists +from .fp16_utils import ( + cast_model_to_fp16, + cast_parameters_to_fp16, + rewrite_program, + update_role_var_grad, +) __all__ = ["decorate"] diff --git a/python/paddle/fluid/contrib/mixed_precision/fp16_lists.py b/python/paddle/static/amp/fp16_lists.py similarity index 99% rename from python/paddle/fluid/contrib/mixed_precision/fp16_lists.py rename to python/paddle/static/amp/fp16_lists.py index 101af59861880898c4d5bdfb80536659f1648769..b2acd0bb5156ddab063a02304dd09d199ee38c80 100644 --- a/python/paddle/fluid/contrib/mixed_precision/fp16_lists.py +++ b/python/paddle/static/amp/fp16_lists.py @@ -13,7 +13,8 @@ # limitations under the License. import copy -from ... import core + +from paddle.fluid import core __all__ = ["CustomOpLists", "AutoMixedPrecisionLists"] diff --git a/python/paddle/fluid/contrib/mixed_precision/fp16_utils.py b/python/paddle/static/amp/fp16_utils.py similarity index 99% rename from python/paddle/fluid/contrib/mixed_precision/fp16_utils.py rename to python/paddle/static/amp/fp16_utils.py index e50a2457147e12d4497c90ad297d08bcade52736..c9cee2ab8d25cf96909896453703acfb483087e7 100644 --- a/python/paddle/fluid/contrib/mixed_precision/fp16_utils.py +++ b/python/paddle/static/amp/fp16_utils.py @@ -12,17 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ... import core -from ... import framework -from ... import layers -from ... import global_scope -from ...log_helper import get_logger -from ...wrapped_decorator import signature_safe_contextmanager -from .fp16_lists import AutoMixedPrecisionLists import collections import logging + import numpy as np +from paddle.fluid import core, framework, global_scope +from paddle.fluid.log_helper import get_logger +from paddle.fluid.wrapped_decorator import signature_safe_contextmanager + +from .fp16_lists import AutoMixedPrecisionLists + __all__ = ["fp16_guard", "cast_model_to_fp16", "cast_parameters_to_fp16"] _logger = get_logger( diff --git a/python/setup.py.in b/python/setup.py.in index d6d01fc4b0a6bf5db880b489820baaecb1eb55d9..71a1cfb748198aaf6a5b3bfa05ba2c0af19e5bf5 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -337,8 +337,6 @@ packages=['paddle', 'paddle.fluid.dataloader', 'paddle.fluid.contrib', 'paddle.fluid.contrib.extend_optimizer', - 'paddle.fluid.contrib.mixed_precision', - 'paddle.fluid.contrib.mixed_precision.bf16', 'paddle.fluid.contrib.layers', 'paddle.fluid.transpiler', 'paddle.fluid.transpiler.details', @@ -400,6 +398,7 @@ packages=['paddle', 'paddle.static', 'paddle.static.nn', 'paddle.static.amp', + 'paddle.static.amp.bf16', 'paddle.static.quantization', 'paddle.quantization', 'paddle.quantization.imperative', diff --git a/setup.py b/setup.py index 177bb64d2842800f604c7bb84b42a1ce2fa3cc60..572d813c46c19b11e12409d967d8e97dd9005214 100644 --- a/setup.py +++ b/setup.py @@ -1236,8 +1236,6 @@ def get_setup_parameters(): 'paddle.fluid.dataloader', 'paddle.fluid.contrib', 'paddle.fluid.contrib.extend_optimizer', - 'paddle.fluid.contrib.mixed_precision', - 'paddle.fluid.contrib.mixed_precision.bf16', 'paddle.fluid.contrib.layers', 'paddle.fluid.transpiler', 'paddle.fluid.transpiler.details', @@ -1299,6 +1297,7 @@ def get_setup_parameters(): 'paddle.static', 'paddle.static.nn', 'paddle.static.amp', + 'paddle.static.amp.bf16', 'paddle.static.quantization', 'paddle.quantization', 'paddle.quantization.imperative',