Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      60 of 102

      Same step, smaller batches

      You want to train on batches of 32 photos, but only 8 fit in memory at once. So you run small batches one after another, and each reports the average slope over its own photos (the slope from “Walk downhill”). Write big_batch_slope(batch_slopes, batch_sizes): the slope one big batch of all those photos would give, so the step you take is the same.

      30 photos to train on, but the GPU only holds 8 at a time. So they run in batches of 8, 8, 8 and the 6 left over, and each batch reports the average slope over its own photos. What you wanted was the slope of one batch of all 30.

      30 photos to train on, and a GPU with room for 8.30 photosGPU memory: 8 photoseach batch reports its average slopebatch 1 · 81batch 2 · 82batch 3 · 83batch 4 · 62one batch of all 30?
      Your functionbig_batch_slope(batch_slopes, batch_sizes)
      batch_slopeseach small batch's AVERAGE slope over its photose.g. [0.7]
      batch_sizeshow many photos were in each small batche.g. [32]
      returnsthe slope one big batch of all those photos would give
      solution.pyLoading Python
      Sign in for an AI hint
      ← One step size per directionProtect what matters →