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,249 @@
|
|
|
1
|
+
# zimage
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **日本語**
|
|
4
|
+
|
|
5
|
+
[mflux Z-Image](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/z_image/README.md) で、画像生成と LoRA ファインチューニング機能を提供します。
|
|
6
|
+
|
|
7
|
+
Z-Image は比較的軽量に扱える画像生成モデルです。
|
|
8
|
+
`turbo` は少ステップで高速、`base` は guidance / negative prompt を使った調整向きです。
|
|
9
|
+
|
|
10
|
+
- **generate**: テキストから画像を生成
|
|
11
|
+
- **train**: キャプション付き画像 ZIP から LoRA アダプタを学習
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
| Endpoint | Name | Description |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `POST /v1/image/zimage/generate` | 画像生成 | プロンプトから画像を生成。`application/json` の body を渡す。 |
|
|
18
|
+
| `POST /v1/image/zimage/train` | LoRA 学習 | キャプション付き画像 ZIP から LoRA アダプタを学習。常に async。 |
|
|
19
|
+
| `GET /v1/image/zimage/models` | モデル一覧 | 利用可能なモデルの一覧を返す。 |
|
|
20
|
+
| `GET /v1/image/zimage/openapi.json` | OpenAPI | 詳細な入出力仕様、使い方、TIPS を返す。 |
|
|
21
|
+
|
|
22
|
+
## API Docs
|
|
23
|
+
|
|
24
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/image/zimage/openapi.json)
|
|
25
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/image/zimage/docs.html)
|
|
26
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/image/zimage/redoc.html)
|
|
27
|
+
|
|
28
|
+
## Dependencies
|
|
29
|
+
|
|
30
|
+
| Package | License | Description |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| [mflux](https://github.com/filipstrand/mflux) | MIT | Z-Image の生成と LoRA 学習を MLX 上で実行。 |
|
|
33
|
+
|
|
34
|
+
## Models
|
|
35
|
+
|
|
36
|
+
| Model | License | Terms | Size | Description |
|
|
37
|
+
|---|---|---|---:|---|
|
|
38
|
+
| [filipstrand/Z-Image-Turbo-mflux-4bit](https://huggingface.co/filipstrand/Z-Image-Turbo-mflux-4bit) | Tongyi Qianwen License | 不要 | 5.5 GB | `turbo`(デフォルト)。蒸留・少ステップ向け。既定は `steps: 9`、`guidance: null`、`quantize: null`。 |
|
|
39
|
+
| [Tongyi-MAI/Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image) | Apache-2.0 | 不要 | 19 GB | `base`。非 distilled のモデル。既定は `steps: 28`、`guidance: 4.0`、`quantize: 8`。 |
|
|
40
|
+
|
|
41
|
+
kiapi の登録値では、`turbo` は重み約 `6.0 GiB` / 実行時ヘッドルーム約 `8.0 GiB`、
|
|
42
|
+
`base` は重み約 `12.0 GiB` / 実行時ヘッドルーム約 `16.0 GiB` を見込んでいます。
|
|
43
|
+
|
|
44
|
+
## Notes
|
|
45
|
+
|
|
46
|
+
- **画像サイズ**:
|
|
47
|
+
`width` / `height` は 16 の倍数。既定は `1024 x 1024`、上限は `2048 x 2048`。
|
|
48
|
+
- **steps / guidance**:
|
|
49
|
+
`steps` は `1..100`。省略時は `turbo` が `9`、`base` が `28`。
|
|
50
|
+
`turbo` は distilled model なので `guidance` と `negative_prompt` の効果はありません。
|
|
51
|
+
`base` は `guidance` と `negative_prompt` を使えます。
|
|
52
|
+
- **quantize**:
|
|
53
|
+
`quantize` は `3` / `4` / `5` / `6` / `8` を指定できます。省略するとモデルごとの既定値を使います。
|
|
54
|
+
`turbo` は 4-bit 事前量子化 repo を使うため、通常は省略します。
|
|
55
|
+
- **LoRA 適用**:
|
|
56
|
+
`generate` の `loras` には `[{ "file": {"type": "file_id", "file_id": "..."}, "scale": 1.0 }]` を渡します。
|
|
57
|
+
既定では最大 4 個まで適用できます。アダプタファイルは Files API に保存されている必要があります。
|
|
58
|
+
- **transient モデル**:
|
|
59
|
+
mflux は量子化レベルと LoRA をモデル構築時に固定します。`loras` を持つ、または
|
|
60
|
+
`quantize` を既定値から上書きするリクエストは、その呼び出し用の一時モデルを構築します。
|
|
61
|
+
常駐モデルを再利用しないため、素の `turbo` / `base` 呼び出しより遅くなります。
|
|
62
|
+
- **出力形式**:
|
|
63
|
+
`format` は `png`(既定)/ `jpeg` / `webp`。`jpeg` / `webp` では `quality`
|
|
64
|
+
`1..100`(既定 `90`)を使います。
|
|
65
|
+
- **LoRA 学習データセット**:
|
|
66
|
+
ZIP のトップレベル、または ZIP 内の単一サブフォルダに画像を置きます。画像ごとに
|
|
67
|
+
同じ語幹の `.txt` キャプションが必要です。
|
|
68
|
+
|
|
69
|
+
## Quickstart
|
|
70
|
+
|
|
71
|
+
### generate - テキストから画像生成
|
|
72
|
+
|
|
73
|
+
画像だけを保存する:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
PARAMS=$(
|
|
77
|
+
jq -n \
|
|
78
|
+
--arg prompt "a red fox in fresh snow, soft morning light, realistic photo" \
|
|
79
|
+
'{
|
|
80
|
+
model: "turbo",
|
|
81
|
+
mode: "sync",
|
|
82
|
+
prompt: $prompt,
|
|
83
|
+
width: 1024,
|
|
84
|
+
height: 1024,
|
|
85
|
+
seed: 1
|
|
86
|
+
}'
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
90
|
+
-H 'Content-Type: application/json' \
|
|
91
|
+
--data-binary "$PARAMS" \
|
|
92
|
+
-o zimage.png
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Job JSON を返す:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
PARAMS=$(
|
|
99
|
+
jq -n \
|
|
100
|
+
--arg prompt "a small robot watering flowers, clean studio illustration" \
|
|
101
|
+
--arg negative_prompt "blurry, low quality" \
|
|
102
|
+
'{
|
|
103
|
+
model: "base",
|
|
104
|
+
mode: "sync",
|
|
105
|
+
prompt: $prompt,
|
|
106
|
+
negative_prompt: $negative_prompt,
|
|
107
|
+
width: 512,
|
|
108
|
+
height: 512,
|
|
109
|
+
seed: 2
|
|
110
|
+
}'
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
114
|
+
-H 'Accept: application/json' \
|
|
115
|
+
-H 'Content-Type: application/json' \
|
|
116
|
+
--data-binary "$PARAMS" |
|
|
117
|
+
jq .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`file_id` が必要な場合はレスポンスヘッダから読めます。
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
PARAMS=$(
|
|
124
|
+
jq -n \
|
|
125
|
+
--arg prompt "a red fox in fresh snow" \
|
|
126
|
+
'{
|
|
127
|
+
mode: "sync",
|
|
128
|
+
prompt: $prompt,
|
|
129
|
+
width: 512,
|
|
130
|
+
height: 512,
|
|
131
|
+
seed: 1
|
|
132
|
+
}'
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
FILE_ID=$(curl -sS -D - -o zimage.png \
|
|
136
|
+
-X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
137
|
+
-H 'Content-Type: application/json' \
|
|
138
|
+
--data-binary "$PARAMS" \
|
|
139
|
+
| awk -F': ' 'tolower($1)=="x-kiapi-file-id"{print $2}' | tr -d '\r')
|
|
140
|
+
|
|
141
|
+
echo "$FILE_ID"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### async
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
PARAMS=$(
|
|
148
|
+
jq -n \
|
|
149
|
+
--arg prompt "a cinematic product photo of a glass teapot" \
|
|
150
|
+
'{
|
|
151
|
+
model: "turbo",
|
|
152
|
+
mode: "async",
|
|
153
|
+
prompt: $prompt,
|
|
154
|
+
width: 512,
|
|
155
|
+
height: 512,
|
|
156
|
+
seed: 11
|
|
157
|
+
}'
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
JOB=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
161
|
+
-H 'Accept: application/json' \
|
|
162
|
+
-H 'Content-Type: application/json' \
|
|
163
|
+
--data-binary "$PARAMS" |
|
|
164
|
+
jq -r .job_id)
|
|
165
|
+
|
|
166
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
完了後、Job の `artifacts[0]` または `result.file_id` を使って画像を取得します。
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
FID=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.file_id)
|
|
173
|
+
curl -sS http://localhost:${PORT:-8000}/v1/files/$FID/download -o zimage-async.png
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### train - LoRA ファインチューニング
|
|
177
|
+
|
|
178
|
+
画像と同じ語幹の `.txt` キャプションを含む ZIP データセットを用意します。
|
|
179
|
+
|
|
180
|
+
```text
|
|
181
|
+
dataset/
|
|
182
|
+
sample_00.png
|
|
183
|
+
sample_00.txt
|
|
184
|
+
sample_01.png
|
|
185
|
+
sample_01.txt
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
データセット ZIP を作り、Files API にアップロードします。
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
(cd dataset && zip -q -r - .) > dataset.zip
|
|
192
|
+
|
|
193
|
+
DATASET_ID=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
194
|
+
-F "file=@dataset.zip;type=application/zip" | jq -r .file_id)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
学習を開始します。train は常に async です。
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
JOB=$(
|
|
201
|
+
jq -n \
|
|
202
|
+
--arg dataset "$DATASET_ID" \
|
|
203
|
+
'{
|
|
204
|
+
model: "turbo",
|
|
205
|
+
dataset: {type: "file_id", file_id: $dataset},
|
|
206
|
+
num_epochs: 10,
|
|
207
|
+
lora_rank: 16,
|
|
208
|
+
max_resolution: 512
|
|
209
|
+
}' |
|
|
210
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/train \
|
|
211
|
+
-H 'Content-Type: application/json' \
|
|
212
|
+
--data-binary @- |
|
|
213
|
+
jq -r .job_id
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
完了後、`result.adapter_file_id` が学習済みアダプタです。
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
ADAPTER=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.adapter_file_id)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
生成で LoRA を適用します。
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
PARAMS=$(
|
|
229
|
+
jq -n \
|
|
230
|
+
--arg prompt "<your trigger word> in a magical garden" \
|
|
231
|
+
--arg adapter "$ADAPTER" \
|
|
232
|
+
'{
|
|
233
|
+
model: "turbo",
|
|
234
|
+
mode: "sync",
|
|
235
|
+
prompt: $prompt,
|
|
236
|
+
width: 512,
|
|
237
|
+
height: 512,
|
|
238
|
+
seed: 7,
|
|
239
|
+
loras: [{file: {type: "file_id", file_id: $adapter}, scale: 1.0}]
|
|
240
|
+
}'
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
244
|
+
-H 'Content-Type: application/json' \
|
|
245
|
+
--data-binary "$PARAMS" \
|
|
246
|
+
-o zimage-lora.png
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`scale` は効きの強さです。`loras` を使うリクエストは毎回一時モデルを構築します。
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# zimage
|
|
2
|
+
|
|
3
|
+
**English** | [日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
[mflux Z-Image](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/z_image/README.md) provides image generation and LoRA fine-tuning functionality.
|
|
6
|
+
|
|
7
|
+
Z-Image is a relatively lightweight image generation model.
|
|
8
|
+
`turbo` is fast with few steps, and `base` is suitable for adjustment using guidance / negative prompt.
|
|
9
|
+
|
|
10
|
+
- **generate**: Generate image from text
|
|
11
|
+
- **train**: Train LoRA adapter from captioned image ZIP
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
| Endpoint | Name | Description |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `POST /v1/image/zimage/generate` | Image generation | Generate image from prompt. Pass the body of `application/json`. |
|
|
18
|
+
| `POST /v1/image/zimage/train` | LoRA learning | Learn LoRA adapter from captioned image ZIP. Always async. |
|
|
19
|
+
| `GET /v1/image/zimage/models` | List of models | Return a list of available models. |
|
|
20
|
+
| `GET /v1/image/zimage/openapi.json` | OpenAPI | Returns detailed input/output specifications, usage, and TIPS. |
|
|
21
|
+
|
|
22
|
+
## API Docs
|
|
23
|
+
|
|
24
|
+
- [OpenAPI JSON](https://kiarina.github.io/kiapi/v1/image/zimage/openapi.json)
|
|
25
|
+
- [Swagger UI](https://kiarina.github.io/kiapi/v1/image/zimage/docs.html)
|
|
26
|
+
- [ReDoc](https://kiarina.github.io/kiapi/v1/image/zimage/redoc.html)
|
|
27
|
+
|
|
28
|
+
## Dependencies
|
|
29
|
+
|
|
30
|
+
| Package | License | Description |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| [mflux](https://github.com/filipstrand/mflux) | MIT | Perform Z-Image generation and LoRA training on MLX. |
|
|
33
|
+
|
|
34
|
+
## Models
|
|
35
|
+
|
|
36
|
+
| Model | License | Terms | Size | Description |
|
|
37
|
+
|---|---|---|---:|---|
|
|
38
|
+
| [filipstrand/Z-Image-Turbo-mflux-4bit](https://huggingface.co/filipstrand/Z-Image-Turbo-mflux-4bit) | Tongyi Qianwen License | Not required | 5.5 GB | `turbo` (default). For distillation and small steps. Defaults are `steps: 9`, `guidance: null`, `quantize: null`. |
|
|
39
|
+
| [Tongyi-MAI/Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image) | Apache-2.0 | Not required | 19 GB | `base`. Non-distilled model. Defaults are `steps: 28`, `guidance: 4.0`, `quantize: 8`. |
|
|
40
|
+
|
|
41
|
+
In kiapi's registered values, `turbo` has a weight of approximately `6.0 GiB` / runtime headroom of approximately `8.0 GiB`,
|
|
42
|
+
`base` is expected to have a weight of approximately `12.0 GiB` / runtime headroom of approximately `16.0 GiB`.
|
|
43
|
+
|
|
44
|
+
## Notes
|
|
45
|
+
|
|
46
|
+
- **Image size**:
|
|
47
|
+
`width` / `height` are multiples of 16. Default is `1024 x 1024`, upper limit is `2048 x 2048`.
|
|
48
|
+
- **steps/guidance**:
|
|
49
|
+
`steps` is `1..100`. If omitted, `turbo` is `9` and `base` is `28`.
|
|
50
|
+
Since `turbo` is a distilled model, `guidance` and `negative_prompt` have no effect.
|
|
51
|
+
`base` can use `guidance` and `negative_prompt`.
|
|
52
|
+
- **quantize**:
|
|
53
|
+
`quantize` can specify `3` / `4` / `5` / `6` / `8`. If omitted, the default value for each model will be used.
|
|
54
|
+
`turbo` uses a 4-bit pre-quantized repo, so it is usually omitted.
|
|
55
|
+
- **LoRA applied**:
|
|
56
|
+
Pass `[{ "file": {"type": "file_id", "file_id": "..."}, "scale": 1.0 }]` to `loras` of `generate`.
|
|
57
|
+
By default, up to 4 can be applied. Adapter files must be stored in the Files API.
|
|
58
|
+
- **transient model**:
|
|
59
|
+
mflux fixes the quantization level and LoRA during model construction. has `loras`, or
|
|
60
|
+
A request to override `quantize` from its default value builds a temporary model for that call.
|
|
61
|
+
It is slower than a plain `turbo` / `base` call because it does not reuse the resident model.
|
|
62
|
+
- **Output format**:
|
|
63
|
+
`format` is `png` (default) / `jpeg` / `webp`. `quality` for `jpeg` / `webp`
|
|
64
|
+
Use `1..100` (default `90`).
|
|
65
|
+
- **LoRA training dataset**:
|
|
66
|
+
Place images at the top level of the ZIP or in a single subfolder within the ZIP. per image
|
|
67
|
+
Requires a `.txt` caption with the same stem.
|
|
68
|
+
|
|
69
|
+
## Quickstart
|
|
70
|
+
|
|
71
|
+
### generate - generate image from text
|
|
72
|
+
|
|
73
|
+
Save only the image:
|
|
74
|
+
```bash
|
|
75
|
+
PARAMS=$(
|
|
76
|
+
jq -n \
|
|
77
|
+
--arg prompt "a red fox in fresh snow, soft morning light, realistic photo" \
|
|
78
|
+
'{
|
|
79
|
+
model: "turbo",
|
|
80
|
+
mode: "sync",
|
|
81
|
+
prompt: $prompt,
|
|
82
|
+
width: 1024,
|
|
83
|
+
height: 1024,
|
|
84
|
+
seed: 1
|
|
85
|
+
}'
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
89
|
+
-H 'Content-Type: application/json' \
|
|
90
|
+
--data-binary "$PARAMS" \
|
|
91
|
+
-o zimage.png
|
|
92
|
+
```
|
|
93
|
+
Returns Job JSON:
|
|
94
|
+
```bash
|
|
95
|
+
PARAMS=$(
|
|
96
|
+
jq -n \
|
|
97
|
+
--arg prompt "a small robot watering flowers, clean studio illustration" \
|
|
98
|
+
--arg negative_prompt "blurry, low quality" \
|
|
99
|
+
'{
|
|
100
|
+
model: "base",
|
|
101
|
+
mode: "sync",
|
|
102
|
+
prompt: $prompt,
|
|
103
|
+
negative_prompt: $negative_prompt,
|
|
104
|
+
width: 512,
|
|
105
|
+
height: 512,
|
|
106
|
+
seed: 2
|
|
107
|
+
}'
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
111
|
+
-H 'Accept: application/json' \
|
|
112
|
+
-H 'Content-Type: application/json' \
|
|
113
|
+
--data-binary "$PARAMS" |
|
|
114
|
+
jq .
|
|
115
|
+
```
|
|
116
|
+
If you need the `file_id`, you can read it from the response header.
|
|
117
|
+
```bash
|
|
118
|
+
PARAMS=$(
|
|
119
|
+
jq -n \
|
|
120
|
+
--arg prompt "a red fox in fresh snow" \
|
|
121
|
+
'{
|
|
122
|
+
mode: "sync",
|
|
123
|
+
prompt: $prompt,
|
|
124
|
+
width: 512,
|
|
125
|
+
height: 512,
|
|
126
|
+
seed: 1
|
|
127
|
+
}'
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
FILE_ID=$(curl -sS -D - -o zimage.png \
|
|
131
|
+
-X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
132
|
+
-H 'Content-Type: application/json' \
|
|
133
|
+
--data-binary "$PARAMS" \
|
|
134
|
+
| awk -F': ' 'tolower($1)=="x-kiapi-file-id"{print $2}' | tr -d '\r')
|
|
135
|
+
|
|
136
|
+
echo "$FILE_ID"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### async
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
PARAMS=$(
|
|
143
|
+
jq -n \
|
|
144
|
+
--arg prompt "a cinematic product photo of a glass teapot" \
|
|
145
|
+
'{
|
|
146
|
+
model: "turbo",
|
|
147
|
+
mode: "async",
|
|
148
|
+
prompt: $prompt,
|
|
149
|
+
width: 512,
|
|
150
|
+
height: 512,
|
|
151
|
+
seed: 11
|
|
152
|
+
}'
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
JOB=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
156
|
+
-H 'Accept: application/json' \
|
|
157
|
+
-H 'Content-Type: application/json' \
|
|
158
|
+
--data-binary "$PARAMS" |
|
|
159
|
+
jq -r .job_id)
|
|
160
|
+
|
|
161
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
162
|
+
```
|
|
163
|
+
After completion, use the Job's `artifacts[0]` or `result.file_id` to get the image.
|
|
164
|
+
```bash
|
|
165
|
+
FID=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.file_id)
|
|
166
|
+
curl -sS http://localhost:${PORT:-8000}/v1/files/$FID/download -o zimage-async.png
|
|
167
|
+
```
|
|
168
|
+
### train - LoRA Fine Tuning
|
|
169
|
+
|
|
170
|
+
Prepare a ZIP dataset containing a `.txt` caption with the same stem as the image.
|
|
171
|
+
```text
|
|
172
|
+
dataset/
|
|
173
|
+
sample_00.png
|
|
174
|
+
sample_00.txt
|
|
175
|
+
sample_01.png
|
|
176
|
+
sample_01.txt
|
|
177
|
+
```
|
|
178
|
+
Create a dataset ZIP and upload it to the Files API.
|
|
179
|
+
```bash
|
|
180
|
+
(cd dataset && zip -q -r - .) > dataset.zip
|
|
181
|
+
|
|
182
|
+
DATASET_ID=$(curl -sS -X POST http://localhost:${PORT:-8000}/v1/files \
|
|
183
|
+
-F "file=@dataset.zip;type=application/zip" | jq -r .file_id)
|
|
184
|
+
```
|
|
185
|
+
Start learning. train is always async.
|
|
186
|
+
```bash
|
|
187
|
+
JOB=$(
|
|
188
|
+
jq -n \
|
|
189
|
+
--arg dataset "$DATASET_ID" \
|
|
190
|
+
'{
|
|
191
|
+
model: "turbo",
|
|
192
|
+
dataset: {type: "file_id", file_id: $dataset},
|
|
193
|
+
num_epochs: 10,
|
|
194
|
+
lora_rank: 16,
|
|
195
|
+
max_resolution: 512
|
|
196
|
+
}' |
|
|
197
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/train \
|
|
198
|
+
-H 'Content-Type: application/json' \
|
|
199
|
+
--data-binary @- |
|
|
200
|
+
jq -r .job_id
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq .
|
|
204
|
+
```
|
|
205
|
+
After completion, `result.adapter_file_id` is the learned adapter.
|
|
206
|
+
```bash
|
|
207
|
+
ADAPTER=$(curl -sS http://localhost:${PORT:-8000}/v1/jobs/$JOB | jq -r .result.adapter_file_id)
|
|
208
|
+
```
|
|
209
|
+
Apply LoRA on generation.
|
|
210
|
+
```bash
|
|
211
|
+
PARAMS=$(
|
|
212
|
+
jq -n \
|
|
213
|
+
--arg prompt "<your trigger word> in a magical garden" \
|
|
214
|
+
--arg adapter "$ADAPTER" \
|
|
215
|
+
'{
|
|
216
|
+
model: "turbo",
|
|
217
|
+
mode: "sync",
|
|
218
|
+
prompt: $prompt,
|
|
219
|
+
width: 512,
|
|
220
|
+
height: 512,
|
|
221
|
+
seed: 7,
|
|
222
|
+
loras: [{file: {type: "file_id", file_id: $adapter}, scale: 1.0}]
|
|
223
|
+
}'
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
curl -sS -X POST http://localhost:${PORT:-8000}/v1/image/zimage/generate \
|
|
227
|
+
-H 'Content-Type: application/json' \
|
|
228
|
+
--data-binary "$PARAMS" \
|
|
229
|
+
-o zimage-lora.png
|
|
230
|
+
```
|
|
231
|
+
`scale` is the strength of the effect. Every request using `loras` builds a temporary model.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""zimage family - Z-Image text-to-image generation via mflux.
|
|
2
|
+
|
|
3
|
+
Endpoint: ``POST /v1/image/zimage/generate`` (multipart params; txt2img).
|
|
4
|
+
Integrates mflux's Z-Image. Two variants:
|
|
5
|
+
|
|
6
|
+
- ``turbo`` (default) - distilled few-step model, pre-quantized 4-bit, fast.
|
|
7
|
+
- ``base`` - full Z-Image, more steps + guidance, higher quality / slower.
|
|
8
|
+
|
|
9
|
+
Both are resident MLX models held under the global budget. A request that adds
|
|
10
|
+
``loras`` or overrides ``quantize`` is served by a one-off transient model
|
|
11
|
+
(mflux bakes those in at load time) via ``memory.reserve()`` instead. Sync/async
|
|
12
|
+
via ``mode``; the PNG lands in the Files API.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from kiapi.capabilities import ValidationError
|
|
16
|
+
|
|
17
|
+
from ._helpers.register import register
|
|
18
|
+
from ._helpers.validate_generate import validate_generate
|
|
19
|
+
from ._operations.handle_generate import handle_generate
|
|
20
|
+
from ._operations.handle_train import handle_train
|
|
21
|
+
from ._settings import settings_manager
|
|
22
|
+
from ._views.generate_request import GenerateRequest
|
|
23
|
+
from ._views.train_request import TrainRequest
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"GenerateRequest",
|
|
27
|
+
"TrainRequest",
|
|
28
|
+
"ValidationError",
|
|
29
|
+
"handle_generate",
|
|
30
|
+
"handle_train",
|
|
31
|
+
"register",
|
|
32
|
+
"settings_manager",
|
|
33
|
+
"validate_generate",
|
|
34
|
+
]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
DESCRIPTION = """Fast text-to-image generation and LoRA training (Z-Image via mflux).
|
|
2
|
+
|
|
3
|
+
Two operations on Alibaba's Z-Image models: `/generate` (text-to-image) and
|
|
4
|
+
`/train` (LoRA finetune). Z-Image is txt2img only — there is no image-to-image
|
|
5
|
+
edit endpoint. To edit an existing image, use the ernie / qwen / flux2 families.
|
|
6
|
+
|
|
7
|
+
## Upstream docs
|
|
8
|
+
- [mflux — Z-Image](https://github.com/filipstrand/mflux/blob/main/src/mflux/models/z_image/README.md) — the MLX engine kiapi runs
|
|
9
|
+
- [Tongyi-MAI/Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image) — `base` weights
|
|
10
|
+
|
|
11
|
+
## Models
|
|
12
|
+
- **turbo** (default) — `filipstrand/Z-Image-Turbo-mflux-4bit`. Distilled,
|
|
13
|
+
few-step (default 9), pre-quantized 4-bit, no guidance. The everyday choice.
|
|
14
|
+
- **base** — `Tongyi-MAI/Z-Image`. The full model: more steps (default 28) and
|
|
15
|
+
guidance (default 4.0), 8-bit by default. Higher quality but slower.
|
|
16
|
+
|
|
17
|
+
Pick the variant with `model`; discover variants at
|
|
18
|
+
`GET /v1/image/zimage/models`. Variant-dependent defaults (`steps` / `guidance` /
|
|
19
|
+
`quantize`) are filled in server-side when omitted, and the resolved values are
|
|
20
|
+
recorded in the result `params`. `negative_prompt` is most effective on `base`
|
|
21
|
+
with guidance > 1; on the distilled `turbo` (no guidance) it has little effect.
|
|
22
|
+
|
|
23
|
+
## Resident vs transient runs
|
|
24
|
+
The warmed, resident model uses the server-default quantization. A request that
|
|
25
|
+
either supplies `loras` or sets a `quantize` differing from the resident model
|
|
26
|
+
builds a **one-off transient model** for that call — mflux bakes those in at load
|
|
27
|
+
time, so weights load fresh and the run is slower and not reused. For the fast
|
|
28
|
+
path, omit `loras` and leave `quantize` unset.
|
|
29
|
+
|
|
30
|
+
## LoRA workflow
|
|
31
|
+
Train an adapter from a captioned image set via `/train` (always async), then
|
|
32
|
+
apply it on `/generate` by passing its `adapter_file_id` in `loras` (up to 4,
|
|
33
|
+
each `{file, scale}`). Dataset = a ZIP uploaded to the Files API with a same-stem
|
|
34
|
+
`.txt` caption next to each image (`cat.png` + `cat.txt`); images may sit at the
|
|
35
|
+
top level or in a single subfolder, and `preview*` images are exempt from the
|
|
36
|
+
caption requirement.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
dataset.zip
|
|
40
|
+
├── cat_01.png # image
|
|
41
|
+
├── cat_01.txt # same-stem caption: "a photo of a tabby cat"
|
|
42
|
+
├── cat_02.jpg
|
|
43
|
+
├── cat_02.txt
|
|
44
|
+
└── preview.png # optional preview, no caption needed
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A single wrapping subfolder is also accepted (the images just need to live
|
|
48
|
+
together under one directory):
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
dataset.zip
|
|
52
|
+
└── cats/
|
|
53
|
+
├── cat_01.png
|
|
54
|
+
├── cat_01.txt
|
|
55
|
+
└── ...
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## TIPS
|
|
59
|
+
- For a quick image, call `sync` without `Accept: application/json` to get the
|
|
60
|
+
raw bytes straight back (`curl -o out.png`).
|
|
61
|
+
- `width`/`height` must be multiples of 16 and at most 2048x2048.
|
|
62
|
+
- First use downloads the Z-Image weights; run `kiapi activate` ahead of time to
|
|
63
|
+
avoid a cold-start download on the first request.
|
|
64
|
+
|
|
65
|
+
## Performance
|
|
66
|
+
- **turbo**: ~9 steps, pre-quantized 4-bit; the fast default.
|
|
67
|
+
- **base**: full model, many steps, 8-bit by default — prefer turbo unless you
|
|
68
|
+
need its quality.
|
|
69
|
+
- First request is slower while weights load + convert; then the model is
|
|
70
|
+
resident until its TTL frees it.
|
|
71
|
+
- Transient runs (any `loras` or a `quantize` override) rebuild the model each
|
|
72
|
+
call and are slower than the resident path.
|
|
73
|
+
"""
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Register zimage's models + OpenAPI description in the global registries."""
|
|
2
|
+
|
|
3
|
+
from kiapi.core.capability import CapabilitySpec, capability_spec_registry
|
|
4
|
+
from kiapi.core.model import ModelSpec, model_registry
|
|
5
|
+
from kiapi.core.setup import HfSnapshotResource
|
|
6
|
+
|
|
7
|
+
from .._constants.description import DESCRIPTION
|
|
8
|
+
from .._models import zimage
|
|
9
|
+
from .._settings import settings_manager
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def register() -> None:
|
|
13
|
+
capability_spec_registry.register(
|
|
14
|
+
CapabilitySpec(
|
|
15
|
+
name="zimage",
|
|
16
|
+
domain="image",
|
|
17
|
+
title="kiapi Z-Image API",
|
|
18
|
+
summary="Generate images and train LoRA adapters with Z-Image models.",
|
|
19
|
+
description=DESCRIPTION,
|
|
20
|
+
openapi_path="/v1/image/zimage/openapi.json",
|
|
21
|
+
docs_path="/v1/image/zimage/docs",
|
|
22
|
+
redoc_path="/v1/image/zimage/redoc",
|
|
23
|
+
path_prefixes=("/v1/image/zimage",),
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
settings = settings_manager.get_settings()
|
|
28
|
+
|
|
29
|
+
model_registry.register(
|
|
30
|
+
ModelSpec(
|
|
31
|
+
name="turbo",
|
|
32
|
+
family="zimage",
|
|
33
|
+
domain="image",
|
|
34
|
+
repo=settings.turbo_repo,
|
|
35
|
+
module=zimage,
|
|
36
|
+
weight_gb=6.0,
|
|
37
|
+
peak_headroom_gb=8.0,
|
|
38
|
+
framework="mlx",
|
|
39
|
+
priority=0,
|
|
40
|
+
default=True,
|
|
41
|
+
setup_resources=(
|
|
42
|
+
HfSnapshotResource(repo=settings.turbo_repo, disk_gb=5.5),
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
model_registry.register(
|
|
48
|
+
ModelSpec(
|
|
49
|
+
name="base",
|
|
50
|
+
family="zimage",
|
|
51
|
+
domain="image",
|
|
52
|
+
repo=settings.base_repo,
|
|
53
|
+
module=zimage,
|
|
54
|
+
weight_gb=12.0,
|
|
55
|
+
peak_headroom_gb=16.0,
|
|
56
|
+
framework="mlx",
|
|
57
|
+
priority=0,
|
|
58
|
+
setup_resources=(
|
|
59
|
+
HfSnapshotResource(repo=settings.base_repo, disk_gb=19.0),
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from kiapi.capabilities import ValidationError
|
|
2
|
+
|
|
3
|
+
from .._settings import ZimageSettings, settings_manager
|
|
4
|
+
from .._views.generate_request import GenerateRequest
|
|
5
|
+
|
|
6
|
+
_MULTIPLE = 16
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def validate_generate(req: GenerateRequest, *, variant: str) -> None:
|
|
10
|
+
settings = settings_manager.get_settings()
|
|
11
|
+
_validate_generate(req, settings, variant=variant)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _validate_generate(
|
|
15
|
+
req: GenerateRequest, settings: ZimageSettings, *, variant: str
|
|
16
|
+
) -> None:
|
|
17
|
+
width = req.width if req.width is not None else settings.default_width
|
|
18
|
+
height = req.height if req.height is not None else settings.default_height
|
|
19
|
+
|
|
20
|
+
if width <= 0 or height <= 0:
|
|
21
|
+
raise ValidationError("width and height must be positive")
|
|
22
|
+
if width % _MULTIPLE or height % _MULTIPLE:
|
|
23
|
+
raise ValidationError(f"width and height must be multiples of {_MULTIPLE}")
|
|
24
|
+
if width > settings.max_width or height > settings.max_height:
|
|
25
|
+
raise ValidationError(
|
|
26
|
+
f"size {width}x{height} exceeds the cap {settings.max_width}x{settings.max_height}"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
steps = (
|
|
30
|
+
req.steps if req.steps is not None else settings.default_steps.get(variant, 9)
|
|
31
|
+
)
|
|
32
|
+
if steps < 1 or steps > settings.max_steps:
|
|
33
|
+
raise ValidationError(f"steps must be in 1..{settings.max_steps}")
|
|
34
|
+
if req.quantize is not None and req.quantize not in (3, 4, 5, 6, 8):
|
|
35
|
+
raise ValidationError("quantize must be one of 3, 4, 5, 6, 8")
|
|
36
|
+
if len(req.loras) > settings.max_loras:
|
|
37
|
+
raise ValidationError(f"at most {settings.max_loras} loras may be applied")
|