Skip to content

English · Español

Fase 25 — Quizzes (espejo)

Las preguntas canónicas viven en data/quizzes/phase-25-pytorch-internals.yaml.


q-25-01 — Riesgo de operación in-place

Prompt (EN): Calling h.add_(self.attn(self.ln1(h))) instead of h = h + self.attn(self.ln1(h)) in a training loop most often results in:

  • A. No change at all; the two are functionally equivalent.
  • B. A RuntimeError from autograd, or silent wrong gradients.
  • C. A type error.
  • D. A 2× memory speedup with no other change.

Correcta: B. La operación in-place modifica un almacenamiento que puede haber sido guardado por el backward de un nodo aguas arriba; la comprobación de versión de PyTorch lanza un error (o, en casos raros, los gradientes son erróneos en silencio).


q-25-02 — Vista (view) vs copia

Prompt (EN): Which of the following operations returns a view (no data copy) of the input tensor?

  • A. x.reshape(-1) when x is already contiguous.
  • B. x.contiguous() when x is non-contiguous.
  • C. x.clone().
  • D. x.to(dtype=torch.float16).

Correcta: A. Con entrada contigua, reshape es una vista. contiguous() sobre datos no contiguos copia. clone() siempre copia. to(dtype=...) copia (el cambio de dtype requiere un nuevo almacenamiento).


q-25-03 — Cinta (tape) de autograd

Prompt (EN): In one or two sentences, describe what PyTorch's autograd "tape" is and what .backward() does with it.

Respuesta libre. Menciones esperadas: grafo dinámico; los nodos son Functions; .backward() recorre en orden topológico inverso.


q-25-04 — Tensores guardados (saved tensors)

Prompt (EN): Select every backward node that saves a tensor needed for its gradient computation.

  • A. AddBackward (for a + b).
  • B. MulBackward (for a * b).
  • C. SoftmaxBackward (for softmax(x)).
  • D. GeluBackward (for gelu(x)).

Correcta: B, C, D. Add no necesita nada (el gradiente simplemente se propaga). Las otras tres necesitan una entrada o salida para calcular su Jacobiano.


q-25-05 — Dispatcher

Prompt (EN): PyTorch's dispatcher dispatches a single operator call (e.g., torch.add) based on several keys. Which keys are part of the dispatch decision?

  • A. Tensor device (CPU, CUDA, MPS, ...).
  • B. Tensor dtype.
  • C. Tensor layout (strided, sparse).
  • D. Whether autograd is enabled.

Correcta: A, B, C, D. Las cuatro son claves de dispatch. El dispatcher selecciona el kernel apropiado (o wrapper de autograd) según la combinación.