Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions src/models/kv_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,14 @@ DefaultKeyValueCache::DefaultKeyValueCache(State& state)
}

// Set the size after empty_past_ has been created with 0 for this field
if (past_present_share_buffer_)
if (state.model_.p_device_->GetType() == DeviceType::NvTensorRtRtx &&
model_.config_->model.decoder.sliding_window.has_value() &&
model_.config_->model.decoder.sliding_window->window_size > 0) {
shape_[2] = std::min(state_.params_->search.max_length,
model_.config_->model.decoder.sliding_window->window_size);
} else if (past_present_share_buffer_) {
shape_[2] = state_.params_->search.max_length;
}

try {
for (int i = 0; i < layer_count_ * 2; ++i) {
Expand Down Expand Up @@ -422,12 +428,13 @@ std::unique_ptr<KeyValueCache> CreateKeyValueCache(State& state) {
return nullptr;
}

if (state.model_.config_->model.decoder.sliding_window &&
if (state.model_.p_device_->GetType() != DeviceType::NvTensorRtRtx &&
state.model_.config_->model.decoder.sliding_window &&
state.model_.config_->model.decoder.sliding_window->slide_key_value_cache) {
return std::make_unique<WindowedKeyValueCache>(state);
}

return std::make_unique<DefaultKeyValueCache>(state);
}

} // namespace Generators
} // namespace Generators
Loading