We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Warning in `mnist.py`
Specifically, https://github.com/kymatio/kymatio/blob/289bc26551e92456ef7a48fbe83d48e157f7632c/examples/2d/mnist.py#L50 generates a warning saying that `size_average` will be deprecated and says to use `reduction='sum'` instead. Is this ok for us to do?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/2d/mnist.py`
Content:
```
1 """
2 Classification of handwritten digits
3 ====================================
4 
5 Based on pytorch example for MNIST
6 """
7 
8 
9 import torch.nn as nn
10 import torch.optim
11 from torchvision import datasets, transforms
12 import torch.nn.functional as F
13 from kymatio import Scattering2D
14 import kymatio.datasets as scattering_datasets
15 import kymatio
16 import torch
17 import argparse
18 import math
19 
20 class View(nn.Module):
21     def __init__(self, *args):
22         super(View, self).__init__()
23         self.shape = args
24 
25     def forward(self, x):
26         return x.view(-1,*self.shape)
27 
28 def train(model, device, train_loader, optimizer, epoch, scattering):
29     model.train()
30     for batch_idx, (data, target) in enumerate(train_loader):
31         data, target = data.to(device), target.to(device)
32         optimizer.zero_grad()
33         output = model(scattering(data))
34         loss = F.cross_entropy(output, target)
35         loss.backward()
36         optimizer.step()
37         if batch_idx % 50 == 0:
38             print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format(
39                 epoch, batch_idx * len(data), len(train_loader.dataset),
40                 100. * batch_idx / len(train_loader), loss.item()))
41 
42 def test(model, device, test_loader, scattering):
43     model.eval()
44     test_loss = 0
45     correct = 0
46     with torch.no_grad():
47         for data, target in test_loader:
48             data, target = data.to(device), target.to(device)
49             output = model(scattering(data))
50             test_loss += F.cross_entropy(output, target, size_average=False).item() # sum up batch loss
51             pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability
52             correct += pred.eq(target.view_as(pred)).sum().item()
53 
54     test_loss /= len(test_loader.dataset)
55     print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.2f}%)\n'.format(
56         test_loss, correct, len(test_loader.dataset),
57         100. * correct / len(test_loader.dataset)))
58 
59 def main():
60     """Train a simple Hybrid Scattering + CNN model on MNIST.
61 
62         Three models are demoed:
63         'linear' - scattering + linear model
64         'mlp' - scattering + MLP
65         'cnn' - scattering + CNN
66 
67         scattering 1st order can also be set by the mode
68         Scattering features are normalized by batch normalization.
69 
70         scatter + linear achieves 99.15% in 15 epochs
71         scatter + cnn achieves 99.3% in 15 epochs
72 
73     """
74     parser = argparse.ArgumentParser(description='MNIST scattering  + hybrid examples')
75     parser.add_argument('--mode', type=int, default=2,help='scattering 1st or 2nd order')
76     parser.add_argument('--classifier', type=str, default='linear',help='classifier model')
77     args = parser.parse_args()
78     assert(args.classifier in ['linear','mlp','cnn'])
79 
80     use_cuda = torch.cuda.is_available()
81     device = torch.device("cuda" if use_cuda else "cpu")
82 
83     if args.mode == 1:
84         scattering = Scattering2D(M=28, N=28, J=2,order2=False)
85         K = 17
86     else:
87         scattering = Scattering2D(M=28, N=28, J=2)
88         K = 81
89     if use_cuda:
90         scattering = scattering.cuda()
91 
92 
93 
94 
95     if args.classifier == 'cnn':
96         model = nn.Sequential(
97             View(K, 7, 7),
98             nn.BatchNorm2d(K),
99             nn.Conv2d(K, 64, 3,padding=1), nn.ReLU(),
100             View(64*7*7),
101             nn.Linear(64 * 7 * 7, 512), nn.ReLU(),
102             nn.Linear(512, 10)
103         ).to(device)
104 
105     elif args.classifier == 'mlp':
106         model = nn.Sequential(
107             View(K, 7, 7),
108             nn.BatchNorm2d(K),
109             View(K*7*7),
110             nn.Linear(K*7*7, 512), nn.ReLU(),
111             nn.Linear(512, 512), nn.ReLU(),
112             nn.Linear(512, 10)
113         )
114 
115     elif args.classifier == 'linear':
116         model = nn.Sequential(
117             View(K, 7, 7),
118             nn.BatchNorm2d(K),
119             View(K * 7 * 7),
120             nn.Linear(K * 7 * 7, 10)
121         )
122     else:
123         raise ValueError('Classifier should be cnn/mlp/linear')
124 
125     model.to(device)
126 
127     #initialize
128     for m in model.modules():
129         if isinstance(m, nn.Conv2d):
130             n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels
131             m.weight.data.normal_(0, 2./math.sqrt(n))
132             m.bias.data.zero_()
133         if isinstance(m, nn.Linear):
134             m.weight.data.normal_(0, 2./math.sqrt(m.in_features))
135             m.bias.data.zero_()
136 
137     # DataLoaders
138     if use_cuda:
139         num_workers = 4
140         pin_memory = True
141     else:
142         num_workers = None
143         pin_memory = False
144 
145     train_loader = torch.utils.data.DataLoader(
146         datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=True, download=True,
147                        transform=transforms.Compose([
148                            transforms.ToTensor(),
149                            transforms.Normalize((0.1307,), (0.3081,))
150                        ])),
151         batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)
152     test_loader = torch.utils.data.DataLoader(
153         datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=False, transform=transforms.Compose([
154             transforms.ToTensor(),
155             transforms.Normalize((0.1307,), (0.3081,))
156         ])),
157         batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)
158 
159     # Optimizer
160     optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9,
161                                 weight_decay=0.0005)
162 
163     for epoch in range(1, 16):
164         train( model, device, train_loader, optimizer, epoch, scattering)
165         test(model, device, test_loader, scattering)
166 
167 
168 if __name__ == '__main__':
169     main()
170
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/2d/mnist.py b/examples/2d/mnist.py
--- a/examples/2d/mnist.py
+++ b/examples/2d/mnist.py
@@ -47,7 +47,7 @@
         for data, target in test_loader:
             data, target = data.to(device), target.to(device)
             output = model(scattering(data))
-            test_loss += F.cross_entropy(output, target, size_average=False).item() # sum up batch loss
+            test_loss += F.cross_entropy(output, target, reduction='sum').item() # sum up batch loss
             pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability
             correct += pred.eq(target.view_as(pred)).sum().item()

{"golden_diff": "diff --git a/examples/2d/mnist.py b/examples/2d/mnist.py\n--- a/examples/2d/mnist.py\n+++ b/examples/2d/mnist.py\n@@ -47,7 +47,7 @@\n         for data, target in test_loader:\n             data, target = data.to(device), target.to(device)\n             output = model(scattering(data))\n-            test_loss += F.cross_entropy(output, target, size_average=False).item() # sum up batch loss\n+            test_loss += F.cross_entropy(output, target, reduction='sum').item() # sum up batch loss\n             pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability\n             correct += pred.eq(target.view_as(pred)).sum().item()\n", "issue": "Warning in `mnist.py`\nSpecifically, https://github.com/kymatio/kymatio/blob/289bc26551e92456ef7a48fbe83d48e157f7632c/examples/2d/mnist.py#L50 generates a warning saying that `size_average` will be deprecated and says to use `reduction='sum'` instead. Is this ok for us to do?\n", "before_files": [{"content": "\"\"\"\nClassification of handwritten digits\n====================================\n\nBased on pytorch example for MNIST\n\"\"\"\n\n\nimport torch.nn as nn\nimport torch.optim\nfrom torchvision import datasets, transforms\nimport torch.nn.functional as F\nfrom kymatio import Scattering2D\nimport kymatio.datasets as scattering_datasets\nimport kymatio\nimport torch\nimport argparse\nimport math\n\nclass View(nn.Module):\n    def __init__(self, *args):\n        super(View, self).__init__()\n        self.shape = args\n\n    def forward(self, x):\n        return x.view(-1,*self.shape)\n\ndef train(model, device, train_loader, optimizer, epoch, scattering):\n    model.train()\n    for batch_idx, (data, target) in enumerate(train_loader):\n        data, target = data.to(device), target.to(device)\n        optimizer.zero_grad()\n        output = model(scattering(data))\n        loss = F.cross_entropy(output, target)\n        loss.backward()\n        optimizer.step()\n        if batch_idx % 50 == 0:\n            print('Train Epoch: {} [{}/{} ({:.0f}%)]\\tLoss: {:.6f}'.format(\n                epoch, batch_idx * len(data), len(train_loader.dataset),\n                100. * batch_idx / len(train_loader), loss.item()))\n\ndef test(model, device, test_loader, scattering):\n    model.eval()\n    test_loss = 0\n    correct = 0\n    with torch.no_grad():\n        for data, target in test_loader:\n            data, target = data.to(device), target.to(device)\n            output = model(scattering(data))\n            test_loss += F.cross_entropy(output, target, size_average=False).item() # sum up batch loss\n            pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability\n            correct += pred.eq(target.view_as(pred)).sum().item()\n\n    test_loss /= len(test_loader.dataset)\n    print('\\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.2f}%)\\n'.format(\n        test_loss, correct, len(test_loader.dataset),\n        100. * correct / len(test_loader.dataset)))\n\ndef main():\n    \"\"\"Train a simple Hybrid Scattering + CNN model on MNIST.\n\n        Three models are demoed:\n        'linear' - scattering + linear model\n        'mlp' - scattering + MLP\n        'cnn' - scattering + CNN\n\n        scattering 1st order can also be set by the mode\n        Scattering features are normalized by batch normalization.\n\n        scatter + linear achieves 99.15% in 15 epochs\n        scatter + cnn achieves 99.3% in 15 epochs\n\n    \"\"\"\n    parser = argparse.ArgumentParser(description='MNIST scattering  + hybrid examples')\n    parser.add_argument('--mode', type=int, default=2,help='scattering 1st or 2nd order')\n    parser.add_argument('--classifier', type=str, default='linear',help='classifier model')\n    args = parser.parse_args()\n    assert(args.classifier in ['linear','mlp','cnn'])\n\n    use_cuda = torch.cuda.is_available()\n    device = torch.device(\"cuda\" if use_cuda else \"cpu\")\n\n    if args.mode == 1:\n        scattering = Scattering2D(M=28, N=28, J=2,order2=False)\n        K = 17\n    else:\n        scattering = Scattering2D(M=28, N=28, J=2)\n        K = 81\n    if use_cuda:\n        scattering = scattering.cuda()\n\n\n\n\n    if args.classifier == 'cnn':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            nn.Conv2d(K, 64, 3,padding=1), nn.ReLU(),\n            View(64*7*7),\n            nn.Linear(64 * 7 * 7, 512), nn.ReLU(),\n            nn.Linear(512, 10)\n        ).to(device)\n\n    elif args.classifier == 'mlp':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            View(K*7*7),\n            nn.Linear(K*7*7, 512), nn.ReLU(),\n            nn.Linear(512, 512), nn.ReLU(),\n            nn.Linear(512, 10)\n        )\n\n    elif args.classifier == 'linear':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            View(K * 7 * 7),\n            nn.Linear(K * 7 * 7, 10)\n        )\n    else:\n        raise ValueError('Classifier should be cnn/mlp/linear')\n\n    model.to(device)\n\n    #initialize\n    for m in model.modules():\n        if isinstance(m, nn.Conv2d):\n            n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels\n            m.weight.data.normal_(0, 2./math.sqrt(n))\n            m.bias.data.zero_()\n        if isinstance(m, nn.Linear):\n            m.weight.data.normal_(0, 2./math.sqrt(m.in_features))\n            m.bias.data.zero_()\n\n    # DataLoaders\n    if use_cuda:\n        num_workers = 4\n        pin_memory = True\n    else:\n        num_workers = None\n        pin_memory = False\n\n    train_loader = torch.utils.data.DataLoader(\n        datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=True, download=True,\n                       transform=transforms.Compose([\n                           transforms.ToTensor(),\n                           transforms.Normalize((0.1307,), (0.3081,))\n                       ])),\n        batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)\n    test_loader = torch.utils.data.DataLoader(\n        datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=False, transform=transforms.Compose([\n            transforms.ToTensor(),\n            transforms.Normalize((0.1307,), (0.3081,))\n        ])),\n        batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)\n\n    # Optimizer\n    optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9,\n                                weight_decay=0.0005)\n\n    for epoch in range(1, 16):\n        train( model, device, train_loader, optimizer, epoch, scattering)\n        test(model, device, test_loader, scattering)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "examples/2d/mnist.py"}], "after_files": [{"content": "\"\"\"\nClassification of handwritten digits\n====================================\n\nBased on pytorch example for MNIST\n\"\"\"\n\n\nimport torch.nn as nn\nimport torch.optim\nfrom torchvision import datasets, transforms\nimport torch.nn.functional as F\nfrom kymatio import Scattering2D\nimport kymatio.datasets as scattering_datasets\nimport kymatio\nimport torch\nimport argparse\nimport math\n\nclass View(nn.Module):\n    def __init__(self, *args):\n        super(View, self).__init__()\n        self.shape = args\n\n    def forward(self, x):\n        return x.view(-1,*self.shape)\n\ndef train(model, device, train_loader, optimizer, epoch, scattering):\n    model.train()\n    for batch_idx, (data, target) in enumerate(train_loader):\n        data, target = data.to(device), target.to(device)\n        optimizer.zero_grad()\n        output = model(scattering(data))\n        loss = F.cross_entropy(output, target)\n        loss.backward()\n        optimizer.step()\n        if batch_idx % 50 == 0:\n            print('Train Epoch: {} [{}/{} ({:.0f}%)]\\tLoss: {:.6f}'.format(\n                epoch, batch_idx * len(data), len(train_loader.dataset),\n                100. * batch_idx / len(train_loader), loss.item()))\n\ndef test(model, device, test_loader, scattering):\n    model.eval()\n    test_loss = 0\n    correct = 0\n    with torch.no_grad():\n        for data, target in test_loader:\n            data, target = data.to(device), target.to(device)\n            output = model(scattering(data))\n            test_loss += F.cross_entropy(output, target, reduction='sum').item() # sum up batch loss\n            pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability\n            correct += pred.eq(target.view_as(pred)).sum().item()\n\n    test_loss /= len(test_loader.dataset)\n    print('\\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.2f}%)\\n'.format(\n        test_loss, correct, len(test_loader.dataset),\n        100. * correct / len(test_loader.dataset)))\n\ndef main():\n    \"\"\"Train a simple Hybrid Scattering + CNN model on MNIST.\n\n        Three models are demoed:\n        'linear' - scattering + linear model\n        'mlp' - scattering + MLP\n        'cnn' - scattering + CNN\n\n        scattering 1st order can also be set by the mode\n        Scattering features are normalized by batch normalization.\n\n        scatter + linear achieves 99.15% in 15 epochs\n        scatter + cnn achieves 99.3% in 15 epochs\n\n    \"\"\"\n    parser = argparse.ArgumentParser(description='MNIST scattering  + hybrid examples')\n    parser.add_argument('--mode', type=int, default=2,help='scattering 1st or 2nd order')\n    parser.add_argument('--classifier', type=str, default='linear',help='classifier model')\n    args = parser.parse_args()\n    assert(args.classifier in ['linear','mlp','cnn'])\n\n    use_cuda = torch.cuda.is_available()\n    device = torch.device(\"cuda\" if use_cuda else \"cpu\")\n\n    if args.mode == 1:\n        scattering = Scattering2D(M=28, N=28, J=2,order2=False)\n        K = 17\n    else:\n        scattering = Scattering2D(M=28, N=28, J=2)\n        K = 81\n    if use_cuda:\n        scattering = scattering.cuda()\n\n\n\n\n    if args.classifier == 'cnn':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            nn.Conv2d(K, 64, 3,padding=1), nn.ReLU(),\n            View(64*7*7),\n            nn.Linear(64 * 7 * 7, 512), nn.ReLU(),\n            nn.Linear(512, 10)\n        ).to(device)\n\n    elif args.classifier == 'mlp':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            View(K*7*7),\n            nn.Linear(K*7*7, 512), nn.ReLU(),\n            nn.Linear(512, 512), nn.ReLU(),\n            nn.Linear(512, 10)\n        )\n\n    elif args.classifier == 'linear':\n        model = nn.Sequential(\n            View(K, 7, 7),\n            nn.BatchNorm2d(K),\n            View(K * 7 * 7),\n            nn.Linear(K * 7 * 7, 10)\n        )\n    else:\n        raise ValueError('Classifier should be cnn/mlp/linear')\n\n    model.to(device)\n\n    #initialize\n    for m in model.modules():\n        if isinstance(m, nn.Conv2d):\n            n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels\n            m.weight.data.normal_(0, 2./math.sqrt(n))\n            m.bias.data.zero_()\n        if isinstance(m, nn.Linear):\n            m.weight.data.normal_(0, 2./math.sqrt(m.in_features))\n            m.bias.data.zero_()\n\n    # DataLoaders\n    if use_cuda:\n        num_workers = 4\n        pin_memory = True\n    else:\n        num_workers = None\n        pin_memory = False\n\n    train_loader = torch.utils.data.DataLoader(\n        datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=True, download=True,\n                       transform=transforms.Compose([\n                           transforms.ToTensor(),\n                           transforms.Normalize((0.1307,), (0.3081,))\n                       ])),\n        batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)\n    test_loader = torch.utils.data.DataLoader(\n        datasets.MNIST(scattering_datasets.get_dataset_dir('MNIST'), train=False, transform=transforms.Compose([\n            transforms.ToTensor(),\n            transforms.Normalize((0.1307,), (0.3081,))\n        ])),\n        batch_size=128, shuffle=True, num_workers=num_workers, pin_memory=pin_memory)\n\n    # Optimizer\n    optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9,\n                                weight_decay=0.0005)\n\n    for epoch in range(1, 16):\n        train( model, device, train_loader, optimizer, epoch, scattering)\n        test(model, device, test_loader, scattering)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "examples/2d/mnist.py"}]}