(allocator: BlockAllocator)
| 39 | |
| 40 | |
| 41 | def test_basic_caching(allocator: BlockAllocator): |
| 42 | allocator.sanity_checks() |
| 43 | |
| 44 | input_ids1 = [1] * 12 |
| 45 | input_ids2 = [1] * 8 |
| 46 | input_ids3 = [2] |
| 47 | input_ids4 = [3] |
| 48 | |
| 49 | completion_ids1 = input_ids1 + [9] * 2 |
| 50 | completion_ids2 = input_ids2 + [9] * 3 |
| 51 | completion_ids3 = input_ids3 + [9] * 4 |
| 52 | |
| 53 | kvs1, num_cached1 = allocator.allocate_with_prefix_match("seq1", input_ids1) |
| 54 | allocator.sanity_checks() |
| 55 | |
| 56 | assert num_cached1 == 0 |
| 57 | |
| 58 | kvs1.extend(allocator.allocate_up_to_length("seq1", kvs1, len(completion_ids1))) |
| 59 | allocator.sanity_checks() |
| 60 | |
| 61 | kvs2, num_cached2 = allocator.allocate_with_prefix_match("seq2", input_ids2) |
| 62 | allocator.sanity_checks() |
| 63 | |
| 64 | # 4, not 8, since last block isn't cached |
| 65 | assert num_cached2 == 4 |
| 66 | assert kvs2[0] == kvs1[0] |
| 67 | assert kvs2[1] != kvs1[1] |
| 68 | |
| 69 | kvs2.extend(allocator.allocate_up_to_length("seq2", kvs2, len(completion_ids2))) |
| 70 | allocator.sanity_checks() |
| 71 | |
| 72 | kvs3, num_cached3 = allocator.allocate_with_prefix_match("seq3", input_ids3) |
| 73 | allocator.sanity_checks() |
| 74 | |
| 75 | assert num_cached3 == 0 |
| 76 | |
| 77 | kvs3.extend(allocator.allocate_up_to_length("seq3", kvs3, len(completion_ids3))) |
| 78 | allocator.sanity_checks() |
| 79 | |
| 80 | with pytest.raises(NoSpaceException): |
| 81 | allocator.allocate_with_prefix_match("seq4", input_ids4) |
| 82 | |
| 83 | |
| 84 | def test_basic_free(allocator: BlockAllocator): |
nothing calls this directly
no test coverage detected