{"record":{"id":"c56b31fbec8cddd0","repo":"LykosAI/StabilityMatrix","slug":"unexpected-torch-verification-output-verificationoutput","errorCode":null,"errorMessage":"Unexpected torch verification output: {verificationOutput}","messagePattern":"Unexpected torch verification output: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs","lineNumber":449,"sourceCode":"            throw new InvalidOperationException(\"torch was not installed after Windows ROCm setup.\");\n        }\n\n        var verificationResult = await venvRunner\n            .Run(\n                \"-c \\\"import json, torch; print(json.dumps({'version': torch.__version__, 'hip': torch.version.hip, 'cuda': torch.cuda.is_available()}))\\\"\"\n            )\n            .ConfigureAwait(false);\n\n        var verificationOutput = (verificationResult.StandardOutput ?? string.Empty).Trim();\n        if (string.IsNullOrWhiteSpace(verificationOutput))\n        {\n            throw new InvalidOperationException(\"Torch verification produced no output.\");\n        }\n\n        var verificationJson = TryExtractJsonObject(verificationOutput);\n        if (string.IsNullOrWhiteSpace(verificationJson))\n        {\n            throw new InvalidOperationException(\n                $\"Unexpected torch verification output: {verificationOutput}\"\n            );\n        }\n\n        JsonDocument verificationDocument;\n        try\n        {\n            verificationDocument = JsonDocument.Parse(verificationJson);\n        }\n        catch (Exception exception)\n        {\n            throw new InvalidOperationException(\n                $\"Unexpected torch verification output: {verificationOutput}\",\n                exception\n            );\n        }\n\n        using (verificationDocument)","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs#L431-L467","documentation":"VerifyWindowsNativeTorchInstallAsync runs a Python one-liner that prints a JSON object describing the installed torch build (torch/torchvision versions, hip, cuda availability). If the raw output contains no parseable JSON object (TryExtractJsonObject returns null/whitespace), the helper treats the verification as uninterpretable and throws this InvalidOperationException. It exists so an install is never silently accepted when the probe output is garbled.","triggerScenarios":"InstallWindowsNativeTorchAsync -> VerifyWindowsNativeTorchInstallAsync when the embedded Python verification snippet prints anything other than a JSON object (extra banner text, warning lines, crash tracebacks, or empty/stderr-only output) so TryExtractJsonObject cannot isolate a JSON object.","commonSituations":"A broken or mismatched Python/venv environment prints import errors or pip warnings into the output; a GPU driver or ROCm runtime emits warning text before the JSON; torch failed to import and the process wrote a traceback instead of the expected JSON; output encoding or console buffering corrupts the JSON.","solutions":["Re-run the torch install with a clean environment so the verification script's stdout contains only the JSON object (check python/pip is on PATH and the venv is intact).","Look at the raw verificationOutput in the exception message to see what actually was printed and fix the underlying probe failure (e.g. missing torch, DLL load error).","Retry the install of the ROCm torch wheels so the package is present before verification runs.","Update the app, as newer versions may harden the JSON extraction against noisy output."],"exampleFix":"// before: verification output polluted by warnings\n\"WARNING: ...\\n{\\\"torch\\\":\\\"2.3.0+rocm5.7\\\"}\"\n// after: ensure the probe prints only JSON, e.g. run with warnings suppressed\npython -W ignore -c \"import json,torch;print(json.dumps({'torch':torch.__version__,...}))\"","handlingStrategy":"validation","validationCode":"var json = TryExtractJsonObject(verificationOutput);\nif (string.IsNullOrWhiteSpace(json)) throw new InvalidOperationException($\"No JSON in torch verification output: {verificationOutput}\");","typeGuard":"static bool LooksLikeJsonObject(string? s) =>\n    !string.IsNullOrWhiteSpace(s) && s.TrimStart().StartsWith('{') && s.TrimEnd().EndsWith('}');","tryCatchPattern":"try { await helper.InstallWindowsNativeTorchAsync(...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected torch verification output\"))\n{\n    logger.Warning(ex, \"Torch verification output unparseable; inspecting environment\");\n    // surface raw output, repair python env, retry\n}","preventionTips":["Keep the probe's stdout pure JSON: suppress warnings or route them to stderr.","Verify the Python/venv and torch import work before invoking install+verify.","Log the raw verification output whenever verification fails.","Pin torch/torchvision versions so probes behave deterministically."],"tags":["rocm","torch","json","windows"],"backgroundTag":"unexpected-response-shape","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}