Skip to content
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
2 changes: 1 addition & 1 deletion paddle/phi/infermeta/multiary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ void FusedBiasActInferMeta(const MetaTensor& x,
x_shapes.push_back(x_dims[i]);
}

if (config.is_runtime) {
if (config.is_runtime && x.numel() != 0) {
PADDLE_ENFORCE_GT(
x.numel() / dim,
0,
Expand Down
14 changes: 14 additions & 0 deletions paddle/phi/kernels/fusion/gpu/fused_bias_act_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ void FusedBiasActKernel(const Context &dev_ctx,
float quant_max_bound,
float quant_min_bound,
DenseTensor *out) {
if (out && out->numel() == 0) {
if (quant_scale > 0) {
dev_ctx.template Alloc<int8_t>(out);
} else if (compute_dtype == "fp16") {
dev_ctx.template Alloc<phi::dtype::float16>(out);
} else if (compute_dtype == "bf16") {
dev_ctx.template Alloc<phi::dtype::bfloat16>(out);
} else if (compute_dtype == "fp32") {
dev_ctx.template Alloc<float>(out);
} else {
dev_ctx.template Alloc<T>(out);
}
return;
}
int64_t cols = x.dims()[x.dims().size() - 1];
int64_t rows = x.numel() / cols;
if (x.dtype() == phi::DataType::INT32) {
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/kernels/fusion/xpu/fused_bias_act_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void FusedBiasActKernel(const Context &dev_ctx,
DenseTensor *out) {
auto xpu_ctx = static_cast<const phi::XPUContext *>(&dev_ctx);
dev_ctx.template Alloc<T>(out);
if (out->numel() == 0) return;

if (dequant_scales && dequant_scales.get().numel() > 0) {
return DispatchComputeImpl<T>(xpu_ctx,
Expand Down
26 changes: 26 additions & 0 deletions test/legacy_test/test_fused_bias_act_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,31 @@ def test_check_output(self):
)


@unittest.skipIf(
not core.is_compiled_with_cuda() and not core.is_compiled_with_rocm(),
"core is not compiled with CUDA or ROCm",
)
class TestFusedBiasActOp_ZeroSize(TestWithoutBias):
def setUp(self):
paddle.seed(2017)
np.random.seed(2017)

self.op_type = "fused_bias_act"
self.rtol = 1e-5
self.atol = 1e-3

self.batch_size = 2
self.seq_len = 0
self.cols = 512

self.dtype = 'float32'
self.act_method = 'gelu'

self.use_glu = False

self.init_test_case()
self.generate_inputs()


if __name__ == '__main__':
unittest.main()