Skip to content

Coupling layers#92

Open
vmoens wants to merge 16 commits intofacebookincubator:mainfrom
vmoens:coupling
Open

Coupling layers#92
vmoens wants to merge 16 commits intofacebookincubator:mainfrom
vmoens:coupling

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

@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.

vmoens added 2 commits April 26, 2022 16:21
# 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
@facebook-github-bot
Copy link
Contributor

Hi @vmoens!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

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