(logits, dim)
| 38 | nn.BatchNorm2d(out_dim), nn.ReLU(True)) |
| 39 | |
| 40 | def 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 | |
| 48 | def gumbel_softmax(logits: torch.Tensor, tau: float = 1, dim: int = -2) -> torch.Tensor: |
| 49 | gumbel_dist = torch.distributions.gumbel.Gumbel( |
nothing calls this directly
no outgoing calls
no test coverage detected