Bases: LMOperationalMetric
Average time-to-first-token (TTFT) in seconds over streamed LM calls.
Measured per streamed call as the wall-clock from the provider request
start to the first non-empty chunk (content or reasoning), then averaged
over the streamed calls in this run. The headline interactivity signal:
how long a user waits before output begins appearing. Only streaming=True
calls contribute -- which the generator restricts to inference -- so this
reads 0.0 on runs that never stream.
Example:
program.compile(
metrics=[
synalinks.metrics.AvgTimeToFirstToken(),
],
)
Source code in synalinks/src/metrics/lm_metrics.py
| @synalinks_export("synalinks.metrics.AvgTimeToFirstToken")
class AvgTimeToFirstToken(LMOperationalMetric):
"""Average time-to-first-token (TTFT) in seconds over streamed LM calls.
Measured per streamed call as the wall-clock from the provider request
start to the first non-empty chunk (content or reasoning), then averaged
over the streamed calls in this run. The headline interactivity signal:
how long a user waits before output begins appearing. Only `streaming=True`
calls contribute -- which the generator restricts to inference -- so this
reads 0.0 on runs that never stream.
Example:
```python
program.compile(
metrics=[
synalinks.metrics.AvgTimeToFirstToken(),
],
)
```
"""
def __init__(self, name="avg_time_to_first_token"):
super().__init__(name=name)
def result(self):
calls = self._delta("streaming_calls")
if calls <= 0:
return 0.0
return self._delta("streaming_ttft_s") / calls
|