()
| 78 | |
| 79 | |
| 80 | def test_packer(): |
| 81 | input_batch_size = 4 |
| 82 | xds = [{"input_ids": seq} for seq in xs] |
| 83 | input_batches = list(batched(xds, input_batch_size)) |
| 84 | d = { |
| 85 | "src_iterable": input_batches, |
| 86 | "src_batch_size": input_batch_size, |
| 87 | "src_max_seq_len": max_seq_len, |
| 88 | "out_batch_size": 5, |
| 89 | "out_pseq_len": 15, |
| 90 | "buffer_size": 5, |
| 91 | "pad_token_id": -1, |
| 92 | "mask_token_id": -2, |
| 93 | "ignore_token_id": -3, |
| 94 | "mask_prob": 0.0, |
| 95 | "seed": 42, |
| 96 | "suppress_masking": True, |
| 97 | } |
| 98 | |
| 99 | out_batches = list(GreedyBestFitSequencePacker(**d)) |
| 100 | |
| 101 | out_expected = [ |
| 102 | { |
| 103 | "input_ids": tensor( |
| 104 | [ |
| 105 | [0, 0, 0, 0, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4], |
| 106 | [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 8, 8], |
| 107 | [5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, -1, -1], |
| 108 | [7, 7, 7, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 18], |
| 109 | [12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14], |
| 110 | ] |
| 111 | ), |
| 112 | "labels": None, |
| 113 | "cu_seqlens": [ |
| 114 | tensor([0, 4, 9, 15], dtype=torch.int32), |
| 115 | tensor([0, 10, 13, 15], dtype=torch.int32), |
| 116 | tensor([0, 6, 13, 15], dtype=torch.int32), |
| 117 | tensor([0, 3, 10, 14, 15], dtype=torch.int32), |
| 118 | tensor([0, 4, 12, 15], dtype=torch.int32), |
| 119 | ], |
| 120 | "max_seqlen": [6, 10, 7, 7, 8], |
| 121 | }, |
| 122 | { |
| 123 | "input_ids": tensor( |
| 124 | [ |
| 125 | [19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 17, 17, 23, 23, -1], |
| 126 | [16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, -1], |
| 127 | [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, -1], |
| 128 | [22, 22, 22, 22, 22, 22, 22, 22, 25, 25, 25, 25, 25, 25, 25], |
| 129 | [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -1, -1, -1, -1, -1], |
| 130 | ] |
| 131 | ), |
| 132 | "labels": None, |
| 133 | "cu_seqlens": [ |
| 134 | tensor([0, 4, 12, 14, 15], dtype=torch.int32), |
| 135 | tensor([0, 7, 14, 15], dtype=torch.int32), |
| 136 | tensor([0, 10, 14, 15], dtype=torch.int32), |
| 137 | tensor([0, 8, 15], dtype=torch.int32), |
nothing calls this directly
no test coverage detected