Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent parameter reloading #9

Closed
pblouw opened this issue Sep 19, 2017 · 0 comments
Closed

Inconsistent parameter reloading #9

pblouw opened this issue Sep 19, 2017 · 0 comments

Comments

@pblouw
Copy link
Contributor

pblouw commented Sep 19, 2017

Reloading model parameters can introduce unexpected indeterminacy to simulations. Minimal example:

import nengo
import nengo.spa as spa
import nengo_dl
import numpy as np
import tensorflow as tf

seed = 98
dims = 32

vocab = spa.Vocabulary(dimensions=dims)
vocab.parse('TRACE')
vocab.parse('CUE')
vocab.add('OUTPUT', vocab.parse('TRACE*~CUE').v)

with nengo.Network(seed=seed) as net:
    net.config[nengo.Ensemble].neuron_type = nengo.RectifiedLinear()
    net.config[nengo.Connection].synapse = None
    
    trace_inp = nengo.Node(vocab['TRACE'].v)
    cue_inp = nengo.Node(vocab['CUE'].v)
    
    extractor = nengo.networks.CircularConvolution(5, dims, invert_b=True)

    nengo.Connection(trace_inp, extractor.input_a)
    nengo.Connection(cue_inp, extractor.input_b)

    out = nengo.Probe(extractor.output)
    
inp_array = vocab['TRACE'].v 
inp_array = inp_array[None, None, :]
cue_array = vocab['CUE'].v
cue_array = cue_array[None, None, :]
out_array = vocab['OUTPUT'].v
out_array = out_array[None, None, :]
    
inputs = {trace_inp: inp_array, cue_inp: cue_array}
outputs = {out: out_array}
        
with nengo_dl.Simulator(net, seed=seed) as sim1:
    optimizer = tf.train.RMSPropOptimizer(1e-3)    
    print('loss pre-training ', sim1.loss(inputs, outputs, 'mse'))
    sim1.train(inputs, outputs, optimizer, n_epochs=5, objective='mse')
    print('loss post-training ', sim1.loss(inputs, outputs, 'mse'))
    sim1.save_params('./example-params')
    
with nengo_dl.Simulator(net, seed=seed) as sim2:
    sim2.load_params('./example-params')
    print('loss post-reloading', sim2.loss(inputs, outputs, 'mse'))

The loss computed after reloading the saved model parameters will not be equivalent to the loss computed prior to saving these parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant