TIMIT Dataset not working with GPU
Opened by TheSeamau5 (closed)

## Describe the bug
I am working trying to use the TIMIT dataset in order to fine-tune Wav2Vec2 model and I am unable to load the "audio" column from the dataset when working with a GPU. 

I am working on Amazon Sagemaker Studio, on the Python 3 (PyTorch 1.8 Python 3.6 GPU Optimized) environment, with a single ml.g4dn.xlarge instance (corresponds to a Tesla T4 GPU). 

I don't know if the issue is GPU related or Python environment related because everything works when I work off of the CPU Optimized environment with a non-GPU instance. My code also works on Google Colab with a GPU instance. 

This issue is blocking because I cannot get the 'audio' column in any way due to this error, which means that I can't pass it to any functions. I later use the dataset.map function and that is where I originally noticed this error. 

## Steps to reproduce the bug
```python
from datasets import load_dataset

timit_train = load_dataset('timit_asr', split='train')
print(timit_train['audio'])
```

## Expected results
Expected to see inside the 'audio' column, which contains an 'array' nested field with the array data I actually need.

## Actual results

Traceback
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-ceeac555e921> in <module>
----> 1 timit_train['audio']

/opt/conda/lib/python3.6/site-packages/datasets/arrow_dataset.py in __getitem__(self, key)
   1917         """Can be used to index columns (by string names) or rows (by integer index or iterable of indices or bools)."""
   1918         return self._getitem(
-> 1919             key,
   1920         )
   1921 

/opt/conda/lib/python3.6/site-packages/datasets/arrow_dataset.py in _getitem(self, key, decoded, **kwargs)
   1902         pa_subtable = query_table(self._data, key, indices=self._indices if self._indices is not None else None)
   1903         formatted_output = format_table(
-> 1904             pa_subtable, key, formatter=formatter, format_columns=format_columns, output_all_columns=output_all_columns
   1905         )
   1906         return formatted_output

/opt/conda/lib/python3.6/site-packages/datasets/formatting/formatting.py in format_table(table, key, formatter, format_columns, output_all_columns)
    529     python_formatter = PythonFormatter(features=None)
    530     if format_columns is None:
--> 531         return formatter(pa_table, query_type=query_type)
    532     elif query_type == "column":
    533         if key in format_columns:

/opt/conda/lib/python3.6/site-packages/datasets/formatting/formatting.py in __call__(self, pa_table, query_type)
    280             return self.format_row(pa_table)
    281         elif query_type == "column":
--> 282             return self.format_column(pa_table)
    283         elif query_type == "batch":
    284             return self.format_batch(pa_table)

/opt/conda/lib/python3.6/site-packages/datasets/formatting/formatting.py in format_column(self, pa_table)
    315         column = self.python_arrow_extractor().extract_column(pa_table)
    316         if self.decoded:
--> 317             column = self.python_features_decoder.decode_column(column, pa_table.column_names[0])
    318         return column
    319 

/opt/conda/lib/python3.6/site-packages/datasets/formatting/formatting.py in decode_column(self, column, column_name)
    221 
    222     def decode_column(self, column: list, column_name: str) -> list:
--> 223         return self.features.decode_column(column, column_name) if self.features else column
    224 
    225     def decode_batch(self, batch: dict) -> dict:

/opt/conda/lib/python3.6/site-packages/datasets/features/features.py in decode_column(self, column, column_name)
   1337         return (
   1338             [self[column_name].decode_example(value) if value is not None else None for value in column]
-> 1339             if self._column_requires_decoding[column_name]
   1340             else column
   1341         )

/opt/conda/lib/python3.6/site-packages/datasets/features/features.py in <listcomp>(.0)
   1336         """
   1337         return (
-> 1338             [self[column_name].decode_example(value) if value is not None else None for value in column]
   1339             if self._column_requires_decoding[column_name]
   1340             else column

/opt/conda/lib/python3.6/site-packages/datasets/features/audio.py in decode_example(self, value)
     85             dict
     86         """
---> 87         path, file = (value["path"], BytesIO(value["bytes"])) if value["bytes"] is not None else (value["path"], None)
     88         if path is None and file is None:
     89             raise ValueError(f"An audio sample should have one of 'path' or 'bytes' but both are None in {value}.")

TypeError: string indices must be integers
```

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version: 1.18.0
- Platform: Linux-4.14.256-197.484.amzn2.x86_64-x86_64-with-debian-buster-sid
- Python version: 3.6.13
- PyArrow version: 6.0.1


Comments: Hi ! I think you should avoid calling `timit_train['audio']`. Indeed by doing so you're **loading all the audio column in memory**. This is problematic in your case because the TIMIT dataset is huge.

If you want to access the audio data of some samples, you should do this instead `timit_train[:10]["train"]` for example.

Other than that, I'm not sure why you get a `TypeError: string indices must be integers`, do you have a code snippet that reproduces the issue that you can share here ?

I get the same error when I try to do `timit_train[0]` or really any indexing into the whole thing. 

Really, that IS the code snippet that reproduces the issue. If you index into other fields like 'file' or whatever, it works. As soon as one of the fields you're looking into is 'audio', you get that issue. It's a weird issue and I suspect it's Sagemaker/environment related, maybe the mix of libraries and dependencies are not good. 


Example code snippet with issue. 
```python
from datasets import load_dataset

timit_train = load_dataset('timit_asr', split='train')
print(timit_train[0])
```

Ok I see ! From the error you got, it looks like the `value` encoded in the arrow file of the TIMIT dataset you loaded is a string instead of a dictionary with keys "path" and "bytes" but we don't support this since 1.18

Can you try regenerating the dataset with `load_dataset('timit_asr', download_mode="force_redownload")` please ? I think it should fix the issue.