From 3e680db4f5469cdaeb4b2fc27f2d399568b39f3e Mon Sep 17 00:00:00 2001 From: SparshM8 <188700067+SparshM8@users.noreply.github.com> Date: Fri, 21 Aug 2026 13:52:16 +0000 Subject: [PATCH] Optimize memory for 512MB free tier: tune ONNX session options and reduce TF-IDF features --- backend/app/services/ai_detection.py | 3 +++ backend/app/services/plagiarism.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/services/ai_detection.py b/backend/app/services/ai_detection.py index 2b5de419..f9c32e9a 100644 --- a/backend/app/services/ai_detection.py +++ b/backend/app/services/ai_detection.py @@ -233,6 +233,9 @@ def _onnx_session(model_path: str) -> "Optional[InferenceSession]": # concurrent inference instead of ballooning and triggering a fallback. sess_options.enable_mem_pattern = False sess_options.enable_cpu_mem_arena = False + # Further memory reduction: disable profiling and memory-heavy optimizations + sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_BASIC + sess_options.add_session_config_entry("session.use_device_allocator_for_initializers", "1") try: return ort.InferenceSession(str(onnx_path), sess_options, providers=providers) except Exception as exc: diff --git a/backend/app/services/plagiarism.py b/backend/app/services/plagiarism.py index f5603476..12a84737 100644 --- a/backend/app/services/plagiarism.py +++ b/backend/app/services/plagiarism.py @@ -66,7 +66,7 @@ def _load_vectorizer(): from sklearn.feature_extraction.text import TfidfVectorizer _vectorizer = TfidfVectorizer( - max_features=20000, + max_features=10000, min_df=2, max_df=0.95, sublinear_tf=True,