We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unusual error on lightly-1.2.12
Getting this error:

```
Epoch 19: 100% 430/430 [17:42<00:00,  2.47s/it, loss=2.05, v_num=0]
Best model is stored at: /content/lightly_outputs/2022-04-04/12-01-48/lightly_epoch_18.ckpt
########## Starting to embed your dataset.

Error executing job with overrides: ['token=min', 'dataset_id=mine', 'input_dir=/content/drive/MyDrive/data/mine/', 'trainer.max_epochs=20']
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/lightly/cli/lightly_cli.py", line 114, in lightly_cli
    return _lightly_cli(cfg)
  File "/usr/local/lib/python3.7/dist-packages/lightly/cli/lightly_cli.py", line 60, in _lightly_cli
    embeddings = _embed_cli(cfg, is_cli_call)
  File "/usr/local/lib/python3.7/dist-packages/lightly/cli/embed_cli.py", line 83, in _embed_cli
    embeddings, labels, filenames = encoder.embed(dataloader, device=device)
  File "/usr/local/lib/python3.7/dist-packages/lightly/embedding/embedding.py", line 113, in embed
    total=len(dataloader.dataset),
AttributeError: 'BackgroundGenerator' object has no attribute 'dataset'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
```

There are jpgs in `/content/drive/MyDrive/data/mine/`
Token/dataset_ide correct

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lightly/embedding/embedding.py`
Content:
```
1 """ Embedding Strategies """
2 
3 # Copyright (c) 2020. Lightly AG and its affiliates.
4 # All Rights Reserved
5 
6 import time
7 from typing import List, Union, Tuple
8 
9 import numpy as np
10 import torch
11 import lightly
12 from lightly.embedding._base import BaseEmbedding
13 from tqdm import tqdm
14 
15 from lightly.utils.reordering import sort_items_by_keys
16 
17 if lightly._is_prefetch_generator_available():
18     from prefetch_generator import BackgroundGenerator
19 
20 
21 class SelfSupervisedEmbedding(BaseEmbedding):
22     """Implementation of self-supervised embedding models.
23 
24     Implements an embedding strategy based on self-supervised learning. A
25     model backbone, self-supervised criterion, optimizer, and dataloader are
26     passed to the constructor. The embedding itself is a pytorch-lightning
27     module.
28 
29     The implementation is based on contrastive learning.
30 
31     * SimCLR: https://arxiv.org/abs/2002.05709
32     * MoCo: https://arxiv.org/abs/1911.05722
33     * SimSiam: https://arxiv.org/abs/2011.10566
34 
35     Attributes:
36         model:
37             A backbone convolutional network with a projection head.
38         criterion:
39             A contrastive loss function.
40         optimizer:
41             A PyTorch optimizer.
42         dataloader:
43             A torchvision dataloader.
44         scheduler:
45             A PyTorch learning rate scheduler.
46 
47     Examples:
48         >>> # define a model, criterion, optimizer, and dataloader above
49         >>> import lightly.embedding as embedding
50         >>> encoder = SelfSupervisedEmbedding(
51         >>>     model,
52         >>>     criterion,
53         >>>     optimizer,
54         >>>     dataloader,
55         >>> )
56         >>> # train the self-supervised embedding with default settings
57         >>> encoder.train_embedding()
58         >>> # pass pytorch-lightning trainer arguments as kwargs
59         >>> encoder.train_embedding(max_epochs=10)
60 
61     """
62 
63     def __init__(
64         self,
65         model: torch.nn.Module,
66         criterion: torch.nn.Module,
67         optimizer: torch.optim.Optimizer,
68         dataloader: torch.utils.data.DataLoader,
69         scheduler=None,
70     ):
71 
72         super(SelfSupervisedEmbedding, self).__init__(
73             model, criterion, optimizer, dataloader, scheduler
74         )
75 
76     def embed(self,
77               dataloader: torch.utils.data.DataLoader,
78               device: torch.device = None
79     ) -> Tuple[np.ndarray, np.ndarray, List[str]]:
80         """Embeds images in a vector space.
81 
82         Args:
83             dataloader:
84                 A PyTorch dataloader.
85             device:
86                 Selected device (`cpu`, `cuda`, see PyTorch documentation)
87 
88         Returns:
89             Tuple of (embeddings, labels, filenames) ordered by the
90             samples in the dataset of the dataloader.
91                 embeddings:
92                     Embedding of shape (n_samples, embedding_feature_size).
93                     One embedding for each sample.
94                 labels:
95                     Labels of shape (n_samples, ).
96                 filenames:
97                     The filenames from dataloader.dataset.get_filenames().
98 
99 
100         Examples:
101             >>> # embed images in vector space
102             >>> embeddings, labels, fnames = encoder.embed(dataloader)
103 
104         """
105 
106         self.model.eval()
107         embeddings, labels, filenames = None, None, []
108 
109         if lightly._is_prefetch_generator_available():
110             dataloader = BackgroundGenerator(dataloader, max_prefetch=3)
111         
112         pbar = tqdm(
113             total=len(dataloader.dataset),
114             unit='imgs'
115         )
116 
117         efficiency = 0.0
118         embeddings = []
119         labels = []
120         with torch.no_grad():
121 
122             start_timepoint = time.time()
123             for (image_batch, label_batch, filename_batch) in dataloader:
124 
125                 batch_size = image_batch.shape[0]
126 
127                 # the following 2 lines are needed to prevent a file handler leak,
128                 # see https://github.com/lightly-ai/lightly/pull/676
129                 image_batch = image_batch.to(device)
130                 label_batch = label_batch.clone()
131 
132                 filenames += [*filename_batch]
133 
134                 prepared_timepoint = time.time()
135 
136                 embedding_batch = self.model.backbone(image_batch)
137                 embedding_batch = embedding_batch.detach().reshape(batch_size, -1)
138 
139                 embeddings.append(embedding_batch)
140                 labels.append(label_batch)
141 
142                 finished_timepoint = time.time()
143 
144                 data_loading_time = prepared_timepoint - start_timepoint
145                 inference_time = finished_timepoint - prepared_timepoint
146                 total_batch_time = data_loading_time + inference_time
147 
148                 efficiency = inference_time / total_batch_time
149                 pbar.set_description("Compute efficiency: {:.2f}".format(efficiency))
150                 start_timepoint = time.time()
151 
152                 pbar.update(batch_size)
153 
154             embeddings = torch.cat(embeddings, 0)
155             labels = torch.cat(labels, 0)
156 
157             embeddings = embeddings.cpu().numpy()
158             labels = labels.cpu().numpy()
159 
160         sorted_filenames = dataloader.dataset.get_filenames()
161         sorted_embeddings = sort_items_by_keys(
162             filenames, embeddings, sorted_filenames
163         )
164         sorted_labels = sort_items_by_keys(
165             filenames, labels, sorted_filenames
166         )
167         embeddings = np.stack(sorted_embeddings)
168         labels = np.stack(sorted_labels)
169 
170         return embeddings, labels, sorted_filenames
171
```
--- 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/lightly/embedding/embedding.py b/lightly/embedding/embedding.py
--- a/lightly/embedding/embedding.py
+++ b/lightly/embedding/embedding.py
@@ -106,11 +106,12 @@
         self.model.eval()
         embeddings, labels, filenames = None, None, []
 
+        dataset = dataloader.dataset
         if lightly._is_prefetch_generator_available():
             dataloader = BackgroundGenerator(dataloader, max_prefetch=3)
         
         pbar = tqdm(
-            total=len(dataloader.dataset),
+            total=len(dataset),
             unit='imgs'
         )
 
@@ -157,7 +158,7 @@
             embeddings = embeddings.cpu().numpy()
             labels = labels.cpu().numpy()
 
-        sorted_filenames = dataloader.dataset.get_filenames()
+        sorted_filenames = dataset.get_filenames()
         sorted_embeddings = sort_items_by_keys(
             filenames, embeddings, sorted_filenames
         )

{"golden_diff": "diff --git a/lightly/embedding/embedding.py b/lightly/embedding/embedding.py\n--- a/lightly/embedding/embedding.py\n+++ b/lightly/embedding/embedding.py\n@@ -106,11 +106,12 @@\n         self.model.eval()\n         embeddings, labels, filenames = None, None, []\n \n+        dataset = dataloader.dataset\n         if lightly._is_prefetch_generator_available():\n             dataloader = BackgroundGenerator(dataloader, max_prefetch=3)\n         \n         pbar = tqdm(\n-            total=len(dataloader.dataset),\n+            total=len(dataset),\n             unit='imgs'\n         )\n \n@@ -157,7 +158,7 @@\n             embeddings = embeddings.cpu().numpy()\n             labels = labels.cpu().numpy()\n \n-        sorted_filenames = dataloader.dataset.get_filenames()\n+        sorted_filenames = dataset.get_filenames()\n         sorted_embeddings = sort_items_by_keys(\n             filenames, embeddings, sorted_filenames\n         )\n", "issue": "Unusual error on lightly-1.2.12\nGetting this error:\r\n\r\n```\r\nEpoch 19: 100% 430/430 [17:42<00:00,  2.47s/it, loss=2.05, v_num=0]\r\nBest model is stored at: /content/lightly_outputs/2022-04-04/12-01-48/lightly_epoch_18.ckpt\r\n########## Starting to embed your dataset.\r\n\r\nError executing job with overrides: ['token=min', 'dataset_id=mine', 'input_dir=/content/drive/MyDrive/data/mine/', 'trainer.max_epochs=20']\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.7/dist-packages/lightly/cli/lightly_cli.py\", line 114, in lightly_cli\r\n    return _lightly_cli(cfg)\r\n  File \"/usr/local/lib/python3.7/dist-packages/lightly/cli/lightly_cli.py\", line 60, in _lightly_cli\r\n    embeddings = _embed_cli(cfg, is_cli_call)\r\n  File \"/usr/local/lib/python3.7/dist-packages/lightly/cli/embed_cli.py\", line 83, in _embed_cli\r\n    embeddings, labels, filenames = encoder.embed(dataloader, device=device)\r\n  File \"/usr/local/lib/python3.7/dist-packages/lightly/embedding/embedding.py\", line 113, in embed\r\n    total=len(dataloader.dataset),\r\nAttributeError: 'BackgroundGenerator' object has no attribute 'dataset'\r\n\r\nSet the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.\r\n```\r\n\r\nThere are jpgs in `/content/drive/MyDrive/data/mine/`\r\nToken/dataset_ide correct\n", "before_files": [{"content": "\"\"\" Embedding Strategies \"\"\"\n\n# Copyright (c) 2020. Lightly AG and its affiliates.\n# All Rights Reserved\n\nimport time\nfrom typing import List, Union, Tuple\n\nimport numpy as np\nimport torch\nimport lightly\nfrom lightly.embedding._base import BaseEmbedding\nfrom tqdm import tqdm\n\nfrom lightly.utils.reordering import sort_items_by_keys\n\nif lightly._is_prefetch_generator_available():\n    from prefetch_generator import BackgroundGenerator\n\n\nclass SelfSupervisedEmbedding(BaseEmbedding):\n    \"\"\"Implementation of self-supervised embedding models.\n\n    Implements an embedding strategy based on self-supervised learning. A\n    model backbone, self-supervised criterion, optimizer, and dataloader are\n    passed to the constructor. The embedding itself is a pytorch-lightning\n    module.\n\n    The implementation is based on contrastive learning.\n\n    * SimCLR: https://arxiv.org/abs/2002.05709\n    * MoCo: https://arxiv.org/abs/1911.05722\n    * SimSiam: https://arxiv.org/abs/2011.10566\n\n    Attributes:\n        model:\n            A backbone convolutional network with a projection head.\n        criterion:\n            A contrastive loss function.\n        optimizer:\n            A PyTorch optimizer.\n        dataloader:\n            A torchvision dataloader.\n        scheduler:\n            A PyTorch learning rate scheduler.\n\n    Examples:\n        >>> # define a model, criterion, optimizer, and dataloader above\n        >>> import lightly.embedding as embedding\n        >>> encoder = SelfSupervisedEmbedding(\n        >>>     model,\n        >>>     criterion,\n        >>>     optimizer,\n        >>>     dataloader,\n        >>> )\n        >>> #\u00a0train the self-supervised embedding with default settings\n        >>> encoder.train_embedding()\n        >>> #\u00a0pass pytorch-lightning trainer arguments as kwargs\n        >>> encoder.train_embedding(max_epochs=10)\n\n    \"\"\"\n\n    def __init__(\n        self,\n        model: torch.nn.Module,\n        criterion: torch.nn.Module,\n        optimizer: torch.optim.Optimizer,\n        dataloader: torch.utils.data.DataLoader,\n        scheduler=None,\n    ):\n\n        super(SelfSupervisedEmbedding, self).__init__(\n            model, criterion, optimizer, dataloader, scheduler\n        )\n\n    def embed(self,\n              dataloader: torch.utils.data.DataLoader,\n              device: torch.device = None\n    ) -> Tuple[np.ndarray, np.ndarray, List[str]]:\n        \"\"\"Embeds images in a vector space.\n\n        Args:\n            dataloader:\n                A PyTorch dataloader.\n            device:\n                Selected device (`cpu`, `cuda`, see PyTorch documentation)\n\n        Returns:\n            Tuple of (embeddings, labels, filenames) ordered by the\n            samples in the dataset of the dataloader.\n                embeddings:\n                    Embedding of shape (n_samples, embedding_feature_size).\n                    One embedding for each sample.\n                labels:\n                    Labels of shape (n_samples, ).\n                filenames:\n                    The filenames from dataloader.dataset.get_filenames().\n\n\n        Examples:\n            >>> # embed images in vector space\n            >>> embeddings, labels, fnames = encoder.embed(dataloader)\n\n        \"\"\"\n\n        self.model.eval()\n        embeddings, labels, filenames = None, None, []\n\n        if lightly._is_prefetch_generator_available():\n            dataloader = BackgroundGenerator(dataloader, max_prefetch=3)\n        \n        pbar = tqdm(\n            total=len(dataloader.dataset),\n            unit='imgs'\n        )\n\n        efficiency = 0.0\n        embeddings = []\n        labels = []\n        with torch.no_grad():\n\n            start_timepoint = time.time()\n            for (image_batch, label_batch, filename_batch) in dataloader:\n\n                batch_size = image_batch.shape[0]\n\n                # the following 2 lines are needed to prevent a file handler leak,\n                # see https://github.com/lightly-ai/lightly/pull/676\n                image_batch = image_batch.to(device)\n                label_batch = label_batch.clone()\n\n                filenames += [*filename_batch]\n\n                prepared_timepoint = time.time()\n\n                embedding_batch = self.model.backbone(image_batch)\n                embedding_batch = embedding_batch.detach().reshape(batch_size, -1)\n\n                embeddings.append(embedding_batch)\n                labels.append(label_batch)\n\n                finished_timepoint = time.time()\n\n                data_loading_time = prepared_timepoint - start_timepoint\n                inference_time = finished_timepoint - prepared_timepoint\n                total_batch_time = data_loading_time + inference_time\n\n                efficiency = inference_time / total_batch_time\n                pbar.set_description(\"Compute efficiency: {:.2f}\".format(efficiency))\n                start_timepoint = time.time()\n\n                pbar.update(batch_size)\n\n            embeddings = torch.cat(embeddings, 0)\n            labels = torch.cat(labels, 0)\n\n            embeddings = embeddings.cpu().numpy()\n            labels = labels.cpu().numpy()\n\n        sorted_filenames = dataloader.dataset.get_filenames()\n        sorted_embeddings = sort_items_by_keys(\n            filenames, embeddings, sorted_filenames\n        )\n        sorted_labels = sort_items_by_keys(\n            filenames, labels, sorted_filenames\n        )\n        embeddings = np.stack(sorted_embeddings)\n        labels = np.stack(sorted_labels)\n\n        return embeddings, labels, sorted_filenames\n", "path": "lightly/embedding/embedding.py"}], "after_files": [{"content": "\"\"\" Embedding Strategies \"\"\"\n\n# Copyright (c) 2020. Lightly AG and its affiliates.\n# All Rights Reserved\n\nimport time\nfrom typing import List, Union, Tuple\n\nimport numpy as np\nimport torch\nimport lightly\nfrom lightly.embedding._base import BaseEmbedding\nfrom tqdm import tqdm\n\nfrom lightly.utils.reordering import sort_items_by_keys\n\nif lightly._is_prefetch_generator_available():\n    from prefetch_generator import BackgroundGenerator\n\n\nclass SelfSupervisedEmbedding(BaseEmbedding):\n    \"\"\"Implementation of self-supervised embedding models.\n\n    Implements an embedding strategy based on self-supervised learning. A\n    model backbone, self-supervised criterion, optimizer, and dataloader are\n    passed to the constructor. The embedding itself is a pytorch-lightning\n    module.\n\n    The implementation is based on contrastive learning.\n\n    * SimCLR: https://arxiv.org/abs/2002.05709\n    * MoCo: https://arxiv.org/abs/1911.05722\n    * SimSiam: https://arxiv.org/abs/2011.10566\n\n    Attributes:\n        model:\n            A backbone convolutional network with a projection head.\n        criterion:\n            A contrastive loss function.\n        optimizer:\n            A PyTorch optimizer.\n        dataloader:\n            A torchvision dataloader.\n        scheduler:\n            A PyTorch learning rate scheduler.\n\n    Examples:\n        >>> # define a model, criterion, optimizer, and dataloader above\n        >>> import lightly.embedding as embedding\n        >>> encoder = SelfSupervisedEmbedding(\n        >>>     model,\n        >>>     criterion,\n        >>>     optimizer,\n        >>>     dataloader,\n        >>> )\n        >>> #\u00a0train the self-supervised embedding with default settings\n        >>> encoder.train_embedding()\n        >>> #\u00a0pass pytorch-lightning trainer arguments as kwargs\n        >>> encoder.train_embedding(max_epochs=10)\n\n    \"\"\"\n\n    def __init__(\n        self,\n        model: torch.nn.Module,\n        criterion: torch.nn.Module,\n        optimizer: torch.optim.Optimizer,\n        dataloader: torch.utils.data.DataLoader,\n        scheduler=None,\n    ):\n\n        super(SelfSupervisedEmbedding, self).__init__(\n            model, criterion, optimizer, dataloader, scheduler\n        )\n\n    def embed(self,\n              dataloader: torch.utils.data.DataLoader,\n              device: torch.device = None\n    ) -> Tuple[np.ndarray, np.ndarray, List[str]]:\n        \"\"\"Embeds images in a vector space.\n\n        Args:\n            dataloader:\n                A PyTorch dataloader.\n            device:\n                Selected device (`cpu`, `cuda`, see PyTorch documentation)\n\n        Returns:\n            Tuple of (embeddings, labels, filenames) ordered by the\n            samples in the dataset of the dataloader.\n                embeddings:\n                    Embedding of shape (n_samples, embedding_feature_size).\n                    One embedding for each sample.\n                labels:\n                    Labels of shape (n_samples, ).\n                filenames:\n                    The filenames from dataloader.dataset.get_filenames().\n\n\n        Examples:\n            >>> # embed images in vector space\n            >>> embeddings, labels, fnames = encoder.embed(dataloader)\n\n        \"\"\"\n\n        self.model.eval()\n        embeddings, labels, filenames = None, None, []\n\n        dataset = dataloader.dataset\n        if lightly._is_prefetch_generator_available():\n            dataloader = BackgroundGenerator(dataloader, max_prefetch=3)\n        \n        pbar = tqdm(\n            total=len(dataset),\n            unit='imgs'\n        )\n\n        efficiency = 0.0\n        embeddings = []\n        labels = []\n        with torch.no_grad():\n\n            start_timepoint = time.time()\n            for (image_batch, label_batch, filename_batch) in dataloader:\n\n                batch_size = image_batch.shape[0]\n\n                # the following 2 lines are needed to prevent a file handler leak,\n                # see https://github.com/lightly-ai/lightly/pull/676\n                image_batch = image_batch.to(device)\n                label_batch = label_batch.clone()\n\n                filenames += [*filename_batch]\n\n                prepared_timepoint = time.time()\n\n                embedding_batch = self.model.backbone(image_batch)\n                embedding_batch = embedding_batch.detach().reshape(batch_size, -1)\n\n                embeddings.append(embedding_batch)\n                labels.append(label_batch)\n\n                finished_timepoint = time.time()\n\n                data_loading_time = prepared_timepoint - start_timepoint\n                inference_time = finished_timepoint - prepared_timepoint\n                total_batch_time = data_loading_time + inference_time\n\n                efficiency = inference_time / total_batch_time\n                pbar.set_description(\"Compute efficiency: {:.2f}\".format(efficiency))\n                start_timepoint = time.time()\n\n                pbar.update(batch_size)\n\n            embeddings = torch.cat(embeddings, 0)\n            labels = torch.cat(labels, 0)\n\n            embeddings = embeddings.cpu().numpy()\n            labels = labels.cpu().numpy()\n\n        sorted_filenames = dataset.get_filenames()\n        sorted_embeddings = sort_items_by_keys(\n            filenames, embeddings, sorted_filenames\n        )\n        sorted_labels = sort_items_by_keys(\n            filenames, labels, sorted_filenames\n        )\n        embeddings = np.stack(sorted_embeddings)\n        labels = np.stack(sorted_labels)\n\n        return embeddings, labels, sorted_filenames\n", "path": "lightly/embedding/embedding.py"}]}