-
Notifications
You must be signed in to change notification settings - Fork 51
Very experimental add some way to get VNNLIB #456
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
Open
pobonomo
wants to merge
30
commits into
Gurobi:main
Choose a base branch
from
pobonomo:vnnlib
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started doing a convolutional net with keras. notebooks/adversarial/adversarial_cnn.ipynb contains a working example that we would want to model with gurobi_ml A conv2d layer is in progress (doesn't crash and does something). The big mess now is variable dimensions. Gurobi ML was more or less designed around the idea that the input of the ML model is 2-d (n_examples, n_features) but of course convolutional layers are 4-d (n_examples, height, width, n_channels) The 2d assumption is all other the place... Missing layers: - MaxPooling - Dropout - Flatten Also for the conv2d only did with valid padding and the for loop is
Let's see if chat gpt can do the max pooling and flatten layers
We get something unsolvable on my example :-()
A very tiny one without pooling layers. A less tiny with pooling. Right now I need to cheat on the bounds of the input layer.
Add MatMult and Plus
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
This commit adds full support for neural networks with arbitrary Directed Acyclic Graph (DAG) topologies, including skip connections, residual connections, and multi-branch architectures. New Features: - DAGNNConstr: Base class for neural networks with DAG topology - AddLayer: New layer type for element-wise addition (residual connections) - ONNXDAGNetworkConstr: ONNX implementation with topological sorting - add_onnx_dag_constr: New API function for DAG models Technical Implementation: - Kahn's algorithm for topological sorting of computation graphs - Tensor variable tracking through the graph - Support for tensor reuse (skip/residual connections) - Handles unnamed ONNX nodes correctly Supported ONNX Operations: - Gemm (fully connected layers with transB support) - MatMul (matrix multiplication) - Add (both bias addition and residual connections) - Relu (activation) - Identity (pass-through) Architecture Support: Sequential networks (backward compatible) Skip connections (input used by multiple layers) Residual connections (intermediate outputs reused) Multi-branch architectures Testing: - 4 new comprehensive tests in test_onnx_dag.py - All existing tests continue to pass (backward compatible) - Validated with real CerSyVe models (pendulum, cart_pole, etc.) - Accuracy: < 1e-7 error vs ONNX Runtime Backward Compatibility: - Original add_onnx_constr and BaseNNConstr unchanged - New functionality is opt-in via add_onnx_dag_constr - Existing code continues to work without modification
Replace the custom implementation of Kahn's algorithm with Python's standard library graphlib.TopologicalSorter (available since Python 3.9). Benefits: - More maintainable (uses standard library) - Better tested (Python standard library) - Cleaner code (less custom implementation) - Better error messages (CycleError with details) The project requires Python 3.10+, so graphlib is always available. Changes: - Import graphlib module - Replace manual Kahn's algorithm with TopologicalSorter - Use static_order() to get sorted nodes - Catch graphlib.CycleError for cycle detection All tests continue to pass with identical behavior.
Update Keras and PyTorch documentation to guide users on using ONNX export for models with skip connections and residual architectures. Changes to Keras (keras.py): - Added comprehensive 'Models with Skip Connections' section - Provided two export methods: tf2onnx and keras2onnx - Included complete code examples - Linked to tf2onnx, keras2onnx, and ONNX documentation Changes to PyTorch (sequential.py): - Added 'Models with Skip Connections' section - Provided torch.onnx.export example with all parameters - Included verification steps - Linked to PyTorch ONNX tutorials and documentation Changes to ONNX module (__init__.py): - Enhanced module docstring with usage examples - Added quick reference for Keras and PyTorch export - Clarified difference between add_onnx_constr and add_onnx_dag_constr New file: ONNX_EXPORT_GUIDE.md - Complete guide for using DAG models via ONNX - Step-by-step examples for Keras and PyTorch - ResNet and skip connection examples - Troubleshooting section - Installation requirements - Links to external documentation This addresses the workflow where users with complex neural network architectures (ResNet, skip connections, etc.) should export to ONNX first rather than using the direct Keras/PyTorch APIs which only support sequential models. References included: - PyTorch ONNX tutorials: pytorch.org/tutorials - tf2onnx documentation: github.com/onnx/tensorflow-onnx - keras2onnx documentation: github.com/onnx/keras-onnx - ONNX official docs: onnx.ai
|
Pierre Bonami seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
1 similar comment
|
Pierre Bonami seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Still slow for large networks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is kind a lot of things that needs testing the goal is to get as many vnn competition models understood.
Needs ONNX, new types of layer (conv2D, pooling,...), new network architectures (skip connections,...), and parsing vnnlib files