Skip to content

Commit 2f1618d

Browse files
committed
address Copilot review: memoize YAML loads, add debug logging, fix test name
- Cache resolved YAML files in _resolve_if_path to avoid redundant disk/network I/O for sibling groups referencing the same file - Add logging.debug when a path cannot be resolved, so failures are never fully silent - Rename misleading test to match its assertion (total depth is 2, not 1; the unresolvable string is treated as a leaf) Signed-off-by: Xuesong Yang <1646669+XuesongYang@users.noreply.github.com>
1 parent 2ae9c79 commit 2f1618d

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

nemo/collections/common/data/lhotse/cutset.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,19 @@ def count_input_cfg_levels(config: Union[DictConfig, dict]) -> int:
499499
2
500500
"""
501501

502+
_cache: dict[str, object] = {}
503+
502504
def _resolve_if_path(val):
503505
"""If *val* is a string/Path, try to load the YAML it points to."""
504506
if isinstance(val, (str, Path)):
505-
try:
506-
return load_yaml(str(val))
507-
except Exception:
508-
return val
507+
key = str(val)
508+
if key not in _cache:
509+
try:
510+
_cache[key] = load_yaml(key)
511+
except Exception:
512+
logging.debug("count_input_cfg_levels: could not load %r, treating as leaf", key)
513+
_cache[key] = val
514+
return _cache[key]
509515
return val
510516

511517
def _max_depth(obj) -> int:

tests/collections/common/test_lhotse_temperature_reweighting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ def test_two_level_string_input_cfg(self, tmp_path):
422422
config = {"input_cfg": str(top_yaml)}
423423
assert count_input_cfg_levels(config) == 2
424424

425-
def test_unresolvable_string_input_cfg_counts_as_one(self):
426-
"""Unresolvable path (e.g. OmegaConf interpolation) counts as 1 level."""
425+
def test_unresolvable_nested_string_input_cfg_is_treated_as_leaf(self):
426+
"""Nested unresolvable string input_cfg is treated as a leaf, so total depth is 2."""
427427
config = {
428428
"input_cfg": [
429429
{

0 commit comments

Comments
 (0)