Created
October 1, 2019 03:59
-
-
Save driazati/6c50d8e15b18d2c043618a8a2432a99e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class M(nn.Module): | |
# Only empty lists/dicts and TorchScript classes need types | |
__annotations__ = { | |
my_list: List[int], | |
} | |
def __init__(self, some_values): | |
super(M, self).__init__() | |
for key in some_values: | |
setattr(self, key, some_values[key]) | |
def forward(self): | |
pass | |
my_values_to_save = { | |
'a': 20, | |
'b': [1, 2, 3], | |
'c': torch.randn(2, 2) | |
} | |
torch.jit.script(M(my_values_to_save)).save('out.pt') | |
# In C++, load `out.pt` as a script::Module and use `get_attribute` to extract | |
# values by name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment