Skip to content

Commit 9ff6839

Browse files
Goutham Rajendranfacebook-github-bot
authored andcommitted
Fixed issue with missing argument in MNIST example (#520)
Summary: Pull Request resolved: #520 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. Reviewed By: ffuuugor Differential Revision: D40253037 fbshipit-source-id: 99984f8963a4efea6829d109bb81acff0e587c93
1 parent 70ec4ce commit 9ff6839

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

examples/mnist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def main():
224224
),
225225
),
226226
batch_size=args.batch_size,
227-
num_workers=1,
227+
num_workers=0,
228228
pin_memory=True,
229229
)
230230
test_loader = torch.utils.data.DataLoader(
@@ -240,7 +240,7 @@ def main():
240240
),
241241
batch_size=args.test_batch_size,
242242
shuffle=True,
243-
num_workers=1,
243+
num_workers=0,
244244
pin_memory=True,
245245
)
246246
run_results = []

examples/mnist_README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# First run
22
To run a basic training script without differential privacy:
33
```shell
4-
python mnist.py --device=cpu --disable-dp --n=20 --lr=.1 -sr=0.004
4+
python mnist.py --device=cpu --disable-dp --n=20 --lr=.1 -b=240
55
```
66
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).
77

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

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

4040
**Baseline: no differential privacy**
4141

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)