Skip to content

Commit 42ea53f

Browse files
authored
Merge pull request #20 from JackyHe398/main
fix: wrongly fallback to low memory model when model corrupted
2 parents f4fc032 + c42aa03 commit 42ea53f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/fast_langdetect/infer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def _load_unix(self, model_path: Path) -> Any:
190190
"""Load model on Unix-like systems."""
191191
try:
192192
return fasttext.load_model(str(model_path))
193+
except MemoryError as e:
194+
# Let MemoryError propagate up to be handled by _get_model
195+
raise e
193196
except Exception as e:
194197
raise DetectError(f"fast-langdetect: Failed to load model: {e}")
195198

@@ -317,7 +320,7 @@ def _get_model(self, low_memory: bool = True) -> Any:
317320
)
318321
self._models[cache_key] = model
319322
return model
320-
except Exception as e:
323+
except MemoryError as e:
321324
if low_memory is not True and self.config.allow_fallback:
322325
logger.info("fast-langdetect: Falling back to low-memory model...")
323326
return self._get_model(low_memory=True)

0 commit comments

Comments
 (0)