MCPcopy Create free account
hub / github.com/AnswerDotAI/ModernBERT / test_packer_masking

Function test_packer_masking

tests/test_sequence_packer.py:148–248  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146
147
148def test_packer_masking():
149 input_batch_size = 4
150 xds = [{"input_ids": seq} for seq in xs]
151 input_batches = list(batched(xds, input_batch_size))
152 d = {
153 "src_iterable": input_batches,
154 "src_batch_size": input_batch_size,
155 "src_max_seq_len": max_seq_len,
156 "out_batch_size": 5,
157 "out_pseq_len": 15,
158 "buffer_size": 5,
159 "pad_token_id": -1,
160 "mask_token_id": -2,
161 "ignore_token_id": -3,
162 "mask_prob": 0.0, # 0 mask probability, like no masking
163 "seed": 42,
164 "suppress_masking": False,
165 }
166
167 out_batches = list(GreedyBestFitSequencePacker(**d))
168
169 # expected given a seed of 42!
170 out_expected = [
171 {
172 "input_ids": tensor(
173 [
174 [0, 0, 0, 0, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4],
175 [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 8, 8],
176 [5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, -1, -1],
177 [7, 7, 7, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 18],
178 [12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14],
179 ]
180 ),
181 "labels": tensor(
182 [
183 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
184 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
185 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
186 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
187 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
188 ]
189 ),
190 "cu_seqlens": [
191 tensor([0, 4, 9, 15], dtype=torch.int32),
192 tensor([0, 10, 13, 15], dtype=torch.int32),
193 tensor([0, 6, 13, 15], dtype=torch.int32),
194 tensor([0, 3, 10, 14, 15], dtype=torch.int32),
195 tensor([0, 4, 12, 15], dtype=torch.int32),
196 ],
197 "max_seqlen": [6, 10, 7, 7, 8],
198 "attention_mask": tensor(
199 [
200 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
201 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
202 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
203 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
204 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
205 ]

Callers

nothing calls this directly

Calls 3

batchedFunction · 0.85
compare_structuresFunction · 0.85

Tested by

no test coverage detected