File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
src/moderators/integrations Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import importlib
34import json
5+ import sys
46from pathlib import Path
57from typing import Any
68
@@ -41,11 +43,19 @@ def load_model(self) -> None:
4143 "Install with: uv pip install -e '.[transformers]' or: uv pip install transformers"
4244 ) from e
4345
44- pipeline = getattr ( _transformers , "pipeline" )
46+ had_torch = "torch" in sys . modules
4547
4648 # Ensure a DL framework (pt/tf/flax)
4749 framework = ensure_dl_framework (auto_install )
4850
51+ if framework == "pt" and not had_torch and "torch" in sys .modules :
52+ try :
53+ _transformers = importlib .reload (_transformers )
54+ except Exception :
55+ pass
56+
57+ pipeline = getattr (_transformers , "pipeline" )
58+
4959 # Ensure Pillow for image tasks
5060 ensure_pillow_for_task (task , auto_install )
5161
You can’t perform that action at this time.
0 commit comments