0
0
PyTorchml~10 mins

Model packaging (.mar files) in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to save a PyTorch model's state dictionary.

PyTorch
torch.save(model[1], 'model.pth')
Drag options to blanks, or click blank then click option'
A.state_dict()
B.parameters()
C.weights
D.get_state()
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.parameters() instead of model.state_dict()
Trying to save the entire model object directly
2fill in blank
medium

Complete the command to create a .mar file using torch-model-archiver.

PyTorch
torch-model-archiver --model-name my_model --version 1.0 --serialized-file [1] --handler handler.py --export-path model_store
Drag options to blanks, or click blank then click option'
Amodel.pth
Bmodel.pt
Cmodel.pkl
Dmodel.json
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file extensions like .json or .pkl
Confusing the handler file with the serialized file
3fill in blank
hard

Fix the error in loading a model from a .mar file using TorchServe.

PyTorch
torchserve --start --model-store model_store --models my_model=[1]
Drag options to blanks, or click blank then click option'
Amy_model.py
Bmy_model-1.0.mar
Chandler.py
Dmodel.pth
Attempts:
3 left
💡 Hint
Common Mistakes
Using the raw weights file instead of the .mar file
Using the handler or source code file name
4fill in blank
hard

Fill both blanks to define a custom handler class for TorchServe.

PyTorch
from ts.torch_handler.base_handler import {{BLANK_1 }}

class CustomHandler({{BLANK_2}}):
    def preprocess(self, data):
        pass
Drag options to blanks, or click blank then click option'
ABaseHandler
BTorchHandler
CBaseModel
DTorchBase
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect base class names like TorchHandler or BaseModel
5fill in blank
hard

Fill all three blanks to create a dictionary for model metadata in the .mar packaging process.

PyTorch
model_info = {
    'model_name': [1],
    'model_version': [2],
    'handler': [3]
}
Drag options to blanks, or click blank then click option'
A'my_model'
B'1.0'
C'handler.py'
D'model.pth'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the model weights file name instead of the handler file
Not using quotes around string values