From e594d02d31af5e2123404812c6b2ea8967ef767d Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Thu, 7 May 2026 22:47:21 +0800 Subject: [PATCH] feat: merge D,E,F into one batch (gated by F at t=8) to show worse static idle --- continuous_batching.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/continuous_batching.py b/continuous_batching.py index 9d2d447..555872b 100644 --- a/continuous_batching.py +++ b/continuous_batching.py @@ -392,13 +392,13 @@ class ContinuousBatching(Scene): gpu_l.move_to([L_OX - 0.55, GY - ROW, 0]) self.play(Write(gpu_l)) - # Static GPU: idle [0-2], batch 1 [2-6], batch 2 [6-10], idle [10-12] + # Static GPU: idle [0-2], batch 1 [2-6], idle [6-8], batch 2 [8-12] s_y_gpu = GY - ROW s_gpu_idle1 = gbox(L_OX, s_y_gpu, 0, 2, RED, 0.45) s_gpu_batch1 = gbox(L_OX, s_y_gpu, 2, 4, GREEN) - s_gpu_batch2 = gbox(L_OX, s_y_gpu, 6, 4, GREEN) - s_gpu_idle2 = gbox(L_OX, s_y_gpu, 10, 2, RED, 0.45) - s_gpu_bars = [s_gpu_idle1, s_gpu_batch1, s_gpu_batch2, s_gpu_idle2] + s_gpu_idle2 = gbox(L_OX, s_y_gpu, 6, 2, RED, 0.45) + s_gpu_batch2 = gbox(L_OX, s_y_gpu, 8, 4, GREEN) + s_gpu_bars = [s_gpu_idle1, s_gpu_batch1, s_gpu_idle2, s_gpu_batch2] for seg in s_gpu_bars: self.play(GrowFromEdge(seg, LEFT), run_time=0.09) @@ -406,18 +406,19 @@ class ContinuousBatching(Scene): s_idle1 = Text("IDLE", font_size=10, color=RED) \ .move_to([L_OX + 1 * CELL, s_y_gpu, 0]) s_idle2 = Text("IDLE", font_size=10, color=RED) \ - .move_to([L_OX + 11 * CELL, s_y_gpu, 0]) + .move_to([L_OX + 7 * CELL, s_y_gpu, 0]) self.play(Write(s_idle1), Write(s_idle2)) - # Same 5 requests as continuous — but scheduled in batches - # each gets a gray WAIT bar before its coloured RUN bar + # Same 6 requests as continuous — but scheduled in batches + # D, E, F grouped into one batch (gated by F's arrival at t=8) # (name, color, wait_start, wait_end, run_start, run_end) s_req_defs = [ ("A", ORANGE, 0, 2, 2, 6), # arrives t=0, waits for C → batch 1 ("B", BLUE, 1, 2, 2, 6), # arrives t=1, waits for C - ("C", PINK, 2, 2, 2, 6), # arrives t=2, no wait (last to arrive) - ("D", ORANGE, 4, 6, 6, 10), # arrives t=4, waits for batch 1 to free GPU - ("E", BLUE, 6, 6, 6, 10), # arrives t=6, no wait (GPU just freed) + ("C", PINK, 2, 2, 2, 6), # arrives t=2, no wait + ("D", ORANGE, 4, 8, 8, 12), # arrives t=4, waits for F → batch 2 + ("E", BLUE, 6, 8, 8, 12), # arrives t=6, waits for F + ("F", PINK, 8, 8, 8, 12), # arrives t=8, no wait ] s_bars = [] for i, (name, col, ws, we, rs, re) in enumerate(s_req_defs): @@ -438,9 +439,9 @@ class ContinuousBatching(Scene): # batch boxes — connect GPU busy segments to the requests they serve s_y_last3 = s_y_gpu - 3 * ROW # Req C is the 3rd request row - s_y_last5 = s_y_gpu - 5 * ROW # Req E is the 5th request row + s_y_last6 = s_y_gpu - 6 * ROW # Req F is the 6th request row b1_rect, b1_lbl = batch_box(L_OX, s_y_gpu, s_y_last3, 2, 4, RED, "Batch 1") - b2_rect, b2_lbl = batch_box(L_OX, s_y_gpu, s_y_last5, 6, 4, RED, "Batch 2") + b2_rect, b2_lbl = batch_box(L_OX, s_y_gpu, s_y_last6, 8, 4, RED, "Batch 2") self.play(Create(b1_rect), Write(b1_lbl)) self.play(Create(b2_rect), Write(b2_lbl)) self.wait(0.8) @@ -466,13 +467,14 @@ class ContinuousBatching(Scene): c_gpu = gbox(R_OX, c_y_gpu, 0, 12, GREEN, 0.75) self.play(GrowFromEdge(c_gpu, LEFT), run_time=0.5) - # Same 5 requests — start immediately, no wait, staggered naturally + # Same 6 requests — start immediately, no wait, staggered naturally c_reqs = [ ("A", ORANGE, 0, 4), ("B", BLUE, 1, 4), ("C", PINK, 2, 4), ("D", ORANGE, 4, 4), ("E", BLUE, 6, 4), + ("F", PINK, 8, 4), ] c_bars = [] c_n_reqs = len(c_reqs) @@ -492,10 +494,10 @@ class ContinuousBatching(Scene): self.wait(1.0) # count annotation - s_count = Text("5 reqs · 2 batches · GPU idle gaps", + s_count = Text("6 reqs · 2 batches · GPU idle gaps", font_size=16, color=RED) \ .next_to(s_gpu_batch1, DOWN, buff=1.0).align_to(s_gpu_batch1, LEFT) - c_count = Text("5 reqs · continuous · GPU never idle", + c_count = Text("6 reqs · continuous · GPU never idle", font_size=16, color=GREEN) \ .next_to(c_gpu, DOWN, buff=1.0).align_to(c_gpu, LEFT) self.play(Write(s_note), Write(c_note))