Skip to content

Commit caebdb9

Browse files
Pathways-on-Cloud Teamcopybara-github
authored andcommitted
Simplify TPU instance regex in validators
Remove unnecessary capture group for the TPU type in the regex. The validation logic only requires the topology dimensions. PiperOrigin-RevId: 842419784
1 parent d7f6251 commit caebdb9

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

pathwaysutils/experimental/shared_pathways_service/validators.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,20 @@ def _validate_tpu_supported(tpu_instance_with_topology: str) -> None:
5151
# tpuv6e:2x4 -> type='tpuv6e', topology='2x4'
5252
# tpuv5p:2x2x1 -> type='tpuv5p', topology='2x2x1'
5353
match = re.match(
54-
r"^(?P<type>tpuv(?:5e|5p|6e)):(?P<topology>\d+(?:x\d+)*)$",
54+
r"^(?:tpuv(?:5e|5p|6e)):(?P<topology>\d+(?:x\d+){1,2})$",
5555
tpu_instance_with_topology,
5656
)
5757

5858
if match:
59-
tpu_base_type = match.group("type")
6059
topology_str = match.group("topology")
6160

62-
if not tpu_base_type:
63-
raise ValueError(
64-
f"Unknown TPU type '{type}' from '{tpu_instance_with_topology}'."
65-
)
66-
6761
try:
68-
dims = [int(d) for d in topology_str.split("x")]
69-
if len(dims) < 2 or len(dims) > 3:
70-
raise ValueError(
71-
f"Error: Invalid topology format '{topology_str}', Expected either"
72-
" 2 or 3 dimensions."
73-
)
74-
num_chips = 1
75-
for dim in dims:
76-
num_chips *= dim
62+
_ = [int(d) for d in topology_str.split("x")]
7763
except ValueError as exc:
7864
raise ValueError(
7965
f"Error: Invalid topology format '{topology_str}' in"
80-
f" '{tpu_instance_with_topology}'."
66+
f" '{tpu_instance_with_topology}'. Expected all numbers, e.g., 2x4"
67+
" for 2d topologies or 2x2x2 for 3-d topologies."
8168
) from exc
8269

8370
return

0 commit comments

Comments
 (0)