DistillPrep
Python
GenAI
GenAI Frameworks
NLP
Deep Learning
Machine Learning
ML Libraries
Statistics
SQL
MLOps
Cloud
System Design
Blog
Learn
Practice
Test
Live Engine
Select Topic
Easy
(36)
Medium
(36)
Hard
(36)
hard
Pytorch Fundamentals
model.half()
converts all model parameters to float16. Input tensors remain float32.
output = model(input_f32)
. What happens?
A
PyTorch automatically casts input to float16 to match model weights
B
RuntimeError
— PyTorch does not automatically cast inputs to match weight dtype. The linear layer's matrix multiplication of float32 input with float16 weights raises a dtype mismatch error. Fix:
input_f16 = input_f32.half()
before the forward pass, or use
autocast()
which handles casting automatically
C
The output is float64 — PyTorch upcasts to the higher precision
D
The computation proceeds in float32 — model weights are automatically cast to float32 for the computation
Confirm Answer
Previous
Back
Next