MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / make_positions

Function make_positions

utils/tts_utils.py:6–17  ·  view source on GitHub ↗

Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols are ignored.

(tensor, padding_idx)

Source from the content-addressed store, hash-verified

4
5
6def make_positions(tensor, padding_idx):
7 """Replace non-padding symbols with their position numbers.
8 Position numbers begin at padding_idx+1. Padding symbols are ignored.
9 """
10 # The series of casts and type-conversions here are carefully
11 # balanced to both work with ONNX export and XLA. In particular XLA
12 # prefers ints, cumsum defaults to output longs, and ONNX doesn't know
13 # how to handle the dtype kwarg in cumsum.
14 mask = tensor.ne(padding_idx).int()
15 return (
16 torch.cumsum(mask, dim=1).type_as(mask) * mask
17 ).long() + padding_idx
18
19
20def softmax(x, dim):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected