Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to push sync and gpu memory logging #134

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading