|
@@ -5,6 +5,7 @@
|
|
|
#include <cstring>
|
|
#include <cstring>
|
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
#include <filesystem>
|
|
#include <filesystem>
|
|
|
|
|
+#include <thread>
|
|
|
|
|
|
|
|
extern "C" {
|
|
extern "C" {
|
|
|
#include "stable-diffusion.h"
|
|
#include "stable-diffusion.h"
|
|
@@ -15,6 +16,7 @@ public:
|
|
|
sd_ctx_t* sdContext = nullptr;
|
|
sd_ctx_t* sdContext = nullptr;
|
|
|
std::string lastError;
|
|
std::string lastError;
|
|
|
std::mutex contextMutex;
|
|
std::mutex contextMutex;
|
|
|
|
|
+ bool verbose = false;
|
|
|
|
|
|
|
|
Impl() {
|
|
Impl() {
|
|
|
// Initialize any required resources
|
|
// Initialize any required resources
|
|
@@ -26,6 +28,9 @@ public:
|
|
|
|
|
|
|
|
bool loadModel(const std::string& modelPath, const StableDiffusionWrapper::GenerationParams& params) {
|
|
bool loadModel(const std::string& modelPath, const StableDiffusionWrapper::GenerationParams& params) {
|
|
|
std::lock_guard<std::mutex> lock(contextMutex);
|
|
std::lock_guard<std::mutex> lock(contextMutex);
|
|
|
|
|
+
|
|
|
|
|
+ // Store verbose flag for use in other functions
|
|
|
|
|
+ verbose = params.verbose;
|
|
|
|
|
|
|
|
// Unload any existing model
|
|
// Unload any existing model
|
|
|
if (sdContext) {
|
|
if (sdContext) {
|
|
@@ -39,7 +44,9 @@ public:
|
|
|
|
|
|
|
|
// Get absolute path for logging
|
|
// Get absolute path for logging
|
|
|
std::filesystem::path absModelPath = std::filesystem::absolute(modelPath);
|
|
std::filesystem::path absModelPath = std::filesystem::absolute(modelPath);
|
|
|
- std::cout << "Loading model from absolute path: " << absModelPath << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Loading model from absolute path: " << absModelPath << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Create persistent string copies to fix lifetime issues
|
|
// Create persistent string copies to fix lifetime issues
|
|
|
// These strings will remain valid for the entire lifetime of the context
|
|
// These strings will remain valid for the entire lifetime of the context
|
|
@@ -74,32 +81,44 @@ public:
|
|
|
// Check if this is a Qwen model based on filename
|
|
// Check if this is a Qwen model based on filename
|
|
|
if (modelFileName.find("qwen") != std::string::npos) {
|
|
if (modelFileName.find("qwen") != std::string::npos) {
|
|
|
isQwenModel = true;
|
|
isQwenModel = true;
|
|
|
- std::cout << "Detected Qwen model from filename: " << modelFileName << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Detected Qwen model from filename: " << modelFileName << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Enhanced path selection logic
|
|
// Enhanced path selection logic
|
|
|
if (parentDirName == "diffusion_models" || parentDirName == "diffusion") {
|
|
if (parentDirName == "diffusion_models" || parentDirName == "diffusion") {
|
|
|
useDiffusionModelPath = true;
|
|
useDiffusionModelPath = true;
|
|
|
- std::cout << "Model is in " << parentDirName << " directory, using diffusion_model_path" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Model is in " << parentDirName << " directory, using diffusion_model_path" << std::endl;
|
|
|
|
|
+ }
|
|
|
} else if (parentDirName == "checkpoints" || parentDirName == "stable-diffusion") {
|
|
} else if (parentDirName == "checkpoints" || parentDirName == "stable-diffusion") {
|
|
|
useDiffusionModelPath = false;
|
|
useDiffusionModelPath = false;
|
|
|
- std::cout << "Model is in " << parentDirName << " directory, using model_path" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Model is in " << parentDirName << " directory, using model_path" << std::endl;
|
|
|
|
|
+ }
|
|
|
} else if (parentDirName == "sd_models" || parentDirName.empty()) {
|
|
} else if (parentDirName == "sd_models" || parentDirName.empty()) {
|
|
|
// Handle models in root /data/SD_MODELS/ directory
|
|
// Handle models in root /data/SD_MODELS/ directory
|
|
|
if (isQwenModel) {
|
|
if (isQwenModel) {
|
|
|
// Qwen models should use diffusion_model_path regardless of directory
|
|
// Qwen models should use diffusion_model_path regardless of directory
|
|
|
useDiffusionModelPath = true;
|
|
useDiffusionModelPath = true;
|
|
|
detectionSource = "qwen_root_detection";
|
|
detectionSource = "qwen_root_detection";
|
|
|
- std::cout << "Qwen model in root directory, preferring diffusion_model_path" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Qwen model in root directory, preferring diffusion_model_path" << std::endl;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
// For non-Qwen models in root, try architecture detection
|
|
// For non-Qwen models in root, try architecture detection
|
|
|
- std::cout << "Model is in root directory '" << parentDirName << "', attempting architecture detection" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Model is in root directory '" << parentDirName << "', attempting architecture detection" << std::endl;
|
|
|
|
|
+ }
|
|
|
detectionSource = "architecture_fallback";
|
|
detectionSource = "architecture_fallback";
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
detectionResult = ModelDetector::detectModel(modelPath);
|
|
detectionResult = ModelDetector::detectModel(modelPath);
|
|
|
detectionSuccessful = true;
|
|
detectionSuccessful = true;
|
|
|
- std::cout << "Architecture detection found: " << detectionResult.architectureName << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Architecture detection found: " << detectionResult.architectureName << std::endl;
|
|
|
|
|
+ }
|
|
|
} catch (const std::exception& e) {
|
|
} catch (const std::exception& e) {
|
|
|
std::cerr << "Warning: Architecture detection failed: " << e.what() << ". Using default loading method." << std::endl;
|
|
std::cerr << "Warning: Architecture detection failed: " << e.what() << ". Using default loading method." << std::endl;
|
|
|
detectionResult.architecture = ModelArchitecture::UNKNOWN;
|
|
detectionResult.architecture = ModelArchitecture::UNKNOWN;
|
|
@@ -127,7 +146,9 @@ public:
|
|
|
default:
|
|
default:
|
|
|
// Unknown architectures fall back to model_path for backward compatibility
|
|
// Unknown architectures fall back to model_path for backward compatibility
|
|
|
useDiffusionModelPath = false;
|
|
useDiffusionModelPath = false;
|
|
|
- std::cout << "Warning: Unknown model architecture detected, using default model_path for backward compatibility" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Warning: Unknown model architecture detected, using default model_path for backward compatibility" << std::endl;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -137,13 +158,17 @@ public:
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// Unknown directory - try architecture detection
|
|
// Unknown directory - try architecture detection
|
|
|
- std::cout << "Model is in unknown directory '" << parentDirName << "', attempting architecture detection as fallback" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Model is in unknown directory '" << parentDirName << "', attempting architecture detection as fallback" << std::endl;
|
|
|
|
|
+ }
|
|
|
detectionSource = "architecture_fallback";
|
|
detectionSource = "architecture_fallback";
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
detectionResult = ModelDetector::detectModel(modelPath);
|
|
detectionResult = ModelDetector::detectModel(modelPath);
|
|
|
detectionSuccessful = true;
|
|
detectionSuccessful = true;
|
|
|
- std::cout << "Fallback detection found architecture: " << detectionResult.architectureName << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Fallback detection found architecture: " << detectionResult.architectureName << std::endl;
|
|
|
|
|
+ }
|
|
|
} catch (const std::exception& e) {
|
|
} catch (const std::exception& e) {
|
|
|
std::cerr << "Warning: Fallback model detection failed: " << e.what() << ". Using default loading method." << std::endl;
|
|
std::cerr << "Warning: Fallback model detection failed: " << e.what() << ". Using default loading method." << std::endl;
|
|
|
detectionResult.architecture = ModelArchitecture::UNKNOWN;
|
|
detectionResult.architecture = ModelArchitecture::UNKNOWN;
|
|
@@ -171,7 +196,9 @@ public:
|
|
|
default:
|
|
default:
|
|
|
// Unknown architectures fall back to model_path for backward compatibility
|
|
// Unknown architectures fall back to model_path for backward compatibility
|
|
|
useDiffusionModelPath = false;
|
|
useDiffusionModelPath = false;
|
|
|
- std::cout << "Warning: Unknown model architecture detected, using default model_path for backward compatibility" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Warning: Unknown model architecture detected, using default model_path for backward compatibility" << std::endl;
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -184,48 +211,68 @@ public:
|
|
|
if (useDiffusionModelPath) {
|
|
if (useDiffusionModelPath) {
|
|
|
ctxParams.diffusion_model_path = persistentModelPath.c_str();
|
|
ctxParams.diffusion_model_path = persistentModelPath.c_str();
|
|
|
ctxParams.model_path = nullptr; // Clear the traditional path
|
|
ctxParams.model_path = nullptr; // Clear the traditional path
|
|
|
- std::cout << "Using diffusion_model_path (source: " << detectionSource << ")" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using diffusion_model_path (source: " << detectionSource << ")" << std::endl;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
ctxParams.model_path = persistentModelPath.c_str();
|
|
ctxParams.model_path = persistentModelPath.c_str();
|
|
|
ctxParams.diffusion_model_path = nullptr; // Clear the modern path
|
|
ctxParams.diffusion_model_path = nullptr; // Clear the modern path
|
|
|
- std::cout << "Using model_path (source: " << detectionSource << ")" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using model_path (source: " << detectionSource << ")" << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Set optional model paths using persistent strings to fix lifetime issues
|
|
// Set optional model paths using persistent strings to fix lifetime issues
|
|
|
if (!persistentClipLPath.empty()) {
|
|
if (!persistentClipLPath.empty()) {
|
|
|
ctxParams.clip_l_path = persistentClipLPath.c_str();
|
|
ctxParams.clip_l_path = persistentClipLPath.c_str();
|
|
|
- std::cout << "Using CLIP-L path: " << std::filesystem::absolute(persistentClipLPath) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using CLIP-L path: " << std::filesystem::absolute(persistentClipLPath) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!persistentClipGPath.empty()) {
|
|
if (!persistentClipGPath.empty()) {
|
|
|
ctxParams.clip_g_path = persistentClipGPath.c_str();
|
|
ctxParams.clip_g_path = persistentClipGPath.c_str();
|
|
|
- std::cout << "Using CLIP-G path: " << std::filesystem::absolute(persistentClipGPath) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using CLIP-G path: " << std::filesystem::absolute(persistentClipGPath) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!persistentVaePath.empty()) {
|
|
if (!persistentVaePath.empty()) {
|
|
|
// Check if VAE file exists before setting it
|
|
// Check if VAE file exists before setting it
|
|
|
if (std::filesystem::exists(persistentVaePath)) {
|
|
if (std::filesystem::exists(persistentVaePath)) {
|
|
|
ctxParams.vae_path = persistentVaePath.c_str();
|
|
ctxParams.vae_path = persistentVaePath.c_str();
|
|
|
- std::cout << "Using VAE path: " << std::filesystem::absolute(persistentVaePath) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using VAE path: " << std::filesystem::absolute(persistentVaePath) << std::endl;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- std::cout << "VAE file not found: " << std::filesystem::absolute(persistentVaePath)
|
|
|
|
|
- << " - continuing without VAE" << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "VAE file not found: " << std::filesystem::absolute(persistentVaePath)
|
|
|
|
|
+ << " - continuing without VAE" << std::endl;
|
|
|
|
|
+ }
|
|
|
ctxParams.vae_path = nullptr;
|
|
ctxParams.vae_path = nullptr;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!persistentTaesdPath.empty()) {
|
|
if (!persistentTaesdPath.empty()) {
|
|
|
ctxParams.taesd_path = persistentTaesdPath.c_str();
|
|
ctxParams.taesd_path = persistentTaesdPath.c_str();
|
|
|
- std::cout << "Using TAESD path: " << std::filesystem::absolute(persistentTaesdPath) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using TAESD path: " << std::filesystem::absolute(persistentTaesdPath) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!persistentControlNetPath.empty()) {
|
|
if (!persistentControlNetPath.empty()) {
|
|
|
ctxParams.control_net_path = persistentControlNetPath.c_str();
|
|
ctxParams.control_net_path = persistentControlNetPath.c_str();
|
|
|
- std::cout << "Using ControlNet path: " << std::filesystem::absolute(persistentControlNetPath) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using ControlNet path: " << std::filesystem::absolute(persistentControlNetPath) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!persistentLoraModelDir.empty()) {
|
|
if (!persistentLoraModelDir.empty()) {
|
|
|
ctxParams.lora_model_dir = persistentLoraModelDir.c_str();
|
|
ctxParams.lora_model_dir = persistentLoraModelDir.c_str();
|
|
|
- std::cout << "Using LoRA model directory: " << std::filesystem::absolute(persistentLoraModelDir) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using LoRA model directory: " << std::filesystem::absolute(persistentLoraModelDir) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!persistentEmbeddingDir.empty()) {
|
|
if (!persistentEmbeddingDir.empty()) {
|
|
|
ctxParams.embedding_dir = persistentEmbeddingDir.c_str();
|
|
ctxParams.embedding_dir = persistentEmbeddingDir.c_str();
|
|
|
- std::cout << "Using embedding directory: " << std::filesystem::absolute(persistentEmbeddingDir) << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Using embedding directory: " << std::filesystem::absolute(persistentEmbeddingDir) << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Set performance parameters
|
|
// Set performance parameters
|
|
@@ -241,7 +288,9 @@ public:
|
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
|
|
|
|
|
|
// Create the stable-diffusion context
|
|
// Create the stable-diffusion context
|
|
|
- std::cout << "Attempting to create stable-diffusion context with selected parameters..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Attempting to create stable-diffusion context with selected parameters..." << std::endl;
|
|
|
|
|
+ }
|
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
|
if (!sdContext) {
|
|
if (!sdContext) {
|
|
|
lastError = "Failed to create stable-diffusion context";
|
|
lastError = "Failed to create stable-diffusion context";
|
|
@@ -249,7 +298,9 @@ public:
|
|
|
|
|
|
|
|
// If we used diffusion_model_path and it failed, try fallback to model_path
|
|
// If we used diffusion_model_path and it failed, try fallback to model_path
|
|
|
if (useDiffusionModelPath) {
|
|
if (useDiffusionModelPath) {
|
|
|
- std::cout << "Warning: Failed to load with diffusion_model_path. Attempting fallback to model_path..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Warning: Failed to load with diffusion_model_path. Attempting fallback to model_path..." << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Re-initialize context parameters
|
|
// Re-initialize context parameters
|
|
|
sd_ctx_params_init(&ctxParams);
|
|
sd_ctx_params_init(&ctxParams);
|
|
@@ -298,7 +349,9 @@ public:
|
|
|
// Re-apply model type
|
|
// Re-apply model type
|
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
|
|
|
|
|
|
- std::cout << "Attempting to create context with fallback model_path..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Attempting to create context with fallback model_path..." << std::endl;
|
|
|
|
|
+ }
|
|
|
// Try creating context again with fallback
|
|
// Try creating context again with fallback
|
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
|
if (!sdContext) {
|
|
if (!sdContext) {
|
|
@@ -307,7 +360,9 @@ public:
|
|
|
|
|
|
|
|
// Additional fallback: try with minimal parameters for GGUF models
|
|
// Additional fallback: try with minimal parameters for GGUF models
|
|
|
if (modelFileName.find(".gguf") != std::string::npos || modelFileName.find(".ggml") != std::string::npos) {
|
|
if (modelFileName.find(".gguf") != std::string::npos || modelFileName.find(".ggml") != std::string::npos) {
|
|
|
- std::cout << "Detected GGUF/GGML model, attempting minimal parameter fallback..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Detected GGUF/GGML model, attempting minimal parameter fallback..." << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Re-initialize with minimal parameters
|
|
// Re-initialize with minimal parameters
|
|
|
sd_ctx_params_init(&ctxParams);
|
|
sd_ctx_params_init(&ctxParams);
|
|
@@ -318,7 +373,9 @@ public:
|
|
|
ctxParams.n_threads = params.nThreads;
|
|
ctxParams.n_threads = params.nThreads;
|
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
|
|
|
|
|
|
- std::cout << "Attempting to create context with minimal GGUF parameters..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Attempting to create context with minimal GGUF parameters..." << std::endl;
|
|
|
|
|
+ }
|
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
|
|
|
|
|
|
if (!sdContext) {
|
|
if (!sdContext) {
|
|
@@ -327,17 +384,23 @@ public:
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- std::cout << "Successfully loaded GGUF model with minimal parameters: " << absModelPath << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Successfully loaded GGUF model with minimal parameters: " << absModelPath << std::endl;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- std::cout << "Successfully loaded model with fallback to model_path: " << absModelPath << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Successfully loaded model with fallback to model_path: " << absModelPath << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// Try minimal fallback for non-diffusion_model_path failures
|
|
// Try minimal fallback for non-diffusion_model_path failures
|
|
|
if (modelFileName.find(".gguf") != std::string::npos || modelFileName.find(".ggml") != std::string::npos) {
|
|
if (modelFileName.find(".gguf") != std::string::npos || modelFileName.find(".ggml") != std::string::npos) {
|
|
|
- std::cout << "Detected GGUF/GGML model, attempting minimal parameter fallback..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Detected GGUF/GGML model, attempting minimal parameter fallback..." << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Re-initialize with minimal parameters
|
|
// Re-initialize with minimal parameters
|
|
|
sd_ctx_params_init(&ctxParams);
|
|
sd_ctx_params_init(&ctxParams);
|
|
@@ -347,7 +410,9 @@ public:
|
|
|
ctxParams.n_threads = params.nThreads;
|
|
ctxParams.n_threads = params.nThreads;
|
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
ctxParams.wtype = StableDiffusionWrapper::stringToModelType(params.modelType);
|
|
|
|
|
|
|
|
- std::cout << "Attempting to create context with minimal GGUF parameters..." << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Attempting to create context with minimal GGUF parameters..." << std::endl;
|
|
|
|
|
+ }
|
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
sdContext = new_sd_ctx(&ctxParams);
|
|
|
|
|
|
|
|
if (!sdContext) {
|
|
if (!sdContext) {
|
|
@@ -356,7 +421,9 @@ public:
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- std::cout << "Successfully loaded GGUF model with minimal parameters: " << absModelPath << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Successfully loaded GGUF model with minimal parameters: " << absModelPath << std::endl;
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
std::cerr << "Error: " << lastError << std::endl;
|
|
std::cerr << "Error: " << lastError << std::endl;
|
|
|
return false;
|
|
return false;
|
|
@@ -365,14 +432,16 @@ public:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Log successful loading with detection information
|
|
// Log successful loading with detection information
|
|
|
- std::cout << "Successfully loaded model: " << absModelPath << std::endl;
|
|
|
|
|
- std::cout << " Detection source: " << detectionSource << std::endl;
|
|
|
|
|
- std::cout << " Loading method: " << (useDiffusionModelPath ? "diffusion_model_path" : "model_path") << std::endl;
|
|
|
|
|
- std::cout << " Parent directory: " << parentDirName << std::endl;
|
|
|
|
|
- std::cout << " Model filename: " << modelFileName << std::endl;
|
|
|
|
|
|
|
+ if (params.verbose) {
|
|
|
|
|
+ std::cout << "Successfully loaded model: " << absModelPath << std::endl;
|
|
|
|
|
+ std::cout << " Detection source: " << detectionSource << std::endl;
|
|
|
|
|
+ std::cout << " Loading method: " << (useDiffusionModelPath ? "diffusion_model_path" : "model_path") << std::endl;
|
|
|
|
|
+ std::cout << " Parent directory: " << parentDirName << std::endl;
|
|
|
|
|
+ std::cout << " Model filename: " << modelFileName << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Log additional model properties if architecture detection was performed
|
|
// Log additional model properties if architecture detection was performed
|
|
|
- if (detectionSuccessful) {
|
|
|
|
|
|
|
+ if (detectionSuccessful && params.verbose) {
|
|
|
std::cout << " Architecture: " << detectionResult.architectureName << std::endl;
|
|
std::cout << " Architecture: " << detectionResult.architectureName << std::endl;
|
|
|
if (detectionResult.textEncoderDim > 0) {
|
|
if (detectionResult.textEncoderDim > 0) {
|
|
|
std::cout << " Text encoder dimension: " << detectionResult.textEncoderDim << std::endl;
|
|
std::cout << " Text encoder dimension: " << detectionResult.textEncoderDim << std::endl;
|
|
@@ -390,7 +459,9 @@ public:
|
|
|
if (sdContext) {
|
|
if (sdContext) {
|
|
|
free_sd_ctx(sdContext);
|
|
free_sd_ctx(sdContext);
|
|
|
sdContext = nullptr;
|
|
sdContext = nullptr;
|
|
|
- std::cout << "Unloaded stable-diffusion model" << std::endl;
|
|
|
|
|
|
|
+ if (verbose) {
|
|
|
|
|
+ std::cout << "Unloaded stable-diffusion model" << std::endl;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -450,8 +521,12 @@ public:
|
|
|
// Generate the image
|
|
// Generate the image
|
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
|
|
|
|
|
|
- // Clear and clean up progress callback
|
|
|
|
|
|
|
+ // Clear and clean up progress callback - FIX: Wait for any pending callbacks
|
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
|
|
|
+
|
|
|
|
|
+ // Add a small delay to ensure any in-flight callbacks complete before cleanup
|
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
+
|
|
|
if (callbackData) {
|
|
if (callbackData) {
|
|
|
delete callbackData;
|
|
delete callbackData;
|
|
|
callbackData = nullptr;
|
|
callbackData = nullptr;
|
|
@@ -561,8 +636,12 @@ public:
|
|
|
// Generate the image
|
|
// Generate the image
|
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
|
|
|
|
|
|
- // Clear and clean up progress callback
|
|
|
|
|
|
|
+ // Clear and clean up progress callback - FIX: Wait for any pending callbacks
|
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
|
|
|
+
|
|
|
|
|
+ // Add a small delay to ensure any in-flight callbacks complete before cleanup
|
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
+
|
|
|
if (callbackData) {
|
|
if (callbackData) {
|
|
|
delete callbackData;
|
|
delete callbackData;
|
|
|
callbackData = nullptr;
|
|
callbackData = nullptr;
|
|
@@ -672,8 +751,12 @@ public:
|
|
|
// Generate the image
|
|
// Generate the image
|
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
|
|
|
|
|
|
- // Clear and clean up progress callback
|
|
|
|
|
|
|
+ // Clear and clean up progress callback - FIX: Wait for any pending callbacks
|
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
|
|
|
+
|
|
|
|
|
+ // Add a small delay to ensure any in-flight callbacks complete before cleanup
|
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
+
|
|
|
if (callbackData) {
|
|
if (callbackData) {
|
|
|
delete callbackData;
|
|
delete callbackData;
|
|
|
callbackData = nullptr;
|
|
callbackData = nullptr;
|
|
@@ -794,8 +877,12 @@ public:
|
|
|
// Generate the image
|
|
// Generate the image
|
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
sd_image_t* sdImages = generate_image(sdContext, &genParams);
|
|
|
|
|
|
|
|
- // Clear and clean up progress callback
|
|
|
|
|
|
|
+ // Clear and clean up progress callback - FIX: Wait for any pending callbacks
|
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
sd_set_progress_callback(nullptr, nullptr);
|
|
|
|
|
+
|
|
|
|
|
+ // Add a small delay to ensure any in-flight callbacks complete before cleanup
|
|
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
+
|
|
|
if (callbackData) {
|
|
if (callbackData) {
|
|
|
delete callbackData;
|
|
delete callbackData;
|
|
|
callbackData = nullptr;
|
|
callbackData = nullptr;
|