Skip to content

TokensPerSecond metric

Bases: LMOperationalMetric

Total tokens per second; use to measure LM speed, not to judge quality.

Example:

program.compile(
    metrics=[
        synalinks.metrics.TokensPerSecond(),
    ],
)
Source code in synalinks/src/metrics/lm_metrics.py
@synalinks_export("synalinks.metrics.TokensPerSecond")
class TokensPerSecond(LMOperationalMetric):
    """Total tokens per second; use to measure LM speed, not to judge quality.

    Example:

    ```python
    program.compile(
        metrics=[
            synalinks.metrics.TokensPerSecond(),
        ],
    )
    ```
    """

    direction = "up"

    def __init__(self, name="tokens_per_second", description=None):
        super().__init__(name=name, description=description)

    def result(self):
        wall = self._wall_clock_delta()
        if wall <= 0.0:
            return 0.0
        return self._delta("tokens") / wall