diff --git a/omlx/cli.py b/omlx/cli.py index 68682c6c76..b7c5a5ec65 100644 --- a/omlx/cli.py +++ b/omlx/cli.py @@ -301,8 +301,13 @@ def launch_command(args): host = args.host or settings.server.host port = args.port or settings.server.port + # 0.0.0.0 is a valid bind address but not a valid connect address. + # Fall back to localhost so launch can reach the server regardless + # of which interface it was bound to. + connect_host = host if host and host != "0.0.0.0" else "127.0.0.1" + # Check if oMLX server is running - base_url = f"http://{host}:{port}" + base_url = f"http://{connect_host}:{port}" try: resp = requests.get(f"{base_url}/health", timeout=3) resp.raise_for_status() @@ -380,7 +385,7 @@ def launch_command(args): port=port, api_key=api_key, model=model, - host=host, + host=connect_host, tools_profile=tools_profile, context_window=context_window, max_tokens=max_tokens, diff --git a/omlx/engine/batched.py b/omlx/engine/batched.py index 42b229594b..12d41de165 100644 --- a/omlx/engine/batched.py +++ b/omlx/engine/batched.py @@ -310,8 +310,21 @@ def _load_model_sync(): try: def _load_draft(): - draft_model, _ = load(specprefill_draft) - return draft_model + from ..patches.mlx_lm_mtp import set_mtp_active + + was_mtp = False + try: + from ..patches.mlx_lm_mtp import is_mtp_active + + was_mtp = is_mtp_active() + except Exception: + pass + set_mtp_active(False) + try: + draft_model, _ = load(specprefill_draft) + return draft_model + finally: + set_mtp_active(was_mtp) draft_model = await loop.run_in_executor( get_mlx_executor(), _load_draft diff --git a/omlx/engine/vlm.py b/omlx/engine/vlm.py index 77d28a8a3b..a4ccb19108 100644 --- a/omlx/engine/vlm.py +++ b/omlx/engine/vlm.py @@ -710,15 +710,28 @@ def _load_vlm_sync(): from ..utils.model_loading import maybe_load_custom_quantization def _load_draft(): - custom_loaded = maybe_load_custom_quantization( - specprefill_draft, - is_vlm=False, - ) - if custom_loaded is not None: - draft_model, _ = custom_loaded + from ..patches.mlx_lm_mtp import set_mtp_active + + was_mtp = False + try: + from ..patches.mlx_lm_mtp import is_mtp_active + + was_mtp = is_mtp_active() + except Exception: + pass + set_mtp_active(False) + try: + custom_loaded = maybe_load_custom_quantization( + specprefill_draft, + is_vlm=False, + ) + if custom_loaded is not None: + draft_model, _ = custom_loaded + return draft_model + draft_model, _ = mlx_lm_load(specprefill_draft) return draft_model - draft_model, _ = mlx_lm_load(specprefill_draft) - return draft_model + finally: + set_mtp_active(was_mtp) draft_model = await loop.run_in_executor(get_mlx_executor(), _load_draft) self._engine.engine.scheduler.set_specprefill_draft_model( draft_model, draft_model_name=specprefill_draft diff --git a/omlx/utils/model_loading.py b/omlx/utils/model_loading.py index 5b3299e863..6e5a926603 100644 --- a/omlx/utils/model_loading.py +++ b/omlx/utils/model_loading.py @@ -29,6 +29,13 @@ def maybe_apply_pre_load_patches( Safe to call repeatedly; the patches are idempotent. """ + # Reset the process-wide MTP flag so non-MTP-compatible models (or + # models with mtp_enabled=False) are not polluted by a prior model + # load that left the flag True. + from ..patches.mlx_lm_mtp import set_mtp_active + + set_mtp_active(False) + config_path = Path(model_name) / "config.json" if not config_path.exists(): return