MCPcopy Create free account
hub / github.com/BorealisAI/scaleformer / rel

Method rel

layers/utils.py:400–412  ·  view source on GitHub ↗
(self, x, y)

Source from the content-addressed store, hash-verified

398 return all_norms
399
400 def rel(self, x, y):
401 num_examples = x.size()[0]
402
403 diff_norms = torch.norm(x.reshape(num_examples,-1) - y.reshape(num_examples,-1), self.p, 1)
404 y_norms = torch.norm(y.reshape(num_examples,-1), self.p, 1)
405
406 if self.reduction:
407 if self.size_average:
408 return torch.mean(diff_norms/y_norms)
409 else:
410 return torch.sum(diff_norms/y_norms)
411
412 return diff_norms/y_norms
413
414 def __call__(self, x, y):
415 return self.rel(x, y)

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected