Skip to content

Commit

Permalink
Fix parse_uid() for model names with dots
Browse files Browse the repository at this point in the history
  • Loading branch information
borzunov committed Jul 24, 2024
1 parent 10fab97 commit 2498592
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/petals/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import re
from enum import Enum
from typing import Any, Dict, Optional, Sequence, Tuple

Expand All @@ -13,8 +14,9 @@

def parse_uid(uid: ModuleUID) -> Tuple[str, int]:
assert CHAIN_DELIMITER not in uid, "parse_uid() does not support chained UIDs"
dht_prefix, index = uid.split(UID_DELIMITER)
return dht_prefix, int(index)
match = re.fullmatch(fr"(.+){re.escape(UID_DELIMITER)}(\d+)", uid)
assert match is not None, f"uid={uid!r} has invalid format"
return match.group(1), int(match.group(2))


@pydantic.dataclasses.dataclass
Expand Down

0 comments on commit 2498592

Please sign in to comment.