EmergentTwilight's picture
download
raw
1.95 kB
"""Exact short-cycle detection shared by autonomous rollout controllers."""
from __future__ import annotations
from collections.abc import Sequence
from typing import TypeVar
T = TypeVar("T")
ImagePhaseSignature = tuple[tuple[int, ...], tuple[int, ...], tuple[int, int]]
def image_phase_cycle_signature(
token_ids: Sequence[int],
*,
marker_token_id: int,
grid: tuple[int, int],
) -> ImagePhaseSignature:
"""Split one image-producing phase into text and complete scaffold."""
values = tuple(int(value) for value in token_ids)
if values.count(marker_token_id) != 1:
raise ValueError("image phase must contain exactly one image_gen marker")
marker = values.index(marker_token_id)
return values[:marker], values[marker:], grid
def repeating_period(
values: Sequence[T], *, repeats: int, max_period: int, min_span: int = 0
) -> int | None:
"""Return an exact suffix period after enough repeats and repeated span."""
if type(repeats) is not int or repeats < 2:
raise ValueError("cycle repeats must be an integer of at least two")
if type(max_period) is not int or max_period < 1:
raise ValueError("cycle max period must be a positive integer")
if type(min_span) is not int or min_span < 0:
raise ValueError("cycle minimum span must be a nonnegative integer")
for period in range(1, min(max_period, len(values) // repeats) + 1):
required_repeats = max(repeats, (min_span + period - 1) // period)
suffix_length = period * required_repeats
if suffix_length > len(values):
continue
suffix = values[-suffix_length:]
if all(
suffix[offset : offset + period] == suffix[:period]
for offset in range(period, len(suffix), period)
):
return period
return None
__all__ = [
"image_phase_cycle_signature",
"ImagePhaseSignature",
"repeating_period",
]

Xet Storage Details

Size:
1.95 kB
·
Xet hash:
f8b6b3f72af66f765babb8c091913b53fa74f0aacd180347dbda751c99fe1b00

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.