Commit ·
a1a9de3
1
Parent(s): e1515b2
fix(h1b): exclude non-EOS specials in offline row_groups
Browse filesSampled reserved specials passed grouping and crashed exact_strprob in VocabIndex.bytes with KeyError. row_groups now marks such responses invalid with reason unsupported_special, using _special_token_ids exactly like the training_step post-filter. Adds T9b regression test; updates H1B_SOURCE hashes with fix entry. Numerical kernels and frozen Strict files unchanged.
- docs/H1B_SOURCE.json +10 -2
- tests/test_h1b.py +19 -0
- tools/h1b/common.py +20 -2
docs/H1B_SOURCE.json
CHANGED
|
@@ -52,7 +52,7 @@
|
|
| 52 |
},
|
| 53 |
{
|
| 54 |
"path": "tools/h1b/common.py",
|
| 55 |
-
"sha256": "
|
| 56 |
},
|
| 57 |
{
|
| 58 |
"path": "tools/h1b/enrich_archive.py",
|
|
@@ -88,7 +88,7 @@
|
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"path": "tests/test_h1b.py",
|
| 91 |
-
"sha256": "
|
| 92 |
}
|
| 93 |
],
|
| 94 |
"frozen_strict": [
|
|
@@ -125,5 +125,13 @@
|
|
| 125 |
"scope": "Automatic runtime selection/ensure only; H1b numerical algorithm and kernels unchanged",
|
| 126 |
"baseline_commit": "2bf0f47109fb9435232d77c1509eba0d894910ea",
|
| 127 |
"path": "tools/h1b/canary.py"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
}
|
|
|
|
| 52 |
},
|
| 53 |
{
|
| 54 |
"path": "tools/h1b/common.py",
|
| 55 |
+
"sha256": "42947a601031445a49d63915ba3e5849cc8172d62fdec256fe9065e0f3596176"
|
| 56 |
},
|
| 57 |
{
|
| 58 |
"path": "tools/h1b/enrich_archive.py",
|
|
|
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"path": "tests/test_h1b.py",
|
| 91 |
+
"sha256": "3e9bc8203c5f4fce2ea1bab21815bc184fbd8e972dc6d0b991dfbc6771710ed9"
|
| 92 |
}
|
| 93 |
],
|
| 94 |
"frozen_strict": [
|
|
|
|
| 125 |
"scope": "Automatic runtime selection/ensure only; H1b numerical algorithm and kernels unchanged",
|
| 126 |
"baseline_commit": "2bf0f47109fb9435232d77c1509eba0d894910ea",
|
| 127 |
"path": "tools/h1b/canary.py"
|
| 128 |
+
},
|
| 129 |
+
"unsupported_special_offline_fix": {
|
| 130 |
+
"updated_sha256": {
|
| 131 |
+
"tools/h1b/common.py": "42947a601031445a49d63915ba3e5849cc8172d62fdec256fe9065e0f3596176",
|
| 132 |
+
"tests/test_h1b.py": "3e9bc8203c5f4fce2ea1bab21815bc184fbd8e972dc6d0b991dfbc6771710ed9"
|
| 133 |
+
},
|
| 134 |
+
"date": "2026-10-20",
|
| 135 |
+
"scope": "Offline row_groups now marks responses containing non-EOS special IDs invalid with reason unsupported_special, using _special_token_ids exactly like the training_step post-filter; previously such responses (e.g. sampled <|reserved_special_token_209|>) crashed exact_strprob in VocabIndex.bytes with KeyError. Numerical kernels and frozen Strict files unchanged"
|
| 136 |
}
|
| 137 |
}
|
tests/test_h1b.py
CHANGED
|
@@ -58,6 +58,25 @@ class H1bTests(unittest.TestCase):
|
|
| 58 |
a=([g.t_idx[0] for g in groups],[g.s_idx[0] for g in groups])
|
| 59 |
self.assertEqual(a,align_byte_span_batch_1to1(tea,stu,tok.eos_token,tok.eos_token,codec,codec))
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def test_T4_trunk_and_exact_enumeration_with_duplicate_byte_ids(self):
|
| 62 |
from kdflow.h1b.vocab_index import VocabIndex
|
| 63 |
from kdflow.h1b.strprob import chunk_logprobs
|
|
|
|
| 58 |
a=([g.t_idx[0] for g in groups],[g.s_idx[0] for g in groups])
|
| 59 |
self.assertEqual(a,align_byte_span_batch_1to1(tea,stu,tok.eos_token,tok.eos_token,codec,codec))
|
| 60 |
|
| 61 |
+
def test_T9b_row_groups_rejects_unsupported_special_whole_response(self):
|
| 62 |
+
import torch
|
| 63 |
+
from tools.h1b.common import row_groups
|
| 64 |
+
# A sampled reserved special must invalidate the whole response with
|
| 65 |
+
# reason 'unsupported_special', matching the training_step post-filter,
|
| 66 |
+
# instead of reaching the byte vocabulary index (KeyError there).
|
| 67 |
+
class Tok(fixtures.Tokenizer):
|
| 68 |
+
pieces={0:'<eos>',1:'a',2:'b',7:'<pad>',8:'<rsvd>'}
|
| 69 |
+
all_special_ids=[0,7,8]
|
| 70 |
+
tok=Tok()
|
| 71 |
+
ids=torch.tensor([[1,2,0],[1,8,0]])
|
| 72 |
+
mask=torch.tensor([[True,True,False],[True,True,False]])
|
| 73 |
+
batch={'stu_input_ids':ids,'stu_loss_mask':mask,'stu_attn_mask':torch.ones_like(ids),
|
| 74 |
+
'tea_input_ids':ids.clone(),'tea_loss_mask':mask.clone(),'tea_attn_mask':torch.ones_like(ids)}
|
| 75 |
+
rows=row_groups(batch,tok,tok)
|
| 76 |
+
self.assertTrue(rows[0].valid)
|
| 77 |
+
self.assertFalse(rows[1].valid)
|
| 78 |
+
self.assertEqual(rows[1].reason,'unsupported_special')
|
| 79 |
+
|
| 80 |
def test_T4_trunk_and_exact_enumeration_with_duplicate_byte_ids(self):
|
| 81 |
from kdflow.h1b.vocab_index import VocabIndex
|
| 82 |
from kdflow.h1b.strprob import chunk_logprobs
|
tools/h1b/common.py
CHANGED
|
@@ -67,14 +67,32 @@ def tokenize_record(record,student_tok,teacher_tok,assume_shared_prompt=False):
|
|
| 67 |
|
| 68 |
|
| 69 |
def row_groups(batch,student_tok,teacher_tok):
|
| 70 |
-
from
|
|
|
|
| 71 |
from kdflow.h1b.groups import align_byte_span_groups_batch
|
| 72 |
rows=[]
|
| 73 |
for key,tok in (('tea',teacher_tok),('stu',student_tok)):
|
| 74 |
labels=batch[key+'_input_ids'].roll(-1,1)
|
| 75 |
rows.append([tok.convert_ids_to_tokens(labels[i][batch[key+'_loss_mask'][i].bool()].tolist()) for i in range(len(labels))])
|
| 76 |
-
|
| 77 |
get_tokenizer_byte_codec(teacher_tok).piece_to_bytes,get_tokenizer_byte_codec(student_tok).piece_to_bytes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
def forward_hidden(model,batch,prefix):
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
def row_groups(batch,student_tok,teacher_tok):
|
| 70 |
+
from dataclasses import replace
|
| 71 |
+
from kdflow.token_alignment import get_tokenizer_byte_codec,_special_token_ids
|
| 72 |
from kdflow.h1b.groups import align_byte_span_groups_batch
|
| 73 |
rows=[]
|
| 74 |
for key,tok in (('tea',teacher_tok),('stu',student_tok)):
|
| 75 |
labels=batch[key+'_input_ids'].roll(-1,1)
|
| 76 |
rows.append([tok.convert_ids_to_tokens(labels[i][batch[key+'_loss_mask'][i].bool()].tolist()) for i in range(len(labels))])
|
| 77 |
+
grouped=align_byte_span_groups_batch(*rows,teacher_tok.eos_token,student_tok.eos_token,
|
| 78 |
get_tokenizer_byte_codec(teacher_tok).piece_to_bytes,get_tokenizer_byte_codec(student_tok).piece_to_bytes)
|
| 79 |
+
# Twin of the H1bSpanCTKD.training_step post-filter: any non-EOS special ID
|
| 80 |
+
# invalidates the whole response, because the byte vocabulary index has no
|
| 81 |
+
# entry for specials (e.g. sampled <|reserved_special_token_*|>). Both sites
|
| 82 |
+
# must use _special_token_ids so the exclusion set can never drift apart.
|
| 83 |
+
tea_special,stu_special=_special_token_ids(teacher_tok),_special_token_ids(student_tok)
|
| 84 |
+
tea_eos,stu_eos=teacher_tok.eos_token_id,student_tok.eos_token_id
|
| 85 |
+
tea_ids=batch['tea_input_ids'].roll(-1,1); stu_ids=batch['stu_input_ids'].roll(-1,1)
|
| 86 |
+
tea_mask=batch['tea_loss_mask'].bool(); stu_mask=batch['stu_loss_mask'].bool()
|
| 87 |
+
fixed=[]
|
| 88 |
+
for i,row in enumerate(grouped):
|
| 89 |
+
tids=tea_ids[i][tea_mask[i]].tolist(); sids=stu_ids[i][stu_mask[i]].tolist()
|
| 90 |
+
if (any(t in tea_special and t!=tea_eos for t in tids)
|
| 91 |
+
or any(s in stu_special and s!=stu_eos for s in sids)):
|
| 92 |
+
fixed.append(replace(row,groups=(),valid=False,reason='unsupported_special'))
|
| 93 |
+
else:
|
| 94 |
+
fixed.append(row)
|
| 95 |
+
return fixed
|
| 96 |
|
| 97 |
|
| 98 |
def forward_hidden(model,batch,prefix):
|