Skip to content

Commit f2b3248

Browse files
committed
minor refactoring of cuda memory report functions
1 parent dd4b524 commit f2b3248

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

clams/app/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,7 @@ def validate_document_locations(mmif: Union[str, Mmif]) -> None:
340340
@staticmethod
341341
def _cuda_memory_to_str(mem) -> str:
342342
mib = mem / (1024 * 1024)
343-
if mib >= 1024:
344-
return f"{mib / 1024:.2f} GiB"
345-
else:
346-
return f"{mib:.1f} MiB"
343+
return f"{mib:.0f} MiB" # No decimal places
347344

348345
@staticmethod
349346
def _cuda_device_name_concat(name, mem):
@@ -440,7 +437,7 @@ def _record_vram_usage(self, parameters: dict, peak_bytes: int) -> None:
440437
else:
441438
self.logger.debug(
442439
f"Updating peak memory for {param_hash}: "
443-
f"{existing/1024**3:.2f}GB -> {peak_bytes/1024**3:.2f}GB"
440+
f"{self._cuda_memory_to_str(existing)} -> {self._cuda_memory_to_str(peak_bytes)}"
444441
)
445442
except (ValueError, IOError, json.JSONDecodeError):
446443
pass # Corrupted file, overwrite
@@ -464,7 +461,7 @@ def _record_vram_usage(self, parameters: dict, peak_bytes: int) -> None:
464461

465462
self.logger.info(
466463
f"Recorded peak memory for {param_hash}: "
467-
f"{peak_bytes/1024**3:.2f}GB"
464+
f"{self._cuda_memory_to_str(peak_bytes)}"
468465
)
469466
except Exception as e:
470467
self.logger.warning(f"Failed to record memory profile: {e}")

0 commit comments

Comments
 (0)