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

Flow identity initialization #72

Open
francesco-vaselli opened this issue Mar 15, 2023 · 1 comment
Open

Flow identity initialization #72

francesco-vaselli opened this issue Mar 15, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@francesco-vaselli
Copy link
Contributor

Hello and thanks for the work on the package,

I am doing some tests with the identity initialization for rational quadratic splines.
When using the new identity init implemented in #65 , giving in input x = torch.tensor([1, 1e-2 ,1e-6, 1e-8, 1e2], dtype=torch.float32) the following is the inverse for the untrained network (which should be initialized as the identity):

# in spline def: enable_identity_init=True

# transform back
flow.transform_to_noise(x.view(-1,1))
tensor([[  1.7013],
        [  1.3796],
        [  1.3739],
        [  1.3739],
        [100.0000]], grad_fn=<AddmmBackward0>)

If instead I manually set the weights of the last layer to 0 in the last layer of the transform network (as done in the normflows package) I get the identity as expected:

# in spline def: enable_identity_init=False

# in the model def
        if init_identity:
          torch.nn.init.constant_(autoregressive_net.final_layer.weight, 0.0)
          torch.nn.init.constant_(
              autoregressive_net.final_layer.bias,
              np.log(np.exp(1 - min_derivative) - 1),
          )

# stuff

# transform back
flow.transform_to_noise(x.view(-1,1))
tensor([[1.0000e+00],
        [1.0000e-02],
        [1.0000e-06],
        [1.0000e-08],
        [1.0000e+02]], grad_fn=<AddmmBackward0>)

I was wondering whether you could help me figure out this difference in behavior.
If this seems potentially useful I can work more than gladly on a pull request.
Best regards,
Francesco

@arturbekasov
Copy link
Contributor

Hey Francesco,

Yeah, this is expected, we don't explicitly initialize the autoregressive_net to identity. The flag applies to the spline function only.

I think having a way to initialize the whole flow to (near?) identity could be useful. I'd happily review a PR on this.

Cheers,

Artur

@arturbekasov arturbekasov added the enhancement New feature or request label Sep 24, 2023
@arturbekasov arturbekasov changed the title stricter (?) identity init Flow identity initialization Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants