Spaces:
Sleeping
Sleeping
Factor Studios
commited on
Update server.py
Browse files
server.py
CHANGED
|
@@ -104,51 +104,51 @@ class VirtualGPUServer:
|
|
| 104 |
"""Handle VRAM read/write operations"""
|
| 105 |
try:
|
| 106 |
op_type = operation.get('type')
|
|
|
|
|
|
|
|
|
|
| 107 |
block_id = operation.get('block_id')
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
if data and isinstance(data, (dict, list)):
|
| 112 |
data = self._make_json_serializable(data)
|
| 113 |
|
| 114 |
if op_type == 'write':
|
| 115 |
-
# Additional error handling and logging
|
| 116 |
-
if not block_id:
|
| 117 |
-
raise ValueError("Missing block_id for VRAM write operation")
|
| 118 |
if data is None:
|
| 119 |
-
raise ValueError("Missing data for
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
# Save data to file
|
| 125 |
-
np.save(file_path, np.array(data))
|
| 126 |
-
# Update cache
|
| 127 |
-
self.vram_cache[block_id] = np.array(data)
|
| 128 |
-
return {'status': 'success', 'message': f'Block {block_id} written'}
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
'status': 'success',
|
| 146 |
-
'data': data.tolist(),
|
| 147 |
-
'source': 'disk'
|
| 148 |
-
}
|
| 149 |
|
| 150 |
-
return {'status': 'error', 'message': 'Block not found'}
|
| 151 |
-
|
| 152 |
async def handle_state_operation(self, operation: dict) -> dict:
|
| 153 |
"""Handle GPU state operations"""
|
| 154 |
op_type = operation.get('type')
|
|
|
|
| 104 |
"""Handle VRAM read/write operations"""
|
| 105 |
try:
|
| 106 |
op_type = operation.get('type')
|
| 107 |
+
if not op_type:
|
| 108 |
+
raise ValueError("Missing operation type")
|
| 109 |
+
|
| 110 |
block_id = operation.get('block_id')
|
| 111 |
+
if not block_id:
|
| 112 |
+
raise ValueError("Missing block_id")
|
| 113 |
|
| 114 |
+
data = operation.get('data')
|
| 115 |
if data and isinstance(data, (dict, list)):
|
| 116 |
data = self._make_json_serializable(data)
|
| 117 |
|
| 118 |
if op_type == 'write':
|
|
|
|
|
|
|
|
|
|
| 119 |
if data is None:
|
| 120 |
+
raise ValueError("Missing data for write operation")
|
| 121 |
+
file_path = self.vram_path / f"{block_id}.npy"
|
| 122 |
+
np.save(file_path, np.array(data))
|
| 123 |
+
self.vram_cache[block_id] = np.array(data)
|
| 124 |
+
return {'status': 'success', 'message': f'Block {block_id} written'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
if op_type == 'read':
|
| 127 |
+
if block_id in self.vram_cache:
|
| 128 |
+
return {
|
| 129 |
+
'status': 'success',
|
| 130 |
+
'data': self.vram_cache[block_id] if isinstance(self.vram_cache[block_id], list) else self.vram_cache[block_id].tolist(),
|
| 131 |
+
'source': 'cache'
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
file_path = self.vram_path / f"{block_id}.npy"
|
| 135 |
+
if file_path.exists():
|
| 136 |
+
data = np.load(file_path)
|
| 137 |
+
self.vram_cache[block_id] = np.array(data)
|
| 138 |
+
return {
|
| 139 |
+
'status': 'success',
|
| 140 |
+
'data': data.tolist(),
|
| 141 |
+
'source': 'disk'
|
| 142 |
+
}
|
| 143 |
+
return {'status': 'error', 'message': 'Block not found'}
|
| 144 |
|
| 145 |
+
return {'status': 'error', 'message': f'Unknown operation type: {op_type}'}
|
| 146 |
+
|
| 147 |
+
except ValueError as e:
|
| 148 |
+
return {'status': 'error', 'message': str(e)}
|
| 149 |
+
except Exception as e:
|
| 150 |
+
return {'status': 'error', 'message': f'Operation failed: {str(e)}'}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
|
|
|
|
|
|
| 152 |
async def handle_state_operation(self, operation: dict) -> dict:
|
| 153 |
"""Handle GPU state operations"""
|
| 154 |
op_type = operation.get('type')
|