Problem · Queue
Dynamic Batch Decode Trace
Learn this problemProblem statement
There are requests 0..scriptedTokens.length-1 waiting in order. For request r, scriptedTokens[r] lists the successive next tokens returned by the simulated model.
- Create
batchSizenumbered slots and initially fill the lowest slots with the earliest requests. - Each model round consumes one next token for every occupied slot, in ascending slot order. Add
r:tokento that round's trace. - A request completes after consuming
stopTokenor itsmaxTokens-th token. - Only after the entire round completes, free completed slots and refill the lowest free slots with waiting requests in increasing request-ID order.
Return one trace row per model round. A final round may contain fewer than batchSize entries.
Function
dynamicBatchTrace(scriptedTokens: String[][], batchSize: int, maxTokens: int, stopToken: String) → String[][]Examples
Example 1
scriptedTokens = [["a","b","<STOP>"],["x","<STOP>"],["m","n","o","p"],["q","<STOP>"]]batchSize = 2maxTokens = 3stopToken = "<STOP>"return = [["0:a","1:x"],["0:b","1:<STOP>"],["0:<STOP>","2:m"],["3:q","2:n"],["3:<STOP>","2:o"]]Request 1 frees slot 1 after round 2, so request 2 enters there. Request 0 then frees slot 0, which request 3 takes. Request 2 finishes by reaching three consumed tokens.
Example 2
scriptedTokens = [["a","b"],["x","y"]]batchSize = 4maxTokens = 2stopToken = "!"return = [["0:a","1:x"],["0:b","1:y"]]The batch is never full because only two requests exist. Both finish together at maxTokens = 2.
Constraints
1 <= scriptedTokens.length <= 100000.1 <= batchSize <= 1000.1 <= maxTokens <= 1000.- Each request contains a stop token within its first
maxTokensentries or contains at leastmaxTokensentries. - Tokens are non-empty ASCII strings and contain no
:. - The total number of consumed tokens is at most
1000000.