Exemple #1
0
def redis2queue_loop(redis, queue, max_size):
    pointer = 0
    redis_len = redis.llen("episodes") - 1
    while True:
        if pointer < redis_len and queue.qsize() < max_size:
            episode = deserialize(redis.lindex("episodes", pointer))
            queue.put(episode, block=True, timeout=1.0)
            pointer += 1
        else:
            time.sleep(1.0)

        redis_len = redis.llen("episodes") - 1
Exemple #2
0
 def load_actor_weights(self):
     if self.resume is not None:
         checkpoint = UtilsFactory.load_checkpoint(self.resume)
         weights = checkpoint[f"actor_state_dict"]
         self.actor.load_state_dict(weights)
     elif self.redis_server is not None:
         weights = deserialize(
             self.redis_server.get(f"{self.redis_prefix}_actor_weights"))
         weights = {k: self.to_tensor(v) for k, v in weights.items()}
         self.actor.load_state_dict(weights)
     else:
         raise NotImplementedError
     self.actor.eval()
Exemple #3
0
def redis2queue_loop(redis, queue, max_size):
    pointer = 0
    redis_len = redis.llen("trajectories") - 1
    while True:
        try:
            need_more = pointer < redis_len and queue.qsize() < max_size
        except NotImplementedError:  # MacOS qsize issue (no sem_getvalue)
            need_more = pointer < redis_len

        if need_more:
            episode = deserialize(redis.lindex("trajectories", pointer))
            queue.put(episode, block=True, timeout=1.0)
            pointer += 1
        else:
            time.sleep(1.0)

        redis_len = redis.llen("trajectories") - 1
Exemple #4
0
def decompress(data):
    if LZ4_ENABLED:
        data = base64.b64decode(data)
        data = lz4.frame.decompress(data)
        data = deserialize(data)
    return data