okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c106e9629
main
1"""tools/image/sdcpp_native/apply.py - put Strata's native Qwen-Image-2.1 DiT runner into a stable-diffusion.cpp 2checkout at the pinned commit (tools/image/qimage.py SD_CPP_COMMIT). Idempotent; the stock runner stays the 3default: sd-cli uses the native one only with --model-args qwen_image_2_1_native=1 (serve/images.py adds it when the 4config's "native" is true), and only in CUDA / HIP builds. 5 6python tools/image/sdcpp_native/apply.py third_party/stable-diffusion.cpp 7 8Two new files (the kernels into ggml/src/ggml-cuda/, which ggml-cuda and ggml-hip compile by glob; the runner into 9src/model/diffusion/) and two small edits (model_builders.cpp picks the runner; CMakeLists.txt defines SD_QI_NATIVE 10for CUDA / HIP builds).""" 11from __future__import annotations 12 13import shutil 14import sys 15from pathlib import Path 16 17HERE = Path (__file__ ).resolve ().parent 18MARK = "// strata: native Qwen-Image-2.1 runner" 19 20BUILDER_OLD = """ if (version == VERSION_QWEN_IMAGE_2_1) { 21result.diffusion = std::make_shared<Qwen::QwenImage21Runner>(ctx.backends.runtime_backend(SDBackendModule::DIFFUSION), 22tensor_storage_map, 23"model.diffusion_model", 24weight_manager, 25sd_ctx_params->model_args); 26""" 27BUILDER_NEW = """ if (version == VERSION_QWEN_IMAGE_2_1) { 28#ifdef SD_QI_NATIVE 29""" + MARK + """ (--model-args qwen_image_2_1_native=1) 30if (sd_ctx_params->model_args != nullptr && 31std::strstr(sd_ctx_params->model_args, "qwen_image_2_1_native=1") != nullptr && 32sd_ctx_params->diffusion_model_path != nullptr && sd_ctx_params->diffusion_model_path[0] != 0) { 33result.diffusion = std::make_shared<Qwen::QwenImage21NativeRunner>(ctx.backends.runtime_backend(SDBackendModule::DIFFUSION), 34tensor_storage_map, 35"model.diffusion_model", 36weight_manager, 37sd_ctx_params->model_args, 38sd_ctx_params->diffusion_model_path); 39} else 40#endif 41result.diffusion = std::make_shared<Qwen::QwenImage21Runner>(ctx.backends.runtime_backend(SDBackendModule::DIFFUSION), 42tensor_storage_map, 43"model.diffusion_model", 44weight_manager, 45sd_ctx_params->model_args); 46""" 47INCLUDE_OLD = '#include "model/diffusion/minit2i.hpp"\n' 48INCLUDE_NEW = INCLUDE_OLD + "#ifdef SD_QI_NATIVE\n#include \"model/diffusion/qwen_image_2_1_native.hpp\" " + MARK + "\n#endif\n" 49CMAKE_OLD = "target_include_directories(${SD_LIB} PUBLIC . src include)\n" 50CMAKE_NEW = ("if (SD_CUDA OR SD_HIPBLAS) # " + MARK .lstrip ("/ " )+ "\n" 51" target_compile_definitions(${SD_LIB} PRIVATE SD_QI_NATIVE)\nendif()\n" + CMAKE_OLD ) 52 53 54def edit (path :Path ,old :str ,new :str )-> None : 55text = path .read_text (encoding = "utf-8" ) 56if new in text : 57return 58if text .count (old )!= 1 : 59raise SystemExit (f" { path } : the expected code is not there (another stable-diffusion.cpp commit?)" ) 60path .write_text (text .replace (old ,new ),encoding = "utf-8" ) 61 62 63def apply (sd :Path )-> None : 64sd = Path (sd ) 65shutil .copy2 (HERE / "qi21-native.cu" ,sd / "ggml" / "src" / "ggml-cuda" / "qi21-native.cu" ) 66shutil .copy2 (HERE / "qwen_image_2_1_native.hpp" ,sd / "src" / "model" / "diffusion" / "qwen_image_2_1_native.hpp" ) 67builders = sd / "src" / "pipeline" / "model_builders.cpp" 68edit (builders ,INCLUDE_OLD ,INCLUDE_NEW ) 69edit (builders ,BUILDER_OLD ,BUILDER_NEW ) 70edit (sd / "CMakeLists.txt" ,CMAKE_OLD ,CMAKE_NEW ) 71 72 73if __name__ == "__main__" : 74apply (Path (sys .argv [1 ])) 75"native Qwen-Image-2.1 runner applied" )