feat: implement ESRGAN upscaler + Metal Backend (#104)

* add esrgan upscaler

* add sd_tiling

* support metal backend

* add clip_skip

---------

Co-authored-by: leejet <leejet714@gmail.com>
This commit is contained in:
Steward Garcia
2023-12-28 10:46:48 -05:00
committed by GitHub
parent 0e64238e4c
commit 004dfbef27
8 changed files with 915 additions and 39 deletions

View File

@@ -14,6 +14,10 @@
#include "ggml/ggml-backend.h"
#include "ggml/ggml.h"
#ifdef SD_USE_METAL
#include "ggml-metal.h"
#endif
#define ST_HEADER_SIZE_LEN 8
uint64_t read_u64(uint8_t* buffer) {
@@ -1197,7 +1201,7 @@ std::string ModelLoader::load_merges() {
return merges_utf8_str;
}
bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb) {
bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend_t backend) {
bool success = true;
for (size_t file_index = 0; file_index < file_paths_.size(); file_index++) {
std::string file_path = file_paths_[file_index];
@@ -1285,11 +1289,13 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb) {
continue;
}
ggml_backend_t backend = ggml_get_backend(dst_tensor);
size_t nbytes_to_read = tensor_storage.nbytes_to_read();
if (backend == NULL || ggml_backend_is_cpu(backend)) {
if (dst_tensor->buffer == NULL || ggml_backend_is_cpu(backend)
#ifdef SD_USE_METAL
|| ggml_backend_is_metal(backend)
#endif
) {
// for the CPU and Metal backend, we can copy directly into the tensor
if (tensor_storage.type == dst_tensor->type) {
GGML_ASSERT(ggml_nbytes(dst_tensor) == tensor_storage.nbytes());