pytorch load model without torchvision
Is it possible to load a pytorch model (from a .pth file, containing architecture+state_dict) without torchvision as a dependency?
import os
import torch
assert os.path.exists(r'.\vgg.pth')
model = torch.load(r'.\vgg.pth')

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
&lt;ipython-input-4-e26863d95688&gt; in &lt;module&gt;
      2 import torch
      3 assert os.path.exists(r'.\vgg.pth')
----&gt; 4 model = torch.load(r'.\vgg.pth')

~\Anaconda3\envs\pytorch_save\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    590                     opened_file.seek(orig_position)
    591                     return torch.jit.load(opened_file)
--&gt; 592                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    593         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    594 

~\Anaconda3\envs\pytorch_save\lib\site-packages\torch\serialization.py in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
    849     unpickler = pickle_module.Unpickler(data_file, **pickle_load_args)
    850     unpickler.persistent_load = persistent_load
--&gt; 851     result = unpickler.load()
    852 
    853     torch._utils._validate_loaded_sparse_tensors()

ModuleNotFoundError: No module named 'torchvision'


I have looked into torch/serialization.py, but I see no reason why it would need torchvision. The imports in this file are as follows:
import difflib
import os
import io
import shutil
import struct
import sys
import torch
import tarfile
import tempfile
import warnings
from contextlib import closing, contextmanager
from ._utils import _import_dotted_name
from ._six import string_classes as _string_classes
from torch._sources import get_source_lines_and_file
from torch.types import Storage
from typing import Any, BinaryIO, cast, Dict, Optional, Type, Tuple, Union, IO
import copyreg
import pickle
import pathlib


What caused my problem
The vgg.pth file in my question was generated as follows:
import torchvision
vgg = models.vgg16(pretrained=True, init_weights=False)
torch.save(vgg, r'.\vgg.pth')

This way, the file vgg.pth contains not only the model parameters, but also the model architecture (see pytorch: save/load entire model). However, as @Kishore pointed out in the comments, it seems that this architecture also needs torchvision as a dependency.  
How I solved it

In an environment with torchvision, I loaded the pretrained VGG model into memory and saved the state_dict

from torchvision.models.vgg import vgg16
import torch

model = vgg16(pretrained=True)
torch.save(model.state_dict, r'.\state_dict.pth')


In an environment without torchvision, I rebuilt the model by inspecting the torchvision.models.vgg code. 
Then I loaded this state_dict file into the state_dict of my model.
Lastly, I saved this model (including architecture) to a .pth file.

import torch

# a file where I pasted the torchvision.models.vgg code
# and commented out the torchvision dependencies I don't need
# in this case: 'from .._internally_replaced_utils import load_state_dict_from_url'
from torch_save import *

model = vgg16()
model.load_state_dict(torch.load(r'.\state_dict.pth'))
torch.save(model, r'.\entire_model.pth')

When I load this again in a torchvision-free environment, I get no errors.
