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.
- acprof/__init__.py +3 -0
- acprof/__main__.py +5 -0
- acprof/_bundle/.dockerignore +20 -0
- acprof/_bundle/LICENSE +202 -0
- acprof/_bundle/NOTICE +43 -0
- acprof/_bundle/acprof/__init__.py +3 -0
- acprof/_bundle/acprof/__main__.py +5 -0
- acprof/_bundle/acprof/analysis/__init__.py +1 -0
- acprof/_bundle/acprof/analysis/audit.py +276 -0
- acprof/_bundle/acprof/analysis/comparison.py +364 -0
- acprof/_bundle/acprof/analysis/compatibility.py +223 -0
- acprof/_bundle/acprof/analysis/conditions.py +185 -0
- acprof/_bundle/acprof/analysis/independent_comparison.py +191 -0
- acprof/_bundle/acprof/analysis/latency_model.py +1106 -0
- acprof/_bundle/acprof/analysis/latency_report.py +577 -0
- acprof/_bundle/acprof/analysis/model.py +276 -0
- acprof/_bundle/acprof/analysis/precision.py +51 -0
- acprof/_bundle/acprof/analysis/uncertainty.py +144 -0
- acprof/_bundle/acprof/application/__init__.py +1 -0
- acprof/_bundle/acprof/application/download.py +14 -0
- acprof/_bundle/acprof/application/errors.py +5 -0
- acprof/_bundle/acprof/application/notifications.py +302 -0
- acprof/_bundle/acprof/application/preparation.py +333 -0
- acprof/_bundle/acprof/application/resources.py +66 -0
- acprof/_bundle/acprof/application/run.py +462 -0
- acprof/_bundle/acprof/application/terminal_log.py +136 -0
- acprof/_bundle/acprof/artifact_layout.py +261 -0
- acprof/_bundle/acprof/artifacts.py +161 -0
- acprof/_bundle/acprof/capabilities.py +404 -0
- acprof/_bundle/acprof/cli/__init__.py +1 -0
- acprof/_bundle/acprof/cli/audit.py +74 -0
- acprof/_bundle/acprof/cli/auto.py +41 -0
- acprof/_bundle/acprof/cli/backfill_compute.py +498 -0
- acprof/_bundle/acprof/cli/compare.py +34 -0
- acprof/_bundle/acprof/cli/coverage.py +70 -0
- acprof/_bundle/acprof/cli/doctor.py +47 -0
- acprof/_bundle/acprof/cli/inspect.py +101 -0
- acprof/_bundle/acprof/cli/load.py +190 -0
- acprof/_bundle/acprof/cli/main.py +64 -0
- acprof/_bundle/acprof/cli/model_store.py +22 -0
- acprof/_bundle/acprof/cli/plot.py +211 -0
- acprof/_bundle/acprof/cli/posthoc.py +113 -0
- acprof/_bundle/acprof/cli/probe.py +186 -0
- acprof/_bundle/acprof/cli/report.py +35 -0
- acprof/_bundle/acprof/cli/results.py +37 -0
- acprof/_bundle/acprof/cli/run.py +54 -0
- acprof/_bundle/acprof/cli/stats.py +94 -0
- acprof/_bundle/acprof/cli/tui.py +65 -0
- acprof/_bundle/acprof/config.py +177 -0
- acprof/_bundle/acprof/container/__init__.py +1 -0
- acprof/_bundle/acprof/container/compat/__init__.py +1 -0
- acprof/_bundle/acprof/container/compat/transformers_dynamic.py +54 -0
- acprof/_bundle/acprof/container/compat/transformers_model_types.json +1091 -0
- acprof/_bundle/acprof/container/compute_profile_runner.py +392 -0
- acprof/_bundle/acprof/container/download_model.py +165 -0
- acprof/_bundle/acprof/container/execution.py +73 -0
- acprof/_bundle/acprof/container/handlers/__init__.py +298 -0
- acprof/_bundle/acprof/container/handlers/audio.py +743 -0
- acprof/_bundle/acprof/container/handlers/custom_pipeline.py +74 -0
- acprof/_bundle/acprof/container/handlers/cv.py +321 -0
- acprof/_bundle/acprof/container/handlers/diffusion.py +728 -0
- acprof/_bundle/acprof/container/handlers/moss.py +64 -0
- acprof/_bundle/acprof/container/handlers/multimodal.py +609 -0
- acprof/_bundle/acprof/container/handlers/nlp.py +747 -0
- acprof/_bundle/acprof/container/handlers/onnx_tasks.py +231 -0
- acprof/_bundle/acprof/container/handlers/onnxruntime.py +90 -0
- acprof/_bundle/acprof/container/handlers/structured.py +185 -0
- acprof/_bundle/acprof/container/handlers/timeseries.py +178 -0
- acprof/_bundle/acprof/container/load_policy.py +81 -0
- acprof/_bundle/acprof/container/loading_quality.py +48 -0
- acprof/_bundle/acprof/container/local_pipeline.py +31 -0
- acprof/_bundle/acprof/container/model_files.py +280 -0
- acprof/_bundle/acprof/container/model_probe.py +80 -0
- acprof/_bundle/acprof/container/onnx_session.py +150 -0
- acprof/_bundle/acprof/container/runtime_manifest.py +150 -0
- acprof/_bundle/acprof/container/runtime_validate.py +156 -0
- acprof/_bundle/acprof/container/server.py +209 -0
- acprof/_bundle/acprof/container/torch_execution.py +55 -0
- acprof/_bundle/acprof/container/validation.py +172 -0
- acprof/_bundle/acprof/cpu_affinity.py +35 -0
- acprof/_bundle/acprof/dependency_locks.py +129 -0
- acprof/_bundle/acprof/experiment.py +356 -0
- acprof/_bundle/acprof/extensions/__init__.py +294 -0
- acprof/_bundle/acprof/extensions/builtin/manifest.json +3591 -0
- acprof/_bundle/acprof/extensions/onnxruntime/manifest.json +191 -0
- acprof/_bundle/acprof/extensions/schema.py +238 -0
- acprof/_bundle/acprof/extensions/transformers/4.57.6.json +1639 -0
- acprof/_bundle/acprof/extensions/transformers/5.10.4.json +1812 -0
- acprof/_bundle/acprof/failures.py +115 -0
- acprof/_bundle/acprof/hardware_conditions.py +18 -0
- acprof/_bundle/acprof/hf_download.py +143 -0
- acprof/_bundle/acprof/hf_endpoints.py +62 -0
- acprof/_bundle/acprof/hf_transport.py +238 -0
- acprof/_bundle/acprof/host/__init__.py +1 -0
- acprof/_bundle/acprof/host/automation.py +161 -0
- acprof/_bundle/acprof/host/client.py +520 -0
- acprof/_bundle/acprof/host/collection_history.py +77 -0
- acprof/_bundle/acprof/host/collection_workflow.py +285 -0
- acprof/_bundle/acprof/host/command.py +119 -0
- acprof/_bundle/acprof/host/container_lifecycle.py +225 -0
- acprof/_bundle/acprof/host/container_state.py +128 -0
- acprof/_bundle/acprof/host/coverage_state.py +259 -0
- acprof/_bundle/acprof/host/detect.py +669 -0
- acprof/_bundle/acprof/host/docker_runtime.py +359 -0
- acprof/_bundle/acprof/host/doctor.py +158 -0
- acprof/_bundle/acprof/host/env_utils.py +233 -0
- acprof/_bundle/acprof/host/execution_conditions.py +87 -0
- acprof/_bundle/acprof/host/gpu_device.py +66 -0
- acprof/_bundle/acprof/host/hardware_conditions.py +130 -0
- acprof/_bundle/acprof/host/images/__init__.py +1 -0
- acprof/_bundle/acprof/host/images/dependencies.py +169 -0
- acprof/_bundle/acprof/host/images/environment.py +313 -0
- acprof/_bundle/acprof/host/images/graph.py +143 -0
- acprof/_bundle/acprof/host/images/identity.py +6 -0
- acprof/_bundle/acprof/host/images/inventory.py +445 -0
- acprof/_bundle/acprof/host/images/runtime.py +457 -0
- acprof/_bundle/acprof/host/images/scan.py +154 -0
- acprof/_bundle/acprof/host/input_plan.py +1056 -0
- acprof/_bundle/acprof/host/interface_probe.py +141 -0
- acprof/_bundle/acprof/host/largest_scale_probe.py +566 -0
- acprof/_bundle/acprof/host/matrix_plan.py +98 -0
- acprof/_bundle/acprof/host/measurement/__init__.py +1 -0
- acprof/_bundle/acprof/host/measurement/boundary.py +162 -0
- acprof/_bundle/acprof/host/measurement/capture.py +139 -0
- acprof/_bundle/acprof/host/measurement/checkpoint.py +275 -0
- acprof/_bundle/acprof/host/measurement/config.py +212 -0
- acprof/_bundle/acprof/host/measurement/diagnostics.py +247 -0
- acprof/_bundle/acprof/host/measurement/energy_validation.py +172 -0
- acprof/_bundle/acprof/host/measurement/errors.py +25 -0
- acprof/_bundle/acprof/host/measurement/execution.py +396 -0
- acprof/_bundle/acprof/host/measurement/load.py +237 -0
- acprof/_bundle/acprof/host/measurement/metrics.py +975 -0
- acprof/_bundle/acprof/host/measurement/monitors.py +143 -0
- acprof/_bundle/acprof/host/measurement/publication.py +171 -0
- acprof/_bundle/acprof/host/measurement/requests.py +97 -0
- acprof/_bundle/acprof/host/measurement/types.py +82 -0
- acprof/_bundle/acprof/host/model_coverage.py +337 -0
- acprof/_bundle/acprof/host/model_errors.py +116 -0
- acprof/_bundle/acprof/host/model_inspection.py +107 -0
- acprof/_bundle/acprof/host/model_schema.py +35 -0
- acprof/_bundle/acprof/host/model_store.py +733 -0
- acprof/_bundle/acprof/host/network_preflight.py +229 -0
- acprof/_bundle/acprof/host/orchestrator.py +1133 -0
- acprof/_bundle/acprof/host/permissions.py +117 -0
- acprof/_bundle/acprof/host/platform_metadata.py +63 -0
- acprof/_bundle/acprof/host/posthoc/__init__.py +12 -0
- acprof/_bundle/acprof/host/posthoc/backfill.py +415 -0
- acprof/_bundle/acprof/host/posthoc/context.py +400 -0
- acprof/_bundle/acprof/host/posthoc/plans.py +597 -0
- acprof/_bundle/acprof/host/posthoc/service.py +303 -0
- acprof/_bundle/acprof/host/posthoc/storage.py +491 -0
- acprof/_bundle/acprof/host/preflight.py +370 -0
- acprof/_bundle/acprof/host/profiling/__init__.py +1 -0
- acprof/_bundle/acprof/host/profiling/compute.py +436 -0
- acprof/_bundle/acprof/host/profiling/compute_plan.py +261 -0
- acprof/_bundle/acprof/host/profiling/execution.py +547 -0
- acprof/_bundle/acprof/host/profiling/execution_plan.py +576 -0
- acprof/_bundle/acprof/host/profiling/progress.py +83 -0
- acprof/_bundle/acprof/host/profiling/support.py +252 -0
- acprof/_bundle/acprof/host/profiling/tools/__init__.py +1 -0
- acprof/_bundle/acprof/host/profiling/tools/advisor.py +164 -0
- acprof/_bundle/acprof/host/profiling/tools/compute_parsers.py +409 -0
- acprof/_bundle/acprof/host/profiling/tools/execution_environment.py +135 -0
- acprof/_bundle/acprof/host/profiling/tools/execution_parsers.py +364 -0
- acprof/_bundle/acprof/host/profiling/tools/massif.py +418 -0
- acprof/_bundle/acprof/host/profiling/tools/ncu.py +696 -0
- acprof/_bundle/acprof/host/profiling/tools/nsys.py +326 -0
- acprof/_bundle/acprof/host/profiling/tools/tool_discovery.py +229 -0
- acprof/_bundle/acprof/host/profiling/tools/torch.py +158 -0
- acprof/_bundle/acprof/host/result_cleanup.py +65 -0
- acprof/_bundle/acprof/host/run_state.py +639 -0
- acprof/_bundle/acprof/host/runtime_settings.py +10 -0
- acprof/_bundle/acprof/host/runtime_validation.py +302 -0
- acprof/_bundle/acprof/host/source_bundle.py +96 -0
- acprof/_bundle/acprof/host/startup_probe.py +95 -0
- acprof/_bundle/acprof/host/static_metadata.py +936 -0
- acprof/_bundle/acprof/host/task_support.py +121 -0
- acprof/_bundle/acprof/installation.py +26 -0
- acprof/_bundle/acprof/latency_slo.py +62 -0
- acprof/_bundle/acprof/messages.py +26 -0
- acprof/_bundle/acprof/metric_registry.py +315 -0
- acprof/_bundle/acprof/model_candidates.py +297 -0
- acprof/_bundle/acprof/model_contract.py +234 -0
- acprof/_bundle/acprof/model_dependencies.py +93 -0
- acprof/_bundle/acprof/model_dependency_domain.py +45 -0
- acprof/_bundle/acprof/model_dependency_eval.py +438 -0
- acprof/_bundle/acprof/model_dependency_flow.py +200 -0
- acprof/_bundle/acprof/model_evidence.py +115 -0
- acprof/_bundle/acprof/model_metadata_analysis.py +156 -0
- acprof/_bundle/acprof/model_repository.py +149 -0
- acprof/_bundle/acprof/model_resolution.py +129 -0
- acprof/_bundle/acprof/model_review.py +155 -0
- acprof/_bundle/acprof/model_source_analysis.py +299 -0
- acprof/_bundle/acprof/model_spec.py +204 -0
- acprof/_bundle/acprof/model_support.py +105 -0
- acprof/_bundle/acprof/model_transforms.py +81 -0
- acprof/_bundle/acprof/monitors/__init__.py +1 -0
- acprof/_bundle/acprof/monitors/common.py +63 -0
- acprof/_bundle/acprof/monitors/energy_cpu.py +651 -0
- acprof/_bundle/acprof/monitors/energy_nvml.py +381 -0
- acprof/_bundle/acprof/monitors/gpu_metrics.py +123 -0
- acprof/_bundle/acprof/monitors/interfaces.py +74 -0
- acprof/_bundle/acprof/monitors/perf_mips.py +617 -0
- acprof/_bundle/acprof/monitors/rapl_topology.py +100 -0
- acprof/_bundle/acprof/monitors/resource_metrics.py +472 -0
- acprof/_bundle/acprof/monitors/resource_readers.py +435 -0
- acprof/_bundle/acprof/monitors/resource_usage.py +450 -0
- acprof/_bundle/acprof/monitors/sampling.py +79 -0
- acprof/_bundle/acprof/network_policy.py +182 -0
- acprof/_bundle/acprof/notifications.py +279 -0
- acprof/_bundle/acprof/packet/__init__.py +1 -0
- acprof/_bundle/acprof/packet/merge_packet_latency.py +369 -0
- acprof/_bundle/acprof/packet/sniff_parse_pcap.py +240 -0
- acprof/_bundle/acprof/pixel_metrics.py +103 -0
- acprof/_bundle/acprof/platform.py +180 -0
- acprof/_bundle/acprof/plotting/__init__.py +1 -0
- acprof/_bundle/acprof/plotting/config.py +487 -0
- acprof/_bundle/acprof/plotting/data.py +236 -0
- acprof/_bundle/acprof/plotting/diagnostics.py +747 -0
- acprof/_bundle/acprof/plotting/latency.py +638 -0
- acprof/_bundle/acprof/plotting/metrics.py +648 -0
- acprof/_bundle/acprof/plotting/plotly-LICENSE.txt +21 -0
- acprof/_bundle/acprof/plotting/report.py +66 -0
- acprof/_bundle/acprof/plotting/styles.py +111 -0
- acprof/_bundle/acprof/precision.py +42 -0
- acprof/_bundle/acprof/preparation_events.py +78 -0
- acprof/_bundle/acprof/progress_events.py +105 -0
- acprof/_bundle/acprof/quality.py +153 -0
- acprof/_bundle/acprof/resource_budget.py +29 -0
- acprof/_bundle/acprof/result_csv.py +263 -0
- acprof/_bundle/acprof/result_layers.py +365 -0
- acprof/_bundle/acprof/run_args.py +223 -0
- acprof/_bundle/acprof/run_options.py +225 -0
- acprof/_bundle/acprof/runtime_dependencies.py +195 -0
- acprof/_bundle/acprof/runtime_profiles.py +258 -0
- acprof/_bundle/acprof/runtime_settings.py +72 -0
- acprof/_bundle/acprof/source_identity.py +68 -0
- acprof/_bundle/acprof/telemetry.py +225 -0
- acprof/_bundle/acprof/testing/__init__.py +1 -0
- acprof/_bundle/acprof/testing/evidence.py +117 -0
- acprof/_bundle/acprof/testing/plugin.py +126 -0
- acprof/_bundle/acprof/testing/provenance.py +53 -0
- acprof/_bundle/acprof/testing/sharding.py +14 -0
- acprof/_bundle/acprof/tui/__init__.py +1 -0
- acprof/_bundle/acprof/tui/app.py +934 -0
- acprof/_bundle/acprof/tui/app_contracts.py +43 -0
- acprof/_bundle/acprof/tui/catalog_controller.py +120 -0
- acprof/_bundle/acprof/tui/commands.py +209 -0
- acprof/_bundle/acprof/tui/configuration_controller.py +436 -0
- acprof/_bundle/acprof/tui/diagnostics.py +340 -0
- acprof/_bundle/acprof/tui/downloads.py +56 -0
- acprof/_bundle/acprof/tui/environment.py +248 -0
- acprof/_bundle/acprof/tui/experiment_catalog.py +279 -0
- acprof/_bundle/acprof/tui/experiment_controller.py +132 -0
- acprof/_bundle/acprof/tui/experiment_picker.py +273 -0
- acprof/_bundle/acprof/tui/field_validation.py +62 -0
- acprof/_bundle/acprof/tui/i18n.py +57 -0
- acprof/_bundle/acprof/tui/image_controller.py +525 -0
- acprof/_bundle/acprof/tui/images.py +737 -0
- acprof/_bundle/acprof/tui/input.py +191 -0
- acprof/_bundle/acprof/tui/localization_controller.py +110 -0
- acprof/_bundle/acprof/tui/log.py +310 -0
- acprof/_bundle/acprof/tui/model_candidates.py +278 -0
- acprof/_bundle/acprof/tui/model_controller.py +111 -0
- acprof/_bundle/acprof/tui/model_input.py +12 -0
- acprof/_bundle/acprof/tui/model_store.py +166 -0
- acprof/_bundle/acprof/tui/preflight_controller.py +271 -0
- acprof/_bundle/acprof/tui/preparation.py +269 -0
- acprof/_bundle/acprof/tui/presentation.py +46 -0
- acprof/_bundle/acprof/tui/process.py +111 -0
- acprof/_bundle/acprof/tui/process_controller.py +218 -0
- acprof/_bundle/acprof/tui/profile_controller.py +109 -0
- acprof/_bundle/acprof/tui/progress.py +195 -0
- acprof/_bundle/acprof/tui/recovery.py +114 -0
- acprof/_bundle/acprof/tui/recovery_controller.py +169 -0
- acprof/_bundle/acprof/tui/rendering.py +75 -0
- acprof/_bundle/acprof/tui/reports.py +303 -0
- acprof/_bundle/acprof/tui/result_controller.py +279 -0
- acprof/_bundle/acprof/tui/review_inputs.py +54 -0
- acprof/_bundle/acprof/tui/run_form.py +125 -0
- acprof/_bundle/acprof/tui/run_planning.py +97 -0
- acprof/_bundle/acprof/tui/run_results.py +175 -0
- acprof/_bundle/acprof/tui/scrollbar.py +65 -0
- acprof/_bundle/acprof/tui/settings.py +203 -0
- acprof/_bundle/acprof/tui/slash_controller.py +95 -0
- acprof/_bundle/acprof/tui/stages.py +97 -0
- acprof/_bundle/acprof/tui/storage.py +150 -0
- acprof/_bundle/acprof/tui/table.py +213 -0
- acprof/_bundle/acprof/tui/themes.py +112 -0
- acprof/_bundle/acprof/tui/translation_catalog.py +1861 -0
- acprof/_bundle/acprof/tui/tui.tcss +373 -0
- acprof/_bundle/acprof/tui/views.py +706 -0
- acprof/_bundle/acprof/window_records.py +165 -0
- acprof/_bundle/acprof/workloads/__init__.py +222 -0
- acprof/_bundle/acprof/workloads/audio.py +621 -0
- acprof/_bundle/acprof/workloads/contract.py +116 -0
- acprof/_bundle/acprof/workloads/cv.py +240 -0
- acprof/_bundle/acprof/workloads/diffusion.py +410 -0
- acprof/_bundle/acprof/workloads/multimodal.py +329 -0
- acprof/_bundle/acprof/workloads/nlp.py +151 -0
- acprof/_bundle/acprof/workloads/structured.py +151 -0
- acprof/_bundle/acprof/workloads/timeseries.py +69 -0
- acprof/_bundle/assets/audio/librispeech-clean-test-en-30s/audio.wav +0 -0
- acprof/_bundle/assets/audio/librispeech-clean-test-en-30s/source.json +81 -0
- acprof/_bundle/dockerfiles/environment_tools.py +314 -0
- acprof/_bundle/dockerfiles/locks/audio-cpu.artifacts.json +503 -0
- acprof/_bundle/dockerfiles/locks/audio-cpu.txt +143 -0
- acprof/_bundle/dockerfiles/locks/audio-cu124.artifacts.json +600 -0
- acprof/_bundle/dockerfiles/locks/audio-cu124.txt +171 -0
- acprof/_bundle/dockerfiles/locks/audio-cu128.artifacts.json +544 -0
- acprof/_bundle/dockerfiles/locks/audio-cu128.txt +155 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cpu.artifacts.json +510 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cpu.txt +145 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cu124.artifacts.json +607 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cu124.txt +173 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cu128.artifacts.json +642 -0
- acprof/_bundle/dockerfiles/locks/custom-multimodal-cu128.txt +183 -0
- acprof/_bundle/dockerfiles/locks/cv-cpu.artifacts.json +279 -0
- acprof/_bundle/dockerfiles/locks/cv-cpu.txt +79 -0
- acprof/_bundle/dockerfiles/locks/cv-cu124.artifacts.json +376 -0
- acprof/_bundle/dockerfiles/locks/cv-cu124.txt +107 -0
- acprof/_bundle/dockerfiles/locks/cv-cu128.artifacts.json +411 -0
- acprof/_bundle/dockerfiles/locks/cv-cu128.txt +117 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cpu.artifacts.json +335 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cpu.txt +95 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cu124.artifacts.json +432 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cu124.txt +123 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cu128.artifacts.json +467 -0
- acprof/_bundle/dockerfiles/locks/diffusion-cu128.txt +133 -0
- acprof/_bundle/dockerfiles/locks/moss-transformers5104.artifacts.json +621 -0
- acprof/_bundle/dockerfiles/locks/moss-transformers5104.txt +177 -0
- acprof/_bundle/dockerfiles/locks/multimodal-transformers4576.artifacts.json +635 -0
- acprof/_bundle/dockerfiles/locks/multimodal-transformers4576.txt +181 -0
- acprof/_bundle/dockerfiles/locks/nlp-cpu.artifacts.json +363 -0
- acprof/_bundle/dockerfiles/locks/nlp-cpu.txt +103 -0
- acprof/_bundle/dockerfiles/locks/nlp-cu124.artifacts.json +460 -0
- acprof/_bundle/dockerfiles/locks/nlp-cu124.txt +131 -0
- acprof/_bundle/dockerfiles/locks/nlp-cu128.artifacts.json +495 -0
- acprof/_bundle/dockerfiles/locks/nlp-cu128.txt +141 -0
- acprof/_bundle/dockerfiles/locks/onnxruntime-cpu.artifacts.json +261 -0
- acprof/_bundle/dockerfiles/locks/onnxruntime-cpu.txt +73 -0
- acprof/_bundle/dockerfiles/locks/platform-cpu.artifacts.json +99 -0
- acprof/_bundle/dockerfiles/locks/platform-cpu.txt +27 -0
- acprof/_bundle/dockerfiles/locks/platform-cu124.artifacts.json +196 -0
- acprof/_bundle/dockerfiles/locks/platform-cu124.txt +55 -0
- acprof/_bundle/dockerfiles/locks/platform-cu128.artifacts.json +231 -0
- acprof/_bundle/dockerfiles/locks/platform-cu128.txt +65 -0
- acprof/_bundle/dockerfiles/locks/platform-python-cpu.artifacts.json +37 -0
- acprof/_bundle/dockerfiles/locks/platform-python-cpu.txt +9 -0
- acprof/_bundle/dockerfiles/locks/structured-cpu.artifacts.json +279 -0
- acprof/_bundle/dockerfiles/locks/structured-cpu.txt +79 -0
- acprof/_bundle/dockerfiles/locks/structured-cu124.artifacts.json +376 -0
- acprof/_bundle/dockerfiles/locks/structured-cu124.txt +107 -0
- acprof/_bundle/dockerfiles/locks/structured-cu128.artifacts.json +411 -0
- acprof/_bundle/dockerfiles/locks/structured-cu128.txt +117 -0
- acprof/_bundle/dockerfiles/locks/system-trixie-amd64.json +620 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cpu.artifacts.json +314 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cpu.txt +89 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cu124.artifacts.json +411 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cu124.txt +117 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cu128.artifacts.json +446 -0
- acprof/_bundle/dockerfiles/locks/timeseries-cu128.txt +127 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cpu.artifacts.json +594 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cpu.txt +169 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cu124.artifacts.json +691 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cu124.txt +197 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cu128.artifacts.json +726 -0
- acprof/_bundle/dockerfiles/locks/transformers5104-cu128.txt +207 -0
- acprof/_bundle/dockerfiles/platform.Dockerfile +22 -0
- acprof/_bundle/dockerfiles/requirements/audio.in +5 -0
- acprof/_bundle/dockerfiles/requirements/custom-multimodal.in +2 -0
- acprof/_bundle/dockerfiles/requirements/cv.in +4 -0
- acprof/_bundle/dockerfiles/requirements/diffusion.in +6 -0
- acprof/_bundle/dockerfiles/requirements/moss-transformers5104.in +9 -0
- acprof/_bundle/dockerfiles/requirements/multimodal-transformers4576.in +3 -0
- acprof/_bundle/dockerfiles/requirements/nlp.in +7 -0
- acprof/_bundle/dockerfiles/requirements/onnxruntime.in +9 -0
- acprof/_bundle/dockerfiles/requirements/service.in +8 -0
- acprof/_bundle/dockerfiles/requirements/structured.in +4 -0
- acprof/_bundle/dockerfiles/requirements/timeseries.in +2 -0
- acprof/_bundle/dockerfiles/requirements/timm.in +1 -0
- acprof/_bundle/dockerfiles/requirements/transformers5104.in +4 -0
- acprof/_bundle/dockerfiles/runtime-final.Dockerfile +34 -0
- acprof/_bundle/dockerfiles/runtime-model.Dockerfile +19 -0
- acprof/_bundle/dockerfiles/runtime.Dockerfile +23 -0
- acprof/_bundle/examples/coverage/regression.json +17 -0
- acprof/_bundle/examples/hardware-validation.json +19 -0
- acprof/_bundle/examples/multimodal/ultravox.model.json +29 -0
- acprof/_bundle/examples/nlp/smoke.py +111 -0
- acprof/_bundle/examples/onnxruntime/fixtures.py +164 -0
- acprof/_bundle/examples/onnxruntime/iris.json +16 -0
- acprof/_bundle/examples/onnxruntime/iris.model.json +7 -0
- acprof/_bundle/examples/onnxruntime/real_models.py +155 -0
- acprof/_bundle/examples/onnxruntime/smoke.py +68 -0
- acprof/_bundle/examples/structured/chronos_smoke.py +56 -0
- acprof/_bundle/examples/structured/export_models.py +71 -0
- acprof/_bundle/examples/structured/smoke.py +71 -0
- acprof/_bundle/licenses/CC-BY-4.0.txt +156 -0
- acprof/analysis/__init__.py +1 -0
- acprof/analysis/audit.py +276 -0
- acprof/analysis/comparison.py +364 -0
- acprof/analysis/compatibility.py +223 -0
- acprof/analysis/conditions.py +185 -0
- acprof/analysis/independent_comparison.py +191 -0
- acprof/analysis/latency_model.py +1106 -0
- acprof/analysis/latency_report.py +577 -0
- acprof/analysis/model.py +276 -0
- acprof/analysis/precision.py +51 -0
- acprof/analysis/uncertainty.py +144 -0
- acprof/application/__init__.py +1 -0
- acprof/application/download.py +14 -0
- acprof/application/errors.py +5 -0
- acprof/application/notifications.py +302 -0
- acprof/application/preparation.py +333 -0
- acprof/application/resources.py +66 -0
- acprof/application/run.py +462 -0
- acprof/application/terminal_log.py +136 -0
- acprof/artifact_layout.py +261 -0
- acprof/artifacts.py +161 -0
- acprof/capabilities.py +404 -0
- acprof/cli/__init__.py +1 -0
- acprof/cli/audit.py +74 -0
- acprof/cli/auto.py +41 -0
- acprof/cli/backfill_compute.py +498 -0
- acprof/cli/compare.py +34 -0
- acprof/cli/coverage.py +70 -0
- acprof/cli/doctor.py +47 -0
- acprof/cli/inspect.py +101 -0
- acprof/cli/load.py +190 -0
- acprof/cli/main.py +64 -0
- acprof/cli/model_store.py +22 -0
- acprof/cli/plot.py +211 -0
- acprof/cli/posthoc.py +113 -0
- acprof/cli/probe.py +186 -0
- acprof/cli/report.py +35 -0
- acprof/cli/results.py +37 -0
- acprof/cli/run.py +54 -0
- acprof/cli/stats.py +94 -0
- acprof/cli/tui.py +65 -0
- acprof/config.py +177 -0
- acprof/container/__init__.py +1 -0
- acprof/container/compat/__init__.py +1 -0
- acprof/container/compat/transformers_dynamic.py +54 -0
- acprof/container/compat/transformers_model_types.json +1091 -0
- acprof/container/compute_profile_runner.py +392 -0
- acprof/container/download_model.py +165 -0
- acprof/container/execution.py +73 -0
- acprof/container/handlers/__init__.py +298 -0
- acprof/container/handlers/audio.py +743 -0
- acprof/container/handlers/custom_pipeline.py +74 -0
- acprof/container/handlers/cv.py +321 -0
- acprof/container/handlers/diffusion.py +728 -0
- acprof/container/handlers/moss.py +64 -0
- acprof/container/handlers/multimodal.py +609 -0
- acprof/container/handlers/nlp.py +747 -0
- acprof/container/handlers/onnx_tasks.py +231 -0
- acprof/container/handlers/onnxruntime.py +90 -0
- acprof/container/handlers/structured.py +185 -0
- acprof/container/handlers/timeseries.py +178 -0
- acprof/container/load_policy.py +81 -0
- acprof/container/loading_quality.py +48 -0
- acprof/container/local_pipeline.py +31 -0
- acprof/container/model_files.py +280 -0
- acprof/container/model_probe.py +80 -0
- acprof/container/onnx_session.py +150 -0
- acprof/container/runtime_manifest.py +150 -0
- acprof/container/runtime_validate.py +156 -0
- acprof/container/server.py +209 -0
- acprof/container/torch_execution.py +55 -0
- acprof/container/validation.py +172 -0
- acprof/cpu_affinity.py +35 -0
- acprof/dependency_locks.py +129 -0
- acprof/experiment.py +356 -0
- acprof/extensions/__init__.py +294 -0
- acprof/extensions/builtin/manifest.json +3591 -0
- acprof/extensions/onnxruntime/manifest.json +191 -0
- acprof/extensions/schema.py +238 -0
- acprof/extensions/transformers/4.57.6.json +1639 -0
- acprof/extensions/transformers/5.10.4.json +1812 -0
- acprof/failures.py +115 -0
- acprof/hardware_conditions.py +18 -0
- acprof/hf_download.py +143 -0
- acprof/hf_endpoints.py +62 -0
- acprof/hf_transport.py +238 -0
- acprof/host/__init__.py +1 -0
- acprof/host/automation.py +161 -0
- acprof/host/client.py +520 -0
- acprof/host/collection_history.py +77 -0
- acprof/host/collection_workflow.py +285 -0
- acprof/host/command.py +119 -0
- acprof/host/container_lifecycle.py +225 -0
- acprof/host/container_state.py +128 -0
- acprof/host/coverage_state.py +259 -0
- acprof/host/detect.py +669 -0
- acprof/host/docker_runtime.py +359 -0
- acprof/host/doctor.py +158 -0
- acprof/host/env_utils.py +233 -0
- acprof/host/execution_conditions.py +87 -0
- acprof/host/gpu_device.py +66 -0
- acprof/host/hardware_conditions.py +130 -0
- acprof/host/images/__init__.py +1 -0
- acprof/host/images/dependencies.py +169 -0
- acprof/host/images/environment.py +313 -0
- acprof/host/images/graph.py +143 -0
- acprof/host/images/identity.py +6 -0
- acprof/host/images/inventory.py +445 -0
- acprof/host/images/runtime.py +457 -0
- acprof/host/images/scan.py +154 -0
- acprof/host/input_plan.py +1056 -0
- acprof/host/interface_probe.py +141 -0
- acprof/host/largest_scale_probe.py +566 -0
- acprof/host/matrix_plan.py +98 -0
- acprof/host/measurement/__init__.py +1 -0
- acprof/host/measurement/boundary.py +162 -0
- acprof/host/measurement/capture.py +139 -0
- acprof/host/measurement/checkpoint.py +275 -0
- acprof/host/measurement/config.py +212 -0
- acprof/host/measurement/diagnostics.py +247 -0
- acprof/host/measurement/energy_validation.py +172 -0
- acprof/host/measurement/errors.py +25 -0
- acprof/host/measurement/execution.py +396 -0
- acprof/host/measurement/load.py +237 -0
- acprof/host/measurement/metrics.py +975 -0
- acprof/host/measurement/monitors.py +143 -0
- acprof/host/measurement/publication.py +171 -0
- acprof/host/measurement/requests.py +97 -0
- acprof/host/measurement/types.py +82 -0
- acprof/host/model_coverage.py +337 -0
- acprof/host/model_errors.py +116 -0
- acprof/host/model_inspection.py +107 -0
- acprof/host/model_schema.py +35 -0
- acprof/host/model_store.py +733 -0
- acprof/host/network_preflight.py +229 -0
- acprof/host/orchestrator.py +1133 -0
- acprof/host/permissions.py +117 -0
- acprof/host/platform_metadata.py +63 -0
- acprof/host/posthoc/__init__.py +12 -0
- acprof/host/posthoc/backfill.py +415 -0
- acprof/host/posthoc/context.py +400 -0
- acprof/host/posthoc/plans.py +597 -0
- acprof/host/posthoc/service.py +303 -0
- acprof/host/posthoc/storage.py +491 -0
- acprof/host/preflight.py +370 -0
- acprof/host/profiling/__init__.py +1 -0
- acprof/host/profiling/compute.py +436 -0
- acprof/host/profiling/compute_plan.py +261 -0
- acprof/host/profiling/execution.py +547 -0
- acprof/host/profiling/execution_plan.py +576 -0
- acprof/host/profiling/progress.py +83 -0
- acprof/host/profiling/support.py +252 -0
- acprof/host/profiling/tools/__init__.py +1 -0
- acprof/host/profiling/tools/advisor.py +164 -0
- acprof/host/profiling/tools/compute_parsers.py +409 -0
- acprof/host/profiling/tools/execution_environment.py +135 -0
- acprof/host/profiling/tools/execution_parsers.py +364 -0
- acprof/host/profiling/tools/massif.py +418 -0
- acprof/host/profiling/tools/ncu.py +696 -0
- acprof/host/profiling/tools/nsys.py +326 -0
- acprof/host/profiling/tools/tool_discovery.py +229 -0
- acprof/host/profiling/tools/torch.py +158 -0
- acprof/host/result_cleanup.py +65 -0
- acprof/host/run_state.py +639 -0
- acprof/host/runtime_settings.py +10 -0
- acprof/host/runtime_validation.py +302 -0
- acprof/host/source_bundle.py +96 -0
- acprof/host/startup_probe.py +95 -0
- acprof/host/static_metadata.py +936 -0
- acprof/host/task_support.py +121 -0
- acprof/installation.py +26 -0
- acprof/latency_slo.py +62 -0
- acprof/messages.py +26 -0
- acprof/metric_registry.py +315 -0
- acprof/model_candidates.py +297 -0
- acprof/model_contract.py +234 -0
- acprof/model_dependencies.py +93 -0
- acprof/model_dependency_domain.py +45 -0
- acprof/model_dependency_eval.py +438 -0
- acprof/model_dependency_flow.py +200 -0
- acprof/model_evidence.py +115 -0
- acprof/model_metadata_analysis.py +156 -0
- acprof/model_repository.py +149 -0
- acprof/model_resolution.py +129 -0
- acprof/model_review.py +155 -0
- acprof/model_source_analysis.py +299 -0
- acprof/model_spec.py +204 -0
- acprof/model_support.py +105 -0
- acprof/model_transforms.py +81 -0
- acprof/monitors/__init__.py +1 -0
- acprof/monitors/common.py +63 -0
- acprof/monitors/energy_cpu.py +651 -0
- acprof/monitors/energy_nvml.py +381 -0
- acprof/monitors/gpu_metrics.py +123 -0
- acprof/monitors/interfaces.py +74 -0
- acprof/monitors/perf_mips.py +617 -0
- acprof/monitors/rapl_topology.py +100 -0
- acprof/monitors/resource_metrics.py +472 -0
- acprof/monitors/resource_readers.py +435 -0
- acprof/monitors/resource_usage.py +450 -0
- acprof/monitors/sampling.py +79 -0
- acprof/network_policy.py +182 -0
- acprof/notifications.py +279 -0
- acprof/packet/__init__.py +1 -0
- acprof/packet/merge_packet_latency.py +369 -0
- acprof/packet/sniff_parse_pcap.py +240 -0
- acprof/pixel_metrics.py +103 -0
- acprof/platform.py +180 -0
- acprof/plotting/__init__.py +1 -0
- acprof/plotting/config.py +487 -0
- acprof/plotting/data.py +236 -0
- acprof/plotting/diagnostics.py +747 -0
- acprof/plotting/latency.py +638 -0
- acprof/plotting/metrics.py +648 -0
- acprof/plotting/plotly-LICENSE.txt +21 -0
- acprof/plotting/report.css +61 -0
- acprof/plotting/report.html +68 -0
- acprof/plotting/report.js +295 -0
- acprof/plotting/report.py +66 -0
- acprof/plotting/styles.py +111 -0
- acprof/plotting/view_model.js +145 -0
- acprof/precision.py +42 -0
- acprof/preparation_events.py +78 -0
- acprof/progress_events.py +105 -0
- acprof/quality.py +153 -0
- acprof/resource_budget.py +29 -0
- acprof/result_csv.py +263 -0
- acprof/result_layers.py +365 -0
- acprof/run_args.py +223 -0
- acprof/run_options.py +225 -0
- acprof/runtime_dependencies.py +195 -0
- acprof/runtime_profiles.py +258 -0
- acprof/runtime_settings.py +72 -0
- acprof/source_identity.py +68 -0
- acprof/telemetry.py +225 -0
- acprof/testing/__init__.py +1 -0
- acprof/testing/evidence.py +117 -0
- acprof/testing/plugin.py +126 -0
- acprof/testing/provenance.py +53 -0
- acprof/testing/sharding.py +14 -0
- acprof/tui/__init__.py +1 -0
- acprof/tui/app.py +934 -0
- acprof/tui/app_contracts.py +43 -0
- acprof/tui/catalog_controller.py +120 -0
- acprof/tui/commands.py +209 -0
- acprof/tui/configuration_controller.py +436 -0
- acprof/tui/diagnostics.py +340 -0
- acprof/tui/downloads.py +56 -0
- acprof/tui/environment.py +248 -0
- acprof/tui/experiment_catalog.py +279 -0
- acprof/tui/experiment_controller.py +132 -0
- acprof/tui/experiment_picker.py +273 -0
- acprof/tui/field_validation.py +62 -0
- acprof/tui/i18n.py +57 -0
- acprof/tui/image_controller.py +525 -0
- acprof/tui/images.py +737 -0
- acprof/tui/input.py +191 -0
- acprof/tui/localization_controller.py +110 -0
- acprof/tui/log.py +310 -0
- acprof/tui/model_candidates.py +278 -0
- acprof/tui/model_controller.py +111 -0
- acprof/tui/model_input.py +12 -0
- acprof/tui/model_store.py +166 -0
- acprof/tui/preflight_controller.py +271 -0
- acprof/tui/preparation.py +269 -0
- acprof/tui/presentation.py +46 -0
- acprof/tui/process.py +111 -0
- acprof/tui/process_controller.py +218 -0
- acprof/tui/profile_controller.py +109 -0
- acprof/tui/progress.py +195 -0
- acprof/tui/recovery.py +114 -0
- acprof/tui/recovery_controller.py +169 -0
- acprof/tui/rendering.py +75 -0
- acprof/tui/reports.py +303 -0
- acprof/tui/result_controller.py +279 -0
- acprof/tui/review_inputs.py +54 -0
- acprof/tui/run_form.py +125 -0
- acprof/tui/run_planning.py +97 -0
- acprof/tui/run_results.py +175 -0
- acprof/tui/scrollbar.py +65 -0
- acprof/tui/settings.py +203 -0
- acprof/tui/slash_controller.py +95 -0
- acprof/tui/stages.py +97 -0
- acprof/tui/storage.py +150 -0
- acprof/tui/table.py +213 -0
- acprof/tui/themes.py +112 -0
- acprof/tui/translation_catalog.py +1861 -0
- acprof/tui/tui.tcss +373 -0
- acprof/tui/views.py +706 -0
- acprof/window_records.py +165 -0
- acprof/workloads/__init__.py +222 -0
- acprof/workloads/audio.py +621 -0
- acprof/workloads/contract.py +116 -0
- acprof/workloads/cv.py +240 -0
- acprof/workloads/diffusion.py +410 -0
- acprof/workloads/multimodal.py +329 -0
- acprof/workloads/nlp.py +151 -0
- acprof/workloads/structured.py +151 -0
- acprof/workloads/timeseries.py +69 -0
- acprof-0.3.0.dist-info/METADATA +117 -0
- acprof-0.3.0.dist-info/RECORD +704 -0
- acprof-0.3.0.dist-info/WHEEL +4 -0
- acprof-0.3.0.dist-info/entry_points.txt +2 -0
- acprof-0.3.0.dist-info/licenses/LICENSE +202 -0
- acprof-0.3.0.dist-info/licenses/NOTICE +43 -0
- acprof-0.3.0.dist-info/licenses/licenses/CC-BY-4.0.txt +156 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Validate a selected candidate interface, never load inference weights."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from acprof.model_spec import (
|
|
7
|
+
FORMAT_BACKENDS,
|
|
8
|
+
custom_code_files,
|
|
9
|
+
task_model_spec,
|
|
10
|
+
validate_model_spec,
|
|
11
|
+
)
|
|
12
|
+
from acprof.model_support import supports_pipeline_task, supports_transformers_task
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def require_resolved_candidate(task_info: Any) -> None:
|
|
16
|
+
resolution = getattr(task_info, "model_resolution", {}) or {}
|
|
17
|
+
if resolution.get("failure", {}).get("reason_code") == "model_contract_required":
|
|
18
|
+
from acprof.failures import Failure, RuntimeFailure
|
|
19
|
+
raise RuntimeFailure(Failure(**resolution["failure"]))
|
|
20
|
+
if (resolution.get("status") in {"ambiguous", "needs_configuration"}
|
|
21
|
+
or resolution.get("semantics", {}).get("status") in {"conflict", "unresolved"}):
|
|
22
|
+
choices = ", ".join(f"{item['task']}/{item['backend']}" for item in resolution.get("candidates", []))
|
|
23
|
+
details = "; ".join([*resolution.get("conflicts", []), *resolution.get("missing", [])])
|
|
24
|
+
raise ValueError(f"model resolution {resolution['status']}: {details}; candidates: {choices or 'none'}; "
|
|
25
|
+
"use --task / --backend / --model-spec to complete the interface")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def resolve_model_interface(task_info: Any) -> dict:
|
|
29
|
+
"""Reject known incompatible layouts; a successful resolution is only a candidate."""
|
|
30
|
+
from acprof.extensions import select_extension
|
|
31
|
+
from acprof.failures import Failure, RuntimeFailure
|
|
32
|
+
from acprof.runtime_profiles import locked_transformers_version, select_runtime_profile
|
|
33
|
+
|
|
34
|
+
require_resolved_candidate(task_info)
|
|
35
|
+
extension = select_extension(task_info)
|
|
36
|
+
backend, library = task_info.runtime_backend, task_info.library_name
|
|
37
|
+
config = getattr(task_info, "model_config", {}) or {}
|
|
38
|
+
files: set[str] = set(getattr(task_info, "repository_files", ()) or ())
|
|
39
|
+
metadata = getattr(task_info, "repository_metadata", {}) or {}
|
|
40
|
+
errors = getattr(task_info, "metadata_errors", ())
|
|
41
|
+
if errors:
|
|
42
|
+
raise ValueError("Model metadata could not be resolved: " + "; ".join(errors))
|
|
43
|
+
spec = task_model_spec(task_info)
|
|
44
|
+
if extension.handler_options.get("requires_model_spec") and not spec:
|
|
45
|
+
failure = Failure("preflight", "model_contract_required",
|
|
46
|
+
f"{backend}/{task_info.pipeline_tag} requires acprof_model.json; input semantics cannot be inferred",
|
|
47
|
+
runtime_profile=getattr(task_info, "runtime_profile_id", ""),
|
|
48
|
+
retryability="after_configuration", evidence={"required_artifact": "acprof_model.json", "backend": backend})
|
|
49
|
+
task_info.model_resolution.update(status="needs_configuration", failure=failure.to_dict())
|
|
50
|
+
raise RuntimeFailure(failure)
|
|
51
|
+
if spec:
|
|
52
|
+
validate_model_spec(spec)
|
|
53
|
+
if spec["task"] != task_info.pipeline_tag or FORMAT_BACKENDS[spec["format"]] != backend:
|
|
54
|
+
raise ValueError("model spec task/format conflicts with selected interface")
|
|
55
|
+
if files and spec.get("model_file") and spec["model_file"] not in files:
|
|
56
|
+
raise ValueError(f"model spec model_file is absent from snapshot: {spec['model_file']}")
|
|
57
|
+
code_files = set()
|
|
58
|
+
for item in [config, *(value for value in metadata.values() if isinstance(value, dict))]:
|
|
59
|
+
code_files.update(custom_code_files(item))
|
|
60
|
+
if files and code_files - files:
|
|
61
|
+
raise ValueError(f"custom code is absent from snapshot: {sorted(code_files - files)}")
|
|
62
|
+
pipeline_name = spec.get("pipeline_task", task_info.pipeline_tag)
|
|
63
|
+
if spec.get("format") == "transformers-pipeline":
|
|
64
|
+
from acprof.model_spec import declared_multimodal_pipeline
|
|
65
|
+
if (task_info.task_family not in {"nlp", "cv", "audio"} and not declared_multimodal_pipeline(task_info)) or task_info.pipeline_tag in {
|
|
66
|
+
"video-classification", "keypoint-detection", "sentence-similarity", "text-ranking",
|
|
67
|
+
}:
|
|
68
|
+
raise ValueError("custom pipeline needs an adapter for this task protocol")
|
|
69
|
+
if pipeline_name not in (config.get("custom_pipelines") or {}):
|
|
70
|
+
raise ValueError(f"pipeline_task {pipeline_name!r} is not declared in config.custom_pipelines")
|
|
71
|
+
if any(item["repo_id"] == task_info.model_id for item in spec.get("dependencies", [])):
|
|
72
|
+
raise ValueError("model dependencies must not override the primary snapshot")
|
|
73
|
+
format_name, loader, operation = "unknown", backend, "predict"
|
|
74
|
+
profile = select_runtime_profile(task_info)
|
|
75
|
+
task_info.runtime_profile_id, task_info.model_adapter = profile.profile_id, profile.adapter
|
|
76
|
+
version = locked_transformers_version(profile.environment)
|
|
77
|
+
if (extension.handler_options.get("uses_pipeline") and backend not in {"sentence_transformers", "cross_encoder"}
|
|
78
|
+
and pipeline_name not in (config.get("custom_pipelines") or {})
|
|
79
|
+
and version and not supports_pipeline_task(version, pipeline_name)):
|
|
80
|
+
raise RuntimeFailure(Failure("preflight", "runtime_task_unsupported",
|
|
81
|
+
f"Pipeline task {pipeline_name!r} is not registered in transformers=={version}",
|
|
82
|
+
runtime_profile=profile.profile_id,
|
|
83
|
+
evidence={"transformers_version": version, "pipeline_task": pipeline_name}))
|
|
84
|
+
if backend in {"transformers_model", "transformers_pipeline", "sentence_transformers", "cross_encoder"}:
|
|
85
|
+
# Unknown ecosystem tags may still wrap a registered native checkpoint;
|
|
86
|
+
# accept actual native metadata, never an unrelated task tag alone.
|
|
87
|
+
native = version and supports_transformers_task(version, task_info.pipeline_tag, str(config.get("model_type", "")), config)
|
|
88
|
+
if library not in {"", "unknown", "transformers", "sentence-transformers", "timm"} and not native and extension.adapter == "family-default":
|
|
89
|
+
raise ValueError(f"library {library!r} has no shared {backend} interface; select a registered backend")
|
|
90
|
+
if files and "config.json" not in files and "modules.json" not in files:
|
|
91
|
+
suffix = "GGUF" if any(name.lower().endswith(".gguf") for name in files) else "missing config.json/modules.json"
|
|
92
|
+
raise RuntimeFailure(Failure("preflight", "artifact_layout_unsupported", f"{backend} cannot load this artifact layout ({suffix})", runtime_profile=profile.profile_id, evidence={"files": sorted(files)}))
|
|
93
|
+
if "adapter_config.json" in files:
|
|
94
|
+
base = (metadata.get("adapter_config.json") or {}).get("base_model_name_or_path")
|
|
95
|
+
raise ValueError(f"adapter requires an offline base model dependency ({base or 'unknown'}); a standalone snapshot is incomplete")
|
|
96
|
+
format_name = "sentence_transformers" if backend == "sentence_transformers" else "transformers"
|
|
97
|
+
if backend == "sentence_transformers":
|
|
98
|
+
loader, operation = "SentenceTransformer", "encode"
|
|
99
|
+
elif backend == "cross_encoder":
|
|
100
|
+
loader = "CrossEncoder"
|
|
101
|
+
else:
|
|
102
|
+
loader = "Transformers Auto/pipeline"
|
|
103
|
+
elif backend == "chronos":
|
|
104
|
+
format_name, loader = "chronos", "BaseChronosPipeline"
|
|
105
|
+
elif backend == "diffusers":
|
|
106
|
+
if files and "model_index.json" not in files:
|
|
107
|
+
format_name = "GGUF" if any(name.lower().endswith(".gguf") for name in files) else "single-file/components"
|
|
108
|
+
raise RuntimeFailure(Failure("preflight", "artifact_layout_unsupported", f"DiffusionPipeline requires model_index.json; {format_name} needs a compatible artifact loader", runtime_profile=profile.profile_id, evidence={"files": sorted(files)}))
|
|
109
|
+
format_name, loader, operation = "diffusers_pipeline", "DiffusionPipeline", "__call__"
|
|
110
|
+
elif backend == "onnxruntime":
|
|
111
|
+
format_name, loader, operation = "onnx", "InferenceSession", "run"
|
|
112
|
+
artifacts = [name for name in files if name.lower().endswith(".onnx")]
|
|
113
|
+
if files and not spec and len(artifacts) != 1:
|
|
114
|
+
raise ValueError("ONNX requires one artifact or --model-spec selecting model_file")
|
|
115
|
+
if files and task_info.task_family in {"cv", "nlp"} and not spec:
|
|
116
|
+
raise RuntimeFailure(Failure("preflight", "model_contract_required", "ONNX image/text preprocessing requires --model-spec (acprof_model.json)", runtime_profile=profile.profile_id))
|
|
117
|
+
elif backend in {"torchscript", "skops"}:
|
|
118
|
+
format_name = backend
|
|
119
|
+
return {**getattr(task_info, "model_resolution", {}),
|
|
120
|
+
"schema_version": 1, "status": "candidate", "task": task_info.pipeline_tag,
|
|
121
|
+
"backend": backend, "library": library, "artifact_format": format_name,
|
|
122
|
+
"loader": loader, "operation": operation, "model_revision": task_info.model_revision,
|
|
123
|
+
"metadata_files": sorted(metadata), "model_type": config.get("model_type"),
|
|
124
|
+
"interface_kind": "custom_pipeline" if pipeline_name in (config.get("custom_pipelines") or {}) else
|
|
125
|
+
"custom_auto" if config.get("auto_map") else "standard",
|
|
126
|
+
"pipeline_task": pipeline_name if backend == "transformers_pipeline" else None,
|
|
127
|
+
"code_revision": task_info.model_revision if code_files else None,
|
|
128
|
+
"code_files": sorted(code_files), "model_spec": spec, "runtime_profile": profile.profile_id,
|
|
129
|
+
"transformers_version": version}
|
acprof/model_review.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Explicit field-level decisions over a pinned, reviewable draft contract."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import copy
|
|
5
|
+
|
|
6
|
+
from acprof.model_evidence import content_digest
|
|
7
|
+
from acprof.model_spec import validate_model_spec
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def review_questions(task_info) -> list[dict]:
|
|
11
|
+
report = task_info.model_resolution.get("contract", {})
|
|
12
|
+
fields = report.get("fields", {})
|
|
13
|
+
pending = report.get("unresolved_fields", [])
|
|
14
|
+
draft = report.get("draft_spec", {})
|
|
15
|
+
inputs = draft.get("multimodal", {}).get("inputs", {})
|
|
16
|
+
input_gaps = [name for name in pending if name.startswith("multimodal.inputs.")]
|
|
17
|
+
questions = []
|
|
18
|
+
unassigned = {name.removeprefix("pipeline.inputs."): item["value"] for name, item in fields.items()
|
|
19
|
+
if name.startswith("pipeline.inputs.") and name.removeprefix("pipeline.inputs.") not in inputs}
|
|
20
|
+
targets = [name for name, item in unassigned.items() if item.get("required")]
|
|
21
|
+
text_names = {"prompt", "text", "messages", "turns"}
|
|
22
|
+
if "multimodal.inputs.text" in input_gaps and not text_names.intersection(targets):
|
|
23
|
+
targets.extend(name for name in unassigned if name in text_names and name not in targets)
|
|
24
|
+
if input_gaps:
|
|
25
|
+
for target in targets:
|
|
26
|
+
questions.append({"path": "multimodal.inputs." + target, "value": None,
|
|
27
|
+
"reason": "; ".join(fields[name].get("reason", name) for name in input_gaps)})
|
|
28
|
+
if not targets:
|
|
29
|
+
questions.append({"path": "multimodal.inputs", "value": inputs,
|
|
30
|
+
"reason": "canonical input mapping is unresolved"})
|
|
31
|
+
for name in pending:
|
|
32
|
+
if name in input_gaps or name == "model_spec" and questions:
|
|
33
|
+
continue
|
|
34
|
+
if name == "pipeline_task" and fields[name]["state"] == "ambiguous":
|
|
35
|
+
config = task_info.repository_metadata.get("config.json", task_info.model_config)
|
|
36
|
+
questions.append({"path": name, "value": None, "reason": fields[name]["reason"],
|
|
37
|
+
"options": sorted(config.get("custom_pipelines", {}))})
|
|
38
|
+
elif name in {"dependencies", "multimodal.forward_kwargs"}:
|
|
39
|
+
editable = True
|
|
40
|
+
blocked = False
|
|
41
|
+
if name == "dependencies":
|
|
42
|
+
value = []
|
|
43
|
+
editable = False
|
|
44
|
+
for candidate in report.get("dependency_candidates", []):
|
|
45
|
+
if candidate.get("activation") == "inactive" or candidate.get("dependency_kind") == "main_model":
|
|
46
|
+
continue
|
|
47
|
+
choice = {"repo_id": candidate["repo_id"], "role": candidate["role"], "required": True}
|
|
48
|
+
if choice not in value:
|
|
49
|
+
value.append(choice)
|
|
50
|
+
undecided = (not candidate.get("repo_id") or candidate.get("role") == "unknown"
|
|
51
|
+
or candidate.get("activation", "active") != "active" or "conditional" in candidate)
|
|
52
|
+
editable |= undecided
|
|
53
|
+
blocked |= not undecided and candidate.get("resolution", {}).get("status") != "pinned"
|
|
54
|
+
else:
|
|
55
|
+
value = draft.get("multimodal", {}).get("forward_kwargs", {})
|
|
56
|
+
question = {"path": name, "value": value, "reason": fields[name].get("reason", name)}
|
|
57
|
+
if name == "dependencies" and (not editable or blocked):
|
|
58
|
+
# An identified dependency with a failed lookup/file selection
|
|
59
|
+
# needs repair, not permission to silently omit that dependency.
|
|
60
|
+
question["read_only"] = True
|
|
61
|
+
questions.append(question)
|
|
62
|
+
else:
|
|
63
|
+
# Arbitrary source/control-flow failures cannot be fixed by accepting
|
|
64
|
+
# a checkbox. They require an explicit adapter/declaration.
|
|
65
|
+
questions.append({"path": name, "value": None, "reason": fields[name].get("reason", name), "read_only": True})
|
|
66
|
+
return questions
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def apply_review(task_info, answers: dict, *, resolve_repository=None):
|
|
70
|
+
"""Return a new task; failed/partial decisions leave the original untouched."""
|
|
71
|
+
from acprof.host.task_support import require_task_support
|
|
72
|
+
from acprof.model_candidates import apply_model_candidate, discover_model_candidates
|
|
73
|
+
|
|
74
|
+
questions = review_questions(task_info)
|
|
75
|
+
if any(item.get("read_only") for item in questions):
|
|
76
|
+
raise ValueError("source or selection gaps require an explicit model spec/adapter")
|
|
77
|
+
expected = {item["path"] for item in questions}
|
|
78
|
+
if set(answers) != expected:
|
|
79
|
+
raise ValueError("answers must cover exactly the unresolved fields")
|
|
80
|
+
task = copy.deepcopy(task_info)
|
|
81
|
+
if set(answers) == {"pipeline_task"}:
|
|
82
|
+
from acprof.host.detect import dependency_metadata, read_model_source
|
|
83
|
+
from acprof.model_contract import apply_model_contract
|
|
84
|
+
if answers["pipeline_task"] not in questions[0].get("options", []):
|
|
85
|
+
raise ValueError("select a declared Pipeline")
|
|
86
|
+
previous = task.model_resolution["contract"]
|
|
87
|
+
task.model_resolution = apply_model_candidate(task, discover_model_candidates(task))
|
|
88
|
+
apply_model_contract(task, lambda name: read_model_source(task.model_id, name, task.model_revision),
|
|
89
|
+
resolve_repository=resolve_repository or dependency_metadata, selected_pipeline=answers["pipeline_task"])
|
|
90
|
+
task.model_resolution["contract"]["reviews"] = [*previous.get("reviews", []),
|
|
91
|
+
{"revision": task.model_revision, "answers": answers, "previous_cache_key": previous["cache_key"]}]
|
|
92
|
+
if task.model_resolution["contract"]["status"] == "resolved":
|
|
93
|
+
require_task_support(task)
|
|
94
|
+
return task
|
|
95
|
+
report = task.model_resolution["contract"]
|
|
96
|
+
draft = copy.deepcopy(report["draft_spec"])
|
|
97
|
+
for path, value in answers.items():
|
|
98
|
+
if path == "dependencies":
|
|
99
|
+
from acprof.host.detect import dependency_metadata
|
|
100
|
+
from acprof.model_dependencies import resolve_dependencies
|
|
101
|
+
if not isinstance(value, list) or len(value) > 16 or any(
|
|
102
|
+
not isinstance(item, dict) or set(item) - {"repo_id", "role", "required"}
|
|
103
|
+
or type(item.get("required", True)) is not bool
|
|
104
|
+
or item.get("required", True) and (not isinstance(item.get("repo_id"), str)
|
|
105
|
+
or not isinstance(item.get("role"), str)) for item in value
|
|
106
|
+
):
|
|
107
|
+
raise ValueError("dependency decisions require a bounded list of repo_id/role/required objects")
|
|
108
|
+
candidates: list[dict[str, object]] = []
|
|
109
|
+
for item in value:
|
|
110
|
+
if not item.get("required", True):
|
|
111
|
+
continue
|
|
112
|
+
# Confirming a conditional loader doesn't change the revision
|
|
113
|
+
# its source will request. Conflicts still need a declaration.
|
|
114
|
+
original = [candidate for candidate in report.get("dependency_candidates", [])
|
|
115
|
+
if candidate.get("repo_id") == item["repo_id"] and candidate.get("role") in {item["role"], "unknown"}
|
|
116
|
+
and candidate.get("activation") != "inactive"
|
|
117
|
+
and candidate.get("dependency_kind") != "main_model"] or [{}]
|
|
118
|
+
candidates.extend({**item, "required": "candidate", "source": "user.review",
|
|
119
|
+
"activation": "active", "dependency_kind": "external", "loader": candidate.get("loader"),
|
|
120
|
+
"requested_revision": candidate.get("requested_revision", "main")}
|
|
121
|
+
for candidate in original)
|
|
122
|
+
value, errors = resolve_dependencies(candidates, resolve_repository or dependency_metadata)
|
|
123
|
+
if errors:
|
|
124
|
+
raise ValueError("; ".join(errors))
|
|
125
|
+
report["reviewed_dependency_candidates"] = candidates
|
|
126
|
+
target = draft
|
|
127
|
+
*parts, key = path.split(".")
|
|
128
|
+
for part in parts:
|
|
129
|
+
target = target.setdefault(part, {})
|
|
130
|
+
target[key] = copy.deepcopy(value)
|
|
131
|
+
validate_model_spec(draft)
|
|
132
|
+
# Decisions are resolver inputs. Never clear unresolved fields or force a
|
|
133
|
+
# final status on the previous contract.
|
|
134
|
+
from acprof.host.detect import read_model_source
|
|
135
|
+
from acprof.model_contract import apply_model_contract
|
|
136
|
+
previous = report
|
|
137
|
+
task.model_spec = draft
|
|
138
|
+
task.model_resolution = apply_model_candidate(task, discover_model_candidates(task))
|
|
139
|
+
def source(name):
|
|
140
|
+
if name not in task.repository_sources:
|
|
141
|
+
task.repository_sources[name] = read_model_source(task.model_id, name, task.model_revision)
|
|
142
|
+
return task.repository_sources[name]
|
|
143
|
+
apply_model_contract(task, source, resolve_repository=resolve_repository,
|
|
144
|
+
selected_pipeline=draft.get("pipeline_task"))
|
|
145
|
+
report = task.model_resolution["contract"]
|
|
146
|
+
report["reviews"] = [*previous.get("reviews", []),
|
|
147
|
+
{"revision": task.model_revision, "answers": copy.deepcopy(answers),
|
|
148
|
+
"previous_cache_key": previous["cache_key"]}]
|
|
149
|
+
for path, value in answers.items():
|
|
150
|
+
report["fields"][path] = {"value": copy.deepcopy(draft["dependencies"] if path == "dependencies" else value),
|
|
151
|
+
"state": "declared", "sources": ["user.review"]}
|
|
152
|
+
report["cache_key"] = content_digest({"resolved": report["cache_key"], "reviews": report["reviews"]})
|
|
153
|
+
if report["status"] == "resolved":
|
|
154
|
+
require_task_support(task)
|
|
155
|
+
return task
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"""Bounded AST facts for Transformers Pipeline methods; no imports or execution."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ast
|
|
5
|
+
import copy
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from functools import lru_cache
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
MAX_SOURCE_BYTES = 256 * 1024
|
|
12
|
+
SOURCE_METADATA_FILES = ("config.json", "tokenizer_config.json", "processor_config.json", "preprocessor_config.json")
|
|
13
|
+
MAX_AST_NODES = 20000
|
|
14
|
+
_MISSING = object()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def parse_source(source: str, filename: str) -> ast.Module:
|
|
18
|
+
if len(source.encode()) > MAX_SOURCE_BYTES:
|
|
19
|
+
raise ValueError(f"{filename}: source exceeds {MAX_SOURCE_BYTES} bytes")
|
|
20
|
+
try:
|
|
21
|
+
tree = ast.parse(source, filename=filename)
|
|
22
|
+
except (SyntaxError, RecursionError, ValueError) as exc:
|
|
23
|
+
raise ValueError(f"{filename}: cannot parse Python source: {exc}") from exc
|
|
24
|
+
if sum(1 for _ in ast.walk(tree)) > MAX_AST_NODES:
|
|
25
|
+
raise ValueError(f"{filename}: AST exceeds {MAX_AST_NODES} nodes")
|
|
26
|
+
return tree
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def top_level_bound_names(tree: ast.Module) -> set[str]:
|
|
30
|
+
"""Return names conservatively proven to remain bound by module execution."""
|
|
31
|
+
bound: set[str] = set()
|
|
32
|
+
for statement in tree.body:
|
|
33
|
+
if isinstance(statement, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
34
|
+
bound.add(statement.name)
|
|
35
|
+
elif isinstance(statement, ast.Assign):
|
|
36
|
+
for target in statement.targets:
|
|
37
|
+
if isinstance(target, ast.Name):
|
|
38
|
+
bound.add(target.id)
|
|
39
|
+
elif isinstance(statement, ast.AnnAssign) and statement.value is not None:
|
|
40
|
+
if isinstance(statement.target, ast.Name):
|
|
41
|
+
bound.add(statement.target.id)
|
|
42
|
+
elif isinstance(statement, ast.Import):
|
|
43
|
+
for alias in statement.names:
|
|
44
|
+
bound.add(alias.asname or alias.name.split(".")[0])
|
|
45
|
+
elif isinstance(statement, ast.ImportFrom):
|
|
46
|
+
# A bare relative from-list cannot prove its own package export.
|
|
47
|
+
if statement.level and not statement.module:
|
|
48
|
+
continue
|
|
49
|
+
for alias in statement.names:
|
|
50
|
+
if alias.name != "*":
|
|
51
|
+
bound.add(alias.asname or alias.name)
|
|
52
|
+
elif isinstance(statement, ast.Delete):
|
|
53
|
+
for target in statement.targets:
|
|
54
|
+
if isinstance(target, ast.Name):
|
|
55
|
+
bound.discard(target.id)
|
|
56
|
+
return bound
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _literal(node: ast.AST | None) -> Any:
|
|
60
|
+
if node is None:
|
|
61
|
+
return _MISSING
|
|
62
|
+
try:
|
|
63
|
+
value = ast.literal_eval(node)
|
|
64
|
+
json.dumps(value, allow_nan=False)
|
|
65
|
+
return value
|
|
66
|
+
except (ValueError, TypeError, RecursionError):
|
|
67
|
+
return _MISSING
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _name(node: ast.AST | None, name: str) -> bool:
|
|
71
|
+
return isinstance(node, ast.Name) and node.id == name
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _signature(method: ast.FunctionDef) -> dict[str, dict[str, Any]]:
|
|
75
|
+
args = [*method.args.posonlyargs, *method.args.args]
|
|
76
|
+
defaults = [None] * (len(args) - len(method.args.defaults)) + list(method.args.defaults)
|
|
77
|
+
result = {}
|
|
78
|
+
for arg, default in [*zip(args[2:], defaults[2:], strict=True), *zip(method.args.kwonlyargs, method.args.kw_defaults, strict=True)]:
|
|
79
|
+
value = _literal(default) if default is not None else _MISSING
|
|
80
|
+
result[arg.arg] = {"required": default is None, "default_known": value is not _MISSING,
|
|
81
|
+
"default": None if value is _MISSING else value,
|
|
82
|
+
"positional_only": arg in method.args.posonlyargs}
|
|
83
|
+
return result
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _input_fields(method: ast.FunctionDef) -> tuple[dict[str, dict[str, Any]], list[str]]:
|
|
87
|
+
args = [*method.args.posonlyargs, *method.args.args]
|
|
88
|
+
if len(args) != 2 or any(item["required"] for item in _signature(method).values()):
|
|
89
|
+
return {}, ["preprocess requires one input mapping"]
|
|
90
|
+
parameter = args[1].arg
|
|
91
|
+
fields: dict[str, dict[str, Any]] = {}
|
|
92
|
+
issues: list[str] = []
|
|
93
|
+
if any(_name(node, parameter) and isinstance(node.ctx, ast.Store) for node in ast.walk(method)
|
|
94
|
+
if isinstance(node, ast.Name)):
|
|
95
|
+
issues.append("preprocess reassigns the input mapping")
|
|
96
|
+
for node in ast.walk(method):
|
|
97
|
+
key, required, default = None, False, _MISSING
|
|
98
|
+
if isinstance(node, ast.Subscript) and _name(node.value, parameter):
|
|
99
|
+
key, required = _literal(node.slice), True
|
|
100
|
+
elif isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and _name(node.func.value, parameter):
|
|
101
|
+
if node.func.attr != "get" or not 1 <= len(node.args) <= 2 or node.keywords:
|
|
102
|
+
issues.append("preprocess uses a dynamic input mapping operation")
|
|
103
|
+
continue
|
|
104
|
+
key = _literal(node.args[0])
|
|
105
|
+
default = _literal(node.args[1]) if len(node.args) == 2 else None
|
|
106
|
+
else:
|
|
107
|
+
continue
|
|
108
|
+
if not isinstance(key, str) or not key.isidentifier():
|
|
109
|
+
issues.append("preprocess uses a dynamic or invalid input key")
|
|
110
|
+
continue
|
|
111
|
+
item = {"required": required, "default_known": default is not _MISSING,
|
|
112
|
+
"default": None if default is _MISSING else default, "line": node.lineno}
|
|
113
|
+
if key in fields:
|
|
114
|
+
previous = fields[key]
|
|
115
|
+
if previous["default"] != item["default"] and previous["default_known"] and item["default_known"]:
|
|
116
|
+
issues.append(f"preprocess has conflicting defaults for {key}")
|
|
117
|
+
item["required"] = previous["required"] or required
|
|
118
|
+
fields[key] = item
|
|
119
|
+
return fields, issues
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _assignments(method: ast.FunctionDef) -> dict[str, ast.expr]:
|
|
123
|
+
"""Only unique, straight-line assignments can supply literal aliases."""
|
|
124
|
+
assignments: dict[str, ast.expr] = {}
|
|
125
|
+
writes: dict[str, int] = {}
|
|
126
|
+
for node in ast.walk(method):
|
|
127
|
+
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store):
|
|
128
|
+
writes[node.id] = writes.get(node.id, 0) + 1
|
|
129
|
+
for statement in method.body:
|
|
130
|
+
if isinstance(statement, ast.Assign) and len(statement.targets) == 1:
|
|
131
|
+
target = statement.targets[0]
|
|
132
|
+
if isinstance(target, ast.Name) and writes.get(target.id) == 1:
|
|
133
|
+
assignments[target.id] = statement.value
|
|
134
|
+
return assignments
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _sanitized_keys(method: ast.FunctionDef) -> list[str] | None:
|
|
138
|
+
if any(not isinstance(statement, (ast.Assign, ast.Return)) and not (
|
|
139
|
+
isinstance(statement, ast.Expr) and isinstance(statement.value, ast.Constant)
|
|
140
|
+
and isinstance(statement.value.value, str)
|
|
141
|
+
) for statement in method.body):
|
|
142
|
+
return None
|
|
143
|
+
assignments = _assignments(method)
|
|
144
|
+
returns = [node for node in ast.walk(method) if isinstance(node, ast.Return)]
|
|
145
|
+
if len(returns) != 1 or returns[0] not in method.body:
|
|
146
|
+
return None
|
|
147
|
+
result = returns[0].value
|
|
148
|
+
if not isinstance(result, (ast.Tuple, ast.List)) or len(result.elts) != 3:
|
|
149
|
+
return None
|
|
150
|
+
forward: ast.expr | None = result.elts[1]
|
|
151
|
+
if isinstance(forward, ast.Name):
|
|
152
|
+
forward = assignments.get(forward.id)
|
|
153
|
+
if isinstance(forward, ast.Dict) and all(isinstance(_literal(key), str) for key in forward.keys):
|
|
154
|
+
return [_literal(key) for key in forward.keys]
|
|
155
|
+
if not isinstance(forward, ast.DictComp) or len(forward.generators) != 1 or method.args.kwarg is None:
|
|
156
|
+
return None
|
|
157
|
+
generator = forward.generators[0]
|
|
158
|
+
if not isinstance(generator.target, ast.Name) or len(generator.ifs) != 1 or generator.is_async:
|
|
159
|
+
return None
|
|
160
|
+
key, kwargs = generator.target.id, method.args.kwarg.arg
|
|
161
|
+
condition = generator.ifs[0]
|
|
162
|
+
if (not _name(generator.iter, kwargs) or not _name(forward.key, key)
|
|
163
|
+
or not isinstance(forward.value, ast.Subscript) or not _name(forward.value.value, kwargs)
|
|
164
|
+
or not _name(forward.value.slice, key) or not isinstance(condition, ast.Compare)
|
|
165
|
+
or not _name(condition.left, key) or len(condition.ops) != 1 or not isinstance(condition.ops[0], ast.In)):
|
|
166
|
+
return None
|
|
167
|
+
allowed: ast.expr | None = condition.comparators[0]
|
|
168
|
+
if isinstance(allowed, ast.Name):
|
|
169
|
+
allowed = assignments.get(allowed.id)
|
|
170
|
+
keys = _literal(allowed)
|
|
171
|
+
return keys if isinstance(keys, list) and all(isinstance(key, str) for key in keys) else None
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _forward_kwargs(method: ast.FunctionDef, signature: dict) -> dict | None:
|
|
175
|
+
"""Recognize direct generation and one explicit temperature-to-sampling idiom.
|
|
176
|
+
|
|
177
|
+
This is a syntax recognizer, not a Python interpreter. All writes affecting
|
|
178
|
+
the selected parameters must match the recognized straight-line pattern.
|
|
179
|
+
"""
|
|
180
|
+
calls: list[ast.Call] = []
|
|
181
|
+
writes: set[str] = set()
|
|
182
|
+
for node in ast.walk(method):
|
|
183
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == "generate":
|
|
184
|
+
calls.append(node)
|
|
185
|
+
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store):
|
|
186
|
+
writes.add(node.id)
|
|
187
|
+
if len(calls) != 1:
|
|
188
|
+
return None
|
|
189
|
+
call = calls[0]
|
|
190
|
+
parameters = [*method.args.posonlyargs, *method.args.args]
|
|
191
|
+
if len(parameters) < 2 or any(kw.arg is None and not _name(kw.value, parameters[1].arg) for kw in call.keywords):
|
|
192
|
+
return None
|
|
193
|
+
# A conditional/nested generation call cannot prove the executed path.
|
|
194
|
+
if not any((isinstance(stmt, (ast.Assign, ast.AnnAssign, ast.Return)) and stmt.value is call)
|
|
195
|
+
for stmt in method.body):
|
|
196
|
+
return None
|
|
197
|
+
keywords = {item.arg: item.value for item in call.keywords if item.arg is not None}
|
|
198
|
+
if not _name(keywords.get("max_new_tokens"), "max_new_tokens") or "max_new_tokens" not in signature:
|
|
199
|
+
return None
|
|
200
|
+
if "max_new_tokens" in writes:
|
|
201
|
+
return None
|
|
202
|
+
assignments = _assignments(method)
|
|
203
|
+
sample = keywords.get("do_sample")
|
|
204
|
+
kwargs: dict[str, Any] = {"max_new_tokens": "$max_new_tokens"}
|
|
205
|
+
if _name(sample, "do_sample") and "do_sample" in signature and "do_sample" not in writes:
|
|
206
|
+
kwargs["do_sample"] = False
|
|
207
|
+
elif "temperature" in signature and _name(sample, "do_sample"):
|
|
208
|
+
normalized = assignments.get("temperature")
|
|
209
|
+
condition = assignments.get("do_sample")
|
|
210
|
+
if (not isinstance(normalized, ast.BoolOp) or not isinstance(normalized.op, ast.Or)
|
|
211
|
+
or len(normalized.values) != 2 or not _name(normalized.values[0], "temperature")
|
|
212
|
+
or _literal(normalized.values[1]) is not None
|
|
213
|
+
or not isinstance(condition, ast.Compare) or not _name(condition.left, "temperature")
|
|
214
|
+
or len(condition.ops) != 1 or not isinstance(condition.ops[0], ast.IsNot)
|
|
215
|
+
or _literal(condition.comparators[0]) is not None
|
|
216
|
+
or not normalized.lineno < condition.lineno < call.lineno
|
|
217
|
+
or not _name(keywords.get("temperature"), "temperature")):
|
|
218
|
+
return None
|
|
219
|
+
kwargs["temperature"] = 0
|
|
220
|
+
else:
|
|
221
|
+
return None
|
|
222
|
+
if any(item["positional_only"] or (item["required"] and name not in kwargs)
|
|
223
|
+
for name, item in signature.items()):
|
|
224
|
+
return None
|
|
225
|
+
return kwargs
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@lru_cache(maxsize=64)
|
|
229
|
+
def _analyze_pipeline(source: str, filename: str, class_name: str) -> dict:
|
|
230
|
+
tree = parse_source(source, filename)
|
|
231
|
+
classes: list[ast.ClassDef] = []
|
|
232
|
+
for node in tree.body:
|
|
233
|
+
if isinstance(node, ast.ClassDef) and node.name == class_name:
|
|
234
|
+
classes.append(node)
|
|
235
|
+
if len(classes) != 1 or classes[0].decorator_list:
|
|
236
|
+
raise ValueError(f"{filename}: pipeline class {class_name} is absent, duplicated or decorated")
|
|
237
|
+
methods = {node.name: node for node in classes[0].body if isinstance(node, ast.FunctionDef)}
|
|
238
|
+
required = {"preprocess", "_forward", "postprocess", "_sanitize_parameters"}
|
|
239
|
+
if not required <= methods.keys() or any(methods[name].decorator_list for name in required):
|
|
240
|
+
raise ValueError(f"{filename}: pipeline methods must be defined locally without decorators")
|
|
241
|
+
fields, issues = _input_fields(methods["preprocess"])
|
|
242
|
+
for method_name in required:
|
|
243
|
+
for scanned in ast.walk(methods[method_name]):
|
|
244
|
+
if isinstance(scanned, ast.Call) and isinstance(scanned.func, ast.Name) and scanned.func.id in {"eval", "exec", "getattr"}:
|
|
245
|
+
issues.append(f"{method_name} uses unsupported dynamic operation {scanned.func.id}")
|
|
246
|
+
signature = _signature(methods["_forward"])
|
|
247
|
+
sanitized = _sanitized_keys(methods["_sanitize_parameters"])
|
|
248
|
+
kwargs = _forward_kwargs(methods["_forward"], signature)
|
|
249
|
+
if sanitized is None:
|
|
250
|
+
issues.append("_sanitize_parameters forward keys are unresolved")
|
|
251
|
+
if kwargs is None:
|
|
252
|
+
issues.append("_forward bounded deterministic generation is unresolved")
|
|
253
|
+
elif sanitized is not None and not set(kwargs) <= set(sanitized):
|
|
254
|
+
issues.append("_sanitize_parameters conflicts with _forward generation parameters")
|
|
255
|
+
kwargs = None
|
|
256
|
+
registrations = []
|
|
257
|
+
for scan_node in ast.walk(tree):
|
|
258
|
+
if isinstance(scan_node, ast.Call) and isinstance(scan_node.func, ast.Attribute) and scan_node.func.attr == "register_pipeline":
|
|
259
|
+
if scan_node.args and any(kw.arg == "pipeline_class" and _name(kw.value, class_name) for kw in scan_node.keywords):
|
|
260
|
+
name = _literal(scan_node.args[0])
|
|
261
|
+
if isinstance(name, str):
|
|
262
|
+
registrations.append(name)
|
|
263
|
+
return {"inputs": fields, "signature": signature, "sanitized_keys": sanitized,
|
|
264
|
+
"forward_kwargs": kwargs, "issues": issues, "registrations": registrations,
|
|
265
|
+
"methods": {name: methods[name].lineno for name in sorted(required)}}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def analyze_pipeline(source: str, filename: str, class_name: str) -> dict:
|
|
269
|
+
# Callers cannot corrupt the process-local content-addressed analysis cache.
|
|
270
|
+
return copy.deepcopy(_analyze_pipeline(source, filename, class_name))
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def dependency_candidates(source: str, filename: str, config: dict, model_id: str) -> list[dict]:
|
|
274
|
+
from acprof.model_dependency_flow import analyze_dependencies
|
|
275
|
+
return analyze_dependencies({filename: source}, config, model_id)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def model_card_examples(text: str) -> list[dict]:
|
|
279
|
+
"""Supplementary literal call keys; examples never establish executable types."""
|
|
280
|
+
result = []
|
|
281
|
+
for block in re.finditer(r"```(?:python|py)\s*\n(.*?)```", text, re.DOTALL):
|
|
282
|
+
try:
|
|
283
|
+
tree = parse_source(block.group(1), "README.md")
|
|
284
|
+
except ValueError:
|
|
285
|
+
continue
|
|
286
|
+
pipelines: set[str] = set()
|
|
287
|
+
for statement in tree.body:
|
|
288
|
+
if (isinstance(statement, ast.Assign) and isinstance(statement.value, ast.Call)
|
|
289
|
+
and ast.unparse(statement.value.func).rsplit(".", 1)[-1] == "pipeline"):
|
|
290
|
+
pipelines.update(target.id for target in statement.targets if isinstance(target, ast.Name))
|
|
291
|
+
for node in ast.walk(tree):
|
|
292
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id in pipelines:
|
|
293
|
+
payload = node.args[0] if node.args else None
|
|
294
|
+
if isinstance(payload, ast.Dict):
|
|
295
|
+
keys = [_literal(key) for key in payload.keys]
|
|
296
|
+
if all(isinstance(key, str) for key in keys):
|
|
297
|
+
result.append({"inputs": keys, "kwargs": [kw.arg for kw in node.keywords if kw.arg],
|
|
298
|
+
"line": text[:block.start(1)].count("\n") + node.lineno})
|
|
299
|
+
return result
|