Saving/loading a dict using pytorch

Hi! I have a code like this

calculate_kl(name):
kl = {'a': [], 'b': [], 'c': []}
        for i in range(64):
            value = calculate_value(name, a, i)    #returns an int
            kl['a'].append(value)
        for i in range(128):
            value = calculate_value(name, b, i)    # returns an int
            kl['b'].append(value)
        for i in range(256):
            value = claculate_value(name, c, i)    # returns an int
            kl['c'].append(value)
       return kl

importnace = {'alpha': calculate_kl('alpha'), 'beta': calculate_kl('beta')}

how can I save the dict importance and then use it in another code?
I used torch.save(importnace, 'kl.csv') and then

importance = {}
importance.load_state_dict(torch.load('kl.csv'))

but it doesn’t work.

You can load it with assignment

importance=torch.load(...) #importance should be OrderedDict type
1 Like