Skip to content

Different behaviour for NSF between versions #75

Closed

Description

@runtingt

Description

I'm observing different outputs between v1.5.0 and v.1.4.1 for the same inputs when using models (such as flows.NSF) that use AutoregressiveTransform internally. When using these models, our rough evaluation sequence is to transform to latent space, flip a boolean context value and then transform back in order to map from one context (simulation) to another (real data). Due to a change in the default value of the slope parameter here, the results differ between the two versions. The slope parameter doesn't appear to be exposed to the user, so currently our solution to use older models with newer versions of zuko is to pin the package to the version used in training.

As this is somewhat brittle and would prevent future updates, would it be possible to make such options available to the user?

Reproduce

import torch
import zuko
print(f"zuko v{zuko.__version__}")

FLIP_CONDITIONAL = True
flow = zuko.flows.NSF(features=2, context=2, transforms=1)
flow = flow.type(torch.float64)
x = torch.tensor([[1., 2.]], dtype=torch.float64)
c = torch.tensor([[1., 0.]], dtype=torch.float64)
transform = flow(c).transform

with torch.no_grad():
    # To latent space
    y = transform(x)

    # Flip condition
    c2 = c.clone()
    if FLIP_CONDITIONAL:
        c2[:, -1] = 1.0 - c2[:, -1]

    # Back to data space
    transform2 = flow(c2).transform
    x_back = transform2.inv(y)

print(f"x: {x}")
print(f"y = transform(x): {y}")
print(f"c: {c}")
print(f"c2 (used for inverse): {c2}")
print(f"x_back = transform.inv(y): {x_back}") # Different values between v1.4.1 and v.1.5.0

Expected behavior

Consistent behaviour between to versions differing only in their MINOR versions, as in https://semver.org/

Causes and solution

Change to the default value of slope here. When creating a flows.NSF object, this parameter isn't exposed to the user so the value is effectively hardcoded.

Environment

  • Zuko version: 1.4.1 and 1.5.0
  • PyTorch version: 2.10.0+cu128
  • Python version: 3.12.12
  • OS: Observed on Fedora 43, Rocky 9.7, RHEL 9.7

Activity

  1. added
    bug
    on Mar 3, 2026
  2. changed the title [-]Different behaviour for `AutoregressiveTransform` betwween versions[/-] [+]Different behaviour for `AutoregressiveTransform` between versions[/+] on Mar 3, 2026
  3. changed the title [-]Different behaviour for `AutoregressiveTransform` between versions[/-] [+]Different behaviour for NSF between versions[/+] on Mar 7, 2026
  4. francois-rozet commented on Mar 7, 2026

    @francois-rozet
    Member

    Hi @runtingt, thank you for the bug report. I am sorry for the issues caused by the latest release. I have implemented your proposed solution in #77. Could you please check if the solution suits your needs?

  5. linked a pull request that will close this issueExpose slope parameter to the user #77on Mar 9, 2026
  6. runtingt commented on Mar 9, 2026

    @runtingt
    Author

    Yep this is great thank you for the super quick fix! Would it be possible to get a new release with this in place?

  7. francois-rozet commented on Mar 14, 2026

    @francois-rozet
    Member

    Yep this is great thank you for the super quick fix! Would it be possible to get a new release with this in place?

    I forgot to mention Zuko 1.6.0 is out 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions