Annexure 10: PyTorch Problems for University Exams
Abstract:
Below is the Annexure 10: PyTorch Problems for University Exams — well-structured, university-level, and divided into Short Answer, Long Answer, Coding, and Case Study problems. This annexure is ready to be inserted into the book.
**Annexure 10
PyTorch Problems for University Exams
(Short, Long, Coding & Case Study Questions)**
This annexure contains exam-oriented questions designed for undergraduate, postgraduate, and professional certification evaluations. Questions range from basic conceptual understanding to advanced applications and coding tasks.
A. Short Answer Questions (2–5 Marks Each)
1. What is a tensor in PyTorch? How is it different from NumPy arrays?
2. Define Autograd. Why is it important in deep learning?
3. What is the purpose of requires_grad=True in PyTorch tensors?
4. Explain the difference between CPU tensors and CUDA tensors.
5. What is a computational graph?
6. What does a PyTorch state_dict contain?
7. Define the term batch size in model training.
8. What is a loss function? Give two examples.
9. Write the purpose of the DataLoader class.
10. State the difference between training mode and evaluation mode in PyTorch.
11. What is the role of optimizer.zero_grad()?
12. What is gradient clipping? When is it used?
13. Define Transfer Learning in PyTorch.
14. What is TorchScript? Why is it required?
15. Explain mixed precision training.
B. Medium/Long Answer Questions (8–15 Marks Each)
1. Explain the complete training loop in PyTorch with all major steps.
2. Describe the architecture of a Convolutional Neural Network (CNN) and its implementation using PyTorch.
3. What is overfitting? Discuss regularization techniques available in PyTorch.
4. Compare SGD, Adam, and RMSProp optimizers in PyTorch.
5. Explain the role of the Autograd engine with a detailed example.
6. What is Distributed Data Parallel (DDP)? Explain its benefits and workflow.
7. Discuss the use of Data Augmentation using torchvision.transforms.
8. Describe Transfer Learning using ResNet in PyTorch. Include all steps.
9. What is ONNX? Explain how PyTorch models can be exported to ONNX format.
10. Explain the workflow of model evaluation using accuracy, confusion matrix, and ROC curve in PyTorch.
11. Describe the concept of model checkpointing and its importance.
12. What is the PyTorch Profiler? How is it used for performance optimization?
C. Coding Questions (10–20 Marks)
1. Write a PyTorch code snippet to:
-
Create a tensor of size (3 × 3)
-
Perform matrix multiplication
-
Move the result to GPU
2. Write a PyTorch program to implement a simple feedforward neural network for MNIST classification.
3. Write code to train a CNN with:
-
Convolution layer
-
Pooling layer
-
Fully connected layers
-
Cross entropy loss
-
Adam optimizer
4. Write code for a custom dataset class that loads images from a folder.
5. Write a PyTorch script to save and load model checkpoints.
6. Implement a simple RNN or LSTM for sequence classification using PyTorch.
7. Write code to freeze all layers except the last layer in a pre-trained ResNet model.
8. Write a PyTorch Lightning version of a typical training loop.
9. Write code to perform gradient clipping in a training loop.
10. Write code for mixed precision training using torch.cuda.amp.
D. Advanced Coding Problems (PG/MTech/Research Level)
1. Implement Distributed Data Parallel (DDP) training with 2 GPUs.
2. Write a custom autograd function using torch.autograd.Function.
3. Implement model quantization (static or dynamic) in PyTorch.
4. Build a Transformer encoder block from scratch using PyTorch.
5. Implement a GAN:
-
Generator
-
Discriminator
-
Training loop with BCE loss
6. Implement a UNet for image segmentation using PyTorch.
7. Write code to export a model to ONNX and run inference using ONNX Runtime.
8. Implement memory-efficient attention for large-scale transformer models.
E. Case Study Questions (High-Weightage, 15–25 Marks)
1. Case Study 1: Image Classification Pipeline
You are working for a healthcare company building a Pneumonia detection system using chest X-rays.
You must:
-
Create a custom dataset loader
-
Apply data augmentation
-
Build a CNN
-
Train, validate, and evaluate
-
Save the best model checkpoint
2. Case Study 2: NLP Sentiment Analysis System
A company wants to analyze customer sentiment from product reviews.
You must:
-
Preprocess text
-
Use embeddings
-
Build an LSTM/GRU model
-
Train and evaluate
-
Provide accuracy, F1-score, confusion matrix
3. Case Study 3: Object Detection System
An autonomous car company wants to detect pedestrians using Faster R-CNN.
Tasks include:
-
Loading a pre-trained model
-
Fine-tuning using custom data
-
Evaluating detection performance
4. Case Study 4: Time Series Forecasting
A stock prediction startup wants a forecasting model using LSTMs.
You must:
-
Prepare sliding window dataset
-
Build LSTM
-
Train and test
-
Plot predicted vs actual graph
5. Case Study 5: Deploying a PyTorch Model
A student-built model must be deployed via FastAPI.
Tasks:
-
Convert the model to TorchScript
-
Build FastAPI app
-
Run inference on JSON input
F. Practical Viva Questions
1. What is the difference between inference_mode and no_grad?
2. Why do we use pin_memory=True?
3. Explain the role of collate_fn in DataLoader.
4. What happens internally when you call loss.backward()?
5. Why is mixed precision training faster?
G. Conclusion
These exam-focused questions provide comprehensive coverage of PyTorch fundamentals, applications, coding skills, and deployment tasks required for university-level evaluations and professional certifications. They can be used for internal assessments, lab exams, end-semester exams, and competitive technical interviews.
Comments
Post a Comment
"Thank you for seeking advice on your career journey! Our team is dedicated to providing personalized guidance on education and success. Please share your specific questions or concerns, and we'll assist you in navigating the path to a fulfilling and successful career."