MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / parse_size

Function parse_size

python/oneflow/remat/__init__.py:21–37  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

19
20
21def parse_size(size):
22 units = {
23 "B": 1,
24 "KB": 2 ** 10,
25 "MB": 2 ** 20,
26 "GB": 2 ** 30,
27 "TB": 2 ** 40,
28 "": 1,
29 "KIB": 10 ** 3,
30 "MIB": 10 ** 6,
31 "GIB": 10 ** 9,
32 "TIB": 10 ** 12,
33 }
34 m = re.match(r"^([\d\.]+)\s*([a-zA-Z]{0,3})$", str(size).strip())
35 assert m is not None
36 number, unit = float(m.group(1)), m.group(2).upper()
37 return int(number * units[unit])
38
39
40def set_budget(budget: str):

Callers 1

set_budgetFunction · 0.85

Calls 1

upperMethod · 0.45

Tested by

no test coverage detected