Ejemplo n.º 1
0
 def __init__(self):
     self.ps = U.Params(params).init_comps()
     self.pre = None
     self.post = None
     i = torch.constant([0.0] * (4 * 10), shape=(4, 10))
     self.src_b = torch.Variable(initial_value=i)
     i = torch.constant([0.0] * (4 * 10), shape=(4, 10))
     self.mem_b = torch.Variable(initial_value=i)
Ejemplo n.º 2
0
def main(_):
    ps = utils.Params(params).init_comps()
    ds = dset_for(ps, TRAIN)
    # with T.distribute.MirroredStrategy().scope():
    mdl = model_for(ps, compiled=True)
    mdl.train_on_batch(ds)
    mp = pth.Path.cwd() / ps.dir_model / ps.model
    assert tf.get_checkpoint_state(str(mp))
    mdl.load_weights(str(mp / TRAIN))
    c = tf.Checkpoint(model=mdl, optimizer=ps.optimizer)
    c.restore(str(mp / TRAIN)).expect_partial()  # .assert_consumed()
    for n, s in tf.list_variables(str(mp)):
        print(n)
    mp2 = pth.Path.cwd() / ps.dir_model / "mnist_2"
    print("saving...")
    c.save(str(mp2 / TRAIN))
    for n, s in tf.list_variables(str(mp2)):
        print(n)
    assert tf.get_checkpoint_state(str(mp2))
    mdl.load_weights(str(mp2 / "train-1"))
Ejemplo n.º 3
0
    PAD=0,
    brackets=None,
    dim_embed=4,
    dim_hidden=8,
    one_hot=None,
    num_toks=16,
    num_types=4,
    len_src=3,
    len_tgt=3,
    pos_max_len=None,
    pos_max=1.0e4,
    pos_min=1.0,
    pos_start=0,
)

ps = U.Params(params).init_comps()


def test_tokembed():
    e = TokEmbed(ps)
    e.build((1, 5))
    src = torch.constant([1, 2, 0, 3, 0], shape=(1, 5))
    e.call(src)
    ps.one_hot = True
    e = TokEmbed(ps)
    e.build((1, 5))
    e.call(src)


def test_w_grad():
    e = TokEmbed(ps)
Ejemplo n.º 4
0
def load_params():
    f = "channels_first" if T.test.is_built_with_cuda() else "channels_last"
    return U.Params(_params, data_format=F.FLAGS.data_format or f)