| 609 | } |
| 610 | |
| 611 | llama_ubatch llama_batch_allocr::split_seq(uint32_t n_ubatch) { |
| 612 | // find the first unused token |
| 613 | uint32_t cur_idx = 0; |
| 614 | while (cur_idx < used.size() && used[cur_idx]) { |
| 615 | ++cur_idx; |
| 616 | } |
| 617 | |
| 618 | // we are done |
| 619 | if (cur_idx >= used.size()) { |
| 620 | return {}; |
| 621 | } |
| 622 | |
| 623 | // this is the starting sequence set |
| 624 | // we allow adding tokens only if their sequence set is a subset of the current sequence set |
| 625 | auto cur_seq_set = seq_set[cur_idx]; |
| 626 | |
| 627 | std::vector<int32_t> idxs; |
| 628 | |
| 629 | while (true) { |
| 630 | idxs.push_back(cur_idx); |
| 631 | |
| 632 | used[cur_idx] = true; |
| 633 | ++n_used; |
| 634 | |
| 635 | if (idxs.size() >= n_ubatch) { |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | do { |
| 640 | ++cur_idx; |
| 641 | } while (cur_idx < get_n_tokens() && (used[cur_idx] || ((cur_seq_set & seq_set[cur_idx]) != seq_set[cur_idx]))); |
| 642 | |
| 643 | if (cur_idx == get_n_tokens()) { |
| 644 | break; |
| 645 | } |
| 646 | |
| 647 | cur_seq_set = seq_set[cur_idx]; |
| 648 | } |
| 649 | |
| 650 | return ubatch_add(idxs, 1, true); |
| 651 | } |
| 652 | |
| 653 | void llama_batch_allocr::clear() { |
| 654 | n_outputs = 0; |
no test coverage detected