Spaces:
Runtime error
Runtime error
Factor Studios commited on
Upload 2 files
Browse files- http_storage.py +23 -0
- test_ai_integration_http.py +17 -27
http_storage.py
CHANGED
|
@@ -48,6 +48,29 @@ class LocalStorage:
|
|
| 48 |
|
| 49 |
self.lock = threading.Lock()
|
| 50 |
self._closing = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Initialize resource monitoring
|
| 53 |
self.resource_monitor = {
|
|
|
|
| 48 |
|
| 49 |
self.lock = threading.Lock()
|
| 50 |
self._closing = False
|
| 51 |
+
self._connected = True
|
| 52 |
+
|
| 53 |
+
# Initialize monitoring
|
| 54 |
+
self.resource_monitor = {
|
| 55 |
+
'vram_used': 0,
|
| 56 |
+
'active_tensors': 0,
|
| 57 |
+
'loaded_models': set(),
|
| 58 |
+
'last_updated': time.time()
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
# Initialize registries
|
| 62 |
+
self.model_registry = {}
|
| 63 |
+
|
| 64 |
+
self.initialized = True
|
| 65 |
+
|
| 66 |
+
def is_connected(self) -> bool:
|
| 67 |
+
"""Check if storage is connected (always True for local storage)"""
|
| 68 |
+
return self._connected and not self._closing and self.ping()
|
| 69 |
+
|
| 70 |
+
def close(self):
|
| 71 |
+
"""Close storage connection"""
|
| 72 |
+
self._closing = True
|
| 73 |
+
self._connected = False
|
| 74 |
|
| 75 |
# Initialize resource monitoring
|
| 76 |
self.resource_monitor = {
|
test_ai_integration_http.py
CHANGED
|
@@ -172,9 +172,16 @@ def test_ai_integration_http():
|
|
| 172 |
|
| 173 |
if success:
|
| 174 |
print(f"Model '{model_id}' loaded successfully to local storage")
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
if not ai_accelerator_for_loading.has_model(model_id):
|
| 177 |
-
raise RuntimeError(f"Model {model_id} not
|
|
|
|
|
|
|
| 178 |
else:
|
| 179 |
raise RuntimeError("Failed to load model in local storage")
|
| 180 |
|
|
@@ -262,31 +269,14 @@ def test_ai_integration_http():
|
|
| 262 |
ai_accelerators = []
|
| 263 |
|
| 264 |
try:
|
| 265 |
-
#
|
| 266 |
-
shared_storage =
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
shared_storage = components['storage']
|
| 274 |
-
logging.info("Successfully reused existing HTTP connection")
|
| 275 |
-
break
|
| 276 |
-
else:
|
| 277 |
-
logging.warning("Existing connection unavailable, creating new HTTP connection...")
|
| 278 |
-
with storage_manager() as new_storage:
|
| 279 |
-
if new_storage and new_storage.is_connected():
|
| 280 |
-
components['storage'] = new_storage
|
| 281 |
-
shared_storage = new_storage
|
| 282 |
-
logging.info("Successfully established new HTTP connection")
|
| 283 |
-
break
|
| 284 |
-
except Exception as e:
|
| 285 |
-
logging.error(f"HTTP connection attempt {attempt + 1} failed: {e}")
|
| 286 |
-
if attempt < max_connection_attempts - 1:
|
| 287 |
-
time.sleep(2)
|
| 288 |
-
continue
|
| 289 |
-
raise RuntimeError(f"Failed to establish HTTP connection after {max_connection_attempts} attempts")
|
| 290 |
|
| 291 |
# Initialize high-performance chip array with HTTP storage
|
| 292 |
total_sms = 0
|
|
|
|
| 172 |
|
| 173 |
if success:
|
| 174 |
print(f"Model '{model_id}' loaded successfully to local storage")
|
| 175 |
+
|
| 176 |
+
# Verify model is loaded in storage
|
| 177 |
+
if not ai_accelerator_for_loading.storage.is_model_loaded(model_id):
|
| 178 |
+
raise RuntimeError(f"Model {model_id} not found in storage")
|
| 179 |
+
|
| 180 |
+
# Verify model is registered in accelerator
|
| 181 |
if not ai_accelerator_for_loading.has_model(model_id):
|
| 182 |
+
raise RuntimeError(f"Model {model_id} not registered in accelerator")
|
| 183 |
+
|
| 184 |
+
print(f"Model {model_id} verified in both storage and accelerator")
|
| 185 |
else:
|
| 186 |
raise RuntimeError("Failed to load model in local storage")
|
| 187 |
|
|
|
|
| 269 |
ai_accelerators = []
|
| 270 |
|
| 271 |
try:
|
| 272 |
+
# Reuse existing storage instance
|
| 273 |
+
shared_storage = components['storage']
|
| 274 |
+
if not shared_storage or not shared_storage.is_connected():
|
| 275 |
+
logging.warning("Storage not available, creating new instance...")
|
| 276 |
+
with storage_manager() as new_storage:
|
| 277 |
+
components['storage'] = new_storage
|
| 278 |
+
shared_storage = new_storage
|
| 279 |
+
logging.info("Successfully initialized local storage")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
# Initialize high-performance chip array with HTTP storage
|
| 282 |
total_sms = 0
|