Skip to content

Commit 9f32642

Browse files
authored
Merge branch 'develop' into fix_logit_bt
2 parents 6ccac7c + 81ef31d commit 9f32642

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+676
-196
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ repos:
6262
- repo: https://github.com/astral-sh/ruff-pre-commit
6363
rev: v0.11.11
6464
hooks:
65-
- id: ruff
65+
- id: ruff-check
6666
args: [--fix, --exit-non-zero-on-fix, --no-cache]
6767
# For C++ files
6868
- repo: local

SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ These tools include adversarial example evaluation test, pseudo-natural environm
1919
Always load and execute untrusted models inside a sandbox and be sure to know the security impacts.
2020
There are several ways in which a model could become untrusted. PaddlePaddle has enough features to impact on the system. (e.g. `paddle.load` uses [pickle](https://docs.python.org/3/library/pickle.html) implicitly, which may cause malformed models to achieve arbitrary code execution). So we recommend when using the untrusted models, you need to carefully audit it and run PaddlePaddle inside a sandbox.
2121

22+
### Using distributed features
23+
PaddlePaddle offers distributed computing capabilities through the paddle.distributed package. These distributed features are meant for secure, trusted environments only, not for use on public or untrusted networks.
24+
25+
For efficiency, PaddlePaddle Distributed (e.g. RPC) does not use encryption or authentication. Messages are sent in plain text, and connections from any source are accepted. This means if you run a PaddlePaddle Distributed program on your network, anyone who can access that network could send tasks to PaddlePaddle, and those tasks will be executed without any security checks, using the same permissions as the PaddlePaddle process.
26+
2227
## PaddlePaddle Code Security
2328

2429
PaddlePaddle always take code security seriously. However, due to the complexity of the framework and its dependence on other thirdparty open source libraries, there may still be some security issues undetected. Therefore, we hope that more security researchers and PaddlePaddle developers can participate in the code security program. We encourage responsible disclosure of security issues, as well as contributing code to improve our vulnerability finding tools to make PaddlePaddle safer.

cmake/cudnn.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ else()
1010
CACHE PATH "CUDNN ROOT")
1111
endif()
1212

13+
set(TARGET_ARCH "x86_64")
14+
if(NOT ${CMAKE_SYSTEM_PROCESSOR})
15+
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
16+
endif()
17+
1318
find_path(
1419
CUDNN_INCLUDE_DIR cudnn.h
15-
PATHS ${CUDNN_ROOT} ${CUDNN_ROOT}/include $ENV{CUDNN_ROOT}
16-
$ENV{CUDNN_ROOT}/include ${CUDA_TOOLKIT_INCLUDE}
20+
PATHS ${CUDNN_ROOT}
21+
${CUDNN_ROOT}/include
22+
${CUDNN_ROOT}/include/${TARGET_ARCH}-linux-gnu
23+
$ENV{CUDNN_ROOT}
24+
$ENV{CUDNN_ROOT}/include
25+
${CUDA_TOOLKIT_INCLUDE}
1726
/usr/local/lib/python${PY_VERSION}/dist-packages/nvidia/cudnn/include/
1827
NO_DEFAULT_PATH)
1928

2029
get_filename_component(__libpath_hist ${CUDA_CUDART_LIBRARY} PATH)
2130

22-
set(TARGET_ARCH "x86_64")
23-
if(NOT ${CMAKE_SYSTEM_PROCESSOR})
24-
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
25-
endif()
26-
2731
list(
2832
APPEND
2933
CUDNN_CHECK_LIBRARY_DIRS

paddle/fluid/pir/dialect/operator/ir/control_flow_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,13 @@ bool WhileOp::InferSymbolicShape(
10031003
auto yield_input_data_opt = yield_input_shape_or_data.data();
10041004
auto input_data_opt =
10051005
infer_context->GetShapeOrDataForValue(body_args[i]).data();
1006-
bool const_data_not_euqal =
1006+
bool const_data_not_equal =
10071007
is_all_const_data(yield_input_data_opt) &&
10081008
(!is_all_const_data(input_data_opt) ||
10091009
is_all_const_data(input_data_opt) &&
10101010
yield_input_data_opt.value() != input_data_opt.value());
10111011
auto result_shape_or_data =
1012-
const_data_not_euqal
1012+
const_data_not_equal
10131013
? symbol::TensorShapeOrDataDimExprs(
10141014
yield_input_shape_or_data.shape(),
10151015
creat_new_data(yield_input_data_opt.value().size()))

paddle/fluid/pir/serialize_deserialize/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ endif()
1313

1414
file(GLOB_RECURSE YAML_PATCH_FILES "*.yaml")
1515
# change pir version when new patches are added
16-
add_definitions(-DDEVELOP_VERSION=0)
17-
add_definitions(-DRELEASE_VERSION=1)
16+
add_definitions(-DDEVELOP_VERSION=2)
17+
add_definitions(-DRELEASE_VERSION=2)
1818
set(TEMPLATE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/patch/template.h.in)
1919
set(PATCH_HEADER ${CMAKE_CURRENT_BINARY_DIR}/patch/patch.h)
2020

paddle/fluid/primitive/decomp_rule/decomp_vjp/details.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,15 +2307,18 @@ void group_norm_grad(const Tensor& x,
23072307
auto tmp1 = out_grad_data * (x_data - mean_new) * sqrt_var_1;
23082308

23092309
auto scale_grad_tmp = reshape<T>(
2310-
tmp1.sum(reduce_axis_except_channel, scale->dtype(), false), {-1});
2310+
tmp1.sum(reduce_axis_except_channel, x_data.dtype(), false), {-1});
2311+
scale_grad_tmp = ConvertToOrig<T>(scale_grad_tmp, scale->dtype());
2312+
23112313
set_output<T>(scale_grad_tmp, scale_grad);
23122314
}
23132315
}
23142316

23152317
if (bias_grad) {
23162318
if (bias) {
23172319
auto bias_grad_tmp =
2318-
out_grad_data.sum(reduce_axis_except_channel, bias->dtype(), false);
2320+
out_grad_data.sum(reduce_axis_except_channel, x_data.dtype(), false);
2321+
bias_grad_tmp = ConvertToOrig<T>(bias_grad_tmp, bias->dtype());
23192322

23202323
set_output<T>(reshape<T>(bias_grad_tmp, {-1}), bias_grad);
23212324
}

paddle/fluid/pybind/eager_method.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef SSIZE_T ssize_t;
2929
#include "paddle/fluid/eager/hooks.h"
3030
#include "paddle/fluid/eager/utils.h"
3131
#include "paddle/fluid/framework/convert_utils.h"
32+
#include "paddle/fluid/framework/tensor_util.h"
3233
#include "paddle/fluid/platform/enforce.h"
3334
#include "paddle/fluid/pybind/eager.h"
3435
#include "paddle/fluid/pybind/eager_utils.h"
@@ -1398,6 +1399,61 @@ static PyObject* tensor_method_get_underline_tensor(TensorObject* self,
13981399
EAGER_CATCH_AND_THROW_RETURN_NULL
13991400
}
14001401

1402+
static PyObject* tensor_method_set_underline_tensor(TensorObject* self,
1403+
PyObject* args,
1404+
PyObject* kwargs) {
1405+
EAGER_TRY
1406+
auto& value = GetTensorFromArgs("set_tensor", "value", args, 0, false);
1407+
if (!value.defined()) {
1408+
PADDLE_THROW(
1409+
common::errors::Unavailable("The `set_tensor()` method of (Dist)Tensor "
1410+
"get a non initialized src value"));
1411+
} else if (value.is_dense_tensor()) {
1412+
auto* src_tensor = static_cast<phi::DenseTensor*>(value.impl().get());
1413+
if (self->tensor.is_dense_tensor()) {
1414+
auto* dst_tensor =
1415+
static_cast<phi::DenseTensor*>(self->tensor.impl().get());
1416+
framework::TensorCopy(*src_tensor, dst_tensor->place(), dst_tensor);
1417+
} else {
1418+
PADDLE_THROW(common::errors::Unavailable(
1419+
"The `set_tensor()` method of non DenseTensor get a DenseTensor src "
1420+
"value"));
1421+
}
1422+
1423+
} else if (value.is_dist_tensor()) {
1424+
#ifdef PADDLE_WITH_DISTRIBUTE
1425+
auto* src_tensor =
1426+
static_cast<phi::distributed::DistTensor*>(value.impl().get());
1427+
if (self->tensor.is_dist_tensor()) {
1428+
auto* dst_tensor =
1429+
static_cast<phi::distributed::DistTensor*>(self->tensor.impl().get());
1430+
framework::TensorCopy(*(src_tensor->unsafe_mutable_value()),
1431+
dst_tensor->place(),
1432+
dst_tensor->unsafe_mutable_value());
1433+
1434+
// TensorCopyFrom(dst_tensor->unsafe_mutable_value(),
1435+
// *(src_tensor->unsafe_mutable_value()), dst_tensor->place(), -1);
1436+
} else {
1437+
PADDLE_THROW(
1438+
common::errors::Unavailable("The `set_tensor()` method of non "
1439+
"DistTensor get a DistTensor src value"));
1440+
}
1441+
#else
1442+
PADDLE_THROW(common::errors::Unavailable(
1443+
"The `set_tensor()` method of (Dist)Tensor is not supported in the "
1444+
"current PaddlePaddle, please recompile and installPaddlePaddle "
1445+
"with the option of `WITH_DISTRIBUTE=ON`."));
1446+
#endif
1447+
1448+
} else {
1449+
PADDLE_THROW(common::errors::Unavailable(
1450+
"The `set_tensor()` method of (Dist)Tensor get a non "
1451+
"DenseTensor/DistTensor src value"));
1452+
}
1453+
RETURN_PY_NONE
1454+
EAGER_CATCH_AND_THROW_RETURN_NULL
1455+
}
1456+
14011457
static PyObject* tensor_method_get_underline_selected_rows(TensorObject* self,
14021458
PyObject* args,
14031459
PyObject* kwargs) {
@@ -3643,6 +3699,10 @@ PyMethodDef variable_methods[] = { // NOLINT
36433699
(PyCFunction)(void (*)())tensor_method__get_tensor_from_selected_rows,
36443700
METH_VARARGS | METH_KEYWORDS,
36453701
nullptr},
3702+
{"set_tensor",
3703+
(PyCFunction)(void (*)())tensor_method_set_underline_tensor,
3704+
METH_VARARGS | METH_KEYWORDS,
3705+
nullptr},
36463706
{"_getitem_dygraph",
36473707
(PyCFunction)(void (*)())tensor__getitem_dygraph,
36483708
METH_VARARGS | METH_KEYWORDS,

paddle/phi/core/memory/allocation/allocator_facade.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,17 @@ class AllocatorFacadePrivate {
791791
}
792792
}
793793

794+
void EraseStream(std::shared_ptr<phi::Allocation> allocation,
795+
phi::stream::stream_t stream) {
796+
if (auto stream_safe_cuda_allocation =
797+
std::dynamic_pointer_cast<StreamSafeCustomDeviceAllocation>(
798+
allocation)) {
799+
stream_safe_cuda_allocation->EraseStream(stream);
800+
} else {
801+
VLOG(6) << "EraseStream for a non-StreamSafeCUDAAllocation";
802+
}
803+
}
804+
794805
phi::stream::stream_t GetStream(
795806
const std::shared_ptr<phi::Allocation>& allocation) const {
796807
const std::shared_ptr<StreamSafeCustomDeviceAllocation>
@@ -1787,11 +1798,17 @@ AllocationPtr AllocatorFacade::Alloc(const phi::Place& place,
17871798
bool AllocatorFacade::InSameStream(
17881799
const std::shared_ptr<phi::Allocation>& allocation,
17891800
const phi::Stream& stream) {
1790-
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
1801+
#if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && \
1802+
!defined(PADDLE_WITH_CUSTOM_DEVICE)
17911803
gpuStream_t s = reinterpret_cast<gpuStream_t>(stream.id()); // NOLINT
17921804
return s == GetStream(allocation);
1805+
#elif defined(PADDLE_WITH_CUSTOM_DEVICE)
1806+
phi::stream::stream_t s =
1807+
reinterpret_cast<phi::stream::stream_t>(stream.id()); // NOLINT
1808+
return s == GetStream(allocation);
17931809
#else
1794-
PADDLE_THROW(common::errors::PreconditionNotMet("Not compiled with GPU."));
1810+
PADDLE_THROW(common::errors::PreconditionNotMet(
1811+
"Not compiled with GPU or CUDA backend."));
17951812
#endif
17961813
}
17971814

@@ -1946,6 +1963,11 @@ bool AllocatorFacade::RecordStream(std::shared_ptr<phi::Allocation> allocation,
19461963
return GetPrivate()->RecordStream(allocation, stream);
19471964
}
19481965

1966+
void AllocatorFacade::EraseStream(std::shared_ptr<phi::Allocation> allocation,
1967+
phi::stream::stream_t stream) {
1968+
GetPrivate()->EraseStream(allocation, stream);
1969+
}
1970+
19491971
const std::shared_ptr<Allocator>& AllocatorFacade::GetAllocator(
19501972
const phi::Place& place, phi::stream::stream_t stream) {
19511973
AllocatorFacadePrivate* m = GetPrivate();

paddle/phi/core/memory/allocation/allocator_facade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class AllocatorFacade {
109109
uint64_t Release(const phi::CustomPlace& place, phi::stream::stream_t stream);
110110
bool RecordStream(std::shared_ptr<Allocation> allocation,
111111
phi::stream::stream_t stream);
112+
void EraseStream(std::shared_ptr<Allocation> allocation,
113+
phi::stream::stream_t stream);
112114
TEST_API const std::shared_ptr<Allocator>& GetAllocator(
113115
const phi::Place& place, phi::stream::stream_t stream);
114116
phi::stream::stream_t GetStream(

paddle/phi/core/memory/allocation/stream_safe_custom_device_allocator.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ bool StreamSafeCustomDeviceAllocation::RecordStream(
5858
return true;
5959
}
6060

61+
void StreamSafeCustomDeviceAllocation::EraseStream(
62+
phi::stream::stream_t stream) {
63+
VLOG(8) << "Try remove stream " << stream << " for address " << ptr();
64+
std::lock_guard<SpinLock> lock_guard(outstanding_event_map_lock_);
65+
auto it = outstanding_event_map_.find(stream);
66+
if (it == outstanding_event_map_.end()) {
67+
return;
68+
}
69+
it->second->Destroy();
70+
outstanding_event_map_.erase(it);
71+
}
72+
6173
bool StreamSafeCustomDeviceAllocation::CanBeFreed() {
6274
std::lock_guard<SpinLock> lock_guard(outstanding_event_map_lock_);
6375
if (!phi::DeviceManager::HasDeviceType(place_.GetDeviceType())) {
@@ -191,7 +203,8 @@ uint64_t StreamSafeCustomDeviceAllocator::ReleaseImpl(const phi::Place& place) {
191203

192204
void StreamSafeCustomDeviceAllocator::ProcessUnfreedAllocations() {
193205
// NOTE(Ruibiao): This condition is to reduce lock completion. It does not
194-
// need to be thread-safe since here occasional misjudgments are permissible.
206+
// need to be thread-safe since here occasional misjudgments are
207+
// permissible.
195208
if (unfreed_allocations_.empty()) {
196209
return;
197210
}

paddle/phi/core/memory/allocation/stream_safe_custom_device_allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class StreamSafeCustomDeviceAllocation : public Allocation {
3636
StreamSafeCustomDeviceAllocator *allocator);
3737

3838
bool RecordStream(phi::stream::stream_t stream);
39+
void EraseStream(phi::stream::stream_t stream);
3940
bool CanBeFreed();
4041
phi::stream::stream_t GetOwningStream() const;
4142
void SetOwningStream(phi::stream::stream_t s);

paddle/phi/core/memory/malloc.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation) {
7777
#endif
7878

7979
#ifdef PADDLE_WITH_CUSTOM_DEVICE
80+
uint64_t Release(const phi::CustomPlace& place, phi::stream::stream_t stream) {
81+
return allocation::AllocatorFacade::Instance().Release(place, stream);
82+
}
83+
8084
bool RecordStream(std::shared_ptr<Allocation> allocation,
8185
phi::stream::stream_t stream) {
8286
return allocation::AllocatorFacade::Instance().RecordStream(allocation,
8387
stream);
8488
}
89+
90+
void EraseStream(std::shared_ptr<Allocation> allocation,
91+
phi::stream::stream_t stream) {
92+
return allocation::AllocatorFacade::Instance().EraseStream(allocation,
93+
stream);
94+
}
95+
96+
phi::stream::stream_t GetStream(const std::shared_ptr<Allocation>& allocation) {
97+
return allocation::AllocatorFacade::Instance().GetStream(allocation);
98+
}
8599
#endif
86100
} // namespace paddle::memory

paddle/phi/core/memory/malloc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ void EraseStream(std::shared_ptr<Allocation> allocation, gpuStream_t stream);
5959
gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation);
6060
#endif
6161
#ifdef PADDLE_WITH_CUSTOM_DEVICE
62+
extern uint64_t Release(const phi::CustomPlace& place,
63+
phi::stream::stream_t stream);
64+
6265
bool RecordStream(std::shared_ptr<Allocation> allocation,
6366
phi::stream::stream_t stream);
67+
68+
void EraseStream(std::shared_ptr<Allocation> allocation,
69+
phi::stream::stream_t stream);
70+
71+
phi::stream::stream_t GetStream(const std::shared_ptr<Allocation>& allocation);
6472
#endif
6573

6674
template <typename StreamType>

paddle/phi/infermeta/unary.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4520,31 +4520,31 @@ void SplitInferMeta(const MetaTensor& x,
45204520
} else {
45214521
auto input_axis_dim = x.dims().at(axis_value);
45224522
std::vector<int64_t> sections_vec;
4523-
const int unknow_dim_val = -1;
4524-
int unknow_dim_idx = -1;
4525-
int num_of_unknow = 0;
4523+
const int unknown_dim_val = -1;
4524+
int unknown_dim_idx = -1;
4525+
int num_of_unknown = 0;
45264526
int64_t sum_of_section = 0;
45274527

45284528
for (int i = 0; i < static_cast<int>(sections_data.size()); ++i) {
45294529
sections_vec.push_back(sections_data[i]);
45304530

4531-
if (sections_data[i] == unknow_dim_val) {
4532-
num_of_unknow++;
4533-
unknow_dim_idx = i;
4531+
if (sections_data[i] == unknown_dim_val) {
4532+
num_of_unknown++;
4533+
unknown_dim_idx = i;
45344534
} else {
45354535
sum_of_section += static_cast<int64_t>(sections_data[i]);
45364536
}
45374537
}
45384538

4539-
PADDLE_ENFORCE_LE(num_of_unknow,
4539+
PADDLE_ENFORCE_LE(num_of_unknown,
45404540
1,
45414541
common::errors::InvalidArgument(
45424542
"Only one dimension value of Attr(num_or_sections) "
45434543
"in SplitOp can be -1. "
45444544
"But received Attr(num_or_sections) = [%s].",
45454545
common::make_ddim(sections_data)));
45464546

4547-
if (unknow_dim_idx != -1) {
4547+
if (unknown_dim_idx != -1) {
45484548
// for example, input shape = [4 ,5], axis = 1, sections = [2, 3, -1].
45494549
// input_axis_dim = 5, sum_of_sections = 5.
45504550
// the following check will fail.
@@ -4561,7 +4561,7 @@ void SplitInferMeta(const MetaTensor& x,
45614561
x.dims(),
45624562
axis_value));
45634563

4564-
sections_vec[unknow_dim_idx] = input_axis_dim - sum_of_section;
4564+
sections_vec[unknown_dim_idx] = input_axis_dim - sum_of_section;
45654565
} else {
45664566
PADDLE_ENFORCE_EQ(
45674567
sum_of_section,

paddle/phi/kernels/cpu/elementwise_add_kernel.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void AddKernel(const Context& dev_ctx,
5252
const DenseTensor& y,
5353
DenseTensor* out) {
5454
if (x.numel() == 0 || y.numel() == 0) {
55-
out->Resize(out->dims());
5655
dev_ctx.template Alloc<T>(out);
5756
return;
5857
}

paddle/phi/kernels/cpu/elementwise_divide_kernel.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void DivideKernel(const Context& dev_ctx,
2828
const DenseTensor& y,
2929
DenseTensor* out) {
3030
if (x.numel() == 0 || y.numel() == 0) {
31-
out->Resize(out->dims());
3231
dev_ctx.template Alloc<T>(out);
3332
return;
3433
}

paddle/phi/kernels/cpu/elementwise_multiply_kernel.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void MultiplyKernel(const Context& dev_ctx,
2828
const DenseTensor& y,
2929
DenseTensor* out) {
3030
if (x.numel() == 0 || y.numel() == 0) {
31-
out->Resize(out->dims());
3231
dev_ctx.template Alloc<T>(out);
3332
return;
3433
}

0 commit comments

Comments
 (0)