Spaces:
Running
Running
abhisheksan
commited on
Commit
•
18faacf
1
Parent(s):
8ecf9f2
Implement model preloading in PoetryGenerationService for faster startup; remove redundant preload method from ModelManager
Browse files
app/services/poetry_generation.py
CHANGED
@@ -37,7 +37,16 @@ class PoetryGenerationService:
|
|
37 |
"emotional": "Create an emotional poem about {}:\n",
|
38 |
"memory": "Write a memory-focused poem about {}:\n"
|
39 |
}
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
@lru_cache(maxsize=100)
|
42 |
def clean_output(self, text: str) -> str:
|
43 |
"""Optimized text cleaning with caching"""
|
@@ -195,13 +204,3 @@ class ModelManager:
|
|
195 |
torch.cuda.empty_cache()
|
196 |
gc.collect()
|
197 |
|
198 |
-
def preload_models(self):
|
199 |
-
"""Minimal preload for faster startup"""
|
200 |
-
try:
|
201 |
-
logger.info("Starting minimal model preload...")
|
202 |
-
_ = self.generate_poem("test", max_new_tokens=20)
|
203 |
-
logger.info("Basic preload completed")
|
204 |
-
return True
|
205 |
-
except Exception as e:
|
206 |
-
logger.error(f"Error preloading models: {str(e)}")
|
207 |
-
raise
|
|
|
37 |
"emotional": "Create an emotional poem about {}:\n",
|
38 |
"memory": "Write a memory-focused poem about {}:\n"
|
39 |
}
|
40 |
+
def preload_models(self):
|
41 |
+
"""Minimal preload for faster startup"""
|
42 |
+
try:
|
43 |
+
logger.info("Starting minimal model preload...")
|
44 |
+
_ = self.generate_poem("test", max_new_tokens=20)
|
45 |
+
logger.info("Basic preload completed")
|
46 |
+
return True
|
47 |
+
except Exception as e:
|
48 |
+
logger.error(f"Error preloading models: {str(e)}")
|
49 |
+
raise
|
50 |
@lru_cache(maxsize=100)
|
51 |
def clean_output(self, text: str) -> str:
|
52 |
"""Optimized text cleaning with caching"""
|
|
|
204 |
torch.cuda.empty_cache()
|
205 |
gc.collect()
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|