"""Score padded embeddings using the local experimental MaxSim provider.""" from __future__ import annotations from pathlib import Path import torch import torch.nn.functional as F from kernels import get_local_kernel kernel = get_local_kernel(Path(__file__).resolve().parent) a = F.normalize(torch.randn(4, 32, 128, device="cuda"), dim=-1).half().requires_grad_() b = F.normalize(torch.randn(8, 180, 128, device="cuda"), dim=-1).half().requires_grad_() scores = kernel.layers.MaxSim()(a, b, None, None) scores.sum().backward() print(scores.shape, a.grad.norm().item(), b.grad.norm().item())