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

Function test_split_packed_batch

tests/test_sequence_packer.py:462–613  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

460
461
462def test_split_packed_batch():
463 input_batches = [
464 {
465 "input_ids": tensor(
466 [
467 [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 8, 8],
468 [5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, -1, -1],
469 [7, 7, 7, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 18],
470 ]
471 ),
472 "labels": tensor(
473 [
474 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
475 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
476 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
477 ]
478 ),
479 "cu_seqlens": [
480 tensor([0, 10, 13, 15], dtype=torch.int32),
481 tensor([0, 6, 13, 15], dtype=torch.int32),
482 tensor([0, 3, 10, 14, 15], dtype=torch.int32),
483 ],
484 "max_seqlen": [10, 7, 7],
485 "attention_mask": tensor(
486 [
487 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
488 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
489 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
490 ]
491 ),
492 },
493 {
494 "input_ids": tensor(
495 [
496 [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, -1],
497 [22, 22, 22, 22, 22, 22, 22, 22, 25, 25, 25, 25, 25, 25, 25],
498 [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, -1, -1, -1, -1],
499 ]
500 ),
501 "labels": tensor(
502 [
503 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
504 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
505 [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
506 ]
507 ),
508 "cu_seqlens": [
509 tensor([0, 10, 14, 15], dtype=torch.int32),
510 tensor([0, 8, 15], dtype=torch.int32),
511 tensor([0, 10, 15], dtype=torch.int32),
512 ],
513 "max_seqlen": [10, 8, 10],
514 "attention_mask": tensor(
515 [
516 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
517 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
518 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
519 ]

Callers

nothing calls this directly

Calls 2

split_packed_batchFunction · 0.90
compare_structuresFunction · 0.85

Tested by

no test coverage detected