{"record":{"id":"8112397a0ca79beb","repo":"sgl-project/sglang","slug":"error-raised-in-subprocess-returned-stderr-decod","errorCode":null,"errorMessage":"Error raised in subprocess:\n{returned.stderr.decode()}","messagePattern":"Error raised in subprocess:\n(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/registry.py","lineNumber":233,"sourceCode":"    # issues like https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file\n    with tempfile.TemporaryDirectory() as tempdir:\n        output_filepath = os.path.join(tempdir, \"registry_output.tmp\")\n\n        # `cloudpickle` allows pickling lambda functions directly\n        input_bytes = cloudpickle.dumps((fn, output_filepath))\n\n        # cannot use `sys.executable __file__` here because the script\n        # contains relative imports\n        returned = subprocess.run(\n            _SUBPROCESS_COMMAND, input=input_bytes, capture_output=True\n        )\n\n        # check if the subprocess is successful\n        try:\n            returned.check_returncode()\n        except Exception as e:\n            # wrap raised exception to provide more information\n            raise RuntimeError(\n                f\"Error raised in subprocess:\\n\" f\"{returned.stderr.decode()}\"\n            ) from e\n\n        with open(output_filepath, \"rb\") as f:\n            return cast(_T, pickle.load(f))\n\n\n@dataclass(frozen=True)\nclass _LazyRegisteredModel(_BaseRegisteredModel):\n    \"\"\"\n    Represents a model that has not been imported in the main process.\n    \"\"\"\n\n    module_name: str\n    class_name: str\n\n    # Performed in another process to avoid initializing CUDA\n    def inspect_model_cls(self) -> _ModelInfo:","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/registry.py#L215-L251","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the stderr text embedded in the message — it contains the child's traceback; fix that root cause first","Reproduce manually: python -c \"import <model_module>\" in the same environment","Install missing optional dependencies (pip install the package named in the child traceback)","If the model fails only under subprocess isolation (e.g. env vars, CUDA_VISIBLE_DEVICES), make import-time code lazy/conditional"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import subprocess\nr = subprocess.run([sys.executable, '-c', f'import {module}'], capture_output=True)\nif r.returncode != 0:\n    raise ImportError(f'cannot import {module}: {r.stderr.decode()}')","typeGuard":null,"tryCatchPattern":"try:\n    arch_info = registry.inspect_model_cls(config)\nexcept RuntimeError as e:\n    stderr = str(e)\n    log.error('subprocess failure: %s', stderr)\n    raise  # fix the root cause in the child traceback, don't retry blindly","preventionTips":["Pre-import all registered model modules in CI to catch broken imports early","Keep model module imports free of CUDA/driver side effects","Pin optional dependencies (flash-attn, diffusers) in the serving environment"],"tags":["registry","subprocess","model-loading","import-error"],"backgroundTag":"subprocess-import-failure","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}