MCPcopy Create free account
hub / github.com/SooLab/CGFormer / hard_softmax

Function hard_softmax

model/layers.py:40–46  ·  view source on GitHub ↗
(logits, dim)

Source from the content-addressed store, hash-verified

38 nn.BatchNorm2d(out_dim), nn.ReLU(True))
39
40def hard_softmax(logits, dim):
41 y_soft = logits.softmax(dim)
42 # Straight through.
43 index = y_soft.max(dim, keepdim=True)[1]
44 y_hard = torch.zeros_like(logits, memory_format=torch.legacy_contiguous_format).scatter_(dim, index, 1.0)
45 ret = y_hard - y_soft.detach() + y_soft
46 return ret
47
48def gumbel_softmax(logits: torch.Tensor, tau: float = 1, dim: int = -2) -> torch.Tensor:
49 gumbel_dist = torch.distributions.gumbel.Gumbel(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected