Search Tutorials


PyTorch MCQ Questions and Answers | JavaInUse

PyTorch MCQ Questions and Answers

Q1. What is a tensor in PyTorch?

A. A multi-dimensional array with additional features for GPU computations
B. A simple Python list
C. A database management system
D. A type of neural network

Q2. Which function is used to convert a numpy array to a PyTorch tensor?

A. torch.array()
B. torch.from_numpy()
C. torch.to_tensor()
D. numpy.to_torch()

Q3. What is autograd in PyTorch?

A. Automatic GPU acceleration
B. Automatic gradient computation
C. Automatic model training
D. Automatic data loading

Q4. Which PyTorch module is used for creating neural networks?

A. torch.nn
B. torch.network
C. torch.neural
D. torch.layers

Q5. What is the purpose of torch.cuda.is_available()?

A. To check if CUDA is installed
B. To enable GPU computing
C. To check if a GPU is available for computation
D. To install CUDA drivers

Q6. Which loss function is commonly used for binary classification?

A. MSELoss
B. CrossEntropyLoss
C. BCELoss
D. L1Loss

Q7. What does torch.no_grad() do?

A. Disables GPU usage
B. Disables gradient computation
C. Disables model training
D. Disables data loading

Q8. Which optimizer is NOT available in PyTorch?

A. SGD
B. Adam
C. RMSprop
D. QuickProp

Q9. What is the purpose of DataLoader in PyTorch?

A. To load pretrained models
B. To load data in batches with various options
C. To load model weights
D. To load GPU drivers

Q10. What does requires_grad=True do in PyTorch?

A. Enables GPU acceleration
B. Enables gradient computation for the tensor
C. Requires gradual training
D. Requires gradient descent optimizer

Q11. Which method is used to move a tensor to GPU?

A. tensor.gpu()
B. tensor.cuda()
C. tensor.to_gpu()
D. tensor.move_gpu()





Q12. What is the purpose of torch.save()?

A. To save training data
B. To save model parameters and state
C. To save GPU memory
D. To save computation time

Q13. What is a Module in PyTorch?

A. A Python package
B. A base class for all neural network layers
C. A type of tensor
D. A data loading utility

Q14. Which function is used to compute gradients in PyTorch?

A. forward()
B. compute_grad()
C. backward()
D. gradient()

Q15. What is the purpose of torch.nn.Sequential?

A. To create sequential data
B. To sequence model training
C. To create a sequential container of modules
D. To load data sequentially

Q16. What is the difference between model.train() and model.eval()?

A. They are the same thing
B. train() enables gradient computation, eval() disables it
C. train() is for training, eval() is for testing only
D. train() enables dropout and batch norm updates, eval() disables them

Q17. What is the purpose of torch.randn()?

A. Creates random integers
B. Creates random normal distributed numbers
C. Creates random binary numbers
D. Creates random uniform distributed numbers

Q18. What is torch.nn.Module?

A. A data structure for tensors
B. Base class for all neural network modules
C. A mathematical operation
D. A type of optimizer

Q19. What does torch.cuda.is_available() check?

A. If CUDA version is latest
B. If GPU memory is sufficient
C. If CUDA-enabled GPU is available
D. If model is CUDA compatible

Q20. What is the purpose of torch.no_grad()?

A. Disables gradient calculation
B. Removes all gradients
C. Stops model training
D. Prevents model updates

Q21. What is the default value of requires_grad for a tensor?

A. True
B. False
C. None
D. Depends on tensor type

Q22. Which function is used to concatenate tensors?

A. torch.stack()
B. torch.cat()
C. torch.join()
D. torch.combine()

Q23. What is the purpose of torch.squeeze()?

A. Reduces tensor dimensions
B. Compresses tensor data
C. Removes dimensions of size 1
D. Reduces tensor size

Q24. What is the main purpose of DataLoader in PyTorch?

A. To load data from files
B. To wrap dataset for batch processing
C. To preprocess data
D. To save data to disk

Q25. What does criterion typically refer to in PyTorch?

A. Model architecture
B. Loss function
C. Optimization algorithm
D. Evaluation metric

Q26. What is the purpose of torch.autograd?

A. Automatic model creation
B. Automatic data loading
C. Automatic differentiation
D. Automatic optimization

Q27. What does .to(device) do in PyTorch?

A. Converts tensor type
B. Moves tensor to specified device
C. Saves tensor to device
D. Copies tensor to memory

Q28. What is the purpose of torch.save()?

A. Saves model architecture
B. Saves training data
C. Saves model parameters
D. Saves Python objects

Q29. What is the purpose of detach() in PyTorch?

A. Removes tensor from computation graph
B. Deletes tensor from memory
C. Detaches GPU from computation
D. Removes model parameters

Q30. What is torch.nn.Sequential?

A. A type of RNN
B. A container for modules
C. A sequential optimizer
D. A data loading method

Q31. What does require_grad_() do?

A. Changes tensor type
B. Enables gradient computation
C. Requires model gradients
D. Evaluates gradients

Q32. What is the purpose of backward() in PyTorch?

A. Moves backward in training data
B. Computes gradients
C. Reverses tensor operations
D. Decrements model parameters