ScoreTimer#

class scio.utils.ScoreTimer(target)[source]#

Bases: object

Timer for Score instances.

Provides a context manager to easily time successive executions of fit() and __call__() for Score instances. For correct usage, see __call__().

Timing statistics are respectively stored in calibration and inference attributes.

Parameters:

target (Score instance) – The target instance, for which execution should be timed.

Note

Different statistics from the same Score instance may originate from different contexts (parameters, calibration data, bound rnet, …). If timing statistics need to be compared, it is up to the user to ensure full consistency since only the type of operation, the number of processed samples and the score’s parameters are stored alongside the execution time.

Useful methods defined here

__call__(op, /, *, n_samples)

Context manager to time execution and store results.

Useful attributes defined here

calibration

Timing statistics for calibrations.

inference

Timing statistics for inferences.

report

Show statistics report in rich table.

stats

Timing statistics for this instance, from oldest to newest.

target

The Score instance being timed.

__call__(op, /, *, n_samples)[source]#

Context manager to time execution and store results.

Parameters:
  • op (ScoreTimerOperationLike) – See ScoreTimerOperation.

  • n_samples (int) – Number of samples to be processed during op.

Example

with timer("calibration", n_calib):
    # Calibration procedure...
Raises:

RuntimeError – If the instance’s target is already dead.

calibration#

Timing statistics for calibrations.

Returns:

calibration (tuple[ScoreTimerStat, ...]) – See ScoreTimerStat.

inference#

Timing statistics for inferences.

Returns:

inference (tuple[ScoreTimerStat, ...]) – See ScoreTimerStat.

report#

Show statistics report in rich table.

Example

>>> # For a given `gram` instance already in use
>>> gram.timer.report
   ScoreTimer report for Gram(separate_diagonal=False,
cut_off=0.1, act_norm=2, calib_labels='pred', mode='raw')
                    at 0x77346d30e490
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Extra params     ┃  Operation  ┃ # samples ┃ Duration ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━┩
│ max_gram_order=2 │  inference  │        20 │ 115.4 ms │
│                  │  inference  │      1352 │ 6.585 s  │
│                  │ calibration │        50 │ 302.9 ms │
├──────────────────┼─────────────┼───────────┼──────────┤
│ max_gram_order=4 │  inference  │        20 │ 246.5 ms │
│                  │  inference  │      1352 │ 13.78 s  │
│                  │ calibration │       677 │ 6.819 s  │
╰──────────────────┴─────────────┴───────────┴──────────╯
        Entries are listed from newest to oldest

Note

Shows nothing if there are no stats.

Warning

The behaviour is only guaranteed for classical (e.g. nonrecursive) parameter values.

stats#

Timing statistics for this instance, from oldest to newest.

Returns:

stats (tuple[ScoreTimerStat, ...]) – See ScoreTimerStat.

target#

The Score instance being timed.

It is stored as a weak reference and evaluates to None if the target object is dead.