Example #1
0
def ensure_plasma_tensorflow_op():
    base_path = os.path.join(pyarrow.__path__[0], "tensorflow")
    lock_path = os.path.join(base_path, "compile_op.lock")
    with filelock.FileLock(lock_path):
        if not os.path.exists(os.path.join(base_path, "plasma_op.so")):
            plasma.build_plasma_tensorflow_op()
        else:
            plasma.load_plasma_tensorflow_op()
Example #2
0
def ensure_plasma_tensorflow_op():
    base_path = os.path.join(pyarrow.__path__[0], "tensorflow")
    lock_path = os.path.join(base_path, "compile_op.lock")
    with filelock.FileLock(lock_path):
        if not os.path.exists(os.path.join(base_path, "plasma_op.so")):
            plasma.build_plasma_tensorflow_op()
        else:
            plasma.load_plasma_tensorflow_op()
Example #3
0
    def __init__(self, worker_index, config, logdir):
        logger.warning(f'Create agent {worker_index}')
        self.dconfig = utils.DotDict(config)
        self.logdir = logdir
        self.worker_index = worker_index
        self.locals = None
        self.feed_dict = None
        self.objective_vars_oid = None
        self.datasets_initialized = False

        import tensorflow as tf
        plasma.load_plasma_tensorflow_op()

        logger.warning(f'Created agent {worker_index}')
Example #4
0
    def __init__(self, config, init_vars):
        import tensorflow as tf
        dconfig = utils.DotDict(config)

        plasma.load_plasma_tensorflow_op()

        store_socket = utils.get_store_socket()
        self.var_oid = None

        self.obj_vars = [
            tf.Variable(init_var, name='obj_var', dtype=tf.float32)
            for init_var in init_vars
        ]
        self.plasma_grads_oids = tf.placeholder(shape=[dconfig.agent_count],
                                                dtype=tf.string,
                                                name="plasma_grads_oids")
        self.plasma_vars_oid = tf.placeholder(shape=[],
                                              dtype=tf.string,
                                              name="plasma_vars_oids")

        shapes = [v.shape for v in self.obj_vars]
        grads = utils.reverse_flat(
            tf.reduce_mean([
                plasma.tf_plasma_op.plasma_to_tensor(
                    self.plasma_grads_oids[a],
                    dtype=tf.float32,
                    plasma_store_socket_name=store_socket)
                for a in range(dconfig.agent_count)
            ],
                           axis=0), shapes)

        obj_optimizer = tf.train.AdamOptimizer(
            learning_rate=dconfig.obj_func_learning_rate)
        self.train_obj_op = obj_optimizer.apply_gradients(
            zip(grads, self.obj_vars))
        with tf.control_dependencies([self.train_obj_op]):
            import tensorflow as tf
            self.update_vars = plasma.tf_plasma_op.tensor_to_plasma(
                [utils.flat(self.obj_vars)],
                self.plasma_vars_oid,
                plasma_store_socket_name=store_socket)

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        self.sess = tf.Session(config=config)
        self.sess.run(tf.global_variables_initializer())