Factor Studios commited on
Commit
d19c131
·
verified ·
1 Parent(s): 6534012

Upload 2 files

Browse files
Files changed (2) hide show
  1. ai.py +33 -0
  2. virtual_vram.py +31 -3
ai.py CHANGED
@@ -47,6 +47,39 @@ class AIAccelerator:
47
  bits=32,
48
  bandwidth_tbps=drift_velocity / 1e-12 # Bandwidth scaled to electron drift speed
49
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  # AI operation statistics
52
  self.operations_performed = 0
 
47
  bits=32,
48
  bandwidth_tbps=drift_velocity / 1e-12 # Bandwidth scaled to electron drift speed
49
  )
50
+ self.tensor_cores_initialized = False
51
+
52
+ def initialize_tensor_cores(self):
53
+ """Initialize tensor cores and verify they're ready for computation"""
54
+ if self.tensor_cores_initialized:
55
+ return True
56
+
57
+ try:
58
+ # Verify tensor core array is properly initialized
59
+ if not hasattr(self, 'tensor_core_array') or self.tensor_core_array is None:
60
+ raise RuntimeError("Tensor core array not properly initialized")
61
+
62
+ # Initialize tensor cores if needed
63
+ if hasattr(self.tensor_core_array, 'initialize'):
64
+ self.tensor_core_array.initialize()
65
+
66
+ # Verify VRAM access
67
+ if self.vram is None:
68
+ raise RuntimeError("VRAM not properly configured")
69
+
70
+ # Test tensor core functionality with a small computation
71
+ test_input = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
72
+ test_result = self.tensor_core_array.matmul(test_input, test_input)
73
+ if test_result is None or test_result.size == 0:
74
+ raise RuntimeError("Tensor core test computation failed")
75
+
76
+ self.tensor_cores_initialized = True
77
+ return True
78
+
79
+ except Exception as e:
80
+ print(f"Failed to initialize tensor cores: {str(e)}")
81
+ self.tensor_cores_initialized = False
82
+ return False
83
 
84
  # AI operation statistics
85
  self.operations_performed = 0
virtual_vram.py CHANGED
@@ -23,9 +23,37 @@ class VirtualVRAM:
23
  }
24
  self.store_vram_state()
25
 
26
- def store_vram_state(self):
27
- """Store VRAM state in WebSocket storage"""
28
- self.storage.store_state("vram", "state", self.vram_state)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  def allocate_block(self, size: int, block_id: Optional[str] = None) -> str:
31
  """Allocate a block of VRAM"""
 
23
  }
24
  self.store_vram_state()
25
 
26
+ def store_vram_state(self, max_retries=3):
27
+ """Store VRAM state in WebSocket storage with retry logic"""
28
+ for attempt in range(max_retries):
29
+ try:
30
+ # Wait for connection if needed
31
+ if not self.storage.wait_for_connection(timeout=5):
32
+ print(f"Waiting for WebSocket connection (attempt {attempt + 1}/{max_retries})")
33
+ time.sleep(1)
34
+ continue
35
+
36
+ # Ensure state is JSON serializable
37
+ safe_state = {
38
+ "total_size": str(self.vram_state["total_size"]) if isinstance(self.vram_state["total_size"], float) and self.vram_state["total_size"] == float('inf') else self.vram_state["total_size"],
39
+ "allocated": self.vram_state["allocated"],
40
+ "blocks": self.vram_state["blocks"],
41
+ "memory_map": self.vram_state["memory_map"],
42
+ "is_unlimited": self.vram_state["is_unlimited"]
43
+ }
44
+
45
+ success = self.storage.store_state("vram", "state", safe_state)
46
+ if success:
47
+ return True
48
+
49
+ print(f"Failed to store VRAM state (attempt {attempt + 1}/{max_retries})")
50
+ time.sleep(1)
51
+
52
+ except Exception as e:
53
+ print(f"Error storing VRAM state (attempt {attempt + 1}/{max_retries}): {str(e)}")
54
+ time.sleep(1)
55
+
56
+ raise RuntimeError("Failed to store VRAM state after multiple attempts")
57
 
58
  def allocate_block(self, size: int, block_id: Optional[str] = None) -> str:
59
  """Allocate a block of VRAM"""