Commit 01f226b
Add check for ctc_loss targets param (#150981)
Fixes #150835
## Test Result
```python
# cuda
>>> import torch
>>> import torch.nn.functional as F
>>> device = "cuda" # "cpu" is fine
>>> num_classes = 4
>>> log_probs = torch.rand(0, 0, num_classes, device=device)
>>> targets = torch.tensor([], device=device, dtype=torch.long)
>>> input_lengths = torch.tensor([], device=device, dtype=torch.long)
>>> target_lengths = torch.tensor([], device=device, dtype=torch.long)
>>> result = F.ctc_loss(log_probs, targets, input_lengths, target_lengths, reduction='none')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/zong/code/pytorch/torch/nn/functional.py", line 3079, in ctc_loss
return torch.ctc_loss(
^^^^^^^^^^^^^^^
RuntimeError: log_probs tensor must not be empty
# cpu
>>> device = "cpu"
>>> num_classes = 4
>>> log_probs = torch.rand(0, 0, num_classes, device=device)
>>> targets = torch.tensor([], device=device, dtype=torch.long)
>>> input_lengths = torch.tensor([], device=device, dtype=torch.long)
>>> target_lengths = torch.tensor([], device=device, dtype=torch.long)
>>> result = F.ctc_loss(log_probs, targets, input_lengths, target_lengths, reduction='none')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/zong/code/pytorch/torch/nn/functional.py", line 3079, in ctc_loss
return torch.ctc_loss(
^^^^^^^^^^^^^^^
RuntimeError: log_probs tensor must not be empty
```
Pull Request resolved: #150981
Approved by: https://github.com/eqy1 parent bbc5fe8 commit 01f226b
File tree
3 files changed
+11
-0
lines changed- aten/src/ATen/native
- cuda
- test
3 files changed
+11
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11532 | 11532 | | |
11533 | 11533 | | |
11534 | 11534 | | |
| 11535 | + | |
| 11536 | + | |
| 11537 | + | |
| 11538 | + | |
| 11539 | + | |
| 11540 | + | |
| 11541 | + | |
| 11542 | + | |
| 11543 | + | |
11535 | 11544 | | |
11536 | 11545 | | |
11537 | 11546 | | |
| |||
0 commit comments