Datasets: Caching processed dataset at wrong folder

Created on 18 Sep 2020  路  12Comments  路  Source: huggingface/datasets

Hi guys, I run this on my Colab (PRO):

from datasets import load_dataset
dataset = load_dataset('text', data_files='/content/corpus.txt', cache_dir='/content/drive/My Drive', split='train')

def encode(examples):
  return tokenizer(examples['text'], truncation=True, padding='max_length')

dataset = dataset.map(encode, batched=True)

The file is about 4 GB, so I cannot process it on the Colab HD because there is no enough space. So I decided to mount my Google Drive fs and do it on it.
The dataset is cached in the right place but by processing it (applying encode function) seems to use a different folder because Colab HD starts to grow and it crashes when it should be done in the Drive fs.

What gets me crazy, it prints it is processing/encoding the dataset in the right folder:

Testing the mapped function outputs
Testing finished, running the mapping function on the dataset
Caching processed dataset at /content/drive/My Drive/text/default-ad3e69d6242ee916/0.0.0/7e13bc0fa76783d4ef197f079dc8acfe54c3efda980f2c9adfab046ede2f0ff7/cache-b16341780a59747d.arrow
bug

All 12 comments

Thanks for reporting !
It uses a temporary file to write the data.
However it looks like the temporary file is not placed in the right directory during the processing

Well actually I just tested and the temporary file is placed in the same directory, so it should work as expected.
Which version of datasets are you using ?

It looks like a pyarrow issue with google colab.
For some reason this code increases the disk usage of google colab while it actually writes into google drive:

import pyarrow as pa

stream = pa.OSFile("/content/drive/My Drive/path/to/file.arrow", "wb")
writer = pa.RecordBatchStreamWriter(stream, schema=pa.schema({"text": pa.string()}))
writer.write_table(pa.Table.from_pydict({"text": ["a"*511 + "\n"] * ((1 << 30) // 512)}))  # 1GiB
writer.close()
stream.close()

Moreover if I rm the file on google drive, it frees disk space on google colab.

It looks like replacing pa.OSFile by open fixes it, I'm going to open a PR

Ok. Thank you so much!

Actually I did more tests it doesn't >.<
I'll let you know if I find a way to fix that

Actually I also have the issue when writing a regular text file

f = open("/content/drive/My Drive/path/to/file", "w")
f.write(("a"*511 + "\n") * ((1 << 30) // 512))  # 1GiB
f.close()

Is that supposed to happen ?

The code you wrote should write a 1GB file in the Google Drive folder. Doesn't it?

Yes it does, but the disk usage of google colab also increases by 1GB

I could check it and as you say as I write to te Drive disk the colab disk also increases...

To reproduce it:

!df -h | grep sda1

```python
f = open("/content/drive/My Drive/test_to_remove.txt", "w")
f.write(("a"511 + "\n") * ((1 << 30) // 512)) # 1GiB
f.write(("a"
511 + "\n") * ((1 << 30) // 512)) # 1GiB
f.close()

```bash
!ls -lh /content/drive/My\ Drive/test_to_remove.txt

!df -h | grep sda1

!rm -rf /content/drive/My\ Drive/test_to_remove.txt

Colab

Was this page helpful?
0 / 5 - 0 ratings

Related issues

elyase picture elyase  路  7Comments

jplu picture jplu  路  5Comments

Nouman97 picture Nouman97  路  4Comments

astariul picture astariul  路  3Comments

ratthachat picture ratthachat  路  6Comments