infixspeed-cli 0.0.16__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.
- infix_cli/__init__.py +5 -0
- infix_cli/__main__.py +6 -0
- infix_cli/agent-guide.txt +71 -0
- infix_cli/cli_framework.py +96 -0
- infix_cli/command_contract.py +157 -0
- infix_cli/commands/__init__.py +1 -0
- infix_cli/commands/_artifacts.py +142 -0
- infix_cli/commands/_comparison.py +443 -0
- infix_cli/commands/_confirm.py +26 -0
- infix_cli/commands/_control.py +290 -0
- infix_cli/commands/_create.py +351 -0
- infix_cli/commands/_create_output.py +139 -0
- infix_cli/commands/_delete.py +288 -0
- infix_cli/commands/_download.py +459 -0
- infix_cli/commands/_fusion_common.py +191 -0
- infix_cli/commands/_fusion_config.py +394 -0
- infix_cli/commands/_fusion_feedback.py +319 -0
- infix_cli/commands/_fusion_tasks.py +507 -0
- infix_cli/commands/_fusion_tensorboard.py +132 -0
- infix_cli/commands/_jobs.py +312 -0
- infix_cli/commands/_logs.py +210 -0
- infix_cli/commands/_publish.py +123 -0
- infix_cli/commands/_register.py +600 -0
- infix_cli/commands/_register_output.py +231 -0
- infix_cli/commands/_storage_tree.py +62 -0
- infix_cli/commands/admin.py +668 -0
- infix_cli/commands/asset.py +2012 -0
- infix_cli/commands/auth.py +246 -0
- infix_cli/commands/deploy.py +850 -0
- infix_cli/commands/evaluation.py +360 -0
- infix_cli/commands/examples.py +138 -0
- infix_cli/commands/fusion.py +1842 -0
- infix_cli/commands/merge.py +709 -0
- infix_cli/commands/resource.py +127 -0
- infix_cli/commands/spark.py +347 -0
- infix_cli/commands/storage.py +329 -0
- infix_cli/commands/training.py +748 -0
- infix_cli/config.py +311 -0
- infix_cli/config_input.py +217 -0
- infix_cli/context.py +84 -0
- infix_cli/discovery.py +459 -0
- infix_cli/domain/__init__.py +1 -0
- infix_cli/domain/dto/__init__.py +6 -0
- infix_cli/domain/dto/admin.py +413 -0
- infix_cli/domain/dto/asset.py +390 -0
- infix_cli/domain/dto/common.py +136 -0
- infix_cli/domain/dto/evaluation.py +296 -0
- infix_cli/domain/dto/logs.py +98 -0
- infix_cli/domain/dto/resource.py +108 -0
- infix_cli/domain/dto/serving.py +156 -0
- infix_cli/domain/dto/spark.py +241 -0
- infix_cli/domain/dto/storage.py +75 -0
- infix_cli/domain/dto/training.py +272 -0
- infix_cli/domain/enums.py +359 -0
- infix_cli/domain/hyperparams.py +190 -0
- infix_cli/domain/refs.py +108 -0
- infix_cli/domain/resolve.py +619 -0
- infix_cli/errors.py +158 -0
- infix_cli/example_data/__init__.py +1 -0
- infix_cli/example_data/fusion/README.md +128 -0
- infix_cli/example_data/fusion/fusion.json +149 -0
- infix_cli/example_data/fusion/prompts/code.jsonl +16 -0
- infix_cli/example_data/fusion/prompts/math.jsonl +16 -0
- infix_cli/example_data/fusion.zip +0 -0
- infix_cli/example_data/merge/README.md +89 -0
- infix_cli/example_data/merge/merge.json +26 -0
- infix_cli/example_data/merge.zip +0 -0
- infix_cli/http/__init__.py +1 -0
- infix_cli/http/browser_auth.py +160 -0
- infix_cli/http/client.py +575 -0
- infix_cli/http/pagination.py +84 -0
- infix_cli/http/upload.py +254 -0
- infix_cli/main.py +432 -0
- infix_cli/pipeline_config_schema.py +122 -0
- infix_cli/render/__init__.py +79 -0
- infix_cli/render/json_out.py +123 -0
- infix_cli/render/progress.py +62 -0
- infix_cli/render/text.py +233 -0
- infix_cli/update_check.py +177 -0
- infix_cli/waiter.py +93 -0
- infix_cli/workspace.py +158 -0
- infixspeed_cli-0.0.16.dist-info/METADATA +58 -0
- infixspeed_cli-0.0.16.dist-info/RECORD +85 -0
- infixspeed_cli-0.0.16.dist-info/WHEEL +4 -0
- infixspeed_cli-0.0.16.dist-info/entry_points.txt +2 -0
infix_cli/__init__.py
ADDED
infix_cli/__main__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
InfiXspeed CLI — Agent integration
|
|
2
|
+
|
|
3
|
+
1. Discover the installed CLI
|
|
4
|
+
infix capabilities --groups
|
|
5
|
+
infix examples list
|
|
6
|
+
infix examples show fusion -o text
|
|
7
|
+
infix examples show merge -o text
|
|
8
|
+
infix schema fusion run
|
|
9
|
+
infix schema merge create
|
|
10
|
+
Use infix capabilities GROUP and infix schema COMMAND for other workflows.
|
|
11
|
+
The index covers the installed CLI. Cache discovery by CLI and contract version.
|
|
12
|
+
|
|
13
|
+
2. Authenticate and resolve inputs
|
|
14
|
+
For interactive use, start infix auth login to authorize in the browser.
|
|
15
|
+
Add --api-url with the platform URL for a non-default deployment.
|
|
16
|
+
In a sandbox or remote terminal, use infix auth login --no-browser. Read
|
|
17
|
+
the approval link and verification code from stderr while login is running.
|
|
18
|
+
Open the link in the user's browser or share it with them. Keep the command
|
|
19
|
+
running while the user checks the code, selects a workspace and approves.
|
|
20
|
+
Use an API key for explicitly configured automation. Pass --api-key or set
|
|
21
|
+
INFIX_API_KEY for that workflow. Clear INFIX_API_KEY for an interactive login
|
|
22
|
+
when the terminal inherits an automation key.
|
|
23
|
+
After login succeeds, use infix doctor to verify identity and workspace
|
|
24
|
+
access. Available models, hardware and features depend on the deployment and
|
|
25
|
+
the approved workspace.
|
|
26
|
+
Use asset model list, asset dataset list, and resource list --task training
|
|
27
|
+
to find available inputs. Check asset versions before choosing a version.
|
|
28
|
+
Use official/NAME, workspace/NAME:VERSION or storage/PATH where supported.
|
|
29
|
+
Prefer fixed versions for reproducible submissions.
|
|
30
|
+
For Fusion/Merge, use fusion parameters or merge methods for live parameters.
|
|
31
|
+
Export editable recipes with infix examples export fusion --dir ./fusion-demo
|
|
32
|
+
or infix examples export merge --dir ./merge-demo. Replace placeholders. In
|
|
33
|
+
JSON output, examples show returns the requested file in content. Use -o text
|
|
34
|
+
to redirect the original file contents.
|
|
35
|
+
|
|
36
|
+
3. Preview and submit
|
|
37
|
+
Read the command's input_modes or config_rules. For structured config, start
|
|
38
|
+
the process with an argv array and send JSON on stdin:
|
|
39
|
+
infix training create --config - --dry-run
|
|
40
|
+
Close stdin after writing the document. Use the same inputs when submitting
|
|
41
|
+
without --dry-run. Follow the command's confirmation rules for writes.
|
|
42
|
+
Preview resolves inputs. When server_admission is not_checked, capacity and
|
|
43
|
+
admission will be decided at submission. Use a unique, recorded task name.
|
|
44
|
+
Start Fusion with fusion run --config fusion.json --to split --dry-run and
|
|
45
|
+
submit the same stage range after reviewing the plan. Use --to opd for a
|
|
46
|
+
full-plan preview when preparing training. For Merge, use merge create
|
|
47
|
+
--config merge.json --dry-run, then submit the same configuration.
|
|
48
|
+
|
|
49
|
+
4. Capture results and follow progress
|
|
50
|
+
Keep exit status, stdout and stderr separate, including on failure.
|
|
51
|
+
Business output defaults to JSON. Read schema.output for known result
|
|
52
|
+
fields, logs formats and workflow commands. Parse NDJSON one line at a time.
|
|
53
|
+
Help, completion and explicitly selected text output use their own formats.
|
|
54
|
+
Use --verbose only for diagnostics. It also writes request traces to stderr.
|
|
55
|
+
Submit asynchronously, save the returned ID, then use the schema's query_argv
|
|
56
|
+
with that ID. Inspect status and the documented completion conditions.
|
|
57
|
+
For Fusion, also retain the execution number to select the same logical run.
|
|
58
|
+
For Fusion and Merge, stages[].status shows whether the stage has started.
|
|
59
|
+
Prefer polling with backoff or an explicit wait command. Local timeout or
|
|
60
|
+
interruption leaves remote work running.
|
|
61
|
+
|
|
62
|
+
5. Recover
|
|
63
|
+
INVALID_ARGUMENT: use error.details and the command schema to fix the input.
|
|
64
|
+
CONFIRMATION_REQUIRED: inspect the resources and confirm through the caller
|
|
65
|
+
before supplying the stated flag.
|
|
66
|
+
WAIT_TIMEOUT: query the existing task using its ID or the reported hint.
|
|
67
|
+
SUBMISSION_UNKNOWN or interrupted write: look up the recorded name or ID before
|
|
68
|
+
attempting another submission. Only reuse an idempotency key on a command that
|
|
69
|
+
advertises support, with the same fixed request.
|
|
70
|
+
JOB_FAILED, JOB_PAUSED or PARTIAL_FAILED: read the current task and logs.
|
|
71
|
+
Use the stage and stop reason to decide whether a resume or retry is appropriate.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""隔离 Typer 的解析器差异,发现和校验共用同一参数类型描述。"""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from types import SimpleNamespace
|
|
6
|
+
from typing import get_args, get_origin
|
|
7
|
+
|
|
8
|
+
from typer.core import TyperGroup
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
from typer import _click as engine
|
|
12
|
+
from typer.exceptions import Abort
|
|
13
|
+
except ImportError:
|
|
14
|
+
import click as engine
|
|
15
|
+
from click import Abort
|
|
16
|
+
|
|
17
|
+
exceptions = importlib.import_module(engine.__name__ + ".exceptions")
|
|
18
|
+
globals_module = importlib.import_module(engine.__name__ + ".globals")
|
|
19
|
+
click = SimpleNamespace(
|
|
20
|
+
Context=engine.Context,
|
|
21
|
+
Group=TyperGroup,
|
|
22
|
+
core=engine.core,
|
|
23
|
+
ClickException=exceptions.ClickException,
|
|
24
|
+
BadParameter=exceptions.BadParameter,
|
|
25
|
+
Abort=Abort,
|
|
26
|
+
get_current_context=globals_module.get_current_context,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parameter_schema(param):
|
|
31
|
+
descriptor = getattr(param, "type_descriptor", None)
|
|
32
|
+
if descriptor is not None:
|
|
33
|
+
annotation = descriptor.annotation
|
|
34
|
+
if get_origin(annotation) is not list and get_args(annotation):
|
|
35
|
+
candidates = [arg for arg in get_args(annotation) if arg is not type(None)]
|
|
36
|
+
if len(candidates) == 1:
|
|
37
|
+
annotation = candidates[0]
|
|
38
|
+
if get_origin(annotation) in {list, tuple}:
|
|
39
|
+
annotation = get_args(annotation)[0]
|
|
40
|
+
if isinstance(annotation, type) and issubclass(annotation, Enum):
|
|
41
|
+
result = {"type": "string", "enum": [item.value for item in annotation]}
|
|
42
|
+
else:
|
|
43
|
+
result = {
|
|
44
|
+
"type": {int: "integer", float: "number", bool: "boolean"}.get(
|
|
45
|
+
annotation, "string"
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
minimum, maximum = getattr(param, "min", None), getattr(param, "max", None)
|
|
49
|
+
else:
|
|
50
|
+
types = importlib.import_module(engine.__name__ + ".types")
|
|
51
|
+
kind = param.type
|
|
52
|
+
# Click 的 Choice 和 Typer 0.27 的 TyperChoice 都公开 choices。
|
|
53
|
+
choices = getattr(kind, "choices", None)
|
|
54
|
+
if choices is not None:
|
|
55
|
+
result = {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"enum": [
|
|
58
|
+
item.value if isinstance(item, Enum) else item
|
|
59
|
+
for item in choices
|
|
60
|
+
],
|
|
61
|
+
}
|
|
62
|
+
else:
|
|
63
|
+
result = {
|
|
64
|
+
"type": "integer"
|
|
65
|
+
if isinstance(kind, types.IntParamType)
|
|
66
|
+
else "number"
|
|
67
|
+
if isinstance(kind, types.FloatParamType)
|
|
68
|
+
else "boolean"
|
|
69
|
+
if isinstance(kind, types.BoolParamType)
|
|
70
|
+
else "string"
|
|
71
|
+
}
|
|
72
|
+
minimum, maximum = getattr(kind, "min", None), getattr(kind, "max", None)
|
|
73
|
+
if minimum is not None:
|
|
74
|
+
result["minimum"] = minimum
|
|
75
|
+
if maximum is not None:
|
|
76
|
+
result["maximum"] = maximum
|
|
77
|
+
if param.multiple or param.nargs == -1:
|
|
78
|
+
result = {"type": "array", "items": result}
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def valid_value(value, schema):
|
|
83
|
+
kind = schema["type"]
|
|
84
|
+
valid = {
|
|
85
|
+
"integer": type(value) is int,
|
|
86
|
+
"number": type(value) in (int, float),
|
|
87
|
+
"boolean": type(value) is bool,
|
|
88
|
+
"string": isinstance(value, str),
|
|
89
|
+
}.get(kind, False)
|
|
90
|
+
if not valid:
|
|
91
|
+
return False
|
|
92
|
+
if "enum" in schema and value not in schema["enum"]:
|
|
93
|
+
return False
|
|
94
|
+
if "minimum" in schema and value < schema["minimum"]:
|
|
95
|
+
return False
|
|
96
|
+
return not ("maximum" in schema and value > schema["maximum"])
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""命令的副作用与任务执行结果说明。"""
|
|
2
|
+
|
|
3
|
+
from infix_cli.commands import _jobs
|
|
4
|
+
from infix_cli.commands.deploy import _SETTLED
|
|
5
|
+
from infix_cli.domain.dto import evaluation, spark, training
|
|
6
|
+
|
|
7
|
+
_READ = {
|
|
8
|
+
"artifacts", "capabilities", "check", "compare-get", "compare-list", "completion",
|
|
9
|
+
"describe", "doctor", "get", "guide", "jobs", "list", "methods", "parameters",
|
|
10
|
+
"preview", "schema", "show", "status", "tags", "teachers", "usage", "user-stats",
|
|
11
|
+
"version", "versions", "wait",
|
|
12
|
+
}
|
|
13
|
+
_CREATE = {"add-version", "compare", "create", "register", "run", "upload"}
|
|
14
|
+
_UPDATE = {"publish", "restart", "resume", "scale", "share", "stop"}
|
|
15
|
+
_STAGE = {"split", "distill", "clean", "warmup", "opd"}
|
|
16
|
+
_OFFLINE = {"capabilities", "schema", "guide", "completion"}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def effects(path, flags):
|
|
20
|
+
"""返回默认副作用和会改变它的参数。"""
|
|
21
|
+
group, action = path[0], path[-1]
|
|
22
|
+
variants = []
|
|
23
|
+
if action in _READ:
|
|
24
|
+
effect = "read"
|
|
25
|
+
elif action in _CREATE:
|
|
26
|
+
effect = "remote_create"
|
|
27
|
+
elif action in _UPDATE or action == "tensorboard":
|
|
28
|
+
effect = "remote_update"
|
|
29
|
+
elif action == "delete":
|
|
30
|
+
effect = "remote_delete"
|
|
31
|
+
elif action in {"login", "logout", "download", "export"}:
|
|
32
|
+
effect = "local_write"
|
|
33
|
+
elif action in {"clone", "logs"}:
|
|
34
|
+
effect = "local_write" if path == ("deploy", "clone") else "read"
|
|
35
|
+
if effect == "read":
|
|
36
|
+
flag = "--save" if action == "clone" else "--download"
|
|
37
|
+
if flag in flags:
|
|
38
|
+
variants.append({"flag": flag, "effect": "local_write"})
|
|
39
|
+
if group in {"fusion", "merge"} and action == "clone":
|
|
40
|
+
variants.append({"when": "text output without --quiet", "effect": "local_write"})
|
|
41
|
+
elif group == "fusion" and action in _STAGE:
|
|
42
|
+
effect = "remote_update"
|
|
43
|
+
variants.append({"flag": "--create", "effect": "remote_create"})
|
|
44
|
+
else:
|
|
45
|
+
effect = "unknown"
|
|
46
|
+
if path == ("auth", "status"):
|
|
47
|
+
variants.append({"when": "a missing workspace name can be resolved", "effect": "local_write"})
|
|
48
|
+
if "--dry-run" in flags:
|
|
49
|
+
variants.append({"flag": "--dry-run", "effect": "read"})
|
|
50
|
+
if action == "tensorboard" and "--status" in flags:
|
|
51
|
+
variants.append({"flag": "--status", "effect": "read"})
|
|
52
|
+
return {
|
|
53
|
+
"effect": effect,
|
|
54
|
+
"offline": group == "examples" or action in _OFFLINE or action == "logout",
|
|
55
|
+
**({"effect_variants": variants} if variants else {}),
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
_STRING = {"type": "string"}
|
|
60
|
+
_STATUS = {"type": "string", "description": "当前状态,未知状态词可能来自更新的后端。"}
|
|
61
|
+
_OBJECT = {"type": "object"}
|
|
62
|
+
_JSON_ARRAY = {"type": "array", "items": _OBJECT}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _object(**properties):
|
|
66
|
+
return {"type": "object", "properties": properties, "required": list(properties)}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _result(id_path, status_path, query, success, failure, **extra):
|
|
70
|
+
return {
|
|
71
|
+
"id_path": id_path,
|
|
72
|
+
"status_path": status_path,
|
|
73
|
+
"query_argv": ["infix", *query.split(), "{id}"],
|
|
74
|
+
"terminal_success": sorted(success),
|
|
75
|
+
"terminal_failure": sorted(failure),
|
|
76
|
+
**extra,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def result_contract(path, *, dry_run):
|
|
81
|
+
"""关键任务命令返回的稳定字段与查询方法。"""
|
|
82
|
+
group, action = path
|
|
83
|
+
result = None
|
|
84
|
+
workflow = None
|
|
85
|
+
if group in {"training", "evaluation", "spark"} and action in {
|
|
86
|
+
"create", "get", "wait", "restart",
|
|
87
|
+
}:
|
|
88
|
+
dto = {"training": training, "evaluation": evaluation, "spark": spark}[group]
|
|
89
|
+
result = _object(id=_STRING, name=_STRING, status=_STATUS)
|
|
90
|
+
workflow = _result(
|
|
91
|
+
"id", "status", f"{group} get", dto.TERMINAL_SUCCESS, dto.TERMINAL_FAILURE,
|
|
92
|
+
wait_argv=["infix", group, "wait", "{id}", "--timeout", "30s"],
|
|
93
|
+
)
|
|
94
|
+
if group == "evaluation":
|
|
95
|
+
result["properties"].update(
|
|
96
|
+
results_collected={"type": "boolean"}, collection_exhausted={"type": "boolean"},
|
|
97
|
+
dataset_version_id={"type": ["string", "null"]},
|
|
98
|
+
)
|
|
99
|
+
workflow["completion_condition"] = {"results_collected": True}
|
|
100
|
+
workflow["wait_only_failure"] = sorted(_jobs._WAIT_ONLY_FAILURE[group])
|
|
101
|
+
elif group == "deploy" and action in {"create", "describe", "wait", "restart", "scale"}:
|
|
102
|
+
result = _object(id=_STRING, name=_STRING, status=_STATUS)
|
|
103
|
+
workflow = _result(
|
|
104
|
+
"id", "status", "deploy describe", {"available"}, _SETTLED - {"available"},
|
|
105
|
+
wait_argv=["infix", "deploy", "wait", "{id}", "--timeout", "30s"],
|
|
106
|
+
)
|
|
107
|
+
elif group == "evaluation" and action in {"compare", "compare-get"}:
|
|
108
|
+
result = _object(id=_STRING, comparison=_STRING, status=_STATUS, results=_JSON_ARRAY)
|
|
109
|
+
workflow = _result(
|
|
110
|
+
"id", "status", "evaluation compare-get",
|
|
111
|
+
{"completed"}, {"failed", "partial_failed", "stopped"},
|
|
112
|
+
)
|
|
113
|
+
elif group in {"fusion", "merge"} and (action in {"get", "run", "create", "resume"} or action in _STAGE):
|
|
114
|
+
execution = _object(id=_STRING, number={"type": "integer"}, status=_STATUS)
|
|
115
|
+
execution["properties"]["stop_reason"] = {"type": ["string", "null"]}
|
|
116
|
+
if action == "get":
|
|
117
|
+
result = _object(summary=_object(id=_STRING, name=_STRING, status=_STATUS), stages=_JSON_ARRAY)
|
|
118
|
+
result["properties"]["execution"] = {"anyOf": [execution, {"type": "null"}]}
|
|
119
|
+
id_path = "summary.id"
|
|
120
|
+
elif action in _STAGE:
|
|
121
|
+
result = _object(name=_STRING, status=_STATUS, execution=execution)
|
|
122
|
+
result["properties"]["id"] = _STRING
|
|
123
|
+
id_path = "id"
|
|
124
|
+
elif action == "resume":
|
|
125
|
+
result = _object(name=_STRING, reason=_STRING)
|
|
126
|
+
result["properties"]["execution"] = {"anyOf": [execution, {"type": "null"}]}
|
|
127
|
+
id_path = None
|
|
128
|
+
else:
|
|
129
|
+
result = _object(id=_STRING, name=_STRING, status=_STATUS, execution=execution)
|
|
130
|
+
id_path = "id"
|
|
131
|
+
workflow = _result(
|
|
132
|
+
id_path, "execution.status", f"{group} get", {"succeeded"}, {"failed"},
|
|
133
|
+
paused=["stopped"],
|
|
134
|
+
successful_stage_boundary={"status": "stopped", "stop_reason": "awaiting_next_stage"},
|
|
135
|
+
run_number_path="execution.number",
|
|
136
|
+
)
|
|
137
|
+
if action == "resume":
|
|
138
|
+
workflow["query_target"] = "Use the task ID passed to resume."
|
|
139
|
+
if action in _STAGE:
|
|
140
|
+
workflow["query_target"] = "Use id for --create, otherwise reuse the target task."
|
|
141
|
+
if group == "fusion":
|
|
142
|
+
workflow["historical_query_argv"] = [
|
|
143
|
+
"infix", "fusion", "get", "{id}", "--run", "{execution.number}",
|
|
144
|
+
]
|
|
145
|
+
if result is None:
|
|
146
|
+
return {}
|
|
147
|
+
contract = {"success_schema": result, "workflow": workflow}
|
|
148
|
+
if dry_run:
|
|
149
|
+
preview = (
|
|
150
|
+
_object(dry_run={"const": True}, name=_STRING, plan=_OBJECT)
|
|
151
|
+
if group in {"fusion", "merge"} or action == "compare"
|
|
152
|
+
else _object(dry_run={"const": True}, module=_STRING, request=_OBJECT, checks=_OBJECT)
|
|
153
|
+
)
|
|
154
|
+
contract["dry_run_schema"] = (
|
|
155
|
+
_object(dry_run={"const": True}, name=_STRING) if action == "resume" else preview
|
|
156
|
+
)
|
|
157
|
+
return contract
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command modules, one per top-level noun."""
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""training artifacts / training download.
|
|
2
|
+
|
|
3
|
+
The backend's artifact download (``/artifacts/{id}/download``) is a stub that
|
|
4
|
+
always answers 501, so neither command uses it. Checkpoints are listed from
|
|
5
|
+
``/artifacts``; files come from the job's output directory, which lives in the
|
|
6
|
+
job creator's Workspace Storage (``{tenant}/{workspace}/{user}/
|
|
7
|
+
Model_Training_Output/<job>-<timestamp>``) and is fetched through
|
|
8
|
+
``/storage/download`` like any other storage file. The tree is walked with the
|
|
9
|
+
job's own ``/output/files`` listing, which — unlike ``/storage/list`` — works
|
|
10
|
+
for a public job someone else created.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from infix_cli.commands import _download, _storage_tree
|
|
20
|
+
from infix_cli.domain import resolve
|
|
21
|
+
from infix_cli.errors import NotFoundError, UsageError
|
|
22
|
+
|
|
23
|
+
# Where the training container sees its output directory. Checkpoint paths
|
|
24
|
+
# reported by the pod may be written against it.
|
|
25
|
+
_CONTAINER_OUTPUT = "/mnt/output"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class CheckpointDTO:
|
|
30
|
+
step: str
|
|
31
|
+
precision: str
|
|
32
|
+
loss: str | None
|
|
33
|
+
size_bytes: int | None
|
|
34
|
+
created_at: str
|
|
35
|
+
path: str
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def from_api(cls, raw: dict) -> "CheckpointDTO":
|
|
39
|
+
size = raw.get("size_bytes")
|
|
40
|
+
return cls(
|
|
41
|
+
step=str(raw.get("step") or ""),
|
|
42
|
+
precision=str(raw.get("precision") or "").lower(),
|
|
43
|
+
loss=str(raw["loss"]) if raw.get("loss") not in (None, "") else None,
|
|
44
|
+
size_bytes=int(size) if isinstance(size, int) else None,
|
|
45
|
+
created_at=str(raw.get("created_time") or ""),
|
|
46
|
+
path=str(raw.get("path") or ""),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def to_json(self) -> dict:
|
|
50
|
+
return dict(self.__dict__)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def size_text(self) -> str:
|
|
54
|
+
from infix_cli.domain.dto.common import format_bytes
|
|
55
|
+
|
|
56
|
+
return format_bytes(self.size_bytes) if self.size_bytes else "--"
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def columns() -> list[tuple[str, str]]:
|
|
60
|
+
return [
|
|
61
|
+
("STEP", "step"), ("PRECISION", "precision"), ("LOSS", "loss"),
|
|
62
|
+
("SIZE", "size_text"), ("CREATED", "created_at"), ("PATH", "path"),
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def output_location(job: dict) -> tuple[str, str]:
|
|
67
|
+
"""``(owner_user_id, path within that user's storage)`` of a job's output."""
|
|
68
|
+
raw = str(job.get("output_path") or "").strip("/")
|
|
69
|
+
parts = raw.split("/", 3)
|
|
70
|
+
if len(parts) < 4 or not parts[3]:
|
|
71
|
+
raise UsageError(
|
|
72
|
+
f'Training job "{job.get("name")}" has no output directory.',
|
|
73
|
+
"It may not have started yet.",
|
|
74
|
+
)
|
|
75
|
+
return parts[2], parts[3]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def checkpoint_subdir(checkpoint: dict, storage_root: str) -> str:
|
|
79
|
+
"""The checkpoint's folder relative to the job's output directory.
|
|
80
|
+
|
|
81
|
+
The pod reports the path; the forms seen are the container mount
|
|
82
|
+
(``/mnt/output/...``), the storage path (``.../Model_Training_Output/...``)
|
|
83
|
+
and a bare relative path. Anything else cannot be placed and is refused
|
|
84
|
+
rather than guessed.
|
|
85
|
+
"""
|
|
86
|
+
path = str(checkpoint.get("path") or "").strip()
|
|
87
|
+
if path.startswith(_CONTAINER_OUTPUT + "/"):
|
|
88
|
+
return path[len(_CONTAINER_OUTPUT) + 1:].strip("/")
|
|
89
|
+
marker = storage_root.rstrip("/") + "/"
|
|
90
|
+
if marker in path:
|
|
91
|
+
return path.split(marker, 1)[1].strip("/")
|
|
92
|
+
if path and not path.startswith("/") and "://" not in path:
|
|
93
|
+
return path.strip("/")
|
|
94
|
+
raise UsageError(
|
|
95
|
+
f'Cannot locate checkpoint step {checkpoint.get("step")} in the output directory '
|
|
96
|
+
f'(reported path: "{path}").',
|
|
97
|
+
'Download the whole output with "infix training download" instead.',
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def download_output(
|
|
102
|
+
run: Any,
|
|
103
|
+
name: str,
|
|
104
|
+
*,
|
|
105
|
+
step: str | None,
|
|
106
|
+
dest: str | None,
|
|
107
|
+
overwrite: bool,
|
|
108
|
+
concurrency: int,
|
|
109
|
+
) -> None:
|
|
110
|
+
client = run.client()
|
|
111
|
+
job = resolve.find_job(client, "training", name)
|
|
112
|
+
job_id = str(job.get("id"))
|
|
113
|
+
detail = client.get(f"/training/jobs/{job_id}")
|
|
114
|
+
detail = detail if isinstance(detail, dict) else job
|
|
115
|
+
owner, root = output_location(detail)
|
|
116
|
+
|
|
117
|
+
sub = ""
|
|
118
|
+
if step is not None:
|
|
119
|
+
listing = client.get(f"/training/jobs/{job_id}/artifacts", params={"page_size": 100})
|
|
120
|
+
items = (listing or {}).get("items") or []
|
|
121
|
+
match = next((c for c in items if str(c.get("step")) == str(step)), None)
|
|
122
|
+
if match is None:
|
|
123
|
+
raise NotFoundError(
|
|
124
|
+
f'Training job "{name}" has no checkpoint at step {step}.',
|
|
125
|
+
f'See "infix training artifacts {name}".',
|
|
126
|
+
)
|
|
127
|
+
sub = checkpoint_subdir(match, root)
|
|
128
|
+
|
|
129
|
+
files = list(_storage_tree.walk(
|
|
130
|
+
client, sub, list_path=f"/training/jobs/{job_id}/output/files",
|
|
131
|
+
))
|
|
132
|
+
if not files:
|
|
133
|
+
where = f'"{root}/{sub}" is empty' if sub else "the job has no output files yet"
|
|
134
|
+
raise UsageError(f"Nothing to download: {where}.")
|
|
135
|
+
|
|
136
|
+
target = Path(dest or ".").expanduser() / Path(root).name
|
|
137
|
+
plan = [
|
|
138
|
+
(_storage_tree.RemoteFile(f"{root}/{f.path}", f.size), target / f.path)
|
|
139
|
+
for f in files
|
|
140
|
+
]
|
|
141
|
+
_download.run_plan(run, client, plan, params={"owner_user_id": owner},
|
|
142
|
+
overwrite=overwrite, concurrency=concurrency)
|