MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / sinusoidal_embedding_1d

Function sinusoidal_embedding_1d

models/transformer/wan/modules/tm2m_model.py:211–221  ·  view source on GitHub ↗
(dim, position)

Source from the content-addressed store, hash-verified

209
210
211def sinusoidal_embedding_1d(dim, position):
212 # preprocess
213 assert dim % 2 == 0
214 half = dim // 2
215 position = position.type(torch.float64)
216
217 # calculation
218 sinusoid = torch.outer(
219 position, torch.pow(10000, -torch.arange(half).to(position).div(half)))
220 x = torch.cat([torch.cos(sinusoid), torch.sin(sinusoid)], dim=1)
221 return x
222
223
224@amp.autocast(enabled=False, device_type="cuda")

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected