Question 1
torch.tensor([1, 4, 7])
torch.tensor([2, 5, 8])
torch.tensor([3, 6, 9])
torch.tensor([4, 5, 6])
torch.tensor([5])

The IIT Madras BS Introduction to Deep Learning and Generative AI (Deep Learning and GenAI) Quiz 1 paper sat on 26 Oct 2025, in the September 2025 term: 20 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
torch.tensor([1, 4, 7])
torch.tensor([2, 5, 8])
torch.tensor([3, 6, 9])
torch.tensor([4, 5, 6])
torch.tensor([5])
Correct answer
torch.tensor([2, 5, 8])
You have a tensor x = torch.tensor([1, 2, 3, 4]) with shape (4,). You perform the following operations:
stacked_x = torch.stack([x, x, x], dim=0)stacked_y = torch.stack([x, x, x], dim=1)What are the shapes of stacked_x and stacked_y respectively?
(3, 4) and (3, 4)
(3, 4) and (4, 3)
(4, 3) and (4, 3)
(4, 3) and (3, 4)
Correct answer
(3, 4) and (4, 3)
(1, 2, 2)
(2, 2)
(2,)
(1, 1, 2, 2)
(1, 2, 2, 1)
Correct answer
(2, 2)
You are writing a PyTorch training script on a machine with a CUDA-enabled GPU. You have correctly identified the device and moved your model to it. However, when you run your script, it crashes on the forward pass with a RuntimeException, indicating that the model's weights and the input data are on different devices.
Review the following code snippet and determine the single line of code that must be added to the ---BLANK --- to fix this specific error.
import torchimport torch.nn as nn
# 1. Setup device and move the model to itdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")model = nn.Linear(in_features=64, out_features=10).to(device)optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
# 2. Create a batch of input data (defaults to CPU)# This simulates data coming from a DataLoaderinput_batch = torch.randn(32, 64) # [batch_size, feature_size]
# 3. Perform a training stepoptimizer.zero_grad()
# --- BLANK ---
# The following line causes the error:# "RuntimeException: Expected all tensors to be on the same device,# but found at least two devices, cuda:0 and cpu!"outputs = model(input_batch)# ... loss calculation and backward pass would followWhat line of code should be placed in the --- BLANK --- to resolve this device mismatch?
model.cuda()
input_batch.cuda()
input_batch = input_batch.requires_grad_(True)
input_batch = input_batch.to(device)
torch.set_default_tensor_type('torch.cuda.FloatTensor')
Correct answer
input_batch = input_batch.to(device)
It prevents parameters from being changed by the optimizer during the forward pass.
It deallocates the model's parameters from the GPU to save memory.
It disables the creation of the computational graph, saving memory and speeding up execution.
It ensures that the model operates entirely on the CPU, preventing unnecessary GPU transfers.
Correct answer
It disables the creation of the computational graph, saving memory and speeding up execution.
Correct answer
Consider the following PyTorch code that defines a small 3-layer fully connected neural network
import torchimport torch.nn as nn
class SmallNet(nn.Module): def __init__(self): super(SmallNet, self).__init__() self.fc1 = nn.Linear(4, 6) # input -> hidden1 self.fc2 = nn.Linear(6, 3) # hidden1 -> hidden2 self.fc3 = nn.Linear(3, 2) # hidden2 -> output def forward(self, x): x = torch.relu(self.fc1(x)) x = torch.relu(self.fc2(x)) x = self.fc3(x) return xHow many trainable parameters (weights + biases) does this network have in total?
Correct answer: 59
Consider the following code:
import torchimport torch.nn as nn
model = nn.Sequential( nn.Linear(10, 10), nn.BatchNorm1d(10), nn.ReLU(), nn.Dropout(p=0.5), nn.Linear(10, 1))X = torch.randn(4, 10)
# Run in training modemodel.train()out_train = model(X)
# Run in evaluation modemodel.eval()out_eval = model(X)
print(out_train)print(out_eval)Removing which of the following layers will make out_train and out_eval identical for the same input?
Correct answer
Based on the above data, answer the given subquestions.
If all the weights are initalized to 0 and the input to the network is also a zero vector, then what should be the value of bias so that the output of the network is 0.5 ?
0.5
ln(5)
ln(1)
1
Correct answer
ln(1)
Based on the above data, answer the given subquestions.
Correct answer
Select the equation representing the forward pass of the given network:
Correct answer
Correct answer: 1
Correct answer: 1
Consider the following CNN defined in PyTorch:
import torchimport torch.nn as nnimport torch.nn.functional as F
class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self).__init__() # Conv Layer 1: in_channels=1 (grayscale), out_channels=8 self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) # Pool Layer 1 self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# Conv Layer 2: in_channels=8, out_channels=16 self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1) # Pool Layer 2 self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
# Fully Connected Layers self.fc1 = nn.Linear(16 * 7 * 7, 128) # Flattened from conv2 output self.fc2 = nn.Linear(128, 10) # Output for 10 classes
def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) # Conv1 + Pool1 x = self.pool2(F.relu(self.conv2(x))) # Conv2 + Pool2 x = x.view(-1, 16 * 7 * 7) # Flatten x = F.relu(self.fc1(x)) # FC1 x = self.fc2(x) # FC2 return x
# Example inputmodel = SimpleCNN()print(model)Based on the above data, answer the given subquestions.
How many trainable parameters are there in the first convolutional layer including bias (conv1)?
Correct answer: 80
Consider the following CNN defined in PyTorch:
import torchimport torch.nn as nnimport torch.nn.functional as F
class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self).__init__() # Conv Layer 1: in_channels=1 (grayscale), out_channels=8 self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) # Pool Layer 1 self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# Conv Layer 2: in_channels=8, out_channels=16 self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1) # Pool Layer 2 self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
# Fully Connected Layers self.fc1 = nn.Linear(16 * 7 * 7, 128) # Flattened from conv2 output self.fc2 = nn.Linear(128, 10) # Output for 10 classes
def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) # Conv1 + Pool1 x = self.pool2(F.relu(self.conv2(x))) # Conv2 + Pool2 x = x.view(-1, 16 * 7 * 7) # Flatten x = F.relu(self.fc1(x)) # FC1 x = self.fc2(x) # FC2 return x
# Example inputmodel = SimpleCNN()print(model)Based on the above data, answer the given subquestions.
What is the total number of trainable parameters in the pooling layers(pool1 and pool2)?
Correct answer: 0
Consider the following CNN defined in PyTorch:
import torchimport torch.nn as nnimport torch.nn.functional as F
class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self).__init__() # Conv Layer 1: in_channels=1 (grayscale), out_channels=8 self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) # Pool Layer 1 self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# Conv Layer 2: in_channels=8, out_channels=16 self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1) # Pool Layer 2 self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
# Fully Connected Layers self.fc1 = nn.Linear(16 * 7 * 7, 128) # Flattened from conv2 output self.fc2 = nn.Linear(128, 10) # Output for 10 classes
def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) # Conv1 + Pool1 x = self.pool2(F.relu(self.conv2(x))) # Conv2 + Pool2 x = x.view(-1, 16 * 7 * 7) # Flatten x = F.relu(self.fc1(x)) # FC1 x = self.fc2(x) # FC2 return x
# Example inputmodel = SimpleCNN()print(model)Based on the above data, answer the given subquestions.
How many parameters (weights and biases) does the first fully connected layer (fc1) have?
Correct answer: 100480
Consider the following CNN defined in PyTorch:
import torchimport torch.nn as nnimport torch.nn.functional as F
class SimpleCNN(nn.Module): def __init__(self): super(SimpleCNN, self).__init__() # Conv Layer 1: in_channels=1 (grayscale), out_channels=8 self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) # Pool Layer 1 self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2)
# Conv Layer 2: in_channels=8, out_channels=16 self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3, stride=1, padding=1) # Pool Layer 2 self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
# Fully Connected Layers self.fc1 = nn.Linear(16 * 7 * 7, 128) # Flattened from conv2 output self.fc2 = nn.Linear(128, 10) # Output for 10 classes
def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) # Conv1 + Pool1 x = self.pool2(F.relu(self.conv2(x))) # Conv2 + Pool2 x = x.view(-1, 16 * 7 * 7) # Flatten x = F.relu(self.fc1(x)) # FC1 x = self.fc2(x) # FC2 return x
# Example inputmodel = SimpleCNN()print(model)Based on the above data, answer the given subquestions.
What is the total number of convolution filters used in this CNN?
Correct answer: 24
Based on the above data, answer the given subquestions.
Correct answer: 1
Based on the above data, answer the given subquestions.
Correct answer: 2
Based on the above data, answer the given subquestions.
Correct answer: 192