Skip to content

env: add knob to control SWA eviction interval#22645

Open
happierpig wants to merge 1 commit intosgl-project:mainfrom
happierpig:add-swa-eviction
Open

env: add knob to control SWA eviction interval#22645
happierpig wants to merge 1 commit intosgl-project:mainfrom
happierpig:add-swa-eviction

Conversation

@happierpig
Copy link
Copy Markdown
Contributor

Motivation

SWA eviction only runs every sliding_window_size decode steps per request. Between evictions, each request holds up to 2 * sliding_window_size SWA tokens — double what the sliding window needs.

Adding a knob to trade-off between the token waste and per-forward overhead.

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a configurable multiplier for the Sliding Window Attention (SWA) eviction interval through a new environment variable, allowing for better control over the trade-off between memory waste and eviction overhead. A review comment points out a potential logic error where the eviction condition might never be met if the calculated interval is 1, and provides a suggestion to handle this edge case while maintaining the requirement to skip the first decode batch index.

# 2. Evict swa every window_size tokens to reduce the overhead.
if req.decode_batch_idx % sliding_window_size == 1:
# 2. Evict swa every eviction_interval tokens to reduce the overhead.
if req.decode_batch_idx % eviction_interval == 1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition req.decode_batch_idx % eviction_interval == 1 will never be true if eviction_interval is 1. This can happen if page_size is 1 and the multiplier is set to a very small value. In this case, SWA eviction would never trigger during decoding, which contradicts the user's intent of increasing eviction frequency.

Additionally, the original logic implicitly skipped the decode_batch_idx == 0 case (as mentioned in the comment above), which should be preserved.

Suggested change
if req.decode_batch_idx % eviction_interval == 1:
if req.decode_batch_idx > 0 and req.decode_batch_idx % eviction_interval == (1 % eviction_interval):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant