Skip to content

Commit 4acc196

Browse files
committed
fix: make sure to parse older bento repo with Gi
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
1 parent d9984f3 commit 4acc196

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/openllm/accelerator_spec.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
from __future__ import annotations
22

3-
import functools, math
3+
import functools, math, re, typing
44
import psutil, pydantic
55

6+
from pydantic import BeforeValidator
67
from typing_extensions import override
78
from openllm.common import BentoInfo, DeploymentTarget, output, Accelerator
89

910

11+
def parse_memory_string(v: typing.Any) -> typing.Any:
12+
"""Parse memory strings like "60Gi" into float."""
13+
if isinstance(v, str):
14+
match = re.match(r"(\d+(\.\d+)?)\s*Gi$", v, re.IGNORECASE)
15+
if match:
16+
return float(match.group(1))
17+
# Pass other types (including numbers or other strings for standard float conversion) through
18+
return v
19+
20+
1021
class Resource(pydantic.BaseModel):
11-
memory: float = 0.0
22+
memory: typing.Annotated[float, BeforeValidator(parse_memory_string)] = 0.0
1223
cpu: int = 0
1324
gpu: int = 0
1425
gpu_type: str = ''

0 commit comments

Comments
 (0)