Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composing Autoregressive and Fixed bijectors error #115

Open
matteobettini opened this issue Nov 2, 2023 · 1 comment
Open

Composing Autoregressive and Fixed bijectors error #115

matteobettini opened this issue Nov 2, 2023 · 1 comment

Comments

@matteobettini
Copy link

matteobettini commented Nov 2, 2023

Issue Description

Hello, I am trying to compuse a bijector with AffineAutoregressive and Tanh.
The flow crashes in this case when computing the log_prob.

Steps to Reproduce

dim = 2

base_dist = torch.distributions.Independent(
    torch.distributions.Normal(torch.zeros(dim), torch.ones(dim)), 1
)
bijectors = bij.Compose(
    [
        bij.AffineAutoregressive(
            params_fn=DenseAutoregressive(
                hidden_dims=(64, 64), nonlinearity=nn.ReLU
            )
        )
        for _ in range(1)
    ]
    + [bij.Tanh()]
)
flow = flowtorch.distributions.Flow(base_dist, bijectors)
flow.log_prob(torch.zeros(400, dim))
Traceback (most recent call last):
  File "/Users/Matteo/PycharmProjects/HetControl/het_control/flowtorch_test.py", line 73, in <module>
    flow.log_prob(torch.zeros(400, 2))
  File "/opt/homebrew/Caskroom/miniforge/base/envs/torchrl/lib/python3.9/site-packages/flowtorch/distributions/flow.py", line 114, in log_prob
    x = self.bijector.inverse(value, context)  # type: ignore
  File "/opt/homebrew/Caskroom/miniforge/base/envs/torchrl/lib/python3.9/site-packages/flowtorch/bijectors/compose.py", line 90, in inverse
    log_detJ = log_detJ + _log_detJ if log_detJ is not None else _log_detJ
RuntimeError: The size of tensor a (2) must match the size of tensor b (400) at non-singleton dimension 1

Expected Behavior

I expected to be able to chain compose the bijectors.

@matteobettini
Copy link
Author

I would have posted this in https://github.com/stefanwebb/flowtorch but there is no issue tab there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant