Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions paddle/phi/kernels/fusion/gpu/fused_layernorm_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,13 @@ void FusedLayerNormKernel(const Context& dev_ctx,
}

using U = phi::funcs::LayerNormParamType<T>;
if (x.numel() == 0) {
dev_ctx.template Alloc<T>(out);
if (residual_out) dev_ctx.template Alloc<T>(residual_out);
if (mean) dev_ctx.template Alloc<U>(mean);
if (variance) dev_ctx.template Alloc<U>(variance);
return;
}
const T* x_data = x.data<T>();
const U* norm_weight_data =
norm_weight ? norm_weight.get().data<U>() : nullptr;
Expand Down
25 changes: 25 additions & 0 deletions test/legacy_test/test_fused_layernorm_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,5 +1204,30 @@ def test_residual_bias_add_layernorm(self):
)


@unittest.skipIf(
not core.is_compiled_with_cuda() and not paddle.is_compiled_with_rocm(),
"core is not compiled with CUDA or ROCM",
)
class TestlayernormOp_ZeroSize(TestlayernormOp):
def setUp(self):
np.random.seed(20)
# 0-size
batch = 0
cols = 256

self.x_np = np.random.uniform(-0.05, 0.05, [batch, cols])
self.residual_np = np.random.uniform(-0.05, 0.05, [batch, cols])
self.bias_np = np.random.uniform(-0.05, 0.05, [cols])
self.norm_weight_np = np.random.uniform(-0.05, 0.05, [cols])
self.norm_bias_np = np.random.uniform(-0.05, 0.05, [cols])
self.epsilon = 1e-5
self.residual_alpha = np.random.uniform(low=0.1, high=1.1, size=[1])

self.quant_scale = 0.15
self.quant_round_type = 1
self.quant_max_bound = 127
self.quant_min_bound = -127


if __name__ == "__main__":
unittest.main()
Loading