Paddle-2.0 API directory migration (#25898)
* Directory migration, test=develop * Change imperative from paddle init to paddle framework, test=develop * Fixed jit bug, test=develop * default static mode, test=develop * fixed format and create parameter belongs to framework, test=develop * Fixed import package, test=develop * fix __init__ format, test=develop * fixed alias problem * fixed paddle.enable_imperative problems, test=develop * Add unittest * delete install_check comment * Fixed unittest timeout * fixed unittest error * move Program default_xx_program to static package * optimize unittest method * fixed framework __init__ format * fixed jit path * delete alias * move jit to paddle * Fixed unittest format * fixed paddle.default_main_program * Fixed save load API in paddle __init__.py * fixed ci paddle.imperative.to_variablerevert-24895-update_cub
parent
cd7b55a221
commit
2efcb481c8
@ -1,44 +0,0 @@
|
||||
# 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.
|
||||
# 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.
|
||||
|
||||
__all__ = [
|
||||
'fc',
|
||||
'batch_norm',
|
||||
'embedding',
|
||||
'bilinear_tensor_product'
|
||||
'conv2d'
|
||||
'conv2d_transpose'
|
||||
'conv3d'
|
||||
'conv3d_transpose'
|
||||
'create_parameter'
|
||||
'crf_decoding'
|
||||
'data_norm'
|
||||
'deformable_conv'
|
||||
'group_norm'
|
||||
'hsigmoid'
|
||||
'instance_norm'
|
||||
'layer_norm'
|
||||
'multi_box_head'
|
||||
'nce'
|
||||
'prelu'
|
||||
'row_conv'
|
||||
'spectral_norm',
|
||||
]
|
||||
|
||||
from ..fluid.layers import fc, batch_norm, bilinear_tensor_product, \
|
||||
conv2d, conv2d_transpose, conv3d, conv3d_transpose, create_parameter, \
|
||||
crf_decoding, data_norm, deformable_conv, group_norm, hsigmoid, instance_norm, \
|
||||
layer_norm, multi_box_head, nce, prelu, row_conv, spectral_norm
|
||||
|
||||
from ..fluid.input import embedding
|
@ -0,0 +1,181 @@
|
||||
# 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.
|
||||
# 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 __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
import unittest
|
||||
import numpy as np
|
||||
import paddle
|
||||
|
||||
|
||||
class TestDirectory(unittest.TestCase):
|
||||
def get_import_command(self, module):
|
||||
paths = module.split('.')
|
||||
if len(paths) <= 1:
|
||||
return module
|
||||
package = '.'.join(paths[:-1])
|
||||
func = paths[-1]
|
||||
cmd = 'from {} import {}'.format(package, func)
|
||||
return cmd
|
||||
|
||||
def test_new_directory(self):
|
||||
new_directory = [
|
||||
'paddle.enable_static', 'paddle.disable_static',
|
||||
'paddle.in_dynamic_mode', 'paddle.to_variable', 'paddle.grad',
|
||||
'paddle.no_grad', 'paddle.save', 'paddle.load',
|
||||
'paddle.static.save', 'paddle.static.load',
|
||||
'paddle.BackwardStrategy', 'paddle.ParallelEnv',
|
||||
'paddle.prepare_context', 'paddle.DataParallel', 'paddle.jit',
|
||||
'paddle.jit.TracedLayer', 'paddle.jit.to_static',
|
||||
'paddle.jit.ProgramTranslator', 'paddle.jit.TranslatedLayer',
|
||||
'paddle.jit.save', 'paddle.jit.load', 'paddle.jit.SaveLoadConfig',
|
||||
'paddle.NoamDecay', 'paddle.PiecewiseDecay',
|
||||
'paddle.NaturalExpDecay', 'paddle.ExponentialDecay',
|
||||
'paddle.InverseTimeDecay', 'paddle.PolynomialDecay',
|
||||
'paddle.CosineDecay', 'paddle.static.Executor',
|
||||
'paddle.static.global_scope', 'paddle.static.scope_guard',
|
||||
'paddle.static.append_backward', 'paddle.static.gradients',
|
||||
'paddle.static.BuildStrategy', 'paddle.static.CompiledProgram',
|
||||
'paddle.static.ExecutionStrategy',
|
||||
'paddle.static.default_main_program',
|
||||
'paddle.static.default_startup_program', 'paddle.static.Program',
|
||||
'paddle.static.name_scope', 'paddle.static.program_guard',
|
||||
'paddle.static.Print', 'paddle.static.py_func',
|
||||
'paddle.static.ParallelExecutor',
|
||||
'paddle.static.WeightNormParamAttr', 'paddle.static.nn.fc',
|
||||
'paddle.static.nn.batch_norm',
|
||||
'paddle.static.nn.bilinear_tensor_product',
|
||||
'paddle.static.nn.conv2d', 'paddle.static.nn.conv2d_transpose',
|
||||
'paddle.static.nn.conv3d', 'paddle.static.nn.conv3d_transpose',
|
||||
'paddle.static.nn.create_parameter',
|
||||
'paddle.static.nn.crf_decoding', 'paddle.static.nn.data_norm',
|
||||
'paddle.static.nn.deformable_conv', 'paddle.static.nn.group_norm',
|
||||
'paddle.static.nn.hsigmoid', 'paddle.static.nn.instance_norm',
|
||||
'paddle.static.nn.layer_norm', 'paddle.static.nn.multi_box_head',
|
||||
'paddle.static.nn.nce', 'paddle.static.nn.prelu',
|
||||
'paddle.static.nn.row_conv', 'paddle.static.nn.spectral_norm',
|
||||
'paddle.static.nn.embedding'
|
||||
]
|
||||
|
||||
import_file = 'run_import_modules.py'
|
||||
|
||||
with open(import_file, "w") as wb:
|
||||
for module in new_directory:
|
||||
run_cmd = self.get_import_command(module)
|
||||
wb.write("{}\n".format(run_cmd))
|
||||
|
||||
_python = sys.executable
|
||||
|
||||
ps_cmd = "{} {}".format(_python, import_file)
|
||||
ps_proc = subprocess.Popen(
|
||||
ps_cmd.strip().split(" "),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = ps_proc.communicate()
|
||||
|
||||
assert "Error" not in str(stderr), "Error: Can't" \
|
||||
" import Module {}".format(module)
|
||||
|
||||
def test_old_directory(self):
|
||||
old_directory = [
|
||||
'paddle.enable_imperative', 'paddle.disable_imperative',
|
||||
'paddle.in_imperative_mode', 'paddle.imperative.to_variable',
|
||||
'paddle.imperative.enable', 'paddle.imperative.guard',
|
||||
'paddle.imperative.grad', 'paddle.imperative.no_grad',
|
||||
'paddle.imperative.save', 'paddle.imperative.load',
|
||||
'paddle.imperative.BackwardStrategy',
|
||||
'paddle.imperative.ParallelEnv',
|
||||
'paddle.imperative.prepare_context',
|
||||
'paddle.imperative.DataParalell', 'paddle.imperative.jit',
|
||||
'paddle.imperative.TracedLayer', 'paddle.imperative.declarative',
|
||||
'paddle.imperative.ProgramTranslator',
|
||||
'paddle.imperative.TranslatedLayer', 'paddle.imperative.jit.save',
|
||||
'paddle.imperative.jit.load',
|
||||
'paddle.imperative.jit.SaveLoadConfig',
|
||||
'paddle.imperative.NoamDecay'
|
||||
'paddle.imperative.PiecewiseDecay',
|
||||
'paddle.imperative.NaturalExpDecay',
|
||||
'paddle.imperative.ExponentialDecay',
|
||||
'paddle.imperative.InverseTimeDecay',
|
||||
'paddle.imperative.PolynomialDecay',
|
||||
'paddle.imperative.CosineDecay', 'paddle.Executor',
|
||||
'paddle.global_scope', 'paddle.scope_guard',
|
||||
'paddle.append_backward', 'paddle.gradients',
|
||||
'paddle.BuildStrategy', 'paddle.CompiledProgram',
|
||||
'paddle.ExecutionStrategy', 'paddle.name_scope',
|
||||
'paddle.program_guard', 'paddle.Print', 'paddle.py_func',
|
||||
'paddle.ParallelExecutor', 'paddle.default_main_program',
|
||||
'paddle.default_startup_program', 'paddle.Program',
|
||||
'paddle.WeightNormParamAttr', 'paddle.declarative.fc',
|
||||
'paddle.declarative.batch_norm',
|
||||
'paddle.declarative.bilinear_tensor_product',
|
||||
'paddle.declarative.conv2d', 'paddle.declarative.conv2d_transpose',
|
||||
'paddle.declarative.conv3d', 'paddle.declarative.conv3d_transpose',
|
||||
'paddle.declarative.create_parameter',
|
||||
'paddle.declarative.crf_decoding', 'paddle.declarative.data_norm',
|
||||
'paddle.declarative.deformable_conv',
|
||||
'paddle.declarative.group_norm', 'paddle.declarative.hsigmoid',
|
||||
'paddle.declarative.instance_norm', 'paddle.declarative.layer_norm',
|
||||
'paddle.declarative.multi_box_head', 'paddle.declarative.nce',
|
||||
'paddle.declarative.prelu', 'paddle.declarative.row_conv',
|
||||
'paddle.declarative.spectral_norm', 'paddle.declarative.embedding'
|
||||
]
|
||||
|
||||
import_file = 'run_old_import_modules.py'
|
||||
|
||||
with open(import_file, "w") as wb:
|
||||
cmd_context_count = """
|
||||
count = 0
|
||||
err_module = ""
|
||||
"""
|
||||
wb.write(cmd_context_count)
|
||||
for module in old_directory:
|
||||
run_cmd = self.get_import_command(module)
|
||||
cmd_context_loop_template = """
|
||||
try:
|
||||
{run_cmd}
|
||||
except:
|
||||
count += 1
|
||||
else:
|
||||
err_module = "{module}"
|
||||
"""
|
||||
cmd_context_loop = cmd_context_loop_template.format(
|
||||
run_cmd=run_cmd, module=module)
|
||||
wb.write(cmd_context_loop)
|
||||
cmd_context_print_template = """
|
||||
if count != {len_old_directory}:
|
||||
print("Error: Module " + err_module + " should not be imported")
|
||||
"""
|
||||
cmd_context_print = cmd_context_print_template.format(
|
||||
len_old_directory=str(len(old_directory)))
|
||||
wb.write(cmd_context_print)
|
||||
|
||||
_python = sys.executable
|
||||
|
||||
ps_cmd = "{} {}".format(_python, import_file)
|
||||
ps_proc = subprocess.Popen(
|
||||
ps_cmd.strip().split(" "),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = ps_proc.communicate()
|
||||
|
||||
assert "Error" not in str(stdout), str(stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue