xref: /aosp_15_r20/external/pytorch/tools/shared/logging_utils.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1def pluralize(count: int, singular_word: str, plural_word: str = "") -> str:
2    if count == 1:
3        return f"{count} {singular_word}"
4
5    if not plural_word:
6        plural_word = f"{singular_word}s"
7
8    return f"{count} {plural_word}"
9
10
11def duration_to_str(seconds: float) -> str:
12    if seconds < 0.00001:
13        return "0s"
14    elif seconds < 60:
15        return f"{seconds:.1f}s"
16    elif seconds < 3600:
17        return f"{seconds / 60:.1f}m"
18    else:
19        return f"{seconds / 3600:.1f}h"
20