kiapi 0.1.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.
- kiapi/__init__.py +3 -0
- kiapi/__main__.py +4 -0
- kiapi/api/__init__.py +26 -0
- kiapi/api/_constants/require_auth.py +14 -0
- kiapi/api/_helpers/build_job_responses.py +73 -0
- kiapi/api/_helpers/build_openapi.py +55 -0
- kiapi/api/_helpers/build_train_responses.py +21 -0
- kiapi/api/_helpers/get_accept.py +20 -0
- kiapi/api/_helpers/get_ctx.py +7 -0
- kiapi/api/_helpers/get_worker.py +7 -0
- kiapi/api/_helpers/register_capability_endpoints.py +70 -0
- kiapi/api/_helpers/submit_and_maybe_wait.py +113 -0
- kiapi/api/_settings.py +50 -0
- kiapi/api/_views/async_job_response.py +21 -0
- kiapi/api/_views/capability_model_spec.py +49 -0
- kiapi/api/app.py +150 -0
- kiapi/api/audio/acestep/_views/extract_response.py +57 -0
- kiapi/api/audio/acestep/_views/track_response.py +57 -0
- kiapi/api/audio/acestep/router.py +190 -0
- kiapi/api/audio/audiogen/_views/audio_response.py +46 -0
- kiapi/api/audio/audiogen/router.py +77 -0
- kiapi/api/chat/_views/chat_completion_response.py +71 -0
- kiapi/api/chat/router.py +253 -0
- kiapi/api/embedding/_views/embedding_response.py +35 -0
- kiapi/api/embedding/router.py +82 -0
- kiapi/api/files/_operations/get_file.py +14 -0
- kiapi/api/files/_operations/get_file_id.py +18 -0
- kiapi/api/files/_views/file_delete_response.py +14 -0
- kiapi/api/files/_views/file_list_response.py +15 -0
- kiapi/api/files/router.py +105 -0
- kiapi/api/health/_views/health_response.py +26 -0
- kiapi/api/health/router.py +28 -0
- kiapi/api/image/depthpro/_views/estimate_response.py +70 -0
- kiapi/api/image/depthpro/router.py +81 -0
- kiapi/api/image/ernie/_views/image_response.py +50 -0
- kiapi/api/image/ernie/router.py +181 -0
- kiapi/api/image/flux2/_views/image_response.py +53 -0
- kiapi/api/image/flux2/router.py +197 -0
- kiapi/api/image/ideogram4/_views/image_response.py +55 -0
- kiapi/api/image/ideogram4/router.py +87 -0
- kiapi/api/image/qwen/_views/image_response.py +47 -0
- kiapi/api/image/qwen/router.py +141 -0
- kiapi/api/image/seedvr2/_views/image_response.py +50 -0
- kiapi/api/image/seedvr2/router.py +83 -0
- kiapi/api/image/zimage/_views/image_response.py +49 -0
- kiapi/api/image/zimage/router.py +131 -0
- kiapi/api/jobs/_operations/get_job_id.py +18 -0
- kiapi/api/jobs/_views/job_delete_response.py +19 -0
- kiapi/api/jobs/_views/job_list_response.py +15 -0
- kiapi/api/jobs/router.py +62 -0
- kiapi/api/models/_schemas/openai_model_spec.py +26 -0
- kiapi/api/models/_views/model_list_response.py +15 -0
- kiapi/api/models/router.py +29 -0
- kiapi/api/video/ltx2/_views/__init__.py +1 -0
- kiapi/api/video/ltx2/_views/video_response.py +59 -0
- kiapi/api/video/ltx2/router.py +89 -0
- kiapi/api/web/_views/__init__.py +7 -0
- kiapi/api/web/_views/fetch_api_request.py +26 -0
- kiapi/api/web/_views/fetch_error_response.py +25 -0
- kiapi/api/web/router.py +302 -0
- kiapi/capabilities/__init__.py +24 -0
- kiapi/capabilities/_exceptions/CapabilityError.py +2 -0
- kiapi/capabilities/_exceptions/ValidationError.py +2 -0
- kiapi/capabilities/_helpers/attach_mflux_progress.py +50 -0
- kiapi/capabilities/_helpers/get_file_path.py +20 -0
- kiapi/capabilities/_helpers/resolve_file_ref.py +16 -0
- kiapi/capabilities/acestep/README.ja.md +174 -0
- kiapi/capabilities/acestep/README.md +167 -0
- kiapi/capabilities/acestep/__init__.py +37 -0
- kiapi/capabilities/acestep/_constants/description.py +122 -0
- kiapi/capabilities/acestep/_exceptions/ace_step_engine_error.py +2 -0
- kiapi/capabilities/acestep/_helpers/register.py +96 -0
- kiapi/capabilities/acestep/_models/acestep.py +105 -0
- kiapi/capabilities/acestep/_operations/handle_cover.py +23 -0
- kiapi/capabilities/acestep/_operations/handle_extract.py +38 -0
- kiapi/capabilities/acestep/_operations/handle_generate.py +18 -0
- kiapi/capabilities/acestep/_operations/handle_repaint.py +25 -0
- kiapi/capabilities/acestep/_operations/resolve_ace_step_paths.py +30 -0
- kiapi/capabilities/acestep/_operations/resolve_cover_params.py +21 -0
- kiapi/capabilities/acestep/_operations/resolve_engine.py +10 -0
- kiapi/capabilities/acestep/_operations/resolve_extract_params.py +24 -0
- kiapi/capabilities/acestep/_operations/resolve_generate_params.py +18 -0
- kiapi/capabilities/acestep/_operations/resolve_repaint_params.py +22 -0
- kiapi/capabilities/acestep/_schemas/ace_step_paths.py +29 -0
- kiapi/capabilities/acestep/_services/ace_step_engine.py +143 -0
- kiapi/capabilities/acestep/_settings.py +82 -0
- kiapi/capabilities/acestep/_views/ace_step_base.py +61 -0
- kiapi/capabilities/acestep/_views/cover_params.py +26 -0
- kiapi/capabilities/acestep/_views/cover_request.py +49 -0
- kiapi/capabilities/acestep/_views/extract_params.py +24 -0
- kiapi/capabilities/acestep/_views/extract_request.py +33 -0
- kiapi/capabilities/acestep/_views/generate_params.py +25 -0
- kiapi/capabilities/acestep/_views/generate_request.py +54 -0
- kiapi/capabilities/acestep/_views/repaint_params.py +27 -0
- kiapi/capabilities/acestep/_views/repaint_request.py +51 -0
- kiapi/capabilities/acestep/_views/track_params.py +7 -0
- kiapi/capabilities/acestep/worker_subprocess.py +247 -0
- kiapi/capabilities/audiogen/README.ja.md +49 -0
- kiapi/capabilities/audiogen/README.md +48 -0
- kiapi/capabilities/audiogen/__init__.py +25 -0
- kiapi/capabilities/audiogen/_constants/description.py +60 -0
- kiapi/capabilities/audiogen/_helpers/attach_audiogen_progress.py +27 -0
- kiapi/capabilities/audiogen/_helpers/register.py +42 -0
- kiapi/capabilities/audiogen/_helpers/validate_generate.py +14 -0
- kiapi/capabilities/audiogen/_models/audiogen.py +98 -0
- kiapi/capabilities/audiogen/_operations/handle_generate.py +27 -0
- kiapi/capabilities/audiogen/_operations/resolve_generate_params.py +25 -0
- kiapi/capabilities/audiogen/_settings.py +34 -0
- kiapi/capabilities/audiogen/_views/generate_params.py +14 -0
- kiapi/capabilities/audiogen/_views/generate_request.py +96 -0
- kiapi/capabilities/chat/README.ja.md +822 -0
- kiapi/capabilities/chat/README.md +806 -0
- kiapi/capabilities/chat/__init__.py +25 -0
- kiapi/capabilities/chat/_constants/description.py +163 -0
- kiapi/capabilities/chat/_helpers/register.py +67 -0
- kiapi/capabilities/chat/_models/qwen3_5.py +183 -0
- kiapi/capabilities/chat/_models/qwen3_omni.py +242 -0
- kiapi/capabilities/chat/_operations/apply_template.py +74 -0
- kiapi/capabilities/chat/_operations/completed_hermes_tool_call_text.py +9 -0
- kiapi/capabilities/chat/_operations/emit_streaming_response.py +297 -0
- kiapi/capabilities/chat/_operations/ensure_streaming_detokenizer_compat.py +49 -0
- kiapi/capabilities/chat/_operations/format_response.py +72 -0
- kiapi/capabilities/chat/_operations/handle_chat.py +25 -0
- kiapi/capabilities/chat/_operations/parse_hermes_tool_calls.py +63 -0
- kiapi/capabilities/chat/_operations/parse_json_tool_calls.py +66 -0
- kiapi/capabilities/chat/_operations/parse_messages.py +326 -0
- kiapi/capabilities/chat/_operations/resolve_chat_params.py +50 -0
- kiapi/capabilities/chat/_operations/stream_text_from_tokens.py +32 -0
- kiapi/capabilities/chat/_operations/strip_tool_calls.py +15 -0
- kiapi/capabilities/chat/_settings.py +74 -0
- kiapi/capabilities/chat/_utils/apply_parallel_tool_call_policy.py +17 -0
- kiapi/capabilities/chat/_utils/apply_seed.py +8 -0
- kiapi/capabilities/chat/_utils/load_audio_mono.py +31 -0
- kiapi/capabilities/chat/_utils/load_mlx_vlm.py +12 -0
- kiapi/capabilities/chat/_utils/warmup_params.py +26 -0
- kiapi/capabilities/chat/_views/chat_params.py +34 -0
- kiapi/capabilities/chat/_views/chat_request.py +153 -0
- kiapi/capabilities/depthpro/README.ja.md +131 -0
- kiapi/capabilities/depthpro/README.md +124 -0
- kiapi/capabilities/depthpro/__init__.py +23 -0
- kiapi/capabilities/depthpro/_constants/description.py +39 -0
- kiapi/capabilities/depthpro/_helpers/register.py +46 -0
- kiapi/capabilities/depthpro/_helpers/validate_estimate.py +32 -0
- kiapi/capabilities/depthpro/_models/depthpro.py +144 -0
- kiapi/capabilities/depthpro/_operations/handle_estimate.py +50 -0
- kiapi/capabilities/depthpro/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/depthpro/_operations/resolve_estimate_params.py +24 -0
- kiapi/capabilities/depthpro/_settings.py +46 -0
- kiapi/capabilities/depthpro/_views/estimate_params.py +21 -0
- kiapi/capabilities/depthpro/_views/estimate_request.py +63 -0
- kiapi/capabilities/embedding/README.ja.md +137 -0
- kiapi/capabilities/embedding/README.md +128 -0
- kiapi/capabilities/embedding/__init__.py +24 -0
- kiapi/capabilities/embedding/_constants/description.py +47 -0
- kiapi/capabilities/embedding/_helpers/register.py +66 -0
- kiapi/capabilities/embedding/_models/qwen3_text.py +53 -0
- kiapi/capabilities/embedding/_models/qwen3_vl.py +97 -0
- kiapi/capabilities/embedding/_operations/format_response.py +24 -0
- kiapi/capabilities/embedding/_operations/handle_embed.py +24 -0
- kiapi/capabilities/embedding/_operations/parse_inputs.py +108 -0
- kiapi/capabilities/embedding/_operations/resolve_embed_params.py +18 -0
- kiapi/capabilities/embedding/_settings.py +27 -0
- kiapi/capabilities/embedding/_utils/to_vector.py +20 -0
- kiapi/capabilities/embedding/_views/embed_params.py +17 -0
- kiapi/capabilities/embedding/_views/embed_request.py +39 -0
- kiapi/capabilities/ernie/README.ja.md +242 -0
- kiapi/capabilities/ernie/README.md +223 -0
- kiapi/capabilities/ernie/__init__.py +34 -0
- kiapi/capabilities/ernie/_constants/description.py +71 -0
- kiapi/capabilities/ernie/_helpers/register.py +60 -0
- kiapi/capabilities/ernie/_helpers/validate_edit.py +19 -0
- kiapi/capabilities/ernie/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/ernie/_models/ernie.py +356 -0
- kiapi/capabilities/ernie/_operations/handle_edit.py +39 -0
- kiapi/capabilities/ernie/_operations/handle_generate.py +38 -0
- kiapi/capabilities/ernie/_operations/handle_train.py +77 -0
- kiapi/capabilities/ernie/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/ernie/_operations/resolve_edit_params.py +44 -0
- kiapi/capabilities/ernie/_operations/resolve_generate_params.py +40 -0
- kiapi/capabilities/ernie/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/ernie/_operations/resolve_train_params.py +43 -0
- kiapi/capabilities/ernie/_operations/validate_common.py +33 -0
- kiapi/capabilities/ernie/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/ernie/_settings.py +151 -0
- kiapi/capabilities/ernie/_views/edit_params.py +36 -0
- kiapi/capabilities/ernie/_views/edit_request.py +142 -0
- kiapi/capabilities/ernie/_views/generate_params.py +32 -0
- kiapi/capabilities/ernie/_views/generate_request.py +127 -0
- kiapi/capabilities/ernie/_views/train_params.py +28 -0
- kiapi/capabilities/ernie/_views/train_request.py +96 -0
- kiapi/capabilities/flux2/README.ja.md +260 -0
- kiapi/capabilities/flux2/README.md +241 -0
- kiapi/capabilities/flux2/__init__.py +36 -0
- kiapi/capabilities/flux2/_constants/description.py +81 -0
- kiapi/capabilities/flux2/_helpers/register.py +98 -0
- kiapi/capabilities/flux2/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/flux2/_helpers/validate_generate.py +8 -0
- kiapi/capabilities/flux2/_models/flux2.py +396 -0
- kiapi/capabilities/flux2/_operations/handle_edit.py +44 -0
- kiapi/capabilities/flux2/_operations/handle_generate.py +46 -0
- kiapi/capabilities/flux2/_operations/handle_train.py +105 -0
- kiapi/capabilities/flux2/_operations/is_quantize_override.py +16 -0
- kiapi/capabilities/flux2/_operations/resolve_edit_params.py +43 -0
- kiapi/capabilities/flux2/_operations/resolve_generate_params.py +44 -0
- kiapi/capabilities/flux2/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/flux2/_operations/resolve_train_params.py +42 -0
- kiapi/capabilities/flux2/_operations/role_spec.py +13 -0
- kiapi/capabilities/flux2/_operations/split_repo.py +11 -0
- kiapi/capabilities/flux2/_operations/validate_common.py +35 -0
- kiapi/capabilities/flux2/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/flux2/_settings.py +181 -0
- kiapi/capabilities/flux2/_views/edit_params.py +36 -0
- kiapi/capabilities/flux2/_views/edit_request.py +145 -0
- kiapi/capabilities/flux2/_views/generate_params.py +36 -0
- kiapi/capabilities/flux2/_views/generate_request.py +150 -0
- kiapi/capabilities/flux2/_views/train_params.py +32 -0
- kiapi/capabilities/flux2/_views/train_request.py +102 -0
- kiapi/capabilities/ideogram4/README.ja.md +230 -0
- kiapi/capabilities/ideogram4/README.md +219 -0
- kiapi/capabilities/ideogram4/__init__.py +24 -0
- kiapi/capabilities/ideogram4/_constants/description.py +65 -0
- kiapi/capabilities/ideogram4/_helpers/register.py +44 -0
- kiapi/capabilities/ideogram4/_helpers/validate_generate.py +31 -0
- kiapi/capabilities/ideogram4/_models/ideogram4.py +120 -0
- kiapi/capabilities/ideogram4/_operations/handle_generate.py +30 -0
- kiapi/capabilities/ideogram4/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/ideogram4/_operations/resolve_generate_params.py +30 -0
- kiapi/capabilities/ideogram4/_settings.py +89 -0
- kiapi/capabilities/ideogram4/_views/generate_params.py +27 -0
- kiapi/capabilities/ideogram4/_views/generate_request.py +118 -0
- kiapi/capabilities/ltx2/README.ja.md +287 -0
- kiapi/capabilities/ltx2/README.md +274 -0
- kiapi/capabilities/ltx2/__init__.py +26 -0
- kiapi/capabilities/ltx2/_constants/description.py +81 -0
- kiapi/capabilities/ltx2/_helpers/register.py +58 -0
- kiapi/capabilities/ltx2/_helpers/validate_generate.py +42 -0
- kiapi/capabilities/ltx2/_models/ltx2.py +106 -0
- kiapi/capabilities/ltx2/_operations/detect_mode.py +19 -0
- kiapi/capabilities/ltx2/_operations/handle_generate.py +52 -0
- kiapi/capabilities/ltx2/_operations/resolve_generate_params.py +31 -0
- kiapi/capabilities/ltx2/_settings.py +93 -0
- kiapi/capabilities/ltx2/_views/generate_params.py +34 -0
- kiapi/capabilities/ltx2/_views/generate_request.py +151 -0
- kiapi/capabilities/qwen/README.ja.md +251 -0
- kiapi/capabilities/qwen/README.md +235 -0
- kiapi/capabilities/qwen/__init__.py +30 -0
- kiapi/capabilities/qwen/_constants/description.py +53 -0
- kiapi/capabilities/qwen/_helpers/register.py +60 -0
- kiapi/capabilities/qwen/_helpers/validate_edit.py +12 -0
- kiapi/capabilities/qwen/_helpers/validate_generate.py +12 -0
- kiapi/capabilities/qwen/_models/qwen.py +224 -0
- kiapi/capabilities/qwen/_operations/handle_edit.py +44 -0
- kiapi/capabilities/qwen/_operations/handle_generate.py +46 -0
- kiapi/capabilities/qwen/_operations/is_quantize_override.py +15 -0
- kiapi/capabilities/qwen/_operations/resolve_edit_params.py +35 -0
- kiapi/capabilities/qwen/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/qwen/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/qwen/_operations/validate_common.py +32 -0
- kiapi/capabilities/qwen/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/qwen/_settings.py +107 -0
- kiapi/capabilities/qwen/_views/edit_params.py +36 -0
- kiapi/capabilities/qwen/_views/edit_request.py +138 -0
- kiapi/capabilities/qwen/_views/generate_params.py +37 -0
- kiapi/capabilities/qwen/_views/generate_request.py +149 -0
- kiapi/capabilities/seedvr2/README.ja.md +234 -0
- kiapi/capabilities/seedvr2/README.md +219 -0
- kiapi/capabilities/seedvr2/__init__.py +24 -0
- kiapi/capabilities/seedvr2/_constants/description.py +46 -0
- kiapi/capabilities/seedvr2/_helpers/register.py +60 -0
- kiapi/capabilities/seedvr2/_helpers/validate_upscale.py +52 -0
- kiapi/capabilities/seedvr2/_models/seedvr2.py +140 -0
- kiapi/capabilities/seedvr2/_operations/handle_upscale.py +42 -0
- kiapi/capabilities/seedvr2/_operations/is_quantize_override.py +12 -0
- kiapi/capabilities/seedvr2/_operations/resolve_upscale_params.py +30 -0
- kiapi/capabilities/seedvr2/_settings.py +74 -0
- kiapi/capabilities/seedvr2/_views/upscale_params.py +27 -0
- kiapi/capabilities/seedvr2/_views/upscale_request.py +94 -0
- kiapi/capabilities/web/README.ja.md +187 -0
- kiapi/capabilities/web/README.md +171 -0
- kiapi/capabilities/web/__init__.py +30 -0
- kiapi/capabilities/web/_constants/description.py +38 -0
- kiapi/capabilities/web/_exceptions/FetchError.py +24 -0
- kiapi/capabilities/web/_exceptions/SearchBackendError.py +11 -0
- kiapi/capabilities/web/_helpers/register.py +59 -0
- kiapi/capabilities/web/_models/crawl4ai.py +32 -0
- kiapi/capabilities/web/_models/searxng.py +44 -0
- kiapi/capabilities/web/_operations/handle_fetch.py +145 -0
- kiapi/capabilities/web/_operations/handle_search.py +56 -0
- kiapi/capabilities/web/_operations/resolve_fetch_params.py +19 -0
- kiapi/capabilities/web/_operations/resolve_search_params.py +34 -0
- kiapi/capabilities/web/_operations/resolve_searxng_config_dir.py +21 -0
- kiapi/capabilities/web/_services/__init__.py +1 -0
- kiapi/capabilities/web/_services/web_backend_process.py +144 -0
- kiapi/capabilities/web/_settings.py +138 -0
- kiapi/capabilities/web/_views/fetch_params.py +27 -0
- kiapi/capabilities/web/_views/fetch_request.py +29 -0
- kiapi/capabilities/web/_views/fetch_result.py +20 -0
- kiapi/capabilities/web/_views/search_params.py +43 -0
- kiapi/capabilities/web/_views/search_request.py +93 -0
- kiapi/capabilities/web/_views/search_response.py +49 -0
- kiapi/capabilities/web/resources/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/__init__.py +0 -0
- kiapi/capabilities/web/resources/searxng/settings.yml +11 -0
- kiapi/capabilities/zimage/README.ja.md +249 -0
- kiapi/capabilities/zimage/README.md +231 -0
- kiapi/capabilities/zimage/__init__.py +34 -0
- kiapi/capabilities/zimage/_constants/description.py +73 -0
- kiapi/capabilities/zimage/_helpers/register.py +62 -0
- kiapi/capabilities/zimage/_helpers/validate_generate.py +37 -0
- kiapi/capabilities/zimage/_models/zimage.py +278 -0
- kiapi/capabilities/zimage/_operations/handle_generate.py +38 -0
- kiapi/capabilities/zimage/_operations/handle_train.py +78 -0
- kiapi/capabilities/zimage/_operations/is_quantize_override.py +11 -0
- kiapi/capabilities/zimage/_operations/resolve_generate_params.py +39 -0
- kiapi/capabilities/zimage/_operations/resolve_lora_params.py +23 -0
- kiapi/capabilities/zimage/_operations/resolve_train_params.py +38 -0
- kiapi/capabilities/zimage/_schemas/lora_ref.py +27 -0
- kiapi/capabilities/zimage/_settings.py +166 -0
- kiapi/capabilities/zimage/_views/generate_params.py +23 -0
- kiapi/capabilities/zimage/_views/generate_request.py +127 -0
- kiapi/capabilities/zimage/_views/train_params.py +22 -0
- kiapi/capabilities/zimage/_views/train_request.py +101 -0
- kiapi/cli/__init__.py +11 -0
- kiapi/cli/_helpers/dedupe_resources.py +12 -0
- kiapi/cli/_helpers/register_all_capabilities.py +36 -0
- kiapi/cli/_helpers/run_resources.py +24 -0
- kiapi/cli/_helpers/select_specs.py +67 -0
- kiapi/cli/activate/_operations/preflight_hf_access.py +129 -0
- kiapi/cli/activate/cli.py +37 -0
- kiapi/cli/check/_helpers/check_audio_acestep_turbo.py +22 -0
- kiapi/cli/check/_helpers/check_audio_acestep_xl_base.py +22 -0
- kiapi/cli/check/_helpers/check_audio_audiogen_medium.py +24 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_6_27b.py +19 -0
- kiapi/cli/check/_helpers/check_chat_chat_qwen3_omni.py +19 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_embedding_8b.py +14 -0
- kiapi/cli/check/_helpers/check_embedding_embedding_qwen3_vl_embedding_2b.py +19 -0
- kiapi/cli/check/_helpers/check_image_depthpro_base.py +21 -0
- kiapi/cli/check/_helpers/check_image_ernie_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_ernie_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_4b.py +23 -0
- kiapi/cli/check/_helpers/check_image_flux2_klein_base_9b.py +23 -0
- kiapi/cli/check/_helpers/check_image_ideogram4_fp8.py +23 -0
- kiapi/cli/check/_helpers/check_image_qwen_edit_2509.py +27 -0
- kiapi/cli/check/_helpers/check_image_qwen_image.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_3b.py +23 -0
- kiapi/cli/check/_helpers/check_image_seedvr2_7b.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_base.py +23 -0
- kiapi/cli/check/_helpers/check_image_zimage_turbo.py +23 -0
- kiapi/cli/check/_helpers/check_video_ltx2_distilled.py +26 -0
- kiapi/cli/check/_helpers/check_web_web_fetch.py +14 -0
- kiapi/cli/check/_helpers/check_web_web_search.py +14 -0
- kiapi/cli/check/_operations/build_check_result.py +20 -0
- kiapi/cli/check/_operations/check_context.py +10 -0
- kiapi/cli/check/_operations/create_sample_image.py +46 -0
- kiapi/cli/check/_schemas/check_result.py +12 -0
- kiapi/cli/check/cli.py +89 -0
- kiapi/cli/cli.py +29 -0
- kiapi/cli/config/cli.py +17 -0
- kiapi/cli/config/edit/cli.py +32 -0
- kiapi/cli/config/init/cli.py +33 -0
- kiapi/cli/config/show/cli.py +13 -0
- kiapi/cli/config/template/cli.py +36 -0
- kiapi/cli/deactivate/cli.py +49 -0
- kiapi/cli/run/asgi.py +16 -0
- kiapi/cli/run/cli.py +59 -0
- kiapi/cli/service/__init__.py +5 -0
- kiapi/cli/service/_services/service_manager.py +107 -0
- kiapi/cli/service/cli.py +19 -0
- kiapi/cli/service/install/cli.py +17 -0
- kiapi/cli/service/start/cli.py +22 -0
- kiapi/cli/service/status/cli.py +81 -0
- kiapi/cli/service/stop/cli.py +19 -0
- kiapi/cli/service/uninstall/cli.py +16 -0
- kiapi/cli/status/cli.py +226 -0
- kiapi/core/app/__init__.py +16 -0
- kiapi/core/app/_schemas/app_context.py +28 -0
- kiapi/core/app/_services/user_directory.py +59 -0
- kiapi/core/app/_settings.py +46 -0
- kiapi/core/capability/__init__.py +11 -0
- kiapi/core/capability/_schemas/capability_spec.py +17 -0
- kiapi/core/capability/_services/capability_spec_registry.py +21 -0
- kiapi/core/config/__init__.py +11 -0
- kiapi/core/config/_exceptions/user_config_error.py +2 -0
- kiapi/core/config/_helpers/get_user_settings_path.py +7 -0
- kiapi/core/config/_helpers/load_user_settings.py +54 -0
- kiapi/core/file/__init__.py +37 -0
- kiapi/core/file/_helpers/create_file_store.py +7 -0
- kiapi/core/file/_helpers/resolve_file_ref.py +90 -0
- kiapi/core/file/_schemas/file_data_url_ref.py +19 -0
- kiapi/core/file/_schemas/file_id_ref.py +16 -0
- kiapi/core/file/_schemas/file_record.py +46 -0
- kiapi/core/file/_schemas/file_url_ref.py +16 -0
- kiapi/core/file/_services/file_store.py +138 -0
- kiapi/core/file/_settings.py +22 -0
- kiapi/core/file/_types/file_id.py +2 -0
- kiapi/core/file/_types/file_ref.py +12 -0
- kiapi/core/file/_views/resolved_file_ref.py +16 -0
- kiapi/core/job/__init__.py +24 -0
- kiapi/core/job/_enums/job_status.py +9 -0
- kiapi/core/job/_helpers/creep_progress.py +123 -0
- kiapi/core/job/_models/job.py +121 -0
- kiapi/core/job/_services/job_store.py +33 -0
- kiapi/core/job/_services/progress_reporter.py +79 -0
- kiapi/core/job/_types/job_id.py +3 -0
- kiapi/core/job/_types/job_result.py +5 -0
- kiapi/core/job/_types/job_type.py +4 -0
- kiapi/core/logging/__init__.py +14 -0
- kiapi/core/logging/_helpers/get_log_level.py +8 -0
- kiapi/core/logging/_helpers/setup_logger.py +14 -0
- kiapi/core/logging/_settings.py +34 -0
- kiapi/core/logging/_types/log_level.py +3 -0
- kiapi/core/memory/__init__.py +21 -0
- kiapi/core/memory/_exceptions/memory_budget_error.py +2 -0
- kiapi/core/memory/_helpers/create_memory_manager.py +17 -0
- kiapi/core/memory/_operations/log_memory_limit.py +29 -0
- kiapi/core/memory/_operations/resolve_effective_memory_limit_gb.py +13 -0
- kiapi/core/memory/_operations/resolve_framework_strategy.py +42 -0
- kiapi/core/memory/_schemas/framework_strategy.py +14 -0
- kiapi/core/memory/_schemas/memory_stats.py +24 -0
- kiapi/core/memory/_schemas/resident_model.py +14 -0
- kiapi/core/memory/_schemas/resident_model_stats.py +49 -0
- kiapi/core/memory/_services/memory_manager.py +257 -0
- kiapi/core/memory/_settings.py +36 -0
- kiapi/core/memory/_types/framework_name.py +4 -0
- kiapi/core/memory/_types/resident_key.py +4 -0
- kiapi/core/model/__init__.py +36 -0
- kiapi/core/model/_exceptions/unknown_model_error.py +2 -0
- kiapi/core/model/_schemas/model_spec.py +145 -0
- kiapi/core/model/_services/model_registry.py +85 -0
- kiapi/core/model/_types/model_alias.py +2 -0
- kiapi/core/model/_types/model_domain.py +6 -0
- kiapi/core/model/_types/model_family.py +5 -0
- kiapi/core/model/_types/model_key.py +8 -0
- kiapi/core/model/_types/model_name.py +4 -0
- kiapi/core/model/_types/model_repo.py +3 -0
- kiapi/core/net/__init__.py +16 -0
- kiapi/core/net/_exceptions/unsafe_url_error.py +7 -0
- kiapi/core/net/_helpers/verify_public_url.py +68 -0
- kiapi/core/net/_settings.py +28 -0
- kiapi/core/setup/__init__.py +25 -0
- kiapi/core/setup/_exceptions/setup_required_error.py +2 -0
- kiapi/core/setup/_schemas/docker_image_resource.py +37 -0
- kiapi/core/setup/_schemas/hf_snapshot_resource.py +50 -0
- kiapi/core/setup/_schemas/local_path_resource.py +43 -0
- kiapi/core/setup/_schemas/python_package_resource.py +58 -0
- kiapi/core/setup/_schemas/python_venv_resource.py +63 -0
- kiapi/core/setup/_schemas/setup_status.py +7 -0
- kiapi/core/setup/_schemas/url_file_resource.py +43 -0
- kiapi/core/setup/_services/setup_manager.py +331 -0
- kiapi/core/setup/_types/setup_resource.py +21 -0
- kiapi/core/setup/_types/setup_target.py +11 -0
- kiapi/core/workdir/__init__.py +8 -0
- kiapi/core/workdir/_helpers/create_work_dir.py +11 -0
- kiapi/core/workdir/_settings.py +21 -0
- kiapi/core/worker/__init__.py +23 -0
- kiapi/core/worker/_helpers/create_worker.py +9 -0
- kiapi/core/worker/_services/worker.py +165 -0
- kiapi/core/worker/_settings.py +36 -0
- kiapi/core/worker/_types/job_thunk.py +6 -0
- kiapi-0.1.0.dist-info/METADATA +337 -0
- kiapi-0.1.0.dist-info/RECORD +465 -0
- kiapi-0.1.0.dist-info/WHEEL +4 -0
- kiapi-0.1.0.dist-info/entry_points.txt +2 -0
- kiapi-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from .._models.job import Job
|
|
5
|
+
from .._types.job_id import JobID
|
|
6
|
+
from .._types.job_type import JobType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class JobStore:
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
self._jobs: dict[JobID, Job] = {}
|
|
12
|
+
self._lock = threading.Lock()
|
|
13
|
+
|
|
14
|
+
def create(self, type: JobType, params: dict[str, Any] | None = None) -> Job:
|
|
15
|
+
job = Job(type=type, params=params or {})
|
|
16
|
+
with self._lock:
|
|
17
|
+
self._jobs[job.id] = job
|
|
18
|
+
return job
|
|
19
|
+
|
|
20
|
+
def get(self, job_id: JobID) -> Job | None:
|
|
21
|
+
with self._lock:
|
|
22
|
+
return self._jobs.get(job_id)
|
|
23
|
+
|
|
24
|
+
def list_all(self) -> list[Job]:
|
|
25
|
+
with self._lock:
|
|
26
|
+
return sorted(self._jobs.values(), key=lambda j: j.created_at, reverse=True)
|
|
27
|
+
|
|
28
|
+
def delete(self, job_id: JobID) -> Job | None:
|
|
29
|
+
"""A running job cannot be interrupted (MLX/generation is not
|
|
30
|
+
preemptible) — deleting it just forgets it once it finishes. Queued jobs
|
|
31
|
+
are effectively canceled."""
|
|
32
|
+
with self._lock:
|
|
33
|
+
return self._jobs.pop(job_id, None)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Ambient progress reporting for the running job.
|
|
2
|
+
|
|
3
|
+
kiapi runs exactly one job at a time on one worker thread (see core/worker), so
|
|
4
|
+
"the progress of the currently running job" is a well-defined ambient rather than
|
|
5
|
+
something every call site must thread through by hand. The worker binds a
|
|
6
|
+
:class:`ProgressReporter` for the job it is about to run; capability code reaches
|
|
7
|
+
it with :meth:`ProgressReporter.current` and calls :meth:`update` / :meth:`step`
|
|
8
|
+
to push coarse progress onto the :class:`Job` (surfaced by /v1/jobs).
|
|
9
|
+
|
|
10
|
+
A reporter bound to no job (the default outside a running job) is a silent no-op,
|
|
11
|
+
so capability code can call ``ProgressReporter.current().update(...)``
|
|
12
|
+
unconditionally. Updates are throttled (time + delta) so a hot denoising loop
|
|
13
|
+
calling ``step`` per iteration stays cheap; the terminal ``1.0`` from
|
|
14
|
+
``Job.mark_succeeded`` is what guarantees a clean final value.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import time
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
from contextvars import ContextVar
|
|
22
|
+
from typing import Self, TypeVar
|
|
23
|
+
|
|
24
|
+
from .._models.job import Job
|
|
25
|
+
|
|
26
|
+
T = TypeVar("T")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ProgressReporter:
|
|
30
|
+
_current: ContextVar[ProgressReporter | None] = ContextVar(
|
|
31
|
+
"kiapi_progress_reporter", default=None
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
job: Job | None = None,
|
|
37
|
+
*,
|
|
38
|
+
min_interval_s: float = 0.5,
|
|
39
|
+
min_delta: float = 0.01,
|
|
40
|
+
) -> None:
|
|
41
|
+
self._job = job
|
|
42
|
+
self._min_interval_s = min_interval_s
|
|
43
|
+
self._min_delta = min_delta
|
|
44
|
+
self._last_at = 0.0
|
|
45
|
+
self._last_fraction = -1.0
|
|
46
|
+
|
|
47
|
+
def update(self, fraction: float, label: str | None = None) -> None:
|
|
48
|
+
if self._job is None:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
now = time.monotonic()
|
|
52
|
+
forced = label is not None or fraction >= 1.0
|
|
53
|
+
|
|
54
|
+
if not forced:
|
|
55
|
+
if now - self._last_at < self._min_interval_s:
|
|
56
|
+
return
|
|
57
|
+
if abs(fraction - self._last_fraction) < self._min_delta:
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
self._last_at = now
|
|
61
|
+
self._last_fraction = fraction
|
|
62
|
+
self._job.update_progress(fraction, label)
|
|
63
|
+
|
|
64
|
+
def step(self, i: int, total: int, label: str | None = None) -> None:
|
|
65
|
+
if total > 0:
|
|
66
|
+
self.update(i / total, label)
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def current(cls) -> Self:
|
|
70
|
+
reporter = cls._current.get()
|
|
71
|
+
return reporter if isinstance(reporter, cls) else cls()
|
|
72
|
+
|
|
73
|
+
def run_bound(self, fn: Callable[[], T]) -> T:
|
|
74
|
+
token = self._current.set(self)
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
return fn()
|
|
78
|
+
finally:
|
|
79
|
+
self._current.reset(token)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from ._helpers.get_log_level import get_log_level
|
|
2
|
+
from ._helpers.setup_logger import setup_logger
|
|
3
|
+
from ._settings import settings_manager
|
|
4
|
+
from ._types.log_level import LogLevel
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
# ._types
|
|
8
|
+
"LogLevel",
|
|
9
|
+
# ._helpers
|
|
10
|
+
"get_log_level",
|
|
11
|
+
# ._settings
|
|
12
|
+
"settings_manager",
|
|
13
|
+
"setup_logger",
|
|
14
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from .._settings import settings_manager
|
|
4
|
+
|
|
5
|
+
_LOG_FORMAT = "%(asctime)s %(levelname)s [%(name)s] %(message)s"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def setup_logger() -> None:
|
|
9
|
+
settings = settings_manager.get_settings()
|
|
10
|
+
log_level = logging.getLevelNamesMapping()[settings.log_level]
|
|
11
|
+
|
|
12
|
+
logging.basicConfig(level=log_level, format=_LOG_FORMAT)
|
|
13
|
+
logging.getLogger().setLevel(log_level)
|
|
14
|
+
logging.getLogger("kiapi").setLevel(log_level)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pydantic import Field, field_validator
|
|
2
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
3
|
+
from pydantic_settings_manager import SettingsManager
|
|
4
|
+
|
|
5
|
+
from ._types.log_level import LogLevel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LoggingSettings(BaseSettings):
|
|
9
|
+
"""Settings for the global kiapi logging level."""
|
|
10
|
+
|
|
11
|
+
model_config = SettingsConfigDict(
|
|
12
|
+
env_prefix="KIAPI_",
|
|
13
|
+
extra="ignore",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
log_level: LogLevel = Field(
|
|
17
|
+
default="INFO",
|
|
18
|
+
title="Log level",
|
|
19
|
+
description=(
|
|
20
|
+
"Verbosity of emitted logs.\n"
|
|
21
|
+
"Standard Python logging levels such as DEBUG, INFO, WARNING, ERROR, "
|
|
22
|
+
"and CRITICAL are accepted."
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
@field_validator("log_level", mode="before")
|
|
27
|
+
@classmethod
|
|
28
|
+
def _to_upper(cls, v: str) -> str:
|
|
29
|
+
if isinstance(v, str):
|
|
30
|
+
return v.upper()
|
|
31
|
+
return v # type: ignore
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
settings_manager = SettingsManager(LoggingSettings)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from ._exceptions.memory_budget_error import MemoryBudgetError
|
|
2
|
+
from ._helpers.create_memory_manager import create_memory_manager
|
|
3
|
+
from ._schemas.memory_stats import MemoryStats
|
|
4
|
+
from ._schemas.resident_model_stats import ResidentModelStats
|
|
5
|
+
from ._services.memory_manager import MemoryManager
|
|
6
|
+
from ._settings import MemorySettings, settings_manager
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
# ._exceptions
|
|
10
|
+
"MemoryBudgetError",
|
|
11
|
+
# ._services
|
|
12
|
+
"MemoryManager",
|
|
13
|
+
# ._settings
|
|
14
|
+
"MemorySettings",
|
|
15
|
+
# ._schemas
|
|
16
|
+
"MemoryStats",
|
|
17
|
+
"ResidentModelStats",
|
|
18
|
+
# ._helpers
|
|
19
|
+
"create_memory_manager",
|
|
20
|
+
"settings_manager",
|
|
21
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .._operations.log_memory_limit import log_memory_limit
|
|
2
|
+
from .._operations.resolve_effective_memory_limit_gb import (
|
|
3
|
+
resolve_effective_memory_limit_gb,
|
|
4
|
+
)
|
|
5
|
+
from .._services.memory_manager import MemoryManager
|
|
6
|
+
from .._settings import settings_manager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def create_memory_manager() -> MemoryManager:
|
|
10
|
+
settings = settings_manager.get_settings()
|
|
11
|
+
|
|
12
|
+
effective_limit_gb = resolve_effective_memory_limit_gb(settings)
|
|
13
|
+
log_memory_limit(settings, effective_limit_gb)
|
|
14
|
+
|
|
15
|
+
return MemoryManager(
|
|
16
|
+
settings.model_copy(update={"memory_limit_gb": effective_limit_gb})
|
|
17
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import psutil # type: ignore[import-untyped]
|
|
4
|
+
|
|
5
|
+
from .._settings import MemorySettings
|
|
6
|
+
|
|
7
|
+
_GB = 1024**3
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def log_memory_limit(settings: MemorySettings, effective_limit_gb: float) -> None:
|
|
12
|
+
memory = psutil.virtual_memory()
|
|
13
|
+
total_gb = memory.total / _GB
|
|
14
|
+
available_gb = memory.available / _GB
|
|
15
|
+
mode = "configured" if settings.memory_limit_gb is not None else "auto"
|
|
16
|
+
|
|
17
|
+
logger.info(
|
|
18
|
+
"memory budget %s: effective %.1f GB (total %.1f GB, available %.1f GB)",
|
|
19
|
+
mode,
|
|
20
|
+
effective_limit_gb,
|
|
21
|
+
total_gb,
|
|
22
|
+
available_gb,
|
|
23
|
+
)
|
|
24
|
+
if available_gb < effective_limit_gb:
|
|
25
|
+
logger.warning(
|
|
26
|
+
"memory budget %.1f GB exceeds currently available memory %.1f GB",
|
|
27
|
+
effective_limit_gb,
|
|
28
|
+
available_gb,
|
|
29
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import psutil # type: ignore[import-untyped]
|
|
2
|
+
|
|
3
|
+
from .._settings import MemorySettings
|
|
4
|
+
|
|
5
|
+
_GB = 1024**3
|
|
6
|
+
_AUTO_MEMORY_LIMIT_RATIO = 0.8
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def resolve_effective_memory_limit_gb(settings: MemorySettings) -> float:
|
|
10
|
+
if settings.memory_limit_gb is not None:
|
|
11
|
+
return settings.memory_limit_gb
|
|
12
|
+
|
|
13
|
+
return float(psutil.virtual_memory().total) / _GB * _AUTO_MEMORY_LIMIT_RATIO
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Resolve a :class:`FrameworkName` to its :class:`FrameworkStrategy`.
|
|
2
|
+
|
|
3
|
+
A new framework plugs in by adding a ``(active_bytes, free_caches)`` pair to
|
|
4
|
+
``_FRAMEWORKS`` and, if it needs extra teardown, a per-module ``release(payload)``
|
|
5
|
+
hook (called by the manager before dropping refs).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .._schemas.framework_strategy import FrameworkStrategy
|
|
9
|
+
from .._types.framework_name import FrameworkName
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _mlx_active() -> int:
|
|
13
|
+
import mlx.core as mx
|
|
14
|
+
|
|
15
|
+
return int(mx.get_active_memory())
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _mlx_free() -> None:
|
|
19
|
+
import mlx.core as mx
|
|
20
|
+
|
|
21
|
+
mx.clear_cache()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _rss_active() -> int:
|
|
25
|
+
import psutil # type: ignore[import-untyped]
|
|
26
|
+
|
|
27
|
+
return int(psutil.Process().memory_info().rss)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _noop_free() -> None:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_FRAMEWORKS: dict[FrameworkName, FrameworkStrategy] = {
|
|
35
|
+
"mlx": FrameworkStrategy(_mlx_active, _mlx_free),
|
|
36
|
+
# framework-agnostic fallback (e.g. torch/MPS until a dedicated entry lands)
|
|
37
|
+
"rss": FrameworkStrategy(_rss_active, _noop_free),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def resolve_framework_strategy(framework: FrameworkName) -> FrameworkStrategy:
|
|
42
|
+
return _FRAMEWORKS.get(framework, _FRAMEWORKS["rss"])
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import NamedTuple
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FrameworkStrategy(NamedTuple):
|
|
6
|
+
"""How to measure and reclaim a framework's memory, so eviction actually
|
|
7
|
+
frees it. Resolved per :class:`FrameworkName`."""
|
|
8
|
+
|
|
9
|
+
active_bytes: Callable[[], int]
|
|
10
|
+
"""Current active allocation, in bytes. Deltas around load/evict give the
|
|
11
|
+
measured footprint."""
|
|
12
|
+
free_caches: Callable[[], None]
|
|
13
|
+
"""Release the framework's cached buffers after dropping refs (e.g. MLX's
|
|
14
|
+
Metal buffer cache); a no-op where the runtime needs none."""
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
from .resident_model_stats import ResidentModelStats
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MemoryStats(BaseModel):
|
|
7
|
+
"""Resident model memory budget snapshot, served by ``/health``."""
|
|
8
|
+
|
|
9
|
+
loaded: list[ResidentModelStats] = Field(
|
|
10
|
+
default_factory=list,
|
|
11
|
+
description="Resident models currently held in memory.",
|
|
12
|
+
)
|
|
13
|
+
resident_gb: float = Field(
|
|
14
|
+
...,
|
|
15
|
+
ge=0.0,
|
|
16
|
+
description="Total resident model weight currently counted against the budget.",
|
|
17
|
+
examples=[12.0],
|
|
18
|
+
)
|
|
19
|
+
budget_gb: float = Field(
|
|
20
|
+
...,
|
|
21
|
+
gt=0.0,
|
|
22
|
+
description="Effective global memory budget in GB shared by all resident models and the running job's peak headroom.",
|
|
23
|
+
examples=[100.0],
|
|
24
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from kiapi.core.model import ModelSpec
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class ResidentModel:
|
|
8
|
+
spec: ModelSpec
|
|
9
|
+
payload: object
|
|
10
|
+
"""Whatever the handler's ``load()`` returned (opaque to the manager)."""
|
|
11
|
+
weight_gb: float
|
|
12
|
+
"""Resident footprint in GB — measured at load, else the spec estimate."""
|
|
13
|
+
last_used: float
|
|
14
|
+
"""``time.monotonic()`` of the most recent acquire; drives LRU + idle TTL."""
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ResidentModelStats(BaseModel):
|
|
5
|
+
"""Snapshot of one resident model held in the memory budget."""
|
|
6
|
+
|
|
7
|
+
name: str = Field(..., description="Model variant name.", examples=["turbo"])
|
|
8
|
+
family: str = Field(
|
|
9
|
+
...,
|
|
10
|
+
description="Model family and API identifier.",
|
|
11
|
+
examples=["zimage"],
|
|
12
|
+
)
|
|
13
|
+
domain: str = Field(
|
|
14
|
+
...,
|
|
15
|
+
description="Capability domain such as chat, embedding, image, audio, video, or web.",
|
|
16
|
+
examples=["image"],
|
|
17
|
+
)
|
|
18
|
+
repo: str = Field(
|
|
19
|
+
...,
|
|
20
|
+
description="Upstream model repository, Docker image, or local resource label.",
|
|
21
|
+
examples=["mflux/z-image-turbo"],
|
|
22
|
+
)
|
|
23
|
+
weight_gb: float = Field(
|
|
24
|
+
...,
|
|
25
|
+
ge=0.0,
|
|
26
|
+
description="Current resident weight estimate in GB.",
|
|
27
|
+
examples=[6.0],
|
|
28
|
+
)
|
|
29
|
+
priority: int = Field(
|
|
30
|
+
...,
|
|
31
|
+
description="Eviction priority. Lower values are evicted before higher values under budget pressure.",
|
|
32
|
+
examples=[0],
|
|
33
|
+
)
|
|
34
|
+
idle_s: float = Field(
|
|
35
|
+
...,
|
|
36
|
+
ge=0.0,
|
|
37
|
+
description="Seconds since this resident model was last used.",
|
|
38
|
+
examples=[12.5],
|
|
39
|
+
)
|
|
40
|
+
ttl_s: float | None = Field(
|
|
41
|
+
default=None,
|
|
42
|
+
description="Idle TTL in seconds. Null means the resident is pinned until budget pressure or shutdown.",
|
|
43
|
+
examples=[1800.0],
|
|
44
|
+
)
|
|
45
|
+
expires_in_s: float | None = Field(
|
|
46
|
+
default=None,
|
|
47
|
+
description="Seconds until TTL eviction. Null when ttl_s is null.",
|
|
48
|
+
examples=[1787.5],
|
|
49
|
+
)
|