nnrl/utils.py
def flat_grad(
    outputs: Union[Tensor, Iterator[Tensor]], inputs: Iterator[Tensor], *args, **kwargs
) -> Tensor:
    """Compute gradients and return a flattened array."""
    params = list(inputs)
    grads = grad(outputs, params, *args, **kwargs)
    zeros = torch.zeros
    return torch.cat(
        [zeros(p.numel()) if g is None else g.flatten() for p, g in zip(params, grads)]
    )
Compute gradients and return a flattened array.
Compute gradients and return a flattened array.
Compute gradients and return a flattened array .
def flat_grad(
    outputs: Union[Tensor, Iterator[Tensor]], inputs: Iterator[Tensor], *args, **kwargs
) -> Tensor:
    params = list(inputs)
    grads = grad(outputs, params, *args, **kwargs)
    zeros = torch.zeros
    return torch.cat(
        [zeros(p.numel()) if g is None else g.flatten() for p, g in zip(params, grads)]
    )
def flat_grad ( outputs : Union [ Tensor , Iterator [ Tensor ] ] , inputs : Iterator [ Tensor ] , * args , ** kwargs ) -> Tensor : params = list ( inputs ) grads = grad ( outputs , params , * args , ** kwargs ) zeros = torch . zeros return torch . cat ( [ zeros ( p . numel ( ) ) if g is None else g . flatten ( ) for p , g in zip ( params , grads ) ] )
Compute gradients and return a flattened array.
Compute gradients and return a flattened array .
"""Compute gradients and return a flattened array."""
outputs
Union[Tensor, Iterator[Tensor]]
inputs
Iterator[Tensor]