Skip to content

Commit

Permalink
Merge branch 'master' into update_ggml
Browse files Browse the repository at this point in the history
  • Loading branch information
leejet committed Jan 5, 2024
2 parents cd4cac5 + db38234 commit a4237ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,27 @@ if(SD_FLASH_ATTN)
add_definitions(-DSD_USE_FLASH_ATTENTION)
endif()

set(SD_LIB stable-diffusion)

add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp model.h model.cpp util.h util.cpp upscaler.cpp
ggml_extend.hpp clip.hpp common.hpp unet.hpp tae.hpp esrgan.hpp lora.hpp denoiser.hpp rng.hpp rng_philox.hpp)

if(BUILD_SHARED_LIBS)
message("Build shared library")
add_definitions(-DSD_BUILD_SHARED_LIB)
target_compile_definitions(${SD_LIB} PRIVATE -DSD_BUILD_DLL)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
else()
message("Build static library")
endif()


set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
# deps
add_subdirectory(ggml)

add_subdirectory(thirdparty)

set(SD_LIB stable-diffusion)

add_library(${SD_LIB} stable-diffusion.h stable-diffusion.cpp model.h model.cpp util.h util.cpp upscaler.cpp
ggml_extend.hpp clip.hpp common.hpp unet.hpp tae.hpp esrgan.hpp lora.hpp denoiser.hpp rng.hpp rng_philox.hpp)
target_link_libraries(${SD_LIB} PUBLIC ggml zip)
target_include_directories(${SD_LIB} PUBLIC . thirdparty)
target_compile_features(${SD_LIB} PUBLIC cxx_std_11)
Expand Down
9 changes: 6 additions & 3 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@ void sd_log_cb(enum sd_log_level_t level, const char* log, void* data) {
return;
}
if (level <= SD_LOG_INFO) {
fprintf(stdout, log);
fputs(log, stdout);
fflush(stdout);
} else {
fprintf(stderr, log);
fputs(log, stderr);
fflush(stderr);
}
};
}

int main(int argc, const char* argv[]) {
SDParams params;
Expand Down Expand Up @@ -560,6 +560,7 @@ int main(int argc, const char* argv[]) {

if (results == NULL) {
printf("generate failed\n");
free_sd_ctx(sd_ctx);
return 1;
}

Expand Down Expand Up @@ -600,6 +601,8 @@ int main(int argc, const char* argv[]) {
free(results[i].data);
results[i].data = NULL;
}
free(results);
free_sd_ctx(sd_ctx);

return 0;
}
1 change: 1 addition & 0 deletions model.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <string>
#include <vector>
#include <set>

#include "ggml/ggml-backend.h"
#include "ggml/ggml.h"
Expand Down
5 changes: 3 additions & 2 deletions stable-diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class StableDiffusionGGML {
}

~StableDiffusionGGML() {
ggml_backend_free(backend);
}

bool load_from_file(const std::string& model_path,
Expand Down Expand Up @@ -626,7 +627,7 @@ class StableDiffusionGGML {

// get_ancestral_step
float sigma_up = std::min(sigmas[i + 1],
std::sqrt(sigmas[i + 1] * sigmas[i + 1] * (sigmas[i] * sigmas[i] - sigmas[i + 1] * sigmas[i + 1]) / (sigmas[i] * sigmas[i])));
std::sqrt(sigmas[i + 1] * sigmas[i + 1] * (sigmas[i] * sigmas[i] - sigmas[i + 1] * sigmas[i + 1]) / (sigmas[i] * sigmas[i])));
float sigma_down = std::sqrt(sigmas[i + 1] * sigmas[i + 1] - sigma_up * sigma_up);

// Euler method
Expand Down Expand Up @@ -802,7 +803,7 @@ class StableDiffusionGGML {

// get_ancestral_step
float sigma_up = std::min(sigmas[i + 1],
std::sqrt(sigmas[i + 1] * sigmas[i + 1] * (sigmas[i] * sigmas[i] - sigmas[i + 1] * sigmas[i + 1]) / (sigmas[i] * sigmas[i])));
std::sqrt(sigmas[i + 1] * sigmas[i + 1] * (sigmas[i] * sigmas[i] - sigmas[i + 1] * sigmas[i + 1]) / (sigmas[i] * sigmas[i])));
float sigma_down = std::sqrt(sigmas[i + 1] * sigmas[i + 1] - sigma_up * sigma_up);
auto t_fn = [](float sigma) -> float { return -log(sigma); };
auto sigma_fn = [](float t) -> float { return exp(-t); };
Expand Down

0 comments on commit a4237ec

Please sign in to comment.