1. Home
  2. Explore
  3. Computer Science
  4. PyTorch Training Breakdown

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

PyTorch Training Breakdown

  • 29Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Tensor Basics
The function used to create a tensor directly from a Python list is
.

29 questions

  1. 1
    The function used to create a tensor directly from a Python list is
    _____
    .
    Hint

    Think of the most straightforward creation function that takes a list as input.

    Answer

    torch.tensor

  2. 2
    To create a tensor with all ones of a given shape, use the function
    _____
    .
    Hint

    Consider the function that generates a tensor filled with the number 1.

    Answer

    torch.ones

  3. 3
    The function that creates a tensor with the same shape as a given tensor but filled with random values is
    _____
    .
    Hint

    This function 'mimics' the shape of an existing tensor.

    Answer

    torch.randn_like

  4. 4
    The three critical attributes of a tensor are shape, dtype, and
    _____
    .
    Hint

    This attribute tells you whether the tensor lives on CPU or GPU.

    Answer

    device

  5. 5
    The default data type for tensors that require gradient calculation is
    _____
    .
    Hint

    This is the standard floating-point precision for model parameters.

    Answer

    float32

  6. 6
    To enable gradient tracking for a tensor, set the attribute
    _____
    to True.
    Hint

    This is the 'magic switch' that tells autograd to track operations.

    Answer

    requires_grad

  7. 7
    The attribute on a tensor that points to the function that created it is
    _____
    .
    Hint

    Think of it as a breadcrumb linking to the operation that produced the tensor.

    Answer

    grad_fn

  8. 8
    The method that triggers gradient computation by walking back through the computation graph is
    _____
    .
    Hint

    This single command calculates all gradients for parameters with requires_grad=True.

    Answer

    loss.backward()

  9. 9
    In PyTorch, elementwise multiplication of two tensors is performed with the operator
    _____
    .
    Hint

    This operator matches positions and multiplies them; tensors must have the same shape.

    Answer
  10. 10
    Matrix multiplication in PyTorch, used for operations like y=xW+by = xW + by=xW+b, uses the operator
    _____
    .
    Hint

    This operator follows linear algebra rules: inner dimensions must match.

    Answer

    @

  11. 11
    When using reduction operations like mean along dimension 0, the operation collapses
    _____
    .
    Hint

    Dimension 0 corresponds to the vertical axis in a 2D tensor.

    Answer

    rows

  12. 12
    The function that returns indices of the maximum values along a specified dimension is
    _____
    .
    Hint

    This is commonly used to get a model's predicted class.

    Answer

    torch.argmax

  13. 13
    For custom selection of elements from a tensor using an index tensor, use the function
    _____
    .
    Hint

    This enables dynamic per-row indexing without loops.

    Answer

    torch.gather

  14. 14
    In the forward pass of a linear model, the prediction is computed as y=xW+by = xW + by=xW+b, which in code is written as
    _____
    .
    Hint

    Use the matrix multiplication operator and addition.

    Answer

    x @ W + b

  15. 15
    The loss function used for regression tasks that measures the average squared difference between predictions and targets is called
    _____
    .
    Hint

    This loss is also known as L2 loss.

    Answer

    mean squared error (MSE)

  16. 16
    The output of a forward pass, representing the model's initial guess, is denoted by the symbol
    _____
    .
    Hint

    It is written as y-hat in mathematics.

    Answer

    y^\hat{y}y^​

  17. 17
    To prevent PyTorch from tracking operations during manual parameter updates, use the context manager
    _____
    .
    Hint

    This tells autograd to ignore the enclosed operations.

    Answer

    torch.no_grad()

  18. 18
    After each training iteration, gradients must be reset to zero using the method
    _____
    .
    Hint

    This method is available on the optimizer or directly on tensors.

    Answer

    .zero_grad()

  19. 19
    To define a custom neural network model in PyTorch, a class must inherit from the base class
    _____
    .
    Hint

    This class provides the structure for all neural network components.

    Answer

    nn.Module

  20. 20
    A pre-built linear layer that performs y=xAT+by = xA^T + by=xAT+b is provided by the class
    _____
    .
    Hint

    This layer replaces manual xW+bxW + bxW+b and manages its own parameters.

    Answer

    nn.Linear

  21. 21
    The activation function that sets all negative inputs to zero is called
    _____
    .
    Hint

    It stands for Rectified Linear Unit.

    Answer

    ReLU

  22. 22
    The activation function that smoothly squashes negative values (used in GPT and LLaMA) is called
    _____
    .
    Hint

    It is a smoother alternative to ReLU, commonly used in transformer models.

    Answer

    GELU

  23. 23
    The activation function that converts raw scores (logits) into probabilities summing to 1 is
    _____
    .
    Hint

    It is typically applied on the output layer for classification.

    Answer

    Softmax

  24. 24
    The layer that maps word IDs to dense vector representations is called
    _____
    .
    Hint

    It acts as a learnable lookup table.

    Answer

    nn.Embedding

  25. 25
    The layer that normalizes inputs by re-centering and re-scaling to mean 0 and standard deviation 1 is
    _____
    .
    Hint

    This stabilizes training in deep networks.

    Answer

    LayerNorm

  26. 26
    During training, the
    _____
    layer randomly zeroes out a fraction of neurons to prevent overfitting.
    Hint

    It is disabled during evaluation by calling .eval().

    Answer

    Dropout

  27. 27
    The optimizer that adjusts learning rates adaptively and is a good default choice is
    _____
    .
    Hint

    It combines momentum and adaptive learning rates.

    Answer

    Adam

  28. 28
    The feed-forward network (FFN) inside a transformer block consists of two linear layers separated by an
    _____
    .
    Hint

    This introduces non-linearity between the linear transformations.

    Answer

    activation function

  29. 29
    The training process for a large language model follows the exact same five-step loop as our toy model; the only differences are scale and
    _____
    .
    Hint

    Think about the specific structure of the model (e.g., transformers vs linear regression).

    Answer

    architecture

1 of 29
Question 1 of 29

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent