Skip to content

Commit

Permalink
Minor fixes to push sync and gpu memory logging (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi-s8 authored Oct 30, 2024
1 parent 09cc4de commit 3bc064a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/algos/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,18 @@ def push(self, neighbors: int | List[int]) -> None:
def calculate_cpu_tensor_memory(self) -> int:
total_memory = 0
for obj in gc.get_objects():
if torch.is_tensor(obj) and obj.device.type == 'cpu':
if torch.is_tensor(obj) and obj.device.type == 'cpu': # type: ignore
total_memory += obj.element_size() * obj.nelement()
return total_memory

def get_memory_metrics(self) -> Tuple[float | int, float | int]:
"""
Get memory metrics
"""
peak_dram = self.calculate_cpu_tensor_memory() if self.log_memory else 0
peak_gpu = torch.cuda.max_memory_allocated() if torch.cuda.is_available() and self.log_memory else 0
peak_dram, peak_gpu = 0, 0
if self.log_memory:
peak_dram = self.calculate_cpu_tensor_memory()
peak_gpu = int(torch.cuda.max_memory_allocated()) # type: ignore
return peak_dram, peak_gpu

class BaseClient(BaseNode):
Expand Down
2 changes: 1 addition & 1 deletion src/utils/communication/grpc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def receive_pushed(self) -> List[OrderedDict[str, Any]]:
for _ in range(self.servicer.received_data.qsize()):
item = self.servicer.received_data.get()
round = item.get("round", 0)
if round <= self_round:
if (not self.synchronous) or round <= self_round:
items.append(item)
else:
self.servicer.received_data.put(item)
Expand Down

0 comments on commit 3bc064a

Please sign in to comment.