{"record":{"id":"f0a9ae5d566e20a6","repo":"unslothai/unsloth","slug":"error-invalid-unsloth-cpu-threads-value-configur","errorCode":null,"errorMessage":"Error: Invalid UNSLOTH_CPU_THREADS value {configured!r}: {exc}","messagePattern":"Error: Invalid UNSLOTH_CPU_THREADS value (.+?): (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"critical","filePath":"studio/backend/run.py","lineNumber":135,"sourceCode":"    os.execv(sys.executable, argv)\n\n\n# Suppress C-level dependency warnings globally (e.g. SwigPyPacked).\nos.environ[\"PYTHONWARNINGS\"] = \"ignore\"\n\n# Add the backend dir to sys.path early so local modules import.\nbackend_dir = Path(__file__).parent\nif str(backend_dir) not in sys.path:\n    sys.path.insert(0, str(backend_dir))\n\n# First, so these vars land before anything below can size an OpenMP/BLAS pool. Imports stdlib only.\nfrom utils.cpu_threads import configure_cpu_threads\n\ntry:\n    configure_cpu_threads()\nexcept ValueError as exc:\n    configured = os.environ.get(\"UNSLOTH_CPU_THREADS\")\n    raise SystemExit(f\"Error: Invalid UNSLOTH_CPU_THREADS value {configured!r}: {exc}\") from None\n\n# Windows ROCm ships no distributed backend, so torchao and the CUDA-only xformers both die on import,\n# taking diffusers/transformers with them. A stub only seeds a name nothing has imported yet, so both\n# must precede the first import below. No-op on other runtimes.\nfrom core._torchao_stub import (\n    install_torchao_windows_rocm_stub,\n    install_xformers_windows_rocm_stub,\n)\n\ninstall_xformers_windows_rocm_stub()\ninstall_torchao_windows_rocm_stub()\n\n# Anaconda/conda-forge Python: seed platform._sys_version_cache before imports\n# that trigger attrs -> rich -> structlog -> platform crash.\n# See: https://github.com/python/cpython/issues/102396\nimport _platform_compat  # noqa: F401\n\nfrom loggers import get_logger, install_uvicorn_duplicate_exception_filter","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/run.py#L117-L153","documentation":"Fatal startup error (SystemExit) from studio/backend/run.py: configure_cpu_threads() parsed the UNSLOTH_CPU_THREADS environment variable and raised ValueError because the value is not a positive integer. It runs before any heavy import so thread-pool sizing is correct; a bad value kills the process immediately with the offending value echoed.","triggerScenarios":"UNSLOTH_CPU_THREADS='4,', '0', '-2', 'four', '2.5', or an empty string exported before `unsloth studio` starts; a .env file with a stray quote; CI passing the var with whitespace or a unit ('8threads').","commonSituations":"Copy-pasted .env lines; docker-compose env with quoting errors; shell loops exporting computed values that occasionally produce empty strings.","solutions":["Unset or fix the variable to a plain positive integer: export UNSLOTH_CPU_THREADS=8.","Remove the line from .env/compose if thread pinning is not needed — absence is fine.","Sanitize in launch scripts: ${UNSLOTH_CPU_THREADS:-} guards or validate before export."],"exampleFix":"# before\nUNSLOTH_CPU_THREADS=\"8 threads\"\n\n# after\nUNSLOTH_CPU_THREADS=8","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\n# Validate before launching\nif [ -n \"${UNSLOTH_CPU_THREADS:-}\" ]; then\n  [[ \"$UNSLOTH_CPU_THREADS\" =~ ^[1-9][0-9]*$ ]] || { echo \"UNSLOTH_CPU_THREADS must be a positive integer, got '$UNSLOTH_CPU_THREADS'\"; exit 1; }\nfi\nexec unsloth studio \"$@\"","typeGuard":"def valid_cpu_threads(v: str | None) -> bool:\n    return v is None or (v.isdigit() and int(v) > 0)","tryCatchPattern":null,"preventionTips":["Keep .env entries to bare integers — no quotes, units, or trailing spaces","Validate numeric env vars in launch scripts and CI before export","Remember absence is valid: only a BAD value is fatal"],"tags":["startup","env-var","configuration","cpu-threads","system-exit"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}