Module 1PyTorch Foundations

Tensor Fundamentals

Master shape reasoning, indexing, broadcasting, and device awareness.

Why this module matters

Every model bug eventually becomes a tensor bug. If shapes do not make sense, nothing above them will make sense either.

Prerequisites

  • Basic Python syntax
  • Lists, loops, and functions

Learning objectives

  • Read and predict tensor shapes before running code
  • Use reshape, permute, squeeze, unsqueeze, and broadcasting safely
  • Move tensors across CPU, MPS, and CUDA devices intentionally

Core concepts

Shape, rank, dtype, and device
Contiguous vs non-contiguous tensors
Broadcasting rules and silent shape expansion

Hands-on practice

  • Write a tensor workbook with 15 small exercises
  • Implement matrix multiplication using batched tensor ops
  • Trigger and debug three broadcasting mistakes on purpose

Expected output

A notebook that explains tensor operations with shape annotations and failure cases.

Study checklist

  • Read and predict tensor shapes before running code
  • Use reshape, permute, squeeze, unsqueeze, and broadcasting safely
  • Move tensors across CPU, MPS, and CUDA devices intentionally

Common mistakes

  • ⚠️ Trusting print output instead of understanding dimensions
  • ⚠️ Using view on non-contiguous tensors
  • ⚠️ Ignoring dtype mismatches during arithmetic

Module rhythm

  • 1. Read the summary and why-it-matters section first.
  • 2. Work through concepts before rushing into practice.
  • 3. Use the checklist to verify real understanding, not just completion.

How to continue

Use this shape intuition to understand autograd and gradient flow.

Back to course overview →

How to use this page well

Treat each module as a compact learning system: understand the intuition, verify the concepts, do one hands-on task, then use the checklist and mistakes section to pressure-test your understanding.