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

Function sinusoidal_embedding_1d

models/transformer/wan/modules/t2m_model.py:210–220  ·  view source on GitHub ↗
(dim, position)

Source from the content-addressed store, hash-verified

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

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected