prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Replicability Issue
  Every time I run the same experiment (e.,g minimal_examples/neural_networks/autoencoder) on the same machine I got slightly different results. Since we set up the seed, this shouldn't happen. 
  
  </issue>
  <code>
  [start of recipes/TIMIT/ASR_CTC/experiment.py]
  1 #!/usr/bin/env python3
  2 import os
  3 import sys
  4 import torch
  5 import speechbrain as sb
  6 import speechbrain.data_io.wer as wer_io
  7 import speechbrain.utils.edit_distance as edit_distance
  8 from speechbrain.data_io.data_io import convert_index_to_lab
  9 from speechbrain.decoders.ctc import ctc_greedy_decode
  10 from speechbrain.decoders.decoders import undo_padding
  11 from speechbrain.utils.checkpoints import ckpt_recency
  12 from speechbrain.utils.train_logger import summarize_error_rate
  13 
  14 # This hack needed to import data preparation script from ..
  15 current_dir = os.path.dirname(os.path.abspath(__file__))
  16 sys.path.append(os.path.dirname(current_dir))
  17 from timit_prepare import TIMITPreparer  # noqa E402
  18 
  19 # Load hyperparameters file with command-line overrides
  20 params_file, overrides = sb.core.parse_arguments(sys.argv[1:])
  21 if "seed" in overrides:
  22     torch.manual_seed(overrides["seed"])
  23 with open(params_file) as fin:
  24     params = sb.yaml.load_extended_yaml(fin, overrides)
  25 
  26 # Create experiment directory
  27 sb.core.create_experiment_directory(
  28     experiment_directory=params.output_folder,
  29     params_to_save=params_file,
  30     overrides=overrides,
  31 )
  32 
  33 
  34 # Define training procedure
  35 class ASR(sb.core.Brain):
  36     def compute_forward(self, x, train_mode=True, init_params=False):
  37         ids, wavs, wav_lens = x
  38         wavs, wav_lens = wavs.to(params.device), wav_lens.to(params.device)
  39         if hasattr(params, "augmentation"):
  40             wavs = params.augmentation(wavs, wav_lens, init_params)
  41         feats = params.compute_features(wavs, init_params)
  42         feats = params.normalize(feats, wav_lens)
  43         out = params.model(feats, init_params)
  44         out = params.output(out, init_params)
  45         pout = params.log_softmax(out)
  46         return pout, wav_lens
  47 
  48     def compute_objectives(self, predictions, targets, train_mode=True):
  49         pout, pout_lens = predictions
  50         ids, phns, phn_lens = targets
  51         phns, phn_lens = phns.to(params.device), phn_lens.to(params.device)
  52         loss = params.compute_cost(pout, phns, [pout_lens, phn_lens])
  53 
  54         if not train_mode:
  55             ind2lab = params.train_loader.label_dict["phn"]["index2lab"]
  56             sequence = ctc_greedy_decode(pout, pout_lens, blank_id=-1)
  57             sequence = convert_index_to_lab(sequence, ind2lab)
  58             phns = undo_padding(phns, phn_lens)
  59             phns = convert_index_to_lab(phns, ind2lab)
  60             stats = edit_distance.wer_details_for_batch(
  61                 ids, phns, sequence, compute_alignments=True
  62             )
  63             stats = {"PER": stats}
  64             return loss, stats
  65 
  66         return loss
  67 
  68     def on_epoch_end(self, epoch, train_stats, valid_stats=None):
  69         per = summarize_error_rate(valid_stats["PER"])
  70         old_lr, new_lr = params.lr_annealing([params.optimizer], epoch, per)
  71         epoch_stats = {"epoch": epoch, "lr": old_lr}
  72         params.train_logger.log_stats(epoch_stats, train_stats, valid_stats)
  73 
  74         params.checkpointer.save_and_keep_only(
  75             meta={"PER": per},
  76             importance_keys=[ckpt_recency, lambda c: -c.meta["PER"]],
  77         )
  78 
  79 
  80 # Prepare data
  81 prepare = TIMITPreparer(
  82     data_folder=params.data_folder,
  83     splits=["train", "dev", "test"],
  84     save_folder=params.data_folder,
  85 )
  86 prepare()
  87 train_set = params.train_loader()
  88 valid_set = params.valid_loader()
  89 first_x, first_y = next(zip(*train_set))
  90 
  91 # Modules are passed to optimizer and have train/eval called on them
  92 modules = [params.model, params.output]
  93 if hasattr(params, "augmentation"):
  94     modules.append(params.augmentation)
  95 
  96 # Create brain object for training
  97 asr_brain = ASR(
  98     modules=modules, optimizer=params.optimizer, first_inputs=[first_x],
  99 )
  100 
  101 # Load latest checkpoint to resume training
  102 params.checkpointer.recover_if_possible()
  103 asr_brain.fit(params.epoch_counter, train_set, valid_set)
  104 
  105 # Load best checkpoint for evaluation
  106 params.checkpointer.recover_if_possible(lambda c: -c.meta["PER"])
  107 test_stats = asr_brain.evaluate(params.test_loader())
  108 params.train_logger.log_stats(
  109     stats_meta={"Epoch loaded": params.epoch_counter.current},
  110     test_stats=test_stats,
  111 )
  112 
  113 # Write alignments to file
  114 per_summary = edit_distance.wer_summary(test_stats["PER"])
  115 with open(params.wer_file, "w") as fo:
  116     wer_io.print_wer_summary(per_summary, fo)
  117     wer_io.print_alignments(test_stats["PER"], fo)
  118
  [end of recipes/TIMIT/ASR_CTC/experiment.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/recipes/TIMIT/ASR_CTC/experiment.py b/recipes/TIMIT/ASR_CTC/experiment.py
  --- a/recipes/TIMIT/ASR_CTC/experiment.py
  +++ b/recipes/TIMIT/ASR_CTC/experiment.py
  @@ -1,7 +1,6 @@
   #!/usr/bin/env python3
   import os
   import sys
  -import torch
   import speechbrain as sb
   import speechbrain.data_io.wer as wer_io
   import speechbrain.utils.edit_distance as edit_distance
  @@ -18,8 +17,6 @@
   
   # Load hyperparameters file with command-line overrides
   params_file, overrides = sb.core.parse_arguments(sys.argv[1:])
  -if "seed" in overrides:
  -    torch.manual_seed(overrides["seed"])
   with open(params_file) as fin:
       params = sb.yaml.load_extended_yaml(fin, overrides)
  
verification_info: {"golden_diff": "diff --git a/recipes/TIMIT/ASR_CTC/experiment.py b/recipes/TIMIT/ASR_CTC/experiment.py\n--- a/recipes/TIMIT/ASR_CTC/experiment.py\n+++ b/recipes/TIMIT/ASR_CTC/experiment.py\n@@ -1,7 +1,6 @@\n #!/usr/bin/env python3\n import os\n import sys\n-import torch\n import speechbrain as sb\n import speechbrain.data_io.wer as wer_io\n import speechbrain.utils.edit_distance as edit_distance\n@@ -18,8 +17,6 @@\n \n # Load hyperparameters file with command-line overrides\n params_file, overrides = sb.core.parse_arguments(sys.argv[1:])\n-if \"seed\" in overrides:\n-    torch.manual_seed(overrides[\"seed\"])\n with open(params_file) as fin:\n     params = sb.yaml.load_extended_yaml(fin, overrides)\n", "issue": "Replicability Issue\nEvery time I run the same experiment (e.,g minimal_examples/neural_networks/autoencoder) on the same machine I got slightly different results. Since we set up the seed, this shouldn't happen. \n", "before_files": [{"content": "#!/usr/bin/env python3\nimport os\nimport sys\nimport torch\nimport speechbrain as sb\nimport speechbrain.data_io.wer as wer_io\nimport speechbrain.utils.edit_distance as edit_distance\nfrom speechbrain.data_io.data_io import convert_index_to_lab\nfrom speechbrain.decoders.ctc import ctc_greedy_decode\nfrom speechbrain.decoders.decoders import undo_padding\nfrom speechbrain.utils.checkpoints import ckpt_recency\nfrom speechbrain.utils.train_logger import summarize_error_rate\n\n# This hack needed to import data preparation script from ..\ncurrent_dir = os.path.dirname(os.path.abspath(__file__))\nsys.path.append(os.path.dirname(current_dir))\nfrom timit_prepare import TIMITPreparer  # noqa E402\n\n# Load hyperparameters file with command-line overrides\nparams_file, overrides = sb.core.parse_arguments(sys.argv[1:])\nif \"seed\" in overrides:\n    torch.manual_seed(overrides[\"seed\"])\nwith open(params_file) as fin:\n    params = sb.yaml.load_extended_yaml(fin, overrides)\n\n# Create experiment directory\nsb.core.create_experiment_directory(\n    experiment_directory=params.output_folder,\n    params_to_save=params_file,\n    overrides=overrides,\n)\n\n\n# Define training procedure\nclass ASR(sb.core.Brain):\n    def compute_forward(self, x, train_mode=True, init_params=False):\n        ids, wavs, wav_lens = x\n        wavs, wav_lens = wavs.to(params.device), wav_lens.to(params.device)\n        if hasattr(params, \"augmentation\"):\n            wavs = params.augmentation(wavs, wav_lens, init_params)\n        feats = params.compute_features(wavs, init_params)\n        feats = params.normalize(feats, wav_lens)\n        out = params.model(feats, init_params)\n        out = params.output(out, init_params)\n        pout = params.log_softmax(out)\n        return pout, wav_lens\n\n    def compute_objectives(self, predictions, targets, train_mode=True):\n        pout, pout_lens = predictions\n        ids, phns, phn_lens = targets\n        phns, phn_lens = phns.to(params.device), phn_lens.to(params.device)\n        loss = params.compute_cost(pout, phns, [pout_lens, phn_lens])\n\n        if not train_mode:\n            ind2lab = params.train_loader.label_dict[\"phn\"][\"index2lab\"]\n            sequence = ctc_greedy_decode(pout, pout_lens, blank_id=-1)\n            sequence = convert_index_to_lab(sequence, ind2lab)\n            phns = undo_padding(phns, phn_lens)\n            phns = convert_index_to_lab(phns, ind2lab)\n            stats = edit_distance.wer_details_for_batch(\n                ids, phns, sequence, compute_alignments=True\n            )\n            stats = {\"PER\": stats}\n            return loss, stats\n\n        return loss\n\n    def on_epoch_end(self, epoch, train_stats, valid_stats=None):\n        per = summarize_error_rate(valid_stats[\"PER\"])\n        old_lr, new_lr = params.lr_annealing([params.optimizer], epoch, per)\n        epoch_stats = {\"epoch\": epoch, \"lr\": old_lr}\n        params.train_logger.log_stats(epoch_stats, train_stats, valid_stats)\n\n        params.checkpointer.save_and_keep_only(\n            meta={\"PER\": per},\n            importance_keys=[ckpt_recency, lambda c: -c.meta[\"PER\"]],\n        )\n\n\n# Prepare data\nprepare = TIMITPreparer(\n    data_folder=params.data_folder,\n    splits=[\"train\", \"dev\", \"test\"],\n    save_folder=params.data_folder,\n)\nprepare()\ntrain_set = params.train_loader()\nvalid_set = params.valid_loader()\nfirst_x, first_y = next(zip(*train_set))\n\n# Modules are passed to optimizer and have train/eval called on them\nmodules = [params.model, params.output]\nif hasattr(params, \"augmentation\"):\n    modules.append(params.augmentation)\n\n# Create brain object for training\nasr_brain = ASR(\n    modules=modules, optimizer=params.optimizer, first_inputs=[first_x],\n)\n\n# Load latest checkpoint to resume training\nparams.checkpointer.recover_if_possible()\nasr_brain.fit(params.epoch_counter, train_set, valid_set)\n\n# Load best checkpoint for evaluation\nparams.checkpointer.recover_if_possible(lambda c: -c.meta[\"PER\"])\ntest_stats = asr_brain.evaluate(params.test_loader())\nparams.train_logger.log_stats(\n    stats_meta={\"Epoch loaded\": params.epoch_counter.current},\n    test_stats=test_stats,\n)\n\n# Write alignments to file\nper_summary = edit_distance.wer_summary(test_stats[\"PER\"])\nwith open(params.wer_file, \"w\") as fo:\n    wer_io.print_wer_summary(per_summary, fo)\n    wer_io.print_alignments(test_stats[\"PER\"], fo)\n", "path": "recipes/TIMIT/ASR_CTC/experiment.py"}]}