Spaces:
Build error
Build error
Download utils/tts_utils.py from Silentlin/DiffSinger: direct link, hf CLI and curl.
- Browser
- Download file 760 Bytes
-
https://huggingface.co/spaces/Silentlin/DiffSinger/resolve/main/utils/tts_utils.py
- Command line
-
hf download hf://spaces/Silentlin/DiffSinger/utils/tts_utils.py
-
curl -L -o tts_utils.py https://huggingface.co/spaces/Silentlin/DiffSinger/resolve/main/utils/tts_utils.py
760 Bytes
| import torch | |
| import torch.nn.functional as F | |
| from collections import defaultdict | |
| def make_positions(tensor, padding_idx): | |
| """Replace non-padding symbols with their position numbers. | |
| Position numbers begin at padding_idx+1. Padding symbols are ignored. | |
| """ | |
| # The series of casts and type-conversions here are carefully | |
| # balanced to both work with ONNX export and XLA. In particular XLA | |
| # prefers ints, cumsum defaults to output longs, and ONNX doesn't know | |
| # how to handle the dtype kwarg in cumsum. | |
| mask = tensor.ne(padding_idx).int() | |
| return ( | |
| torch.cumsum(mask, dim=1).type_as(mask) * mask | |
| ).long() + padding_idx | |
| def softmax(x, dim): | |
| return F.softmax(x, dim=dim, dtype=torch.float32) | |