mirror of
https://github.com/koush/scrypted.git
synced 2026-02-03 06:03:27 +00:00
openvino: avoid CLIP startup timeout by loading HF cache first (#1949)
Scrypted could restart the OpenVINO plugin on startup in offline/firewalled setups because CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32") triggers HuggingFace Hub network checks/retries that exceed the plugin startup watchdog.
Update predict/clip.py to:
- Load the CLIP processor from the local HF cache first (local_files_only=True) so startup is fast/offline-safe.
- Refresh the processor cache online asynchronously in a background thread (asyncio.to_thread) so update checks don’t block startup.
- Add simple log prints to indicate cache load vs refresh success/failure.
This commit is contained in:
@@ -15,6 +15,8 @@ class ClipEmbedding(PredictPlugin, scrypted_sdk.TextEmbedding, scrypted_sdk.Imag
|
||||
def __init__(self, plugin: PredictPlugin, nativeId: str):
|
||||
super().__init__(nativeId=nativeId, plugin=plugin)
|
||||
|
||||
hf_id = "openai/clip-vit-base-patch32"
|
||||
|
||||
self.inputwidth = 224
|
||||
self.inputheight = 224
|
||||
|
||||
@@ -23,10 +25,35 @@ class ClipEmbedding(PredictPlugin, scrypted_sdk.TextEmbedding, scrypted_sdk.Imag
|
||||
self.minThreshold = 0.5
|
||||
|
||||
self.model = self.initModel()
|
||||
self.processor = CLIPProcessor.from_pretrained(
|
||||
"openai/clip-vit-base-patch32",
|
||||
cache_dir=os.path.join(os.environ["SCRYPTED_PLUGIN_VOLUME"], "files", "hf"),
|
||||
)
|
||||
cache_dir = os.path.join(os.environ["SCRYPTED_PLUGIN_VOLUME"], "files", "hf")
|
||||
os.makedirs(cache_dir, exist_ok=True)
|
||||
|
||||
self.processor = None
|
||||
print("Loading CLIP processor from local cache.")
|
||||
try:
|
||||
self.processor = CLIPProcessor.from_pretrained(
|
||||
hf_id,
|
||||
cache_dir=cache_dir,
|
||||
local_files_only=True,
|
||||
)
|
||||
print("Loaded CLIP processor from local cache.")
|
||||
except Exception:
|
||||
print("CLIP processor not available in local cache yet.")
|
||||
|
||||
asyncio.ensure_future(self.refreshClipProcessor(hf_id, cache_dir), loop=self.loop)
|
||||
|
||||
async def refreshClipProcessor(self, hf_id: str, cache_dir: str):
|
||||
try:
|
||||
print("Refreshing CLIP processor cache (online).")
|
||||
processor = await asyncio.to_thread(
|
||||
CLIPProcessor.from_pretrained,
|
||||
hf_id,
|
||||
cache_dir=cache_dir,
|
||||
)
|
||||
self.processor = processor
|
||||
print("Refreshed CLIP processor cache.")
|
||||
except Exception:
|
||||
print("CLIP processor cache refresh failed.")
|
||||
|
||||
def getFiles(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user