adaptive-local 0.5.0a1__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.
- adaptive_local/__init__.py +3 -0
- adaptive_local/benchmark/__init__.py +4 -0
- adaptive_local/benchmark/comparison.py +87 -0
- adaptive_local/benchmark/quality.py +80 -0
- adaptive_local/benchmark/reporting.py +142 -0
- adaptive_local/benchmark/runner.py +396 -0
- adaptive_local/benchmark/sampling.py +130 -0
- adaptive_local/benchmark/schemas.py +235 -0
- adaptive_local/benchmark/sentinel.py +78 -0
- adaptive_local/benchmark/statistics.py +72 -0
- adaptive_local/benchmark/storage.py +69 -0
- adaptive_local/benchmark/workloads.py +202 -0
- adaptive_local/cli/__init__.py +3 -0
- adaptive_local/cli/__main__.py +3 -0
- adaptive_local/cli/main.py +1048 -0
- adaptive_local/config/__init__.py +3 -0
- adaptive_local/config/settings.py +60 -0
- adaptive_local/core/__init__.py +1 -0
- adaptive_local/diagnostics/__init__.py +3 -0
- adaptive_local/diagnostics/doctor.py +79 -0
- adaptive_local/errors.py +30 -0
- adaptive_local/hardware/__init__.py +4 -0
- adaptive_local/hardware/benchmarks.py +187 -0
- adaptive_local/hardware/cache.py +71 -0
- adaptive_local/hardware/capabilities.py +150 -0
- adaptive_local/hardware/collectors.py +476 -0
- adaptive_local/hardware/inspect.py +245 -0
- adaptive_local/hardware/schemas.py +283 -0
- adaptive_local/hub/__init__.py +19 -0
- adaptive_local/hub/service.py +419 -0
- adaptive_local/models/__init__.py +3 -0
- adaptive_local/models/gguf.py +39 -0
- adaptive_local/models/registry.py +111 -0
- adaptive_local/optimization/__init__.py +1 -0
- adaptive_local/optimization/autotune/__init__.py +4 -0
- adaptive_local/optimization/autotune/budgets.py +20 -0
- adaptive_local/optimization/autotune/cache.py +81 -0
- adaptive_local/optimization/autotune/constraints.py +58 -0
- adaptive_local/optimization/autotune/controller.py +191 -0
- adaptive_local/optimization/autotune/evaluator.py +160 -0
- adaptive_local/optimization/autotune/explanation.py +24 -0
- adaptive_local/optimization/autotune/objective.py +73 -0
- adaptive_local/optimization/autotune/pareto.py +29 -0
- adaptive_local/optimization/autotune/schemas.py +184 -0
- adaptive_local/optimization/autotune/search_space.py +97 -0
- adaptive_local/optimization/autotune/strategies/__init__.py +6 -0
- adaptive_local/optimization/autotune/strategies/heuristic.py +18 -0
- adaptive_local/optimization/autotune/strategies/random_search.py +11 -0
- adaptive_local/optimization/autotune/strategies/successive_halving.py +28 -0
- adaptive_local/optimization/autotune/strategies/tpe.py +35 -0
- adaptive_local/optimization/autotune/validation.py +63 -0
- adaptive_local/resources/__init__.py +51 -0
- adaptive_local/resources/actions.py +175 -0
- adaptive_local/resources/admission.py +114 -0
- adaptive_local/resources/capabilities.py +46 -0
- adaptive_local/resources/controller.py +272 -0
- adaptive_local/resources/feedback.py +195 -0
- adaptive_local/resources/linux_controls.py +534 -0
- adaptive_local/resources/monitor.py +173 -0
- adaptive_local/resources/ownership.py +53 -0
- adaptive_local/resources/schemas.py +150 -0
- adaptive_local/resources/session.py +816 -0
- adaptive_local/runtimes/__init__.py +23 -0
- adaptive_local/runtimes/artifacts.py +138 -0
- adaptive_local/runtimes/base.py +165 -0
- adaptive_local/runtimes/cache.py +25 -0
- adaptive_local/runtimes/catalog.json +30 -0
- adaptive_local/runtimes/compatibility.py +21 -0
- adaptive_local/runtimes/errors.py +56 -0
- adaptive_local/runtimes/installer.py +153 -0
- adaptive_local/runtimes/lifecycle.py +42 -0
- adaptive_local/runtimes/llamacpp/__init__.py +3 -0
- adaptive_local/runtimes/llamacpp/adapter.py +611 -0
- adaptive_local/runtimes/manager.py +26 -0
- adaptive_local/runtimes/registry.py +53 -0
- adaptive_local/runtimes/schemas.py +162 -0
- adaptive_local-0.5.0a1.dist-info/METADATA +218 -0
- adaptive_local-0.5.0a1.dist-info/RECORD +81 -0
- adaptive_local-0.5.0a1.dist-info/WHEEL +4 -0
- adaptive_local-0.5.0a1.dist-info/entry_points.txt +2 -0
- adaptive_local-0.5.0a1.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from adaptive_local.benchmark.schemas import BenchmarkRun, ComparisonResult, ExperimentManifest
|
|
4
|
+
from adaptive_local.benchmark.statistics import bootstrap_median_ci, summarize
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def compare_configurations(
|
|
8
|
+
manifest: ExperimentManifest, runs: list[BenchmarkRun], baseline_id: str, candidate_id: str
|
|
9
|
+
) -> ComparisonResult:
|
|
10
|
+
ids = {item.configuration_id for item in manifest.configurations}
|
|
11
|
+
if baseline_id not in ids or candidate_id not in ids:
|
|
12
|
+
raise ValueError("configuration not present in experiment")
|
|
13
|
+
warnings = []
|
|
14
|
+
successful = [run for run in runs if run.status == "success" and run.run_kind == "warm"]
|
|
15
|
+
baseline_workloads = {
|
|
16
|
+
run.workload_id for run in successful if run.configuration_id == baseline_id
|
|
17
|
+
}
|
|
18
|
+
candidate_workloads = {
|
|
19
|
+
run.workload_id for run in successful if run.configuration_id == candidate_id
|
|
20
|
+
}
|
|
21
|
+
compatible = baseline_workloads == candidate_workloads and bool(baseline_workloads)
|
|
22
|
+
if not compatible:
|
|
23
|
+
warnings.append("configuration workload sets differ; direct speedup is invalid")
|
|
24
|
+
fields = {
|
|
25
|
+
"decode_tokens_per_second_runtime": "decode_tokens_per_second_runtime",
|
|
26
|
+
"ttft_seconds": "ttft_seconds",
|
|
27
|
+
"request_latency_seconds": "request_latency_seconds",
|
|
28
|
+
"observed_peak_process_rss_bytes": "observed_peak_process_rss_bytes",
|
|
29
|
+
}
|
|
30
|
+
metrics = {}
|
|
31
|
+
for name, field in fields.items():
|
|
32
|
+
base = [
|
|
33
|
+
float(value)
|
|
34
|
+
for run in successful
|
|
35
|
+
if run.configuration_id == baseline_id
|
|
36
|
+
and (value := getattr(run.metrics, field)) is not None
|
|
37
|
+
]
|
|
38
|
+
candidate = [
|
|
39
|
+
float(value)
|
|
40
|
+
for run in successful
|
|
41
|
+
if run.configuration_id == candidate_id
|
|
42
|
+
and (value := getattr(run.metrics, field)) is not None
|
|
43
|
+
]
|
|
44
|
+
base_summary, candidate_summary = summarize(name, base), summarize(name, candidate)
|
|
45
|
+
base_median, candidate_median = base_summary.median, candidate_summary.median
|
|
46
|
+
speedup = (
|
|
47
|
+
candidate_median / base_median
|
|
48
|
+
if compatible and base_median and "per_second" in name
|
|
49
|
+
else None
|
|
50
|
+
)
|
|
51
|
+
reduction = (
|
|
52
|
+
(base_median - candidate_median) / base_median
|
|
53
|
+
if compatible and base_median and ("seconds" in name or "bytes" in name)
|
|
54
|
+
else None
|
|
55
|
+
)
|
|
56
|
+
metrics[name] = {
|
|
57
|
+
"baseline": base_median,
|
|
58
|
+
"candidate": candidate_median,
|
|
59
|
+
"speedup": speedup,
|
|
60
|
+
"reduction": reduction,
|
|
61
|
+
}
|
|
62
|
+
if compatible and "per_second" in name:
|
|
63
|
+
base_by_run = {
|
|
64
|
+
(run.workload_id, run.repetition): getattr(run.metrics, field)
|
|
65
|
+
for run in successful
|
|
66
|
+
if run.configuration_id == baseline_id
|
|
67
|
+
}
|
|
68
|
+
candidate_by_run = {
|
|
69
|
+
(run.workload_id, run.repetition): getattr(run.metrics, field)
|
|
70
|
+
for run in successful
|
|
71
|
+
if run.configuration_id == candidate_id
|
|
72
|
+
}
|
|
73
|
+
paired_ratios = [
|
|
74
|
+
float(candidate_by_run[key]) / float(base_value)
|
|
75
|
+
for key, base_value in base_by_run.items()
|
|
76
|
+
if base_value and candidate_by_run.get(key) is not None
|
|
77
|
+
]
|
|
78
|
+
interval = bootstrap_median_ci(paired_ratios)
|
|
79
|
+
metrics[name]["speedup_ci95_low"] = interval[0] if interval else None
|
|
80
|
+
metrics[name]["speedup_ci95_high"] = interval[1] if interval else None
|
|
81
|
+
return ComparisonResult(
|
|
82
|
+
compatible=compatible,
|
|
83
|
+
warnings=tuple(warnings),
|
|
84
|
+
baseline_id=baseline_id,
|
|
85
|
+
candidate_id=candidate_id,
|
|
86
|
+
metrics=metrics,
|
|
87
|
+
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from adaptive_local.benchmark.schemas import EvaluationMethod, QualityResult, WorkloadManifest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _normalized(value: str) -> str:
|
|
11
|
+
return " ".join(re.sub(r"[^\w\s]", " ", value.casefold()).split())
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def evaluate(run_id: str, workload: WorkloadManifest, response: str) -> QualityResult:
|
|
15
|
+
method = workload.evaluation_method
|
|
16
|
+
passed: bool | None = None
|
|
17
|
+
invalid = False
|
|
18
|
+
reason = None
|
|
19
|
+
try:
|
|
20
|
+
if method == EvaluationMethod.NONE:
|
|
21
|
+
reason = "no deterministic evaluator for this open-text task"
|
|
22
|
+
elif method == EvaluationMethod.EXACT:
|
|
23
|
+
passed = response.strip() == str(workload.expected_output).strip()
|
|
24
|
+
elif method == EvaluationMethod.NORMALIZED:
|
|
25
|
+
passed = _normalized(response) == _normalized(str(workload.expected_output))
|
|
26
|
+
elif method == EvaluationMethod.NUMERIC:
|
|
27
|
+
numeric = re.fullmatch(r"\s*([-+]?\d+(?:\.\d+)?)\s*", response)
|
|
28
|
+
if numeric is None:
|
|
29
|
+
raise ValueError("numeric response must contain only one number")
|
|
30
|
+
number = float(numeric.group(1))
|
|
31
|
+
passed = math.isclose(
|
|
32
|
+
number,
|
|
33
|
+
float(workload.expected_output),
|
|
34
|
+
abs_tol=float(workload.evaluation_options.get("tolerance", 0)),
|
|
35
|
+
)
|
|
36
|
+
elif method == EvaluationMethod.MULTIPLE_CHOICE:
|
|
37
|
+
answer = response.strip().upper()
|
|
38
|
+
expected = str(workload.expected_output).strip().upper()
|
|
39
|
+
passed = len(answer) == 1 and answer == expected
|
|
40
|
+
elif method == EvaluationMethod.JSON_VALID:
|
|
41
|
+
json.loads(response)
|
|
42
|
+
passed = True
|
|
43
|
+
elif method in {EvaluationMethod.REQUIRED_FIELDS, EvaluationMethod.JSON_SCHEMA}:
|
|
44
|
+
body = json.loads(response)
|
|
45
|
+
required = workload.evaluation_options.get("required", workload.expected_output or {})
|
|
46
|
+
passed = isinstance(body, dict) and all(
|
|
47
|
+
body.get(key) == value for key, value in required.items()
|
|
48
|
+
)
|
|
49
|
+
elif method == EvaluationMethod.INSTRUCTION:
|
|
50
|
+
folded = response.casefold()
|
|
51
|
+
passed = all(
|
|
52
|
+
x.casefold() in folded for x in workload.evaluation_options.get("contains", [])
|
|
53
|
+
) and not any(
|
|
54
|
+
x.casefold() in folded for x in workload.evaluation_options.get("forbidden", [])
|
|
55
|
+
)
|
|
56
|
+
elif method == EvaluationMethod.FACTS:
|
|
57
|
+
folded = response.casefold()
|
|
58
|
+
passed = all(str(x).casefold() in folded for x in workload.expected_output)
|
|
59
|
+
elif method == EvaluationMethod.TOOL_CALL:
|
|
60
|
+
body = json.loads(response)
|
|
61
|
+
passed = body.get("name") == workload.evaluation_options.get("name") and body.get(
|
|
62
|
+
"arguments"
|
|
63
|
+
) == workload.evaluation_options.get("arguments")
|
|
64
|
+
except (AttributeError, TypeError, ValueError, json.JSONDecodeError) as error:
|
|
65
|
+
invalid = True
|
|
66
|
+
passed = False
|
|
67
|
+
reason = f"invalid output for {method.value}: {error}"
|
|
68
|
+
if passed is False and reason is None:
|
|
69
|
+
reason = "output did not satisfy the frozen deterministic evaluator"
|
|
70
|
+
return QualityResult(
|
|
71
|
+
run_id=run_id,
|
|
72
|
+
workload_id=workload.workload_id,
|
|
73
|
+
category=workload.category,
|
|
74
|
+
method=method,
|
|
75
|
+
passed=passed,
|
|
76
|
+
invalid=invalid,
|
|
77
|
+
score=None if passed is None else float(passed),
|
|
78
|
+
reason=reason,
|
|
79
|
+
response_text=response,
|
|
80
|
+
)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from adaptive_local.benchmark.comparison import compare_configurations
|
|
7
|
+
from adaptive_local.benchmark.schemas import BenchmarkRun, ExperimentManifest, QualityResult
|
|
8
|
+
from adaptive_local.benchmark.statistics import summarize
|
|
9
|
+
from adaptive_local.benchmark.storage import atomic_json, read_jsonl
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_report(directory: Path) -> str:
|
|
13
|
+
manifest = ExperimentManifest.model_validate_json((directory / "experiment.json").read_text())
|
|
14
|
+
runs = read_jsonl(directory / "runs.jsonl", BenchmarkRun)
|
|
15
|
+
quality = read_jsonl(directory / "quality_results.jsonl", QualityResult)
|
|
16
|
+
successful = [run for run in runs if run.status == "success" and run.run_kind == "warm"]
|
|
17
|
+
summaries = {}
|
|
18
|
+
for config in manifest.configurations:
|
|
19
|
+
selected = [run for run in successful if run.configuration_id == config.configuration_id]
|
|
20
|
+
summaries[config.configuration_id] = {
|
|
21
|
+
"request_latency_seconds": summarize(
|
|
22
|
+
"request_latency_seconds",
|
|
23
|
+
[
|
|
24
|
+
run.metrics.request_latency_seconds
|
|
25
|
+
for run in selected
|
|
26
|
+
if run.metrics.request_latency_seconds is not None
|
|
27
|
+
],
|
|
28
|
+
).model_dump(mode="json"),
|
|
29
|
+
"decode_tokens_per_second_runtime": summarize(
|
|
30
|
+
"decode_tokens_per_second_runtime",
|
|
31
|
+
[
|
|
32
|
+
run.metrics.decode_tokens_per_second_runtime
|
|
33
|
+
for run in selected
|
|
34
|
+
if run.metrics.decode_tokens_per_second_runtime is not None
|
|
35
|
+
],
|
|
36
|
+
).model_dump(mode="json"),
|
|
37
|
+
"ttft_seconds": summarize(
|
|
38
|
+
"ttft_seconds",
|
|
39
|
+
[
|
|
40
|
+
run.metrics.ttft_seconds
|
|
41
|
+
for run in selected
|
|
42
|
+
if run.metrics.ttft_seconds is not None
|
|
43
|
+
],
|
|
44
|
+
).model_dump(mode="json"),
|
|
45
|
+
"error_rate": 1
|
|
46
|
+
- len(selected)
|
|
47
|
+
/ max(
|
|
48
|
+
1,
|
|
49
|
+
len(
|
|
50
|
+
[
|
|
51
|
+
run
|
|
52
|
+
for run in runs
|
|
53
|
+
if run.configuration_id == config.configuration_id
|
|
54
|
+
and run.run_kind == "warm"
|
|
55
|
+
]
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
"quality_accuracy": sum(
|
|
59
|
+
item.passed is True
|
|
60
|
+
for item in quality
|
|
61
|
+
if any(
|
|
62
|
+
run.run_id == item.run_id and run.configuration_id == config.configuration_id
|
|
63
|
+
for run in runs
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
/ max(
|
|
67
|
+
1,
|
|
68
|
+
sum(
|
|
69
|
+
item.passed is not None
|
|
70
|
+
for item in quality
|
|
71
|
+
if any(
|
|
72
|
+
run.run_id == item.run_id
|
|
73
|
+
and run.configuration_id == config.configuration_id
|
|
74
|
+
for run in runs
|
|
75
|
+
)
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
}
|
|
79
|
+
comparison = None
|
|
80
|
+
if len(manifest.configurations) == 2:
|
|
81
|
+
comparison = compare_configurations(
|
|
82
|
+
manifest,
|
|
83
|
+
runs,
|
|
84
|
+
manifest.configurations[0].configuration_id,
|
|
85
|
+
manifest.configurations[1].configuration_id,
|
|
86
|
+
)
|
|
87
|
+
summary = {
|
|
88
|
+
"experiment_id": manifest.experiment_id,
|
|
89
|
+
"run_count": len(runs),
|
|
90
|
+
"successful_warm_runs": len(successful),
|
|
91
|
+
"configurations": summaries,
|
|
92
|
+
"comparison": comparison.model_dump(mode="json") if comparison else None,
|
|
93
|
+
}
|
|
94
|
+
atomic_json(directory / "summary.json", summary)
|
|
95
|
+
lines = [
|
|
96
|
+
f"# Benchmark Report — {manifest.experiment_id}",
|
|
97
|
+
"",
|
|
98
|
+
f"Suite: `{manifest.suite_id}`",
|
|
99
|
+
f"Model: `{manifest.model.model_id}`",
|
|
100
|
+
f"Runtime: `{manifest.runtime.runtime}` {manifest.runtime.version or 'unknown'}",
|
|
101
|
+
"",
|
|
102
|
+
"## Results",
|
|
103
|
+
"",
|
|
104
|
+
]
|
|
105
|
+
for config_id, values in summaries.items():
|
|
106
|
+
lines.extend(
|
|
107
|
+
[
|
|
108
|
+
f"### {config_id}",
|
|
109
|
+
"",
|
|
110
|
+
f"- Warm runs: {values['request_latency_seconds']['count']}",
|
|
111
|
+
f"- Median latency: {values['request_latency_seconds']['median']}",
|
|
112
|
+
"- Median runtime decode tok/s: "
|
|
113
|
+
f"{values['decode_tokens_per_second_runtime']['median']}",
|
|
114
|
+
f"- Median TTFT: {values['ttft_seconds']['median']}",
|
|
115
|
+
f"- Error rate: {values['error_rate']:.3f}",
|
|
116
|
+
f"- Deterministic quality accuracy: {values['quality_accuracy']:.3f}",
|
|
117
|
+
"",
|
|
118
|
+
]
|
|
119
|
+
)
|
|
120
|
+
if comparison:
|
|
121
|
+
lines.extend(
|
|
122
|
+
[
|
|
123
|
+
"## Comparison",
|
|
124
|
+
"",
|
|
125
|
+
"```json",
|
|
126
|
+
json.dumps(comparison.model_dump(mode="json"), indent=2),
|
|
127
|
+
"```",
|
|
128
|
+
"",
|
|
129
|
+
]
|
|
130
|
+
)
|
|
131
|
+
lines.extend(
|
|
132
|
+
[
|
|
133
|
+
"## Limitations",
|
|
134
|
+
"",
|
|
135
|
+
"TTFT is client-observed. Chunk intervals are not token-level ITL when chunks "
|
|
136
|
+
"contain multiple tokens. Runtime-reported prefill/decode metrics remain distinct. "
|
|
137
|
+
"Periodic memory peaks are observed peaks.",
|
|
138
|
+
]
|
|
139
|
+
)
|
|
140
|
+
report = "\n".join(lines) + "\n"
|
|
141
|
+
(directory / "report.md").write_text(report)
|
|
142
|
+
return report
|