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

Don't rely on out_features to get output dimension of PytorchModel #165

Closed
Robbybp opened this issue Jan 16, 2025 · 0 comments · Fixed by #166
Closed

Don't rely on out_features to get output dimension of PytorchModel #165

Robbybp opened this issue Jan 16, 2025 · 0 comments · Fixed by #166

Comments

@Robbybp
Copy link
Collaborator

Robbybp commented Jan 16, 2025

out_features is only defined for linear layers (or, at least, it's not defined for sigmoid layers). MWE:

# model.py
import torch
nn = torch.nn.Sequential(torch.nn.Linear(1, 10), torch.nn.Sigmoid())
torch.save(nn, "sigmoid_output.pt")
# model.jl
import MathOptAI
import PythonCall
import JuMP

nn = MathOptAI.PytorchModel("sigmoid_output.pt")
gb = MathOptAI.GrayBox(nn)
model = JuMP.Model()
JuMP.@variable(model, x)
MathOptAI.add_predictor(model, gb, [x])

Fails with: ERROR: LoadError: Python: AttributeError: 'Sigmoid' object has no attribute 'out_features'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant