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.

Resume the second pass after a CUDA error

Bowen Xue683313ead2d6
diff --git a/freevideo_engine/adaptive.py b/freevideo_engine/adaptive.py
index 234acb4..5be6329 100644
--- a/freevideo_engine/adaptive.py
+++ b/freevideo_engine/adaptive.py
@@ -41,6 +41,32 @@ def commit_exhausted(error):
return found(error)
+# A CUDA error that may leave the device itself unusable; never retried.
+DEVICE_STATE_ERRORS = ('cuda error: unknown error', 'device is lost', 'device lost', 'gpu is lost',
+ 'illegal memory access', 'device-side assert', 'unspecified launch failure', 'driver shutting down',
+ 'device has been removed', 'cuda error: launch timeout', 'the launch timed out',
+ 'cudaerrorillegaladdress', 'cudaerrorunknown')
+
+
+def second_pass_resumable(error, failure, metrics, attempts):
+ """A rejected, non-sticky CUDA call in the second pass, first pass retained.
+
+ The retry is one fresh process that loads the retained first pass and
+ repeats only the second pass with the same placement. A sticky device
+ error, an unconfirmed worker stop, a failure after sampling finished and
+ any earlier resumed attempt stay final; out-of-memory keeps its own path.
+ """
+ from .decode_resume import completed_sampling, refine_checkpoint_complete
+ if failure.get('kind') != 'code_error' or not isinstance(metrics, dict):
+ return False
+ recorded = str(metrics.get('error', '')).lower()
+ if not (cuda_runtime_error(error) or 'cuda error' in recorded) or 'out of memory' in recorded:
+ return False
+ if not refine_checkpoint_complete(metrics) or completed_sampling(metrics):
+ return False
+ return not any(row.get('decision', {}).get('second_pass_resume') for row in attempts)
+
+
def classify_failure(error, metrics=None):
"""Only positively identified resource failures are retriable.
@@ -55,10 +81,7 @@ def classify_failure(error, metrics=None):
attached = getattr(error, 'cleanup_errors', [])
cleanup += attached if isinstance(attached, list) else [attached]
text = '\n'.join([str(error), str(metrics.get('error', ''))] + [str(item) for item in cleanup]).lower()
- if any(part in text for part in ('cuda error: unknown error', 'device is lost', 'device lost',
- 'gpu is lost', 'illegal memory access', 'device-side assert', 'unspecified launch failure',
- 'driver shutting down', 'device has been removed', 'cuda error: launch timeout',
- 'the launch timed out', 'cudaerrorillegaladdress', 'cudaerrorunknown')) or details.get('kind') == 'cuda_error':
+ if any(part in text for part in DEVICE_STATE_ERRORS) or details.get('kind') == 'cuda_error':
kind, outcome, retry = 'cuda_error', 'discarded', False
elif getattr(error, 'worker_stop_confirmed', None) is False:
kind, outcome, retry = 'worker_stop_unconfirmed', 'discarded', False
@@ -628,17 +651,25 @@ def execute_attempts(history, identity, profile, canvas, launch, *,
history.finish(attempt, failure['outcome'], details=details)
row.update(state=failure['outcome'], failure=failure)
persist()
- if not automatic or not failure['retryable'] or index == max_retries:
+ resume = (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'
for r in report['resource_attempts'][:-1])
previous_gpu_retries = sum(r.get('failure', {}).get('kind') == 'gpu_oom'
for r in report['resource_attempts'][:-1])
from .decode_resume import completed_sampling
- updated, decision = next_placement(current, failure, (metrics or {}).get('phase', 'sample'), canvas,
- previous_ram_retries=previous_ram_retries,
- previous_gpu_retries=previous_gpu_retries,
- sampling_complete=completed_sampling(metrics))
+ if 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.',
+ numerical_class='unchanged', second_pass_resume=True)
+ else:
+ updated, decision = next_placement(current, failure, (metrics or {}).get('phase', 'sample'), canvas,
+ previous_ram_retries=previous_ram_retries,
+ previous_gpu_retries=previous_gpu_retries,
+ sampling_complete=completed_sampling(metrics))
if updated is None:
row['recovery_note'] = decision['reason']
persist()
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index 3d79a00..ff599ce 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -104,8 +104,11 @@ def child(command, env, descriptor, log, *, ram_budget_bytes=None, gpu=None, on_
except BaseException as stop_error:
# A stop timeout is not a controlled timeout. The worker may
# still own CUDA; never convert this into an ordinary retry.
- error.worker_stop_confirmed = False
- error.worker_stop_error = repr(stop_error)
+ # A worker observed gone afterwards owns nothing, whatever the
+ # signal call reported while it was exiting.
+ if not processes.gone(process):
+ error.worker_stop_confirmed = False
+ error.worker_stop_error = repr(stop_error)
error.telemetry = telemetry
raise
finally:
diff --git a/freevideo_engine/processes.py b/freevideo_engine/processes.py
index b91069f..54c3dce 100644
--- a/freevideo_engine/processes.py
+++ b/freevideo_engine/processes.py
@@ -163,6 +163,17 @@ def popen(command, *, pass_fds=(), supervise=False, **kwargs):
return subprocess.Popen(command, pass_fds=pass_fds, **kwargs)
+def gone(process):
+ """The worker process no longer exists, checked directly rather than by a signal."""
+ try:
+ if hasattr(process, 'created'):
+ from .resident_process import alive
+ return not alive(process.pid, process.created)
+ return process.poll() is not None
+ except BaseException:
+ return False
+
+
def stop(process, grace=10):
if hasattr(process, 'stop_request'):
return process.stop_request(grace=grace)