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

Univariate user-defined functions with the multivariate signature #2534

Closed
odow opened this issue Aug 13, 2024 · 4 comments · Fixed by #2542
Closed

Univariate user-defined functions with the multivariate signature #2534

odow opened this issue Aug 13, 2024 · 4 comments · Fixed by #2542
Labels
Submodule: Nonlinear About the Nonlinear submodule

Comments

@odow
Copy link
Member

odow commented Aug 13, 2024

See https://discourse.julialang.org/t/nested-optimization-matrix-multiplication-and-internal-functions/118098/10?u=odow

@odow
Copy link
Member Author

odow commented Aug 28, 2024

This is needed for my work in lanl-ansi/MathOptAI.jl#90

@odow
Copy link
Member Author

odow commented Aug 29, 2024

An alternative would be to allow univariate functions to not support second-order derivatives.

@odow
Copy link
Member Author

odow commented Aug 29, 2024

As a motivating example, we have this working:

    filename = joinpath(dir, "model_Tanh_vector_GrayBox.pt")
    PythonCall.pyexec(
        """
        import torch

        model = torch.nn.Sequential(
            torch.nn.Linear(3, 16),
            torch.nn.Tanh(),
            torch.nn.Linear(16, 2),
        )

        torch.save(model, filename)
        """,
        @__MODULE__,
        (; filename = filename),
    )
    # Full-space
    model = Model(Ipopt.Optimizer)
    set_silent(model)
    @variable(model, x[1:3])
    ml_model = MathOptAI.PytorchModel(filename)
    y = MathOptAI.add_predictor(model, ml_model, x; gray_box = true)

where the PyTorch model is loaded as a user-defined function with automatic memoization for the vector-valued output and we use torch to compute the Jacobian via PythonCall.

But...it doesn't work if the network has a scalar input.

@odow
Copy link
Member Author

odow commented Sep 2, 2024

I realized that this is no longer trivial, because we've pushed the opt-in part of this into the solvers:
https://github.com/jump-dev/Ipopt.jl/blob/4c156461ef1fda3c9f015520197afda4e8ca3e26/src/MOI_wrapper.jl#L606-L611

So perhaps we just need a way for univariates to not supply second derivatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Submodule: Nonlinear About the Nonlinear submodule
Development

Successfully merging a pull request may close this issue.

1 participant