diff --git a/examples/BuddyStableDiffusion/CMakeLists.txt b/examples/BuddyStableDiffusion/CMakeLists.txt index 767eaa069..67dad3250 100644 --- a/examples/BuddyStableDiffusion/CMakeLists.txt +++ b/examples/BuddyStableDiffusion/CMakeLists.txt @@ -13,179 +13,287 @@ add_custom_command( COMMENT "Generating forward.mlir, subgraph0.mlir and parameter files" ) - add_custom_command( OUTPUT forward_text_encoder.o - COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_text_encoder.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith), \ - empty-tensor-to-alloc-tensor, convert-elementwise-to-linalg, arith-bufferize, \ - func.func(linalg-bufferize, tensor-bufferize), func-bufferize)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-opt - -pass-pipeline - "builtin.module(func.func(buffer-deallocation-simplification, convert-linalg-to-loops), \ - eliminate-empty-tensors, func.func(llvm-request-c-wrappers), \ - convert-math-to-llvm, convert-math-to-libm, convert-scf-to-cf, \ - convert-arith-to-llvm, expand-strided-metadata, finalize-memref-to-llvm, \ - convert-func-to-llvm, reconcile-unrealized-casts)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | - ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 - -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_text_encoder.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_text_encoder.mlir - COMMENT "Building forward_text_encoder.o" + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_text_encoder.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp + -func-bufferize + -arith-bufferize + -tensor-bufferize + -buffer-deallocation + -finalizing-bufferize + -convert-vector-to-scf + -expand-strided-metadata + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm + -convert-scf-to-cf + -llvm-request-c-wrappers + -convert-openmp-to-llvm + -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm + -convert-func-to-llvm + -reconcile-unrealized-casts | + ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | + ${LLVM_TOOLS_BINARY_DIR}/llvm-as | + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_text_encoder.o + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_text_encoder.mlir + COMMENT "Building forward_text_encoder.o " VERBATIM) - add_custom_command( - OUTPUT subgraph0_text_encoder.o - COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_text_encoder.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" | - ${BUDDY_BINARY_DIR}/buddy-opt + OUTPUT subgraph0_text_encoder.o + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_text_encoder.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt -convert-elementwise-to-linalg + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp -func-bufferize-dynamic-offset - -arith-bufferize - -func-bufferize -tensor-bufferize - -linalg-bufferize + -arith-bufferize + -buffer-deallocation -finalizing-bufferize - -convert-linalg-to-loops - -lower-affine + -convert-vector-to-scf + -expand-strided-metadata + -cse + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm -convert-scf-to-cf -llvm-request-c-wrappers - -convert-math-to-llvm - -convert-math-to-libm + -convert-openmp-to-llvm -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm -convert-func-to-llvm - -expand-strided-metadata - -finalize-memref-to-llvm - -reconcile-unrealized-casts | + -reconcile-unrealized-casts | ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/subgraph0_text_encoder.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_text_encoder.mlir - buddy-opt - COMMENT "Building subgraph0_text_encoder.o" - VERBATIM) + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_text_encoder.mlir + COMMENT "Building subgraph0_text_encoder.o " + VERBATIM) add_custom_command( OUTPUT forward_unet.o - COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_unet.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith), \ - empty-tensor-to-alloc-tensor, convert-elementwise-to-linalg, arith-bufferize, \ - func.func(linalg-bufferize, tensor-bufferize), func-bufferize)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-opt - -pass-pipeline - "builtin.module(func.func(buffer-deallocation-simplification, convert-linalg-to-loops), \ - eliminate-empty-tensors, func.func(llvm-request-c-wrappers), \ - convert-math-to-llvm, convert-math-to-libm, convert-scf-to-cf, \ - convert-arith-to-llvm, expand-strided-metadata, finalize-memref-to-llvm, \ - convert-func-to-llvm, reconcile-unrealized-casts)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | - ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 - -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_unet.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_unet.mlir - COMMENT "Building forward_unet.o" + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_unet.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp + -func-bufferize + -arith-bufferize + -tensor-bufferize + -buffer-deallocation + -finalizing-bufferize + -convert-vector-to-scf + -expand-strided-metadata + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm + -convert-scf-to-cf + -llvm-request-c-wrappers + -convert-openmp-to-llvm + -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm + -convert-func-to-llvm + -reconcile-unrealized-casts | + ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | + ${LLVM_TOOLS_BINARY_DIR}/llvm-as | + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_unet.o + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_unet.mlir + COMMENT "Building forward_unet.o " VERBATIM) - add_custom_command( - OUTPUT subgraph0_unet.o - COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_unet.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" | - ${BUDDY_BINARY_DIR}/buddy-opt + OUTPUT subgraph0_unet.o + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_unet.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt -convert-elementwise-to-linalg + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp -func-bufferize-dynamic-offset - -arith-bufferize - -func-bufferize -tensor-bufferize - -linalg-bufferize + -arith-bufferize + -buffer-deallocation -finalizing-bufferize - -convert-linalg-to-loops - -lower-affine + -convert-vector-to-scf + -expand-strided-metadata + -cse + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm -convert-scf-to-cf -llvm-request-c-wrappers - -convert-math-to-llvm - -convert-math-to-libm + -convert-openmp-to-llvm -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm -convert-func-to-llvm - -expand-strided-metadata - -finalize-memref-to-llvm - -reconcile-unrealized-casts | + -reconcile-unrealized-casts | ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/subgraph0_unet.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_unet.mlir - buddy-opt - COMMENT "Building subgraph0_unet.o" - VERBATIM) + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_unet.mlir + COMMENT "Building subgraph0_unet.o " + VERBATIM) add_custom_command( OUTPUT forward_vae.o - COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_vae.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith), \ - empty-tensor-to-alloc-tensor, convert-elementwise-to-linalg, arith-bufferize, \ - func.func(linalg-bufferize, tensor-bufferize), func-bufferize)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-opt - -pass-pipeline - "builtin.module(func.func(buffer-deallocation-simplification, convert-linalg-to-loops), \ - eliminate-empty-tensors, func.func(llvm-request-c-wrappers), \ - convert-math-to-llvm, convert-math-to-libm, convert-scf-to-cf, \ - convert-arith-to-llvm, expand-strided-metadata, finalize-memref-to-llvm, \ - convert-func-to-llvm, reconcile-unrealized-casts)" | - ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | - ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 - -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_vae.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_vae.mlir - COMMENT "Building forward_vae.o" + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_vae.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp + -func-bufferize + -arith-bufferize + -tensor-bufferize + -buffer-deallocation + -finalizing-bufferize + -convert-vector-to-scf + -expand-strided-metadata + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm + -convert-scf-to-cf + -llvm-request-c-wrappers + -convert-openmp-to-llvm + -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm + -convert-func-to-llvm + -reconcile-unrealized-casts | + ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | + ${LLVM_TOOLS_BINARY_DIR}/llvm-as | + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/forward_vae.o + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/forward_vae.mlir + COMMENT "Building forward_vae.o " VERBATIM) - add_custom_command( - OUTPUT subgraph0_vae.o - COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_vae.mlir - -pass-pipeline - "builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" | - ${BUDDY_BINARY_DIR}/buddy-opt + OUTPUT subgraph0_vae.o + COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_vae.mlir + -pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | + ${BUDDY_BINARY_DIR}/buddy-opt -convert-elementwise-to-linalg + -arith-expand + -eliminate-empty-tensors + -empty-tensor-to-alloc-tensor + -one-shot-bufferize + -matmul-parallel-vectorization-optimize + -batchmatmul-optimize + -convert-linalg-to-affine-loops + -affine-loop-fusion + -affine-parallelize + -lower-affine + -convert-scf-to-openmp -func-bufferize-dynamic-offset - -arith-bufferize - -func-bufferize -tensor-bufferize - -linalg-bufferize + -arith-bufferize + -buffer-deallocation -finalizing-bufferize - -convert-linalg-to-loops - -lower-affine + -convert-vector-to-scf + -expand-strided-metadata + -cse + -convert-vector-to-llvm + -memref-expand + -arith-expand + -convert-arith-to-llvm + -finalize-memref-to-llvm -convert-scf-to-cf -llvm-request-c-wrappers - -convert-math-to-llvm - -convert-math-to-libm + -convert-openmp-to-llvm -convert-arith-to-llvm + -convert-math-to-llvm + -convert-math-to-libm -convert-func-to-llvm - -expand-strided-metadata - -finalize-memref-to-llvm - -reconcile-unrealized-casts | + -reconcile-unrealized-casts | ${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir | ${LLVM_TOOLS_BINARY_DIR}/llvm-as | - ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 + ${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3 -o ${BUDDY_BINARY_DIR}/../examples/BuddyStableDiffusion/subgraph0_vae.o - DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_vae.mlir - buddy-opt - COMMENT "Building subgraph0_vae.o" - VERBATIM) + DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyStableDiffusion/subgraph0_vae.mlir + COMMENT "Building subgraph0_vae.o " + VERBATIM) + add_library(TEXTENCODER STATIC subgraph0_text_encoder.o forward_text_encoder.o) add_library(UNET STATIC subgraph0_unet.o forward_unet.o) add_library(VAE STATIC subgraph0_vae.o forward_vae.o) +SET_SOURCE_FILES_PROPERTIES( + template.o + PROPERTIES + EXTERNAL_OBJECT true + GENERATED true) + target_compile_options(TEXTENCODER PRIVATE -ffunction-sections -fdata-sections -mcmodel=large -mlong-calls) target_compile_options(UNET PRIVATE -ffunction-sections -fdata-sections -mcmodel=large -mlong-calls) target_compile_options(VAE PRIVATE -ffunction-sections -fdata-sections -mcmodel=large -mlong-calls) @@ -199,7 +307,11 @@ target_link_directories(buddy-stablediffusion-run PRIVATE ${LLVM_LIBRARY_DIR}) target_link_options(buddy-stablediffusion-run PRIVATE -Wl,--no-relax) -set(BUDDY_STABLEDIFFUSION_LIBS TEXTENCODER UNET VAE mlir_c_runner_utils) +set(BUDDY_STABLEDIFFUSION_LIBS TEXTENCODER UNET VAE mlir_c_runner_utils omp) + +if(BUDDY_MLIR_USE_MIMALLOC) + list(APPEND BUDDY_LLAMA_LIBS mimalloc) +endif() target_link_libraries(buddy-stablediffusion-run ${BUDDY_STABLEDIFFUSION_LIBS} ${JPEG_LIBRARIES} ${PNG_LIBRARIES}) include_directories(${JPEG_INCLUDE_DIRS}) diff --git a/examples/BuddyStableDiffusion/buddy-stablediffusion-main.cpp b/examples/BuddyStableDiffusion/buddy-stablediffusion-main.cpp index 45e176a42..7969ddbe1 100644 --- a/examples/BuddyStableDiffusion/buddy-stablediffusion-main.cpp +++ b/examples/BuddyStableDiffusion/buddy-stablediffusion-main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -21,14 +20,14 @@ void getUserInput(std::string &inputStr) { } void getInferenceSteps(int &input) { - std::cout << "\nPlease enter the number of inference steps:" << std::endl; + std::cout << "Please enter the number of inference steps:" << std::endl; std::cout << ">>> "; std::cin >> input; std::cout << std::endl; } void getFileName(std::string &input) { - std::cout << "\nPlease enter the file name of the generated image:" << std::endl; + std::cout << "Please enter the file name of the generated image:" << std::endl; std::cout << ">>> "; std::cin >> input; std::cout << std::endl; @@ -299,8 +298,19 @@ int main() { MemRef timestep({1}); // Define vae parameters MemRef resultVae({1, 3, 512, 512}); - MemRef arg0_vae({49490179}); + MemRef arg0_vae({49490199}); + //Output directory information + printLogLabel(); + std::cout << "Vocab file: " << std::filesystem::canonical(vocabDir) + << std::endl; + printLogLabel(); + std::cout << "Params file: " << std::endl + << std::filesystem::canonical(TextEncoderParamsDir1) << std::endl + << std::filesystem::canonical(TextEncoderParamsDir2) << std::endl + << std::filesystem::canonical(UnetParamsDir) << std::endl + << std::filesystem::canonical(VaeParamsDir) << std::endl; + // Loading model parameters printLogLabel(); std::cout << "Loading params..." << std::endl; @@ -316,7 +326,7 @@ int main() { << "s\n" << std::endl; - // encode prompt + // Encode prompt printLogLabel(); std::cout << "Encoding prompt..." << std::endl; const auto encodeStart = std::chrono::high_resolution_clock::now(); @@ -359,6 +369,7 @@ int main() { auto timesteps = set_timesteps(InferenceSteps); // Denoising loop + const auto inferenceTotalStart = std::chrono::high_resolution_clock::now(); for (int i = 0; i < (int)timesteps.size() ; i ++){ MemRef noise({2, 4, 64, 64}); for (int j = 0 ; j < 2 * 4 * 64 * 64 ; j ++ ) @@ -376,12 +387,19 @@ int main() { } latents = step_plms(pred_noise, timesteps[i], latents, InferenceSteps, config, i, ets); } + const auto inferenceTotalEnd = std::chrono::high_resolution_clock::now(); + const std::chrono::duration inferenceTotalTime = inferenceTotalEnd - inferenceTotalStart; + printLogLabel(); + std::cout << "Denoising complete." << std::endl; + printLogLabel(); + std::cout << "Total time spent on denoising: " << (double)(encodeTime.count()) / 1000 + << "s" << std::endl; for (int i = 0 ; i < 1 * 4 * 64 * 64 ; i ++){ latents.getData()[i] = latents.getData()[i] / 0.18215; } - // decode + // Decode std::cout << std::endl; printLogLabel(); std::cout << "Start decoding..." << std::endl; @@ -413,12 +431,17 @@ int main() { img.getData()[i + 2] = resultVae.getData()[i / 3 + 512 * 512 * 0]; } - String filename = "../../examples/BuddyStableDiffusion/" + image_name + ".png"; + String Imgfilename = "../../examples/BuddyStableDiffusion/" + image_name + ".bmp"; // Call the imwrite function - bool success = imwrite(filename, img); + bool success = imwrite(Imgfilename, img); + + printLogLabel(); + std::cout << "The prompt used to generate the image:"<< inputStr << std::endl; + printLogLabel(); if (success) { - std::cout << "Image saved successfully to " << filename << std::endl; + std::cout << "Image saved successfully to " + << std::filesystem::canonical(Imgfilename) << std::endl; } else { std::cerr << "Failed to save the image." << std::endl; } diff --git a/examples/BuddyStableDiffusion/import-stable-diffusion.py b/examples/BuddyStableDiffusion/import-stable-diffusion.py index a48056816..c1eb580d8 100644 --- a/examples/BuddyStableDiffusion/import-stable-diffusion.py +++ b/examples/BuddyStableDiffusion/import-stable-diffusion.py @@ -22,6 +22,9 @@ prompt = "a photo of an astronaut riding a horse on mars" tokenizer = pipe.tokenizer +pipe.text_encoder.eval() +pipe.unet.eval() +pipe.vae.eval() text_encoder = pipe.text_encoder.forward unet = pipe.unet.forward vae = pipe.vae.decode diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 25044a291..f3864f9c0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,10 +28,6 @@ if (BUDDY_STABLEDIFFUSION_EXAMPLES) add_subdirectory(BuddyStableDiffusion) endif() -if (BUDDY_TESTOP_EXAMPLES) - add_subdirectory(TestOp) -endif() - if(BUDDY_DSL_EXAMPLES) add_subdirectory(ToyDSL) endif() diff --git a/examples/lit.cfg.py b/examples/lit.cfg.py index 3f7cadb12..598805149 100644 --- a/examples/lit.cfg.py +++ b/examples/lit.cfg.py @@ -42,7 +42,6 @@ 'BuddyWhisper', 'BuddyBert', 'BuddyMobileNetV3', - 'TestOp', 'BuddyStableDiffusion', 'BuddyResNet18', 'BuddyGPU',