Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the TorchServe handler module.
PyTorch
from ts.torch_handler import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import torchserve or serve which are not modules in ts.torch_handler.
Using model_handler which is not a standard import.
✗ Incorrect
The base_handler module is imported from ts.torch_handler to create custom handlers in TorchServe.
2fill in blank
mediumComplete the command to start TorchServe with a model store directory.
PyTorch
torchserve --start --model-store [1] --models my_model.mar Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a directory that does not exist or is not accessible.
Omitting the --model-store option.
✗ Incorrect
The model store directory is specified with --model-store. /tmp/model_store is a common default directory.
3fill in blank
hardFix the error in the handler class definition by completing the base class name.
PyTorch
class MyHandler([1]): def __init__(self): super().__init__()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect base class names like HandlerBase or TorchHandler.
Forgetting to call super().__init__() in the constructor.
✗ Incorrect
Custom handlers inherit from BaseHandler class provided by TorchServe.
4fill in blank
hardFill both blanks to create a dictionary mapping model names to their .mar files for TorchServe registration.
PyTorch
models = [1]: '[2].mar' for [1] in ['resnet18', 'bert']}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed strings instead of variables in the comprehension.
Mixing variable names between key and value.
✗ Incorrect
The dictionary comprehension uses model_name as the variable and key, and the value is model_name with .mar extension.
5fill in blank
hardFill all three blanks to define a TorchServe model archive creation command with model file, handler, and export path.
PyTorch
torch-model-archiver --model-name [1] --version 1.0 --serialized-file [2] --handler [3] --export-path model_store
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing model names and handlers from different model types.
Using incorrect file names or handler names.
✗ Incorrect
The model archive command uses the model name 'resnet18', the serialized file 'resnet18.pth', and the handler 'image_classifier'.