Skip to content

[0-size Tensor No.85] Add 0-size Tensor support for paddle.incubate.nn.functional.fused_matmul_bias #74152

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

Merged
merged 2 commits into from
Jul 23, 2025
Merged
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
19 changes: 19 additions & 0 deletions test/legacy_test/test_fused_matmul_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,24 @@ def test_static_graph(self):
paddle.disable_static()


@unittest.skipIf(
not is_fused_matmul_bias_supported(),
"fused_gemm_epilogue is only supported when CUDA version >= 11.6",
)
class TestFusedLinear_ZeroSize(unittest.TestCase):
def check_fused_linear(self, transpose):
x = paddle.randn([0, 40])
x.stop_gradient = False
linear = FusedLinear(40, 50, transpose_weight=transpose)
y1 = linear(x)
y2 = fused_linear(x, linear.weight, linear.bias, transpose)
np.testing.assert_array_equal(y1.numpy(), y2.numpy())
y2.sum().backward()
np.testing.assert_allclose(x.grad.shape, x.shape)

def test_non_transpose(self):
self.check_fused_linear(False)


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