farguney commited on
Commit
05bc0dc
·
verified ·
1 Parent(s): a8c6b98

Upload jobs/g1fs16_probe.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. jobs/g1fs16_probe.py +17 -4
jobs/g1fs16_probe.py CHANGED
@@ -752,11 +752,24 @@ def train_one(seed: int, perms: List[np.ndarray],
752
  # is a variance-reduction of a listed term, not a new one.
753
  exec_term = per_word.new_zeros(())
754
  for mask in strata:
755
- mass = float(q[mask].sum())
756
- if mass <= 0.0:
 
 
 
 
 
 
 
 
 
 
757
  continue
758
- sub = q[mask] / mass
759
- pick = int(torch.multinomial(sub, 1))
 
 
 
760
  idx = int(mask.nonzero()[pick])
761
  exec_term = exec_term + mass * per_word[idx]
762
  else:
 
752
  # is a variance-reduction of a listed term, not a new one.
753
  exec_term = per_word.new_zeros(())
754
  for mask in strata:
755
+ wts = q[mask]
756
+ mass = float(wts.sum())
757
+ # A stratum can hold thousands of words whose total
758
+ # posterior mass underflows once the posterior
759
+ # concentrates -- the composite stratum at depth 10 holds
760
+ # 2044 of the 2047 words and goes to ~0 the moment a
761
+ # singleton wins. Normalizing by that mass produced a
762
+ # distribution containing inf and tripped a device-side
763
+ # assert inside multinomial. Sampling from UNNORMALIZED
764
+ # non-negative weights is exactly equivalent -- torch
765
+ # normalizes internally -- and removes the division.
766
+ if not math.isfinite(mass) or mass <= 0.0:
767
  continue
768
+ wts = torch.nan_to_num(wts, nan=0.0, posinf=0.0,
769
+ neginf=0.0).clamp_min(0.0)
770
+ if float(wts.sum()) <= 0.0:
771
+ continue
772
+ pick = int(torch.multinomial(wts, 1))
773
  idx = int(mask.nonzero()[pick])
774
  exec_term = exec_term + mass * per_word[idx]
775
  else: