Skip to content

Commit dc7ca3f

Browse files
zhengshengningzrr1999cszdrgscyyh11
authored
[Cherry-pick Fleety_12] Bigtensor and api precision (#76028)
* CallScalarFunction uses the dtype of 'self' as the type of 'other' when opotype is 'div'(#75237) * LinspaceKernel uses the dtype of 'self' as the type of 'step' when tensor is floating (#75238) * align LinspaceKernel * update meta * update gpu kernel * fix LinspaceKernelInner * improve kernel * fix CudaSigmoidGradFunctor and CudaSiluGradFunctor (#75341) * Softplus accuracy and torch alignment 1 (#75363) * [Precision Depth Alignment] paddle.tan reverse calculation: dx = dout *(1 + tan(x)^2) (#75335) * Tan reverse calculation: dx = dout *(1 + tan(x)^2) * [Precision Depth Alignment] Add support for CUDNN to paddle.nn.functional.grid_sample to align with torch accuracy. (#75355) * accuracy_stable_grid_sample * fix * correlation supports big tensor (#75383) * fix * fix test * fix * paddle.tanh Grad and torch alignment (float16) (#75454) * [Precision Depth Alignment] paddle.sin and paddle.cos aligns with torch precision. (#75503) * accuracy_stable_sin * accuracy_stable_cos * [深度对齐]Divide (#75379) * fix * fix * fix * fix * fix * [Precision Depth Alignment] fix precision for float16 of paddle.tan backward (#75525) * fix precision for float16 of paddle.tan backward * fix else branch of CudaTanGradFunctor * [Precision Depth Alignment] fix precision for paddle.expm1 (#75549) * accuracy_stable_expm1 * fix * Bigtensor排查修复[Paddle/paddle/phi/kernels/funcs] (#75523) * fix * fix * [Precision Depth Alignment] fix beta and threshold of paddle.nn.functional.softplus to double (#75426) * fix beta and threshold of Softplus to double * fix test_softplus_activation_fuse_pass v1 * fix test_activation_zero * fix flaot of SoftplusDoubleGradKernel to double * add op_patches for softplus * add yaml for ops/yaml/legacy * fix infershape/operator for FLOAT64 * fix * add SoftPlusOpTranscriber * fix * fix * fix1 * fix2 * fix coverage * fix coverage2 * fix (#75605) * [深度对齐] dot (#75717) * fix * fix * fix dcu * [Precision Depth Alignment] paddle.log aligns with torch precision (#75799) * accuracy_stable_log * accuracy_stable_log * fix * fix * fix * fix * fix5 * [Precision Depth Alignment] fix eps of paddle.logit from float to double (#75816) * accuracy_stable_logit * add LogitOpTranscriber * fix coverage * fix 0yaml * [Precision Depth Alignment] paddle.log_sigmoid (#75898) * accuracy_stable_log_sigmoid * fix test_activation_stride_op.py * [Precision Depth Alignment] Modify the negative_slope parameter of the paddle.nn.functional.leaky_relu API to double (#75547) * [big tensor] Paddle/paddle/phi/kernels/funcs gpuBigtensor (#75856) * fix funcs * gpu * fix * fix * 修改PADDLE_ENFORCE信息 * fix cpu error * fix dcu * fix dcu * fix * [Fix] log sigmoid complex (#75953) * feature: Add specialized LogSigmoidFunctor and CudaLogSigmoidFunctor for complex numbers This commit introduces specialized implementations of LogSigmoidFunctor and CudaLogSigmoidFunctor to handle complex number inputs. The new implementations utilize direct formulas for improved accuracy and stability in calculations involving complex types. * refactor: Optimize LogSigmoidFunctor and CudaLogSigmoidFunctor for complex types by caching exp(-x) to reduce redundant computations. This change enhances performance while maintaining accuracy in calculations. * refactor: modified the formula in LogSigmoidFunctor to make it numerical stable --------- Co-authored-by: Zhan Rongrui <[email protected]> Co-authored-by: 正在学习 <[email protected]> Co-authored-by: Bvicii <[email protected]>
1 parent 64c6859 commit dc7ca3f

File tree

166 files changed

+2800
-1134
lines changed

Some content is hidden

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

166 files changed

+2800
-1134
lines changed

paddle/fluid/framework/infershape_utils.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ CompatInferMetaContext BuildInferMetaContext(InferShapeContext* ctx,
795795
infer_meta_context.EmplaceBackAttr(PADDLE_GET_CONST(float, attr));
796796
break;
797797
case phi::AttributeType::FLOAT64:
798+
if (AttrTypeID(attr) == framework::proto::AttrType::FLOAT) {
799+
const auto val = PADDLE_GET_CONST(float, attr);
800+
infer_meta_context.EmplaceBackAttr(static_cast<double>(val));
801+
break;
802+
}
798803
infer_meta_context.EmplaceBackAttr(
799804
PADDLE_GET_CONST(double, attr));
800805
break;

paddle/fluid/framework/new_executor/instruction/onednn/onednn_instruction.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static phi::Attribute ConvertPirAttribute2RuntimeAttribute(
5353
return attr.dyn_cast<pir::Int32Attribute>().data();
5454
} else if (attr_type_name == "pir::FloatAttribute") {
5555
return attr.dyn_cast<pir::FloatAttribute>().data();
56+
} else if (attr_type_name == "pir::DoubleAttribute") {
57+
return attr.dyn_cast<pir::DoubleAttribute>().data();
5658
} else if (attr_type_name == "pir::BoolAttribute") {
5759
return attr.dyn_cast<pir::BoolAttribute>().data();
5860
} else if (attr_type_name == "pir::StrAttribute") {

paddle/fluid/framework/operator.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,6 +3494,12 @@ void OperatorWithKernel::BuildPhiKernelContext(
34943494
PADDLE_GET_CONST(float, attr_iter->second));
34953495
break;
34963496
case phi::AttributeType::FLOAT64:
3497+
if (AttrTypeID(attr_iter->second) ==
3498+
framework::proto::AttrType::FLOAT) {
3499+
const auto val = PADDLE_GET_CONST(float, attr_iter->second);
3500+
phi_kernel_context->EmplaceBackAttr(static_cast<double>(val));
3501+
break;
3502+
}
34973503
phi_kernel_context->EmplaceBackAttr(
34983504
PADDLE_GET_CONST(double, attr_iter->second));
34993505
break;

paddle/fluid/ir_adaptor/translator/op_translator.cc

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,42 @@ struct CastOpTranscriber : public OpTranscriber {
10851085
}
10861086
};
10871087

1088+
struct LeakyReLUOpTranscriber : public OpTranscriber {
1089+
pir::AttributeMap TranslateOpAttribute(
1090+
pir::IrContext* ctx,
1091+
const std::string& normalized_op_name,
1092+
const OpAttributeInfoList& op_attr_infos,
1093+
const OpDesc& op_desc) override {
1094+
auto& attribute_translator = AttributeTranslator::instance();
1095+
auto& op_normalizer = OpNameNormalizer::instance();
1096+
pir::AttributeMap attribute_map = {};
1097+
1098+
for (const auto& info : op_attr_infos) {
1099+
auto legacy_attr_name =
1100+
op_normalizer.GetLegacyAttrName(op_desc.Type(), info.name);
1101+
VLOG(10) << "[op: " << op_desc.Type()
1102+
<< "][attr] from: " << legacy_attr_name << " to: " << info.name;
1103+
if (op_desc.HasAttr(legacy_attr_name)) {
1104+
paddle::framework::Attribute legacy_attr =
1105+
op_desc.GetAttr(legacy_attr_name);
1106+
VLOG(10) << "attribute in " << op_desc.Type()
1107+
<< " name: " << legacy_attr_name << " " << legacy_attr.index();
1108+
pir::Attribute new_attr =
1109+
attribute_translator(info.type_name, legacy_attr);
1110+
if (legacy_attr_name == "alpha") {
1111+
new_attr = pir::DoubleAttribute::get(
1112+
ctx,
1113+
static_cast<double>(
1114+
new_attr.dyn_cast<pir::FloatAttribute>().data()));
1115+
}
1116+
attribute_map[info.name] = new_attr;
1117+
}
1118+
}
1119+
1120+
return attribute_map;
1121+
}
1122+
};
1123+
10881124
struct Conv2dOpTranscriber : public OpTranscriber {
10891125
void HandleNonexistentAttribute(pir::IrContext* ctx,
10901126
pir::AttributeMap* attribute_map,
@@ -3921,6 +3957,80 @@ struct SyncCommStreamOpTranscriber : public OpTranscriber {
39213957
}
39223958
};
39233959

3960+
struct SoftPlusOpTranscriber : public OpTranscriber {
3961+
pir::AttributeMap TranslateOpAttribute(
3962+
pir::IrContext* ctx,
3963+
const std::string& normalized_op_name,
3964+
const OpAttributeInfoList& op_attr_infos,
3965+
const OpDesc& op_desc) override {
3966+
auto& attribute_translator = AttributeTranslator::instance();
3967+
auto& op_normalizer = OpNameNormalizer::instance();
3968+
pir::AttributeMap attribute_map = {};
3969+
3970+
for (const auto& info : op_attr_infos) {
3971+
auto legacy_attr_name =
3972+
op_normalizer.GetLegacyAttrName(op_desc.Type(), info.name);
3973+
VLOG(10) << "[op: " << op_desc.Type()
3974+
<< "][attr] from: " << legacy_attr_name << " to: " << info.name;
3975+
if (op_desc.HasAttr(legacy_attr_name)) {
3976+
paddle::framework::Attribute legacy_attr =
3977+
op_desc.GetAttr(legacy_attr_name);
3978+
VLOG(10) << "attribute in " << op_desc.Type()
3979+
<< " name: " << legacy_attr_name << " " << legacy_attr.index();
3980+
pir::Attribute new_attr =
3981+
attribute_translator(info.type_name, legacy_attr);
3982+
if (legacy_attr_name == "beta" || legacy_attr_name == "threshold") {
3983+
new_attr = pir::DoubleAttribute::get(
3984+
ctx,
3985+
static_cast<double>(
3986+
new_attr.dyn_cast<pir::FloatAttribute>().data()));
3987+
}
3988+
attribute_map[info.name] = new_attr;
3989+
} else {
3990+
this->HandleNonexistentAttribute(ctx, &attribute_map, info);
3991+
}
3992+
}
3993+
return attribute_map;
3994+
}
3995+
};
3996+
3997+
struct LogitOpTranscriber : public OpTranscriber {
3998+
pir::AttributeMap TranslateOpAttribute(
3999+
pir::IrContext* ctx,
4000+
const std::string& normalized_op_name,
4001+
const OpAttributeInfoList& op_attr_infos,
4002+
const OpDesc& op_desc) override {
4003+
auto& attribute_translator = AttributeTranslator::instance();
4004+
auto& op_normalizer = OpNameNormalizer::instance();
4005+
pir::AttributeMap attribute_map = {};
4006+
4007+
for (const auto& info : op_attr_infos) {
4008+
auto legacy_attr_name =
4009+
op_normalizer.GetLegacyAttrName(op_desc.Type(), info.name);
4010+
VLOG(10) << "[op: " << op_desc.Type()
4011+
<< "][attr] from: " << legacy_attr_name << " to: " << info.name;
4012+
if (op_desc.HasAttr(legacy_attr_name)) {
4013+
paddle::framework::Attribute legacy_attr =
4014+
op_desc.GetAttr(legacy_attr_name);
4015+
VLOG(10) << "attribute in " << op_desc.Type()
4016+
<< " name: " << legacy_attr_name << " " << legacy_attr.index();
4017+
pir::Attribute new_attr =
4018+
attribute_translator(info.type_name, legacy_attr);
4019+
if (legacy_attr_name == "eps") {
4020+
new_attr = pir::DoubleAttribute::get(
4021+
ctx,
4022+
static_cast<double>(
4023+
new_attr.dyn_cast<pir::FloatAttribute>().data()));
4024+
}
4025+
attribute_map[info.name] = new_attr;
4026+
} else {
4027+
this->HandleNonexistentAttribute(ctx, &attribute_map, info);
4028+
}
4029+
}
4030+
return attribute_map;
4031+
}
4032+
};
4033+
39244034
OpTranslator::OpTranslator() {
39254035
pir::IrContext* ctx = pir::IrContext::Instance();
39264036
ctx->GetOrRegisterDialect<paddle::dialect::OperatorDialect>();
@@ -3933,6 +4043,8 @@ OpTranslator::OpTranslator() {
39334043
special_handlers["batch_norm"] = BatchNormOpTranscriber();
39344044
special_handlers["range"] = ArangeOpTranscriber();
39354045
special_handlers["cast"] = CastOpTranscriber();
4046+
special_handlers["leaky_relu"] = LeakyReLUOpTranscriber();
4047+
special_handlers["leaky_relu_grad"] = LeakyReLUOpTranscriber();
39364048
special_handlers["conv2d"] = Conv2dOpTranscriber();
39374049
special_handlers["conv3d"] = Conv3dOpTranscriber();
39384050
special_handlers["cross_entropy_with_softmax"] =
@@ -4033,5 +4145,9 @@ OpTranslator::OpTranslator() {
40334145
WithXShapeAndAxisGradOpTranscriber<dialect::UnsqueezeGradOp>();
40344146

40354147
special_handlers["c_sync_comm_stream"] = SyncCommStreamOpTranscriber();
4148+
special_handlers["softplus"] = SoftPlusOpTranscriber();
4149+
special_handlers["softplus_grad"] = SoftPlusOpTranscriber();
4150+
special_handlers["logit"] = LogitOpTranscriber();
4151+
special_handlers["logit_grad"] = LogitOpTranscriber();
40364152
}
40374153
} // namespace paddle::translator

paddle/fluid/pir/drr/include/drr_pattern_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class TEST_API ResultPattern {
297297

298298
Attribute Float32Attr(float value) const;
299299

300+
Attribute DoubleAttr(double value) const;
301+
300302
Attribute VectorInt64Attr(const std::vector<int64_t>& value) const;
301303

302304
Attribute VectorInt32Attr(const std::vector<int32_t>& value) const;

paddle/fluid/pir/drr/src/pattern_context.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ Attribute ResultPattern::Float32Attr(float value) const {
205205
[=](const MatchContext& match_ctx) -> float { return value; });
206206
}
207207

208+
Attribute ResultPattern::DoubleAttr(double value) const {
209+
return ComputeAttr(
210+
[=](const MatchContext& match_ctx) -> double { return value; });
211+
}
212+
208213
Attribute ResultPattern::VectorInt64Attr(
209214
const std::vector<int64_t>& value) const {
210215
return ComputeAttr(

paddle/fluid/pir/serialize_deserialize/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313

1414
file(GLOB_RECURSE YAML_PATCH_FILES "*.yaml")
1515
# change pir version when new patches are added
16-
add_definitions(-DDEVELOP_VERSION=3)
16+
add_definitions(-DDEVELOP_VERSION=0)
1717
add_definitions(-DRELEASE_VERSION=3)
1818
set(TEMPLATE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/patch/template.h.in)
1919
set(PATCH_HEADER ${CMAKE_CURRENT_BINARY_DIR}/patch/patch.h)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
op_patches:
2+
- op_name : pd_op.leaky_relu
3+
actions:
4+
- action : modify_attr
5+
object : negative_slope
6+
type : pir::DoubleAttribute
7+
- op_name : pd_op.softplus
8+
actions:
9+
- action : modify_attr
10+
object : beta
11+
type : pir::DoubleAttribute
12+
- action : modify_attr
13+
object : threshold
14+
type : pir::DoubleAttribute
15+
- op_name : onednn_op.fused_softplus
16+
actions:
17+
- action : modify_attr
18+
object : beta
19+
type : pir::DoubleAttribute
20+
- action : modify_attr
21+
object : threshold
22+
type : pir::DoubleAttribute
23+
- action : modify_attr
24+
object : fuse_alpha
25+
type : pir::DoubleAttribute
26+
- action : modify_attr
27+
object : fuse_beta
28+
type : pir::DoubleAttribute
29+
- op_name : pd_op.logit
30+
actions:
31+
- action : modify_attr
32+
object : eps
33+
type : pir::DoubleAttribute

paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ConvActivationFusePattern : public paddle::drr::DrrPatternBase {
136136
pat.AddConstraint([&](const paddle::drr::MatchContext &match_ctx) {
137137
if (activation_name_ == "leaky_relu_" ||
138138
activation_name_ == "leaky_relu") {
139-
float negative_slope = match_ctx.Attr<float>("negative_slope");
139+
auto negative_slope = match_ctx.Attr<double>("negative_slope");
140140
// leaky relu alpha is a positive number
141141
if (negative_slope <= 0.0) {
142142
return false;

paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class NConvConcatActivationFusePattern : public paddle::drr::DrrPatternBase {
160160
}
161161
pat.AddConstraint([&](const paddle::drr::MatchContext &match_ctx) {
162162
if (activation_name_ == "leaky_relu") {
163-
float negative_slope = match_ctx.Attr<float>("negative_slope");
163+
double negative_slope = match_ctx.Attr<double>("negative_slope");
164164
// leaky relu alpha is a positive number
165165
if (negative_slope <= 0.0) {
166166
return false;

0 commit comments

Comments
 (0)