Skip to content

Commit

Permalink
【Fluid Clean】 Rename paddle.fluid to paddle.base (PaddlePaddle#56576)
Browse files Browse the repository at this point in the history
* rename fluid to base

* fix setup and rename paddle.fluid

* fix protobuf generated paddle.fluid

* fix some errors

* fix cmake depends

* fix some error

* try to fix cache error

* fix codestyle && some doc error

* remove build change

* fix some error

---------

Co-authored-by: XiangGao <jeff41404@gmail.com>
  • Loading branch information
Difers and jeff41404 committed Sep 7, 2023
1 parent 0e9cc55 commit e53afe5
Show file tree
Hide file tree
Showing 1,965 changed files with 13,864 additions and 13,959 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ select = C,E,W
exclude =
./build,
# Exclude fluid directory
./python/paddle/fluid/**,
./python/paddle/base/**,
# Exclude third-party libraries
./third_party/**,
./python/paddle/utils/gast/**,
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ paddle/fluid/framework/__init__.py
paddle/phi/api/profiler/__init__.py
python/paddle/incubate/fleet/parameter_server/pslib/ps_pb2.py
paddle/phi/kernels/fusion/cutlass/conv2d/generated/*
python/paddle/fluid/incubate/fleet/parameter_server/pslib/ps_pb2.py
python/paddle/base/incubate/fleet/parameter_server/pslib/ps_pb2.py
paddle/fluid/ir_adaptor/translator/op_compat_info.cc
paddle/fluid/pybind/static_op_function.*
paddle/fluid/pybind/ops_api.cc
16 changes: 15 additions & 1 deletion cmake/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,21 @@ function(py_proto_compile TARGET_NAME)
"${multiValueArgs}" ${ARGN})
set(py_srcs)
protobuf_generate_python(py_srcs ${py_proto_compile_SRCS})
add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs} protobuf)

add_custom_target(${TARGET_NAME}_replace DEPENDS ${py_srcs})

foreach(py_src ${py_srcs})
add_custom_command(
TARGET ${TARGET_NAME}_replace
POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/cmake/replace_string.py
${py_src}
COMMENT
"Replacing 'paddle.fluid' with 'paddle.base' generated by protobuf"
COMMENT "Replace ${py_src}")
endforeach()

add_custom_target(${TARGET_NAME} ALL DEPENDS protobuf ${TARGET_NAME}_replace)
endfunction()

function(py_test TARGET_NAME)
Expand Down
31 changes: 31 additions & 0 deletions cmake/replace_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2023 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.

import sys


def main():
src = sys.argv[1]

with open(src, 'r') as file:
content = file.read()

new_content = content.replace('paddle.fluid', 'paddle.base')

with open(src, 'w') as file:
file.write(new_content)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion paddle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(PYTHON_TESTS_DIR
${PADDLE_BINARY_DIR}/python/paddle/fluid/tests
${PADDLE_BINARY_DIR}/python/paddle/base/tests
CACHE INTERNAL "python tests directory")

add_subdirectory(utils)
Expand Down
2 changes: 1 addition & 1 deletion paddle/cinn/hlir/op/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ CINN_REGISTER_HELPER(transform_ops) {
// pointers, the code generated by operator fusion will have out-of-bounds
// access. It should not fuse with any other injective operators, though
// scatter_add is injective. turn KNonFusible to kInjective will fail
// /Paddle/python/paddle/fluid/tests/unittests/test_index_select_op.py
// /Paddle/python/paddle/base/tests/unittests/test_index_select_op.py
.set_attr<cinn::hlir::framework::OpPatternKind>(
"OpPattern", cinn::hlir::framework::OpPatternKind::kNonFusible)
.set_support_level(4);
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/API.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
paddle.fluid.optimizer.PipelineOptimizer (paddle.fluid.optimizer.PipelineOptimizer, ('document', '2e55a29dbeb874934f7a1a1af3a22b8c'))
paddle.fluid.optimizer.PipelineOptimizer.__init__ (ArgSpec(args=['self', 'optimizer', 'num_microbatches', 'start_cpu_core_id'], varargs=None, keywords=None, defaults=(1, 0)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.fluid.optimizer.PipelineOptimizer.minimize (ArgSpec(args=['self', 'loss', 'startup_program', 'parameter_list', 'no_grad_set'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.incubate.optimizer.PipelineOptimizer (paddle.incubate.optimizer.PipelineOptimizer, ('document', '2e55a29dbeb874934f7a1a1af3a22b8c'))
paddle.incubate.optimizer.PipelineOptimizer.__init__ (ArgSpec(args=['self', 'optimizer', 'num_microbatches', 'start_cpu_core_id'], varargs=None, keywords=None, defaults=(1, 0)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.incubate.optimizer.PipelineOptimizer.minimize (ArgSpec(args=['self', 'loss', 'startup_program', 'parameter_list', 'no_grad_set'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', '6adf97f83acf6453d4a6a4b1070f3754'))
paddle.audio.features (ArgSpec(), ('document', 'd41d8cd98f00b204e9800998ecf8427e'))
paddle.audio.features.layers.LogMelSpectrogram (ArgSpec(), ('document', 'c38b53606aa89215c4f00d3833e158b8'))
paddle.audio.features.layers.LogMelSpectrogram.forward (ArgSpec(args=['self', 'x'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={'return': <class 'paddle.Tensor'>, 'x': <class 'paddle.Tensor'>}), ('document', '6c14f6f78dc697a6981cf90412e2f1ea'))
Expand Down
8 changes: 4 additions & 4 deletions paddle/fluid/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ if(WITH_PYTHON)
TARGET framework_py_proto
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
${PADDLE_BINARY_DIR}/python/paddle/fluid/proto
COMMAND cp *.py ${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/
${PADDLE_BINARY_DIR}/python/paddle/base/proto
COMMAND cp *.py ${PADDLE_BINARY_DIR}/python/paddle/base/proto/
COMMAND cp distributed_strategy_*.py
${PADDLE_BINARY_DIR}/python/paddle/distributed/fleet/proto
COMMENT "Copy generated python proto into directory paddle/fluid/proto."
Expand All @@ -620,15 +620,15 @@ if(WITH_PYTHON)
endif()
else()
string(REPLACE "/" "\\" proto_dstpath
"${PADDLE_BINARY_DIR}/python/paddle/fluid/proto/")
"${PADDLE_BINARY_DIR}/python/paddle/base/proto/")
string(
REPLACE "/" "\\" fleet_proto_dstpath
"${PADDLE_BINARY_DIR}/python/paddle/distributed/fleet/proto/")
add_custom_command(
TARGET framework_py_proto
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
${PADDLE_BINARY_DIR}/python/paddle/fluid/proto
${PADDLE_BINARY_DIR}/python/paddle/base/proto
COMMAND copy /Y *.py ${proto_dstpath}
COMMAND copy /Y distributed_strategy_*.py ${fleet_proto_dstpath}
COMMENT "Copy generated python proto into directory paddle/fluid/proto."
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/ir/auto_mixed_precision_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool OpSupportPrecision(const std::string& op_type,
// The set of ops that support fp16 calculation and are considered
// numerically-dangerous, slower and whose effects may also be observed in
// downstream ops.
// ref to python/paddle/fluid/contrib/mixed_precision/fp16_lists.py
// ref to python/paddle/base/contrib/mixed_precision/fp16_lists.py
void AutoMixedPrecisionPass::SetDefaultBlacklist() const {
black_list_.insert({
// numerically-dangerous
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/pybind/imperative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ void BindImperative(py::module *m_ptr) {
import paddle
data = np.random.randint(10, size=(3, 4))
tensor = paddle.fluid.core.to_uva_tensor(data)
tensor = paddle.base.core.to_uva_tensor(data)
print(tensor)
)DOC");

Expand Down Expand Up @@ -1165,7 +1165,7 @@ void BindImperative(py::module *m_ptr) {
import numpy as np
import paddle
from paddle.fluid import core
from paddle.base import core
from paddle.device import cuda
if core.is_compiled_with_cuda():
Expand Down Expand Up @@ -1397,7 +1397,7 @@ void BindImperative(py::module *m_ptr) {
import numpy as np
import paddle
from paddle.fluid import core
from paddle.base import core
from paddle.device import cuda
if core.is_compiled_with_cuda():
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/pybind/place.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ void BindPlace(pybind11::module &m) { // NOLINT
**Note**:
Examples:
.. code-block:: python
import paddle.fluid as fluid
xpu_place = fluid.XPUPlace(0)
import paddle.base as base
xpu_place = base.XPUPlace(0)
)DOC");
g_xpuplace_pytype = reinterpret_cast<PyTypeObject *>(xpuplace.ptr());
xpuplace
Expand Down
15 changes: 7 additions & 8 deletions paddle/fluid/pybind/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ PYBIND11_MODULE(libpaddle, m) {
});

// NOTE(zjl): ctest would load environment variables at the beginning even
// though we have not `import paddle.fluid as fluid`. So we add this API
// though we have not `import paddle.base as base`. So we add this API
// to enable eager deletion mode in unittest.
m.def("_set_eager_deletion_mode", &paddle::framework::SetEagerDeletionMode);

Expand Down Expand Up @@ -1239,7 +1239,6 @@ All parameter, weight, gradient are variables in Paddle.
Examples:
.. code-block:: python
import paddle.fluid as fluid
# create tensor from a scope and set value to it.
param = scope.var('Param').get_tensor()
param_array = np.full((height, row_numel), 5.0).astype("float32")
Expand Down Expand Up @@ -2149,9 +2148,9 @@ All parameter, weight, gradient are variables in Paddle.
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
arr = fluid.LoDTensorArray()
arr = base.LoDTensorArray()
)DOC");
g_framework_lodtensorarray_pytype =
reinterpret_cast<PyTypeObject *>(pylodtensorarray.ptr());
Expand Down Expand Up @@ -2193,12 +2192,12 @@ All parameter, weight, gradient are variables in Paddle.
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
arr = fluid.LoDTensorArray()
t = fluid.LoDTensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
arr = base.LoDTensorArray()
t = base.LoDTensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
arr.append(t)
)DOC")
.def(
Expand Down
46 changes: 23 additions & 23 deletions paddle/fluid/pybind/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
)DOC")

.def(
Expand All @@ -413,11 +413,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
print(t.shape()) # [5, 30]
)DOC")
.def("_to_dlpack",
Expand Down Expand Up @@ -517,11 +517,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
t.set_lod([[0, 2, 5]])
print(t.lod()) # [[0, 2, 5]]
)DOC")
Expand Down Expand Up @@ -566,11 +566,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
t.set_recursive_sequence_lengths([[2, 3]])
print(t.recursive_sequence_lengths()) # [[2, 3]]
print(t.lod()) # [[0, 2, 5]]
Expand All @@ -594,11 +594,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
t.set_lod([[0, 2, 5]])
print(t.lod()) # [[0, 2, 5]]
)DOC")
Expand All @@ -623,11 +623,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
t.set_recursive_sequence_lengths([[2, 3]])
print(t.recursive_sequence_lengths()) # [[2, 3]]
)DOC")
Expand All @@ -647,11 +647,11 @@ void BindTensor(pybind11::module &m) { // NOLINT
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle.base as base
import numpy as np
t = fluid.Tensor()
t.set(np.ndarray([5, 30]), fluid.CPUPlace())
t = base.Tensor()
t.set(np.ndarray([5, 30]), base.CPUPlace())
t.set_recursive_sequence_lengths([[2, 3]])
print(t.has_valid_recursive_sequence_lengths()) # True
)DOC")
Expand Down Expand Up @@ -824,7 +824,7 @@ void BindTensor(pybind11::module &m) { // NOLINT
import paddle
tensor = paddle.ones([3,3])
metainfo = tensor.value().get_tensor()._share_cuda()
tensor_from_shared = paddle.to_tensor(paddle.fluid.core.LoDTensor._new_shared_cuda(metainfo))
tensor_from_shared = paddle.to_tensor(paddle.base.core.LoDTensor._new_shared_cuda(metainfo))
)DOC")
#endif
Expand Down Expand Up @@ -945,7 +945,7 @@ void BindTensor(pybind11::module &m) { // NOLINT
import paddle
tensor = paddle.ones([3,3])
metainfo = tensor.value().get_tensor()._share_filename()
tensor_from_shared = paddle.to_tensor(paddle.fluid.core.LoDTensor._new_shared_filename(metainfo))
tensor_from_shared = paddle.to_tensor(paddle.base.core.LoDTensor._new_shared_filename(metainfo))
)DOC")
.def("_shared_incref",
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/api/profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
proto_library(phi_profiler_proto SRCS profiler.proto)

if(WITH_PYTHON AND EXISTS ${PADDLE_BINARY_DIR})
set(FLUID_PATH ${PADDLE_BINARY_DIR}/python/paddle/fluid)
set(FLUID_PATH ${PADDLE_BINARY_DIR}/python/paddle/base)
py_proto_compile(profiler_py_proto SRCS profiler.proto)
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/__init__.py)
if(NOT WIN32)
Expand Down
5 changes: 3 additions & 2 deletions paddle/scripts/paddle_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ set -ex

function parallel_test_base_ipu() {
mkdir -p ${PADDLE_ROOT}/build
cd ${PADDLE_ROOT}/build/python/paddle/fluid/tests/unittests/ipu
cd ${PADDLE_ROOT}/build/python/paddle/base/tests/unittests/ipu
if [ ${WITH_TESTING:-ON} == "ON" ] ; then
cat <<EOF
========================================
Expand Down Expand Up @@ -3275,7 +3275,7 @@ function build_pr_and_develop() {
rm -rf ${PADDLE_ROOT}/build/Makefile ${PADDLE_ROOT}/build/CMakeCache.txt ${PADDLE_ROOT}/build/build.ninja
rm -rf ${PADDLE_ROOT}/build/third_party
fi

git checkout -b develop_base_pr upstream/$BRANCH
git submodule update --init
run_setup ${PYTHON_ABI:-""} "rerun-cmake bdist_wheel" ${parallel_number}
Expand All @@ -3285,6 +3285,7 @@ function build_pr_and_develop() {
mv ${PADDLE_ROOT}/dist/*.whl ${PADDLE_ROOT}/build/python/dist/
mkdir ${PADDLE_ROOT}/build/dev_whl && cp ${PADDLE_ROOT}/build/python/dist/*.whl ${PADDLE_ROOT}/build/dev_whl
fi

generate_api_spec "$1" "DEV"

}
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ skip = ["build", "third_party", "__init__.py"]
extend_skip_glob = [
# These files do not need to be formatted,
# see .flake8 for more details
"python/paddle/fluid/**",
"python/paddle/base/**",
"python/paddle/utils/gast/**",
]

[tool.ruff]
exclude = [
"./build",
"third_party",
"./python/paddle/fluid/**",
"./python/paddle/base/**",
"./python/paddle/utils/gast/**",
]
target-version = "py37"
Expand Down
Loading

0 comments on commit e53afe5

Please sign in to comment.