Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix init of batch state #682

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/turbomind/models/llama/LlamaBatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ bool LlamaBatch<T>::Initialize()
});

// all blocks are not enough to hold a single sequence
FT_CHECK_WITH_INFO(active_end != idxs.begin(), "No enough blocks.");
if (!sequences.empty()) {
FT_CHECK_WITH_INFO(active_end != idxs.begin(), "No enough blocks.");
}

// move swap-ins to the back
auto swapin_beg = std::stable_partition(idxs.begin(), active_end, [&](int idx) {
Expand Down Expand Up @@ -398,6 +400,8 @@ bool LlamaBatch<T>::Initialize()
ClearState(*incoming_);
}

FT_CHECK(state_->size <= max_batch_size_);

/// Update block ptrs when there were
// 1. swap-in or swap-out
// 2. holes in the active buffer
Expand Down Expand Up @@ -810,9 +814,6 @@ auto LlamaBatch<T>::InitializeGeneration() -> GenerationState
// for
for (int i = 0; i < batch_size; ++i) {
h_seq_limit_len_[i] = state_->seq_len_limit[i] + (max_context_len - state_->h_context_length[i]);
if (max_context_len >= h_seq_limit_len_[i]) { // mask finished sequences
state_->h_finished[i] = true;
}
}
Copy(h_seq_limit_len_, batch_size, seq_limit_len_);
Copy(state_->h_finished, batch_size, finished_buf_);
Expand Down Expand Up @@ -1402,6 +1403,8 @@ void LlamaBatch<T>::InternalThreadEntry(int device_id)
shared_state->barrier->wait();

auto modified = Initialize();
// finished sequences is handled by `Initialize()`
finished_count = 0;

ContextDecode();

Expand Down
Loading