Start by clarifying the black-box interface constraints (e.g., synchronous calls, no access to logits) and the performance goals. Then outline a slot-based architecture with a request manager, a scheduler that fills slots from the waiting queue, and a per-slot state machine that tracks token limits and stopping conditions. Emphasize correctness of slot-to-request mapping and efficient handling of stop sequences.
Pro tip: Use a generation counter or unique request ID per slot to detect stale outputs when slots are reused, and always validate stop sequences by checking the suffix of the generated text rather than relying on token-level matching.
Ask about the black-box interface (e.g., can it generate multiple tokens per call? Is it synchronous?), expected throughput, and whether stop sequences can span multiple tokens. Confirm that per-request token limits include prompt tokens or only generated tokens.
Define a Request object with fields: id, prompt, max_tokens, stop_token, stop_sequence, generated_tokens, and state. Define a Slot object with: slot_id, current_request_id, and generation counter. Maintain a waiting queue (FIFO or priority) and a fixed-size array of slots.
In each iteration, fill empty slots by dequeuing requests from the waiting queue. For each active slot, call the black-box model to generate the next token(s). Then, for each slot, check stopping conditions: token limit reached, stop token generated, or stop sequence suffix matched. If stopped, finalize the request, clear the slot, and immediately refill from the queue.
When a slot is assigned to a request, store the request ID and increment a generation counter. When processing model outputs, verify that the slot's current request ID matches the one used for the call, and discard any output if the generation counter changed (indicating the slot was reused).
Address trade-offs: batching multiple tokens per call vs. per-token calls, handling stop sequences efficiently (e.g., using a trie or rolling hash), and whether to prioritize short or long requests. Mention potential optimizations like dynamic batch sizing or speculative decoding if applicable.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.