Skip to content

Commit e884f8d

Browse files
committed
Some formatting fix
1 parent 9f7c00b commit e884f8d

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

ONNX_EXPORT_GUIDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Gurobi ML supports two types of neural network architectures:
88

99
1. **Sequential Models**: Linear chains of layers (Dense → ReLU → Dense → ...)
1010
- Supported directly via `add_keras_constr` and `add_sequential_constr`
11-
11+
1212
2. **DAG Models**: Arbitrary directed acyclic graphs with skip/residual connections
1313
- Supported via ONNX export + `add_onnx_dag_constr`
1414

@@ -105,14 +105,14 @@ class ResidualBlock(nn.Module):
105105
self.linear1 = nn.Linear(dim, dim)
106106
self.relu = nn.ReLU()
107107
self.linear2 = nn.Linear(dim, dim)
108-
108+
109109
def forward(self, x):
110110
identity = x # Skip connection
111-
111+
112112
out = self.linear1(x)
113113
out = self.relu(out)
114114
out = self.linear2(out)
115-
115+
116116
out = out + identity # Residual addition
117117
return out
118118

@@ -122,7 +122,7 @@ class ResNetModel(nn.Module):
122122
self.input_layer = nn.Linear(4, 8)
123123
self.residual_block = ResidualBlock(8)
124124
self.output_layer = nn.Linear(8, 2)
125-
125+
126126
def forward(self, x):
127127
x = self.input_layer(x)
128128
x = self.residual_block(x) # Residual connection inside

src/gurobi_ml/onnx/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
Provides two implementations:
1919
2020
1. **add_onnx_constr**: Sequential feed-forward networks only
21-
21+
2222
- Validates that models have sequential topology
2323
- Rejects models with skip/residual connections
2424
- Use for simple feed-forward networks
2525
2626
2. **add_onnx_dag_constr**: Supports arbitrary DAG topologies
27-
27+
2828
- Skip connections (input used by multiple layers)
2929
- Residual connections (intermediate outputs reused)
3030
- Multi-branch architectures
3131
- Any valid directed acyclic graph
32-
32+
3333
**Recommended Workflow for Keras and PyTorch Models:**
3434
3535
For models with complex architectures (ResNet, skip connections, etc.),

src/gurobi_ml/onnx/onnx_dag_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _topological_sort(self, graph):
141141
-------
142142
list of onnx.NodeProto
143143
Nodes in topological order
144-
144+
145145
Raises
146146
------
147147
NoModel

src/gurobi_ml/torch/sequential.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,29 @@ def add_sequential_constr(
6464
Notes
6565
-----
6666
|VariablesDimensionsWarn|
67-
67+
6868
**Models with Skip Connections or Residual Architectures**
69-
69+
7070
This function only supports :external+torch:py:class:`torch.nn.Sequential` models
7171
(linear chains of layers). For models with more complex architectures such as:
72-
72+
7373
- Skip connections (input reused by multiple layers)
7474
- Residual connections (intermediate outputs reused)
7575
- Custom :external+torch:py:class:`torch.nn.Module` with complex forward() logic
7676
- ResNet, DenseNet, or other modern architectures
77-
77+
7878
**Use the ONNX export workflow instead:**
79-
79+
8080
1. Export your PyTorch model to ONNX format:
81-
81+
8282
.. code-block:: python
83-
83+
8484
import torch
8585
import onnx
86-
86+
8787
# Prepare dummy input with correct shape
8888
dummy_input = torch.randn(1, input_dim)
89-
89+
9090
# Export to ONNX
9191
torch.onnx.export(
9292
pytorch_model, # Your model
@@ -102,23 +102,23 @@ def add_sequential_constr(
102102
'output': {0: 'batch_size'}
103103
}
104104
)
105-
105+
106106
# Verify the exported model
107107
onnx_model = onnx.load("model.onnx")
108108
onnx.checker.check_model(onnx_model)
109-
109+
110110
2. Load and use with Gurobi ML's ONNX DAG support:
111-
111+
112112
.. code-block:: python
113-
113+
114114
import onnx
115115
from gurobi_ml.onnx import add_onnx_dag_constr
116-
116+
117117
onnx_model = onnx.load("model.onnx")
118118
pred = add_onnx_dag_constr(gp_model, onnx_model, input_vars)
119-
119+
120120
For more details on exporting PyTorch models to ONNX, see:
121-
121+
122122
- `PyTorch ONNX export tutorial <https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html>`_
123123
- `torch.onnx documentation <https://pytorch.org/docs/stable/onnx.html>`_
124124
- `ONNX tutorials <https://onnx.ai/get-started.html>`_

0 commit comments

Comments
 (0)