{"record":{"id":"22016c9b5c493289","repo":"sgl-project/sglang","slug":"modelopt-export-functionality-is-not-available-pl","errorCode":null,"errorMessage":"ModelOpt export functionality is not available. Please ensure you have the latest version of modelopt installed.","messagePattern":"ModelOpt export functionality is not available\\. Please ensure you have the latest version of modelopt installed\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/model_loader/loader.py","lineNumber":3870,"sourceCode":"    ) -> None:\n        \"\"\"\n        Export the quantized model to HuggingFace format using ModelOpt export API.\n\n        Args:\n            model: The quantized model to export\n            export_path: Directory path to export the model to\n            model_path: Path to the original model (for tokenizer export)\n            trust_remote_code: Whether to trust remote code for tokenizer loading\n\n        Raises:\n            ImportError: If ModelOpt export functionality is not available\n            Exception: If export fails\n        \"\"\"\n        try:\n            from modelopt.torch.export import export_hf_checkpoint\n            from transformers import AutoTokenizer\n        except ImportError as e:\n            raise ImportError(\n                \"ModelOpt export functionality is not available. \"\n                \"Please ensure you have the latest version of modelopt installed.\"\n            ) from e\n\n        # Create export directory if it doesn't exist\n        os.makedirs(export_path, exist_ok=True)\n\n        # Export the quantized model\n        export_hf_checkpoint(model, export_dir=export_path)\n\n        # Export the tokenizer if model_path is provided\n        if model_path:\n            try:\n                tokenizer = AutoTokenizer.from_pretrained(\n                    model_path, trust_remote_code=trust_remote_code\n                )\n                tokenizer.save_pretrained(export_path)\n                rank0_log(f\"Tokenizer exported to {export_path}\")","sourceCodeStart":3852,"sourceCodeEnd":3888,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/model_loader/loader.py#L3852-L3888","documentation":"The ModelOpt export path (_maybe_export_modelopt) imports `export_hf_checkpoint` from modelopt.torch.export; older modelopt releases do not have that module, so the import fails and is re-raised as this ImportError. It means your installed modelopt version is too old (or too minimal) to export a HuggingFace checkpoint.","triggerScenarios":"Running sglang with a ModelOpt load format plus an export path (e.g. --modelopt-export-path / --json-model-override-args with export_path) while the installed nvidia-modelopt lacks modelopt.torch.export.export_hf_checkpoint.","commonSituations":"Pinning an old modelopt version; using a modelopt wheel built without export extras; transformers missing is also caught by the same try block.","solutions":["Upgrade modelopt: pip install -U nvidia-modelopt (export API exists in recent releases)","Verify: python -c \"from modelopt.torch.export import export_hf_checkpoint\"","Ensure transformers is installed/importable since it's imported in the same try block","If you don't need export, remove the export path argument"],"exampleFix":"# before\npip install nvidia-modelopt==0.09  # lacks export API\npython -m sglang.launch_server --load-format modelopt --modelopt-export-path ./out\n\n# after\npip install -U nvidia-modelopt\npython -m sglang.launch_server --load-format modelopt --modelopt-export-path ./out","handlingStrategy":"validation","validationCode":"def modelopt_export_available() -> bool:\n    try:\n        from modelopt.torch.export import export_hf_checkpoint  # noqa\n        import transformers  # noqa\n        return True\n    except ImportError:\n        return False\n\nif export_path and not modelopt_export_available():\n    raise SystemExit(\"Upgrade nvidia-modelopt to use --modelopt-export-path\")","typeGuard":null,"tryCatchPattern":"try:\n    server.launch(args_with_export)\nexcept ImportError as e:\n    if \"ModelOpt export\" in str(e): print(\"pip install -U nvidia-modelopt\"); raise","preventionTips":["Check for the export API before enabling export_path","Keep modelopt upgraded in lockstep with sglang","Don't request export on clusters with old pinned modelopt wheels"],"tags":["modelopt","export","version-mismatch","import-error","sglang"],"backgroundTag":"package-version-incompatibility","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}