Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
46838f7
some convolutional net
pobonomo Jun 17, 2024
4de0c11
Some additional layers
Oct 5, 2025
2e00ad8
It almost works
pobonomo Oct 5, 2025
d4406d2
The models for conv2d, maxpool and flatten seem correct now!
pobonomo Oct 5, 2025
20ef6e9
Notebooks for cnn
pobonomo Oct 6, 2025
066bf54
Add some support of ONNX through codex
pobonomo Oct 7, 2025
1559b31
Add an adversarial notebook for ONNX
pobonomo Oct 7, 2025
a7ef2db
Add more ONNX operation
Oct 13, 2025
717ecc3
Review onnx code
Oct 14, 2025
e18c1a0
Add a composite test
Oct 14, 2025
9581e59
Enable composite example in tox
Oct 16, 2025
a43c42f
Apply suggestion from @Copilot
pobonomo Oct 30, 2025
97dbbef
Apply suggestion from @Copilot
pobonomo Oct 30, 2025
069eb8b
Set ONNX version in test
pobonomo Oct 30, 2025
d068839
Add some detection of non-sequential neural networks
pobonomo Nov 7, 2025
4646df7
Add DAG neural network support for skip and residual connections
pobonomo Nov 7, 2025
5a99cc4
Use Python's TopologicalSorter instead of custom Kahn's algorithm
pobonomo Nov 7, 2025
b2b505a
Add documentation for ONNX export workflow for DAG models
pobonomo Nov 7, 2025
62a78e7
Merge branch 'onnx' into vnnlib
pobonomo Nov 11, 2025
d4f2863
Add convolutional layers to ONNX models
pobonomo Nov 11, 2025
534de49
Add padding support in onnx
pobonomo Nov 11, 2025
0718074
Speed up a bit the convolutional layers
pobonomo Nov 11, 2025
54d65e5
Merge branch 'feature/dag-neural-network-support' into vnnlib
pobonomo Nov 11, 2025
a9b10ca
Extend non-sequential neural nets to convolutional layers
pobonomo Nov 11, 2025
db7ee2d
Non working
Nov 11, 2025
657d7a0
This should now speed up convolutional networks
pobonomo Nov 11, 2025
1d7ca0c
Add batch normalization layers and conversion scripts
pobonomo Nov 12, 2025
e1a59bd
Add simple vnnlib parser
pobonomo Nov 12, 2025
166521c
Improve vnnlib conversion organization
pobonomo Nov 12, 2025
5d116e2
Fix skipping
pobonomo Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions DOCUMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Documentation Updates Summary

## Overview

Updated documentation across Keras, PyTorch, and ONNX modules to guide users on the recommended workflow for neural networks with skip connections and residual architectures.

## Key Message

**For models with complex architectures (skip connections, ResNet, etc.):**
- Export to ONNX format first
- Use `add_onnx_dag_constr` for full DAG support
- Direct Keras/PyTorch APIs only support sequential models

## Files Updated

### 1. Keras Documentation (`src/gurobi_ml/keras/keras.py`)

**Added Section:** "Models with Skip Connections or Residual Architectures"

**Content:**
- Explains when to use ONNX export (skip connections, Functional API, etc.)
- Two export methods with code examples:
- tf2onnx (recommended)
- keras2onnx (alternative)
- Complete workflow from export to Gurobi ML usage
- Links to external documentation

**Key References:**
- https://github.com/onnx/tensorflow-onnx (tf2onnx)
- https://github.com/onnx/keras-onnx (keras2onnx)
- https://onnx.ai/get-started.html (ONNX)

### 2. PyTorch Documentation (`src/gurobi_ml/torch/sequential.py`)

**Added Section:** "Models with Skip Connections or Residual Architectures"

**Content:**
- Explains limitations of torch.nn.Sequential
- Complete torch.onnx.export example with all parameters
- Model verification steps
- Workflow from export to Gurobi ML usage
- Links to official tutorials

**Key References:**
- https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html
- https://pytorch.org/docs/stable/onnx.html
- https://onnx.ai/get-started.html

### 3. ONNX Module Documentation (`src/gurobi_ml/onnx/__init__.py`)

**Enhanced:** Module-level docstring

**Content:**
- Clear distinction between add_onnx_constr and add_onnx_dag_constr
- Quick reference examples for Keras and PyTorch export
- Recommended workflow overview

### 4. Comprehensive Guide (`ONNX_EXPORT_GUIDE.md`)

**New File:** Complete tutorial and reference

**Sections:**
1. Overview - When to use ONNX export
2. Keras Models with Skip Connections
- Full example with skip connection
- Step-by-step export process
- Gurobi ML integration
3. PyTorch Models with Residual Connections
- ResNet-style example
- Detailed export parameters
- Accuracy verification
4. Supported ONNX Operations
5. Accuracy Information
6. Installation Requirements
7. Common Issues and Solutions
8. References

## Documentation Style

All documentation follows these principles:

1. **Problem First:** Explains when users need ONNX export
2. **Step-by-Step:** Clear numbered steps with code examples
3. **Complete Code:** Runnable examples, not fragments
4. **External Links:** References to official documentation
5. **Troubleshooting:** Common issues and solutions

## Example Workflow Documented

### Keras
```python
# 1. Export to ONNX
import tf2onnx
spec = (tf.TensorSpec((None, input_dim), tf.float32, name="input"),)
model_proto, _ = tf2onnx.convert.from_keras(keras_model, input_signature=spec)
onnx.save(model_proto, "model.onnx")

# 2. Use with Gurobi ML
from gurobi_ml.onnx import add_onnx_dag_constr
onnx_model = onnx.load("model.onnx")
pred = add_onnx_dag_constr(gp_model, onnx_model, input_vars)
```

### PyTorch
```python
# 1. Export to ONNX
torch.onnx.export(pytorch_model, dummy_input, "model.onnx",
export_params=True, opset_version=11)

# 2. Use with Gurobi ML
from gurobi_ml.onnx import add_onnx_dag_constr
onnx_model = onnx.load("model.onnx")
pred = add_onnx_dag_constr(gp_model, onnx_model, input_vars)
```

## Impact

**Before:**
- Users with ResNet/skip connection models would get NoModel errors
- No guidance on alternatives
- Frustration and confusion

**After:**
- Clear explanation of limitations
- Step-by-step ONNX export workflow
- Links to official documentation
- Working examples
- Troubleshooting guide

## Testing

All documentation has been verified for:
- ✓ Python syntax correctness
- ✓ Presence of key sections (Skip Connections, ONNX export)
- ✓ References to export functions (tf2onnx, torch.onnx.export)
- ✓ Links to external documentation
- ✓ Complete code examples

## Related Files

- `DAG_IMPLEMENTATION_SUMMARY.md` - Technical implementation details
- `COMPLETE_SOLUTION_SUMMARY.md` - Complete solution overview
- `DEMO_DAG_IMPLEMENTATION.py` - Working demonstration script

## Future Considerations

If direct Keras/PyTorch DAG support is added later:
1. Update these documentation sections
2. Add new API functions
3. Keep ONNX workflow as alternative
4. Maintain backward compatibility
Loading
Loading