पाठ 33 / 33
Mixed self-check
यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।
Test yourself across tensors, autograd, models, data, performance and deployment, and find which sections to revise.
लेखक: Rahul Agarwal · 15 साल से वेब डेवलपर
Use the self-check honestly
This last topic mixes ideas from every section. Before revealing any answer, say your choice and your reason out loud or write it down. A right answer for the wrong reason counts as wrong for revision purposes.
Map your mistakes back to the course. Shape and dimension errors point to the tensor foundations section. Confusion about .grad, no_grad or detach points to autograd. Mixing up eval() and no_grad(), or the loss rules, points to the models and training sections. Device, precision and speed questions point to the performance section, and anything about torch.load, checkpoints or export points to the production section.
Then do something practical: write the training skeleton from memory, run it on a small dataset such as MNIST or CIFAR-10 from torchvision, and deliberately introduce each bug from the previous topic to see its symptom. Seeing a bug's symptom once makes it far easier to recognise later in your own projects.
Quick-fire shape check
Predict every printed shape before running. Answers: (8, 16, 32, 32), (8, 16), (8, 10) and (10,).
import torch
from torch import nn
x = torch.randn(8, 3, 32, 32)
conv = nn.Conv2d(3, 16, kernel_size=3, padding=1)
h = conv(x)
print(h.shape)
pooled = h.mean(dim=(2, 3))
print(pooled.shape)
logits = nn.Linear(16, 10)(pooled)
print(logits.shape)
print(logits.mean(dim=0).shape)Spaced revision
Come back to the quizzes after a few days rather than rereading immediately. Retrieval after a gap strengthens memory far more than rereading notes, and it shows you which topics actually stuck.
त्वरित जाँच: You load a NumPy `float64` array with `torch.from_numpy`, pass it to an `nn.Linear` model and get *expected scalar type Float but found Double*. What is the fix?
- Convert the tensor with `.float()` before passing it to the model
- Call `model.double()` on every model you ever train
- Use `torch.no_grad()` around the forward pass
- Move the model to the GPU
Answer
Convert the tensor with `.float()` before passing it to the model — The data is float64 while the model's weights are float32. Converting the input with `.float()` is the standard fix; switching the whole model to float64 is slower and rarely needed.