PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Apple

Debug a PyTorch U-Net shape mismatch

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in PyTorch model implementation, convolutional output shape arithmetic, channel configuration, and debugging of U-Net-style segmentation networks with valid (no-padding) convolutions.

  • medium
  • Apple
  • Coding & Algorithms
  • Machine Learning Engineer

Debug a PyTorch U-Net shape mismatch

Company: Apple

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a PyTorch implementation of a U-Net-like segmentation model that should follow the *original U-Net style* with **valid convolutions (no padding)**. A unit test is failing due to shape mismatches and an incorrect output channel count. ## Requirements - Input tensor shape: **(B, 1, 572, 572)** - Output tensor shape must be: **(B, 2, 388, 388)** - Here `2` is the number of segmentation classes. - The model uses an encoder/decoder with skip connections, and the decoder concatenates encoder features with upsampled decoder features. ## Task Fix the U-Net implementation by editing only a few scalar values/flags (no redesign). The buggy areas are: 1. The **expected input tensor shape / input channels** used to construct the first layer. 2. A **boolean flag** in the decoder block (e.g., controlling upsampling behavior or concatenation logic). 3. The **kernel size** of the final convolutional block. 4. The model’s `num_classes` setting. ## What to deliver - Update the provided code so that a forward pass on an input of shape `(B, 1, 572, 572)` runs without errors and returns a tensor of shape `(B, 2, 388, 388)`. - Assume `B>=1`. (You do not need to write training code.)

Quick Answer: This question evaluates proficiency in PyTorch model implementation, convolutional output shape arithmetic, channel configuration, and debugging of U-Net-style segmentation networks with valid (no-padding) convolutions.

Related Interview Questions

  • Minimum Cells to Bridge a Magic Grid - Apple (hard)
  • Find Common Prefix Across Strings - Apple (easy)
  • Find Minimum Processing Rate - Apple
  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
Apple logo
Apple
Mar 1, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
11
0
Loading...

You are given a PyTorch implementation of a U-Net-like segmentation model that should follow the original U-Net style with valid convolutions (no padding).

A unit test is failing due to shape mismatches and an incorrect output channel count.

Requirements

  • Input tensor shape: (B, 1, 572, 572)
  • Output tensor shape must be: (B, 2, 388, 388)
    • Here 2 is the number of segmentation classes.
  • The model uses an encoder/decoder with skip connections, and the decoder concatenates encoder features with upsampled decoder features.

Task

Fix the U-Net implementation by editing only a few scalar values/flags (no redesign). The buggy areas are:

  1. The expected input tensor shape / input channels used to construct the first layer.
  2. A boolean flag in the decoder block (e.g., controlling upsampling behavior or concatenation logic).
  3. The kernel size of the final convolutional block.
  4. The model’s num_classes setting.

What to deliver

  • Update the provided code so that a forward pass on an input of shape (B, 1, 572, 572) runs without errors and returns a tensor of shape (B, 2, 388, 388) .
  • Assume B>=1 .

(You do not need to write training code.)

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Machine Learning Engineer•Apple Machine Learning Engineer•Apple Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.