sgl-project/sglang · error · ValueError

: directory has no .pt files at top level and multiple…

Error message

{label}: directory {directory} has no .pt files at top level and multiple subdirectories contain data ({names}). Please specify the exact subdirectory.

What it means

auto_descend_dir raises this when the given directory has no top-level .pt files and two or more subdirectories contain .pt files, making auto-descent ambiguous. The message lists the candidate subdirectory names and asks the user to point at the exact one.

Solutions

  1. Pass the specific subdirectory path containing the run's .pt files instead of the parent
  2. Or delete/move the stale sibling directories so only one candidate remains
  3. Check the listed names in the message to pick the intended run

Example fix

# before
compare --dir runs/           # contains runs/tp2/*.pt and runs/tp4/*.pt
# after
compare --dir runs/tp4/        # explicit subdirectory
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
def unique_pt_child(d: Path):
    cands = [p for p in d.iterdir() if p.is_dir() and any(p.glob('*.pt'))]
    return cands[0] if len(cands) == 1 else (None if not cands else cands)

Try / catch

try:
    resolved = auto_descend_dir(directory, label)
except ValueError as e:
    print(e); sys.exit(2)  # pick a subdir from the listed names

Prevention

When it happens

Trigger: Calling run() (which calls auto_descend_dir) with a parent dump directory containing e.g. both 'tp2/' and 'tp4/' subdirs each holding .pt files; also directly via test_error_with_multiple_nonempty_children.

Common situations: A dump root holding multiple runs/rank-sharded subdirectories (different TP sizes, before/after dumps), so the tool cannot guess which run to compare.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/41e7f7701fb36c51. Report an issue: GitHub.

Appendix: source

Thrown at python/sglang/srt/debug_utils/comparator/utils.py:38

        raise ValueError(f"Length mismatch: {details}")


def auto_descend_dir(directory: Path, label: str) -> Path:
    """If directory has no .pt files but exactly one subdirectory does, descend into it.

    Raises ValueError when the layout is ambiguous (>=2 subdirs with .pt)
    or when no .pt data is found at all.
    """
    if any(directory.glob("*.pt")):
        return directory

    candidates: list[Path] = [
        sub for sub in directory.iterdir() if sub.is_dir() and any(sub.glob("*.pt"))
    ]

    if len(candidates) >= 2:
        names: str = ", ".join(sorted(c.name for c in candidates))
        raise ValueError(
            f"{label}: directory {directory} has no .pt files at top level "
            f"and multiple subdirectories contain data ({names}). "
            f"Please specify the exact subdirectory."
        )

    if len(candidates) == 0:
        raise ValueError(
            f"{label}: no .pt files found in {directory} or any of its subdirectories."
        )

    resolved: Path = candidates[0]

    from sglang.srt.debug_utils.comparator.log_sink import log_sink
    from sglang.srt.debug_utils.comparator.output_types import InfoLog

    log_sink.add(
        InfoLog(
            category="auto_descend",

View on GitHub (pinned to 0132848349)