Skip to content

[SC-17529] Treat broken torch installs as "not a PyTorch model" - #549

Merged
panchicore merged 1 commit into
mainfrom
panchicore/sc-17529/handle-broken-torch-install-oserror
Jul 29, 2026
Merged

[SC-17529] Treat broken torch installs as "not a PyTorch model"#549
panchicore merged 1 commit into
mainfrom
panchicore/sc-17529/handle-broken-torch-install-oserror

Conversation

@panchicore

Copy link
Copy Markdown
Member

Pull Request Description

What and why?

SC-17529 / ZD 741: a customer on Windows could not run vm.init_model() on a scikit-learn logistic regression because is_pytorch_model() crashed while probing for torch.

The probe only caught ImportError, but a broken torch install can fail with other errors — in the customer's case OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed while loading c10.dll. That error escaped the except and aborted model initialization for a model that doesn't even use torch.

Now any failure to import torch is treated as "not a PyTorch model", matching the existing broad-catch precedent for the optional torch import in validmind/client.py.

Note for the ZD ticket: the customer's torch install is still broken (missing VC++ redistributable / mixed wheels are typical causes) — this fix makes the library robust to it so sklearn workflows are unaffected.

How to test

make test ONLY=tests.test_model

The new test_broken_torch_install_returns_false simulates the broken install by making torch's import raise OSError (WinError 1114) via a meta-path finder; it fails without the one-line fix and passes with it.

What needs special review?

Nothing — one-line exception-handling change plus tests.

Dependencies, breaking changes, and deployment notes

None.

Release notes

Fixed an error where vm.init_model() could fail for non-PyTorch models (e.g. scikit-learn) when a broken PyTorch installation was present in the environment, such as a WinError 1114 DLL initialization failure on Windows.

Checklist

  • What and why
  • Screenshots or videos (Frontend)
  • How to test
  • Special review areas
  • Dependencies, breaking changes, deployment notes
  • Release notes + label

🤖 Generated with Claude Code

is_pytorch_model() only caught ImportError, but a broken torch install
can raise other errors on import — e.g. OSError WinError 1114 when
c10.dll fails to load on Windows — which crashed vm.init_model() even
for non-torch models like sklearn LogisticRegression (ZD 741).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@panchicore panchicore added the bug Something isn't working label Jul 29, 2026
@panchicore
panchicore requested a review from cachafla July 29, 2026 16:05
@github-actions

Copy link
Copy Markdown
Contributor

PR Summary

This pull request enhances the functionality of the is_pytorch_model function in validmind/vm_models/model.py. The change broadens the exception handling from specifically catching an ImportError to catching any exception during the torch import. This adjustment is made to gracefully handle scenarios where a torch installation might be present but fail to load due to errors such as OSError (e.g., WinError 1114 when a native DLL like c10.dll fails to initialize).

Additionally, new unit tests have been introduced in tests/test_model.py to verify this behavior:

  • One test confirms that non-PyTorch models (using, e.g., LogisticRegression) correctly return false.
  • Another test simulates a broken torch installation by dynamically modifying the import mechanism to throw an OSError, ensuring that the function correctly handles such cases by returning false.

These modifications improve the robustness of the model detection logic in situations where external dependencies, like torch, might be present but not properly functional.

Test Suggestions

  • Test with an actual PyTorch model to ensure that is_pytorch_model returns true when expected.
  • Simulate additional failure modes (e.g., AttributeError) during torch import to verify broader exception handling.
  • Test performance impact if torch is available versus when it is not or is broken using mocks.
  • Run tests on different operating systems to ensure consistent behavior, particularly on Windows where DLL issues are common.

@panchicore panchicore self-assigned this Jul 29, 2026
@cachafla cachafla added the support Support-related PR label Jul 29, 2026
@panchicore
panchicore merged commit f9efb09 into main Jul 29, 2026
23 checks passed
@panchicore
panchicore deleted the panchicore/sc-17529/handle-broken-torch-install-oserror branch July 29, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working support Support-related PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants