# Running out of RAM using iterable datasets

**URL:** <https://discuss.huggingface.co/t/running-out-of-ram-using-iterable-datasets/169790>\
**Category:** Intermediate\
**Created:** [November 1, 2025, 5:27am UTC](https://discuss.huggingface.co/t/running-out-of-ram-using-iterable-datasets/169790 "2025-11-01T05:27:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anand095](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@anand095](https://discuss.huggingface.co/u/anand095)\
**Post date:** [November 1, 2025, 5:27am UTC](https://discuss.huggingface.co/t/running-out-of-ram-using-iterable-datasets/169790/1 "2025-11-01T05:27:23Z")

</div>

Trying to fine tune a wav2vec2 model for classification task on 3 labels, I am running out of memory in colab.

All my initializations are lazy and i cant understand why its taking so much space of RAM. My model is hardly 500 MBs and model training is being done on a batch size of 16.

```auto
hindi_ds = load_dataset("SPRINGLab/IndicVoices-R_Hindi",split="train",streaming=True)
tamil_ds=load_dataset("SPRINGLab/IndicVoices-R_Tamil",split="train",streaming=True)
bengali_ds=load_dataset("SPRINGLab/IndicVoices-R_Bengali",split="train",streaming=True)

small_hindi = hindi_ds.take(500)
small_tamil = tamil_ds.take(500)
small_bengali = bengali_ds.take(500)

small_bengali=small_bengali.map(add_lang) # function simply changed lang column dtype to int
small_hindi=small_hindi.map(add_lang) # function simply changed lang column dtype to int
small_tamil=small_tamil.map(add_lang) # function simply changed lang column dtype to int

ds=interleave_datasets([small_tamil,small_hindi,small_bengali])

ds=ds.cast_column("audio",Audio(sampling_rate=16000))

*All Lazy Initialisation Till Here. Shouldnt take much memory*

```

```auto
model_id="facebook/wav2vec2-base-960h"
extractor=Wav2Vec2FeatureExtractor.from_pretrained(model_id)

def feature_extractor(batch):
  audio_arrays=[example['array'] for example in batch["audio"]]
  inputs=extractor(audio_arrays,
                     sampling_rate=extractor.sampling_rate,
                     return_attention_mask=True,
                   return_tensors="pt",
                   padding=True,
                  max_length=160000,
                 truncation=True
                     )
  return inputs

ds_encoded=ds.map(feature_extractor,
                  remove_columns=cols_to_remove,
                  batched=True,
                  batch_size=50,
                  )
*For a batch size of 50, memory requirement would be approx (50X160000X2)bytes=16 MB

model=AutoModelForAudioClassification.from_pretrained(model_id,
                                                      num_labels=3
                                                      )

ds_encoded = ds_encoded.rename_column("lang", "label")

```

```auto
model_name="wave2vec2-base-960h"
training_args=TrainingArguments(
    f"{model_name}-finetuned-springlab-tamil-hindi-bengali",
    save_strategy='epoch',
    learning_rate=5e-5,
    per_device_train_batch_size=16,
    num_train_epochs=10,
    logging_strategy="epoch",
    fp16="True",
    max_steps=500
)

trainer = Trainer(
    model,
    training_args,
    train_dataset=ds_encoded,
    processing_class=feature_extractor,
)

trainer.train()

```

Can anyone please comment..

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [November 1, 2025, 8:05am UTC](https://discuss.huggingface.co/t/running-out-of-ram-using-iterable-datasets/169790/2 "2025-11-01T08:05:42Z")

</div>

For [datasets using audio, `.map` consumes a significant amount of RAM, so that’s likely the main cause](https://huggingface.co/datasets/John6666/forum2/blob/main/ram_explode_wav_ds_1.md).

Colab CPU has considerably less RAM, but the fixed path in the script within the markdown barely managed to run without an OOM error…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [November 2, 2025, 8:34am UTC](https://discuss.huggingface.co/t/running-out-of-ram-using-iterable-datasets/169790/3 "2025-11-02T08:34:42Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
