Skip to content

Instantly share code, notes, and snippets.

View DeNeutoy's full-sized avatar

Mark Neumann DeNeutoy

View GitHub Profile
from mpmath import mp
mp.dps = 100
import torch
# Take some list of values that shrink to be really small in log space:
torch_lps = torch.log_softmax(-torch.arange(20.0, dtype=torch.float64), dim=0)
mpmath_lps = -torch.arange(20.0, dtype=torch.float64)
Z = sum([mp.exp(mp.mpf(mpmath_lps[i].item())) for i in range(len(mpmath_lps))])