@@ -455,27 +455,36 @@ def test_many_concurrent_sequences(self):
455455 self .assertAlmostEqual (float (out [0 , 0 ]), sums [s ] + s , places = 3 )
456456
457457 def test_staggered_sequences (self ):
458- # Sequences of different lengths that start/end at different steps, so
459- # batch slots are freed and reused. Each sequence's state is independent
460- # and resets on its own START.
458+ # Sequences of different lengths begin and end at different ticks on a
459+ # shared timeline, so they overlap: some finish (freeing their batch
460+ # slot) while others stay live and new ones start into the freed slots.
461+ # Each sequence keeps independent state that resets on its own START.
462+ # plan: seq_id -> (first_tick, values)
461463 plans = {
462- 400 : [1.0 , 2.0 ], # short
463- 401 : [3.0 , 4.0 , 5.0 , 6.0 ], # long
464- 402 : [10.0 , 10.0 , 10.0 ],
464+ 400 : (0 , [1.0 , 2.0 ]), # ticks 0-1
465+ 401 : (0 , [3.0 , 4.0 , 5.0 , 6.0 ]), # ticks 0-3
466+ 402 : (2 , [10.0 , 10.0 , 10.0 ]), # ticks 2-4 (starts after 400 ends)
467+ 403 : (3 , [7.0 , 8.0 ]), # ticks 3-4
465468 }
469+ last_tick = max (start + len (values ) - 1 for start , values in plans .values ())
470+ running = {seq_id : 0.0 for seq_id in plans }
466471 with http .InferenceServerClient ("localhost:8000" ) as client :
467- for seq_id , steps in plans .items ():
468- running = 0.0
469- for i , value in enumerate (steps ):
470- running += value
472+ for tick in range (last_tick + 1 ):
473+ for seq_id , (first_tick , values ) in plans .items ():
474+ idx = tick - first_tick
475+ if idx < 0 or idx >= len (values ):
476+ continue # sequence not live at this tick
477+ running [seq_id ] += values [idx ]
471478 out = self ._infer_step (
472479 client ,
473480 seq_id = seq_id ,
474- value = value ,
475- start = (i == 0 ),
476- end = (i == len (steps ) - 1 ),
481+ value = values [idx ],
482+ start = (idx == 0 ),
483+ end = (idx == len (values ) - 1 ),
484+ )
485+ self .assertAlmostEqual (
486+ float (out [0 , 0 ]), running [seq_id ] + seq_id , places = 3
477487 )
478- self .assertAlmostEqual (float (out [0 , 0 ]), running + seq_id , places = 3 )
479488
480489 def test_initial_state_sequence (self ):
481490 # Model relies on a declared zero initial_state (no START reset). Output
0 commit comments