I have a dataset of 9 gigs of wav files for music synthesis, and to manage batches across different files i load each file into custom WavFileDataset which i then combine in ConcatDataset to use as a dataset for dataloader. Problems begin when i try to sample from dataloader, even with batch_size = 1 and length of sequences of 100 samples: ram gets quickly filled up to 21gb, stays there and then restarts the notebook session. It looks like the problem is in the fact that while sampling, dataloader tries to load an entire dataset into ram, since when i use just one file to create ConcatDataset, everything works fine. So, is that an intended behavior, and if it is, how do i get around it?
Some code:
WavFileDataset:
class WavFileDataset(Dataset):
  def __init__(self, file_path, seq_length):
    sequence = pydub.AudioSegment.from_file(file_path)
    sequence = sequence.set_channels(1)
    sequence = np.asarray(sequence.get_array_of_samples())
    self.length = len(sequence) - (seq_length + 1)
    self.seq_length = seq_length+1 #We will be using seq_length samples as a feature 
#and one sample as a label
    self.file_path = file_path
  def __len__(self):
    return self.length
  def __getitem__(self,idx):
    sequence = pydub.AudioSegment.from_file(self.file_path)
    sequence = sequence.set_channels(1)
    sequence = np.asarray(sequence.get_array_of_samples())
    seq = sequence[idx:idx+self.seq_length]
    seq = (seq / (1<<15))
    feature = seq[0:-1].astype('float32')
    label = seq[-1:len(seq)].astype('float32')

    return feature,label

Dataset construction code:
data_dir = r"./datasets/rammwav"
save_dir = r'/content/drive/My Drive/checkpoints/rammwav/model.tar'
files = [os.path.join(data_dir,f) for f in os.listdir(data_dir) if os.path.isfile(os.path.join(data_dir, f))]
#files = [files[0]] #Take one file to speed up dataset processing
datasets = []
files_count = len(files)
seq_length = 100
batch_size = 1
i = 1
print("Processing datasets...")
for file in files:
  datasets.append(WavFileDataset(file,seq_length))
  print_inline("Processed {}/{}".format(i,files_count))
  i += 1
print("\n Datasets processed")

model = LSTM(input_size = 1, hidden_layer_size = 1, output_size = 1, batch_size_ = batch_size).cuda()
loss_function = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

dataset = torch.utils.data.ConcatDataset(datasets)

data_loader = torch.utils.data.DataLoader(dataset,
                                   batch_size=batch_size,
                                   shuffle=True,
                                   num_workers=0,
                                   pin_memory=False,
                                   drop_last=True)