Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Fixed issue with missing argument in MNIST example
Summary:
sr stands for sampling rate, which is now legacy code. Now, it's just sample_rate = 1 / len(data_loader). This has been fixed in the example, by setting batch size to be 60000 * 0.004 = 240 (thanks to https://github.com/ffuuugor for the clarification).

On another note, when running with DP, the following error is thrown
```
AttributeError: Can't pickle local object 'wrap_collate_with_empty.<locals>.collate'
```

For now, a temporary fix (based on IBM/Project_CodeNet#21 (comment)) is to make num_workers=0 in the dataset loaders. This commit does that.

Differential Revision: D40253037

fbshipit-source-id: e2d491937c12f701e05cf12547cf7eddb0ffb0b6
  • Loading branch information
gouthamuoc authored and facebook-github-bot committed Oct 24, 2022
commit d1ff7e145ec9ec838bd40121c56f8cd2e935dce9
4 changes: 2 additions & 2 deletions examples/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def main():
),
),
batch_size=args.batch_size,
num_workers=1,
num_workers=0,
pin_memory=True,
)
test_loader = torch.utils.data.DataLoader(
Expand All @@ -240,7 +240,7 @@ def main():
),
batch_size=args.test_batch_size,
shuffle=True,
num_workers=1,
num_workers=0,
pin_memory=True,
)
run_results = []
Expand Down
12 changes: 6 additions & 6 deletions examples/mnist_README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# First run
To run a basic training script without differential privacy:
```shell
python mnist.py --device=cpu --disable-dp --n=20 --lr=.1 -sr=0.004
python mnist.py --device=cpu --disable-dp --n=20 --lr=.1 -b=240
```
The first time the script runs, it attempts to download the MNIST dataset from http://yann.lecun.com and place it in `../mnist/MNIST/raw`. If you prefer a different location or your execution environment does not have access to the outside world, download and unpack the dataset yourself and pass the location as `--data-root=custom_dir_name`. The script will expect to find under `custom_dir_name/MNIST/processed` two files: `test.pt` (7.9 MB) and `training.pt` (47.5 MB).

Expand All @@ -21,7 +21,7 @@ Test set: Average loss: 0.0000, Accuracy: 9893/10000 (98.93%)

To train a differentially private model, run the following command:
```shell
python mnist.py --device=cpu -n=15 --lr=.25 --sigma=1.3 -c=1.5 -sr=0.004
python mnist.py --device=cpu -n=15 --lr=.25 --sigma=1.3 -c=1.5 -b=240
```
If the run is successful, expect to see
```
Expand All @@ -39,24 +39,24 @@ Test set: Average loss: 0.0004, Accuracy: 9486/10000 (94.86%)

**Baseline: no differential privacy**

Command: `--disable-dp --n=20 --lr=.1 -sr=0.004`
Command: `--disable-dp --n=20 --lr=.1 -b=240`

Result: accuracy averaged over 10 runs 98.94% ± 0.32%

**(6.86, 10<sup>-5</sup>)-DP**

Command: `-n=45 --lr=.25 --sigma=.7 -c=1.5 -sr=0.004`
Command: `-n=45 --lr=.25 --sigma=.7 -c=1.5 -b=240`

Result: accuracy averaged over 10 runs 97.09% ± 0.17%

**(2.91, 10<sup>-5</sup>)-DP**

Command: `-n 60 --lr=.15 --sigma=1.1 -c=1.0 -sr=0.004`
Command: `-n 60 --lr=.15 --sigma=1.1 -c=1.0 -b=240`

Result: accuracy averaged over 10 runs 96.78% ± 0.21%

**(1.16, 10<sup>-5</sup>)-DP**

Command: `-n=15 --lr=.25 --sigma=1.3 -c=1.5 -sr=0.004`
Command: `-n=15 --lr=.25 --sigma=1.3 -c=1.5 -b=240`

Result: accuracy averaged over 10 runs 94.63% ± 0.34%