Skip to content

RewardTokensPerSecond metric

Bases: LMRewardsOperationalMetric

Throughput in tokens per second during reward computation.

Example:

program.compile(
    metrics=[
        synalinks.metrics.RewardTokensPerSecond(),
    ],
)
Source code in synalinks/src/metrics/lm_metrics.py
@synalinks_export("synalinks.metrics.RewardTokensPerSecond")
class RewardTokensPerSecond(LMRewardsOperationalMetric):
    """Throughput in tokens per second during reward computation.

    Example:

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

    def __init__(self, name="reward_tokens_per_second"):
        super().__init__(name=name)

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