Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Record a decode retry that fails again so the compatibility level can still rise

Bowen Xuebdb061d7a35d
diff --git a/freevideo_engine/adaptive.py b/freevideo_engine/adaptive.py
index 71edc9a..e5355d6 100644
--- a/freevideo_engine/adaptive.py
+++ b/freevideo_engine/adaptive.py
@@ -67,6 +67,26 @@ def second_pass_resumable(error, failure, metrics, attempts):
return not any(row.get('decision', {}).get('second_pass_resume') for row in attempts)
+def decode_resumable(error, failure, metrics, attempts):
+ """A CUDA error after sampling finished and its latents were saved and validated.
+
+ Any CUDA error qualifies, including a lost or unknown device state: the
+ retry is one fresh process that loads only the retained latents and decodes
+ them with the same placement, so no earlier context is reused and the
+ sampling is not repeated. It is not repeated itself, and a worker that may
+ still own the device never gets it. Out-of-memory keeps its own path.
+ """
+ from .decode_resume import completed_sampling
+ if failure.get('kind') not in ('cuda_error', 'code_error') or getattr(error, 'worker_stop_confirmed', None) is False:
+ return False
+ recorded = str((metrics or {}).get('error', '')).lower()
+ if not (cuda_runtime_error(error) or 'cuda error' in recorded) or 'out of memory' in recorded:
+ return False
+ if not completed_sampling(metrics):
+ return False
+ return not any(row.get('decision', {}).get('decode_resume') for row in attempts)
+
+
def classify_failure(error, metrics=None):
"""Only positively identified resource failures are retriable.
@@ -651,8 +671,10 @@ def execute_attempts(history, identity, profile, canvas, launch, *,
history.finish(attempt, failure['outcome'], details=details)
row.update(state=failure['outcome'], failure=failure)
persist()
- resume = (automatic and index < max_retries and not failure['retryable']
- and second_pass_resumable(error, failure, metrics, report['resource_attempts']))
+ decode_resume = (automatic and index < max_retries and not failure['retryable']
+ and decode_resumable(error, failure, metrics, report['resource_attempts']))
+ resume = decode_resume or (automatic and index < max_retries and not failure['retryable']
+ and second_pass_resumable(error, failure, metrics, report['resource_attempts']))
if not automatic or not (failure['retryable'] or resume) or index == max_retries:
raise
previous_ram_retries = sum(r.get('failure', {}).get('kind') == 'ram_pressure'
@@ -660,7 +682,12 @@ def execute_attempts(history, identity, profile, canvas, launch, *,
previous_gpu_retries = sum(r.get('failure', {}).get('kind') == 'gpu_oom'
for r in report['resource_attempts'][:-1])
from .decode_resume import completed_sampling
- if resume:
+ if decode_resume:
+ updated, decision = copy.deepcopy(current), dict(
+ reason='A CUDA error ended the request after sampling finished; decode only the '
+ 'retained latents in a fresh worker with the same placement.',
+ numerical_class='unchanged', decode_resume=True)
+ elif resume:
updated, decision = copy.deepcopy(current), dict(
reason='A CUDA call was rejected in the second pass; repeat only the second pass '
'from the retained first pass with the same placement.',
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index 1a84f8a..fc585f5 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -30,6 +30,42 @@ from .adaptive import (WorkerExit, classify_failure, local_identity, history_pat
from .resource_history import ResourceHistory
+# A worker that exits after a CUDA error normally does so at once. One whose
+# driver teardown never returns would otherwise hold the request forever, so
+# the controller ends a worker that recorded this failure and is still running.
+FAILED_WORKER_GRACE_SECONDS = 20.
+
+
+class FailureReceipt:
+ """Whether the worker's metrics file records a request ended by a CUDA error."""
+ def __init__(self, command):
+ self.path = self.stamp = None
+ self.found = False
+ self.since = time.time_ns() # A receipt left by an earlier request is not this worker's.
+ try:
+ request = json.loads(Path(command[command.index('--request') + 1]).read_text(encoding='utf-8'))
+ self.path = Path(request['metrics']) if request.get('metrics') else None
+ except (ValueError, IndexError, KeyError, OSError, TypeError):
+ pass
+
+ def recorded(self):
+ if self.path is None or self.found:
+ return self.found
+ try:
+ status = self.path.stat()
+ stamp = (status.st_mtime_ns, status.st_size)
+ if stamp == self.stamp or status.st_mtime_ns < self.since:
+ return False
+ metrics = json.loads(self.path.read_text(encoding='utf-8'))
+ except (OSError, ValueError):
+ return False # Unreadable or half written: read again at the next poll.
+ self.stamp = stamp
+ failure = metrics.get('failure') if isinstance(metrics, dict) else None
+ self.found = (isinstance(failure, dict) and metrics.get('success') is False
+ and failure.get('kind') == 'cuda_error')
+ return self.found
+
+
def child(command, env, descriptor, log, *, ram_budget_bytes=None, gpu=None, on_start=None,
minimum_available_bytes=None, ram_budget_is_estimate=False):
from .ram import ProcessMemory
@@ -55,6 +91,8 @@ def child(command, env, descriptor, log, *, ram_budget_bytes=None, gpu=None, on_
process = processes.popen(command, env=env, stdout=stream, stderr=subprocess.STDOUT,
pass_fds=(descriptor,), start_new_session=True)
pending_error = None
+ receipt = FailureReceipt(command)
+ failed_since = None
try:
if on_start:
on_start(process.pid)
@@ -90,6 +128,14 @@ def child(command, env, descriptor, log, *, ram_budget_bytes=None, gpu=None, on_
(', '.join(pressure['enforced_reasons']), pressure['working_bytes']/2**30,
ram_budget_bytes/2**30, pressure['available_bytes']/2**30,
pressure['emergency_floor_bytes']/2**30)) + detail)
+ if receipt.recorded():
+ failed_since = time.monotonic() if failed_since is None else failed_since
+ if time.monotonic() - failed_since >= FAILED_WORKER_GRACE_SECONDS:
+ telemetry['worker_unresponsive_after_failure_seconds'] = time.monotonic() - failed_since
+ telemetry['worker_exit'] = dict(exit_reading(None), memory=memory_sample())
+ print(json.dumps({'event': 'worker_ended_after_failure',
+ 'seconds': telemetry['worker_unresponsive_after_failure_seconds']}), flush=True)
+ raise WorkerExit(None, log)
try:
process.wait(timeout=.5)
except subprocess.TimeoutExpired:
diff --git a/freevideo_engine/resource_history.py b/freevideo_engine/resource_history.py
index 339bfbe..abe0b79 100644
--- a/freevideo_engine/resource_history.py
+++ b/freevideo_engine/resource_history.py
@@ -409,7 +409,14 @@ class ResourceHistory:
if observation is not None and outcome != 'success':
raise ValueError('Failed attempts cannot certify resource calibration')
if outcome == 'discarded':
- if (details or {}).get('kind') in ('cuda_error', 'unknown_worker_exit'):
+ # A first CUDA error in the decode phase comes after sampling finished: the
+ # sampling partitions a compatibility level changes did not fail, and the
+ # retry decodes the saved latents. A decode retry that fails again is
+ # recorded, since only a higher level changes the decoder.
+ repeated = bool(json.loads(row['details_json']).get('decision_evidence', {}).get('decode_resume'))
+ after_sampling = ((details or {}).get('kind') == 'cuda_error'
+ and (details or {}).get('failed_phase') == 'decode' and not repeated)
+ if (details or {}).get('kind') in ('cuda_error', 'unknown_worker_exit') and not after_sampling:
from .compatibility import Store
Store(self.path.parent).incident(self._row(row), details['kind'], evidence=details)
db.execute('DELETE FROM attempts WHERE id=?',(attempt_id,))