# tf.estimator.SecondOrStepTimer

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/basic_session_run_hooks.py#L85-L150) |

Timer that triggers at most once every N seconds or once every N steps. (deprecated)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.estimator.SecondOrStepTimer`](https://www.tensorflow.org/api_docs/python/tf/estimator/SecondOrStepTimer), [`tf.compat.v1.train.SecondOrStepTimer`](https://www.tensorflow.org/api_docs/python/tf/estimator/SecondOrStepTimer)

<br />

    tf.estimator.SecondOrStepTimer(
        every_secs=None, every_steps=None
    )

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use tf.keras instead.

This symbol is also exported to v2 in tf.estimator namespace. See
<https://github.com/tensorflow/estimator/blob/master/tensorflow_estimator/python/estimator/hooks/basic_session_run_hooks.py>

## Methods

### `last_triggered_step`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/basic_session_run_hooks.py#L149-L150)

    last_triggered_step()

Returns the last triggered time step or None if never triggered.

### `reset`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/basic_session_run_hooks.py#L105-L107)

    reset()

Resets the timer.

### `should_trigger_for_step`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/basic_session_run_hooks.py#L109-L134)

    should_trigger_for_step(
        step
    )

Return true if the timer should trigger for the specified step.

<br />

<br />

<br />

| Args ||
|---|---|
| `step` | Training step to trigger on. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| True if the difference between the current time and the time of the last trigger exceeds `every_secs`, or if the difference between the current step and the last triggered step exceeds `every_steps`. False otherwise. ||

<br />

### `update_last_triggered_step`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/training/basic_session_run_hooks.py#L136-L147)

    update_last_triggered_step(
        step
    )

Update the last triggered time and step number.

<br />

<br />

<br />

| Args ||
|---|---|
| `step` | The current step. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A pair `(elapsed_time, elapsed_steps)`, where `elapsed_time` is the number of seconds between the current trigger and the last one (a float), and `elapsed_steps` is the number of steps between the current trigger and the last one. Both values will be set to `None` on the first trigger. ||

<br />