Skip to content

Commit c373ca2

Browse files
committed
Error handling
1 parent 0739361 commit c373ca2

File tree

11 files changed

+213
-77
lines changed

11 files changed

+213
-77
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
type: boolean
1010
push:
1111
branches:
12-
- master
12+
- dreamio
1313
- ci
1414
paths:
1515
[
@@ -78,14 +78,14 @@ jobs:
7878
7979
- name: Pack artifacts
8080
id: pack_artifacts
81-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
81+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
8282
run: |
8383
cp ggml/LICENSE ./build/bin/ggml.txt
8484
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
8585
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/*
8686
8787
- name: Upload artifacts
88-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
88+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
8989
uses: actions/upload-artifact@v4
9090
with:
9191
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
@@ -131,22 +131,22 @@ jobs:
131131
132132
- name: Pack artifacts
133133
id: pack_artifacts
134-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
134+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
135135
run: |
136136
cp ggml/LICENSE ./build/bin/ggml.txt
137137
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
138138
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/*
139139
140140
- name: Upload artifacts
141-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
141+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
142142
uses: actions/upload-artifact@v4
143143
with:
144144
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
145145
path: |
146146
sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
147147
148148
windows-latest-cmake:
149-
runs-on: windows-2025
149+
runs-on: windows-2022
150150

151151
env:
152152
VULKAN_VERSION: 1.3.261.1
@@ -163,11 +163,15 @@ jobs:
163163
- build: "avx512"
164164
defines: "-DGGML_NATIVE=OFF -DGGML_AVX512=ON -DGGML_AVX=ON -DGGML_AVX2=ON -DSD_BUILD_SHARED_LIBS=ON"
165165
- build: "cuda12"
166-
defines: "-DSD_CUDA=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES=90;89;80;75"
166+
defines: "-DSD_CUDA=ON -DSD_BUILD_SHARED_LIBS=ON"
167+
- build: "cuda12-noavx"
168+
defines: "-DGGML_NATIVE=OFF -DSD_CUDA=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DSD_BUILD_SHARED_LIBS=ON"
167169
# - build: "rocm5.5"
168170
# defines: '-G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DSD_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release -DAMDGPU_TARGETS="gfx1100;gfx1102;gfx1030" -DSD_BUILD_SHARED_LIBS=ON'
169171
- build: 'vulkan'
170172
defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON"
173+
- build: 'vulkan-noavx'
174+
defines: "-DGGML_NATIVE=OFF -DSD_VULKAN=ON -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DSD_BUILD_SHARED_LIBS=ON"
171175
steps:
172176
- name: Clone
173177
id: checkout
@@ -177,10 +181,10 @@ jobs:
177181

178182
- name: Install cuda-toolkit
179183
id: cuda-toolkit
180-
if: ${{ matrix.build == 'cuda12' }}
184+
if: ${{ matrix.build == 'cuda12' || matrix.build == 'cuda12-noavx' }}
181185
uses: Jimver/[email protected]
182186
with:
183-
cuda: "12.6.2"
187+
cuda: "12.4.0"
184188
method: "network"
185189
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
186190

@@ -199,7 +203,7 @@ jobs:
199203
version: 1.11.1
200204
- name: Install Vulkan SDK
201205
id: get_vulkan
202-
if: ${{ matrix.build == 'vulkan' }}
206+
if: ${{ matrix.build == 'vulkan' || matrix.build == 'vulkan-noavx' }}
203207
run: |
204208
curl.exe -o $env:RUNNER_TEMP/VulkanSDK-Installer.exe -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/VulkanSDK-${env:VULKAN_VERSION}-Installer.exe"
205209
& "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install
@@ -229,12 +233,12 @@ jobs:
229233
230234
- name: Get commit hash
231235
id: commit
232-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
236+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
233237
uses: pr-mpt/actions-commit-hash@v2
234238

235239
- name: Pack artifacts
236240
id: pack_artifacts
237-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
241+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
238242
run: |
239243
$filePath = ".\build\bin\Release\*"
240244
if (Test-Path $filePath) {
@@ -254,31 +258,31 @@ jobs:
254258
255259
- name: Copy and pack Cuda runtime
256260
id: pack_cuda_runtime
257-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }}
261+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }}
258262
run: |
259263
echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}"
260264
$dst='.\build\bin\cudart\'
261265
robocopy "${{steps.cuda-toolkit.outputs.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
262266
7z a cudart-sd-bin-win-cu12-x64.zip $dst\*
263267
264268
- name: Upload Cuda runtime
265-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }}
269+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' && matrix.build == 'cuda12' ) || github.event.inputs.create_release == 'true' }}
266270
uses: actions/upload-artifact@v4
267271
with:
268272
name: sd-cudart-sd-bin-win-cu12-x64.zip
269273
path: |
270274
cudart-sd-bin-win-cu12-x64.zip
271275
272276
- name: Upload artifacts
273-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
277+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
274278
uses: actions/upload-artifact@v4
275279
with:
276280
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip
277281
path: |
278282
sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip
279283
280284
release:
281-
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
285+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/dreamio' ) || github.event.inputs.create_release == 'true' }}
282286

283287
runs-on: ubuntu-latest
284288

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ test/
1010
*.gguf
1111
output*.png
1212
models*
13-
*.log
13+
*.log
14+
/.idea

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "ggml"]
22
path = ggml
3-
url = https://github.com/ggerganov/ggml.git
3+
url = https://github.com/SkutteOleg/ggml.git

conditioner.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,12 @@ struct SD3CLIPEmbedder : public Conditioner {
993993
int num_input_imgs,
994994
int adm_in_channels = -1,
995995
bool force_zero_embeddings = false) {
996-
GGML_ASSERT(0 && "Not implemented yet!");
996+
throw std::runtime_error("Not implemented yet!");
997997
}
998998

999999
std::string remove_trigger_from_prompt(ggml_context* work_ctx,
10001000
const std::string& prompt) {
1001-
GGML_ASSERT(0 && "Not implemented yet!");
1001+
throw std::runtime_error("Not implemented yet!");
10021002
}
10031003
};
10041004

@@ -1214,12 +1214,12 @@ struct FluxCLIPEmbedder : public Conditioner {
12141214
int num_input_imgs,
12151215
int adm_in_channels = -1,
12161216
bool force_zero_embeddings = false) {
1217-
GGML_ASSERT(0 && "Not implemented yet!");
1217+
throw std::runtime_error("Not implemented yet!");
12181218
}
12191219

12201220
std::string remove_trigger_from_prompt(ggml_context* work_ctx,
12211221
const std::string& prompt) {
1222-
GGML_ASSERT(0 && "Not implemented yet!");
1222+
throw std::runtime_error("Not implemented yet!");
12231223
}
12241224
};
12251225

@@ -1416,12 +1416,12 @@ struct PixArtCLIPEmbedder : public Conditioner {
14161416
int num_input_imgs,
14171417
int adm_in_channels = -1,
14181418
bool force_zero_embeddings = false) {
1419-
GGML_ASSERT(0 && "Not implemented yet!");
1419+
throw std::runtime_error("Not implemented yet!");
14201420
}
14211421

14221422
std::string remove_trigger_from_prompt(ggml_context* work_ctx,
14231423
const std::string& prompt) {
1424-
GGML_ASSERT(0 && "Not implemented yet!");
1424+
throw std::runtime_error("Not implemented yet!");
14251425
}
14261426
};
14271427

examples/cli/main.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,11 @@ int main(int argc, const char* argv[]) {
892892
params.chroma_t5_mask_pad,
893893
};
894894

895-
sd_ctx_t* sd_ctx = new_sd_ctx(&sd_ctx_params);
895+
sd_err_t err;
896+
sd_ctx_t* sd_ctx = new_sd_ctx(&sd_ctx_params, &err);
896897

897-
if (sd_ctx == NULL) {
898-
printf("new_sd_ctx_t failed\n");
898+
if (err != SD_OK) {
899+
printf("new_sd_ctx_t failed, error code: %d\n", err);
899900
return 1;
900901
}
901902

@@ -917,14 +918,21 @@ int main(int argc, const char* argv[]) {
917918
3,
918919
control_image_buffer};
919920
if (params.canny_preprocess) { // apply preprocessor
920-
control_image->data = preprocess_canny(control_image->data,
921-
control_image->width,
922-
control_image->height,
923-
0.08f,
924-
0.08f,
925-
0.8f,
926-
1.0f,
927-
false);
921+
uint8_t* canny_image_data = NULL;
922+
sd_err_t err = preprocess_canny(control_image->data,
923+
control_image->width,
924+
control_image->height,
925+
0.08f,
926+
0.08f,
927+
0.8f,
928+
1.0f,
929+
false,
930+
&canny_image_data);
931+
if (err != SD_OK) {
932+
fprintf(stderr, "canny preprocess failed, error code: %d\n", err);
933+
return 1;
934+
}
935+
control_image->data = canny_image_data;
928936
}
929937
}
930938

@@ -967,7 +975,7 @@ int main(int argc, const char* argv[]) {
967975
params.input_id_images_path.c_str(),
968976
};
969977

970-
results = generate_image(sd_ctx, &img_gen_params);
978+
results = generate_image(sd_ctx, &img_gen_params, &err);
971979
expected_num_results = params.batch_count;
972980
} else if (params.mode == VID_GEN) {
973981
sd_vid_gen_params_t vid_gen_params = {
@@ -985,7 +993,7 @@ int main(int argc, const char* argv[]) {
985993
params.augmentation_level,
986994
};
987995

988-
results = generate_video(sd_ctx, &vid_gen_params);
996+
results = generate_video(sd_ctx, &vid_gen_params, &err);
989997
expected_num_results = params.video_frames;
990998
}
991999

@@ -998,20 +1006,21 @@ int main(int argc, const char* argv[]) {
9981006
int upscale_factor = 4; // unused for RealESRGAN_x4plus_anime_6B.pth
9991007
if (params.esrgan_path.size() > 0 && params.upscale_repeats > 0) {
10001008
upscaler_ctx_t* upscaler_ctx = new_upscaler_ctx(params.esrgan_path.c_str(),
1001-
params.n_threads);
1009+
params.n_threads,
1010+
&err);
10021011

1003-
if (upscaler_ctx == NULL) {
1004-
printf("new_upscaler_ctx failed\n");
1012+
if (err != SD_OK) {
1013+
printf("new_upscaler_ctx failed, error code: %d\n", err);
10051014
} else {
10061015
for (int i = 0; i < params.batch_count; i++) {
10071016
if (results[i].data == NULL) {
10081017
continue;
10091018
}
10101019
sd_image_t current_image = results[i];
10111020
for (int u = 0; u < params.upscale_repeats; ++u) {
1012-
sd_image_t upscaled_image = upscale(upscaler_ctx, current_image, upscale_factor);
1013-
if (upscaled_image.data == NULL) {
1014-
printf("upscale failed\n");
1021+
sd_image_t upscaled_image = upscale(upscaler_ctx, current_image, upscale_factor, &err);
1022+
if (err != SD_OK) {
1023+
printf("upscale failed, error code: %d\n", err);
10151024
break;
10161025
}
10171026
free(current_image.data);

ggml

model.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,20 +2245,33 @@ int64_t ModelLoader::get_params_mem_size(ggml_backend_t backend, ggml_type type)
22452245
return mem_size;
22462246
}
22472247

2248-
bool convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type, const char* tensor_type_rules) {
2248+
sd_err_t convert(const char* input_path, const char* vae_path, const char* output_path, sd_type_t output_type, const char* tensor_type_rules) {
2249+
ggml_reset_abort();
22492250
ModelLoader model_loader;
22502251

22512252
if (!model_loader.init_from_file(input_path)) {
22522253
LOG_ERROR("init model loader from file failed: '%s'", input_path);
2253-
return false;
2254+
if (ggml_is_aborted()) {
2255+
return SD_ERR_GGML_ABORT;
2256+
}
2257+
return SD_ERR_MISSING_RESOURCE;
22542258
}
22552259

22562260
if (vae_path != NULL && strlen(vae_path) > 0) {
22572261
if (!model_loader.init_from_file(vae_path, "vae.")) {
22582262
LOG_ERROR("init model loader from file failed: '%s'", vae_path);
2259-
return false;
2263+
if (ggml_is_aborted()) {
2264+
return SD_ERR_GGML_ABORT;
2265+
}
2266+
return SD_ERR_MISSING_RESOURCE;
22602267
}
22612268
}
22622269
bool success = model_loader.save_to_gguf_file(output_path, (ggml_type)output_type, tensor_type_rules);
2263-
return success;
2270+
if (success) {
2271+
return SD_OK;
2272+
}
2273+
if (ggml_is_aborted()) {
2274+
return SD_ERR_GGML_ABORT;
2275+
}
2276+
return SD_ERR_INTERNAL;
22642277
}

preprocessing.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void threshold_hystersis(struct ggml_tensor* img, float high_threshold, float lo
162162
}
163163
}
164164

165-
uint8_t* preprocess_canny(uint8_t* img, int width, int height, float high_threshold, float low_threshold, float weak, float strong, bool inverse) {
165+
sd_err_t preprocess_canny(uint8_t* img, int width, int height, float high_threshold, float low_threshold, float weak, float strong, bool inverse, uint8_t** out_img) {
166166
struct ggml_init_params params;
167167
params.mem_size = static_cast<size_t>(10 * 1024 * 1024); // 10
168168
params.mem_buffer = NULL;
@@ -171,7 +171,7 @@ uint8_t* preprocess_canny(uint8_t* img, int width, int height, float high_thresh
171171

172172
if (!work_ctx) {
173173
LOG_ERROR("ggml_init() failed");
174-
return NULL;
174+
return SD_ERR_INTERNAL;
175175
}
176176

177177
float kX[9] = {
@@ -219,9 +219,12 @@ uint8_t* preprocess_canny(uint8_t* img, int width, int height, float high_thresh
219219
}
220220
}
221221
free(img);
222-
uint8_t* output = sd_tensor_to_image(image);
222+
*out_img = sd_tensor_to_image(image);
223223
ggml_free(work_ctx);
224-
return output;
224+
if (ggml_is_aborted()) {
225+
return SD_ERR_GGML_ABORT;
226+
}
227+
return SD_OK;
225228
}
226229

227230
#endif // __PREPROCESSING_HPP__

0 commit comments

Comments
 (0)