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

Coupling layers #92

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Coupling layers #92

wants to merge 16 commits into from

Conversation

vmoens
Copy link
Contributor

@vmoens vmoens commented Feb 9, 2022

Adds Coupling layers.

### Test plan

from flowtorch.parameters.coupling import DenseCoupling, ConvCoupling
from flowtorch.bijectors.coupling import CouplingBijector as Coupling, ConvCouplingBijector
import torch
torch.set_default_dtype(torch.double)

def test():
    d = DenseCoupling()
    c = Coupling(d)
    c = c(shape=torch.Size([32,]))
    for p in c.parameters():
        p.data += torch.randn_like(p)/10
    x = torch.randn(1, 32,requires_grad=True)
    y = c.forward(x)
    yd = y.detach_from_flow()
    x_bis = c.inverse(yd)
    torch.testing.assert_allclose(x, x_bis)
    
    torch.testing.assert_allclose(
        c.log_abs_det_jacobian(x, y), 
        c.log_abs_det_jacobian(x, yd)
    )
    
test()

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 9, 2022
@vmoens vmoens changed the title Coupling layers [WIP] Coupling layers Feb 9, 2022
Copy link
Contributor

@stefanwebb stefanwebb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really fantastic - I think it's almost there! Let's have a chat offline about coupling transforms, I think there may be a few ways to interpret them from the literature

flowtorch/bijectors/affine_autoregressive.py Outdated Show resolved Hide resolved
flowtorch/bijectors/affine_autoregressive.py Outdated Show resolved Hide resolved
flowtorch/bijectors/coupling.py Outdated Show resolved Hide resolved
flowtorch/parameters/__init__.py Outdated Show resolved Hide resolved
flowtorch/parameters/base.py Outdated Show resolved Hide resolved
flowtorch/parameters/dense_autoregressive.py Show resolved Hide resolved
flowtorch/parameters/dense_autoregressive.py Show resolved Hide resolved
flowtorch/parameters/coupling.py Outdated Show resolved Hide resolved
@vmoens vmoens marked this pull request as ready for review April 22, 2022 12:04
@vmoens vmoens changed the title [WIP] Coupling layers Coupling layers Apr 22, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #92 (54b4078) into main (4992731) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   98.25%   98.29%   +0.04%     
==========================================
  Files           6        6              
  Lines         229      235       +6     
==========================================
+ Hits          225      231       +6     
  Misses          4        4              
Flag Coverage Δ
unittests 98.29% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
tests/test_bijectivetensor.py 98.64% <ø> (ø)
tests/test_bijector.py 100.00% <100.00%> (ø)
tests/test_distribution.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4992731...54b4078. Read the comment docs.

# Conflicts:
#	flowtorch/bijectors/base.py
#	flowtorch/bijectors/compose.py
#	flowtorch/bijectors/ops/spline.py
#	tests/test_bijector.py
facebook-github-bot pushed a commit that referenced this pull request May 9, 2022
Summary:
### Motivation
As pointed out in #85, it may be preferable to use `softplus` rather than `exp` to calculate the scale parameter of the affine map in `bij.ops.Affine`.

### Changes proposed
Another PR #92 by vmoens implements `softplus`, `sigmoid`, and `exp` options for the scale parameter - I have factored that out and simplified some of the design in order to make #92 easier for review. `softplus` is now the default option for `Affine`

Pull Request resolved: #109

Test Plan: `pytest tests/`

Reviewed By: vmoens

Differential Revision: D36169529

Pulled By: stefanwebb

fbshipit-source-id: 625387e10399291a5a404c28f4ada743d0945649
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants