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

Initial fix for token corruption when batching #665

Merged
merged 2 commits into from
Dec 10, 2024
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: 8 additions & 3 deletions shortfin/python/shortfin_apps/llm/components/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ async def run(self):
for r in self.exec_requests:
assert r.start_position == 0

extra_token_slots = 1 if is_decode else 0
bsl = max(
(r.start_position + len(r.input_token_ids)) for r in self.exec_requests
(extra_token_slots + len(r.input_token_ids)) for r in self.exec_requests
)
bsl = int(math.ceil(bsl / seq_stride) * seq_stride)
block_count = bsl // seq_stride
Expand Down Expand Up @@ -389,13 +390,17 @@ async def run(self):
if self.phase == InferencePhase.DECODE:
start_positions_host = start_positions.for_transfer()
with start_positions_host.map(discard=True) as m:
m.fill(0)
m.fill(
1
) # Pad unused requests. Must pad with nonzero value because division by 0 floods clobber page (page 0) in cache with NaN values.
m.items = [req.start_position for req in self.exec_requests]
start_positions_host.copy_to(start_positions)

seq_lens_host = seq_lens.for_transfer()
with seq_lens_host.map(discard=True) as m:
m.fill(0)
m.fill(
1
) # Pad unused requests. Must pad with nonzero value because division by 0 floods clobber page (page 0) in cache with NaN values.
m.items = [
req.start_position + len(req.input_token_ids)
for req in self.exec_requests
Expand Down
Loading