MCPcopy Index your code
hub / github.com/modelscope/FunASR / get_human_readable_count

Function get_human_readable_count

funasr/train_utils/model_summary.py:5–39  ·  view source on GitHub ↗

Return human_readable_count Originated from: https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/core/memory.py Abbreviates an integer number with K, M, B, T for thousands, millions, billions and trillions, respectively. Examples: >>> get

(number: int)

Source from the content-addressed store, hash-verified

3
4
5def get_human_readable_count(number: int) -> str:
6 """Return human_readable_count
7
8 Originated from:
9 https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/core/memory.py
10
11 Abbreviates an integer number with K, M, B, T for thousands, millions,
12 billions and trillions, respectively.
13 Examples:
14 >>> get_human_readable_count(123)
15 '123 '
16 >>> get_human_readable_count(1234) # (one thousand)
17 '1 K'
18 >>> get_human_readable_count(2e6) # (two million)
19 '2 M'
20 >>> get_human_readable_count(3e9) # (three billion)
21 '3 B'
22 >>> get_human_readable_count(4e12) # (four trillion)
23 '4 T'
24 >>> get_human_readable_count(5e15) # (more than trillion)
25 '5,000 T'
26 Args:
27 number: a positive integer number
28 Return:
29 A string formatted according to the pattern described above.
30 """
31 assert number >= 0
32 labels = [" ", "K", "M", "B", "T"]
33 num_digits = int(np.floor(np.log10(number)) + 1 if number > 0 else 1)
34 num_groups = int(np.ceil(num_digits / 3))
35 num_groups = min(num_groups, len(labels)) # don't abbreviate beyond trillions
36 shift = -3 * (num_groups - 1)
37 number = number * (10**shift)
38 index = num_groups - 1
39 return f"{number:.2f} {labels[index]}"
40
41
42def to_bytes(dtype) -> int:

Callers 1

model_summaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…