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,166 @@
|
|
|
1
|
+
"""Image (zimage) capability defaults + caps, read from ``KIAPI_ZIMAGE_``."""
|
|
2
|
+
|
|
3
|
+
from typing import cast
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
7
|
+
from pydantic_settings_manager import SettingsManager
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ZimageSettings(BaseSettings):
|
|
11
|
+
"""Settings for Z-Image model variants, generation defaults, and LoRA training defaults."""
|
|
12
|
+
|
|
13
|
+
model_config = SettingsConfigDict(
|
|
14
|
+
env_prefix="KIAPI_ZIMAGE_",
|
|
15
|
+
extra="ignore",
|
|
16
|
+
protected_namespaces=(),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
turbo_repo: str = Field(
|
|
20
|
+
default="filipstrand/Z-Image-Turbo-mflux-4bit",
|
|
21
|
+
title="Turbo model repo",
|
|
22
|
+
description="Hugging Face repo ID used as the Z-Image turbo variant.",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
base_repo: str = Field(
|
|
26
|
+
default="Tongyi-MAI/Z-Image",
|
|
27
|
+
title="Base model repo",
|
|
28
|
+
description="Hugging Face repo ID used as the Z-Image base variant.",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
default_quantize: dict[str, int | None] = Field(
|
|
32
|
+
default_factory=lambda: {"turbo": None, "base": 8},
|
|
33
|
+
title="Default quantization bits by variant",
|
|
34
|
+
description=(
|
|
35
|
+
"Default quantization bit count used when loading a generation model.\n"
|
|
36
|
+
"Keys are variant names; values are bit counts such as 8, or None "
|
|
37
|
+
"for no quantization."
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# --------------------------------------------------
|
|
42
|
+
# generate
|
|
43
|
+
# --------------------------------------------------
|
|
44
|
+
|
|
45
|
+
default_steps: dict[str, int] = Field(
|
|
46
|
+
default_factory=lambda: {"turbo": 9, "base": 28},
|
|
47
|
+
title="Default steps by variant",
|
|
48
|
+
description=(
|
|
49
|
+
"Diffusion step count used when a generation request omits steps.\n"
|
|
50
|
+
"Keys are variant names such as turbo or base; values are step counts."
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
default_guidance: dict[str, float | None] = Field(
|
|
55
|
+
default_factory=lambda: {"turbo": None, "base": 4.0},
|
|
56
|
+
title="Default guidance by variant",
|
|
57
|
+
description=(
|
|
58
|
+
"Guidance strength used when a generation request omits guidance.\n"
|
|
59
|
+
"Keys are variant names; values are guidance values. None uses the "
|
|
60
|
+
"model default."
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
default_width: int = Field(
|
|
65
|
+
default=1024,
|
|
66
|
+
title="Default width",
|
|
67
|
+
description="Output image width in pixels used when a request omits width.",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
default_height: int = Field(
|
|
71
|
+
default=1024,
|
|
72
|
+
title="Default height",
|
|
73
|
+
description="Output image height in pixels used when a request omits height.",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
max_width: int = Field(
|
|
77
|
+
default=2048,
|
|
78
|
+
title="Maximum width",
|
|
79
|
+
description="Upper pixel limit for the output image width accepted in a request.",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
max_height: int = Field(
|
|
83
|
+
default=2048,
|
|
84
|
+
title="Maximum height",
|
|
85
|
+
description="Upper pixel limit for the output image height accepted in a request.",
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
max_steps: int = Field(
|
|
89
|
+
default=100,
|
|
90
|
+
title="Maximum inference steps",
|
|
91
|
+
description="Upper limit for the diffusion step count accepted in a request.",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
max_loras: int = Field(
|
|
95
|
+
default=4,
|
|
96
|
+
title="Maximum LoRA count",
|
|
97
|
+
description="Maximum number of LoRA adapters that can be applied in one generation request.",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# --------------------------------------------------
|
|
101
|
+
# train
|
|
102
|
+
# --------------------------------------------------
|
|
103
|
+
|
|
104
|
+
train_reserve_gb: float = Field(
|
|
105
|
+
default=24.0,
|
|
106
|
+
title="LoRA training reserved memory GB",
|
|
107
|
+
description="Memory in GB reserved for the runtime peak of a Z-Image LoRA training job.",
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
train_steps: dict[str, int] = Field(
|
|
111
|
+
default_factory=lambda: {"turbo": 9, "base": 20},
|
|
112
|
+
title="Training steps by variant",
|
|
113
|
+
description=(
|
|
114
|
+
"Step count used when a LoRA training request omits steps.\n"
|
|
115
|
+
"Keys are variant names; values are training step counts."
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
train_timestep_low: dict[str, int] = Field(
|
|
120
|
+
default_factory=lambda: {"turbo": 4, "base": 0},
|
|
121
|
+
title="Training timestep lower bound by variant",
|
|
122
|
+
description=(
|
|
123
|
+
"Lower bound of the timestep range used during LoRA training.\n"
|
|
124
|
+
"Keys are variant names; values are lower-bound timestep values."
|
|
125
|
+
),
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
train_quantize: dict[str, int | None] = Field(
|
|
129
|
+
default_factory=lambda: cast(dict[str, int | None], {"turbo": 8, "base": 8}),
|
|
130
|
+
title="Training quantization bits by variant",
|
|
131
|
+
description=(
|
|
132
|
+
"Quantization bit count applied to the model during LoRA training.\n"
|
|
133
|
+
"Keys are variant names; values are bit counts such as 8, or None "
|
|
134
|
+
"for no quantization."
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
train_default_epochs: int = Field(
|
|
139
|
+
default=10,
|
|
140
|
+
title="Default LoRA training epochs",
|
|
141
|
+
description="Epoch count used when a LoRA training request omits epochs.",
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
train_default_rank: int = Field(
|
|
145
|
+
default=16,
|
|
146
|
+
title="Default LoRA training rank",
|
|
147
|
+
description=(
|
|
148
|
+
"LoRA rank used when a LoRA training request omits rank.\n"
|
|
149
|
+
"Higher values increase expressiveness and memory usage."
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
train_default_lr: float = Field(
|
|
154
|
+
default=1e-4,
|
|
155
|
+
title="Default LoRA training learning rate",
|
|
156
|
+
description="Learning rate used when a LoRA training request omits lr.",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
train_max_epochs: int = Field(
|
|
160
|
+
default=1000,
|
|
161
|
+
title="Maximum LoRA training epochs",
|
|
162
|
+
description="Upper limit for epochs accepted in a LoRA training request.",
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
settings_manager = SettingsManager(ZimageSettings)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Resolved Z-Image generation parameters passed to the model layer."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from .._schemas.lora_ref import LoraRef
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GenerateParams(BaseModel):
|
|
11
|
+
model: str
|
|
12
|
+
prompt: str
|
|
13
|
+
negative_prompt: str | None
|
|
14
|
+
seed: int
|
|
15
|
+
width: int
|
|
16
|
+
height: int
|
|
17
|
+
steps: int
|
|
18
|
+
guidance: float | None
|
|
19
|
+
quantize: int | None
|
|
20
|
+
format: Literal["png", "jpeg", "webp"]
|
|
21
|
+
quality: int
|
|
22
|
+
loras: list[LoraRef]
|
|
23
|
+
mode: Literal["txt2img"] = "txt2img"
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Z-Image text-to-image request model.
|
|
2
|
+
|
|
3
|
+
One endpoint serves both sync and async via ``mode``. Defaults for ``steps`` /
|
|
4
|
+
``guidance`` / ``quantize`` are variant-dependent (turbo vs base) and resolved
|
|
5
|
+
server-side when omitted. A ``quantize`` override or any ``loras`` builds a
|
|
6
|
+
one-off transient model (slower, not reused).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
12
|
+
|
|
13
|
+
from .._schemas.lora_ref import LoraRef
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GenerateRequest(BaseModel):
|
|
17
|
+
model_config = ConfigDict(extra="allow")
|
|
18
|
+
|
|
19
|
+
model: str | None = Field(
|
|
20
|
+
default=None,
|
|
21
|
+
description=(
|
|
22
|
+
"Model variant (see GET /v1/image/zimage/models). Omit for the default "
|
|
23
|
+
"`turbo` (distilled, few-step, fast); `base` is the full, higher-quality, "
|
|
24
|
+
"slower variant."
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
mode: Literal["sync", "async"] = Field(
|
|
28
|
+
default="sync",
|
|
29
|
+
description=(
|
|
30
|
+
"`sync` waits for the image (504 on timeout); `async` returns 202 with "
|
|
31
|
+
"a job_id immediately — poll GET /v1/jobs/{job_id}."
|
|
32
|
+
),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
prompt: str = Field(
|
|
36
|
+
...,
|
|
37
|
+
min_length=1,
|
|
38
|
+
description="Text prompt describing the image to generate (required).",
|
|
39
|
+
)
|
|
40
|
+
negative_prompt: str | None = Field(
|
|
41
|
+
default=None,
|
|
42
|
+
description=(
|
|
43
|
+
"Optional text describing what to avoid in the image. Most effective on "
|
|
44
|
+
"`base` with guidance > 1; `turbo` is distilled (no guidance) so it has "
|
|
45
|
+
"little effect there."
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
width: int | None = Field(
|
|
50
|
+
default=None,
|
|
51
|
+
description=(
|
|
52
|
+
"Output width in pixels. Omit for the server default (1024). Must be a "
|
|
53
|
+
"multiple of 16 and at most 2048."
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
height: int | None = Field(
|
|
57
|
+
default=None,
|
|
58
|
+
description=(
|
|
59
|
+
"Output height in pixels. Omit for the server default (1024). Must be a "
|
|
60
|
+
"multiple of 16 and at most 2048."
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
steps: int | None = Field(
|
|
64
|
+
default=None,
|
|
65
|
+
ge=1,
|
|
66
|
+
description=(
|
|
67
|
+
"Number of denoising steps (1..100). Omit for the variant default "
|
|
68
|
+
"(turbo 9, base 28). More steps = slower, sometimes higher quality."
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
guidance: float | None = Field(
|
|
72
|
+
default=None,
|
|
73
|
+
description=(
|
|
74
|
+
"Classifier-free guidance scale. Omit for the variant default "
|
|
75
|
+
"(turbo: none — distilled; base: 4.0). Higher follows the prompt more "
|
|
76
|
+
"strictly."
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
seed: int | None = Field(
|
|
80
|
+
default=None,
|
|
81
|
+
description=(
|
|
82
|
+
"Random seed for reproducibility. Omit for a random seed (the resolved "
|
|
83
|
+
"seed is recorded in the result `params`)."
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
quantize: int | None = Field(
|
|
87
|
+
default=None,
|
|
88
|
+
description=(
|
|
89
|
+
"Quantization bits, one of {3, 4, 5, 6, 8}. Omit to use the resident "
|
|
90
|
+
"model's quantization (turbo is pre-quantized 4-bit; base defaults to 8). "
|
|
91
|
+
"A differing value builds a one-off transient model (slower, not reused)."
|
|
92
|
+
),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
format: Literal["png", "jpeg", "webp"] = Field(
|
|
96
|
+
default="png",
|
|
97
|
+
description="Output image encoding for the produced file.",
|
|
98
|
+
)
|
|
99
|
+
quality: int = Field(
|
|
100
|
+
default=90,
|
|
101
|
+
ge=1,
|
|
102
|
+
le=100,
|
|
103
|
+
description="Encoder quality 1..100 (used for jpeg/webp; ignored for png).",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
loras: list[LoraRef] = Field(
|
|
107
|
+
default_factory=list,
|
|
108
|
+
description=(
|
|
109
|
+
"Up to 4 LoRA adapters [{file, scale}] referencing Files-API ids. Any "
|
|
110
|
+
"lora forces a one-off transient model (slower, not reused)."
|
|
111
|
+
),
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def gen_params(self) -> dict:
|
|
115
|
+
return {
|
|
116
|
+
"prompt": self.prompt,
|
|
117
|
+
"negative_prompt": self.negative_prompt,
|
|
118
|
+
"width": self.width,
|
|
119
|
+
"height": self.height,
|
|
120
|
+
"steps": self.steps,
|
|
121
|
+
"guidance": self.guidance,
|
|
122
|
+
"seed": self.seed,
|
|
123
|
+
"quantize": self.quantize,
|
|
124
|
+
"format": self.format,
|
|
125
|
+
"quality": self.quality,
|
|
126
|
+
"loras": [lr.model_dump() for lr in self.loras],
|
|
127
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Resolved Z-Image LoRA finetune parameters passed to the model layer."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TrainParams(BaseModel):
|
|
7
|
+
model: str
|
|
8
|
+
seed: int
|
|
9
|
+
steps: int
|
|
10
|
+
guidance: float
|
|
11
|
+
quantize: int | None
|
|
12
|
+
max_resolution: int | None
|
|
13
|
+
low_ram: bool
|
|
14
|
+
num_epochs: int
|
|
15
|
+
batch_size: int
|
|
16
|
+
timestep_low: int
|
|
17
|
+
timestep_high: int
|
|
18
|
+
learning_rate: float
|
|
19
|
+
save_frequency: int
|
|
20
|
+
lora_rank: int
|
|
21
|
+
lora_include_ff: bool
|
|
22
|
+
lora_layers: dict | None
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Z-Image LoRA finetune request model. Always async (long-running).
|
|
2
|
+
|
|
3
|
+
The dataset is a ZIP uploaded to the Files API, with each image accompanied by a
|
|
4
|
+
same-stem ``.txt`` caption. The trained adapter is stored back in the Files API
|
|
5
|
+
and returned as the job's artifact (``adapter_file_id``).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
9
|
+
|
|
10
|
+
from kiapi.core.file import FileRef
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TrainRequest(BaseModel):
|
|
14
|
+
model_config = ConfigDict(extra="allow")
|
|
15
|
+
|
|
16
|
+
model: str | None = Field(
|
|
17
|
+
default=None,
|
|
18
|
+
description=(
|
|
19
|
+
"Model variant to finetune (see GET /v1/image/zimage/models). Omit for "
|
|
20
|
+
"the default `turbo`."
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
dataset: FileRef = Field(
|
|
24
|
+
description=(
|
|
25
|
+
"Training dataset as a Files-API reference to a ZIP. Images may sit at "
|
|
26
|
+
"the top level or in a single subfolder; each image needs a same-stem "
|
|
27
|
+
"`.txt` caption (e.g. `cat.png` + `cat.txt`). `preview*` images are "
|
|
28
|
+
"exempt from the caption requirement."
|
|
29
|
+
),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
seed: int = Field(default=42, description="Random seed for the training run.")
|
|
33
|
+
steps: int | None = Field(
|
|
34
|
+
default=None,
|
|
35
|
+
description=(
|
|
36
|
+
"Inference/denoising steps used during training. Omit for the variant "
|
|
37
|
+
"default (turbo 9, base 20)."
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
guidance: float = Field(
|
|
41
|
+
default=0.0,
|
|
42
|
+
description="Guidance scale used during training.",
|
|
43
|
+
)
|
|
44
|
+
quantize: int | None = Field(
|
|
45
|
+
default=None,
|
|
46
|
+
description=(
|
|
47
|
+
"Quantization bits during training, one of {3, 4, 5, 6, 8}. Omit for "
|
|
48
|
+
"the variant default (8)."
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
max_resolution: int | None = Field(
|
|
52
|
+
default=512,
|
|
53
|
+
description=(
|
|
54
|
+
"Images are resized so their long side is at most this many pixels."
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
low_ram: bool = Field(
|
|
58
|
+
default=True,
|
|
59
|
+
description="Trade speed for lower peak memory during training.",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
num_epochs: int = Field(
|
|
63
|
+
default=10, ge=1, description="Number of passes over the dataset."
|
|
64
|
+
)
|
|
65
|
+
batch_size: int = Field(default=1, ge=1, description="Training batch size.")
|
|
66
|
+
timestep_low: int | None = Field(
|
|
67
|
+
default=None,
|
|
68
|
+
description=(
|
|
69
|
+
"Lower diffusion-timestep bound to sample. Omit for the variant default "
|
|
70
|
+
"(turbo 4, base 0)."
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
timestep_high: int | None = Field(
|
|
74
|
+
default=None,
|
|
75
|
+
description="Upper diffusion-timestep bound to sample. Omit to use `steps`.",
|
|
76
|
+
)
|
|
77
|
+
learning_rate: float = Field(default=1e-4, description="AdamW learning rate.")
|
|
78
|
+
save_frequency: int | None = Field(
|
|
79
|
+
default=None,
|
|
80
|
+
description=(
|
|
81
|
+
"Checkpoint every N steps. Omit to only keep the final checkpoint."
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
lora_rank: int = Field(
|
|
86
|
+
default=16, ge=1, description="Rank of the trained LoRA adapter."
|
|
87
|
+
)
|
|
88
|
+
lora_include_ff: bool = Field(
|
|
89
|
+
default=False,
|
|
90
|
+
description=(
|
|
91
|
+
"Also train feed-forward layers (larger adapter), not just attention "
|
|
92
|
+
"projections."
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
lora_layers: dict | None = Field(
|
|
96
|
+
default=None,
|
|
97
|
+
description=(
|
|
98
|
+
"Advanced: explicit mflux LoRA target spec. Omit to use the built-in "
|
|
99
|
+
"default targets derived from `lora_rank` / `lora_include_ff`."
|
|
100
|
+
),
|
|
101
|
+
)
|
kiapi/cli/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from ._helpers.dedupe_resources import dedupe_resources
|
|
2
|
+
from ._helpers.register_all_capabilities import register_all_capabilities
|
|
3
|
+
from ._helpers.run_resources import run_resources
|
|
4
|
+
from ._helpers.select_specs import select_specs
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"dedupe_resources",
|
|
8
|
+
"register_all_capabilities",
|
|
9
|
+
"run_resources",
|
|
10
|
+
"select_specs",
|
|
11
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
from kiapi.core.model import ModelSpec
|
|
4
|
+
from kiapi.core.setup import SetupResource
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def dedupe_resources(specs: Iterable[ModelSpec]) -> list[SetupResource]:
|
|
8
|
+
resources: dict[str, SetupResource] = {}
|
|
9
|
+
for spec in specs:
|
|
10
|
+
for resource in spec.setup_resources:
|
|
11
|
+
resources.setdefault(resource.key, resource)
|
|
12
|
+
return list(resources.values())
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from kiapi.capabilities.acestep import register as register_acestep
|
|
2
|
+
from kiapi.capabilities.audiogen import register as register_audiogen
|
|
3
|
+
from kiapi.capabilities.chat import register as register_chat
|
|
4
|
+
from kiapi.capabilities.depthpro import register as register_depthpro
|
|
5
|
+
from kiapi.capabilities.embedding import register as register_embedding
|
|
6
|
+
from kiapi.capabilities.ernie import register as register_ernie
|
|
7
|
+
from kiapi.capabilities.flux2 import register as register_flux2
|
|
8
|
+
from kiapi.capabilities.ideogram4 import register as register_ideogram4
|
|
9
|
+
from kiapi.capabilities.ltx2 import register as register_ltx2
|
|
10
|
+
from kiapi.capabilities.qwen import register as register_qwen
|
|
11
|
+
from kiapi.capabilities.seedvr2 import register as register_seedvr2
|
|
12
|
+
from kiapi.capabilities.web import register as register_web
|
|
13
|
+
from kiapi.capabilities.zimage import register as register_zimage
|
|
14
|
+
|
|
15
|
+
_registered = False
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def register_all_capabilities() -> None:
|
|
19
|
+
global _registered
|
|
20
|
+
if _registered:
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
register_acestep()
|
|
24
|
+
register_audiogen()
|
|
25
|
+
register_chat()
|
|
26
|
+
register_depthpro()
|
|
27
|
+
register_embedding()
|
|
28
|
+
register_ernie()
|
|
29
|
+
register_flux2()
|
|
30
|
+
register_ideogram4()
|
|
31
|
+
register_ltx2()
|
|
32
|
+
register_qwen()
|
|
33
|
+
register_seedvr2()
|
|
34
|
+
register_web()
|
|
35
|
+
register_zimage()
|
|
36
|
+
_registered = True
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from kiapi.core.setup import SetupManager, SetupResource
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def run_resources(
|
|
7
|
+
action: str, resources: list[SetupResource], manager: SetupManager
|
|
8
|
+
) -> None:
|
|
9
|
+
if not resources:
|
|
10
|
+
click.echo("No setup resources.")
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
for resource in resources:
|
|
14
|
+
click.echo(f"{action}: {resource.kind} {resource.label}")
|
|
15
|
+
try:
|
|
16
|
+
if action == "activate":
|
|
17
|
+
state = manager.activate(resource)
|
|
18
|
+
else:
|
|
19
|
+
state = manager.deactivate(resource)
|
|
20
|
+
except Exception as exc:
|
|
21
|
+
raise click.ClickException(f"{resource.label}: {exc}") from exc
|
|
22
|
+
|
|
23
|
+
mark = "ok" if state.ready else "missing"
|
|
24
|
+
click.echo(f" [{mark}] {state.detail}")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import questionary
|
|
3
|
+
|
|
4
|
+
from kiapi.core.model import ModelSpec, model_registry
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def select_specs(
|
|
8
|
+
*,
|
|
9
|
+
all_selected: bool,
|
|
10
|
+
domains: tuple[str, ...],
|
|
11
|
+
families: tuple[str, ...],
|
|
12
|
+
repos: tuple[str, ...],
|
|
13
|
+
interactive: bool,
|
|
14
|
+
action: str = "activate",
|
|
15
|
+
) -> list[ModelSpec]:
|
|
16
|
+
specs = model_registry.list_specs()
|
|
17
|
+
if all_selected:
|
|
18
|
+
return specs
|
|
19
|
+
|
|
20
|
+
if domains or families or repos:
|
|
21
|
+
selected = [
|
|
22
|
+
spec
|
|
23
|
+
for spec in specs
|
|
24
|
+
if _matches(spec, domains=domains, families=families, repos=repos)
|
|
25
|
+
]
|
|
26
|
+
if not selected:
|
|
27
|
+
raise click.ClickException("No matching models found.")
|
|
28
|
+
return selected
|
|
29
|
+
|
|
30
|
+
if not interactive:
|
|
31
|
+
raise click.ClickException("Specify --all, --domain, --family, or --repo.")
|
|
32
|
+
|
|
33
|
+
choices = [
|
|
34
|
+
questionary.Choice(title=_spec_choice_title(spec), value=spec) for spec in specs
|
|
35
|
+
]
|
|
36
|
+
selected = questionary.checkbox(
|
|
37
|
+
f"Select models to {action}:", choices=choices
|
|
38
|
+
).ask()
|
|
39
|
+
if not selected:
|
|
40
|
+
raise click.ClickException("No models selected.")
|
|
41
|
+
return list(selected)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _matches(
|
|
45
|
+
spec: ModelSpec,
|
|
46
|
+
*,
|
|
47
|
+
domains: tuple[str, ...],
|
|
48
|
+
families: tuple[str, ...],
|
|
49
|
+
repos: tuple[str, ...],
|
|
50
|
+
) -> bool:
|
|
51
|
+
if domains and spec.domain in domains:
|
|
52
|
+
return True
|
|
53
|
+
if families and spec.family in families:
|
|
54
|
+
return True
|
|
55
|
+
if repos:
|
|
56
|
+
values = {spec.repo, *spec.aliases}
|
|
57
|
+
values.update(resource.label for resource in spec.setup_resources)
|
|
58
|
+
if values.intersection(repos):
|
|
59
|
+
return True
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _spec_choice_title(spec: ModelSpec) -> str:
|
|
64
|
+
size = sum(resource.disk_gb or 0.0 for resource in spec.setup_resources)
|
|
65
|
+
size_label = f" ~{size:g} GB" if size else ""
|
|
66
|
+
default = " default" if spec.default else ""
|
|
67
|
+
return f"{spec.domain}/{spec.family}/{spec.name}{default}{size_label}"
|