sgl-project/sglang · error · ImportError
ModelOpt export functionality is not available. Please ensur
Error message
ModelOpt export functionality is not available. Please ensure you have the latest version of modelopt installed.
What it means
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.
Source
Thrown at python/sglang/srt/model_loader/loader.py:3870
) -> None:
"""
Export the quantized model to HuggingFace format using ModelOpt export API.
Args:
model: The quantized model to export
export_path: Directory path to export the model to
model_path: Path to the original model (for tokenizer export)
trust_remote_code: Whether to trust remote code for tokenizer loading
Raises:
ImportError: If ModelOpt export functionality is not available
Exception: If export fails
"""
try:
from modelopt.torch.export import export_hf_checkpoint
from transformers import AutoTokenizer
except ImportError as e:
raise ImportError(
"ModelOpt export functionality is not available. "
"Please ensure you have the latest version of modelopt installed."
) from e
# Create export directory if it doesn't exist
os.makedirs(export_path, exist_ok=True)
# Export the quantized model
export_hf_checkpoint(model, export_dir=export_path)
# Export the tokenizer if model_path is provided
if model_path:
try:
tokenizer = AutoTokenizer.from_pretrained(
model_path, trust_remote_code=trust_remote_code
)
tokenizer.save_pretrained(export_path)
rank0_log(f"Tokenizer exported to {export_path}")View on GitHub (pinned to 0132848349)
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
Example fix
# before pip install nvidia-modelopt==0.09 # lacks export API python -m sglang.launch_server --load-format modelopt --modelopt-export-path ./out # after pip install -U nvidia-modelopt python -m sglang.launch_server --load-format modelopt --modelopt-export-path ./out
Defensive patterns
Strategy: validation
Validate before calling
def modelopt_export_available() -> bool:
try:
from modelopt.torch.export import export_hf_checkpoint # noqa
import transformers # noqa
return True
except ImportError:
return False
if export_path and not modelopt_export_available():
raise SystemExit("Upgrade nvidia-modelopt to use --modelopt-export-path") Try / catch
try:
server.launch(args_with_export)
except ImportError as e:
if "ModelOpt export" in str(e): print("pip install -U nvidia-modelopt"); raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: Pinning an old modelopt version; using a modelopt wheel built without export extras; transformers missing is also caught by the same try block.
Related errors
- Failed to import 'set_transfer_engine' from 'mooncake.pg'. P
- ModelOpt is not available. Please install modelopt.
- ModelOpt quantization config '{quant_cfg_name}' not found. P
- Failed to load serve backend {name!r} from {self._entry_poin
- Serve backend {name!r} uses API version {backend.api_version
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/22016c9b5c493289.
Report an issue: GitHub.