Split Model Layers Into Pipeline Stages Minimizing the Bottleneck

Last updated: November 29, 2026

Quick Overview

Given per-layer compute costs in order and a number of pipeline stages, partition the layers into at most that many contiguous groups so that the largest group cost (the pipeline bottleneck) is as small as possible; return the bottleneck and one valid grouping.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given per-layer compute costs in order and a number of pipeline stages, partition the layers into at most that many contiguous groups so that the largest group cost (the pipeline bottleneck) is as small as possible; return the bottleneck and one valid grouping.

Pipeline parallelism splits a large model's layers across devices, and throughput is limited by the slowest stage, which makes balanced partitioning a real concern for OpenAI training infrastructure. The interviewer checks that you binary search on the answer with a greedy feasibility test and can argue why the greedy check is correct.

What the Interviewer Expects
  • Bound the answer between the max layer cost and the total cost
  • Write a greedy feasibility check that packs layers until the limit is exceeded
  • Prove monotonicity: if a limit works, any larger limit works
  • Reconstruct a grouping from the optimal limit
  • Compare with an O(n^2 k) DP
Key Topics to Cover
binary search on answer
greedy feasibility
partitioning
pipeline parallelism
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Stages also pay a communication cost per boundary: how does the objective change?
  • Devices have different speeds: how would you adapt the feasibility check?
  • Memory per stage is also capped: add a second constraint.
  • Layers can be reordered within residual blocks: does the problem get easier or harder?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: positive layer_costs in fixed order, and stages greater than or equal to 1.
  • Groups must be contiguous and cover all layers; using fewer stages than allowed is fine.
  • Output: minimal bo...
High-Level Design

The bottleneck lies in [max(cost), sum(cost)]. For a candidate limit, a greedy pass packs layers into the current stage until adding the next would exceed the limit, then opens a new stage; the limi...


Submit Your Answer
Markdown supported