sgl-project/sglang · error · RuntimeError

Error raised in subprocess

Error message

Error raised in subprocess:
{returned.stderr.decode()}

What it means

registry.inspect_model_cls loads candidate model classes in a subprocess to avoid polluting the parent process; this RuntimeError wraps any non-zero exit of that subprocess and surfaces its stderr. The real failure is whatever the child process printed (import error, CUDA init error, etc.).

Solutions

  1. Read the stderr text embedded in the message — it contains the child's traceback; fix that root cause first
  2. Reproduce manually: python -c "import <model_module>" in the same environment
  3. Install missing optional dependencies (pip install the package named in the child traceback)
  4. If the model fails only under subprocess isolation (e.g. env vars, CUDA_VISIBLE_DEVICES), make import-time code lazy/conditional
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess
r = subprocess.run([sys.executable, '-c', f'import {module}'], capture_output=True)
if r.returncode != 0:
    raise ImportError(f'cannot import {module}: {r.stderr.decode()}')

Try / catch

try:
    arch_info = registry.inspect_model_cls(config)
except RuntimeError as e:
    stderr = str(e)
    log.error('subprocess failure: %s', stderr)
    raise  # fix the root cause in the child traceback, don't retry blindly

Prevention

When it happens

Trigger: Calling inspect_model_cls for an architecture whose module fails to import in a clean subprocess — missing optional dependency, syntax/attribute error in the model file, driver/CUDA unavailable, or heavy import-time side effects crashing the child.

Common situations: Adding a new model whose file imports a package not in the environment; model code that imports torch.cuda at module scope on CPU-only machines; registry inspection running in a sandboxed/minimal CI container where flash-attn or diffusers extras are absent.

Related errors


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

Appendix: source

Thrown at python/sglang/multimodal_gen/runtime/models/registry.py:233

    # issues like https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
    with tempfile.TemporaryDirectory() as tempdir:
        output_filepath = os.path.join(tempdir, "registry_output.tmp")

        # `cloudpickle` allows pickling lambda functions directly
        input_bytes = cloudpickle.dumps((fn, output_filepath))

        # cannot use `sys.executable __file__` here because the script
        # contains relative imports
        returned = subprocess.run(
            _SUBPROCESS_COMMAND, input=input_bytes, capture_output=True
        )

        # check if the subprocess is successful
        try:
            returned.check_returncode()
        except Exception as e:
            # wrap raised exception to provide more information
            raise RuntimeError(
                f"Error raised in subprocess:\n" f"{returned.stderr.decode()}"
            ) from e

        with open(output_filepath, "rb") as f:
            return cast(_T, pickle.load(f))


@dataclass(frozen=True)
class _LazyRegisteredModel(_BaseRegisteredModel):
    """
    Represents a model that has not been imported in the main process.
    """

    module_name: str
    class_name: str

    # Performed in another process to avoid initializing CUDA
    def inspect_model_cls(self) -> _ModelInfo:

View on GitHub (pinned to 0132848349)