prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Typo
  https://github.com/pytorch/examples/blob/4db11160c21d0e26634ca1fcb94a73ad8d870ba7/snli/train.py#L122
  
  `validation` instead of `valiation`
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `snli/train.py`
  Content:
  ```
  1 import os
  2 import time
  3 import glob
  4 
  5 import torch
  6 import torch.optim as O
  7 import torch.nn as nn
  8 
  9 from torchtext import data
  10 from torchtext import datasets
  11 
  12 from model import SNLIClassifier
  13 from util import get_args, makedirs
  14 
  15 
  16 args = get_args()
  17 if torch.cuda.is_available():
  18     torch.cuda.set_device(args.gpu)
  19     device = torch.device('cuda:{}'.format(args.gpu))
  20 else:
  21     device = torch.device('cpu')
  22 
  23 inputs = data.Field(lower=args.lower, tokenize='spacy')
  24 answers = data.Field(sequential=False)
  25 
  26 train, dev, test = datasets.SNLI.splits(inputs, answers)
  27 
  28 inputs.build_vocab(train, dev, test)
  29 if args.word_vectors:
  30     if os.path.isfile(args.vector_cache):
  31         inputs.vocab.vectors = torch.load(args.vector_cache)
  32     else:
  33         inputs.vocab.load_vectors(args.word_vectors)
  34         makedirs(os.path.dirname(args.vector_cache))
  35         torch.save(inputs.vocab.vectors, args.vector_cache)
  36 answers.build_vocab(train)
  37 
  38 train_iter, dev_iter, test_iter = data.BucketIterator.splits(
  39             (train, dev, test), batch_size=args.batch_size, device=device)
  40 
  41 config = args
  42 config.n_embed = len(inputs.vocab)
  43 config.d_out = len(answers.vocab)
  44 config.n_cells = config.n_layers
  45 
  46 # double the number of cells for bidirectional networks
  47 if config.birnn:
  48     config.n_cells *= 2
  49 
  50 if args.resume_snapshot:
  51     model = torch.load(args.resume_snapshot, map_location=device)
  52 else:
  53     model = SNLIClassifier(config)
  54     if args.word_vectors:
  55         model.embed.weight.data.copy_(inputs.vocab.vectors)
  56         model.to(device)
  57 
  58 criterion = nn.CrossEntropyLoss()
  59 opt = O.Adam(model.parameters(), lr=args.lr)
  60 
  61 iterations = 0
  62 start = time.time()
  63 best_dev_acc = -1
  64 header = '  Time Epoch Iteration Progress    (%Epoch)   Loss   Dev/Loss     Accuracy  Dev/Accuracy'
  65 dev_log_template = ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{:8.6f},{:12.4f},{:12.4f}'.split(','))
  66 log_template =     ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{},{:12.4f},{}'.split(','))
  67 makedirs(args.save_path)
  68 print(header)
  69 
  70 for epoch in range(args.epochs):
  71     train_iter.init_epoch()
  72     n_correct, n_total = 0, 0
  73     for batch_idx, batch in enumerate(train_iter):
  74 
  75         # switch model to training mode, clear gradient accumulators
  76         model.train(); opt.zero_grad()
  77 
  78         iterations += 1
  79 
  80         # forward pass
  81         answer = model(batch)
  82 
  83         # calculate accuracy of predictions in the current batch
  84         n_correct += (torch.max(answer, 1)[1].view(batch.label.size()) == batch.label).sum().item()
  85         n_total += batch.batch_size
  86         train_acc = 100. * n_correct/n_total
  87 
  88         # calculate loss of the network output with respect to training labels
  89         loss = criterion(answer, batch.label)
  90 
  91         # backpropagate and update optimizer learning rate
  92         loss.backward(); opt.step()
  93 
  94         # checkpoint model periodically
  95         if iterations % args.save_every == 0:
  96             snapshot_prefix = os.path.join(args.save_path, 'snapshot')
  97             snapshot_path = snapshot_prefix + '_acc_{:.4f}_loss_{:.6f}_iter_{}_model.pt'.format(train_acc, loss.item(), iterations)
  98             torch.save(model, snapshot_path)
  99             for f in glob.glob(snapshot_prefix + '*'):
  100                 if f != snapshot_path:
  101                     os.remove(f)
  102 
  103         # evaluate performance on validation set periodically
  104         if iterations % args.dev_every == 0:
  105 
  106             # switch model to evaluation mode
  107             model.eval(); dev_iter.init_epoch()
  108 
  109             # calculate accuracy on validation set
  110             n_dev_correct, dev_loss = 0, 0
  111             with torch.no_grad():
  112                 for dev_batch_idx, dev_batch in enumerate(dev_iter):
  113                      answer = model(dev_batch)
  114                      n_dev_correct += (torch.max(answer, 1)[1].view(dev_batch.label.size()) == dev_batch.label).sum().item()
  115                      dev_loss = criterion(answer, dev_batch.label)
  116             dev_acc = 100. * n_dev_correct / len(dev)
  117 
  118             print(dev_log_template.format(time.time()-start,
  119                 epoch, iterations, 1+batch_idx, len(train_iter),
  120                 100. * (1+batch_idx) / len(train_iter), loss.item(), dev_loss.item(), train_acc, dev_acc))
  121 
  122             # update best valiation set accuracy
  123             if dev_acc > best_dev_acc:
  124 
  125                 # found a model with better validation set accuracy
  126 
  127                 best_dev_acc = dev_acc
  128                 snapshot_prefix = os.path.join(args.save_path, 'best_snapshot')
  129                 snapshot_path = snapshot_prefix + '_devacc_{}_devloss_{}__iter_{}_model.pt'.format(dev_acc, dev_loss.item(), iterations)
  130 
  131                 # save model, delete previous 'best_snapshot' files
  132                 torch.save(model, snapshot_path)
  133                 for f in glob.glob(snapshot_prefix + '*'):
  134                     if f != snapshot_path:
  135                         os.remove(f)
  136 
  137         elif iterations % args.log_every == 0:
  138 
  139             # print progress message
  140             print(log_template.format(time.time()-start,
  141                 epoch, iterations, 1+batch_idx, len(train_iter),
  142                 100. * (1+batch_idx) / len(train_iter), loss.item(), ' '*8, n_correct/n_total*100, ' '*12))
  143         if args.dry_run:
  144             break
  145
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/snli/train.py b/snli/train.py
  --- a/snli/train.py
  +++ b/snli/train.py
  @@ -119,7 +119,7 @@
                   epoch, iterations, 1+batch_idx, len(train_iter),
                   100. * (1+batch_idx) / len(train_iter), loss.item(), dev_loss.item(), train_acc, dev_acc))
   
  -            # update best valiation set accuracy
  +            # update best validation set accuracy
               if dev_acc > best_dev_acc:
   
                   # found a model with better validation set accuracy
  
verification_info: {"golden_diff": "diff --git a/snli/train.py b/snli/train.py\n--- a/snli/train.py\n+++ b/snli/train.py\n@@ -119,7 +119,7 @@\n                 epoch, iterations, 1+batch_idx, len(train_iter),\n                 100. * (1+batch_idx) / len(train_iter), loss.item(), dev_loss.item(), train_acc, dev_acc))\n \n-            # update best valiation set accuracy\n+            # update best validation set accuracy\n             if dev_acc > best_dev_acc:\n \n                 # found a model with better validation set accuracy\n", "issue": "Typo\nhttps://github.com/pytorch/examples/blob/4db11160c21d0e26634ca1fcb94a73ad8d870ba7/snli/train.py#L122\r\n\r\n`validation` instead of `valiation`\n", "before_files": [{"content": "import os\nimport time\nimport glob\n\nimport torch\nimport torch.optim as O\nimport torch.nn as nn\n\nfrom torchtext import data\nfrom torchtext import datasets\n\nfrom model import SNLIClassifier\nfrom util import get_args, makedirs\n\n\nargs = get_args()\nif torch.cuda.is_available():\n    torch.cuda.set_device(args.gpu)\n    device = torch.device('cuda:{}'.format(args.gpu))\nelse:\n    device = torch.device('cpu')\n\ninputs = data.Field(lower=args.lower, tokenize='spacy')\nanswers = data.Field(sequential=False)\n\ntrain, dev, test = datasets.SNLI.splits(inputs, answers)\n\ninputs.build_vocab(train, dev, test)\nif args.word_vectors:\n    if os.path.isfile(args.vector_cache):\n        inputs.vocab.vectors = torch.load(args.vector_cache)\n    else:\n        inputs.vocab.load_vectors(args.word_vectors)\n        makedirs(os.path.dirname(args.vector_cache))\n        torch.save(inputs.vocab.vectors, args.vector_cache)\nanswers.build_vocab(train)\n\ntrain_iter, dev_iter, test_iter = data.BucketIterator.splits(\n            (train, dev, test), batch_size=args.batch_size, device=device)\n\nconfig = args\nconfig.n_embed = len(inputs.vocab)\nconfig.d_out = len(answers.vocab)\nconfig.n_cells = config.n_layers\n\n# double the number of cells for bidirectional networks\nif config.birnn:\n    config.n_cells *= 2\n\nif args.resume_snapshot:\n    model = torch.load(args.resume_snapshot, map_location=device)\nelse:\n    model = SNLIClassifier(config)\n    if args.word_vectors:\n        model.embed.weight.data.copy_(inputs.vocab.vectors)\n        model.to(device)\n\ncriterion = nn.CrossEntropyLoss()\nopt = O.Adam(model.parameters(), lr=args.lr)\n\niterations = 0\nstart = time.time()\nbest_dev_acc = -1\nheader = '  Time Epoch Iteration Progress    (%Epoch)   Loss   Dev/Loss     Accuracy  Dev/Accuracy'\ndev_log_template = ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{:8.6f},{:12.4f},{:12.4f}'.split(','))\nlog_template =     ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{},{:12.4f},{}'.split(','))\nmakedirs(args.save_path)\nprint(header)\n\nfor epoch in range(args.epochs):\n    train_iter.init_epoch()\n    n_correct, n_total = 0, 0\n    for batch_idx, batch in enumerate(train_iter):\n\n        # switch model to training mode, clear gradient accumulators\n        model.train(); opt.zero_grad()\n\n        iterations += 1\n\n        # forward pass\n        answer = model(batch)\n\n        # calculate accuracy of predictions in the current batch\n        n_correct += (torch.max(answer, 1)[1].view(batch.label.size()) == batch.label).sum().item()\n        n_total += batch.batch_size\n        train_acc = 100. * n_correct/n_total\n\n        # calculate loss of the network output with respect to training labels\n        loss = criterion(answer, batch.label)\n\n        # backpropagate and update optimizer learning rate\n        loss.backward(); opt.step()\n\n        # checkpoint model periodically\n        if iterations % args.save_every == 0:\n            snapshot_prefix = os.path.join(args.save_path, 'snapshot')\n            snapshot_path = snapshot_prefix + '_acc_{:.4f}_loss_{:.6f}_iter_{}_model.pt'.format(train_acc, loss.item(), iterations)\n            torch.save(model, snapshot_path)\n            for f in glob.glob(snapshot_prefix + '*'):\n                if f != snapshot_path:\n                    os.remove(f)\n\n        # evaluate performance on validation set periodically\n        if iterations % args.dev_every == 0:\n\n            # switch model to evaluation mode\n            model.eval(); dev_iter.init_epoch()\n\n            # calculate accuracy on validation set\n            n_dev_correct, dev_loss = 0, 0\n            with torch.no_grad():\n                for dev_batch_idx, dev_batch in enumerate(dev_iter):\n                     answer = model(dev_batch)\n                     n_dev_correct += (torch.max(answer, 1)[1].view(dev_batch.label.size()) == dev_batch.label).sum().item()\n                     dev_loss = criterion(answer, dev_batch.label)\n            dev_acc = 100. * n_dev_correct / len(dev)\n\n            print(dev_log_template.format(time.time()-start,\n                epoch, iterations, 1+batch_idx, len(train_iter),\n                100. * (1+batch_idx) / len(train_iter), loss.item(), dev_loss.item(), train_acc, dev_acc))\n\n            # update best valiation set accuracy\n            if dev_acc > best_dev_acc:\n\n                # found a model with better validation set accuracy\n\n                best_dev_acc = dev_acc\n                snapshot_prefix = os.path.join(args.save_path, 'best_snapshot')\n                snapshot_path = snapshot_prefix + '_devacc_{}_devloss_{}__iter_{}_model.pt'.format(dev_acc, dev_loss.item(), iterations)\n\n                # save model, delete previous 'best_snapshot' files\n                torch.save(model, snapshot_path)\n                for f in glob.glob(snapshot_prefix + '*'):\n                    if f != snapshot_path:\n                        os.remove(f)\n\n        elif iterations % args.log_every == 0:\n\n            # print progress message\n            print(log_template.format(time.time()-start,\n                epoch, iterations, 1+batch_idx, len(train_iter),\n                100. * (1+batch_idx) / len(train_iter), loss.item(), ' '*8, n_correct/n_total*100, ' '*12))\n        if args.dry_run:\n            break\n", "path": "snli/train.py"}], "after_files": [{"content": "import os\nimport time\nimport glob\n\nimport torch\nimport torch.optim as O\nimport torch.nn as nn\n\nfrom torchtext import data\nfrom torchtext import datasets\n\nfrom model import SNLIClassifier\nfrom util import get_args, makedirs\n\n\nargs = get_args()\nif torch.cuda.is_available():\n    torch.cuda.set_device(args.gpu)\n    device = torch.device('cuda:{}'.format(args.gpu))\nelse:\n    device = torch.device('cpu')\n\ninputs = data.Field(lower=args.lower, tokenize='spacy')\nanswers = data.Field(sequential=False)\n\ntrain, dev, test = datasets.SNLI.splits(inputs, answers)\n\ninputs.build_vocab(train, dev, test)\nif args.word_vectors:\n    if os.path.isfile(args.vector_cache):\n        inputs.vocab.vectors = torch.load(args.vector_cache)\n    else:\n        inputs.vocab.load_vectors(args.word_vectors)\n        makedirs(os.path.dirname(args.vector_cache))\n        torch.save(inputs.vocab.vectors, args.vector_cache)\nanswers.build_vocab(train)\n\ntrain_iter, dev_iter, test_iter = data.BucketIterator.splits(\n            (train, dev, test), batch_size=args.batch_size, device=device)\n\nconfig = args\nconfig.n_embed = len(inputs.vocab)\nconfig.d_out = len(answers.vocab)\nconfig.n_cells = config.n_layers\n\n# double the number of cells for bidirectional networks\nif config.birnn:\n    config.n_cells *= 2\n\nif args.resume_snapshot:\n    model = torch.load(args.resume_snapshot, map_location=device)\nelse:\n    model = SNLIClassifier(config)\n    if args.word_vectors:\n        model.embed.weight.data.copy_(inputs.vocab.vectors)\n        model.to(device)\n\ncriterion = nn.CrossEntropyLoss()\nopt = O.Adam(model.parameters(), lr=args.lr)\n\niterations = 0\nstart = time.time()\nbest_dev_acc = -1\nheader = '  Time Epoch Iteration Progress    (%Epoch)   Loss   Dev/Loss     Accuracy  Dev/Accuracy'\ndev_log_template = ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{:8.6f},{:12.4f},{:12.4f}'.split(','))\nlog_template =     ' '.join('{:>6.0f},{:>5.0f},{:>9.0f},{:>5.0f}/{:<5.0f} {:>7.0f}%,{:>8.6f},{},{:12.4f},{}'.split(','))\nmakedirs(args.save_path)\nprint(header)\n\nfor epoch in range(args.epochs):\n    train_iter.init_epoch()\n    n_correct, n_total = 0, 0\n    for batch_idx, batch in enumerate(train_iter):\n\n        # switch model to training mode, clear gradient accumulators\n        model.train(); opt.zero_grad()\n\n        iterations += 1\n\n        # forward pass\n        answer = model(batch)\n\n        # calculate accuracy of predictions in the current batch\n        n_correct += (torch.max(answer, 1)[1].view(batch.label.size()) == batch.label).sum().item()\n        n_total += batch.batch_size\n        train_acc = 100. * n_correct/n_total\n\n        # calculate loss of the network output with respect to training labels\n        loss = criterion(answer, batch.label)\n\n        # backpropagate and update optimizer learning rate\n        loss.backward(); opt.step()\n\n        # checkpoint model periodically\n        if iterations % args.save_every == 0:\n            snapshot_prefix = os.path.join(args.save_path, 'snapshot')\n            snapshot_path = snapshot_prefix + '_acc_{:.4f}_loss_{:.6f}_iter_{}_model.pt'.format(train_acc, loss.item(), iterations)\n            torch.save(model, snapshot_path)\n            for f in glob.glob(snapshot_prefix + '*'):\n                if f != snapshot_path:\n                    os.remove(f)\n\n        # evaluate performance on validation set periodically\n        if iterations % args.dev_every == 0:\n\n            # switch model to evaluation mode\n            model.eval(); dev_iter.init_epoch()\n\n            # calculate accuracy on validation set\n            n_dev_correct, dev_loss = 0, 0\n            with torch.no_grad():\n                for dev_batch_idx, dev_batch in enumerate(dev_iter):\n                     answer = model(dev_batch)\n                     n_dev_correct += (torch.max(answer, 1)[1].view(dev_batch.label.size()) == dev_batch.label).sum().item()\n                     dev_loss = criterion(answer, dev_batch.label)\n            dev_acc = 100. * n_dev_correct / len(dev)\n\n            print(dev_log_template.format(time.time()-start,\n                epoch, iterations, 1+batch_idx, len(train_iter),\n                100. * (1+batch_idx) / len(train_iter), loss.item(), dev_loss.item(), train_acc, dev_acc))\n\n            # update best validation set accuracy\n            if dev_acc > best_dev_acc:\n\n                # found a model with better validation set accuracy\n\n                best_dev_acc = dev_acc\n                snapshot_prefix = os.path.join(args.save_path, 'best_snapshot')\n                snapshot_path = snapshot_prefix + '_devacc_{}_devloss_{}__iter_{}_model.pt'.format(dev_acc, dev_loss.item(), iterations)\n\n                # save model, delete previous 'best_snapshot' files\n                torch.save(model, snapshot_path)\n                for f in glob.glob(snapshot_prefix + '*'):\n                    if f != snapshot_path:\n                        os.remove(f)\n\n        elif iterations % args.log_every == 0:\n\n            # print progress message\n            print(log_template.format(time.time()-start,\n                epoch, iterations, 1+batch_idx, len(train_iter),\n                100. * (1+batch_idx) / len(train_iter), loss.item(), ' '*8, n_correct/n_total*100, ' '*12))\n        if args.dry_run:\n            break\n", "path": "snli/train.py"}]}