Split Model Layers Into Pipeline Stages Under an SRAM Cap

Last updated: November 29, 2026

Quick Overview

A model has layers in order, each with a compute time and a memory footprint. Split them into at most k contiguous pipeline stages so each stage fits in a memory cap, minimizing the slowest stage's total compute; return -1 if impossible.

Cerebras
Coding & Algorithms
Machine Learning Engineer
Cerebras
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A model has layers in order, each with a compute time and a memory footprint. Split them into at most k contiguous pipeline stages so each stage fits in a memory cap, minimizing the slowest stage's total compute; return -1 if impossible.

Mapping a network onto fixed on-chip memory regions is a central compiler problem when weights and activations live in SRAM. This question checks whether you can combine two constraints (memory and stage count) with binary search on the answer and prove the greedy check is correct.

What the Interviewer Expects
  • Spots binary search on the bottleneck value with a greedy feasibility check
  • Explains why greedy packing is optimal for contiguous partitions with two monotone constraints
  • Detects infeasibility from memory alone before searching
  • States O(n log S) complexity
  • Connects stage throughput to pipeline throughput (slowest stage sets the rate)
Key Topics to Cover
binary search on answer
greedy partition
pipeline parallelism
memory constraints
compiler placement
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
  • Can you also return the actual split points?
  • What if stages are on a 2D grid and communication between stages has a cost?
  • How does a DP solution compare, and when would you prefer it?
  • What if compute time depends on how many cores you give a stage?
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

Inputs: compute[i], memory[i] per layer, max stages k, per-stage memory cap M. Stages are contiguous ranges. Constraint: sum of memory in a stage is at most M. Objective: minimize the largest stag...

High-Level Design

Fix a candidate bottleneck T. Can we split into at most k stages with each stage compute at most T and memory at most M? Greedily extend the current stage while both sums stay within limits, otherwise...


Submit Your Answer
Markdown supported

Related Questions