Skip to content

Commit 9acc507

Browse files
committed
fix(core): disable swa_full for non-SWA models (sync llama.cpp upstream #20291)
- Fallback `context_params.swa_full` to False if `_n_swa == 0` and emit a warning. - Updated `is_hybrid` validation to use the resolved `self.context_params.swa_full` state.
1 parent 955ac33 commit 9acc507

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

llama_cpp/llama.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,22 @@ def __init__(
479479
_is_recurrent = self._model.is_recurrent()
480480
_is_hybrid = self._model.is_hybrid()
481481
_n_swa = self._model.n_swa()
482+
# Sync llama.cpp upstream (#20291): warn swa-full is not supported for non-SWA models.
483+
if _n_swa == 0:
484+
if (self.context_params.swa_full):
485+
self.context_params.swa_full = False
486+
if self.verbose:
487+
print("Llama.__init__: swa_full is not supported by this model, it will be disabled", file=sys.stderr)
488+
482489
# checkpoints are created only if:
483490
# - the model uses SWA and we are not using `swa_full`
484491
# - the model architecture is marked as recurrent or hybrid
485-
self.is_hybrid = _is_recurrent or _is_hybrid or (_n_swa > 0 and not swa_full)
492+
self.is_hybrid = _is_recurrent or _is_hybrid or (_n_swa > 0 and not self.context_params.swa_full)
486493

487494
if self.is_hybrid:
488495
if self.verbose:
489496
print(f"Llama.__init__: Hybrid/Recurrent model detected."
490-
f"(is_recurrent: {_is_recurrent}, is_hybrid: {_is_hybrid}, n_swa: {_n_swa}, swa_full: {swa_full}). "
497+
f"(is_recurrent: {_is_recurrent}, is_hybrid: {_is_hybrid}, n_swa: {_n_swa}, swa_full: {self.context_params.swa_full}). "
491498
f" Enabling HybridCheckpointCache(ctx_checkpoints={ctx_checkpoints}, checkpoint_interval={checkpoint_interval}).",
492499
file=sys.stderr)
493500
self.ctx_checkpoints = ctx_checkpoints

0 commit comments

Comments
 (0)