Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions omlx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions omlx/engine/batched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions omlx/engine/vlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions omlx/utils/model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down