Parse test_dflash stdout into {prefill_s, decode_tps, al, stages{}}.
(stdout: str)
| 132 | |
| 133 | |
| 134 | def _parse_dflash(stdout: str) -> dict: |
| 135 | """Parse test_dflash stdout into {prefill_s, decode_tps, al, stages{}}.""" |
| 136 | m_pf = _RE_DF_PREFILL.search(stdout) |
| 137 | m_al = _RE_AL.search(stdout) |
| 138 | # decode tps line is the LAST tok/s in the file ("[dflash] generated ... -> X tok/s") |
| 139 | matches = list(_RE_DECODE_TPS.finditer(stdout)) |
| 140 | if not (m_pf and m_al and matches): |
| 141 | raise RuntimeError(f"test_dflash parse failed:\n{stdout[-1500:]}") |
| 142 | decode_tps = float(matches[-1].group(1)) |
| 143 | |
| 144 | # Per-stage timing block (lines like " draft_compute 14.70") |
| 145 | stages = {} |
| 146 | in_block = False |
| 147 | for line in stdout.splitlines(): |
| 148 | if line.startswith("[timing]"): |
| 149 | in_block = True |
| 150 | continue |
| 151 | if in_block: |
| 152 | if line.startswith("[") or line.startswith("---"): |
| 153 | # " ----- sum 132.20" ends block; "[dflash] generated…" too |
| 154 | if "----- sum" in line: |
| 155 | m = re.search(r"sum\s+(\d+(?:\.\d+)?)", line) |
| 156 | if m: |
| 157 | stages["sum"] = float(m.group(1)) |
| 158 | in_block = False |
| 159 | continue |
| 160 | if line.startswith("["): |
| 161 | in_block = False |
| 162 | continue |
| 163 | m = _RE_TIMING_LINE.match(line) |
| 164 | if m: |
| 165 | stages[m.group(1)] = float(m.group(2)) |
| 166 | |
| 167 | return { |
| 168 | "prefill_s": float(m_pf.group(2)), |
| 169 | "n_prompt_seen": int(m_pf.group(1)), |
| 170 | "decode_tps": decode_tps, |
| 171 | "al": float(m_al.group(1)), |
| 172 | "stages": stages, |
| 173 | } |
| 174 | |
| 175 | |
| 176 | def _parse_ar(stdout: str) -> dict: |