Skip to content

fix(inference): fail when an input glob matches no files - #254

Closed
kevin9327 wants to merge 1 commit into
NVIDIA:mainfrom
kevin9327:fix-inference-glob-no-match
Closed

kevin9327 wants to merge 1 commit into
NVIDIA:mainfrom
kevin9327:fix-inference-glob-no-match

Conversation

@kevin9327

Copy link
Copy Markdown

Problem

-i/--input-files accepts glob patterns (inputs/*.json). _from_files already rejects an empty input list, and a literal path that doesn't exist raises FileNotFoundError. A pattern that matches nothing, though, expands to an empty list and is silently dropped:

from_files(Sample, [d / "*.json"])    # [Sample(name='a')]
from_files(Sample, [d / "*.jsn"])     # []                  <- typo, no error
from_files(Sample, [d / "nope.json"]) # FileNotFoundError

In scripts/inference.py (lines 43–72) that empty list flows on. The script logs Loaded 0 samples, builds the pipeline (loading the checkpoint), calls generate([]) and exits normally without generating anything. When several patterns are passed and only one has a typo, that pattern's samples just go missing from the run. inference/ray/submit.py, inference/ray/gradio.py and scripts/upsample_prompts.py load inputs through the same function.

Fix

When a glob pattern matches no file, raise ValueError("No inference parameter files match '<pattern>'"), in line with the existing empty-list and missing-path errors. Literal paths and patterns that do match are unchanged.

Tests

Added to cosmos_framework/inference/common/args_test.py:

  • test_from_files_expands_glob_patterns: a matching pattern loads every match (sorted), and a missing literal path still raises FileNotFoundError. Passes both before and after the change, so the check only adds the no-match case.
  • test_from_files_raises_when_a_glob_matches_nothing: a non-matching pattern raises, including when it sits next to a matching one.

Fail-before (source reverted, tests kept):

_____________ test_from_files_raises_when_a_glob_matches_nothing ______________
cosmos_framework/inference/common/args_test.py:46: in test_from_files_raises_when_a_glob_matches_nothing
    with pytest.raises(ValueError, match=r"No inference parameter files match"):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   Failed: DID NOT RAISE ValueError

Counts for args_test.py:

passed failed
main, existing tests 10 2
new tests, source reverted 11 3
new tests, with fix 12 2

The 2 failures present in every row come from my environment (Windows, CPU) and fail the same way on main: test_download_file needs symlink privilege, and test_parse_checkpoint_path builds a path longer than MAX_PATH.

Run on CPU: PYTHONUTF8=1 COSMOS_TRAINING=0 pytest cosmos_framework/inference/common/args_test.py.

Lint

ruff 0.12.7 (repo pin): ruff check passes on both touched files before and after. ruff format --diff is the same size before and after for each file (3 and 4 lines, pre-existing).

🤖 Generated with Claude Code

_from_files rejects an empty input list, and a literal path that does not
exist raises FileNotFoundError, but a pattern such as "inputs/*.jsnol"
that matches nothing expanded to an empty list and was silently dropped.
The run then loaded the checkpoint and generated nothing, or skipped that
pattern's samples when another pattern matched.

Raise a ValueError naming the pattern instead.

Signed-off-by: kevin9327 <5299031+kevin9327@users.noreply.github.com>

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lfengad lfengad closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants