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

Function make_positions

utils/__init__.py:145–157  ·  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

143
144
145def make_positions(tensor, padding_idx):
146 """Replace non-padding symbols with their position numbers.
147
148 Position numbers begin at padding_idx+1. Padding symbols are ignored.
149 """
150 # The series of casts and type-conversions here are carefully
151 # balanced to both work with ONNX export and XLA. In particular XLA
152 # prefers ints, cumsum defaults to output longs, and ONNX doesn't know
153 # how to handle the dtype kwarg in cumsum.
154 mask = tensor.ne(padding_idx).int()
155 return (
156 torch.cumsum(mask, dim=1).type_as(mask) * mask
157 ).long() + padding_idx
158
159
160def softmax(x, dim):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected