Skip to content
Closed
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
4 changes: 4 additions & 0 deletions aten/src/ATen/native/TensorShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,12 @@ Tensor cat(TensorList tensors, Dimname dim) {

// torch.concat, alias for torch.cat
Tensor& concat_out(TensorList tensors, Dimname dim, Tensor& result) {
TORCH_CHECK(!tensors.empty(), "expected a non-empty list of Tensors");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TORCH_CHECK(!tensors.empty(), "expected a non-empty list of Tensors");
TORCH_CHECK_VALUE(!tensors.empty(), "expected a non-empty list of Tensors");

These should all be ValueErrors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll replace all of them in #155460

return at::cat_out(result, tensors, dimname_to_position(tensors[0], dim));
}

Tensor concat(TensorList tensors, Dimname dim) {
TORCH_CHECK(!tensors.empty(), "expected a non-empty list of Tensors");
return at::cat(tensors, dimname_to_position(tensors[0], dim));
}

Expand All @@ -791,10 +793,12 @@ Tensor concat(TensorList tensors, int64_t dim) {

// torch.concatenate, alias for torch.cat
Tensor& concatenate_out(TensorList tensors, Dimname dim, Tensor& result) {
TORCH_CHECK(!tensors.empty(), "expected a non-empty list of Tensors");
return at::cat_out(result, tensors, dimname_to_position(tensors[0], dim));
}

Tensor concatenate(TensorList tensors, Dimname dim) {
TORCH_CHECK(!tensors.empty(), "expected a non-empty list of Tensors");
return at::cat(tensors, dimname_to_position(tensors[0], dim));
}

Expand Down
8 changes: 8 additions & 0 deletions test/test_tensor_creation_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ def test_cat_empty(self, device):
res1 = torch.cat([empty, empty], dim=1)
self.assertEqual(res1, empty)

def test_concat_empty_list_error(self, device):
# Regression test for https://github.com/pytorch/pytorch/issues/155306
msg = "expected a non-empty list of Tensors"
with self.assertRaisesRegex(RuntimeError, msg):
torch.concat([], dim='N')
with self.assertRaisesRegex(RuntimeError, msg):
torch.concatenate([], dim='N')

def test_cat_out(self, device):
x = torch.zeros((0), device=device)
y = torch.randn((4, 6), device=device)
Expand Down
Loading