Skip to content

Commit 4f9d17a

Browse files
authored
[0-size Tensor No.184] Add 0-size Tensor support for label_smooth (#72993)
1 parent 98db28a commit 4f9d17a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/legacy_test/test_label_smooth_op.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ def setUp(self):
173173
)
174174

175175

176+
class TestLabelSmoothOp_ZeroSize(TestLabelSmoothOp):
177+
def config(self):
178+
self.op_type = "label_smooth"
179+
self.python_api = paddle.nn.functional.label_smooth
180+
self.init_dtype()
181+
self.epsilon = 0.1
182+
batch_size, self.label_dim = 0, 12
183+
self.label = np.zeros((batch_size, self.label_dim)).astype(self.dtype)
184+
nonzero_index = np.random.randint(self.label_dim, size=(batch_size))
185+
self.label[np.arange(batch_size), nonzero_index] = 1
186+
187+
176188
if __name__ == '__main__':
177189
paddle.enable_static()
178190
unittest.main()

0 commit comments

Comments
 (0)