Spaces:
Running on Zero
Running on Zero
File size: 2,116 Bytes
5ed07ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True)
class SVSEvalSchedule:
run_val_loss: bool
run_audio_eval: bool
def should_run_interval(
*,
step: int,
interval: int,
total_steps: int,
include_step_zero: bool = False,
) -> bool:
if total_steps <= 0:
return False
last_step = total_steps - 1
if step == last_step:
return True
if step == 0:
return include_step_zero
if interval <= 0:
return False
return step % interval == 0
def build_svs_eval_schedule(
*,
step: int,
total_steps: int,
valid_interval: int,
audio_eval_interval: int,
has_validation: bool,
validate_at_step_zero: bool = False,
audio_validate_at_step_zero: bool = False,
) -> SVSEvalSchedule:
if not has_validation:
return SVSEvalSchedule(run_val_loss=False, run_audio_eval=False)
return SVSEvalSchedule(
run_val_loss=should_run_interval(
step=step,
interval=valid_interval,
total_steps=total_steps,
include_step_zero=validate_at_step_zero,
),
# Audio eval at step 0 is opt-in via ``audio_validate_at_step_zero``
# (separate from val_loss step-0 gating, since audio eval is orders
# of magnitude more expensive). Useful for debugging the audio-eval
# path without waiting for the first ``audio_eval_interval`` hit.
run_audio_eval=should_run_interval(
step=step,
interval=audio_eval_interval,
total_steps=total_steps,
include_step_zero=audio_validate_at_step_zero,
),
)
def should_save_checkpoint(
*,
step: int,
save_interval: int,
total_steps: int,
skip_step_zero: bool = False,
) -> bool:
if should_run_interval(
step=step,
interval=save_interval,
total_steps=total_steps,
include_step_zero=not skip_step_zero,
):
if skip_step_zero and step == 0 and step != total_steps - 1:
return False
return True
return False
|