Skip to content

Add lazy loading for pytorch, tensorflow and the benchmarking module#170

Closed
deruyter92 wants to merge 4 commits intoDeepLabCut:mainfrom
deruyter92:jaap/lazy_loading
Closed

Add lazy loading for pytorch, tensorflow and the benchmarking module#170
deruyter92 wants to merge 4 commits intoDeepLabCut:mainfrom
deruyter92:jaap/lazy_loading

Conversation

@deruyter92
Copy link
Collaborator

@deruyter92 deruyter92 commented Mar 11, 2026

edit: This PR is replaced with #171 (accidentally opened from a fork instead of main repo)

Summary:
This PR fixes import-time failures when optional ML backends are not installed, and makes top-level package imports lighter and safer.

What changed

  • Added centralized lazy import helpers in dlclive/utils.py:get_torch(required=..., feature=...), get_tensorflow(required=..., feature=...)
  • Updated get_available_backends to use those helpers.
  • Enforced clear fail-fast behavior in required runtime paths: dlclive/factory.py now validates backend availability before creating PyTorch/TensorFlow runners.
  • Removed eager torch imports from non-required paths: dlclive/benchmark.py, dlclive/live_inference.py
  • Made benchmark APIs lazily loaded from package root: dlclive.init now lazily resolves benchmark_videos and download_benchmarking_data.

Why
torch/tensorflow are optional extras. Importing dlclive should not fail if one backend is missing, while backend-specific execution should still raise actionable errors when that backend is actually required.

@deruyter92 deruyter92 requested a review from C-Achard March 11, 2026 13:46
@deruyter92 deruyter92 marked this pull request as ready for review March 11, 2026 13:46
@deruyter92
Copy link
Collaborator Author

closed in favor of #170

@deruyter92 deruyter92 closed this Mar 13, 2026
@C-Achard
Copy link
Collaborator

(Did you mean #171 ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants