codemaivanngu commited on
Commit
5960155
·
verified ·
1 Parent(s): cdb8f01

add padding-trigger ablation for the 4096-cap parity bug

Browse files
Files changed (1) hide show
  1. diag/diagnose_padding_trigger.py +41 -0
diag/diagnose_padding_trigger.py CHANGED
@@ -119,6 +119,47 @@ def main() -> None:
119
  return p
120
 
121
  pos_stored = positions_for(attn)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  prefix = torch.zeros_like(attn)
123
  for i, L in enumerate(lengths):
124
  prefix[i, :L] = 1
 
119
  return p
120
 
121
  pos_stored = positions_for(attn)
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Per-row delta for the stored configuration, for EVERY row.
125
+ #
126
+ # Discriminator between two mechanisms: if rows AFTER the first are affected
127
+ # (row 1 sees row 0, row 3 sees rows 0-2) then the trainer's forward couples
128
+ # rows -- a concatenation/packing-style defect. If only the LONGEST row is
129
+ # affected it is a length/width effect. The two have different fixes.
130
+ # ---------------------------------------------------------------------
131
+ with torch.inference_mode():
132
+ padded_all = model(input_ids=ids.cuda(), attention_mask=attn.cuda(),
133
+ position_ids=pos_stored.cuda(), use_cache=False).logits
134
+ per_row: dict[str, Any] = {}
135
+ for i in range(ids.shape[0]):
136
+ n_i = int(lengths[i])
137
+ with torch.inference_mode():
138
+ ref_i = model(input_ids=ids[i:i + 1, :n_i].cuda(), use_cache=False).logits[0]
139
+ per_row[str(i)] = max_logit_delta(padded_all[i, :n_i], ref_i)
140
+ del ref_i
141
+ torch.cuda.empty_cache()
142
+ print("TRIGGER_PER_ROW=" + json.dumps(
143
+ {"row": i, "length": n_i, **per_row[str(i)]}, sort_keys=True), flush=True)
144
+ del padded_all
145
+ torch.cuda.empty_cache()
146
+ report["per_row_stored_config"] = per_row
147
+
148
+ # Structure of the padded region only: is it a single constant pad value? No
149
+ # token ids are printed, just counts.
150
+ pad_region = []
151
+ for i in range(ids.shape[0]):
152
+ L = int(lengths[i])
153
+ if L >= width:
154
+ pad_region.append({"row": i, "padded_tokens": 0})
155
+ continue
156
+ seg = ids[i, L:]
157
+ uniq = int(torch.unique(seg).numel())
158
+ pad_region.append({"row": i, "padded_tokens": int(seg.numel()),
159
+ "distinct_pad_values": uniq, "all_equal": bool(uniq == 1)})
160
+ report["pad_region_structure"] = pad_region
161
+ print("TRIGGER_PAD_REGION=" + json.dumps(pad_region), flush=True)
162
+
163
  prefix = torch.zeros_like(attn)
164
  for i, L in enumerate(lengths):
165
  prefix[i, :L] = 1