#16081·Speech

max_open_streams with a multi-manifest config raises AttributeError: LazyNeMoIterator has no attribute to_shards

Author: udsy19Created Aug 18, 2026Updated Sep 29, 2026
Labelscommunity-request

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:

python
# 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:

python
# 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:

python
# 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:

  1. metadata_only=true + max_open_streams — the user should see the actionable assert above, but gets a raw AttributeError instead. This breaks scripts/speech_recognition/estimate_duration_bins.py and scripts/speech_recognition/estimate_data_weights.py, which both force metadata_only, for any config that also sets max_open_streams.
  2. Non-tarred manifests + max_open_streams (a normal training config, no metadata_only) — same AttributeError, 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

bash
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 2

Actual 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):

bash
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):

python
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 compatible

Expected behavior

  1. metadata_only/force_finite combined with max_open_streams should raise the existing, actionable AssertionError from mux() — "max_open_streams and metadata_only/force_finite options are not compatible" — regardless of which manifest_filepath spelling was used. Today the group path does this and the multi-manifest read_nemo_manifest path does not.
  2. Non-tarred manifests with max_open_streams should be muxed as one stream per manifest (there are no shards to split), matching what parse_and_combine_datasets() already does when it calls mux(..., 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 main at d0a07c056, run with PYTHONPATH pointing 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.