{"record":{"id":"84a2dabcedb8ae17","repo":"unslothai/unsloth","slug":"failed-to-export-lora-adapter","errorCode":null,"errorMessage":"Failed to export LoRA adapter","messagePattern":"Failed to export LoRA adapter","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"studio/backend/routes/export.py","lineNumber":479,"sourceCode":"\n        if not success:\n            raise HTTPException(status_code = 400, detail = message)\n\n        return ExportOperationResponse(\n            success = True,\n            message = message,\n            details = await asyncio.to_thread(_export_details, output_path, refresh_index = True),\n        )\n    except HTTPException:\n        raise\n    except Exception as e:\n        from utils.transformers_version import SidecarSwapInProgress\n\n        if isinstance(e, SidecarSwapInProgress):\n            # Expected loss of the race against a sidecar install: retryable 409.\n            raise HTTPException(status_code = 409, detail = str(e))\n        logger.error(f\"Error exporting LoRA adapter: {e}\", exc_info = True)\n        raise HTTPException(\n            status_code = 500,\n            detail = \"Failed to export LoRA adapter\",\n        )\n\n\n# Live export log stream (Server-Sent Events).\n#\n# The export worker's stdout/stderr is piped to the orchestrator as log\n# entries (core/export/worker.py, orchestrator.py); this endpoint streams\n# them to the browser for a live terminal panel during export operations.\n#\n# Shape follows routes/training.py::stream_training_progress: each event\n# carries id/event/data, the stream starts with a `retry:` directive, and\n# `Last-Event-ID` is honored on reconnect.\n\n\ndef _format_sse(\n    data: str,","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/export.py#L461-L497","documentation":"Generic 500 from the LoRA adapter export endpoint's catch-all. Deliberate failures arrive as (False, message) tuples (→400) and sidecar swaps as 409, so this 500 means an unexpected exception escaped backend.export_lora_adapter or the follow-up _export_details call. The true traceback is logged server-side as 'Error exporting LoRA adapter:' with exc_info.","triggerScenarios":"POST /export/lora where adapter serialization crashes (corrupt PEFT state, disk full writing adapter_model.safetensors), gguf conversion of the adapter fails unexpectedly (request.gguf=true), or the hub push raises from network/auth errors.","commonSituations":"Exporting an adapter whose training process crashed midway, requesting GGUF conversion of the adapter without the conversion toolchain present, or an expired hf_token raising inside the push path instead of returning a failure tuple.","solutions":["Inspect the backend log traceback — it identifies whether serialization, gguf conversion, or the hub push failed.","Re-save/reload the PEFT model if the adapter state is corrupt, or retrain briefly to regenerate it.","Retry with gguf=false and push_to_hub=false to isolate which stage fails.","Validate hf_token before export when pushing."],"exampleFix":"# before\nresp = client.post('/api/export/lora', json={'gguf': True})\n# 500 'Failed to export LoRA adapter'\n\n# after\nresp = client.post('/api/export/lora', json={'gguf': False})  # isolate the failure\n# check backend log; re-enable gguf only if conversion tooling is present","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await exportLora(body); }\ncatch (e) { if (e.status === 500) { captureBackendTraceback(); notify('LoRA export crashed — see backend log'); } }","preventionTips":["Export adapters immediately after successful training, before other state changes.","Disable gguf/push options first to isolate failing stages.","Keep hf_token fresh when pushing adapters to the hub."],"tags":["export","lora","http-500","peft"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}