def save_checkpoint_vars(dic, path):
    """
    Save variables in dic to path.

    Args:
        dic: {name: value}. values have to be numpy arrays
        path: save as npz if the name ends with '.npz', otherwise save as a checkpoint.
    """
    logger.info("Variables to save to {}:".format(path))
    keys = sorted(dic.keys())
    logger.info(pprint.pformat(keys))

    assert not path.endswith('.npy')
    if path.endswith('.npz'):
        np.savez_compressed(path, **dic)
    else:
        with tfv1.Graph().as_default(), \
                tfv1.Session() as sess:
            for k, v in six.iteritems(dic):
                k = get_op_tensor_name(k)[0]
                _ = tfv1.Variable(name=k, initial_value=v)    # noqa
            sess.run(tfv1.global_variables_initializer())
            saver = tfv1.train.Saver()
            saver.save(sess, path, write_meta_graph=False)

    Save variables in dic to path.

    Args:
        dic: {name: value}. values have to be numpy arrays
        path: save as npz if the name ends with '.npz', otherwise save as a checkpoint.
    
tensorpack/tfutils/varmanip.py