MCPcopy Index your code
hub / github.com/openai/guided-diffusion / compute_top_k

Function compute_top_k

scripts/classifier_train.py:185–190  ·  view source on GitHub ↗
(logits, labels, k, reduction="mean")

Source from the content-addressed store, hash-verified

183
184
185def compute_top_k(logits, labels, k, reduction="mean"):
186 _, top_ks = th.topk(logits, k, dim=-1)
187 if reduction == "mean":
188 return (top_ks == labels[:, None]).float().sum(dim=-1).mean().item()
189 elif reduction == "none":
190 return (top_ks == labels[:, None]).float().sum(dim=-1)
191
192
193def split_microbatches(microbatch, *args):

Callers 1

forward_backward_logFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected