You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4.[Reproducing the Benchmark](#reproducing-the-benchmark)
14
-
5.[License and terms of use](#license-and-terms-of-use)
15
-
6.[References](#references)
13
+
4.[License and terms of use](#license-and-terms-of-use)
14
+
5.[References](#references)
16
15
17
16
humancompatible-train is still under active development! If you find bugs or have feature
18
17
requests, please file a
@@ -32,28 +31,32 @@ The only dependencies of this package are `numpy` and `torch`.
32
31
33
32
The toolkit implements algorithms for constrained training of neural networks based on PyTorch.
34
33
35
-
The algorithms follow the `dual_step()` - `step()` framework: taking inspiration from PyTorch, the `dual_step()` does updates related to the dual parameters and prepares for the primal update (by, e.g., saving constraint gradients), and `step()` updates the primal parameters.
34
+
The algorithms are intended for use in tandem with classic PyTorch optimizers, calculating the Lagrangian and keeping track of the dual variables.
35
+
36
+
<!-- The algorithms follow the `dual_step()` - `step()` framework: taking inspiration from PyTorch, the `dual_step()` does updates related to the dual parameters and prepares for the primal update (by, e.g., saving constraint gradients), and `step()` updates the primal parameters. -->
36
37
37
38
In general, your code using `humancompatible-train` would look something like this:
The key difference is calculating the lagrangian using **`lgr = forward_update(loss, constraints)`**, and then running **`lgr.backward()`** instead of `loss.backward()`.
59
+
57
60
Our idea is to
58
61
59
62
1. Deviate minimally from the usual PyTorch workflow
@@ -63,22 +66,70 @@ Our idea is to
63
66
64
67
You are invited to check out our new API presented in notebooks in the `examples` folder.
65
68
66
-
The example notebooks have additional dependencies, such as `fairret`. To install those, run
69
+
The example notebooks have additional dependencies for data and plotting, such as `fairret`. To install those, run
67
70
68
71
```
69
72
pip install humancompatible-train[examples]
70
73
```
71
74
72
-
*The legacy API used for the benchmark is presented in `examples/_old_/algorithm_demo.ipynb` and `examples/_old_/constraint_demo.ipynb`.*
73
-
74
75
## Extending the toolkit
75
76
76
-
### Adding new code
77
-
78
77
**To add a new algorithm**, you can subclass the PyTorch ```Optimizer``` class and proceed following the API guideline presented above.
79
78
80
79
## Reproducing the Benchmark
81
80
81
+
The code for benchmarking constrained regularization algorithms is available in the `benchmark` directory.
The benchmark offers two families of datasets: Folktables and Dutch, several pre-defined constraints, and several constrained optimization algorithms: `ALM` (smoothed and non-smoothed), `SPBM`, and Switching Subgradient; we are currently working to add Stochastic Ghost within the new framework as well.
113
+
114
+
To run an experiment, run:
115
+
116
+
```
117
+
python run_benchmark.py --dataset <DATASET> [folktables, dutch] --task <TYPE OF CONSTRAINT> [loss, equalized_odds_pairwise, equalized_odds_vec, weight_norm] --n_runs <NUMBER OF RUNS OF EACH METHOD> --n_epochs <NUMBER OF EPOCHS PER RUN>
118
+
```
119
+
120
+
The constraint options are:
121
+
122
+
-`loss`: constraint(s) on the absolute difference between the classification loss on each group and the overall classification loss;
123
+
-`equalized_odds_pairwise`: constraint(s) on the absolute difference between the positive rate between each group;
124
+
-`equalized_odds_vec`: constraint on the Positive Rate of each group as defined by `fairret.NormLoss`;
125
+
-`weight_norm`: constraint on the Frobenius norm of the weights and biases of each layer of the neural network.
126
+
127
+
The benchmarking code (all of which is contained in the `benchmark` directory) is easy to parse and extend with other datasets and constraints.
128
+
129
+
130
+
<!--
131
+
## Reproducing the Benchmark
132
+
82
133
The code used in [our benchmark paper](https://arxiv.org/abs/2507.04033) is not migrated to the new API yet (WIP).
83
134
84
135
### Basic installation instructions
@@ -122,11 +173,6 @@ pip install -e .
122
173
123
174
after installing requirements.txt; otherwise, the algorithm will run slower. However, this is not supported on MacOS and may fail on some Windows devices.
124
175
125
-
<!-- Install via pip -->
126
-
<!-- ``` -->
127
-
<!-- pip install folktables -->
128
-
<!-- ``` -->
129
-
130
176
### Running the algorithms
131
177
132
178
The benchmark comprises the following algorithms:
@@ -149,19 +195,6 @@ python run_folktables.py data=folktables alg=fairret # baseline, fairness with r
149
195
150
196
Each command will start 10 runs of the `alg`, 30 seconds each.
151
197
The results will be saved to `experiments/utils/saved_models` and `experiments/utils/exp_results`.
152
-
<!-- In the repository, we include the configuration needed to reproduce the experiments in the paper. To do so, go to `experiments` and run `python run_folktables.py data=folktables alg=sslalm`. -->
153
-
<!-- Repeat for the other algorithms by changing the `alg` parameter. -->
154
-
155
-
This repository uses [Hydra](https://hydra.cc/) to manage parameters; see `experiments/conf` for configuration files.
156
-
157
-
- To change the parameters of the experiment, such as the number of runs for each algorithm, run time, the dataset used (*note: for now supports only Folktables*) - use `experiment.yaml`.
158
-
- To change the dataset settings - such as file location - or do dataset-specific adjustments - such as the configuration of the protected attributes - use `data/{dataset_name}.yaml`
159
-
- To change algorithm hyperparameters, use `alg/{algorithm_name}.yaml`.
160
-
- To change constraint hyperparameters, use `constraint/{constraint_name}.yaml`
161
-
162
-
<!-- ; it is installed as one of the dependencies. -->
163
-
<!-- To learn more about using Hydra, please check out the [official tutorial](https://hydra.cc/docs/tutorials/basic/your_first_app). -->
164
-
165
198
### Producing plots
166
199
167
200
The plots and tables like the ones in the paper can be produced using the two notebooks. `experiments/algo_plots.ipynb` houses the convergence plots, and `experiments/model_plots.ipynb` - all the others.
@@ -176,25 +209,14 @@ It provides code to download data from the American Community Survey
176
209
The data itself is governed by the terms of use provided by the Census Bureau.
177
210
For more information, see <https://www.census.gov/data/developers/about/terms-of-service.html>
178
211
179
-
<!-- ## Cite this work -->
212
+
-->
180
213
181
-
<!-- If you use this work, we encourage you to cite our paper, and the folktables dataset [[1]](#1). -->
182
214
183
-
<!-- ``` -->
184
-
<!-- @article{ding2021retiring, -->
185
-
<!-- title={Retiring Adult: New Datasets for Fair Machine Learning}, -->
186
-
<!-- author={Ding, Frances and Hardt, Moritz and Miller, John and Schmidt, Ludwig}, -->
187
-
<!-- journal={Advances in Neural Information Processing Systems}, -->
188
-
<!-- volume={34}, -->
189
-
<!-- year={2021} -->
190
-
<!-- } -->
191
-
<!-- ``` -->
192
215
193
216
## Future work
194
217
195
218
- Add more algorithms
196
219
- Add more examples from different fields where constrained training of DNNs is employed
0 commit comments