|
153 | 153 | # .. code:: python |
154 | 154 | # |
155 | 155 | # model = TheModelClass(*args, **kwargs) |
156 | | -# model.load_state_dict(torch.load(PATH)) |
| 156 | +# model.load_state_dict(torch.load(PATH), weights_only=True) |
157 | 157 | # model.eval() |
158 | 158 | # |
159 | 159 | # .. note:: |
|
206 | 206 | # .. code:: python |
207 | 207 | # |
208 | 208 | # # Model class must be defined somewhere |
209 | | -# model = torch.load(PATH) |
| 209 | +# model = torch.load(PATH, weights_only=False) |
210 | 210 | # model.eval() |
211 | 211 | # |
212 | 212 | # This save/load process uses the most intuitive syntax and involves the |
|
290 | 290 | # model = TheModelClass(*args, **kwargs) |
291 | 291 | # optimizer = TheOptimizerClass(*args, **kwargs) |
292 | 292 | # |
293 | | -# checkpoint = torch.load(PATH) |
| 293 | +# checkpoint = torch.load(PATH, weights_only=True) |
294 | 294 | # model.load_state_dict(checkpoint['model_state_dict']) |
295 | 295 | # optimizer.load_state_dict(checkpoint['optimizer_state_dict']) |
296 | 296 | # epoch = checkpoint['epoch'] |
|
354 | 354 | # optimizerA = TheOptimizerAClass(*args, **kwargs) |
355 | 355 | # optimizerB = TheOptimizerBClass(*args, **kwargs) |
356 | 356 | # |
357 | | -# checkpoint = torch.load(PATH) |
| 357 | +# checkpoint = torch.load(PATH, weights_only=True) |
358 | 358 | # modelA.load_state_dict(checkpoint['modelA_state_dict']) |
359 | 359 | # modelB.load_state_dict(checkpoint['modelB_state_dict']) |
360 | 360 | # optimizerA.load_state_dict(checkpoint['optimizerA_state_dict']) |
|
407 | 407 | # .. code:: python |
408 | 408 | # |
409 | 409 | # modelB = TheModelBClass(*args, **kwargs) |
410 | | -# modelB.load_state_dict(torch.load(PATH), strict=False) |
| 410 | +# modelB.load_state_dict(torch.load(PATH), strict=False, weights_only=True) |
411 | 411 | # |
412 | 412 | # Partially loading a model or loading a partial model are common |
413 | 413 | # scenarios when transfer learning or training a new complex model. |
|
446 | 446 | # |
447 | 447 | # device = torch.device('cpu') |
448 | 448 | # model = TheModelClass(*args, **kwargs) |
449 | | -# model.load_state_dict(torch.load(PATH, map_location=device)) |
| 449 | +# model.load_state_dict(torch.load(PATH, map_location=device, weights_only=True)) |
450 | 450 | # |
451 | 451 | # When loading a model on a CPU that was trained with a GPU, pass |
452 | 452 | # ``torch.device('cpu')`` to the ``map_location`` argument in the |
|
469 | 469 | # |
470 | 470 | # device = torch.device("cuda") |
471 | 471 | # model = TheModelClass(*args, **kwargs) |
472 | | -# model.load_state_dict(torch.load(PATH)) |
| 472 | +# model.load_state_dict(torch.load(PATH, weights_only=True)) |
473 | 473 | # model.to(device) |
474 | 474 | # # Make sure to call input = input.to(device) on any input tensors that you feed to the model |
475 | 475 | # |
|
497 | 497 | # |
498 | 498 | # device = torch.device("cuda") |
499 | 499 | # model = TheModelClass(*args, **kwargs) |
500 | | -# model.load_state_dict(torch.load(PATH, map_location="cuda:0")) # Choose whatever GPU device number you want |
| 500 | +# model.load_state_dict(torch.load(PATH, weights_only=True, map_location="cuda:0")) # Choose whatever GPU device number you want |
501 | 501 | # model.to(device) |
502 | 502 | # # Make sure to call input = input.to(device) on any input tensors that you feed to the model |
503 | 503 | # |
|
0 commit comments