{"record":{"id":"b56aab4fcdcf22d6","repo":"LykosAI/StabilityMatrix","slug":"torch-is-not-installed-in-this-environment-install-the","errorCode":null,"errorMessage":"torch is not installed in this environment. Install the Windows ROCm torch build first.","messagePattern":"torch is not installed in this environment\\. Install the Windows ROCm torch build first\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs","lineNumber":142,"sourceCode":"    /// Ensures <c>rocm-sdk-devel</c> is installed from the ROCm multi-arch index.\n    /// It prefers a build whose date token matches the installed ROCm torch build and falls back to the latest available build when no exact match is available.\n    /// </summary>\n    public async Task EnsureWindowsSdkDevelAsync(\n        IPyVenvRunner venvRunner,\n        IProgress<ProgressReport>? progress = null,\n        Action<ProcessOutput>? onConsoleOutput = null,\n        CancellationToken cancellationToken = default\n    )\n    {\n        var state = machineState.Value;\n        var multiArchPythonPackageIndexUrl = WindowsRocmSupport.GetMultiArchPythonPackageIndexUrl(\n            state.RuntimeGfxArch\n        );\n\n        var torchInfo = await venvRunner.PipShow(\"torch\").ConfigureAwait(false);\n        if (torchInfo is null)\n        {\n            throw new InvalidOperationException(\n                \"torch is not installed in this environment. Install the Windows ROCm torch build first.\"\n            );\n        }\n\n        if (!IsUsableWindowsNativeTorchBuild(torchInfo.Version, null))\n        {\n            throw new InvalidOperationException(\n                $\"Installed torch is not a usable Windows ROCm build (detected version: {torchInfo.Version}).\"\n            );\n        }\n\n        var nightlyBuildDateToken = TryGetNightlyBuildDateToken(torchInfo.Version);\n        var installedRocmSdkDevel = await venvRunner.PipShow(RocmSdkDevelPackageName).ConfigureAwait(false);\n        if (\n            !string.IsNullOrWhiteSpace(nightlyBuildDateToken)\n            && HasNightlyBuildDateToken(installedRocmSdkDevel?.Version, nightlyBuildDateToken)\n        )\n        {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Services/Rocm/RocmPackageHelper.cs#L124-L160","documentation":"EnsureWindowsSdkDevelAsync validates a Windows ROCm Python environment before installing the ROCm SDK devel package. It runs pip show torch in the venv; if torch is not installed at all (PipShow returns null), it throws InvalidOperationException telling the user to install the Windows ROCm torch build first, because the SDK devel install logic depends on an existing torch build's version metadata.","triggerScenarios":"Calling EnsureWindowsSdkDevelAsync on a venv where torch was never installed, torch installation previously failed or was rolled back, or the venvRunner points at a different/empty Python environment than expected.","commonSituations":"Fresh venv created but the Windows ROCm torch wheel install step failed or was skipped; user manually deleted torch; wrong venv path configured so pip show runs against an unrelated environment.","solutions":["Install the Windows ROCm torch build into the venv first (pip install torch --index-url https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/ or the appropriate multi-arch index)","Run InstallWindowsNativeTorchAsync / the package helper's install flow before calling EnsureWindowsSdkDevelAsync","Verify the venvRunner targets the intended Python environment (check venv path) and that pip show torch succeeds there","Recreate the venv and re-run the full ROCm setup flow if the environment is inconsistent"],"exampleFix":"// before\nawait rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...); // torch missing\n// after\nif (await venvRunner.PipShow(\"torch\") is null)\n{\n    await rocmHelper.InstallWindowsNativeTorchAsync(venvRunner, ...);\n}\nawait rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...);","handlingStrategy":"validation","validationCode":"if (await venvRunner.PipShow(\"torch\") is null)\n{\n    throw new InvalidOperationException(\"Install the Windows ROCm torch build first.\");\n}","typeGuard":"async Task<bool> HasTorchAsync(IPyVenvRunner venv) => await venv.PipShow(\"torch\") is not null;","tryCatchPattern":"try { await rocmHelper.EnsureWindowsSdkDevelAsync(venvRunner, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"torch is not installed\"))\n{\n    await rocmHelper.InstallWindowsNativeTorchAsync(venvRunner, ...);\n}","preventionTips":["Always run the full ROCm setup flow in order (torch install, then SDK devel)","Verify the venvRunner targets the intended venv","Check pip show torch after any venv recreation or manual pip surgery"],"tags":["rocm","torch","venv","windows"],"backgroundTag":"missing-dependency","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"}