feat(cycle): Cycle and Recurrence return early on Stop with the last finished state
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 56/100
Direzione di ricerca
Read packages/pipekit-cycle/src/pipekit_cycle/cycles/_cycle.py and the P8 roadmap entry, then review the existing Cycle and Recurrence loops and their tests. Implement the specified stop handling, state and history behavior, and attributes for both classes; update their docstrings and the roadmap. Done means the listed stop, repeat-call, exception, history, and hash checks pass, along with make test, lint, and typecheck.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem / Request
pipekit_cycle.Cycle and Recurrence cannot end early and return where they were.
This issue makes both catch pipekit_ops.Stop (added by P8 (pipekit-ops, #382)), record it as self.stop, and return the stop's carrier with the state of the last step that finished.
It is the pipekit-cycle half of phase P8 of packages/pipekit-ops/docs/design/roadmap.md.
User Story
As the author of a chunked model run on
Cycle, I want a monitor inside the step to end the run cleanly at a chunk edge, so that I get the last good state back and can write a checkpoint from it.
Motivation
sesmax-experiment runs a model in chunks as Cycle(step_op=chunk, n_steps=timeline.n_chunks)(first, 0), where chunk is a Sequential of an AdvanceChunk (a StatefulOperator whose state is the chunk index), the monitors, and the snapshot and checkpoint stages (run/chunks.py @ 12f169f6bf).
When a monitor wants the run to end (a wall-clock budget, a SIGTERM, a steady state), it raises sesmax's own RunStopped, which escapes Cycle.
To know the last frame for teardown, sesmax adds Tap(lambda frame: last.__setitem__(0, frame)) to the step.
With this issue the monitor raises Stop, Cycle returns, and both workarounds go.
Cycle._apply today (pipekit_cycle/cycles/_cycle.py @ be1b64a900):
def _apply(self, carrier, state):
self.history = []
for i in range(self.n_steps):
carrier, state = self.step_op(carrier, state)
if self.save_history and (i % self.history_stride == 0):
self.history.append((carrier, state))
return carrier, state
Recurrence._apply loops step_op until condition_op(state) is truthy or max_iters is reached, and records self.iters and self.converged.
Proposed API
# pipekit_cycle/cycles/_cycle.py (proposed, this issue)
class Cycle(StatefulOperator):
stop: Stop | None # the Stop that ended the last call, or None
steps_done: int # the steps that finished in the last call
class Recurrence(StatefulOperator):
stop: Stop | None # as above; converged stays False when a Stop ends the loop
Neither constructor changes, and neither does get_config, so pipeline_hash stays the same.
Design Snapshot
from pipekit_ops import Stop
from pipekit_cycle import Cycle
# within the loop
try:
carrier, state = self.step_op(carrier, state)
except Stop as stop:
self.stop = stop
return stop.carrier, state # state: the last step that finished
The returned state is that of the last step that finished, because the step that raised did not return one.
The carrier is the stop's, so it can be one step ahead of the returned state when the operator that raised runs after the model advanced in the same step; sesmax's frames record their own chunk index, so the caller can tell.
History keeps only finished steps.
Any other exception propagates as today.
EnsembleCycle and WindowedCycle are out of scope; they can follow when a user needs them.
References & Existing Code
- Roadmap:
packages/pipekit-ops/docs/design/roadmap.md, phase P8 (merged in #374). Cycle,Recurrenceinpackages/pipekit-cycle/src/pipekit_cycle/cycles/_cycle.py@be1b64a900.Stopfrom P8 (pipekit-ops, #382):Stop(reason, carrier=None, *, resumable=False, complete=False), aBaseExceptionexported bypipekit_ops.- pipekit-cycle depends on
pipekit-ops>=0.4.0today (packages/pipekit-cycle/pyproject.toml@be1b64a900).
Implementation Steps
- Raise the floor in
packages/pipekit-cycle/pyproject.tomlto the pipekit-ops release that holdsStop. - In
Cycle._apply, resetself.stop = Noneandself.steps_done = 0, catchStoparoundself.step_op(...), and return(stop.carrier, state). - Do the same in
Recurrence._apply, leavingconvergedfalse. - Update the docstrings of both classes with the new attributes and an example.
- Mark the pipekit-cycle part of P8 as built in the roadmap.
Definition of Done
- Code lands at the path above
- Tests pass:
make test - Lint and typecheck pass:
make lint && make typecheck - Google-style docstrings describe
stopandsteps_done
Testing
- G8-1: a
Cycleof 10 steps whose step raisesStopat step 4 returns the stop's carrier and the state after step 3;cycle.stop.reasonis the reason given andcycle.steps_done == 3. - G8-3: a second call of the same
Cyclethat runs to the end hascycle.stop is Noneandsteps_done == 10. - G8-4: a
ValueErrorraised at step 4 propagates out ofCycleandRecurrenceunchanged. - G8-6:
pipeline_hashofCycleandRecurrenceis unchanged (pinned in a test). - With
save_history=True, a stop at step 4 leaves the history of steps 1 to 3 only. -
Recurrencewhose step raisesStopat iteration 2 returns its carrier withconvergedfalse anditers == 1.
Documentation
- The pipekit-cycle API page lists
stopandsteps_done.
Relationships
- Parent (theme epic): #379
- Blocked by: #382, and a pipekit-ops release that holds
Stop - Blocks: #385 (its gate G10-5 runs a guard inside a
Cycle) - Related: #230 (pipekit-cycle roadmap)
- Lingua principale
- Python
- Stelle
- 0
- Fork
- 0
- Merge medio
- 3h 50m
- PR unite (30g)
- 143
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di jejjohnson/pipekit
-
area:code layer:0-primitives priority:p2 type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jejjohnson/pipekit#296 ·
I maintainer di solito rispondono entro 1 giorno
-
area:code type:feature
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
jejjohnson/pipekit#411 ·
I maintainer di solito rispondono entro 1 giorno
-
area:code type:feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
jejjohnson/pipekit#410 ·
I maintainer di solito rispondono entro 1 giorno
-
area:code type:feature
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
jejjohnson/pipekit#409 ·
I maintainer di solito rispondono entro 1 giorno
-
area:code type:feature
Difficoltà 3/5 1-2 giorni Idoneità per principianti 75/100
jejjohnson/pipekit#408 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di jejjohnson/pipekit
Issue simili
-
A JSON chat answer blocks the backend event loop for the whole RAG runForse già presa @NopeCharon l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
The-OpenROAD-Project/ORAssistant#656 ·
I maintainer di solito rispondono entro 1 giorno
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorForse già presa @jejjohnson l’ha presa oggi. Apertatype:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
jejjohnson/integrix#144 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
finos/ai-governance-framework#459 ·
-
slurm: a case outcome nested too deep crashes status/collect instead of reading as no outcomeAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno