max_open_streams with a multi-manifest config raises AttributeError: LazyNeMoIterator has no attribute to_shards
AttributeError: 'LazyNeMoIterator' object has no attribute 'to_shards' masks the friendly max_open_streams/metadata_only guard
Describe the bug
read_nemo_manifest() in nemo/collections/common/data/lhotse/cutset.py calls nemo_iter.to_shards() unconditionally whenever max_open_streams is set:
# nemo/collections/common/data/lhotse/cutset.py:1767-1777
# [optional] When we have a limit on the number of open streams,
# split the manifest to individual shards if applicable.
# This helps the multiplexing achieve closer data distribution
# to the one desired in spite of the limit.
if config.get("max_open_streams") is not None:
for subiter in nemo_iter.to_shards():
...But to_shards() is only implemented on LazyNeMoTarredIterator (nemo_adapters.py:639). A few lines earlier the same loop picks LazyNeMoIterator whenever is_tarred and not metadata_only is false:
# nemo/collections/common/data/lhotse/cutset.py:1740-1751
if is_tarred and not metadata_only:
nemo_iter = LazyNeMoTarredIterator(...)
else:
nemo_iter = LazyNeMoIterator(...)So the attribute access blows up before control ever reaches mux(), which contains a guard written for exactly this situation:
# nemo/collections/common/data/lhotse/cutset.py:1823
assert not force_finite, "max_open_streams and metadata_only/force_finite options are not compatible"Two configurations hit this:
metadata_only=true+max_open_streams— the user should see the actionable assert above, but gets a rawAttributeErrorinstead. This breaksscripts/speech_recognition/estimate_duration_bins.pyandscripts/speech_recognition/estimate_data_weights.py, which both forcemetadata_only, for any config that also setsmax_open_streams.- Non-tarred manifests +
max_open_streams(a normal training config, nometadata_only) — sameAttributeError, and here there is no guard at all; the option is simply unusable.
Both only affect the multi-manifest branch (manifest_filepath given as a list of lists / [path, weight] pairs). The group/input_cfg path already raises the friendly assert for case 1 (see the last snippet below), so read_nemo_manifest() is the outlier.
Steps/Code to reproduce bug
mkdir -p data
python - <<'EOF'
import json
for i in (1, 2):
with open(f"data/manifest_{i}.json", "w") as f:
for j in range(3):
f.write(json.dumps({"audio_filepath": f"audio_{i}_{j}.wav",
"duration": 1.0 + j,
"text": f"hello {i} {j}"}) + "\n")
EOF
touch data/audio_1.tar data/audio_2.tar
cat > input_cfg.yaml <<'EOF'
- type: nemo_tarred
manifest_filepath:
- - data/manifest_1.json
- - data/manifest_2.json
tarred_audio_filepaths:
- - data/audio_1.tar
- - data/audio_2.tar
max_open_streams: 4
EOF
python scripts/speech_recognition/estimate_duration_bins.py input_cfg=input_cfg.yaml -b 2Actual output:
Traceback (most recent call last):
File ".../scripts/speech_recognition/estimate_duration_bins.py", line 124, in <module>
main()
File ".../scripts/speech_recognition/estimate_duration_bins.py", line 86, in main
cuts, _ = read_cutset_from_config(config)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 139, in read_cutset_from_config
cuts, is_tarred = read_dataset_config(config)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 300, in read_dataset_config
cuts, is_tarred = parse_and_combine_datasets(config.input_cfg, propagate_attrs=propagate_attrs)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 632, in parse_and_combine_datasets
item_cuts, item_is_tarred = parse_group(item, next_propagate_attrs)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 313, in parse_group
cuts, is_tarred = parser_fn(grp_cfg)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 1772, in read_nemo_manifest
for subiter in nemo_iter.to_shards():
AttributeError: 'LazyNeMoIterator' object has no attribute 'to_shards'estimate_data_weights.py fails identically on the same YAML (it calls get_parser_fn(entry.type)(entry) under quick_iter_options, which sets metadata_only/force_finite):
python scripts/speech_recognition/estimate_data_weights.py input_cfg.yaml out.yaml
...
File ".../scripts/speech_recognition/estimate_data_weights.py", line 88, in count
iterable, is_tarred = get_parser_fn(entry.type)(entry)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 1772, in read_nemo_manifest
for subiter in nemo_iter.to_shards():
AttributeError: 'LazyNeMoIterator' object has no attribute 'to_shards'Case 2 (non-tarred, no metadata_only — i.e. a plain training config):
from omegaconf import OmegaConf
from nemo.collections.common.data.lhotse.cutset import read_nemo_manifest
read_nemo_manifest(OmegaConf.create({
"type": "nemo",
"manifest_filepath": [["data/manifest_1.json"], ["data/manifest_2.json"]],
"max_open_streams": 4,
}))Traceback (most recent call last):
File "repro2.py", line 12, in <module>
cuts, is_tarred = read_nemo_manifest(cfg)
File ".../nemo/collections/common/data/lhotse/cutset.py", line 1772, in read_nemo_manifest
for subiter in nemo_iter.to_shards():
AttributeError: 'LazyNeMoIterator' object has no attribute 'to_shards'For contrast, the equivalent config routed through the group path (scalar manifest_filepath per entry, top-level max_open_streams) already produces the intended message today:
File ".../nemo/collections/common/data/lhotse/cutset.py", line 662, in parse_and_combine_datasets
cuts = mux(
File ".../nemo/collections/common/data/lhotse/cutset.py", line 1823, in mux
assert not force_finite, "max_open_streams and metadata_only/force_finite options are not compatible"
AssertionError: max_open_streams and metadata_only/force_finite options are not compatibleExpected behavior
metadata_only/force_finitecombined withmax_open_streamsshould raise the existing, actionableAssertionErrorfrommux()— "max_open_streams and metadata_only/force_finite options are not compatible" — regardless of whichmanifest_filepathspelling was used. Today the group path does this and the multi-manifestread_nemo_manifestpath does not.- Non-tarred manifests with
max_open_streamsshould be muxed as one stream per manifest (there are no shards to split), matching whatparse_and_combine_datasets()already does when it callsmux(..., max_open_streams=...)on arbitrary cutsets — not crash.
Environment overview (please complete the following information)
- Environment location: Bare-metal (macOS), local venv
- Method of NeMo install: from source — checkout of
mainatd0a07c056, run withPYTHONPATHpointing at the checkout
Environment details
- OS version: macOS 26.5.1 (Darwin 25.5.0, arm64)
- PyTorch version: 2.12.0 (CPU)
- Python version: 3.10.18
- Lhotse version: 2.0.0a3
Additional context
Affected source: nemo/collections/common/data/lhotse/cutset.py:1740-1777 (attribute access at :1772) vs. the guard at :1823. to_shards() is defined only on LazyNeMoTarredIterator (nemo/collections/common/data/lhotse/nemo_adapters.py:639).
The existing comment at :1768 already says "split the manifest to individual shards if applicable", so the condition looks like it was meant to be narrower than it is.
Follow-up worth discussing separately: should the metadata-only scripts simply ignore max_open_streams instead of erroring? max_open_streams is purely an open-file-descriptor limit for tar streams, and metadata_only performs no audio I/O — so arguably estimate_duration_bins.py should just work when pointed at a real training config. That is a policy change to the existing assert, so this report only asks that the guard actually fire.
Source: NVIDIA-NeMo/Speech