algorithms/impala_moa.py
def _make_time_major(policy, seq_lens, tensor, drop_last=False):
    """Swaps batch and trajectory axis.

    Arguments:
        policy: Policy reference
        seq_lens: Sequence lengths if recurrent or None
        tensor: A tensor or list of tensors to reshape.
        drop_last: A bool indicating whether to drop the last
        trajectory item.

    Returns:
        res: A tensor with swapped axes or a list of tensors with
        swapped axes.
    """
    if isinstance(tensor, list):
        return [_make_time_major(policy, seq_lens, t, drop_last) for t in tensor]

    if policy.is_recurrent():
        B = tf.shape(seq_lens)[0]
        T = tf.shape(tensor)[0] // B
    else:
        # Important: chop the tensor into batches at known episode cut
        # boundaries. TODO(ekl) this is kind of a hack
        T = policy.config["rollout_fragment_length"]
        B = tf.shape(tensor)[0] // T
    rs = tf.reshape(tensor, tf.concat([[B, T], tf.shape(tensor)[1:]], axis=0))

    # swap B and T axes
    res = tf.transpose(rs, [1, 0] + list(range(2, 1 + int(tf.shape(tensor).shape[0]))))

    if drop_last:
        return res[:-1]
    return res
Swaps batch and trajectory axis.

    Arguments:
        policy: Policy reference
        seq_lens: Sequence lengths if recurrent or None
        tensor: A tensor or list of tensors to reshape.
        drop_last: A bool indicating whether to drop the last
        trajectory item.

    Returns:
        res: A tensor with swapped axes or a list of tensors with
        swapped axes.
    
Swaps batch and trajectory axis.
Arguments:
policy: Policy reference
seq_lens: Sequence lengths if recurrent or None
tensor: A tensor or list of tensors to reshape.
drop_last: A bool indicating whether to drop the last
trajectory item.

A tensor with swapped axes or a list of tensors with
swapped axes.
Swaps batch and trajectory axis . Arguments : policy : Policy reference seq_lens : Sequence lengths if recurrent or None tensor : A tensor or list of tensors to reshape . drop_last : A bool indicating whether to drop the last trajectory item . A tensor with swapped axes or a list of tensors with swapped axes .
def _make_time_major(policy, seq_lens, tensor, drop_last=False):
    if isinstance(tensor, list):
        return [_make_time_major(policy, seq_lens, t, drop_last) for t in tensor]
    if policy.is_recurrent():
        B = tf.shape(seq_lens)[0]
        T = tf.shape(tensor)[0] // B
    else:
        T = policy.config["rollout_fragment_length"]
        B = tf.shape(tensor)[0] // T
    rs = tf.reshape(tensor, tf.concat([[B, T], tf.shape(tensor)[1:]], axis=0))
    res = tf.transpose(rs, [1, 0] + list(range(2, 1 + int(tf.shape(tensor).shape[0]))))
    if drop_last:
        return res[:-1]
    return res
def _make_time_major ( policy , seq_lens , tensor , drop_last = False ) : if isinstance ( tensor , list ) : return [ _make_time_major ( policy , seq_lens , t , drop_last ) for t in tensor ] if policy . is_recurrent ( ) : B = tf . shape ( seq_lens ) [ 0 ] T = tf . shape ( tensor ) [ 0 ] // B else : T = policy . config [ "rollout_fragment_length" ] B = tf . shape ( tensor ) [ 0 ] // T rs = tf . reshape ( tensor , tf . concat ( [ [ B , T ] , tf . shape ( tensor ) [ 1 : ] ] , axis = 0 ) ) res = tf . transpose ( rs , [ 1 , 0 ] + list ( range ( 2 , 1 + int ( tf . shape ( tensor ) . shape [ 0 ] ) ) ) ) if drop_last : return res [ : - 1 ] return res
Swaps batch and trajectory axis.
Swaps batch and trajectory axis .
"""Swaps batch and trajectory axis.

    Arguments:
        policy: Policy reference
        seq_lens: Sequence lengths if recurrent or None
        tensor: A tensor or list of tensors to reshape.
        drop_last: A bool indicating whether to drop the last
        trajectory item.

    Returns:
        res: A tensor with swapped axes or a list of tensors with
        swapped axes.
    """ # Important: chop the tensor into batches at known episode cut # boundaries. TODO(ekl) this is kind of a hack # swap B and T axes
policy
seq_lens
tensor
drop_last