nemo-evaluator-launcher 0.1.0rc2__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.

Potentially problematic release.


This version of nemo-evaluator-launcher might be problematic. Click here for more details.

Files changed (57) hide show
  1. nemo_evaluator_launcher/__init__.py +65 -0
  2. nemo_evaluator_launcher/api/__init__.py +24 -0
  3. nemo_evaluator_launcher/api/functional.py +641 -0
  4. nemo_evaluator_launcher/api/types.py +89 -0
  5. nemo_evaluator_launcher/api/utils.py +19 -0
  6. nemo_evaluator_launcher/cli/__init__.py +15 -0
  7. nemo_evaluator_launcher/cli/export.py +148 -0
  8. nemo_evaluator_launcher/cli/info.py +117 -0
  9. nemo_evaluator_launcher/cli/kill.py +39 -0
  10. nemo_evaluator_launcher/cli/ls_runs.py +113 -0
  11. nemo_evaluator_launcher/cli/ls_tasks.py +34 -0
  12. nemo_evaluator_launcher/cli/main.py +136 -0
  13. nemo_evaluator_launcher/cli/run.py +135 -0
  14. nemo_evaluator_launcher/cli/status.py +118 -0
  15. nemo_evaluator_launcher/cli/version.py +52 -0
  16. nemo_evaluator_launcher/common/__init__.py +16 -0
  17. nemo_evaluator_launcher/common/execdb.py +189 -0
  18. nemo_evaluator_launcher/common/helpers.py +157 -0
  19. nemo_evaluator_launcher/common/logging_utils.py +349 -0
  20. nemo_evaluator_launcher/common/mapping.py +310 -0
  21. nemo_evaluator_launcher/configs/__init__.py +15 -0
  22. nemo_evaluator_launcher/configs/default.yaml +28 -0
  23. nemo_evaluator_launcher/configs/deployment/nim.yaml +32 -0
  24. nemo_evaluator_launcher/configs/deployment/none.yaml +16 -0
  25. nemo_evaluator_launcher/configs/deployment/sglang.yaml +38 -0
  26. nemo_evaluator_launcher/configs/deployment/vllm.yaml +41 -0
  27. nemo_evaluator_launcher/configs/execution/lepton/default.yaml +92 -0
  28. nemo_evaluator_launcher/configs/execution/local.yaml +17 -0
  29. nemo_evaluator_launcher/configs/execution/slurm/default.yaml +33 -0
  30. nemo_evaluator_launcher/executors/__init__.py +22 -0
  31. nemo_evaluator_launcher/executors/base.py +97 -0
  32. nemo_evaluator_launcher/executors/lepton/__init__.py +16 -0
  33. nemo_evaluator_launcher/executors/lepton/deployment_helpers.py +589 -0
  34. nemo_evaluator_launcher/executors/lepton/executor.py +905 -0
  35. nemo_evaluator_launcher/executors/lepton/job_helpers.py +394 -0
  36. nemo_evaluator_launcher/executors/local/__init__.py +15 -0
  37. nemo_evaluator_launcher/executors/local/executor.py +491 -0
  38. nemo_evaluator_launcher/executors/local/run.template.sh +88 -0
  39. nemo_evaluator_launcher/executors/registry.py +38 -0
  40. nemo_evaluator_launcher/executors/slurm/__init__.py +15 -0
  41. nemo_evaluator_launcher/executors/slurm/executor.py +982 -0
  42. nemo_evaluator_launcher/exporters/__init__.py +36 -0
  43. nemo_evaluator_launcher/exporters/base.py +112 -0
  44. nemo_evaluator_launcher/exporters/gsheets.py +391 -0
  45. nemo_evaluator_launcher/exporters/local.py +488 -0
  46. nemo_evaluator_launcher/exporters/mlflow.py +448 -0
  47. nemo_evaluator_launcher/exporters/registry.py +40 -0
  48. nemo_evaluator_launcher/exporters/utils.py +669 -0
  49. nemo_evaluator_launcher/exporters/wandb.py +376 -0
  50. nemo_evaluator_launcher/package_info.py +35 -0
  51. nemo_evaluator_launcher/resources/mapping.toml +344 -0
  52. nemo_evaluator_launcher-0.1.0rc2.dist-info/METADATA +35 -0
  53. nemo_evaluator_launcher-0.1.0rc2.dist-info/RECORD +57 -0
  54. nemo_evaluator_launcher-0.1.0rc2.dist-info/WHEEL +5 -0
  55. nemo_evaluator_launcher-0.1.0rc2.dist-info/entry_points.txt +3 -0
  56. nemo_evaluator_launcher-0.1.0rc2.dist-info/licenses/LICENSE +451 -0
  57. nemo_evaluator_launcher-0.1.0rc2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,641 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ """Public API functions for nemo-evaluator-launcher.
17
+
18
+ This module provides the main functional entry points for running evaluations, querying job status, and listing available tasks. These functions are intended to be used by CLI commands and external integrations.
19
+ """
20
+
21
+ from typing import Any, List, Optional, Union
22
+
23
+ from omegaconf import DictConfig, OmegaConf
24
+
25
+ from nemo_evaluator_launcher.api.types import RunConfig
26
+ from nemo_evaluator_launcher.common.execdb import ExecutionDB, JobData
27
+ from nemo_evaluator_launcher.common.mapping import load_tasks_mapping
28
+ from nemo_evaluator_launcher.executors.registry import get_executor
29
+ from nemo_evaluator_launcher.exporters import create_exporter
30
+
31
+
32
+ def get_tasks_list() -> list[list[Any]]:
33
+ """Get a list of available tasks from the mapping.
34
+
35
+ Returns:
36
+ list[list[Any]]: Each sublist contains task name, endpoint type, harness, and container.
37
+ """
38
+ mapping = load_tasks_mapping()
39
+ data = [
40
+ [
41
+ task_data.get("task"),
42
+ task_data.get("endpoint_type"),
43
+ task_data.get("harness"),
44
+ task_data.get("container"),
45
+ ]
46
+ for task_data in mapping.values()
47
+ ]
48
+ return data
49
+
50
+
51
+ def _validate_no_missing_values(cfg: Any, path: str = "") -> None:
52
+ """Recursively validate that no MISSING values exist in the configuration.
53
+
54
+ Args:
55
+ cfg: The configuration object to validate.
56
+ path: Current path in the configuration for error reporting.
57
+
58
+ Raises:
59
+ ValueError: If any MISSING values are found in the configuration.
60
+ """
61
+ if OmegaConf.is_dict(cfg):
62
+ for key, value in cfg.items():
63
+ current_path = f"{path}.{key!s}" if path else str(key)
64
+ # Check if this specific key has a MISSING value
65
+ if OmegaConf.is_missing(cfg, key):
66
+ raise ValueError(
67
+ f"Configuration has MISSING value at path: {current_path!s}"
68
+ )
69
+ _validate_no_missing_values(value, current_path)
70
+ elif OmegaConf.is_list(cfg):
71
+ for i, value in enumerate(cfg):
72
+ current_path = f"{path}[{i}]"
73
+ _validate_no_missing_values(value, current_path)
74
+
75
+
76
+ def run_eval(cfg: RunConfig, dry_run: bool = False) -> Optional[str]:
77
+ """Run evaluation with specified config and overrides.
78
+
79
+ Args:
80
+ cfg: The configuration object for the evaluation run.
81
+ dry_run: If True, do not run the evaluation, just prepare scripts and save them.
82
+
83
+ Returns:
84
+ Optional[str]: The invocation ID for the evaluation run.
85
+
86
+ Raises:
87
+ ValueError: If configuration validation fails or MISSING values are found.
88
+ RuntimeError: If the executor fails to start the evaluation.
89
+ """
90
+ # Validate that no MISSING values exist in the configuration
91
+ _validate_no_missing_values(cfg)
92
+
93
+ if dry_run:
94
+ print(OmegaConf.to_yaml(cfg))
95
+
96
+ _check_api_endpoint_when_deployment_is_configured(cfg)
97
+ return get_executor(cfg.execution.type).execute_eval(cfg, dry_run)
98
+
99
+
100
+ def get_status(job_ids: list[str]) -> list[dict[str, Any]]:
101
+ """Get status of jobs by their IDs or invocation IDs.
102
+
103
+ Args:
104
+ job_ids: List of job IDs or invocation IDs to check status for.
105
+
106
+ Returns:
107
+ list[dict[str, Any]]: List of status dictionaries for each job or invocation.
108
+ Each dictionary contains keys: 'invocation', 'job_id', 'status', and 'data'.
109
+ If a job or invocation is not found, status is 'not_found'.
110
+ If an error occurs, status is 'error' and 'data' contains error details.
111
+ """
112
+ db = ExecutionDB()
113
+ results: List[dict[str, Any]] = []
114
+
115
+ for job_id in job_ids:
116
+ # If id looks like an invocation_id (8 hex digits, no dot), get all jobs for it
117
+ if len(job_id) == 8 and "." not in job_id:
118
+ jobs = db.get_jobs(job_id)
119
+ if not jobs:
120
+ results.append(
121
+ {
122
+ "invocation": job_id,
123
+ "job_id": None,
124
+ "status": "not_found",
125
+ "data": {},
126
+ }
127
+ )
128
+ continue
129
+
130
+ # Get the executor class from the first job
131
+ first_job_data = next(iter(jobs.values()))
132
+ try:
133
+ executor_cls = get_executor(first_job_data.executor)
134
+ except ValueError as e:
135
+ results.append(
136
+ {
137
+ "invocation": job_id,
138
+ "job_id": None,
139
+ "status": "error",
140
+ "data": {"error": str(e)},
141
+ }
142
+ )
143
+ continue
144
+
145
+ # Get status from the executor for all jobs in the invocation
146
+ try:
147
+ status_list = executor_cls.get_status(job_id)
148
+
149
+ # Create a result for each job in the invocation
150
+ for job_id_in_invocation, job_data in jobs.items():
151
+ # Find the status for this specific job
152
+ job_status: str | None = None
153
+ job_progress: Optional[dict[str, Any]] = None
154
+ for status in status_list:
155
+ if status.id == job_id_in_invocation:
156
+ job_status = status.state.value
157
+ job_progress = status.progress
158
+ break
159
+
160
+ results.append(
161
+ {
162
+ "invocation": job_id,
163
+ "job_id": job_id_in_invocation,
164
+ "status": (
165
+ job_status if job_status is not None else "unknown"
166
+ ),
167
+ "progress": (
168
+ job_progress if job_progress is not None else "unknown"
169
+ ),
170
+ "data": job_data.data,
171
+ }
172
+ )
173
+
174
+ except Exception as e:
175
+ results.append(
176
+ {
177
+ "invocation": job_id,
178
+ "job_id": None,
179
+ "status": "error",
180
+ "data": {"error": str(e)},
181
+ }
182
+ )
183
+ else:
184
+ # Otherwise, treat as job_id
185
+ single_job_data: Optional[JobData] = db.get_job(job_id)
186
+
187
+ if single_job_data is None:
188
+ results.append(
189
+ {
190
+ "invocation": None,
191
+ "job_id": job_id,
192
+ "status": "not_found",
193
+ "data": {},
194
+ }
195
+ )
196
+ continue
197
+
198
+ # Get the executor class
199
+ try:
200
+ executor_cls = get_executor(single_job_data.executor)
201
+ except ValueError as e:
202
+ results.append(
203
+ {
204
+ "invocation": None,
205
+ "job_id": job_id,
206
+ "status": "error",
207
+ "data": {"error": str(e)},
208
+ }
209
+ )
210
+ continue
211
+
212
+ # Get status from the executor
213
+ try:
214
+ status_list = executor_cls.get_status(job_id)
215
+
216
+ if not status_list:
217
+ results.append(
218
+ {
219
+ "invocation": single_job_data.invocation_id,
220
+ "job_id": job_id,
221
+ "status": "unknown",
222
+ "data": single_job_data.data,
223
+ }
224
+ )
225
+ else:
226
+ # For individual job queries, return the first status
227
+ results.append(
228
+ {
229
+ "invocation": single_job_data.invocation_id,
230
+ "job_id": job_id,
231
+ "status": (
232
+ status_list[0].state.value if status_list else "unknown"
233
+ ),
234
+ "progress": (
235
+ status_list[0].progress if status_list else "unknown"
236
+ ),
237
+ "data": single_job_data.data,
238
+ }
239
+ )
240
+
241
+ except Exception as e:
242
+ results.append(
243
+ {
244
+ "invocation": (
245
+ single_job_data.invocation_id if single_job_data else None
246
+ ),
247
+ "job_id": job_id,
248
+ "status": "error",
249
+ "data": {"error": str(e)},
250
+ }
251
+ )
252
+
253
+ return results
254
+
255
+
256
+ def list_all_invocations_summary() -> list[dict[str, Any]]:
257
+ """Return a concise per-invocation summary from the exec DB.
258
+
259
+ Columns: invocation_id, earliest_job_ts, num_jobs, executor (or 'mixed').
260
+ Sorted by earliest_job_ts (newest first).
261
+ """
262
+ db = ExecutionDB()
263
+ jobs = db.get_all_jobs()
264
+
265
+ inv_to_earliest: dict[str, float] = {}
266
+ inv_to_count: dict[str, int] = {}
267
+ inv_to_execs: dict[str, set[str]] = {}
268
+
269
+ for jd in jobs.values():
270
+ inv = jd.invocation_id
271
+ ts = jd.timestamp or 0.0
272
+ if inv not in inv_to_earliest or ts < inv_to_earliest[inv]:
273
+ inv_to_earliest[inv] = ts
274
+ inv_to_count[inv] = inv_to_count.get(inv, 0) + 1
275
+ if inv not in inv_to_execs:
276
+ inv_to_execs[inv] = set()
277
+ inv_to_execs[inv].add(jd.executor)
278
+
279
+ rows: list[dict[str, Any]] = []
280
+ for inv, earliest_ts in inv_to_earliest.items():
281
+ execs = inv_to_execs.get(inv, set())
282
+ executor = (
283
+ next(iter(execs)) if len(execs) == 1 else ("mixed" if execs else None)
284
+ )
285
+ rows.append(
286
+ {
287
+ "invocation_id": inv,
288
+ "earliest_job_ts": earliest_ts,
289
+ "num_jobs": inv_to_count.get(inv, 0),
290
+ "executor": executor,
291
+ }
292
+ )
293
+
294
+ rows.sort(key=lambda r: r.get("earliest_job_ts") or 0, reverse=True)
295
+ return rows
296
+
297
+
298
+ def get_invocation_benchmarks(invocation_id: str) -> list[str]:
299
+ """Return a sorted list of benchmark/task names for a given invocation.
300
+
301
+ Extracted from stored configs in the execution DB. If anything goes wrong,
302
+ returns an empty list; callers can display 'unknown' if desired.
303
+ """
304
+ db = ExecutionDB()
305
+ jobs = db.get_jobs(invocation_id)
306
+ names: set[str] = set()
307
+ for jd in jobs.values():
308
+ try:
309
+ cfg = jd.config or {}
310
+ tasks = (cfg.get("evaluation", {}) or {}).get("tasks", []) or []
311
+ for t in tasks:
312
+ n = t.get("name") if isinstance(t, dict) else None
313
+ if n:
314
+ names.add(str(n))
315
+ except Exception:
316
+ # Ignore malformed entries; continue collecting from others
317
+ continue
318
+ return sorted(names)
319
+
320
+
321
+ def kill_job_or_invocation(id: str) -> list[dict[str, Any]]:
322
+ """Kill a job or an entire invocation by its ID.
323
+
324
+ Args:
325
+ id: The job ID (e.g., aefc4819.0) or invocation ID (e.g., aefc4819) to kill.
326
+
327
+ Returns:
328
+ list[dict[str, Any]]: List of kill operation results.
329
+ Each dictionary contains keys: 'invocation', 'job_id', 'status', and 'data'.
330
+ If a job is not found, status is 'not_found'.
331
+ If an error occurs, status is 'error' and 'data' contains error details.
332
+ """
333
+ db = ExecutionDB()
334
+ results = []
335
+
336
+ def kill_single_job(job_id: str, job_data: JobData) -> dict[str, Any]:
337
+ """Helper function to kill a single job."""
338
+ try:
339
+ executor_cls = get_executor(job_data.executor)
340
+ if hasattr(executor_cls, "kill_job"):
341
+ executor_cls.kill_job(job_id)
342
+ # Success - job was killed
343
+ return {
344
+ "invocation": job_data.invocation_id,
345
+ "job_id": job_id,
346
+ "status": "killed",
347
+ "data": {"result": "Successfully killed job"},
348
+ }
349
+ else:
350
+ return {
351
+ "invocation": job_data.invocation_id,
352
+ "job_id": job_id,
353
+ "status": "error",
354
+ "data": {
355
+ "error": f"Executor {job_data.executor} does not support killing jobs"
356
+ },
357
+ }
358
+ except (ValueError, RuntimeError) as e:
359
+ # Expected errors from kill_job
360
+ return {
361
+ "invocation": job_data.invocation_id,
362
+ "job_id": job_id,
363
+ "status": "error",
364
+ "data": {"error": str(e)},
365
+ }
366
+ except Exception as e:
367
+ # Unexpected errors
368
+ return {
369
+ "invocation": job_data.invocation_id,
370
+ "job_id": job_id,
371
+ "status": "error",
372
+ "data": {"error": f"Unexpected error: {str(e)}"},
373
+ }
374
+
375
+ # Determine if this is a job ID or invocation ID
376
+ if "." in id:
377
+ # This is a job ID - kill single job
378
+ job_data = db.get_job(id)
379
+ if job_data is None:
380
+ return [
381
+ {
382
+ "invocation": None,
383
+ "job_id": id,
384
+ "status": "not_found",
385
+ "data": {},
386
+ }
387
+ ]
388
+ results.append(kill_single_job(id, job_data))
389
+ else:
390
+ # This is an invocation ID - kill all jobs in the invocation
391
+ jobs = db.get_jobs(id)
392
+ if not jobs:
393
+ return [
394
+ {
395
+ "invocation": id,
396
+ "job_id": None,
397
+ "status": "not_found",
398
+ "data": {},
399
+ }
400
+ ]
401
+
402
+ # Kill each job in the invocation
403
+ for job_id, job_data in jobs.items():
404
+ results.append(kill_single_job(job_id, job_data))
405
+
406
+ return results
407
+
408
+
409
+ def export_results(
410
+ invocation_ids: Union[str, List[str]],
411
+ dest: str = "local",
412
+ config: dict[Any, Any] | None = None,
413
+ ) -> dict:
414
+ """Export results for one or more IDs (jobs/invocations/pipeline IDs) to a destination.
415
+
416
+ Args:
417
+ invocation_ids: Single invocation ID or list of invocation/job IDs
418
+ dest: Export destination (local, wandb, jet, mlflow, gsheets)
419
+ config: exporter configuration
420
+
421
+ Returns:
422
+ Export evaluation results dictionary
423
+ """
424
+
425
+ try:
426
+ # Normalize to list
427
+ if isinstance(invocation_ids, str):
428
+ invocation_ids = [invocation_ids]
429
+
430
+ exporter = create_exporter(dest, config or {})
431
+
432
+ if len(invocation_ids) == 1:
433
+ # Single id (job or invocation)
434
+ single_id = invocation_ids[0]
435
+
436
+ if "." in single_id: # job_id
437
+ job_data = ExecutionDB().get_job(single_id)
438
+ if job_data is None:
439
+ return {
440
+ "success": False,
441
+ "error": f"Job {single_id} not found in ExecutionDB",
442
+ }
443
+
444
+ # Convert single job result to invocation-like structure
445
+ job_result = exporter.export_job(job_data)
446
+ return {
447
+ "success": job_result.success,
448
+ "invocation_id": job_data.invocation_id,
449
+ "jobs": {
450
+ job_data.job_id: {
451
+ "success": job_result.success,
452
+ "message": job_result.message,
453
+ "metadata": job_result.metadata or {},
454
+ }
455
+ },
456
+ "metadata": job_result.metadata or {},
457
+ }
458
+ elif single_id.isdigit(): # pipeline_id
459
+ # Find job by pipeline_id
460
+ db = ExecutionDB()
461
+ # Search all jobs for matching pipeline_id
462
+ for job_id, job_data in db._jobs.items():
463
+ if job_data.data.get("pipeline_id") == int(single_id):
464
+ job_result = exporter.export_job(job_data)
465
+ return {
466
+ "success": job_result.success,
467
+ "invocation_id": job_data.invocation_id,
468
+ "jobs": {
469
+ job_data.job_id: {
470
+ "success": job_result.success,
471
+ "message": job_result.message,
472
+ "metadata": job_result.metadata or {},
473
+ }
474
+ },
475
+ "metadata": job_result.metadata or {},
476
+ }
477
+ return {"success": False, "error": f"Pipeline {single_id} not found"}
478
+ else: # invocation_id
479
+ result = exporter.export_invocation(single_id)
480
+ # Ensure metadata is present in job results to prevent KeyError
481
+ if "jobs" in result:
482
+ for job_id, job_result in result["jobs"].items():
483
+ if "metadata" not in job_result:
484
+ job_result["metadata"] = {}
485
+ return result # type: ignore[no-any-return]
486
+ else:
487
+ # Multiple IDs - parse and group
488
+ db = ExecutionDB()
489
+ grouped_jobs: dict[
490
+ str, dict[str, Any]
491
+ ] = {} # invocation_id -> {job_id: job_data}
492
+ invocation_only = set() # invocation_ids with no specific jobs
493
+ all_jobs_for_consolidated = {} # job_id -> job_data (for consolidated export)
494
+
495
+ # Parse and group IDs
496
+ for id_str in invocation_ids:
497
+ if "." in id_str: # job_id
498
+ job_data = db.get_job(id_str)
499
+ if job_data:
500
+ inv_id = job_data.invocation_id
501
+ if inv_id not in grouped_jobs:
502
+ grouped_jobs[inv_id] = {}
503
+ grouped_jobs[inv_id][id_str] = job_data
504
+ all_jobs_for_consolidated[id_str] = job_data
505
+ elif id_str.isdigit(): # pipeline_id
506
+ # Find job by pipeline_id and add to group
507
+ for job_id, job_data in db._jobs.items():
508
+ if job_data.data.get("pipeline_id") == int(id_str):
509
+ inv_id = job_data.invocation_id
510
+ if inv_id not in grouped_jobs:
511
+ grouped_jobs[inv_id] = {}
512
+ grouped_jobs[inv_id][job_id] = job_data
513
+ all_jobs_for_consolidated[job_id] = job_data
514
+ break
515
+ else: # invocation_id
516
+ invocation_only.add(id_str)
517
+ # Add all jobs from this invocation for consolidated export
518
+ invocation_jobs = db.get_jobs(id_str)
519
+ all_jobs_for_consolidated.update(invocation_jobs)
520
+
521
+ # Check if we should use consolidated export (local + json/csv format)
522
+ should_consolidate = (
523
+ dest == "local"
524
+ and config
525
+ and config.get("format") in ["json", "csv"]
526
+ and (
527
+ len(invocation_only) > 1
528
+ or (len(invocation_only) == 1 and len(grouped_jobs) > 0)
529
+ )
530
+ )
531
+
532
+ if should_consolidate and hasattr(exporter, "export_multiple_invocations"):
533
+ # Use consolidated export for local exporter with JSON/CSV format
534
+ all_invocation_ids = list(invocation_only)
535
+ # Add invocations from grouped jobs
536
+ all_invocation_ids.extend(
537
+ set(
538
+ job_data.invocation_id
539
+ for jobs in grouped_jobs.values()
540
+ for job_data in jobs.values()
541
+ )
542
+ )
543
+ all_invocation_ids = list(set(all_invocation_ids)) # remove duplicates
544
+
545
+ try:
546
+ consolidated_result = exporter.export_multiple_invocations(
547
+ all_invocation_ids
548
+ )
549
+ return consolidated_result # type: ignore[no-any-return]
550
+ except Exception as e:
551
+ return {
552
+ "success": False,
553
+ "error": f"Consolidated export failed: {str(e)}",
554
+ }
555
+
556
+ # Regular multi-invocation export
557
+ all_results = {}
558
+ overall_success = True
559
+
560
+ # Export grouped jobs (partial invocations)
561
+ for inv_id, jobs in grouped_jobs.items():
562
+ try:
563
+ # Create a custom partial invocation export
564
+ results = {}
565
+ for job_id, job_data in jobs.items():
566
+ job_result = exporter.export_job(job_data)
567
+ results[job_id] = {
568
+ "success": job_result.success,
569
+ "message": job_result.message,
570
+ "metadata": job_result.metadata or {},
571
+ }
572
+ if not job_result.success:
573
+ overall_success = False
574
+
575
+ all_results[inv_id] = {
576
+ "success": all(r["success"] for r in results.values()),
577
+ "invocation_id": inv_id,
578
+ "jobs": results,
579
+ "partial": True, # indicate this was partial invocation
580
+ }
581
+ except Exception as e:
582
+ all_results[inv_id] = {
583
+ "success": False,
584
+ "error": f"Partial invocation export failed: {str(e)}",
585
+ }
586
+ overall_success = False
587
+
588
+ # Export full invocations
589
+ for inv_id in invocation_only:
590
+ result = exporter.export_invocation(inv_id)
591
+ # Ensure metadata is present in job results to prevent KeyError
592
+ if "jobs" in result:
593
+ for job_id, job_result in result["jobs"].items():
594
+ if "metadata" not in job_result:
595
+ job_result["metadata"] = {}
596
+ all_results[inv_id] = result
597
+ if not result.get("success", False):
598
+ overall_success = False
599
+
600
+ return {
601
+ "success": overall_success,
602
+ "invocations": all_results,
603
+ "metadata": {
604
+ "total_invocations": len(all_results),
605
+ "successful_invocations": sum(
606
+ 1 for r in all_results.values() if r.get("success")
607
+ ),
608
+ "mixed_export": len(grouped_jobs)
609
+ > 0, # indicates mixed job/invocation export
610
+ },
611
+ }
612
+
613
+ except Exception as e:
614
+ return {"success": False, "error": f"Export failed: {str(e)}"}
615
+
616
+
617
+ def _check_api_endpoint_when_deployment_is_configured(cfg: RunConfig) -> None:
618
+ """Check API endpoint configuration when deployment is configured.
619
+
620
+ Args:
621
+ cfg: Configuration object.
622
+
623
+ Raises:
624
+ ValueError: If invalid configuration is detected.
625
+ """
626
+ if cfg.deployment.type == "none":
627
+ return
628
+ if "target" not in cfg or not isinstance(cfg.target, DictConfig):
629
+ return
630
+ if "api_endpoint" not in cfg.target or not isinstance(
631
+ cfg.target.api_endpoint, DictConfig
632
+ ):
633
+ return
634
+ if "url" in cfg.target.api_endpoint:
635
+ raise ValueError(
636
+ "when deployment is configured, url field should not exist in target.api_endpoint"
637
+ )
638
+ if "model_id" in cfg.target.api_endpoint:
639
+ raise ValueError(
640
+ "when deployment is configured, model_id field should not exist in target.api_endpoint"
641
+ )