MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / scale_for_cosine_sim_qkv

Function scale_for_cosine_sim_qkv

k_diffusion/models/attention.py:48–51  ·  view source on GitHub ↗
(qkv, scale, eps)

Source from the content-addressed store, hash-verified

46 return q * scale_q.to(q.dtype), k * scale_k.to(k.dtype)
47
48def scale_for_cosine_sim_qkv(qkv, scale, eps):
49 q, k, v = qkv.unbind(2)
50 q, k = scale_for_cosine_sim(q, k, scale[:, None], eps)
51 return torch.stack((q, k, v), dim=2)
52
53def scale_for_cosine_sim_single(q, scale, eps):
54 dtype = reduce(torch.promote_types, (q.dtype, scale.dtype, torch.float32))

Callers 1

forwardMethod · 0.70

Calls 1

scale_for_cosine_simFunction · 0.70

Tested by

no test coverage detected