ba4be087d5
Create PR to main with cherry-pick from release / cherry-pick (push) Failing after 0s
CICD NeMo / pre-flight (push) Failing after 0s
CICD NeMo / configure (push) Has been skipped
Build, validate, and release Neural Modules / pre-flight (push) Failing after 1s
CICD NeMo / code-linting (push) Has been skipped
Build, validate, and release Neural Modules / release (push) Has been skipped
Build, validate, and release Neural Modules / release-summary (push) Has been cancelled
CICD NeMo / cicd-test-container-build (push) Has been cancelled
CICD NeMo / cicd-import-tests (push) Has been cancelled
CICD NeMo / L0_Setup_Test_Data_And_Models (push) Has been cancelled
CICD NeMo / cicd-main-unit-tests (push) Has been cancelled
CICD NeMo / cicd-main-speech (push) Has been cancelled
CICD NeMo / Nemo_CICD_Test (push) Has been cancelled
CICD NeMo / Coverage (e2e) (push) Has been cancelled
CICD NeMo / Coverage (unit-test) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
CICD NeMo / cicd-wait-in-queue (push) Has been cancelled
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import torch
|
|
|
|
from nemo.utils import logging
|
|
|
|
|
|
class FallbackDataset(torch.utils.data.Dataset):
|
|
"""
|
|
FallbackDataset is a wrapper on an existing map-style ``torch.utils.data.Dataset``.
|
|
It's used to return the previous item (or batch, depending on Dataset) whenever
|
|
the underlying ``Dataset`` returns ``None``.
|
|
This is useful when ``Dataset`` returns a full batch (as e.g. Lhotse datasets typically do),
|
|
and wasn't able to read any of the items in that batch.
|
|
|
|
Example::
|
|
|
|
>>> dataset = AudioToTextLhotseDataset(...)
|
|
... dataset = FallbackDataset(dataset)
|
|
"""
|
|
|
|
def __init__(self, dataset):
|
|
self.dataset = dataset
|
|
self._fallback = None
|
|
|
|
def __getitem__(self, item):
|
|
ans = self.dataset[item]
|
|
if ans is None:
|
|
if self._fallback is None:
|
|
logging.warning(
|
|
f"FallbackDataset received None from {self.dataset} on the first call to __getitem__, "
|
|
f"and must return None instead of an actual batch."
|
|
f"This indicates an issue with data reading."
|
|
)
|
|
ans = self._fallback
|
|
self._fallback = ans
|
|
return ans
|
|
|
|
def __len__(self):
|
|
return len(self.dataset)
|