Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select the device for inference based on availability.
MLOps
device = 'cuda' if torch.cuda.is_available() else [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gpu' as fallback device
Using 'tpu' or 'fpga' without hardware support
✗ Incorrect
When GPU is not available, the CPU is used for inference.
2fill in blank
mediumComplete the code to set batch size for CPU inference to avoid overload.
MLOps
batch_size = [1] if device == 'cpu' else 64
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using large batch sizes like 128 or 256 on CPU causing slowdowns
✗ Incorrect
Smaller batch sizes like 16 help prevent CPU overload during inference.
3fill in blank
hardFix the error in the code that measures inference time on CPU.
MLOps
start = time.time()
output = model(input.to([1]))
end = time.time() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cuda' or 'gpu' when running on CPU causing runtime errors
✗ Incorrect
Input tensor must be moved to CPU device for CPU inference.
4fill in blank
hardFill both blanks to create a dictionary showing inference speed tradeoffs.
MLOps
inference_speed = {'CPU': [1], 'GPU': [2] # in milliseconds Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping CPU and GPU speeds
Using equal speeds for both devices
✗ Incorrect
CPU inference is slower (100 ms) compared to GPU (5 ms) for the same model.
5fill in blank
hardFill all three blanks to filter models suitable for CPU inference with low memory.
MLOps
suitable_models = {m: mem for m, mem in models.items() if mem [1] 4 and 'light' [2] m and mem [3] 1} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators
Using '==' instead of 'in' for substring check
✗ Incorrect
We select models with memory less or equal 4GB, name containing 'light', and memory greater or equal 1GB.