|

楼主 |
发表于 2024-11-3 10:33:10
|
显示全部楼层
- Training Start!
- ====================================================================================================
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
-   0%
-  0/229 [00:00<?, ?it/s]
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- /tmp/ipykernel_31/152112840.py:32: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
- 'token_type_ids':torch.tensor(encoded_dict['token_type_ids'],dtype=torch.long).unsqueeze(dim=0)}
- ---------------------------------------------------------------------------
- KeyError Traceback (most recent call last)
- Cell In[58], line 4
- 1 print('Training Start!')
- 2 print('=' * 100)
- ----> 4 train(model,
- 5 device,
- 6 train_dataloader,
- 7 valid_dataloader,
- 8 CFG.epochs,
- 9 loss_fn,
- 10 optimizer,
- 11 metric)
- 13 del model,train_dataloader, valid_dataloader
- 14 gc.collect()
- Cell In[39], line 17, in train(model, device, train_dataloader, valid_dataloader, epochs, loss_fn, optimizer, metric)
- 14 train_step = 0
- 15 pbar = tqdm(train_dataloader)#tqdm参数是一个iterable
- ---> 17 for batch in pbar: # you can also write like "for batch in tqdm(train_dataloader"
- 18 optimizer.zero_grad() # initialize
- 19 train_step += 1
- File /opt/conda/lib/python3.10/site-packages/tqdm/notebook.py:250, in tqdm_notebook.__iter__(self)
- 248 try:
- 249 it = super().__iter__()
- --> 250 for obj in it:
- 251 # return super(tqdm...) will not catch exception
- 252 yield obj
- 253 # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
- File /opt/conda/lib/python3.10/site-packages/tqdm/std.py:1181, in tqdm.__iter__(self)
- 1178 time = self._time
- 1180 try:
- -> 1181 for obj in iterable:
- 1182 yield obj
- 1183 # Update and possibly print the progressbar.
- 1184 # Note: does not call self.update(1) for speed optimisation.
- File /opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py:630, in _BaseDataLoaderIter.__next__(self)
- 627 if self._sampler_iter is None:
- 628 # TODO(https://github.com/pytorch/pytorch/issues/76750)
- 629 self._reset() # type: ignore[call-arg]
- --> 630 data = self._next_data()
- 631 self._num_yielded += 1
- 632 if self._dataset_kind == _DatasetKind.Iterable and \
- 633 self._IterableDataset_len_called is not None and \
- 634 self._num_yielded > self._IterableDataset_len_called:
- File /opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py:1344, in _MultiProcessingDataLoaderIter._next_data(self)
- 1342 else:
- 1343 del self._task_info[idx]
- -> 1344 return self._process_data(data)
- File /opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py:1370, in _MultiProcessingDataLoaderIter._process_data(self, data)
- 1368 self._try_put_index()
- 1369 if isinstance(data, ExceptionWrapper):
- -> 1370 data.reraise()
- 1371 return data
- File /opt/conda/lib/python3.10/site-packages/torch/_utils.py:706, in ExceptionWrapper.reraise(self)
- 702 except TypeError:
- 703 # If the exception takes multiple arguments, don't try to
- 704 # instantiate since we don't know how to
- 705 raise RuntimeError(msg) from None
- --> 706 raise exception
- KeyError: Caught KeyError in DataLoader worker process 0.
- Original Traceback (most recent call last):
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc
- return self._engine.get_loc(casted_key)
- File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc
- File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc
- File "pandas/_libs/hashtable_class_helper.pxi", line 2606, in pandas._libs.hashtable.Int64HashTable.get_item
- File "pandas/_libs/hashtable_class_helper.pxi", line 2630, in pandas._libs.hashtable.Int64HashTable.get_item
- KeyError: 1287
- The above exception was the direct cause of the following exception:
- Traceback (most recent call last):
- File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 309, in _worker_loop
- data = fetcher.fetch(index) # type: ignore[possibly-undefined]
- File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
- data = [self.dataset[idx] for idx in possibly_batched_index]
- File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 52, in <listcomp>
- data = [self.dataset[idx] for idx in possibly_batched_index]
- File "/tmp/ipykernel_31/152112840.py", line 15, in __getitem__
- text = self.df.loc[idx]['cleaned'] # extracting text from each row
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexing.py", line 1191, in __getitem__
- return self._getitem_axis(maybe_callable, axis=axis)
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexing.py", line 1431, in _getitem_axis
- return self._get_label(key, axis=axis)
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexing.py", line 1381, in _get_label
- return self.obj.xs(label, axis=axis)
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/generic.py", line 4301, in xs
- loc = index.get_loc(key)
- File "/opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc
- raise KeyError(key) from err
- KeyError: 1287
复制代码
报错如上 |
|