unslothai/unsloth · error · ValueError
Do not reserve system RAM must be true or false.
Error message
Do not reserve system RAM must be true or false.
What it means
Identical coercion guard for the second field: no_ram_reserve passes through _coerce_bool() and any non-None unrecognized value raises. It maps to the 'Do not reserve system RAM' toggle that influences llama.cpp's RAM reservation behavior at model load time.
Source
Thrown at studio/backend/utils/model_memory_settings.py:152
return pair
def set_model_memory_settings(
keep_resident: Any = None, no_ram_reserve: Any = None
) -> tuple[bool, bool]:
"""One-transaction write; ``None`` leaves a stored value untouched."""
updates: dict[str, bool] = {}
if keep_resident is not None:
parsed = _coerce_bool(keep_resident)
if parsed is None:
raise ValueError("Keep model in GPU memory must be true or false.")
updates[KEEP_RESIDENT_SETTING_KEY] = parsed
if no_ram_reserve is not None:
parsed = _coerce_bool(no_ram_reserve)
if parsed is None:
raise ValueError("Do not reserve system RAM must be true or false.")
updates[NO_RAM_RESERVE_SETTING_KEY] = parsed
if updates:
from storage.studio_db import upsert_app_settings
upsert_app_settings(updates)
_invalidate(*updates)
return get_keep_resident(), get_no_ram_reserve()
def memlock_limit_bytes() -> Optional[int]:
"""Soft RLIMIT_MEMLOCK, or None when unlimited or unavailable.
mlock cannot exceed this. Linux commonly defaults to 8 MB, where llama.cpp
logs "failed to mlock" and carries on, so residency would silently do
nothing. None on Windows (no RLIMIT_MEMLOCK) and on macOS (unlimited).
"""
try:View on GitHub (pinned to 203007d190)
Solutions
- Send a real boolean: set_model_memory_settings(no_ram_reserve=False)
- Normalize string flags client-side to booleans before the request
- Pass None to leave the stored value untouched
Example fix
# before set_model_memory_settings(no_ram_reserve='off') # ValueError: Do not reserve system RAM must be true or false. # after set_model_memory_settings(no_ram_reserve=False)
Defensive patterns
Strategy: type-guard
Validate before calling
def is_bool_like(v) -> bool:
return v is None or isinstance(v, bool) or v in (0, 1) or str(v).strip().lower() in ('true', 'false')
if not is_bool_like(payload.get('no_ram_reserve')):
return 400 'no_ram_reserve must be a boolean' Type guard
def coerce_bool_or_none(v):
if v is None or isinstance(v, bool):
return v
if isinstance(v, int) and v in (0, 1):
return bool(v)
if isinstance(v, str) and v.strip().lower() in ('true', 'false'):
return v.strip().lower() == 'true'
return None # caller rejects Try / catch
try:
set_model_memory_settings(no_ram_reserve=v)
except ValueError as e:
return 422 {'detail': str(e)} Prevention
- Validate both flag fields with the same boolean schema
- Document that None means 'unchanged', not false
When it happens
Trigger: set_model_memory_settings(no_ram_reserve='Y'), no_ram_reserve='toggle', or any value _coerce_bool cannot map to a bool. Fires independently of keep_resident — either field can raise on its own.
Common situations: Clients using localized truthy strings; form libraries emitting '1'/'0' strings where only a subset is accepted; copy-pasted payloads from a different API version with string flags.
Related errors
- Keep model in GPU memory must be true or false.
- Helper LLM startup pre-cache must be true or false.
- OpenAI auto-switch must be true or false.
- Keep KV on idle unload must be true or false.
- Auto-download missing models must be true or false.
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/0b7124724eaeccf7.
Report an issue: GitHub.