Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Function optimization] remove temporary flag set_to_1d completely #61227

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions paddle/fluid/pybind/eager_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ typedef SSIZE_T ssize_t;
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/utils/pybind.h"

PHI_DECLARE_bool(set_to_1d);
PHI_DECLARE_bool(use_stride_kernel);

namespace paddle {
Expand Down Expand Up @@ -179,34 +178,7 @@ static PyObject* tensor_method_numpy(TensorObject* self,
Py_intptr_t py_strides[paddle::framework::DDim::kMaxRank]; // NOLINT
size_t py_rank = tensor_dims.size();
size_t numel = 1;
if (py_rank == 0) {
Py_ssize_t args_num = PyTuple_Size(args);
// true by default
bool set_to_1d = FLAGS_set_to_1d;
if (args_num == (Py_ssize_t)1) {
PyObject* obj = PyTuple_GET_ITEM(args, 0);
if (obj == Py_False) {
set_to_1d = false;
}
}
if (set_to_1d) {
// 0D Tensor hack process to 1D numpy, will remove in release 2.6
VLOG(0)
<< "Warning:: 0D Tensor cannot be used as 'Tensor.numpy()[0]' . In "
"order to avoid this problem, "
"0D Tensor will be changed to 1D numpy currently, but it's not "
"correct and will be "
"removed in release 2.6. For Tensor contain only one element, "
"Please "
"modify "
" 'Tensor.numpy()[0]' to 'float(Tensor)' as soon as "
"possible, "
"otherwise 'Tensor.numpy()[0]' will raise error in release 2.6.";
py_rank = 1;
py_dims[0] = 1;
py_strides[0] = static_cast<Py_intptr_t>(sizeof_dtype * numel);
}
} else if (self->tensor.is_dense_tensor()) {
if (self->tensor.is_dense_tensor()) {
auto tensor_stride = self->tensor.strides();

for (int i = static_cast<int>(tensor_dims.size()) - 1; i >= 0; --i) {
Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/pybind/imperative.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ limitations under the License. */
#include "paddle/phi/core/compat/arg_map_context.h"
#include "paddle/phi/core/type_defs.h"

PHI_DECLARE_bool(set_to_1d);
namespace paddle {
namespace pybind {

Expand Down
10 changes: 0 additions & 10 deletions paddle/phi/core/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -743,16 +743,6 @@ PHI_DEFINE_EXPORTED_int32(
"less FLAGS_max_inplace_grad_add, than it will be use several grad_add"
"instead of sum. Default is 0.");

/**
* Tensor.numpy() has a hack, and this flag can close this hack
* [true]: set 0D Tensor to 1D Numpy
* [false]: not set 0D Tensor to 1D Numpy, close the hack
*
* Now, just set true by default in 2.5 transition time
* which will be removed in future (2.6) .
*/
PHI_DEFINE_EXPORTED_bool(set_to_1d, false, "set 0D Tensor to 1D numpy");

/**
* Debug related FLAG
* Name: tracer_mkldnn_ops_on
Expand Down
7 changes: 0 additions & 7 deletions paddle/phi/kernels/funcs/slice_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ limitations under the License. */
#include <vector>
#include "paddle/phi/core/flags.h"

PHI_DECLARE_bool(set_to_1d);

namespace phi {

namespace funcs {
Expand Down Expand Up @@ -205,11 +203,6 @@ inline DDim GetDecreasedDims(const DDim slice_dims,
new_shape.push_back(decreased_dims[i]);
}
}
if (FLAGS_set_to_1d && new_shape.size() == 0) {
// NOTE(zoooo0820): Hack procssing to 1-D, when axes decrease to 0-D in
// slice. This will remove in release 2.6.
new_shape.push_back(1);
}
decreased_dims = common::make_ddim(new_shape);
}
return decreased_dims;
Expand Down
8 changes: 0 additions & 8 deletions paddle/phi/kernels/stride/slice_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/funcs/slice_utils.h"

PHI_DECLARE_bool(set_to_1d);

namespace phi {

template <typename Context>
Expand Down Expand Up @@ -74,12 +72,6 @@ void SliceStridedKernel(const Context& ctx,
new_stride.push_back(output_stride[i]);
}
}
if (FLAGS_set_to_1d && new_shape.size() == 0) {
// NOTE(zoooo0820): Hack processing to 1-D, when axes decrease to 0-D in
// slice. This will remove in release 2.6.
new_shape.push_back(1);
new_stride.push_back(0);
}
output_dims = new_shape;
output_stride = new_stride;
}
Expand Down
1 change: 0 additions & 1 deletion paddle/scripts/paddle_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ for /F %%# in ('wmic os get localdatetime^|findstr 20') do set start=%%#
set start=%start:~4,10%

set FLAGS_call_stack_level=2
set FLAGS_set_to_1d=False
dir %THIRD_PARTY_PATH:/=\%\install\openblas\lib
dir %THIRD_PARTY_PATH:/=\%\install\openblas\bin
dir %THIRD_PARTY_PATH:/=\%\install\zlib\bin
Expand Down
1 change: 0 additions & 1 deletion paddle/scripts/paddle_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function init() {

# NOTE(chenweihang): For easy debugging, CI displays the C++ error stacktrace by default
export FLAGS_call_stack_level=2
export FLAGS_set_to_1d=False
}

function cmake_base() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle

from ..utils import compute_compatible_dim_mapping, is_dim_shard
from .common import (
Expand Down Expand Up @@ -72,14 +71,7 @@ def is_output_compatible(self, dist_op):
if i not in decrease_axis:
ref_indices.append(i)
if ref_indices == []:
# NOTE(zoooo0820): When all axes are decreased, the output will be 1-D
# with FLAGS_set_to_1d=True.
if paddle.get_flags('FLAGS_set_to_1d')['FLAGS_set_to_1d']:
assert len(out_dims_mapping) == 1
if is_dim_shard(out_dims_mapping[0]):
return False
else:
assert len(out_dims_mapping) == 0
assert len(out_dims_mapping) == 0
else:
for i in range(len(out_dims_mapping)):
ref_index = ref_indices[i]
Expand Down Expand Up @@ -149,11 +141,6 @@ def update_dims_mapping(self, dist_op):
ref_indices.append(i)

if ref_dims_mapping == []:
# NOTE(zoooo0820): When all axes are decreased, the output will be 1-D
# with FLAGS_set_to_1d=True.
if paddle.get_flags('FLAGS_set_to_1d')['FLAGS_set_to_1d']:
ref_dims_mapping = [-1]
assert ref_dims_mapping[0] == out_dims_mapping[0]
assert len(ref_dims_mapping) == len(out_dims_mapping)
changed = False
else:
Expand Down