LykosAI/StabilityMatrix · error · InvalidOperationException
Unexpected torch verification output
Error message
Unexpected torch verification output: {verificationOutput} What it means
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.
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.
Example fix
// before: verification output polluted by warnings
"WARNING: ...\n{\"torch\":\"2.3.0+rocm5.7\"}"
// after: ensure the probe prints only JSON, e.g. run with warnings suppressed
python -W ignore -c "import json,torch;print(json.dumps({'torch':torch.__version__,...}))" Defensive patterns
Strategy: validation
Validate before calling
var json = TryExtractJsonObject(verificationOutput);
if (string.IsNullOrWhiteSpace(json)) throw new InvalidOperationException($"No JSON in torch verification output: {verificationOutput}"); Type guard
static bool LooksLikeJsonObject(string? s) =>
!string.IsNullOrWhiteSpace(s) && s.TrimStart().StartsWith('{') && s.TrimEnd().EndsWith('}'); Try / catch
try { await helper.InstallWindowsNativeTorchAsync(...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Unexpected torch verification output"))
{
logger.Warning(ex, "Torch verification output unparseable; inspecting environment");
// surface raw output, repair python env, retry
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- torch is not installed in this environment. Install the…
- Installed torch is not a usable Windows ROCm build
- torch was not installed after Windows ROCm setup.
- Torch verification produced no output.
- Installed torch is not a usable ROCm build. Verification…
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/c56b31fbec8cddd0.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs:449
throw new InvalidOperationException("torch was not installed after Windows ROCm setup.");
}
var verificationResult = await venvRunner
.Run(
"-c \"import json, torch; print(json.dumps({'version': torch.__version__, 'hip': torch.version.hip, 'cuda': torch.cuda.is_available()}))\""
)
.ConfigureAwait(false);
var verificationOutput = (verificationResult.StandardOutput ?? string.Empty).Trim();
if (string.IsNullOrWhiteSpace(verificationOutput))
{
throw new InvalidOperationException("Torch verification produced no output.");
}
var verificationJson = TryExtractJsonObject(verificationOutput);
if (string.IsNullOrWhiteSpace(verificationJson))
{
throw new InvalidOperationException(
$"Unexpected torch verification output: {verificationOutput}"
);
}
JsonDocument verificationDocument;
try
{
verificationDocument = JsonDocument.Parse(verificationJson);
}
catch (Exception exception)
{
throw new InvalidOperationException(
$"Unexpected torch verification output: {verificationOutput}",
exception
);
}
using (verificationDocument)View on GitHub (pinned to af93d6ef57)