Skip to content

Commit ee4372b

Browse files
committed
initial fix
1 parent b585963 commit ee4372b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • shortfin/python/shortfin_apps/llm/components

shortfin/python/shortfin_apps/llm/components/service.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ async def run(self):
340340
for r in self.exec_requests:
341341
assert r.start_position == 0
342342

343+
extra_token_slots = 1 if is_decode else 0
343344
bsl = max(
344-
(r.start_position + len(r.input_token_ids)) for r in self.exec_requests
345+
(extra_token_slots + len(r.input_token_ids)) for r in self.exec_requests
345346
)
346347
bsl = int(math.ceil(bsl / seq_stride) * seq_stride)
347348
block_count = bsl // seq_stride
@@ -389,13 +390,13 @@ async def run(self):
389390
if self.phase == InferencePhase.DECODE:
390391
start_positions_host = start_positions.for_transfer()
391392
with start_positions_host.map(discard=True) as m:
392-
m.fill(0)
393+
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.
393394
m.items = [req.start_position for req in self.exec_requests]
394395
start_positions_host.copy_to(start_positions)
395396

396397
seq_lens_host = seq_lens.for_transfer()
397398
with seq_lens_host.map(discard=True) as m:
398-
m.fill(0)
399+
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.
399400
m.items = [
400401
req.start_position + len(req.input_token_ids)
401402
for req in self.exec_requests

0 commit comments

Comments
 (0)