Skip to content

Commit

Permalink
Update state.json migration on gateways (#2152)
Browse files Browse the repository at this point in the history
The updated migration will handle inconsistent
`state.json` with models present in service
details but missing in the models index, most
likely due to a bug. Such models are now ignored.
  • Loading branch information
jvstme authored Dec 27, 2024
1 parent aca56fe commit 361891c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/dstack/_internal/proxy/gateway/repo/state_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from datetime import datetime
from pathlib import Path
from typing import Iterable
from typing import Iterable, Optional

from dstack._internal.core.models.instances import SSHConnectionParams
from dstack._internal.proxy.gateway.models import ACMESettings, GlobalProxyConfig, ModelEntrypoint
Expand Down Expand Up @@ -75,7 +75,8 @@ def get_services_models(
parsed_model = parse_model(
project_name, parsed_service.run_name, model, state_v1["openai"]["index"]
)
models.setdefault(project_name, {})[parsed_model.name] = parsed_model
if parsed_model is not None:
models.setdefault(project_name, {})[parsed_model.name] = parsed_model

return services, models

Expand All @@ -100,8 +101,15 @@ def parse_replica(replica: dict) -> Replica:
)


def parse_model(project_name: str, run_name: str, model: dict, openai_index: dict) -> ChatModel:
created_ts = openai_index[project_name]["chat"][model["name"]]["created"]
def parse_model(
project_name: str, run_name: str, model: dict, openai_index: dict
) -> Optional[ChatModel]:
created_ts = (
openai_index.get(project_name, {}).get("chat", {}).get(model["name"], {}).get("created")
)
if created_ts is None:
# some models can be missing in the index, most likely due to a bug
return None
format_spec: AnyModelFormat
if model["format"] == "tgi":
format_spec = TGIChatModelFormat(
Expand Down

0 comments on commit 361891c

Please sign in to comment.