# Best practice for saving large datasets to a cloud storage

**URL:** <https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277>\
**Category:** 🤗Datasets\
**Created:** [October 11, 2022, 1:39pm UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277 "2022-10-11T13:39:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saied](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saied/32/29266_2.png) [@saied](https://discuss.huggingface.co/u/saied)\
**Post date:** [October 11, 2022, 1:39pm UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/1 "2022-10-11T13:39:57Z")

</div>

Hi,  
I wanted to combine multiple large datasets and do some processing on them. for example one of them is [OSCAR Dataset](https://huggingface.co/datasets/oscar-corpus/OSCAR-2201). I thought of loading this dataset on a VM(for example EC2) and then saving each record on cloud storage like S3 buckets. But for multiple large datasets(~200GB of text), this procedure will cost both money and time.  
I wanted to know if is there a better way to do this.  
Thanks

---

<div class="post-metadata">

**Author:** ![saied](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saied/32/29266_2.png) [@saied](https://discuss.huggingface.co/u/saied)\
**Post date:** [October 11, 2022, 3:18pm UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/2 "2022-10-11T15:18:34Z")

</div>

So with some search and testing, I found a solution that looks good so sharing it here:

# How to download/transfer HF dataset to S3 bucket

Imports:

```python
from botocore.session import Session
import s3fs
from datasets import load_dataset_builder

```

First enter your credentials(AWS Access Key ID, AWS Secret Access Key):

```python
storage_options = {"key": "XXX",

"secret": "XXX"}

```

Then instantiate a boto session

```python
s3_session = Session(profile="your_profile_name")

storage_options = {"session": s3_session}

```

_Heads UP!_  
to create profile name enter this command

```bash
aws configure --profile "your_profile_name"

```

After that create file system

```python
fs = s3fs.S3FileSystem(**storage_options)

```

and then download your data set in a bucket of S3:

```python
builder = load_dataset_builder("your dataset id")

output_dir = "s3://path/to/the/bucket/"

builder.download_and_prepare(output_dir, storage_options=storage_options, file_format="parquet")

```

Ref:  
[HF Cloud storage](https://huggingface.co/docs/datasets/filesystems)

---

<div class="post-metadata">

**Author:** ![chudotony](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/chudotony/32/34046_2.png) [@chudotony](https://discuss.huggingface.co/u/chudotony)\
**Post date:** [March 7, 2023, 10:58am UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/3 "2023-03-07T10:58:20Z")

</div>

Hi! I’m trying to work with this code from Datalore (jupyter notebook service like Colab), and have issues with AWS profile:

```auto
/usr/bin/sh: 1: aws: not found

```

Do you know how to fix it? Maybe I should set up my AWS profile or bucket somehow?

---

<div class="post-metadata">

**Author:** ![saied](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saied/32/29266_2.png) [@saied](https://discuss.huggingface.co/u/saied)\
**Post date:** [March 30, 2023, 1:06pm UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/4 "2023-03-30T13:06:51Z")

</div>

@chudotony Did you install `awscli` in your environment?

---

<div class="post-metadata">

**Author:** ![chudotony](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/chudotony/32/34046_2.png) [@chudotony](https://discuss.huggingface.co/u/chudotony)\
**Post date:** [April 13, 2023, 9:03am UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/6 "2023-04-13T09:03:08Z")

</div>

[  
chudotony](https://discuss.huggingface.co/u/chudotony)

[1m](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/5)

I tried it after your comment, but it didn’t help

---

<div class="post-metadata">

**Author:** ![aireenmei](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@aireenmei](https://discuss.huggingface.co/u/aireenmei)\
**Post date:** [April 3, 2024, 11:44pm UTC](https://discuss.huggingface.co/t/best-practice-for-saving-large-datasets-to-a-cloud-storage/24277/7 "2024-04-03T23:44:10Z")

</div>

What’s the best practice for GCS? I tried downloading allenai/c4/en with builder.download\_and\_prepare(), it is very slow and and gets stuck. I’ve tried several times.
