Parse a shape_info string like "M=4096, N=4096, K=4096" into a dict. Handles various formats: - "M=4096, N=4096, K=4096" - "B=1, H=32, N=4096, D=128" - "batch=4096, vocab=32000" - "rows=4096, cols=4096" Returns None if parsing fails.
(shape_info_str: str, op_type: str)
| 174 | # --------------------------------------------------------------------------- |
| 175 | |
| 176 | def parse_shape_info(shape_info_str: str, op_type: str) -> Optional[Dict[str, int]]: |
| 177 | """ |
| 178 | Parse a shape_info string like "M=4096, N=4096, K=4096" into a dict. |
| 179 | |
| 180 | Handles various formats: |
| 181 | - "M=4096, N=4096, K=4096" |
| 182 | - "B=1, H=32, N=4096, D=128" |
| 183 | - "batch=4096, vocab=32000" |
| 184 | - "rows=4096, cols=4096" |
| 185 | |
| 186 | Returns None if parsing fails. |
| 187 | """ |
| 188 | if not shape_info_str or not isinstance(shape_info_str, str): |
| 189 | return None |
| 190 | |
| 191 | # Match key=value pairs |
| 192 | pairs = re.findall(r"([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(\d+)", shape_info_str) |
| 193 | if not pairs: |
| 194 | return None |
| 195 | |
| 196 | raw = {k: int(v) for k, v in pairs} |
| 197 | |
| 198 | # Map to canonical bench.py keys using alias map |
| 199 | alias_map = SHAPE_ALIAS_MAP.get(op_type, {}) |
| 200 | if alias_map: |
| 201 | canonical = {} |
| 202 | for k, v in raw.items(): |
| 203 | mapped_key = alias_map.get(k, k) |
| 204 | canonical[mapped_key] = v |
| 205 | return canonical |
| 206 | else: |
| 207 | return raw |
| 208 | |
| 209 | |
| 210 | def shape_to_display(shape: Dict[str, int]) -> str: |