acprof 0.3.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.
Files changed (704) hide show
  1. acprof/__init__.py +3 -0
  2. acprof/__main__.py +5 -0
  3. acprof/_bundle/.dockerignore +20 -0
  4. acprof/_bundle/LICENSE +202 -0
  5. acprof/_bundle/NOTICE +43 -0
  6. acprof/_bundle/acprof/__init__.py +3 -0
  7. acprof/_bundle/acprof/__main__.py +5 -0
  8. acprof/_bundle/acprof/analysis/__init__.py +1 -0
  9. acprof/_bundle/acprof/analysis/audit.py +276 -0
  10. acprof/_bundle/acprof/analysis/comparison.py +364 -0
  11. acprof/_bundle/acprof/analysis/compatibility.py +223 -0
  12. acprof/_bundle/acprof/analysis/conditions.py +185 -0
  13. acprof/_bundle/acprof/analysis/independent_comparison.py +191 -0
  14. acprof/_bundle/acprof/analysis/latency_model.py +1106 -0
  15. acprof/_bundle/acprof/analysis/latency_report.py +577 -0
  16. acprof/_bundle/acprof/analysis/model.py +276 -0
  17. acprof/_bundle/acprof/analysis/precision.py +51 -0
  18. acprof/_bundle/acprof/analysis/uncertainty.py +144 -0
  19. acprof/_bundle/acprof/application/__init__.py +1 -0
  20. acprof/_bundle/acprof/application/download.py +14 -0
  21. acprof/_bundle/acprof/application/errors.py +5 -0
  22. acprof/_bundle/acprof/application/notifications.py +302 -0
  23. acprof/_bundle/acprof/application/preparation.py +333 -0
  24. acprof/_bundle/acprof/application/resources.py +66 -0
  25. acprof/_bundle/acprof/application/run.py +462 -0
  26. acprof/_bundle/acprof/application/terminal_log.py +136 -0
  27. acprof/_bundle/acprof/artifact_layout.py +261 -0
  28. acprof/_bundle/acprof/artifacts.py +161 -0
  29. acprof/_bundle/acprof/capabilities.py +404 -0
  30. acprof/_bundle/acprof/cli/__init__.py +1 -0
  31. acprof/_bundle/acprof/cli/audit.py +74 -0
  32. acprof/_bundle/acprof/cli/auto.py +41 -0
  33. acprof/_bundle/acprof/cli/backfill_compute.py +498 -0
  34. acprof/_bundle/acprof/cli/compare.py +34 -0
  35. acprof/_bundle/acprof/cli/coverage.py +70 -0
  36. acprof/_bundle/acprof/cli/doctor.py +47 -0
  37. acprof/_bundle/acprof/cli/inspect.py +101 -0
  38. acprof/_bundle/acprof/cli/load.py +190 -0
  39. acprof/_bundle/acprof/cli/main.py +64 -0
  40. acprof/_bundle/acprof/cli/model_store.py +22 -0
  41. acprof/_bundle/acprof/cli/plot.py +211 -0
  42. acprof/_bundle/acprof/cli/posthoc.py +113 -0
  43. acprof/_bundle/acprof/cli/probe.py +186 -0
  44. acprof/_bundle/acprof/cli/report.py +35 -0
  45. acprof/_bundle/acprof/cli/results.py +37 -0
  46. acprof/_bundle/acprof/cli/run.py +54 -0
  47. acprof/_bundle/acprof/cli/stats.py +94 -0
  48. acprof/_bundle/acprof/cli/tui.py +65 -0
  49. acprof/_bundle/acprof/config.py +177 -0
  50. acprof/_bundle/acprof/container/__init__.py +1 -0
  51. acprof/_bundle/acprof/container/compat/__init__.py +1 -0
  52. acprof/_bundle/acprof/container/compat/transformers_dynamic.py +54 -0
  53. acprof/_bundle/acprof/container/compat/transformers_model_types.json +1091 -0
  54. acprof/_bundle/acprof/container/compute_profile_runner.py +392 -0
  55. acprof/_bundle/acprof/container/download_model.py +165 -0
  56. acprof/_bundle/acprof/container/execution.py +73 -0
  57. acprof/_bundle/acprof/container/handlers/__init__.py +298 -0
  58. acprof/_bundle/acprof/container/handlers/audio.py +743 -0
  59. acprof/_bundle/acprof/container/handlers/custom_pipeline.py +74 -0
  60. acprof/_bundle/acprof/container/handlers/cv.py +321 -0
  61. acprof/_bundle/acprof/container/handlers/diffusion.py +728 -0
  62. acprof/_bundle/acprof/container/handlers/moss.py +64 -0
  63. acprof/_bundle/acprof/container/handlers/multimodal.py +609 -0
  64. acprof/_bundle/acprof/container/handlers/nlp.py +747 -0
  65. acprof/_bundle/acprof/container/handlers/onnx_tasks.py +231 -0
  66. acprof/_bundle/acprof/container/handlers/onnxruntime.py +90 -0
  67. acprof/_bundle/acprof/container/handlers/structured.py +185 -0
  68. acprof/_bundle/acprof/container/handlers/timeseries.py +178 -0
  69. acprof/_bundle/acprof/container/load_policy.py +81 -0
  70. acprof/_bundle/acprof/container/loading_quality.py +48 -0
  71. acprof/_bundle/acprof/container/local_pipeline.py +31 -0
  72. acprof/_bundle/acprof/container/model_files.py +280 -0
  73. acprof/_bundle/acprof/container/model_probe.py +80 -0
  74. acprof/_bundle/acprof/container/onnx_session.py +150 -0
  75. acprof/_bundle/acprof/container/runtime_manifest.py +150 -0
  76. acprof/_bundle/acprof/container/runtime_validate.py +156 -0
  77. acprof/_bundle/acprof/container/server.py +209 -0
  78. acprof/_bundle/acprof/container/torch_execution.py +55 -0
  79. acprof/_bundle/acprof/container/validation.py +172 -0
  80. acprof/_bundle/acprof/cpu_affinity.py +35 -0
  81. acprof/_bundle/acprof/dependency_locks.py +129 -0
  82. acprof/_bundle/acprof/experiment.py +356 -0
  83. acprof/_bundle/acprof/extensions/__init__.py +294 -0
  84. acprof/_bundle/acprof/extensions/builtin/manifest.json +3591 -0
  85. acprof/_bundle/acprof/extensions/onnxruntime/manifest.json +191 -0
  86. acprof/_bundle/acprof/extensions/schema.py +238 -0
  87. acprof/_bundle/acprof/extensions/transformers/4.57.6.json +1639 -0
  88. acprof/_bundle/acprof/extensions/transformers/5.10.4.json +1812 -0
  89. acprof/_bundle/acprof/failures.py +115 -0
  90. acprof/_bundle/acprof/hardware_conditions.py +18 -0
  91. acprof/_bundle/acprof/hf_download.py +143 -0
  92. acprof/_bundle/acprof/hf_endpoints.py +62 -0
  93. acprof/_bundle/acprof/hf_transport.py +238 -0
  94. acprof/_bundle/acprof/host/__init__.py +1 -0
  95. acprof/_bundle/acprof/host/automation.py +161 -0
  96. acprof/_bundle/acprof/host/client.py +520 -0
  97. acprof/_bundle/acprof/host/collection_history.py +77 -0
  98. acprof/_bundle/acprof/host/collection_workflow.py +285 -0
  99. acprof/_bundle/acprof/host/command.py +119 -0
  100. acprof/_bundle/acprof/host/container_lifecycle.py +225 -0
  101. acprof/_bundle/acprof/host/container_state.py +128 -0
  102. acprof/_bundle/acprof/host/coverage_state.py +259 -0
  103. acprof/_bundle/acprof/host/detect.py +669 -0
  104. acprof/_bundle/acprof/host/docker_runtime.py +359 -0
  105. acprof/_bundle/acprof/host/doctor.py +158 -0
  106. acprof/_bundle/acprof/host/env_utils.py +233 -0
  107. acprof/_bundle/acprof/host/execution_conditions.py +87 -0
  108. acprof/_bundle/acprof/host/gpu_device.py +66 -0
  109. acprof/_bundle/acprof/host/hardware_conditions.py +130 -0
  110. acprof/_bundle/acprof/host/images/__init__.py +1 -0
  111. acprof/_bundle/acprof/host/images/dependencies.py +169 -0
  112. acprof/_bundle/acprof/host/images/environment.py +313 -0
  113. acprof/_bundle/acprof/host/images/graph.py +143 -0
  114. acprof/_bundle/acprof/host/images/identity.py +6 -0
  115. acprof/_bundle/acprof/host/images/inventory.py +445 -0
  116. acprof/_bundle/acprof/host/images/runtime.py +457 -0
  117. acprof/_bundle/acprof/host/images/scan.py +154 -0
  118. acprof/_bundle/acprof/host/input_plan.py +1056 -0
  119. acprof/_bundle/acprof/host/interface_probe.py +141 -0
  120. acprof/_bundle/acprof/host/largest_scale_probe.py +566 -0
  121. acprof/_bundle/acprof/host/matrix_plan.py +98 -0
  122. acprof/_bundle/acprof/host/measurement/__init__.py +1 -0
  123. acprof/_bundle/acprof/host/measurement/boundary.py +162 -0
  124. acprof/_bundle/acprof/host/measurement/capture.py +139 -0
  125. acprof/_bundle/acprof/host/measurement/checkpoint.py +275 -0
  126. acprof/_bundle/acprof/host/measurement/config.py +212 -0
  127. acprof/_bundle/acprof/host/measurement/diagnostics.py +247 -0
  128. acprof/_bundle/acprof/host/measurement/energy_validation.py +172 -0
  129. acprof/_bundle/acprof/host/measurement/errors.py +25 -0
  130. acprof/_bundle/acprof/host/measurement/execution.py +396 -0
  131. acprof/_bundle/acprof/host/measurement/load.py +237 -0
  132. acprof/_bundle/acprof/host/measurement/metrics.py +975 -0
  133. acprof/_bundle/acprof/host/measurement/monitors.py +143 -0
  134. acprof/_bundle/acprof/host/measurement/publication.py +171 -0
  135. acprof/_bundle/acprof/host/measurement/requests.py +97 -0
  136. acprof/_bundle/acprof/host/measurement/types.py +82 -0
  137. acprof/_bundle/acprof/host/model_coverage.py +337 -0
  138. acprof/_bundle/acprof/host/model_errors.py +116 -0
  139. acprof/_bundle/acprof/host/model_inspection.py +107 -0
  140. acprof/_bundle/acprof/host/model_schema.py +35 -0
  141. acprof/_bundle/acprof/host/model_store.py +733 -0
  142. acprof/_bundle/acprof/host/network_preflight.py +229 -0
  143. acprof/_bundle/acprof/host/orchestrator.py +1133 -0
  144. acprof/_bundle/acprof/host/permissions.py +117 -0
  145. acprof/_bundle/acprof/host/platform_metadata.py +63 -0
  146. acprof/_bundle/acprof/host/posthoc/__init__.py +12 -0
  147. acprof/_bundle/acprof/host/posthoc/backfill.py +415 -0
  148. acprof/_bundle/acprof/host/posthoc/context.py +400 -0
  149. acprof/_bundle/acprof/host/posthoc/plans.py +597 -0
  150. acprof/_bundle/acprof/host/posthoc/service.py +303 -0
  151. acprof/_bundle/acprof/host/posthoc/storage.py +491 -0
  152. acprof/_bundle/acprof/host/preflight.py +370 -0
  153. acprof/_bundle/acprof/host/profiling/__init__.py +1 -0
  154. acprof/_bundle/acprof/host/profiling/compute.py +436 -0
  155. acprof/_bundle/acprof/host/profiling/compute_plan.py +261 -0
  156. acprof/_bundle/acprof/host/profiling/execution.py +547 -0
  157. acprof/_bundle/acprof/host/profiling/execution_plan.py +576 -0
  158. acprof/_bundle/acprof/host/profiling/progress.py +83 -0
  159. acprof/_bundle/acprof/host/profiling/support.py +252 -0
  160. acprof/_bundle/acprof/host/profiling/tools/__init__.py +1 -0
  161. acprof/_bundle/acprof/host/profiling/tools/advisor.py +164 -0
  162. acprof/_bundle/acprof/host/profiling/tools/compute_parsers.py +409 -0
  163. acprof/_bundle/acprof/host/profiling/tools/execution_environment.py +135 -0
  164. acprof/_bundle/acprof/host/profiling/tools/execution_parsers.py +364 -0
  165. acprof/_bundle/acprof/host/profiling/tools/massif.py +418 -0
  166. acprof/_bundle/acprof/host/profiling/tools/ncu.py +696 -0
  167. acprof/_bundle/acprof/host/profiling/tools/nsys.py +326 -0
  168. acprof/_bundle/acprof/host/profiling/tools/tool_discovery.py +229 -0
  169. acprof/_bundle/acprof/host/profiling/tools/torch.py +158 -0
  170. acprof/_bundle/acprof/host/result_cleanup.py +65 -0
  171. acprof/_bundle/acprof/host/run_state.py +639 -0
  172. acprof/_bundle/acprof/host/runtime_settings.py +10 -0
  173. acprof/_bundle/acprof/host/runtime_validation.py +302 -0
  174. acprof/_bundle/acprof/host/source_bundle.py +96 -0
  175. acprof/_bundle/acprof/host/startup_probe.py +95 -0
  176. acprof/_bundle/acprof/host/static_metadata.py +936 -0
  177. acprof/_bundle/acprof/host/task_support.py +121 -0
  178. acprof/_bundle/acprof/installation.py +26 -0
  179. acprof/_bundle/acprof/latency_slo.py +62 -0
  180. acprof/_bundle/acprof/messages.py +26 -0
  181. acprof/_bundle/acprof/metric_registry.py +315 -0
  182. acprof/_bundle/acprof/model_candidates.py +297 -0
  183. acprof/_bundle/acprof/model_contract.py +234 -0
  184. acprof/_bundle/acprof/model_dependencies.py +93 -0
  185. acprof/_bundle/acprof/model_dependency_domain.py +45 -0
  186. acprof/_bundle/acprof/model_dependency_eval.py +438 -0
  187. acprof/_bundle/acprof/model_dependency_flow.py +200 -0
  188. acprof/_bundle/acprof/model_evidence.py +115 -0
  189. acprof/_bundle/acprof/model_metadata_analysis.py +156 -0
  190. acprof/_bundle/acprof/model_repository.py +149 -0
  191. acprof/_bundle/acprof/model_resolution.py +129 -0
  192. acprof/_bundle/acprof/model_review.py +155 -0
  193. acprof/_bundle/acprof/model_source_analysis.py +299 -0
  194. acprof/_bundle/acprof/model_spec.py +204 -0
  195. acprof/_bundle/acprof/model_support.py +105 -0
  196. acprof/_bundle/acprof/model_transforms.py +81 -0
  197. acprof/_bundle/acprof/monitors/__init__.py +1 -0
  198. acprof/_bundle/acprof/monitors/common.py +63 -0
  199. acprof/_bundle/acprof/monitors/energy_cpu.py +651 -0
  200. acprof/_bundle/acprof/monitors/energy_nvml.py +381 -0
  201. acprof/_bundle/acprof/monitors/gpu_metrics.py +123 -0
  202. acprof/_bundle/acprof/monitors/interfaces.py +74 -0
  203. acprof/_bundle/acprof/monitors/perf_mips.py +617 -0
  204. acprof/_bundle/acprof/monitors/rapl_topology.py +100 -0
  205. acprof/_bundle/acprof/monitors/resource_metrics.py +472 -0
  206. acprof/_bundle/acprof/monitors/resource_readers.py +435 -0
  207. acprof/_bundle/acprof/monitors/resource_usage.py +450 -0
  208. acprof/_bundle/acprof/monitors/sampling.py +79 -0
  209. acprof/_bundle/acprof/network_policy.py +182 -0
  210. acprof/_bundle/acprof/notifications.py +279 -0
  211. acprof/_bundle/acprof/packet/__init__.py +1 -0
  212. acprof/_bundle/acprof/packet/merge_packet_latency.py +369 -0
  213. acprof/_bundle/acprof/packet/sniff_parse_pcap.py +240 -0
  214. acprof/_bundle/acprof/pixel_metrics.py +103 -0
  215. acprof/_bundle/acprof/platform.py +180 -0
  216. acprof/_bundle/acprof/plotting/__init__.py +1 -0
  217. acprof/_bundle/acprof/plotting/config.py +487 -0
  218. acprof/_bundle/acprof/plotting/data.py +236 -0
  219. acprof/_bundle/acprof/plotting/diagnostics.py +747 -0
  220. acprof/_bundle/acprof/plotting/latency.py +638 -0
  221. acprof/_bundle/acprof/plotting/metrics.py +648 -0
  222. acprof/_bundle/acprof/plotting/plotly-LICENSE.txt +21 -0
  223. acprof/_bundle/acprof/plotting/report.py +66 -0
  224. acprof/_bundle/acprof/plotting/styles.py +111 -0
  225. acprof/_bundle/acprof/precision.py +42 -0
  226. acprof/_bundle/acprof/preparation_events.py +78 -0
  227. acprof/_bundle/acprof/progress_events.py +105 -0
  228. acprof/_bundle/acprof/quality.py +153 -0
  229. acprof/_bundle/acprof/resource_budget.py +29 -0
  230. acprof/_bundle/acprof/result_csv.py +263 -0
  231. acprof/_bundle/acprof/result_layers.py +365 -0
  232. acprof/_bundle/acprof/run_args.py +223 -0
  233. acprof/_bundle/acprof/run_options.py +225 -0
  234. acprof/_bundle/acprof/runtime_dependencies.py +195 -0
  235. acprof/_bundle/acprof/runtime_profiles.py +258 -0
  236. acprof/_bundle/acprof/runtime_settings.py +72 -0
  237. acprof/_bundle/acprof/source_identity.py +68 -0
  238. acprof/_bundle/acprof/telemetry.py +225 -0
  239. acprof/_bundle/acprof/testing/__init__.py +1 -0
  240. acprof/_bundle/acprof/testing/evidence.py +117 -0
  241. acprof/_bundle/acprof/testing/plugin.py +126 -0
  242. acprof/_bundle/acprof/testing/provenance.py +53 -0
  243. acprof/_bundle/acprof/testing/sharding.py +14 -0
  244. acprof/_bundle/acprof/tui/__init__.py +1 -0
  245. acprof/_bundle/acprof/tui/app.py +934 -0
  246. acprof/_bundle/acprof/tui/app_contracts.py +43 -0
  247. acprof/_bundle/acprof/tui/catalog_controller.py +120 -0
  248. acprof/_bundle/acprof/tui/commands.py +209 -0
  249. acprof/_bundle/acprof/tui/configuration_controller.py +436 -0
  250. acprof/_bundle/acprof/tui/diagnostics.py +340 -0
  251. acprof/_bundle/acprof/tui/downloads.py +56 -0
  252. acprof/_bundle/acprof/tui/environment.py +248 -0
  253. acprof/_bundle/acprof/tui/experiment_catalog.py +279 -0
  254. acprof/_bundle/acprof/tui/experiment_controller.py +132 -0
  255. acprof/_bundle/acprof/tui/experiment_picker.py +273 -0
  256. acprof/_bundle/acprof/tui/field_validation.py +62 -0
  257. acprof/_bundle/acprof/tui/i18n.py +57 -0
  258. acprof/_bundle/acprof/tui/image_controller.py +525 -0
  259. acprof/_bundle/acprof/tui/images.py +737 -0
  260. acprof/_bundle/acprof/tui/input.py +191 -0
  261. acprof/_bundle/acprof/tui/localization_controller.py +110 -0
  262. acprof/_bundle/acprof/tui/log.py +310 -0
  263. acprof/_bundle/acprof/tui/model_candidates.py +278 -0
  264. acprof/_bundle/acprof/tui/model_controller.py +111 -0
  265. acprof/_bundle/acprof/tui/model_input.py +12 -0
  266. acprof/_bundle/acprof/tui/model_store.py +166 -0
  267. acprof/_bundle/acprof/tui/preflight_controller.py +271 -0
  268. acprof/_bundle/acprof/tui/preparation.py +269 -0
  269. acprof/_bundle/acprof/tui/presentation.py +46 -0
  270. acprof/_bundle/acprof/tui/process.py +111 -0
  271. acprof/_bundle/acprof/tui/process_controller.py +218 -0
  272. acprof/_bundle/acprof/tui/profile_controller.py +109 -0
  273. acprof/_bundle/acprof/tui/progress.py +195 -0
  274. acprof/_bundle/acprof/tui/recovery.py +114 -0
  275. acprof/_bundle/acprof/tui/recovery_controller.py +169 -0
  276. acprof/_bundle/acprof/tui/rendering.py +75 -0
  277. acprof/_bundle/acprof/tui/reports.py +303 -0
  278. acprof/_bundle/acprof/tui/result_controller.py +279 -0
  279. acprof/_bundle/acprof/tui/review_inputs.py +54 -0
  280. acprof/_bundle/acprof/tui/run_form.py +125 -0
  281. acprof/_bundle/acprof/tui/run_planning.py +97 -0
  282. acprof/_bundle/acprof/tui/run_results.py +175 -0
  283. acprof/_bundle/acprof/tui/scrollbar.py +65 -0
  284. acprof/_bundle/acprof/tui/settings.py +203 -0
  285. acprof/_bundle/acprof/tui/slash_controller.py +95 -0
  286. acprof/_bundle/acprof/tui/stages.py +97 -0
  287. acprof/_bundle/acprof/tui/storage.py +150 -0
  288. acprof/_bundle/acprof/tui/table.py +213 -0
  289. acprof/_bundle/acprof/tui/themes.py +112 -0
  290. acprof/_bundle/acprof/tui/translation_catalog.py +1861 -0
  291. acprof/_bundle/acprof/tui/tui.tcss +373 -0
  292. acprof/_bundle/acprof/tui/views.py +706 -0
  293. acprof/_bundle/acprof/window_records.py +165 -0
  294. acprof/_bundle/acprof/workloads/__init__.py +222 -0
  295. acprof/_bundle/acprof/workloads/audio.py +621 -0
  296. acprof/_bundle/acprof/workloads/contract.py +116 -0
  297. acprof/_bundle/acprof/workloads/cv.py +240 -0
  298. acprof/_bundle/acprof/workloads/diffusion.py +410 -0
  299. acprof/_bundle/acprof/workloads/multimodal.py +329 -0
  300. acprof/_bundle/acprof/workloads/nlp.py +151 -0
  301. acprof/_bundle/acprof/workloads/structured.py +151 -0
  302. acprof/_bundle/acprof/workloads/timeseries.py +69 -0
  303. acprof/_bundle/assets/audio/librispeech-clean-test-en-30s/audio.wav +0 -0
  304. acprof/_bundle/assets/audio/librispeech-clean-test-en-30s/source.json +81 -0
  305. acprof/_bundle/dockerfiles/environment_tools.py +314 -0
  306. acprof/_bundle/dockerfiles/locks/audio-cpu.artifacts.json +503 -0
  307. acprof/_bundle/dockerfiles/locks/audio-cpu.txt +143 -0
  308. acprof/_bundle/dockerfiles/locks/audio-cu124.artifacts.json +600 -0
  309. acprof/_bundle/dockerfiles/locks/audio-cu124.txt +171 -0
  310. acprof/_bundle/dockerfiles/locks/audio-cu128.artifacts.json +544 -0
  311. acprof/_bundle/dockerfiles/locks/audio-cu128.txt +155 -0
  312. acprof/_bundle/dockerfiles/locks/custom-multimodal-cpu.artifacts.json +510 -0
  313. acprof/_bundle/dockerfiles/locks/custom-multimodal-cpu.txt +145 -0
  314. acprof/_bundle/dockerfiles/locks/custom-multimodal-cu124.artifacts.json +607 -0
  315. acprof/_bundle/dockerfiles/locks/custom-multimodal-cu124.txt +173 -0
  316. acprof/_bundle/dockerfiles/locks/custom-multimodal-cu128.artifacts.json +642 -0
  317. acprof/_bundle/dockerfiles/locks/custom-multimodal-cu128.txt +183 -0
  318. acprof/_bundle/dockerfiles/locks/cv-cpu.artifacts.json +279 -0
  319. acprof/_bundle/dockerfiles/locks/cv-cpu.txt +79 -0
  320. acprof/_bundle/dockerfiles/locks/cv-cu124.artifacts.json +376 -0
  321. acprof/_bundle/dockerfiles/locks/cv-cu124.txt +107 -0
  322. acprof/_bundle/dockerfiles/locks/cv-cu128.artifacts.json +411 -0
  323. acprof/_bundle/dockerfiles/locks/cv-cu128.txt +117 -0
  324. acprof/_bundle/dockerfiles/locks/diffusion-cpu.artifacts.json +335 -0
  325. acprof/_bundle/dockerfiles/locks/diffusion-cpu.txt +95 -0
  326. acprof/_bundle/dockerfiles/locks/diffusion-cu124.artifacts.json +432 -0
  327. acprof/_bundle/dockerfiles/locks/diffusion-cu124.txt +123 -0
  328. acprof/_bundle/dockerfiles/locks/diffusion-cu128.artifacts.json +467 -0
  329. acprof/_bundle/dockerfiles/locks/diffusion-cu128.txt +133 -0
  330. acprof/_bundle/dockerfiles/locks/moss-transformers5104.artifacts.json +621 -0
  331. acprof/_bundle/dockerfiles/locks/moss-transformers5104.txt +177 -0
  332. acprof/_bundle/dockerfiles/locks/multimodal-transformers4576.artifacts.json +635 -0
  333. acprof/_bundle/dockerfiles/locks/multimodal-transformers4576.txt +181 -0
  334. acprof/_bundle/dockerfiles/locks/nlp-cpu.artifacts.json +363 -0
  335. acprof/_bundle/dockerfiles/locks/nlp-cpu.txt +103 -0
  336. acprof/_bundle/dockerfiles/locks/nlp-cu124.artifacts.json +460 -0
  337. acprof/_bundle/dockerfiles/locks/nlp-cu124.txt +131 -0
  338. acprof/_bundle/dockerfiles/locks/nlp-cu128.artifacts.json +495 -0
  339. acprof/_bundle/dockerfiles/locks/nlp-cu128.txt +141 -0
  340. acprof/_bundle/dockerfiles/locks/onnxruntime-cpu.artifacts.json +261 -0
  341. acprof/_bundle/dockerfiles/locks/onnxruntime-cpu.txt +73 -0
  342. acprof/_bundle/dockerfiles/locks/platform-cpu.artifacts.json +99 -0
  343. acprof/_bundle/dockerfiles/locks/platform-cpu.txt +27 -0
  344. acprof/_bundle/dockerfiles/locks/platform-cu124.artifacts.json +196 -0
  345. acprof/_bundle/dockerfiles/locks/platform-cu124.txt +55 -0
  346. acprof/_bundle/dockerfiles/locks/platform-cu128.artifacts.json +231 -0
  347. acprof/_bundle/dockerfiles/locks/platform-cu128.txt +65 -0
  348. acprof/_bundle/dockerfiles/locks/platform-python-cpu.artifacts.json +37 -0
  349. acprof/_bundle/dockerfiles/locks/platform-python-cpu.txt +9 -0
  350. acprof/_bundle/dockerfiles/locks/structured-cpu.artifacts.json +279 -0
  351. acprof/_bundle/dockerfiles/locks/structured-cpu.txt +79 -0
  352. acprof/_bundle/dockerfiles/locks/structured-cu124.artifacts.json +376 -0
  353. acprof/_bundle/dockerfiles/locks/structured-cu124.txt +107 -0
  354. acprof/_bundle/dockerfiles/locks/structured-cu128.artifacts.json +411 -0
  355. acprof/_bundle/dockerfiles/locks/structured-cu128.txt +117 -0
  356. acprof/_bundle/dockerfiles/locks/system-trixie-amd64.json +620 -0
  357. acprof/_bundle/dockerfiles/locks/timeseries-cpu.artifacts.json +314 -0
  358. acprof/_bundle/dockerfiles/locks/timeseries-cpu.txt +89 -0
  359. acprof/_bundle/dockerfiles/locks/timeseries-cu124.artifacts.json +411 -0
  360. acprof/_bundle/dockerfiles/locks/timeseries-cu124.txt +117 -0
  361. acprof/_bundle/dockerfiles/locks/timeseries-cu128.artifacts.json +446 -0
  362. acprof/_bundle/dockerfiles/locks/timeseries-cu128.txt +127 -0
  363. acprof/_bundle/dockerfiles/locks/transformers5104-cpu.artifacts.json +594 -0
  364. acprof/_bundle/dockerfiles/locks/transformers5104-cpu.txt +169 -0
  365. acprof/_bundle/dockerfiles/locks/transformers5104-cu124.artifacts.json +691 -0
  366. acprof/_bundle/dockerfiles/locks/transformers5104-cu124.txt +197 -0
  367. acprof/_bundle/dockerfiles/locks/transformers5104-cu128.artifacts.json +726 -0
  368. acprof/_bundle/dockerfiles/locks/transformers5104-cu128.txt +207 -0
  369. acprof/_bundle/dockerfiles/platform.Dockerfile +22 -0
  370. acprof/_bundle/dockerfiles/requirements/audio.in +5 -0
  371. acprof/_bundle/dockerfiles/requirements/custom-multimodal.in +2 -0
  372. acprof/_bundle/dockerfiles/requirements/cv.in +4 -0
  373. acprof/_bundle/dockerfiles/requirements/diffusion.in +6 -0
  374. acprof/_bundle/dockerfiles/requirements/moss-transformers5104.in +9 -0
  375. acprof/_bundle/dockerfiles/requirements/multimodal-transformers4576.in +3 -0
  376. acprof/_bundle/dockerfiles/requirements/nlp.in +7 -0
  377. acprof/_bundle/dockerfiles/requirements/onnxruntime.in +9 -0
  378. acprof/_bundle/dockerfiles/requirements/service.in +8 -0
  379. acprof/_bundle/dockerfiles/requirements/structured.in +4 -0
  380. acprof/_bundle/dockerfiles/requirements/timeseries.in +2 -0
  381. acprof/_bundle/dockerfiles/requirements/timm.in +1 -0
  382. acprof/_bundle/dockerfiles/requirements/transformers5104.in +4 -0
  383. acprof/_bundle/dockerfiles/runtime-final.Dockerfile +34 -0
  384. acprof/_bundle/dockerfiles/runtime-model.Dockerfile +19 -0
  385. acprof/_bundle/dockerfiles/runtime.Dockerfile +23 -0
  386. acprof/_bundle/examples/coverage/regression.json +17 -0
  387. acprof/_bundle/examples/hardware-validation.json +19 -0
  388. acprof/_bundle/examples/multimodal/ultravox.model.json +29 -0
  389. acprof/_bundle/examples/nlp/smoke.py +111 -0
  390. acprof/_bundle/examples/onnxruntime/fixtures.py +164 -0
  391. acprof/_bundle/examples/onnxruntime/iris.json +16 -0
  392. acprof/_bundle/examples/onnxruntime/iris.model.json +7 -0
  393. acprof/_bundle/examples/onnxruntime/real_models.py +155 -0
  394. acprof/_bundle/examples/onnxruntime/smoke.py +68 -0
  395. acprof/_bundle/examples/structured/chronos_smoke.py +56 -0
  396. acprof/_bundle/examples/structured/export_models.py +71 -0
  397. acprof/_bundle/examples/structured/smoke.py +71 -0
  398. acprof/_bundle/licenses/CC-BY-4.0.txt +156 -0
  399. acprof/analysis/__init__.py +1 -0
  400. acprof/analysis/audit.py +276 -0
  401. acprof/analysis/comparison.py +364 -0
  402. acprof/analysis/compatibility.py +223 -0
  403. acprof/analysis/conditions.py +185 -0
  404. acprof/analysis/independent_comparison.py +191 -0
  405. acprof/analysis/latency_model.py +1106 -0
  406. acprof/analysis/latency_report.py +577 -0
  407. acprof/analysis/model.py +276 -0
  408. acprof/analysis/precision.py +51 -0
  409. acprof/analysis/uncertainty.py +144 -0
  410. acprof/application/__init__.py +1 -0
  411. acprof/application/download.py +14 -0
  412. acprof/application/errors.py +5 -0
  413. acprof/application/notifications.py +302 -0
  414. acprof/application/preparation.py +333 -0
  415. acprof/application/resources.py +66 -0
  416. acprof/application/run.py +462 -0
  417. acprof/application/terminal_log.py +136 -0
  418. acprof/artifact_layout.py +261 -0
  419. acprof/artifacts.py +161 -0
  420. acprof/capabilities.py +404 -0
  421. acprof/cli/__init__.py +1 -0
  422. acprof/cli/audit.py +74 -0
  423. acprof/cli/auto.py +41 -0
  424. acprof/cli/backfill_compute.py +498 -0
  425. acprof/cli/compare.py +34 -0
  426. acprof/cli/coverage.py +70 -0
  427. acprof/cli/doctor.py +47 -0
  428. acprof/cli/inspect.py +101 -0
  429. acprof/cli/load.py +190 -0
  430. acprof/cli/main.py +64 -0
  431. acprof/cli/model_store.py +22 -0
  432. acprof/cli/plot.py +211 -0
  433. acprof/cli/posthoc.py +113 -0
  434. acprof/cli/probe.py +186 -0
  435. acprof/cli/report.py +35 -0
  436. acprof/cli/results.py +37 -0
  437. acprof/cli/run.py +54 -0
  438. acprof/cli/stats.py +94 -0
  439. acprof/cli/tui.py +65 -0
  440. acprof/config.py +177 -0
  441. acprof/container/__init__.py +1 -0
  442. acprof/container/compat/__init__.py +1 -0
  443. acprof/container/compat/transformers_dynamic.py +54 -0
  444. acprof/container/compat/transformers_model_types.json +1091 -0
  445. acprof/container/compute_profile_runner.py +392 -0
  446. acprof/container/download_model.py +165 -0
  447. acprof/container/execution.py +73 -0
  448. acprof/container/handlers/__init__.py +298 -0
  449. acprof/container/handlers/audio.py +743 -0
  450. acprof/container/handlers/custom_pipeline.py +74 -0
  451. acprof/container/handlers/cv.py +321 -0
  452. acprof/container/handlers/diffusion.py +728 -0
  453. acprof/container/handlers/moss.py +64 -0
  454. acprof/container/handlers/multimodal.py +609 -0
  455. acprof/container/handlers/nlp.py +747 -0
  456. acprof/container/handlers/onnx_tasks.py +231 -0
  457. acprof/container/handlers/onnxruntime.py +90 -0
  458. acprof/container/handlers/structured.py +185 -0
  459. acprof/container/handlers/timeseries.py +178 -0
  460. acprof/container/load_policy.py +81 -0
  461. acprof/container/loading_quality.py +48 -0
  462. acprof/container/local_pipeline.py +31 -0
  463. acprof/container/model_files.py +280 -0
  464. acprof/container/model_probe.py +80 -0
  465. acprof/container/onnx_session.py +150 -0
  466. acprof/container/runtime_manifest.py +150 -0
  467. acprof/container/runtime_validate.py +156 -0
  468. acprof/container/server.py +209 -0
  469. acprof/container/torch_execution.py +55 -0
  470. acprof/container/validation.py +172 -0
  471. acprof/cpu_affinity.py +35 -0
  472. acprof/dependency_locks.py +129 -0
  473. acprof/experiment.py +356 -0
  474. acprof/extensions/__init__.py +294 -0
  475. acprof/extensions/builtin/manifest.json +3591 -0
  476. acprof/extensions/onnxruntime/manifest.json +191 -0
  477. acprof/extensions/schema.py +238 -0
  478. acprof/extensions/transformers/4.57.6.json +1639 -0
  479. acprof/extensions/transformers/5.10.4.json +1812 -0
  480. acprof/failures.py +115 -0
  481. acprof/hardware_conditions.py +18 -0
  482. acprof/hf_download.py +143 -0
  483. acprof/hf_endpoints.py +62 -0
  484. acprof/hf_transport.py +238 -0
  485. acprof/host/__init__.py +1 -0
  486. acprof/host/automation.py +161 -0
  487. acprof/host/client.py +520 -0
  488. acprof/host/collection_history.py +77 -0
  489. acprof/host/collection_workflow.py +285 -0
  490. acprof/host/command.py +119 -0
  491. acprof/host/container_lifecycle.py +225 -0
  492. acprof/host/container_state.py +128 -0
  493. acprof/host/coverage_state.py +259 -0
  494. acprof/host/detect.py +669 -0
  495. acprof/host/docker_runtime.py +359 -0
  496. acprof/host/doctor.py +158 -0
  497. acprof/host/env_utils.py +233 -0
  498. acprof/host/execution_conditions.py +87 -0
  499. acprof/host/gpu_device.py +66 -0
  500. acprof/host/hardware_conditions.py +130 -0
  501. acprof/host/images/__init__.py +1 -0
  502. acprof/host/images/dependencies.py +169 -0
  503. acprof/host/images/environment.py +313 -0
  504. acprof/host/images/graph.py +143 -0
  505. acprof/host/images/identity.py +6 -0
  506. acprof/host/images/inventory.py +445 -0
  507. acprof/host/images/runtime.py +457 -0
  508. acprof/host/images/scan.py +154 -0
  509. acprof/host/input_plan.py +1056 -0
  510. acprof/host/interface_probe.py +141 -0
  511. acprof/host/largest_scale_probe.py +566 -0
  512. acprof/host/matrix_plan.py +98 -0
  513. acprof/host/measurement/__init__.py +1 -0
  514. acprof/host/measurement/boundary.py +162 -0
  515. acprof/host/measurement/capture.py +139 -0
  516. acprof/host/measurement/checkpoint.py +275 -0
  517. acprof/host/measurement/config.py +212 -0
  518. acprof/host/measurement/diagnostics.py +247 -0
  519. acprof/host/measurement/energy_validation.py +172 -0
  520. acprof/host/measurement/errors.py +25 -0
  521. acprof/host/measurement/execution.py +396 -0
  522. acprof/host/measurement/load.py +237 -0
  523. acprof/host/measurement/metrics.py +975 -0
  524. acprof/host/measurement/monitors.py +143 -0
  525. acprof/host/measurement/publication.py +171 -0
  526. acprof/host/measurement/requests.py +97 -0
  527. acprof/host/measurement/types.py +82 -0
  528. acprof/host/model_coverage.py +337 -0
  529. acprof/host/model_errors.py +116 -0
  530. acprof/host/model_inspection.py +107 -0
  531. acprof/host/model_schema.py +35 -0
  532. acprof/host/model_store.py +733 -0
  533. acprof/host/network_preflight.py +229 -0
  534. acprof/host/orchestrator.py +1133 -0
  535. acprof/host/permissions.py +117 -0
  536. acprof/host/platform_metadata.py +63 -0
  537. acprof/host/posthoc/__init__.py +12 -0
  538. acprof/host/posthoc/backfill.py +415 -0
  539. acprof/host/posthoc/context.py +400 -0
  540. acprof/host/posthoc/plans.py +597 -0
  541. acprof/host/posthoc/service.py +303 -0
  542. acprof/host/posthoc/storage.py +491 -0
  543. acprof/host/preflight.py +370 -0
  544. acprof/host/profiling/__init__.py +1 -0
  545. acprof/host/profiling/compute.py +436 -0
  546. acprof/host/profiling/compute_plan.py +261 -0
  547. acprof/host/profiling/execution.py +547 -0
  548. acprof/host/profiling/execution_plan.py +576 -0
  549. acprof/host/profiling/progress.py +83 -0
  550. acprof/host/profiling/support.py +252 -0
  551. acprof/host/profiling/tools/__init__.py +1 -0
  552. acprof/host/profiling/tools/advisor.py +164 -0
  553. acprof/host/profiling/tools/compute_parsers.py +409 -0
  554. acprof/host/profiling/tools/execution_environment.py +135 -0
  555. acprof/host/profiling/tools/execution_parsers.py +364 -0
  556. acprof/host/profiling/tools/massif.py +418 -0
  557. acprof/host/profiling/tools/ncu.py +696 -0
  558. acprof/host/profiling/tools/nsys.py +326 -0
  559. acprof/host/profiling/tools/tool_discovery.py +229 -0
  560. acprof/host/profiling/tools/torch.py +158 -0
  561. acprof/host/result_cleanup.py +65 -0
  562. acprof/host/run_state.py +639 -0
  563. acprof/host/runtime_settings.py +10 -0
  564. acprof/host/runtime_validation.py +302 -0
  565. acprof/host/source_bundle.py +96 -0
  566. acprof/host/startup_probe.py +95 -0
  567. acprof/host/static_metadata.py +936 -0
  568. acprof/host/task_support.py +121 -0
  569. acprof/installation.py +26 -0
  570. acprof/latency_slo.py +62 -0
  571. acprof/messages.py +26 -0
  572. acprof/metric_registry.py +315 -0
  573. acprof/model_candidates.py +297 -0
  574. acprof/model_contract.py +234 -0
  575. acprof/model_dependencies.py +93 -0
  576. acprof/model_dependency_domain.py +45 -0
  577. acprof/model_dependency_eval.py +438 -0
  578. acprof/model_dependency_flow.py +200 -0
  579. acprof/model_evidence.py +115 -0
  580. acprof/model_metadata_analysis.py +156 -0
  581. acprof/model_repository.py +149 -0
  582. acprof/model_resolution.py +129 -0
  583. acprof/model_review.py +155 -0
  584. acprof/model_source_analysis.py +299 -0
  585. acprof/model_spec.py +204 -0
  586. acprof/model_support.py +105 -0
  587. acprof/model_transforms.py +81 -0
  588. acprof/monitors/__init__.py +1 -0
  589. acprof/monitors/common.py +63 -0
  590. acprof/monitors/energy_cpu.py +651 -0
  591. acprof/monitors/energy_nvml.py +381 -0
  592. acprof/monitors/gpu_metrics.py +123 -0
  593. acprof/monitors/interfaces.py +74 -0
  594. acprof/monitors/perf_mips.py +617 -0
  595. acprof/monitors/rapl_topology.py +100 -0
  596. acprof/monitors/resource_metrics.py +472 -0
  597. acprof/monitors/resource_readers.py +435 -0
  598. acprof/monitors/resource_usage.py +450 -0
  599. acprof/monitors/sampling.py +79 -0
  600. acprof/network_policy.py +182 -0
  601. acprof/notifications.py +279 -0
  602. acprof/packet/__init__.py +1 -0
  603. acprof/packet/merge_packet_latency.py +369 -0
  604. acprof/packet/sniff_parse_pcap.py +240 -0
  605. acprof/pixel_metrics.py +103 -0
  606. acprof/platform.py +180 -0
  607. acprof/plotting/__init__.py +1 -0
  608. acprof/plotting/config.py +487 -0
  609. acprof/plotting/data.py +236 -0
  610. acprof/plotting/diagnostics.py +747 -0
  611. acprof/plotting/latency.py +638 -0
  612. acprof/plotting/metrics.py +648 -0
  613. acprof/plotting/plotly-LICENSE.txt +21 -0
  614. acprof/plotting/report.css +61 -0
  615. acprof/plotting/report.html +68 -0
  616. acprof/plotting/report.js +295 -0
  617. acprof/plotting/report.py +66 -0
  618. acprof/plotting/styles.py +111 -0
  619. acprof/plotting/view_model.js +145 -0
  620. acprof/precision.py +42 -0
  621. acprof/preparation_events.py +78 -0
  622. acprof/progress_events.py +105 -0
  623. acprof/quality.py +153 -0
  624. acprof/resource_budget.py +29 -0
  625. acprof/result_csv.py +263 -0
  626. acprof/result_layers.py +365 -0
  627. acprof/run_args.py +223 -0
  628. acprof/run_options.py +225 -0
  629. acprof/runtime_dependencies.py +195 -0
  630. acprof/runtime_profiles.py +258 -0
  631. acprof/runtime_settings.py +72 -0
  632. acprof/source_identity.py +68 -0
  633. acprof/telemetry.py +225 -0
  634. acprof/testing/__init__.py +1 -0
  635. acprof/testing/evidence.py +117 -0
  636. acprof/testing/plugin.py +126 -0
  637. acprof/testing/provenance.py +53 -0
  638. acprof/testing/sharding.py +14 -0
  639. acprof/tui/__init__.py +1 -0
  640. acprof/tui/app.py +934 -0
  641. acprof/tui/app_contracts.py +43 -0
  642. acprof/tui/catalog_controller.py +120 -0
  643. acprof/tui/commands.py +209 -0
  644. acprof/tui/configuration_controller.py +436 -0
  645. acprof/tui/diagnostics.py +340 -0
  646. acprof/tui/downloads.py +56 -0
  647. acprof/tui/environment.py +248 -0
  648. acprof/tui/experiment_catalog.py +279 -0
  649. acprof/tui/experiment_controller.py +132 -0
  650. acprof/tui/experiment_picker.py +273 -0
  651. acprof/tui/field_validation.py +62 -0
  652. acprof/tui/i18n.py +57 -0
  653. acprof/tui/image_controller.py +525 -0
  654. acprof/tui/images.py +737 -0
  655. acprof/tui/input.py +191 -0
  656. acprof/tui/localization_controller.py +110 -0
  657. acprof/tui/log.py +310 -0
  658. acprof/tui/model_candidates.py +278 -0
  659. acprof/tui/model_controller.py +111 -0
  660. acprof/tui/model_input.py +12 -0
  661. acprof/tui/model_store.py +166 -0
  662. acprof/tui/preflight_controller.py +271 -0
  663. acprof/tui/preparation.py +269 -0
  664. acprof/tui/presentation.py +46 -0
  665. acprof/tui/process.py +111 -0
  666. acprof/tui/process_controller.py +218 -0
  667. acprof/tui/profile_controller.py +109 -0
  668. acprof/tui/progress.py +195 -0
  669. acprof/tui/recovery.py +114 -0
  670. acprof/tui/recovery_controller.py +169 -0
  671. acprof/tui/rendering.py +75 -0
  672. acprof/tui/reports.py +303 -0
  673. acprof/tui/result_controller.py +279 -0
  674. acprof/tui/review_inputs.py +54 -0
  675. acprof/tui/run_form.py +125 -0
  676. acprof/tui/run_planning.py +97 -0
  677. acprof/tui/run_results.py +175 -0
  678. acprof/tui/scrollbar.py +65 -0
  679. acprof/tui/settings.py +203 -0
  680. acprof/tui/slash_controller.py +95 -0
  681. acprof/tui/stages.py +97 -0
  682. acprof/tui/storage.py +150 -0
  683. acprof/tui/table.py +213 -0
  684. acprof/tui/themes.py +112 -0
  685. acprof/tui/translation_catalog.py +1861 -0
  686. acprof/tui/tui.tcss +373 -0
  687. acprof/tui/views.py +706 -0
  688. acprof/window_records.py +165 -0
  689. acprof/workloads/__init__.py +222 -0
  690. acprof/workloads/audio.py +621 -0
  691. acprof/workloads/contract.py +116 -0
  692. acprof/workloads/cv.py +240 -0
  693. acprof/workloads/diffusion.py +410 -0
  694. acprof/workloads/multimodal.py +329 -0
  695. acprof/workloads/nlp.py +151 -0
  696. acprof/workloads/structured.py +151 -0
  697. acprof/workloads/timeseries.py +69 -0
  698. acprof-0.3.0.dist-info/METADATA +117 -0
  699. acprof-0.3.0.dist-info/RECORD +704 -0
  700. acprof-0.3.0.dist-info/WHEEL +4 -0
  701. acprof-0.3.0.dist-info/entry_points.txt +2 -0
  702. acprof-0.3.0.dist-info/licenses/LICENSE +202 -0
  703. acprof-0.3.0.dist-info/licenses/NOTICE +43 -0
  704. acprof-0.3.0.dist-info/licenses/licenses/CC-BY-4.0.txt +156 -0
@@ -0,0 +1,1106 @@
1
+ """数值延迟模型拟合、预测及验证;不依赖绘图层。"""
2
+
3
+ import math
4
+ from types import SimpleNamespace
5
+ from typing import Any
6
+
7
+ import numpy as np
8
+ import pandas as pd
9
+
10
+ GPU_MODE_ON_VALUES = {"on", "1", "1.0", "true", "yes", "gpu"}
11
+ GPU_MODE_OFF_VALUES = {"off", "0", "0.0", "false", "no", "cpu"}
12
+ LATENCY_MODEL_FEATURES = {
13
+ "cpu": [
14
+ "intercept",
15
+ "log_input_scale",
16
+ "log_input_scale_squared",
17
+ "log_cpu_cores",
18
+ "log_cpu_cores_squared",
19
+ "log_mem_cap_gb",
20
+ "log_input_scale_x_log_cpu_cores",
21
+ "log_input_scale_x_log_mem_cap_gb",
22
+ "log_cpu_cores_x_log_mem_cap_gb",
23
+ ],
24
+ "gpu": [
25
+ "intercept",
26
+ "log_input_scale",
27
+ "inverse_cpu_cores",
28
+ "inverse_cpu_cores_squared",
29
+ "log_mem_cap_gb",
30
+ "log_input_scale_x_inverse_cpu_cores",
31
+ "log_input_scale_x_inverse_cpu_cores_squared",
32
+ ],
33
+ }
34
+ LATENCY_MODEL_RESOURCE_FEATURES = {
35
+ "cpu": {
36
+ "log_cpu_cores",
37
+ "log_cpu_cores_squared",
38
+ "log_mem_cap_gb",
39
+ "log_input_scale_x_log_cpu_cores",
40
+ "log_input_scale_x_log_mem_cap_gb",
41
+ "log_cpu_cores_x_log_mem_cap_gb",
42
+ },
43
+ "gpu": {
44
+ "inverse_cpu_cores",
45
+ "inverse_cpu_cores_squared",
46
+ "log_mem_cap_gb",
47
+ "log_input_scale_x_inverse_cpu_cores",
48
+ "log_input_scale_x_inverse_cpu_cores_squared",
49
+ },
50
+ }
51
+ LATENCY_MODEL_FORMULAS = {
52
+ "cpu": (
53
+ "latency_s = exp(intercept + log_input_scale "
54
+ "+ log_input_scale_squared "
55
+ "+ log_cpu_cores + log_cpu_cores_squared + log_mem_cap_gb "
56
+ "+ log_input_scale_x_log_cpu_cores "
57
+ "+ log_input_scale_x_log_mem_cap_gb "
58
+ "+ log_cpu_cores_x_log_mem_cap_gb)"
59
+ ),
60
+ "gpu": (
61
+ "within-range latency_s = exp(intercept + log_input_scale "
62
+ "+ piecewise_linear_log_input_scale_hinges "
63
+ "+ inverse_cpu_cores + inverse_cpu_cores_squared "
64
+ "+ log_mem_cap_gb + log_input_scale_x_inverse_cpu_cores "
65
+ "+ log_input_scale_x_inverse_cpu_cores_squared); when activated, "
66
+ "upper-tail latency_s = boundary_spline_latency_s + "
67
+ "affine_tail(input_scale) - affine_tail(boundary_input_scale)"
68
+ ),
69
+ }
70
+ LATENCY_MODEL_GPU_UPPER_TAIL_FEATURES = [
71
+ "intercept",
72
+ "input_scale",
73
+ "inverse_cpu_cores",
74
+ "inverse_cpu_cores_squared",
75
+ "log_mem_cap_gb",
76
+ "input_scale_x_inverse_cpu_cores",
77
+ "input_scale_x_inverse_cpu_cores_squared",
78
+ ]
79
+ # A GPU log-spline is excellent inside the profiled scale range, but extending
80
+ # one noisy boundary segment can be brittle. When a nested one-step-forward
81
+ # check exceeds this MAPE, upper extrapolation switches to a continuous affine
82
+ # work tail fitted in latency space.
83
+ LATENCY_MODEL_GPU_UPPER_TAIL_ACTIVATION_MAPE = 0.05
84
+ LATENCY_MODEL_GPU_UPPER_TAIL_MIN_SCALE_SPAN_RATIO = 10.0
85
+ LATENCY_MODEL_MIN_VALIDATION_R2 = 0.80
86
+ LATENCY_MODEL_MAX_VALIDATION_RELATIVE_MAE = 0.20
87
+ LATENCY_MODEL_MAX_VALIDATION_MAPE = 0.20
88
+ LATENCY_MODEL_MAX_CONFIGURATION_FOLD_RELATIVE_MAE = 0.30
89
+ LATENCY_MODEL_MAX_CONFIGURATION_FOLD_MAPE = 0.30
90
+ LATENCY_MODEL_MAX_VALIDATION_CASE_RELATIVE_ERROR = 0.30
91
+ # Compatibility alias retained for callers that used the original max-scale-only
92
+ # threshold name.
93
+ LATENCY_MODEL_MIN_VALIDATION_POINTS = 4
94
+
95
+
96
+ def _hardware_model_name(gpu_mode: object) -> str:
97
+ if pd.isna(gpu_mode):
98
+ raise ValueError("gpu_mode contains a missing value")
99
+ normalized = str(gpu_mode).strip().lower()
100
+ if normalized in GPU_MODE_ON_VALUES:
101
+ return "gpu"
102
+ if normalized in GPU_MODE_OFF_VALUES:
103
+ return "cpu"
104
+ raise ValueError(f"unsupported gpu_mode value: {gpu_mode!r}")
105
+
106
+
107
+ def _format_input_scale_knot(input_scale: float) -> str:
108
+ return (
109
+ format(float(input_scale), ".12g")
110
+ .replace("-", "neg_")
111
+ .replace(".", "p")
112
+ )
113
+
114
+
115
+ def _model_feature_names(
116
+ hardware_model: str,
117
+ input_scale_spline_knots: list[float] | None = None,
118
+ ) -> list[str]:
119
+ if hardware_model == "cpu":
120
+ return list(LATENCY_MODEL_FEATURES[hardware_model])
121
+ if hardware_model == "gpu":
122
+ knots = input_scale_spline_knots or []
123
+ return [
124
+ "intercept",
125
+ "log_input_scale",
126
+ *[
127
+ f"log_input_scale_hinge_at_{_format_input_scale_knot(knot)}"
128
+ for knot in knots
129
+ ],
130
+ *LATENCY_MODEL_FEATURES[hardware_model][2:],
131
+ ]
132
+ raise ValueError(f"unknown latency hardware model: {hardware_model}")
133
+
134
+
135
+ def _gpu_input_scale_spline_knots(rows: list) -> list[float]:
136
+ """Use every interior observed scale as a shared log-scale spline knot."""
137
+ input_scales = sorted({float(row.input_scale) for row in rows})
138
+ return input_scales[1:-1]
139
+
140
+
141
+ def _model_features(
142
+ row,
143
+ hardware_model: str,
144
+ input_scale_spline_knots: list[float] | None = None,
145
+ ) -> list[float]:
146
+ input_scale = float(row.input_scale)
147
+ cpu_cores = float(row.cpu_cores)
148
+ mem_cap_gb = float(row.mem_cap_gb)
149
+ log_input_scale = math.log(input_scale)
150
+ log_mem_cap_gb = math.log(mem_cap_gb)
151
+
152
+ if hardware_model == "cpu":
153
+ log_cpu_cores = math.log(cpu_cores)
154
+ return [
155
+ 1.0,
156
+ log_input_scale,
157
+ log_input_scale**2,
158
+ log_cpu_cores,
159
+ log_cpu_cores**2,
160
+ log_mem_cap_gb,
161
+ log_input_scale * log_cpu_cores,
162
+ log_input_scale * log_mem_cap_gb,
163
+ log_cpu_cores * log_mem_cap_gb,
164
+ ]
165
+ if hardware_model == "gpu":
166
+ inverse_cpu_cores = 1.0 / cpu_cores
167
+ inverse_cpu_cores_squared = inverse_cpu_cores**2
168
+ spline_knots = input_scale_spline_knots or []
169
+ return [
170
+ 1.0,
171
+ log_input_scale,
172
+ *[
173
+ max(0.0, log_input_scale - math.log(float(knot)))
174
+ for knot in spline_knots
175
+ ],
176
+ inverse_cpu_cores,
177
+ inverse_cpu_cores_squared,
178
+ log_mem_cap_gb,
179
+ log_input_scale * inverse_cpu_cores,
180
+ log_input_scale * inverse_cpu_cores_squared,
181
+ ]
182
+ raise ValueError(f"unknown latency hardware model: {hardware_model}")
183
+
184
+
185
+ def _fit_rank_revealing_linear_model(
186
+ feature_matrix: np.ndarray,
187
+ target: np.ndarray,
188
+ ) -> dict:
189
+ """Solve a standardized linear model after removing dependent columns."""
190
+ if feature_matrix.ndim != 2 or target.ndim != 1:
191
+ raise ValueError("model matrix and target have invalid dimensions")
192
+ if feature_matrix.shape[0] != target.shape[0]:
193
+ raise ValueError("model matrix and target row counts differ")
194
+ if feature_matrix.shape[1] < 2:
195
+ raise ValueError("model matrix needs an intercept and a predictor")
196
+ if not np.isfinite(feature_matrix).all() or not np.isfinite(target).all():
197
+ raise ValueError("model inputs contain non-finite values")
198
+
199
+ means = np.zeros(feature_matrix.shape[1], dtype=float)
200
+ scales = np.ones(feature_matrix.shape[1], dtype=float)
201
+ standardized = np.zeros_like(feature_matrix)
202
+ standardized[:, 0] = 1.0
203
+ for feature_idx in range(1, feature_matrix.shape[1]):
204
+ column = feature_matrix[:, feature_idx]
205
+ means[feature_idx] = float(column.mean())
206
+ scales[feature_idx] = float(column.std())
207
+ if scales[feature_idx] > 1e-12:
208
+ standardized[:, feature_idx] = (
209
+ column - means[feature_idx]
210
+ ) / scales[feature_idx]
211
+
212
+ selected_indices: list[int] = []
213
+ for feature_idx in range(standardized.shape[1]):
214
+ candidate_indices = selected_indices + [feature_idx]
215
+ candidate = standardized[:, candidate_indices]
216
+ if int(np.linalg.matrix_rank(candidate)) > len(selected_indices):
217
+ selected_indices.append(feature_idx)
218
+
219
+ if len(selected_indices) < 2:
220
+ raise ValueError("model matrix has no usable varying predictor")
221
+
222
+ selected_matrix = standardized[:, selected_indices]
223
+ standardized_coefficients, _, rank, singular_values = np.linalg.lstsq(
224
+ selected_matrix,
225
+ target,
226
+ rcond=None,
227
+ )
228
+ if int(rank) != len(selected_indices):
229
+ raise ValueError(
230
+ f"rank-deficient model matrix: rank={int(rank)}, "
231
+ f"features={len(selected_indices)}"
232
+ )
233
+
234
+ coefficients = np.zeros(feature_matrix.shape[1], dtype=float)
235
+ for position, feature_idx in enumerate(selected_indices):
236
+ if feature_idx == 0:
237
+ continue
238
+ coefficients[feature_idx] = (
239
+ standardized_coefficients[position] / scales[feature_idx]
240
+ )
241
+ intercept_position = selected_indices.index(0)
242
+ coefficients[0] = standardized_coefficients[intercept_position] - sum(
243
+ coefficients[feature_idx] * means[feature_idx]
244
+ for feature_idx in selected_indices
245
+ if feature_idx != 0
246
+ )
247
+
248
+ smallest_singular = float(singular_values[-1])
249
+ condition_number = (
250
+ None
251
+ if smallest_singular <= 0.0
252
+ else float(singular_values[0] / smallest_singular)
253
+ )
254
+ return {
255
+ "coefficients": [float(value) for value in coefficients],
256
+ "selected_indices": selected_indices,
257
+ "rank": int(rank),
258
+ "condition_number": condition_number,
259
+ }
260
+
261
+
262
+ def _gpu_upper_tail_features(row) -> list[float]:
263
+ """Features for a stable affine GPU latency tail above the fitted range."""
264
+ input_scale = float(row.input_scale)
265
+ inverse_cpu_cores = 1.0 / float(row.cpu_cores)
266
+ inverse_cpu_cores_squared = inverse_cpu_cores**2
267
+ return [
268
+ 1.0,
269
+ input_scale,
270
+ inverse_cpu_cores,
271
+ inverse_cpu_cores_squared,
272
+ math.log(float(row.mem_cap_gb)),
273
+ input_scale * inverse_cpu_cores,
274
+ input_scale * inverse_cpu_cores_squared,
275
+ ]
276
+
277
+
278
+ def _fit_gpu_upper_tail_model(rows: list) -> dict:
279
+ feature_matrix = np.asarray(
280
+ [_gpu_upper_tail_features(row) for row in rows],
281
+ dtype=float,
282
+ )
283
+ target = np.asarray([float(row.latency_s) for row in rows], dtype=float)
284
+ solution = _fit_rank_revealing_linear_model(feature_matrix, target)
285
+ selected_feature_names = [
286
+ LATENCY_MODEL_GPU_UPPER_TAIL_FEATURES[feature_idx]
287
+ for feature_idx in solution["selected_indices"]
288
+ ]
289
+ scale_slope_features = {
290
+ "input_scale",
291
+ "input_scale_x_inverse_cpu_cores",
292
+ "input_scale_x_inverse_cpu_cores_squared",
293
+ }
294
+ if not scale_slope_features.intersection(selected_feature_names):
295
+ raise ValueError("GPU upper-tail model has no input-scale slope")
296
+
297
+ coefficients = solution["coefficients"]
298
+ training_configurations = sorted({
299
+ (float(row.cpu_cores), float(row.mem_cap_gb)) for row in rows
300
+ })
301
+ fitted_slopes = []
302
+ for cpu_cores, mem_cap_gb in training_configurations:
303
+ at_zero = SimpleNamespace(
304
+ input_scale=0.0,
305
+ cpu_cores=cpu_cores,
306
+ mem_cap_gb=mem_cap_gb,
307
+ )
308
+ at_one = SimpleNamespace(
309
+ input_scale=1.0,
310
+ cpu_cores=cpu_cores,
311
+ mem_cap_gb=mem_cap_gb,
312
+ )
313
+ fitted_slopes.append(float(np.dot(
314
+ coefficients,
315
+ np.asarray(_gpu_upper_tail_features(at_one))
316
+ - np.asarray(_gpu_upper_tail_features(at_zero)),
317
+ )))
318
+
319
+ return {
320
+ "feature_names": list(LATENCY_MODEL_GPU_UPPER_TAIL_FEATURES),
321
+ "selected_indices": solution["selected_indices"],
322
+ "selected_feature_names": selected_feature_names,
323
+ "dropped_feature_names": [
324
+ feature_name
325
+ for feature_name in LATENCY_MODEL_GPU_UPPER_TAIL_FEATURES
326
+ if feature_name not in selected_feature_names
327
+ ],
328
+ "coefficients": coefficients,
329
+ "rank": solution["rank"],
330
+ "condition_number": solution["condition_number"],
331
+ "minimum_fitted_slope_s_per_scale": min(fitted_slopes),
332
+ }
333
+
334
+
335
+ def _fit_log_latency_model(
336
+ rows: list,
337
+ hardware_model: str,
338
+ *,
339
+ calibrate_gpu_upper_tail: bool = True,
340
+ ) -> dict:
341
+ """Fit log(latency) with rank-revealing least squares.
342
+
343
+ Regressors are standardized before solving. Constant or linearly dependent
344
+ columns are removed so CPU-only, GPU-only, and reduced resource matrices do
345
+ not fail merely because a feature is constant.
346
+ """
347
+ if len(rows) < 3:
348
+ raise ValueError(f"need at least 3 case rows, got {len(rows)}")
349
+
350
+ input_scale_spline_knots = (
351
+ _gpu_input_scale_spline_knots(rows)
352
+ if hardware_model == "gpu"
353
+ else []
354
+ )
355
+ feature_names = _model_feature_names(
356
+ hardware_model,
357
+ input_scale_spline_knots,
358
+ )
359
+ feature_matrix = np.asarray(
360
+ [
361
+ _model_features(
362
+ row,
363
+ hardware_model,
364
+ input_scale_spline_knots,
365
+ )
366
+ for row in rows
367
+ ],
368
+ dtype=float,
369
+ )
370
+ target = np.log(np.asarray([float(row.latency_s) for row in rows], dtype=float))
371
+ solution = _fit_rank_revealing_linear_model(feature_matrix, target)
372
+ selected_indices = solution["selected_indices"]
373
+ model = {
374
+ "hardware_model": hardware_model,
375
+ "input_scale_spline_knots": input_scale_spline_knots,
376
+ "input_scale_min": min(float(row.input_scale) for row in rows),
377
+ "input_scale_max": max(float(row.input_scale) for row in rows),
378
+ "feature_names": feature_names,
379
+ "selected_indices": selected_indices,
380
+ "selected_feature_names": [
381
+ feature_names[feature_idx] for feature_idx in selected_indices
382
+ ],
383
+ "dropped_feature_names": [
384
+ feature_names[feature_idx]
385
+ for feature_idx in range(len(feature_names))
386
+ if feature_idx not in selected_indices
387
+ ],
388
+ "coefficients": solution["coefficients"],
389
+ "rank": solution["rank"],
390
+ "condition_number": solution["condition_number"],
391
+ "fit_case_rows": len(rows),
392
+ }
393
+
394
+ if hardware_model == "gpu" and calibrate_gpu_upper_tail:
395
+ input_scales = sorted({float(row.input_scale) for row in rows})
396
+ input_scale_span_ratio = input_scales[-1] / input_scales[0]
397
+ calibration: dict[str, Any] = {
398
+ "available": False,
399
+ "held_out_input_scale": None,
400
+ "mean_absolute_percentage_error": None,
401
+ "activation_threshold_mape": (
402
+ LATENCY_MODEL_GPU_UPPER_TAIL_ACTIVATION_MAPE
403
+ ),
404
+ }
405
+ if len(input_scales) >= 3:
406
+ calibration_scale = input_scales[-1]
407
+ calibration_rows = [
408
+ row for row in rows
409
+ if float(row.input_scale) < calibration_scale
410
+ ]
411
+ calibration_test_rows = [
412
+ row for row in rows
413
+ if float(row.input_scale) == calibration_scale
414
+ ]
415
+ try:
416
+ calibration_model = _fit_log_latency_model(
417
+ calibration_rows,
418
+ hardware_model,
419
+ calibrate_gpu_upper_tail=False,
420
+ )
421
+ calibration_predictions = np.asarray([
422
+ _predict_latency(row, calibration_model)
423
+ for row in calibration_test_rows
424
+ ])
425
+ calibration_actuals = np.asarray([
426
+ float(row.latency_s) for row in calibration_test_rows
427
+ ])
428
+ calibration_mape = float(np.mean(
429
+ np.abs(calibration_actuals - calibration_predictions)
430
+ / calibration_actuals
431
+ ))
432
+ calibration = {
433
+ "available": True,
434
+ "held_out_input_scale": calibration_scale,
435
+ "train_input_scale_max": max(
436
+ float(row.input_scale) for row in calibration_rows
437
+ ),
438
+ "mean_absolute_percentage_error": calibration_mape,
439
+ "activation_threshold_mape": (
440
+ LATENCY_MODEL_GPU_UPPER_TAIL_ACTIVATION_MAPE
441
+ ),
442
+ }
443
+ except ValueError as exc:
444
+ calibration["reason"] = str(exc)
445
+
446
+ try:
447
+ upper_tail_model = _fit_gpu_upper_tail_model(rows)
448
+ upper_tail_model["calibration"] = calibration
449
+ upper_tail_model["training_input_scale_span_ratio"] = (
450
+ input_scale_span_ratio
451
+ )
452
+ upper_tail_model["enabled"] = bool(
453
+ calibration["available"]
454
+ and calibration["mean_absolute_percentage_error"]
455
+ > LATENCY_MODEL_GPU_UPPER_TAIL_ACTIVATION_MAPE
456
+ and input_scale_span_ratio
457
+ >= LATENCY_MODEL_GPU_UPPER_TAIL_MIN_SCALE_SPAN_RATIO
458
+ and upper_tail_model["minimum_fitted_slope_s_per_scale"] > 0.0
459
+ )
460
+ model["gpu_upper_tail"] = upper_tail_model
461
+ except ValueError as exc:
462
+ model["gpu_upper_tail"] = {
463
+ "enabled": False,
464
+ "reason": str(exc),
465
+ "calibration": calibration,
466
+ }
467
+
468
+ return model
469
+
470
+
471
+ def _predict_primary_latency(row, model: dict) -> float:
472
+ """Evaluate the positive log-link model without tail extrapolation."""
473
+ linear_prediction = sum(
474
+ coefficient * feature
475
+ for coefficient, feature in zip(
476
+ model["coefficients"],
477
+ _model_features(
478
+ row,
479
+ model["hardware_model"],
480
+ model.get("input_scale_spline_knots", []),
481
+ ),
482
+ strict=True,
483
+ )
484
+ )
485
+ # The exponential link makes predictions positive. Clipping only protects
486
+ # artifact generation from floating-point overflow on extreme extrapolation.
487
+ bounded_prediction = min(max(linear_prediction, -700.0), 700.0)
488
+ return float(math.exp(bounded_prediction))
489
+
490
+
491
+ def _predict_latency(row, model: dict) -> float:
492
+ primary_prediction = _predict_primary_latency(row, model)
493
+ upper_tail_model = model.get("gpu_upper_tail", {})
494
+ input_scale_max = model.get("input_scale_max")
495
+ if not (
496
+ model.get("hardware_model") == "gpu"
497
+ and upper_tail_model.get("enabled")
498
+ and input_scale_max is not None
499
+ and float(row.input_scale) > float(input_scale_max)
500
+ ):
501
+ return primary_prediction
502
+
503
+ boundary_row = SimpleNamespace(
504
+ input_scale=float(input_scale_max),
505
+ cpu_cores=float(row.cpu_cores),
506
+ mem_cap_gb=float(row.mem_cap_gb),
507
+ )
508
+ boundary_prediction = _predict_primary_latency(boundary_row, model)
509
+ feature_delta = (
510
+ np.asarray(_gpu_upper_tail_features(row), dtype=float)
511
+ - np.asarray(_gpu_upper_tail_features(boundary_row), dtype=float)
512
+ )
513
+ tail_delta = float(np.dot(
514
+ np.asarray(upper_tail_model["coefficients"], dtype=float),
515
+ feature_delta,
516
+ ))
517
+ tail_prediction = boundary_prediction + tail_delta
518
+ if math.isfinite(tail_prediction) and tail_prediction > 0.0:
519
+ return tail_prediction
520
+ return primary_prediction
521
+
522
+
523
+ def _regression_metrics(
524
+ actuals: list[float],
525
+ predictions: list[float],
526
+ ) -> dict[str, float | int | None]:
527
+ prediction_count = len(predictions)
528
+ nonfinite_prediction_count = sum(
529
+ not math.isfinite(float(prediction)) for prediction in predictions
530
+ )
531
+ nonpositive_prediction_count = sum(
532
+ math.isfinite(float(prediction)) and float(prediction) <= 0.0
533
+ for prediction in predictions
534
+ )
535
+ valid_pairs = [
536
+ (float(actual), float(prediction))
537
+ for actual, prediction in zip(actuals, predictions, strict=True)
538
+ if math.isfinite(float(actual)) and math.isfinite(float(prediction))
539
+ ]
540
+ if not valid_pairs:
541
+ return {
542
+ "r2": None,
543
+ "mae": None,
544
+ "rmse": None,
545
+ "relative_mae": None,
546
+ "mean_absolute_percentage_error": None,
547
+ "maximum_absolute_percentage_error": None,
548
+ "smape": None,
549
+ "p95_absolute_error": None,
550
+ "mean_actual": None,
551
+ "prediction_count": prediction_count,
552
+ "nonfinite_prediction_count": nonfinite_prediction_count,
553
+ "nonpositive_prediction_count": nonpositive_prediction_count,
554
+ "min_prediction": None,
555
+ "max_prediction": None,
556
+ }
557
+
558
+ valid_actuals = [pair[0] for pair in valid_pairs]
559
+ valid_predictions = [pair[1] for pair in valid_pairs]
560
+ errors = [
561
+ actual - predicted
562
+ for actual, predicted in zip(valid_actuals, valid_predictions, strict=True)
563
+ ]
564
+ absolute_errors = [abs(error) for error in errors]
565
+ mae = sum(absolute_errors) / len(absolute_errors)
566
+ rmse = math.sqrt(sum(error * error for error in errors) / len(errors))
567
+ mean_actual = sum(valid_actuals) / len(valid_actuals)
568
+ ss_tot = sum((actual - mean_actual) ** 2 for actual in valid_actuals)
569
+ ss_res = sum(error * error for error in errors)
570
+ r2 = None if ss_tot <= 1e-24 else 1.0 - (ss_res / ss_tot)
571
+ relative_mae = None if mean_actual <= 0.0 else mae / mean_actual
572
+ absolute_percentage_errors = [
573
+ abs(actual - predicted) / abs(actual)
574
+ for actual, predicted in zip(valid_actuals, valid_predictions, strict=True)
575
+ if abs(actual) > 0.0
576
+ ]
577
+ mean_absolute_percentage_error = (
578
+ None
579
+ if not absolute_percentage_errors
580
+ else sum(absolute_percentage_errors) / len(absolute_percentage_errors)
581
+ )
582
+ maximum_absolute_percentage_error = (
583
+ None
584
+ if not absolute_percentage_errors
585
+ else max(absolute_percentage_errors)
586
+ )
587
+ smape_terms = [
588
+ 2.0 * abs(actual - predicted) / (abs(actual) + abs(predicted))
589
+ for actual, predicted in zip(valid_actuals, valid_predictions, strict=True)
590
+ if abs(actual) + abs(predicted) > 0.0
591
+ ]
592
+ smape = None if not smape_terms else sum(smape_terms) / len(smape_terms)
593
+ return {
594
+ "r2": r2,
595
+ "mae": mae,
596
+ "rmse": rmse,
597
+ "relative_mae": relative_mae,
598
+ "mean_absolute_percentage_error": mean_absolute_percentage_error,
599
+ "maximum_absolute_percentage_error": maximum_absolute_percentage_error,
600
+ "smape": smape,
601
+ "p95_absolute_error": float(np.percentile(absolute_errors, 95)),
602
+ "mean_actual": mean_actual,
603
+ "prediction_count": prediction_count,
604
+ "nonfinite_prediction_count": nonfinite_prediction_count,
605
+ "nonpositive_prediction_count": nonpositive_prediction_count,
606
+ "min_prediction": min(valid_predictions),
607
+ "max_prediction": max(valid_predictions),
608
+ }
609
+
610
+
611
+ def _latency_model_frame(df: pd.DataFrame) -> pd.DataFrame:
612
+ required = {"cpu_cores", "mem_cap_gb", "gpu_mode", "input_scale", "latency_s"}
613
+ missing = required - set(df.columns)
614
+ if missing:
615
+ raise ValueError(f"CSV missing required modeling columns: {sorted(missing)}")
616
+
617
+ model_df = df[list(required)].copy()
618
+ for col in ("cpu_cores", "mem_cap_gb", "input_scale", "latency_s"):
619
+ model_df[col] = pd.to_numeric(model_df[col], errors="coerce")
620
+ model_df = model_df[
621
+ model_df["cpu_cores"].notna()
622
+ & model_df["mem_cap_gb"].notna()
623
+ & model_df["input_scale"].notna()
624
+ & model_df["latency_s"].notna()
625
+ & (model_df["cpu_cores"] > 0)
626
+ & (model_df["mem_cap_gb"] > 0)
627
+ & (model_df["input_scale"] > 0)
628
+ & (model_df["latency_s"] > 0)
629
+ ].copy()
630
+ model_df["source_row"] = model_df.index
631
+ model_df["hardware_model"] = model_df["gpu_mode"].map(_hardware_model_name)
632
+ return model_df.sort_values(
633
+ ["hardware_model", "cpu_cores", "mem_cap_gb", "input_scale", "source_row"]
634
+ ).reset_index(drop=True)
635
+
636
+
637
+ def _aggregate_latency_model_points(model_df: pd.DataFrame) -> list:
638
+ """Collapse repeated windows before any fit or validation split."""
639
+ point_df = model_df.groupby(
640
+ ["hardware_model", "cpu_cores", "mem_cap_gb", "input_scale"],
641
+ as_index=False,
642
+ sort=True,
643
+ ).agg(
644
+ latency_s=("latency_s", "median"),
645
+ latency_mean_s=("latency_s", "mean"),
646
+ latency_std_s=("latency_s", lambda values: values.std(ddof=0)),
647
+ repeat_count=("latency_s", "size"),
648
+ )
649
+ point_df["latency_std_s"] = point_df["latency_std_s"].fillna(0.0)
650
+ return list(point_df.itertuples(index=False))
651
+
652
+
653
+ def _point_key(row) -> tuple[str, float, float, float]:
654
+ return (
655
+ str(row.hardware_model),
656
+ float(row.cpu_cores),
657
+ float(row.mem_cap_gb),
658
+ float(row.input_scale),
659
+ )
660
+
661
+
662
+ def _resource_configuration_validation(
663
+ rows: list,
664
+ hardware_model: str,
665
+ ) -> tuple[dict, dict[tuple[str, float, float, float], float]]:
666
+ """Leave one complete (CPU, memory) configuration out per fold."""
667
+ configurations = sorted({
668
+ (float(row.cpu_cores), float(row.mem_cap_gb)) for row in rows
669
+ })
670
+ if len(configurations) < 3:
671
+ return {
672
+ "available": False,
673
+ "reason": (
674
+ "need at least 3 resource configurations so each held-out fold "
675
+ "retains at least 2 training configurations"
676
+ ),
677
+ "folds": 0,
678
+ "completed_folds": 0,
679
+ "failed_folds": [],
680
+ "r2_quality_gate_applicable": True,
681
+ "train_test_group_overlap_count": 0,
682
+ "metrics": _regression_metrics([], []),
683
+ }, {}
684
+
685
+ predictions: dict[tuple[str, float, float, float], float] = {}
686
+ failed_folds = []
687
+ fold_details = []
688
+ train_test_group_overlap_count = 0
689
+ completed_folds = 0
690
+ for cpu_cores, mem_cap_gb in configurations:
691
+ test_rows = [
692
+ row
693
+ for row in rows
694
+ if (
695
+ float(row.cpu_cores) == cpu_cores
696
+ and float(row.mem_cap_gb) == mem_cap_gb
697
+ )
698
+ ]
699
+ train_rows = [
700
+ row
701
+ for row in rows
702
+ if not (
703
+ float(row.cpu_cores) == cpu_cores
704
+ and float(row.mem_cap_gb) == mem_cap_gb
705
+ )
706
+ ]
707
+ train_groups = {
708
+ (float(row.cpu_cores), float(row.mem_cap_gb)) for row in train_rows
709
+ }
710
+ test_groups = {
711
+ (float(row.cpu_cores), float(row.mem_cap_gb)) for row in test_rows
712
+ }
713
+ fold_overlap_count = len(train_groups & test_groups)
714
+ train_test_group_overlap_count += fold_overlap_count
715
+ fold_detail: dict[str, Any] = {
716
+ "held_out_cpu_cores": cpu_cores,
717
+ "held_out_mem_cap_gb": mem_cap_gb,
718
+ "train_case_rows": len(train_rows),
719
+ "test_case_rows": len(test_rows),
720
+ "train_test_group_overlap_count": fold_overlap_count,
721
+ }
722
+ try:
723
+ fold_model = _fit_log_latency_model(train_rows, hardware_model)
724
+ if not (
725
+ LATENCY_MODEL_RESOURCE_FEATURES[hardware_model]
726
+ & set(fold_model["selected_feature_names"])
727
+ ):
728
+ raise ValueError(
729
+ "held-out fold has no identifiable CPU or memory predictor"
730
+ )
731
+ except ValueError as exc:
732
+ fold_detail["status"] = "failed"
733
+ fold_detail["reason"] = str(exc)
734
+ fold_details.append(fold_detail)
735
+ failed_folds.append({
736
+ "cpu_cores": cpu_cores,
737
+ "mem_cap_gb": mem_cap_gb,
738
+ "reason": str(exc),
739
+ })
740
+ continue
741
+
742
+ fold_predictions = [
743
+ _predict_latency(row, fold_model) for row in test_rows
744
+ ]
745
+ for row, prediction in zip(test_rows, fold_predictions, strict=True):
746
+ predictions[_point_key(row)] = prediction
747
+ fold_detail["status"] = "ok"
748
+ fold_detail["metrics"] = _regression_metrics(
749
+ [float(row.latency_s) for row in test_rows],
750
+ fold_predictions,
751
+ )
752
+ fold_details.append(fold_detail)
753
+ completed_folds += 1
754
+
755
+ predicted_rows = [row for row in rows if _point_key(row) in predictions]
756
+ actuals = [float(row.latency_s) for row in predicted_rows]
757
+ predicted = [predictions[_point_key(row)] for row in predicted_rows]
758
+ case_relative_errors = [
759
+ abs(actual - prediction) / actual
760
+ for actual, prediction in zip(actuals, predicted, strict=True)
761
+ ]
762
+ worst_case_idx = (
763
+ None
764
+ if not predicted_rows
765
+ else max(
766
+ range(len(predicted_rows)),
767
+ key=lambda idx: case_relative_errors[idx],
768
+ )
769
+ )
770
+ worst_case = (
771
+ None if worst_case_idx is None else predicted_rows[worst_case_idx]
772
+ )
773
+ completed_fold_details = [
774
+ fold_detail
775
+ for fold_detail in fold_details
776
+ if fold_detail.get("status") == "ok"
777
+ ]
778
+ worst_relative_mae_fold = (
779
+ None
780
+ if not completed_fold_details
781
+ else max(
782
+ completed_fold_details,
783
+ key=lambda fold_detail: (
784
+ math.inf
785
+ if fold_detail["metrics"].get("relative_mae") is None
786
+ else float(fold_detail["metrics"]["relative_mae"])
787
+ ),
788
+ )
789
+ )
790
+ return {
791
+ "available": not failed_folds and len(predicted_rows) == len(rows),
792
+ "method": "leave-one-(cpu_cores,mem_cap_gb)-configuration-out",
793
+ "r2_quality_gate_applicable": True,
794
+ "group_columns": ["cpu_cores", "mem_cap_gb"],
795
+ "all_input_scales_move_with_held_out_configuration": True,
796
+ "folds": len(configurations),
797
+ "completed_folds": completed_folds,
798
+ "failed_folds": failed_folds,
799
+ "fold_details": fold_details,
800
+ "train_test_group_overlap_count": train_test_group_overlap_count,
801
+ "test_case_rows": len(predicted_rows),
802
+ "worst_fold_relative_mae": (
803
+ None
804
+ if worst_relative_mae_fold is None
805
+ else worst_relative_mae_fold["metrics"]["relative_mae"]
806
+ ),
807
+ "worst_fold_configuration": (
808
+ None
809
+ if worst_relative_mae_fold is None
810
+ else {
811
+ "cpu_cores": worst_relative_mae_fold["held_out_cpu_cores"],
812
+ "mem_cap_gb": worst_relative_mae_fold["held_out_mem_cap_gb"],
813
+ }
814
+ ),
815
+ "worst_case_relative_error": (
816
+ None
817
+ if worst_case_idx is None
818
+ else case_relative_errors[worst_case_idx]
819
+ ),
820
+ "worst_case_configuration": (
821
+ None
822
+ if worst_case is None
823
+ else {
824
+ "cpu_cores": float(worst_case.cpu_cores),
825
+ "mem_cap_gb": float(worst_case.mem_cap_gb),
826
+ "input_scale": float(worst_case.input_scale),
827
+ }
828
+ ),
829
+ "metrics": _regression_metrics(actuals, predicted),
830
+ }, predictions
831
+
832
+
833
+ def _input_scale_validation(
834
+ rows: list,
835
+ hardware_model: str,
836
+ ) -> tuple[dict, dict[tuple[str, float, float, float], float]]:
837
+ """Train on smaller scales and hold out the largest scale for extrapolation."""
838
+ input_scales = sorted({float(row.input_scale) for row in rows})
839
+ if len(input_scales) < 3:
840
+ return {
841
+ "available": False,
842
+ "reason": (
843
+ "need at least 3 input scales so the maximum can be held out "
844
+ "while at least 2 distinct scales remain for training"
845
+ ),
846
+ "held_out_input_scale": None,
847
+ "group_columns": ["input_scale"],
848
+ "r2_quality_gate_applicable": False,
849
+ "r2_quality_gate_note": (
850
+ "A single held-out scale tests level extrapolation; R-squared "
851
+ "within that scale only measures resource-configuration "
852
+ "variation and is not used as an extrapolation gate."
853
+ ),
854
+ "train_test_group_overlap_count": 0,
855
+ "metrics": _regression_metrics([], []),
856
+ }, {}
857
+
858
+ held_out_scale = input_scales[-1]
859
+ train_rows = [row for row in rows if float(row.input_scale) < held_out_scale]
860
+ test_rows = [row for row in rows if float(row.input_scale) == held_out_scale]
861
+ train_scale_groups = {float(row.input_scale) for row in train_rows}
862
+ test_scale_groups = {float(row.input_scale) for row in test_rows}
863
+ train_test_group_overlap_count = len(train_scale_groups & test_scale_groups)
864
+ try:
865
+ scale_model = _fit_log_latency_model(train_rows, hardware_model)
866
+ if "log_input_scale" not in scale_model["selected_feature_names"]:
867
+ raise ValueError(
868
+ "maximum-scale training fold has no identifiable input-scale predictor"
869
+ )
870
+ except ValueError as exc:
871
+ return {
872
+ "available": False,
873
+ "reason": str(exc),
874
+ "held_out_input_scale": held_out_scale,
875
+ "group_columns": ["input_scale"],
876
+ "r2_quality_gate_applicable": False,
877
+ "r2_quality_gate_note": (
878
+ "A single held-out scale tests level extrapolation; R-squared "
879
+ "within that scale only measures resource-configuration "
880
+ "variation and is not used as an extrapolation gate."
881
+ ),
882
+ "train_input_scale_max": max(
883
+ (float(row.input_scale) for row in train_rows),
884
+ default=None,
885
+ ),
886
+ "train_test_group_overlap_count": train_test_group_overlap_count,
887
+ "metrics": _regression_metrics([], []),
888
+ }, {}
889
+
890
+ predictions = {
891
+ _point_key(row): _predict_latency(row, scale_model) for row in test_rows
892
+ }
893
+ actuals = [float(row.latency_s) for row in test_rows]
894
+ predicted = [predictions[_point_key(row)] for row in test_rows]
895
+ case_relative_errors = [
896
+ abs(actual - prediction) / actual
897
+ for actual, prediction in zip(actuals, predicted, strict=True)
898
+ ]
899
+ worst_case_idx = max(
900
+ range(len(test_rows)),
901
+ key=lambda idx: case_relative_errors[idx],
902
+ )
903
+ worst_case = test_rows[worst_case_idx]
904
+ return {
905
+ "available": True,
906
+ "method": "forward holdout of maximum input_scale",
907
+ "group_columns": ["input_scale"],
908
+ "r2_quality_gate_applicable": False,
909
+ "r2_quality_gate_note": (
910
+ "A single held-out scale tests level extrapolation; R-squared "
911
+ "within that scale only measures resource-configuration variation "
912
+ "and is reported for context, not used as an extrapolation gate."
913
+ ),
914
+ "held_out_input_scale": held_out_scale,
915
+ "train_input_scale_max": max(float(row.input_scale) for row in train_rows),
916
+ "test_input_scale_min": min(float(row.input_scale) for row in test_rows),
917
+ "strict_extrapolation": (
918
+ max(float(row.input_scale) for row in train_rows)
919
+ < min(float(row.input_scale) for row in test_rows)
920
+ ),
921
+ "train_test_group_overlap_count": train_test_group_overlap_count,
922
+ "train_case_rows": len(train_rows),
923
+ "test_case_rows": len(test_rows),
924
+ "worst_case_relative_error": case_relative_errors[worst_case_idx],
925
+ "worst_case_configuration": {
926
+ "cpu_cores": float(worst_case.cpu_cores),
927
+ "mem_cap_gb": float(worst_case.mem_cap_gb),
928
+ "input_scale": float(worst_case.input_scale),
929
+ },
930
+ "metrics": _regression_metrics(actuals, predicted),
931
+ }, predictions
932
+
933
+
934
+ def _validation_quality_failures(validation_name: str, validation: dict) -> list[str]:
935
+ if not validation.get("available"):
936
+ return [
937
+ f"{validation_name} unavailable: "
938
+ f"{validation.get('reason', 'incomplete validation folds')}"
939
+ ]
940
+
941
+ metrics = validation["metrics"]
942
+ failures = []
943
+ if int(metrics.get("prediction_count") or 0) < LATENCY_MODEL_MIN_VALIDATION_POINTS:
944
+ failures.append(
945
+ f"{validation_name} has fewer than "
946
+ f"{LATENCY_MODEL_MIN_VALIDATION_POINTS} predictions"
947
+ )
948
+ if int(validation.get("train_test_group_overlap_count") or 0) > 0:
949
+ failures.append(f"{validation_name} has train/test group leakage")
950
+ failed_quality_folds = []
951
+ for fold_detail in validation.get("fold_details", []):
952
+ if fold_detail.get("status") != "ok":
953
+ continue
954
+ fold_metrics = fold_detail["metrics"]
955
+ fold_relative_mae = fold_metrics.get("relative_mae")
956
+ fold_mape = fold_metrics.get("mean_absolute_percentage_error")
957
+ if (
958
+ fold_relative_mae is None
959
+ or not math.isfinite(float(fold_relative_mae))
960
+ or float(fold_relative_mae)
961
+ > LATENCY_MODEL_MAX_CONFIGURATION_FOLD_RELATIVE_MAE
962
+ or fold_mape is None
963
+ or not math.isfinite(float(fold_mape))
964
+ or float(fold_mape) > LATENCY_MODEL_MAX_CONFIGURATION_FOLD_MAPE
965
+ or int(fold_metrics.get("nonfinite_prediction_count") or 0) > 0
966
+ or int(fold_metrics.get("nonpositive_prediction_count") or 0) > 0
967
+ ):
968
+ failed_quality_folds.append(fold_detail)
969
+ if failed_quality_folds:
970
+ worst_fold = max(
971
+ failed_quality_folds,
972
+ key=lambda fold_detail: max(
973
+ math.inf
974
+ if (
975
+ fold_detail["metrics"].get("relative_mae") is None
976
+ or not math.isfinite(
977
+ float(fold_detail["metrics"]["relative_mae"])
978
+ )
979
+ )
980
+ else (
981
+ float(fold_detail["metrics"]["relative_mae"])
982
+ / LATENCY_MODEL_MAX_CONFIGURATION_FOLD_RELATIVE_MAE
983
+ ),
984
+ math.inf
985
+ if (
986
+ fold_detail["metrics"].get(
987
+ "mean_absolute_percentage_error"
988
+ )
989
+ is None
990
+ or not math.isfinite(
991
+ float(
992
+ fold_detail["metrics"][
993
+ "mean_absolute_percentage_error"
994
+ ]
995
+ )
996
+ )
997
+ )
998
+ else (
999
+ float(
1000
+ fold_detail["metrics"][
1001
+ "mean_absolute_percentage_error"
1002
+ ]
1003
+ )
1004
+ / LATENCY_MODEL_MAX_CONFIGURATION_FOLD_MAPE
1005
+ ),
1006
+ ),
1007
+ )
1008
+ failures.append(
1009
+ f"{validation_name} has {len(failed_quality_folds)} held-out "
1010
+ "configuration fold(s) above the relative-MAE/MAPE/validity "
1011
+ "threshold; "
1012
+ f"worst=(cpu_cores={worst_fold['held_out_cpu_cores']},"
1013
+ f"mem_cap_gb={worst_fold['held_out_mem_cap_gb']}), "
1014
+ f"relative_mae={worst_fold['metrics'].get('relative_mae')!r}, "
1015
+ "mean_absolute_percentage_error="
1016
+ f"{worst_fold['metrics'].get('mean_absolute_percentage_error')!r}"
1017
+ )
1018
+ worst_case_relative_error = validation.get("worst_case_relative_error")
1019
+ if (
1020
+ worst_case_relative_error is not None
1021
+ and (
1022
+ not math.isfinite(float(worst_case_relative_error))
1023
+ or float(worst_case_relative_error)
1024
+ > LATENCY_MODEL_MAX_VALIDATION_CASE_RELATIVE_ERROR
1025
+ )
1026
+ ):
1027
+ failures.append(
1028
+ f"{validation_name} worst case relative_error="
1029
+ f"{worst_case_relative_error!r} exceeds "
1030
+ f"{LATENCY_MODEL_MAX_VALIDATION_CASE_RELATIVE_ERROR}; "
1031
+ f"configuration={validation.get('worst_case_configuration')!r}"
1032
+ )
1033
+ if validation.get("r2_quality_gate_applicable", True):
1034
+ r2 = metrics.get("r2")
1035
+ if (
1036
+ r2 is None
1037
+ or not math.isfinite(float(r2))
1038
+ or float(r2) < LATENCY_MODEL_MIN_VALIDATION_R2
1039
+ ):
1040
+ failures.append(
1041
+ f"{validation_name} r2={r2!r} is below "
1042
+ f"{LATENCY_MODEL_MIN_VALIDATION_R2}"
1043
+ )
1044
+ relative_mae = metrics.get("relative_mae")
1045
+ if (
1046
+ relative_mae is None
1047
+ or not math.isfinite(float(relative_mae))
1048
+ or float(relative_mae) > LATENCY_MODEL_MAX_VALIDATION_RELATIVE_MAE
1049
+ ):
1050
+ failures.append(
1051
+ f"{validation_name} relative_mae={relative_mae!r} exceeds "
1052
+ f"{LATENCY_MODEL_MAX_VALIDATION_RELATIVE_MAE}"
1053
+ )
1054
+ mean_absolute_percentage_error = metrics.get(
1055
+ "mean_absolute_percentage_error"
1056
+ )
1057
+ if (
1058
+ mean_absolute_percentage_error is None
1059
+ or not math.isfinite(float(mean_absolute_percentage_error))
1060
+ or float(mean_absolute_percentage_error) > LATENCY_MODEL_MAX_VALIDATION_MAPE
1061
+ ):
1062
+ failures.append(
1063
+ f"{validation_name} mean_absolute_percentage_error="
1064
+ f"{mean_absolute_percentage_error!r} exceeds "
1065
+ f"{LATENCY_MODEL_MAX_VALIDATION_MAPE}"
1066
+ )
1067
+ if int(metrics.get("nonfinite_prediction_count") or 0) > 0:
1068
+ failures.append(f"{validation_name} contains non-finite predictions")
1069
+ if int(metrics.get("nonpositive_prediction_count") or 0) > 0:
1070
+ failures.append(f"{validation_name} contains non-positive predictions")
1071
+ return failures
1072
+
1073
+
1074
+ def _validation_is_evaluable(validation: dict) -> bool:
1075
+ if not validation.get("available"):
1076
+ return False
1077
+ metrics = validation.get("metrics", {})
1078
+ metric_names = ["relative_mae", "mean_absolute_percentage_error"]
1079
+ if validation.get("r2_quality_gate_applicable", True):
1080
+ metric_names.append("r2")
1081
+ return bool(
1082
+ int(metrics.get("prediction_count") or 0)
1083
+ >= LATENCY_MODEL_MIN_VALIDATION_POINTS
1084
+ and all(
1085
+ metrics.get(metric_name) is not None
1086
+ and math.isfinite(float(metrics[metric_name]))
1087
+ for metric_name in metric_names
1088
+ )
1089
+ )
1090
+
1091
+
1092
+ def _training_range(rows: list) -> dict[str, dict[str, float]]:
1093
+ return {
1094
+ "cpu_cores": {
1095
+ "min": min(float(row.cpu_cores) for row in rows),
1096
+ "max": max(float(row.cpu_cores) for row in rows),
1097
+ },
1098
+ "mem_cap_gb": {
1099
+ "min": min(float(row.mem_cap_gb) for row in rows),
1100
+ "max": max(float(row.mem_cap_gb) for row in rows),
1101
+ },
1102
+ "input_scale": {
1103
+ "min": min(float(row.input_scale) for row in rows),
1104
+ "max": max(float(row.input_scale) for row in rows),
1105
+ },
1106
+ }