nufi-python 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nufi/__init__.py +52 -0
- nufi/auth.py +364 -0
- nufi/cli/__init__.py +0 -0
- nufi/cli/commands/__init__.py +1 -0
- nufi/cli/commands/auth.py +113 -0
- nufi/cli/commands/common.py +198 -0
- nufi/cli/commands/compiles.py +507 -0
- nufi/cli/commands/custom_evaluation_templates.py +206 -0
- nufi/cli/commands/datasets.py +697 -0
- nufi/cli/commands/evaluations.py +854 -0
- nufi/cli/commands/leaderboards.py +763 -0
- nufi/cli/commands/models.py +1347 -0
- nufi/cli/commands/monitoring.py +350 -0
- nufi/cli/commands/profile.py +123 -0
- nufi/cli/commands/projects.py +308 -0
- nufi/cli/commands/servings.py +306 -0
- nufi/cli/main.py +66 -0
- nufi/client.py +103 -0
- nufi/config.py +281 -0
- nufi/evaluator.py +559 -0
- nufi/exceptions.py +58 -0
- nufi/http_utils.py +51 -0
- nufi/models/__init__.py +185 -0
- nufi/models/compiles.py +79 -0
- nufi/models/custom_evaluation_templates.py +111 -0
- nufi/models/datasets.py +94 -0
- nufi/models/evaluations.py +253 -0
- nufi/models/leaderboards.py +178 -0
- nufi/models/monitoring.py +179 -0
- nufi/models/pagination.py +33 -0
- nufi/models/projects.py +32 -0
- nufi/models/registry.py +138 -0
- nufi/models/servings.py +27 -0
- nufi/py.typed +1 -0
- nufi/resources/__init__.py +34 -0
- nufi/resources/base.py +190 -0
- nufi/resources/compiles.py +193 -0
- nufi/resources/custom_evaluation_templates.py +126 -0
- nufi/resources/datasets.py +786 -0
- nufi/resources/evaluations.py +428 -0
- nufi/resources/leaderboards.py +413 -0
- nufi/resources/models.py +726 -0
- nufi/resources/monitoring.py +82 -0
- nufi/resources/projects.py +114 -0
- nufi/resources/servings.py +80 -0
- nufi/transport.py +248 -0
- nufi_python-1.0.0.dist-info/METADATA +228 -0
- nufi_python-1.0.0.dist-info/RECORD +52 -0
- nufi_python-1.0.0.dist-info/WHEEL +5 -0
- nufi_python-1.0.0.dist-info/entry_points.txt +2 -0
- nufi_python-1.0.0.dist-info/licenses/LICENSE +21 -0
- nufi_python-1.0.0.dist-info/top_level.txt +1 -0
nufi/models/registry.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RegisteredModel(BaseModel):
|
|
10
|
+
"""One registered model summary."""
|
|
11
|
+
|
|
12
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
13
|
+
|
|
14
|
+
id: int
|
|
15
|
+
name: str
|
|
16
|
+
description: str | None = None
|
|
17
|
+
author: str | None = None
|
|
18
|
+
version_count: int = Field(alias="versionCount")
|
|
19
|
+
created_at: datetime = Field(alias="createdAt")
|
|
20
|
+
updated_at: datetime = Field(alias="updatedAt")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ModelArtifact(BaseModel):
|
|
24
|
+
"""One model artifact returned by the model registry."""
|
|
25
|
+
|
|
26
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
27
|
+
|
|
28
|
+
id: int
|
|
29
|
+
name: str
|
|
30
|
+
format: str | None = None
|
|
31
|
+
platform: str | None = None
|
|
32
|
+
uri: str | None = None
|
|
33
|
+
storage_key: str | None = Field(default=None, alias="storageKey")
|
|
34
|
+
size_bytes: int | None = Field(default=None, alias="sizeBytes")
|
|
35
|
+
metadata: dict[str, Any] | None = None
|
|
36
|
+
architectures: list[str] = Field(default_factory=list)
|
|
37
|
+
compilation_run_id: int | None = Field(default=None, alias="compilationRunId")
|
|
38
|
+
source_type: str | None = Field(default=None, alias="sourceType")
|
|
39
|
+
source_optimizer_run_id: int | None = Field(
|
|
40
|
+
default=None, alias="sourceOptimizerRunId"
|
|
41
|
+
)
|
|
42
|
+
source_optimizer_trial_id: int | None = Field(
|
|
43
|
+
default=None, alias="sourceOptimizerTrialId"
|
|
44
|
+
)
|
|
45
|
+
promoted_at: datetime | None = Field(default=None, alias="promotedAt")
|
|
46
|
+
created_at: datetime | None = Field(default=None, alias="createdAt")
|
|
47
|
+
updated_at: datetime | None = Field(default=None, alias="updatedAt")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ModelArtifactCreate(BaseModel):
|
|
51
|
+
"""Artifact fields accepted by version and artifact creation."""
|
|
52
|
+
|
|
53
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
54
|
+
|
|
55
|
+
uri: str
|
|
56
|
+
name: str | None = None
|
|
57
|
+
format: str | None = None
|
|
58
|
+
platform: str | None = None
|
|
59
|
+
storage_key: str | None = Field(default=None, alias="storageKey")
|
|
60
|
+
size_bytes: int | None = Field(default=None, alias="sizeBytes")
|
|
61
|
+
metadata: dict[str, Any] | None = None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ModelVersion(BaseModel):
|
|
65
|
+
"""One registered model version."""
|
|
66
|
+
|
|
67
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
68
|
+
|
|
69
|
+
id: int
|
|
70
|
+
version: str
|
|
71
|
+
description: str | None = None
|
|
72
|
+
state: str
|
|
73
|
+
author: str | None = None
|
|
74
|
+
metadata: dict[str, Any] | None = None
|
|
75
|
+
source_type: str | None = Field(default=None, alias="sourceType")
|
|
76
|
+
source_ref: str | None = Field(default=None, alias="sourceRef")
|
|
77
|
+
artifacts: list[ModelArtifact] = Field(default_factory=list)
|
|
78
|
+
created_at: datetime = Field(alias="createdAt")
|
|
79
|
+
updated_at: datetime = Field(alias="updatedAt")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class ModelDetail(RegisteredModel):
|
|
83
|
+
"""A registered model with all currently returned versions."""
|
|
84
|
+
|
|
85
|
+
versions: list[ModelVersion] = Field(default_factory=list)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class ArtifactValidation(BaseModel):
|
|
89
|
+
"""Server validation result for a model artifact URI."""
|
|
90
|
+
|
|
91
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
92
|
+
|
|
93
|
+
uri: str
|
|
94
|
+
format: str
|
|
95
|
+
size_bytes: int | None = Field(default=None, alias="sizeBytes")
|
|
96
|
+
metadata: dict[str, Any] | None = None
|
|
97
|
+
resolved_root: str | None = Field(default=None, alias="resolvedRoot")
|
|
98
|
+
model_file_count: int | None = Field(default=None, alias="modelFileCount")
|
|
99
|
+
ambiguous_roots: list[str] = Field(default_factory=list, alias="ambiguousRoots")
|
|
100
|
+
warnings: list[str] = Field(default_factory=list)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ModelImport(BaseModel):
|
|
104
|
+
"""One Hugging Face or MLflow model import job."""
|
|
105
|
+
|
|
106
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
107
|
+
|
|
108
|
+
id: int
|
|
109
|
+
source_type: str = Field(alias="sourceType")
|
|
110
|
+
source_ref: str = Field(alias="sourceRef")
|
|
111
|
+
source_metadata: dict[str, Any] | None = Field(default=None, alias="sourceMetadata")
|
|
112
|
+
source_revision: str | None = Field(default=None, alias="sourceRevision")
|
|
113
|
+
source_commit: str | None = Field(default=None, alias="sourceCommit")
|
|
114
|
+
target_model: str = Field(alias="targetModel")
|
|
115
|
+
target_version: str = Field(alias="targetVersion")
|
|
116
|
+
storage_pvc: str = Field(alias="storagePvc")
|
|
117
|
+
state: str
|
|
118
|
+
error_message: str | None = Field(default=None, alias="errorMessage")
|
|
119
|
+
job_name: str | None = Field(default=None, alias="jobName")
|
|
120
|
+
artifact_uri: str | None = Field(default=None, alias="artifactUri")
|
|
121
|
+
completed_at: datetime | None = Field(default=None, alias="completedAt")
|
|
122
|
+
created_at: datetime = Field(alias="createdAt")
|
|
123
|
+
updated_at: datetime = Field(alias="updatedAt")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class HuggingFaceMapping(BaseModel):
|
|
127
|
+
"""A completed Hugging Face import mapping."""
|
|
128
|
+
|
|
129
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
130
|
+
|
|
131
|
+
target_model: str = Field(alias="targetModel")
|
|
132
|
+
target_version: str = Field(alias="targetVersion")
|
|
133
|
+
repository: str
|
|
134
|
+
revision: str
|
|
135
|
+
commit: str
|
|
136
|
+
artifact_uri: str = Field(alias="artifactUri")
|
|
137
|
+
import_job_id: int = Field(alias="importJobId")
|
|
138
|
+
imported_at: datetime = Field(alias="importedAt")
|
nufi/models/servings.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Serving(BaseModel):
|
|
9
|
+
model_config = ConfigDict(extra="allow", populate_by_name=True)
|
|
10
|
+
|
|
11
|
+
name: str
|
|
12
|
+
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
13
|
+
spec: dict[str, Any] = Field(default_factory=dict)
|
|
14
|
+
status: dict[str, Any] = Field(default_factory=dict)
|
|
15
|
+
endpoint: str | None = None
|
|
16
|
+
ready_replicas: int | None = Field(default=None, alias="readyReplicas")
|
|
17
|
+
desired_replicas: int | None = Field(default=None, alias="desiredReplicas")
|
|
18
|
+
deploy_status: str | None = Field(default=None, alias="deployStatus")
|
|
19
|
+
|
|
20
|
+
@model_validator(mode="before")
|
|
21
|
+
@classmethod
|
|
22
|
+
def default_name_from_metadata(cls, data: Any) -> Any:
|
|
23
|
+
if isinstance(data, dict) and not data.get("name"):
|
|
24
|
+
metadata = data.get("metadata")
|
|
25
|
+
if isinstance(metadata, dict) and metadata.get("name"):
|
|
26
|
+
data = {**data, "name": metadata["name"]}
|
|
27
|
+
return data
|
nufi/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from nufi.resources.compiles import CompilesResource
|
|
2
|
+
from nufi.resources.custom_evaluation_templates import CustomEvaluationTemplatesResource
|
|
3
|
+
from nufi.resources.datasets import DatasetsResource
|
|
4
|
+
from nufi.resources.evaluations import EvaluationMethodsResource, EvaluationsResource
|
|
5
|
+
from nufi.resources.leaderboards import LeaderboardsResource
|
|
6
|
+
from nufi.resources.monitoring import MonitoringResource
|
|
7
|
+
from nufi.resources.models import (
|
|
8
|
+
HuggingFaceImportsResource,
|
|
9
|
+
MLflowImportsResource,
|
|
10
|
+
ModelArtifactsResource,
|
|
11
|
+
ModelImportsResource,
|
|
12
|
+
ModelsResource,
|
|
13
|
+
ModelVersionsResource,
|
|
14
|
+
)
|
|
15
|
+
from nufi.resources.projects import ProjectsResource
|
|
16
|
+
from nufi.resources.servings import ServingsResource
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"CompilesResource",
|
|
20
|
+
"CustomEvaluationTemplatesResource",
|
|
21
|
+
"DatasetsResource",
|
|
22
|
+
"EvaluationMethodsResource",
|
|
23
|
+
"EvaluationsResource",
|
|
24
|
+
"LeaderboardsResource",
|
|
25
|
+
"HuggingFaceImportsResource",
|
|
26
|
+
"MLflowImportsResource",
|
|
27
|
+
"ModelArtifactsResource",
|
|
28
|
+
"ModelImportsResource",
|
|
29
|
+
"ModelsResource",
|
|
30
|
+
"ModelVersionsResource",
|
|
31
|
+
"MonitoringResource",
|
|
32
|
+
"ProjectsResource",
|
|
33
|
+
"ServingsResource",
|
|
34
|
+
]
|
nufi/resources/base.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import time
|
|
5
|
+
from collections.abc import Callable, Iterator
|
|
6
|
+
from typing import Any, TypeVar
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
from nufi.exceptions import APIError, ConfigurationError, NotFoundError
|
|
10
|
+
from nufi.models import Page, Project
|
|
11
|
+
from nufi.transport import SyncTransport
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
ProjectRef = int | str
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def escape_path(value: str) -> str:
|
|
19
|
+
return quote(value, safe="")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def response_json(response: Any) -> dict[str, Any]:
|
|
23
|
+
payload = response.json()
|
|
24
|
+
if not isinstance(payload, dict):
|
|
25
|
+
raise ValueError("Expected JSON object response from NuFi API.")
|
|
26
|
+
return payload
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class BaseResource:
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
transport: SyncTransport,
|
|
33
|
+
default_project: ProjectRef | None = None,
|
|
34
|
+
):
|
|
35
|
+
self._transport = transport
|
|
36
|
+
self._default_project = default_project
|
|
37
|
+
|
|
38
|
+
def _resolve_project_id(self, project: ProjectRef | None = None) -> int:
|
|
39
|
+
project = project if project is not None else self._default_project
|
|
40
|
+
if project is None:
|
|
41
|
+
raise ConfigurationError(
|
|
42
|
+
"No project is configured. Pass project= or construct NuFi with "
|
|
43
|
+
"a default project."
|
|
44
|
+
)
|
|
45
|
+
if isinstance(project, int):
|
|
46
|
+
return project
|
|
47
|
+
|
|
48
|
+
project = project.strip()
|
|
49
|
+
response = self._transport.get("/api/v1/projects")
|
|
50
|
+
projects = [
|
|
51
|
+
Project.model_validate(item)
|
|
52
|
+
for item in response_json(response).get("projects", [])
|
|
53
|
+
if isinstance(item, dict)
|
|
54
|
+
]
|
|
55
|
+
for candidate in projects:
|
|
56
|
+
if str(candidate.id) == project:
|
|
57
|
+
return candidate.id
|
|
58
|
+
for candidate in projects:
|
|
59
|
+
if candidate.name == project:
|
|
60
|
+
return candidate.id
|
|
61
|
+
raise NotFoundError(f"Project not found: {project}")
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def _pagination_params(
|
|
65
|
+
page: int | None,
|
|
66
|
+
limit: int | None,
|
|
67
|
+
*,
|
|
68
|
+
default_page: int | None = None,
|
|
69
|
+
default_limit: int | None = None,
|
|
70
|
+
) -> tuple[dict[str, int], int, int]:
|
|
71
|
+
resolved_page = page if page is not None else default_page
|
|
72
|
+
resolved_limit = limit if limit is not None else default_limit
|
|
73
|
+
if resolved_page is not None and resolved_page < 1:
|
|
74
|
+
raise ValueError("page must be at least 1")
|
|
75
|
+
if resolved_limit is not None and not 1 <= resolved_limit <= 100:
|
|
76
|
+
raise ValueError("limit must be between 1 and 100")
|
|
77
|
+
params = {}
|
|
78
|
+
if resolved_page is not None:
|
|
79
|
+
params["page"] = resolved_page
|
|
80
|
+
if resolved_limit is not None:
|
|
81
|
+
params["limit"] = resolved_limit
|
|
82
|
+
return params, resolved_page or 1, resolved_limit or 100
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def _page(
|
|
86
|
+
cls,
|
|
87
|
+
payload: dict[str, Any],
|
|
88
|
+
model: type[T],
|
|
89
|
+
*,
|
|
90
|
+
item_keys: tuple[str, ...] = ("items",),
|
|
91
|
+
page: int,
|
|
92
|
+
limit: int,
|
|
93
|
+
) -> Page[T]:
|
|
94
|
+
raw_items: list[Any] = []
|
|
95
|
+
for key in item_keys:
|
|
96
|
+
value = payload.get(key)
|
|
97
|
+
if isinstance(value, list):
|
|
98
|
+
raw_items = value
|
|
99
|
+
break
|
|
100
|
+
items = [model.model_validate(item) for item in raw_items]
|
|
101
|
+
normalized = {
|
|
102
|
+
key: value
|
|
103
|
+
for key, value in payload.items()
|
|
104
|
+
if key not in {*item_keys, "totalCount"}
|
|
105
|
+
}
|
|
106
|
+
return Page[T].model_validate(
|
|
107
|
+
{
|
|
108
|
+
**normalized,
|
|
109
|
+
"items": items,
|
|
110
|
+
"total": int(
|
|
111
|
+
payload.get("total", payload.get("totalCount", len(items)))
|
|
112
|
+
),
|
|
113
|
+
"page": int(payload.get("page", page)),
|
|
114
|
+
"limit": int(payload.get("limit", limit)),
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def _iter_all(
|
|
120
|
+
fetch: Callable[[int, int], Page[T]],
|
|
121
|
+
*,
|
|
122
|
+
limit: int = 100,
|
|
123
|
+
) -> Iterator[T]:
|
|
124
|
+
if not 1 <= limit <= 100:
|
|
125
|
+
raise ValueError("limit must be between 1 and 100")
|
|
126
|
+
page_number = 1
|
|
127
|
+
yielded = 0
|
|
128
|
+
seen_pages: set[int] = set()
|
|
129
|
+
seen_items: set[tuple[type[Any], Any]] = set()
|
|
130
|
+
while True:
|
|
131
|
+
page = fetch(page_number, limit)
|
|
132
|
+
if page.page in seen_pages:
|
|
133
|
+
raise APIError(f"Pagination returned repeated page {page.page}.")
|
|
134
|
+
seen_pages.add(page.page)
|
|
135
|
+
if not page.items:
|
|
136
|
+
if yielded < page.total:
|
|
137
|
+
raise APIError("Pagination made no progress before reaching total.")
|
|
138
|
+
return
|
|
139
|
+
new_items = []
|
|
140
|
+
for item in page.items:
|
|
141
|
+
identity = BaseResource._item_identity(item)
|
|
142
|
+
if identity not in seen_items:
|
|
143
|
+
seen_items.add(identity)
|
|
144
|
+
new_items.append(item)
|
|
145
|
+
if not new_items:
|
|
146
|
+
raise APIError("Pagination made no progress before reaching total.")
|
|
147
|
+
yield from new_items
|
|
148
|
+
yielded += len(new_items)
|
|
149
|
+
if yielded >= page.total or len(page.items) < page.limit:
|
|
150
|
+
return
|
|
151
|
+
page_number += 1
|
|
152
|
+
|
|
153
|
+
@staticmethod
|
|
154
|
+
def _item_identity(item: T) -> tuple[type[Any], Any]:
|
|
155
|
+
for attribute in ("id", "submission_id"):
|
|
156
|
+
if (item_id := getattr(item, attribute, None)) is not None:
|
|
157
|
+
return type(item), str(item_id)
|
|
158
|
+
try:
|
|
159
|
+
hash(item)
|
|
160
|
+
except TypeError:
|
|
161
|
+
return type(item), repr(item)
|
|
162
|
+
return type(item), item
|
|
163
|
+
|
|
164
|
+
@staticmethod
|
|
165
|
+
def _wait(
|
|
166
|
+
fetch: Callable[[], T],
|
|
167
|
+
state: Callable[[T], str | None],
|
|
168
|
+
terminal_states: frozenset[str],
|
|
169
|
+
*,
|
|
170
|
+
target: str,
|
|
171
|
+
timeout: float,
|
|
172
|
+
interval: float,
|
|
173
|
+
) -> T:
|
|
174
|
+
if not math.isfinite(timeout) or timeout <= 0:
|
|
175
|
+
raise ValueError("timeout must be greater than 0")
|
|
176
|
+
if not math.isfinite(interval) or interval <= 0:
|
|
177
|
+
raise ValueError("interval must be greater than 0")
|
|
178
|
+
deadline = time.monotonic() + timeout
|
|
179
|
+
while True:
|
|
180
|
+
item = fetch()
|
|
181
|
+
current = state(item)
|
|
182
|
+
if current in terminal_states:
|
|
183
|
+
return item
|
|
184
|
+
remaining = deadline - time.monotonic()
|
|
185
|
+
if remaining <= 0:
|
|
186
|
+
raise TimeoutError(
|
|
187
|
+
f"Timed out waiting for {target}; "
|
|
188
|
+
f"last state: {current or 'unknown'}"
|
|
189
|
+
)
|
|
190
|
+
time.sleep(min(interval, remaining))
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from nufi.models import CompileListResponse, CompileRun, Page
|
|
7
|
+
from nufi.resources.base import BaseResource, ProjectRef, escape_path, response_json
|
|
8
|
+
|
|
9
|
+
_TERMINAL_PHASES = frozenset({"Registered", "Failed", "RegistrationFailed"})
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CompilesResource(BaseResource):
|
|
13
|
+
def list(
|
|
14
|
+
self,
|
|
15
|
+
*,
|
|
16
|
+
project: ProjectRef | None = None,
|
|
17
|
+
model_name: str | None = None,
|
|
18
|
+
version: str | None = None,
|
|
19
|
+
phase: str | list[str] | None = None,
|
|
20
|
+
page: int | None = None,
|
|
21
|
+
limit: int | None = None,
|
|
22
|
+
) -> list[CompileRun]:
|
|
23
|
+
project_id = self._resolve_project_id(project)
|
|
24
|
+
params, _, _ = self._pagination_params(page, limit)
|
|
25
|
+
if model_name:
|
|
26
|
+
params["modelName"] = model_name
|
|
27
|
+
if version:
|
|
28
|
+
params["version"] = version
|
|
29
|
+
if phase:
|
|
30
|
+
params["phase"] = ",".join(phase) if isinstance(phase, list) else phase
|
|
31
|
+
response = self._transport.get(
|
|
32
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines",
|
|
33
|
+
params=params,
|
|
34
|
+
)
|
|
35
|
+
return CompileListResponse.model_validate(response_json(response)).items
|
|
36
|
+
|
|
37
|
+
def list_page(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
project: ProjectRef | None = None,
|
|
41
|
+
model_name: str | None = None,
|
|
42
|
+
version: str | None = None,
|
|
43
|
+
phase: str | list[str] | None = None,
|
|
44
|
+
page: int | None = None,
|
|
45
|
+
limit: int | None = None,
|
|
46
|
+
) -> Page[CompileRun]:
|
|
47
|
+
"""Return one compile-run page with normalized pagination metadata."""
|
|
48
|
+
project_id = self._resolve_project_id(project)
|
|
49
|
+
params, resolved_page, resolved_limit = self._pagination_params(
|
|
50
|
+
page, limit, default_page=1, default_limit=100
|
|
51
|
+
)
|
|
52
|
+
if model_name:
|
|
53
|
+
params["modelName"] = model_name
|
|
54
|
+
if version:
|
|
55
|
+
params["version"] = version
|
|
56
|
+
if phase:
|
|
57
|
+
params["phase"] = ",".join(phase) if isinstance(phase, list) else phase
|
|
58
|
+
response = self._transport.get(
|
|
59
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines",
|
|
60
|
+
params=params,
|
|
61
|
+
)
|
|
62
|
+
return self._page(
|
|
63
|
+
response_json(response),
|
|
64
|
+
CompileRun,
|
|
65
|
+
page=resolved_page,
|
|
66
|
+
limit=resolved_limit,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def iter_all(
|
|
70
|
+
self,
|
|
71
|
+
*,
|
|
72
|
+
project: ProjectRef | None = None,
|
|
73
|
+
model_name: str | None = None,
|
|
74
|
+
version: str | None = None,
|
|
75
|
+
phase: str | list[str] | None = None,
|
|
76
|
+
limit: int = 100,
|
|
77
|
+
) -> Iterator[CompileRun]:
|
|
78
|
+
"""Iterate all matching compile runs in server order."""
|
|
79
|
+
return self._iter_all(
|
|
80
|
+
lambda page, page_limit: self.list_page(
|
|
81
|
+
project=project,
|
|
82
|
+
model_name=model_name,
|
|
83
|
+
version=version,
|
|
84
|
+
phase=phase,
|
|
85
|
+
page=page,
|
|
86
|
+
limit=page_limit,
|
|
87
|
+
),
|
|
88
|
+
limit=limit,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def create(
|
|
92
|
+
self,
|
|
93
|
+
*,
|
|
94
|
+
project: ProjectRef | None = None,
|
|
95
|
+
model_name: str,
|
|
96
|
+
version: str,
|
|
97
|
+
artifact_name: str | None = None,
|
|
98
|
+
tensor_parallel_size: int | None = None,
|
|
99
|
+
pipeline_parallel_size: int | None = None,
|
|
100
|
+
max_model_len: int | None = None,
|
|
101
|
+
optim_level: str | None = None,
|
|
102
|
+
cpu_request: str | None = None,
|
|
103
|
+
memory_request: str | None = None,
|
|
104
|
+
extra_args: str | list[str] | None = None,
|
|
105
|
+
env: list[dict[str, Any]] | None = None,
|
|
106
|
+
) -> CompileRun:
|
|
107
|
+
project_id = self._resolve_project_id(project)
|
|
108
|
+
compile_payload: dict[str, Any] = {}
|
|
109
|
+
for key, value in {
|
|
110
|
+
"tensorParallelSize": tensor_parallel_size,
|
|
111
|
+
"pipelineParallelSize": pipeline_parallel_size,
|
|
112
|
+
"maxModelLen": max_model_len,
|
|
113
|
+
"optimLevel": optim_level,
|
|
114
|
+
"cpuRequest": cpu_request,
|
|
115
|
+
"memoryRequest": memory_request,
|
|
116
|
+
"extraArgs": extra_args,
|
|
117
|
+
"env": env,
|
|
118
|
+
}.items():
|
|
119
|
+
if value is not None:
|
|
120
|
+
compile_payload[key] = value
|
|
121
|
+
|
|
122
|
+
payload: dict[str, Any] = {
|
|
123
|
+
"modelName": model_name,
|
|
124
|
+
"version": version,
|
|
125
|
+
"platform": "rngd",
|
|
126
|
+
"compile": compile_payload,
|
|
127
|
+
}
|
|
128
|
+
if artifact_name is not None:
|
|
129
|
+
payload["artifactName"] = artifact_name
|
|
130
|
+
|
|
131
|
+
response = self._transport.post(
|
|
132
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines",
|
|
133
|
+
json=payload,
|
|
134
|
+
)
|
|
135
|
+
return CompileRun.model_validate(response_json(response))
|
|
136
|
+
|
|
137
|
+
def get(self, name: str, *, project: ProjectRef | None = None) -> CompileRun:
|
|
138
|
+
project_id = self._resolve_project_id(project)
|
|
139
|
+
response = self._transport.get(
|
|
140
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines/{escape_path(name)}"
|
|
141
|
+
)
|
|
142
|
+
return CompileRun.model_validate(response_json(response))
|
|
143
|
+
|
|
144
|
+
def get_by_id(
|
|
145
|
+
self, run_id: int, *, project: ProjectRef | None = None
|
|
146
|
+
) -> CompileRun:
|
|
147
|
+
project_id = self._resolve_project_id(project)
|
|
148
|
+
response = self._transport.get(
|
|
149
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines/id/{run_id}"
|
|
150
|
+
)
|
|
151
|
+
return CompileRun.model_validate(response_json(response))
|
|
152
|
+
|
|
153
|
+
def wait(
|
|
154
|
+
self,
|
|
155
|
+
target: str | int,
|
|
156
|
+
*,
|
|
157
|
+
project: ProjectRef | None = None,
|
|
158
|
+
timeout: float = 1800,
|
|
159
|
+
interval: float = 5,
|
|
160
|
+
) -> CompileRun:
|
|
161
|
+
"""Wait for a compile run by CR name or numeric ID using only its GET route."""
|
|
162
|
+
return self._wait(
|
|
163
|
+
lambda: (
|
|
164
|
+
self.get_by_id(target, project=project)
|
|
165
|
+
if isinstance(target, int)
|
|
166
|
+
else self.get(target, project=project)
|
|
167
|
+
),
|
|
168
|
+
lambda run: "RegistrationFailed" if run.registration_error else run.phase,
|
|
169
|
+
_TERMINAL_PHASES,
|
|
170
|
+
target=f"compile run {target}",
|
|
171
|
+
timeout=timeout,
|
|
172
|
+
interval=interval,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def retry(
|
|
176
|
+
self,
|
|
177
|
+
name: str,
|
|
178
|
+
step_name: str,
|
|
179
|
+
*,
|
|
180
|
+
project: ProjectRef | None = None,
|
|
181
|
+
) -> dict[str, Any]:
|
|
182
|
+
project_id = self._resolve_project_id(project)
|
|
183
|
+
response = self._transport.post(
|
|
184
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines/"
|
|
185
|
+
f"{escape_path(name)}/steps/{escape_path(step_name)}/retry"
|
|
186
|
+
)
|
|
187
|
+
return response_json(response)
|
|
188
|
+
|
|
189
|
+
def delete(self, name: str, *, project: ProjectRef | None = None) -> None:
|
|
190
|
+
project_id = self._resolve_project_id(project)
|
|
191
|
+
self._transport.delete(
|
|
192
|
+
f"/api/v1/projects/{project_id}/npu-porting-pipelines/{escape_path(name)}"
|
|
193
|
+
)
|