Commit def3aa9 for stable-diffusion.cpp
commit def3aa92355eca5a637ba16f027a48103f86d018
Author: leejet <leejet714@gmail.com>
Date: Thu Dec 3 23:33:38 2026 +0800
refactor: use tensor::load for PuLID embeddings (#2506)
diff --git a/docs/development/pulid.md b/docs/development/pulid.md
index 1bb8764..0f472ff 100644
--- a/docs/development/pulid.md
+++ b/docs/development/pulid.md
@@ -16,20 +16,12 @@ Each cross-attention layer takes the current image tokens as query, the
32-token / 2048-dim identity embedding as key+value, and adds its output
(scaled by `id_weight`, typically 1.0) back to the image tokens.
-## Format (gguf)
+## Identity embedding format
-The embedding is a standard **gguf** container holding a single tensor:
-
-```
-tensor name : "pulid_id"
-shape : [token_dim, num_tokens] (ggml order; typically [2048, 32])
-type : F16 (also accepts F32 / BF16)
-metadata : general.architecture = "pulid", pulid.version = 1
-```
-
-stable-diffusion.cpp loads it with the normal gguf reader
-(`gguf_init_from_file`) and converts to fp32 at load time -- no bespoke
-parser. Total file size for the typical (32, 2048, fp16) case is ~131 KB.
+The extraction script writes a float32 NumPy array of shape
+`(num_tokens, 2048)`, typically `(32, 2048)`. DGL reads it with
+`tensor::load` as `[2048, num_tokens]`, with the token dimension contiguous.
+`pulid::apply` checks the tensor's dtype and shape.
## Verification
diff --git a/docs/dgl-builtins.md b/docs/dgl-builtins.md
index cdebc7d..aabffa7 100644
--- a/docs/dgl-builtins.md
+++ b/docs/dgl-builtins.md
@@ -79,7 +79,6 @@ Optional parameters are marked with `?`. Default values follow `=`. See [DGL syn
| `preview` | `decoder?: vae`, `circular_x?: bool = false`, `circular_y?: bool = false` | `sampling_observer` |
| `pulid::apply` | `condition: dict`, `pulid: pulid`, `embedding: tensor`, `strength?: number = 1`, `start_sigma?: number`, `end_sigma?: number` | same type as `condition`<br>`pulid: pulid_bindings` |
| `pulid::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false`, `linear_type?: string = "auto"` | `pulid` |
-| `pulid::load_embedding` | `path: string` | `tensor` |
| `regions::crop` | `image: tensor`, `regions: dict` | `list<tensor>` |
| `regions::from_boxes` | `width: int`, `height: int`, `boxes: any` | `dict`<br>`boxes: tensor`<br>`height: int`<br>`width: int` |
| `regions::paste` | `background: tensor`, `foregrounds: list<tensor>`, `regions: dict` | `tensor` |
diff --git a/docs/dgl.md b/docs/dgl.md
index 1897979..db89869 100644
--- a/docs/dgl.md
+++ b/docs/dgl.md
@@ -1524,7 +1524,9 @@ fn main() {
`start_sigma` and `end_sigma` bounds.
[Classic and Plus use different vision inputs](models/ip_adapter.md#dgl).
- [PuLID](dgl/pulid/pulid-flux1-schnell.dgl) loads the attention weights with
- `pulid::load` and the precomputed identity with `pulid::load_embedding`.
+ `pulid::load` and the precomputed `.npy` identity with `tensor::load`.
+ See [PuLID embedding preparation](models/pulid.md#prepare-the-identity-embedding)
+ for converting existing `.pulidembd` files.
`pulid::apply(condition, pulid, embedding)` binds an identity to one
predictor branch. Set its `strength` and optional `start_sigma` and
`end_sigma` bounds.
@@ -1679,7 +1681,6 @@ argument order, defaults and result fields are unchanged:
| `encode_photomaker_prompt` | `photomaker::encode_prompt` |
| `apply_photomaker` | `photomaker::apply` |
| `load_pulid` | `pulid::load` |
-| `load_pulid_embedding` | `pulid::load_embedding` |
| `apply_pulid` | `pulid::apply` |
| `load_animatediff` | `animatediff::load` |
| `apply_animatediff` | `animatediff::apply` |
diff --git a/docs/dgl/pulid/pulid-flux1-schnell.dgl b/docs/dgl/pulid/pulid-flux1-schnell.dgl
index 2e9d949..7ac9b95 100644
--- a/docs/dgl/pulid/pulid-flux1-schnell.dgl
+++ b/docs/dgl/pulid/pulid-flux1-schnell.dgl
@@ -8,7 +8,7 @@ var {
clip_l_path = "../models/text_encoders/clip_l.safetensors"
vae_path = "../models/vae/ae.safetensors"
- identity_path = "../inputs/source.pulidembd"
+ identity_path = "../inputs/source.npy"
output_path = "out.png"
prompt = "candid photograph of a young woman on a beach at sunset"
@@ -27,7 +27,7 @@ fn main() {
pulid = pulid::load(pulid_path)
text = load_text_encoder(encoder_path, family = "flux", clip_l_path = clip_l_path, backend = "cpu")
vae = load_vae(vae_path, family = "flux")
- identity = pulid::load_embedding(identity_path)
+ identity = tensor::load(identity_path)
condition = pulid::apply(encode_prompt(text, prompt), pulid, identity, strength = 1.0)
predict = predictor(dit, condition)
base = tensor::zeros(latent_shape(vae, width = width, height = height))
diff --git a/docs/models/pulid.md b/docs/models/pulid.md
index 7e5b6fe..6352aaf 100644
--- a/docs/models/pulid.md
+++ b/docs/models/pulid.md
@@ -12,12 +12,12 @@ identity embedding once with the external Python tool, then reuse it.
| --- | --- | --- | --- |
| FLUX.1 base components | [FLUX.1 guide](flux.md) | `load_dit`, `load_vae`, `load_text_encoder` | Required; dev or schnell |
| PuLID v0.9.x weights | [guozinan/PuLID](https://huggingface.co/guozinan/PuLID) | `pulid::load` | v0.9.1 is the tested version; v1.1 is unsupported |
-| Identity embedding | `source.pulidembd` from preparation below | `pulid::load_embedding` | Required for identity preservation |
+| Identity embedding | `source.npy` from preparation below | `tensor::load` | Required for identity preservation |
### Prepare the identity embedding
The precompute tool extracts an identity embedding from a single portrait
-and writes it to a `.pulidembd` file. Run it once per source
+and writes it to a float32 `.npy` file. Run it once per source
person; the same file is reused for any number of generations.
Use
@@ -25,7 +25,7 @@ Use
requires:
- A working CUDA / CPU PyTorch stack
- `insightface`, `facexlib`, `eva-clip`, `torchvision`, `opencv-python`,
- `huggingface_hub`, `gguf`
+ `huggingface_hub`, `numpy`, `Pillow`
- The PuLID weights file (same one stable-diffusion.cpp will load below)
- The ToTheBeginning/PuLID repo's `pulid/` package (including
`pulid/pipeline_flux.py`) and `eva_clip/` package on `PYTHONPATH`; `flux/`
@@ -36,18 +36,35 @@ From the source repository root, run:
**Windows (PowerShell)**
```powershell
-python scripts\pulid_extract_id.py --portrait .\inputs\source-photo.jpg --pulid-weights .\models\pulid\pulid_flux_v0.9.1.safetensors --out .\inputs\source.pulidembd
+python scripts\pulid_extract_id.py --portrait .\inputs\source-photo.jpg --pulid-weights .\models\pulid\pulid_flux_v0.9.1.safetensors --out .\inputs\source.npy
```
**Linux/macOS**
```sh
-python scripts/pulid_extract_id.py --portrait ./inputs/source-photo.jpg --pulid-weights ./models/pulid/pulid_flux_v0.9.1.safetensors --out ./inputs/source.pulidembd
+python scripts/pulid_extract_id.py --portrait ./inputs/source-photo.jpg --pulid-weights ./models/pulid/pulid_flux_v0.9.1.safetensors --out ./inputs/source.npy
```
The script writes the embedding to the repository's `inputs/` directory.
The examples below read the same file from the build directory.
+To reuse an existing `.pulidembd` file, save the following script as
+`convert-pulid.dgl` next to `source.pulidembd`. From that directory, run
+`sd-cli -M dgl --script convert-pulid.dgl` with an older executable that provides
+`pulid::load_embedding`. Set the generation script's `identity_path` to the
+resulting `source.npy`.
+
+```dgl
+# version: 0.0.0
+
+fn main() {
+ identity = pulid::load_embedding("source.pulidembd")
+ shape = tensor::shape(identity)
+ tensor::save("source.npy", tensor::reshape(identity, [shape[0], shape[1]]))
+ return identity
+}
+```
+
## Usage
### Web UI
@@ -86,7 +103,7 @@ and the server's file-access rules.
Load PuLID weights separately with `pulid::load` on the same compute backend
as the FLUX.1 denoiser. Read the identity embedding with
-`pulid::load_embedding` and bind it to a text condition with `pulid::apply`
+`tensor::load` and bind it to a text condition with `pulid::apply`
before calling `predictor`. Each binding sets its own `strength` and can
set `start_sigma` and `end_sigma` to bound the contribution in sigma space.
Omitting both bounds enables the binding throughout sampling.
@@ -96,8 +113,8 @@ default guidance is 3.5.
## Options
-Load weights with `pulid::load`, read the prepared `.pulidembd` file with
-`pulid::load_embedding`, and attach it to the positive condition with
+Load weights with `pulid::load`, read the prepared `.npy` file with
+`tensor::load`, and attach it to the positive condition with
`pulid::apply(..., strength=1.0)`. Typical identity strengths are 0.7–1.2.
Optional `start_sigma` and `end_sigma` bound the active noise interval.
diff --git a/examples/common/download_file.cpp b/examples/common/download_file.cpp
index dee4269..f3faf72 100644
--- a/examples/common/download_file.cpp
+++ b/examples/common/download_file.cpp
@@ -264,7 +264,7 @@ namespace sd::download {
}
if (fd < 0) {
temporary = temporary_name();
- fd = openat(temporary_dir(), temporary.c_str(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
+ fd = openat(temporary_dir(), temporary.c_str(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
if (fd < 0)
throw file_error("cannot create temporary download file");
owned = true;
@@ -316,7 +316,7 @@ namespace sd::download {
if (std::fflush(file_->stream) != 0)
throw file_error("cannot flush download");
const int fd = fileno(file_->stream);
- struct stat staged {};
+ struct stat staged{};
if (fstat(fd, &staged) < 0)
throw file_error("cannot inspect staged download");
// Checkpoints created by older builds may still have shared write permissions.
@@ -326,7 +326,7 @@ namespace sd::download {
const auto name = file_->target.filename();
if (linkat(file_->temporary_dir(), file_->temporary.c_str(), file_->parent, name.c_str(), 0) < 0) {
const auto error = file_error("cannot publish download");
- struct stat status {};
+ struct stat status{};
if (errno != EEXIST || fstatat(file_->parent, name.c_str(), &status, AT_SYMLINK_NOFOLLOW) < 0 ||
!S_ISREG(status.st_mode))
throw error;
diff --git a/examples/server/routes_dgl.cpp b/examples/server/routes_dgl.cpp
index 480c448..c66597d 100644
--- a/examples/server/routes_dgl.cpp
+++ b/examples/server/routes_dgl.cpp
@@ -165,12 +165,12 @@ void register_dgl_endpoints(httplib::Server& svr, ServerRuntime& runtime) {
send_error(res, 400, "Expected non-empty UTF-8 source");
return;
}
- auto job = std::make_shared<AsyncGenerationJob>();
- job->kind = AsyncJobKind::Dgl;
- job->dgl_source = std::move(source);
- const auto origin = req.get_header_value("Origin");
- const bool loopback = req.remote_addr == "127.0.0.1" || req.remote_addr == "::1" ||
- req.remote_addr == "::ffff:127.0.0.1";
+ auto job = std::make_shared<AsyncGenerationJob>();
+ job->kind = AsyncJobKind::Dgl;
+ job->dgl_source = std::move(source);
+ const auto origin = req.get_header_value("Origin");
+ const bool loopback = req.remote_addr == "127.0.0.1" || req.remote_addr == "::1" ||
+ req.remote_addr == "::ffff:127.0.0.1";
const bool local_same_origin = loopback && origin == "http://" + req.get_header_value("Host");
// The server authenticates POST requests before routing when API keys are configured.
job->dgl_allow_download = !runtime.svr_params->api_keys.empty() || local_same_origin;
diff --git a/scripts/pulid_extract_id.py b/scripts/pulid_extract_id.py
index 05199be..9aeeb6c 100644
--- a/scripts/pulid_extract_id.py
+++ b/scripts/pulid_extract_id.py
@@ -1,22 +1,21 @@
"""
Precompute a PuLID-Flux identity embedding from a single source portrait.
-Writes a gguf file (a single tensor `pulid_id`) consumed by the DGL
-`pulid::load_embedding` function.
+Writes a float32 NumPy array consumed by the DGL `tensor::load` function.
Dependencies (recommended: vendor rather than pip-install due to upstream
packaging quirks):
- torch + safetensors
- The ToTheBeginning/PuLID repository's `pulid/` package and `eva_clip/`.
Put them on PYTHONPATH or sys.path before running this script.
- - insightface, facexlib, torchvision, opencv-python, huggingface_hub, gguf
+ - insightface, facexlib, torchvision, opencv-python, huggingface_hub
- numpy, Pillow
Usage:
python scripts/pulid_extract_id.py \\
--portrait /path/to/source-photo.jpg \\
--pulid-weights /path/to/pulid_flux_v0.9.1.safetensors \\
- --out /path/to/source.pulidembd
+ --out /path/to/source.npy
The portrait must contain a clearly visible face. insightface's antelopev2
detector will be auto-downloaded on first run.
@@ -67,40 +66,17 @@ def extract(portrait_path: str, pulid_weights: str) -> "torch.Tensor":
return id_embedding
-def write_embd(tensor, out_path: str, dtype_choice: str) -> None:
- import gguf
+def write_embd(tensor, out_path: str) -> None:
+ import numpy as np
import torch
if tensor.ndim != 2:
raise ValueError(f"expected (num_tokens, token_dim); got {tuple(tensor.shape)}")
- num_tokens, token_dim = tensor.shape
-
os.makedirs(os.path.dirname(out_path) or ".", exist_ok=True)
-
- writer = gguf.GGUFWriter(out_path, arch="pulid")
- writer.add_uint32("pulid.version", 1)
-
- if dtype_choice == "fp16":
- arr = tensor.to(torch.float16).contiguous().cpu().numpy()
- writer.add_tensor("pulid_id", arr)
- elif dtype_choice == "fp32":
- arr = tensor.to(torch.float32).contiguous().cpu().numpy()
- writer.add_tensor("pulid_id", arr)
- elif dtype_choice == "bf16":
- raw = tensor.to(torch.bfloat16).contiguous().view(torch.uint16).cpu().numpy()
- writer.add_tensor("pulid_id", raw,
- raw_shape=(int(num_tokens), int(token_dim)),
- raw_dtype=gguf.GGMLQuantizationType.BF16)
- else:
- raise ValueError(f"unknown --dtype {dtype_choice}")
-
- writer.write_header_to_file()
- writer.write_kv_data_to_file()
- writer.write_tensors_to_file()
- writer.close()
-
- print(f"wrote {out_path}: gguf, tensor pulid_id [{token_dim}, {num_tokens}] {dtype_choice}",
- flush=True)
+ array = tensor.detach().to(torch.float32).contiguous().cpu().numpy()
+ with open(out_path, "wb") as output:
+ np.save(output, array, allow_pickle=False)
+ print(f"wrote {out_path}: float32 NumPy array {array.shape}", flush=True)
def main() -> int:
@@ -112,10 +88,7 @@ def main() -> int:
ap.add_argument("--pulid-weights", required=True,
help="Path to pulid_flux_v0.9.x.safetensors.")
ap.add_argument("--out", required=True,
- help="Output path for the .pulidembd binary.")
- ap.add_argument("--dtype", default="fp16",
- choices=["fp16", "bf16", "fp32"],
- help="Storage dtype (default fp16; produces ~131 KB).")
+ help="Output path for the float32 .npy file.")
args = ap.parse_args()
if not os.path.exists(args.portrait):
@@ -126,7 +99,7 @@ def main() -> int:
return 3
embedding = extract(args.portrait, args.pulid_weights)
- write_embd(embedding, args.out, args.dtype)
+ write_embd(embedding, args.out)
return 0
diff --git a/src/dgl/bindings/components.cpp b/src/dgl/bindings/components.cpp
index 19ab183..9ca0dfe 100644
--- a/src/dgl/bindings/components.cpp
+++ b/src/dgl/bindings/components.cpp
@@ -23,7 +23,6 @@
#include "dgl/ops/prompt.h"
#include "dgl/ops/sampling.h"
#include "dgl/ops/vae.h"
-#include "extensions/pulid_embedding.h"
#include "model/vae/vae.hpp"
#include "model_definition.h"
#include "model_loader.h"
@@ -259,16 +258,6 @@ namespace sd::dgl {
return tensor_value(ops::sample(input, sigmas, *predictor, rng, options, state.events));
}
- Value execute_load_pulid_embedding(Values& args, RunState&) {
- auto path = get_string(args, "path");
- require_file_access(path, SD_DGL_FILE_READ);
- auto result = load_pulid_id_embedding(path.c_str());
- if (result.empty()) {
- throw std::runtime_error("cannot load PuLID identity embedding");
- }
- return tensor_value(std::move(result));
- }
-
Value execute_vae_to_dit_latents(Values& args, RunState&) {
return convert_vae_latent(args, true);
}
diff --git a/src/dgl/bindings/components.h b/src/dgl/bindings/components.h
index 4afb78a..d26f000 100644
--- a/src/dgl/bindings/components.h
+++ b/src/dgl/bindings/components.h
@@ -17,7 +17,6 @@ namespace sd::dgl {
Value denoiser_scalings(Values& args, RunState&);
Value make_sigmas(Values& args, RunState&);
Value sample_tensor(Values& args, RunState& state);
- Value execute_load_pulid_embedding(Values& args, RunState&);
Value execute_vae_to_dit_latents(Values& args, RunState&);
Value execute_dit_to_vae_latents(Values& args, RunState&);
Value execute_add_noise(Values& args, RunState&);
diff --git a/src/dgl/bindings/registration.cpp b/src/dgl/bindings/registration.cpp
index 104fa7e..f21c4f1 100644
--- a/src/dgl/bindings/registration.cpp
+++ b/src/dgl/bindings/registration.cpp
@@ -483,8 +483,6 @@ namespace sd::dgl {
registry["animatediff::load"] = component_loader<models::AnimateDiff>(SDBackendModule::DIFFUSION, family, load_animatediff);
registry["load_latent_upscaler"] = component_loader<models::LatentUpscaler>(
SDBackendModule::DIFFUSION, choice("family", {"auto", "ltxav", "minimax_h3"}, "auto"), load_latent_upscaler);
- registry["pulid::load_embedding"] = make_operation(
- {required("path", Kind::String)}, {Kind::Tensor}, execute_load_pulid_embedding);
registry["photomaker::encode_images"] = make_operation(
{required("photomaker", Kind::PhotoMaker),
list_argument("images", Kind::Tensor),
diff --git a/src/dgl/models/photomaker.cpp b/src/dgl/models/photomaker.cpp
index c833552..50fdca4 100644
--- a/src/dgl/models/photomaker.cpp
+++ b/src/dgl/models/photomaker.cpp
@@ -5,7 +5,6 @@
#include "core/image_tensor.h"
#include "core/util.h"
#include "dgl/models/component_sources.h"
-#include "extensions/photomaker_embedding.h"
#include "model/adapter/pmid.hpp"
namespace sd::dgl::models {
@@ -36,7 +35,7 @@ namespace sd::dgl::models {
const int64_t count = images.size();
if (count == 0 || count > 75 / (v2 ? 2 : 1))
throw std::runtime_error("PhotoMaker image count exceeds the available prompt slots");
- if (v2 && (!embedding || embedding->shape() != std::vector<int64_t>{sd::photomaker::id_embedding_width, count}))
+ if (v2 && (!embedding || embedding->shape() != std::vector<int64_t>{512, count}))
throw std::runtime_error("PhotoMaker v2 requires a float32 embedding with 512 values per image");
if (!v2 && embedding)
throw std::runtime_error("PhotoMaker identity embeddings require v2");
diff --git a/src/extensions/photomaker_embedding.cpp b/src/extensions/photomaker_embedding.cpp
deleted file mode 100644
index 11691b9..0000000
--- a/src/extensions/photomaker_embedding.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#include "photomaker_embedding.h"
-
-#include <algorithm>
-#include <cctype>
-#include <filesystem>
-#include <fstream>
-#include <limits>
-
-#include "ggml.h"
-#include "model_io/npy_io.h"
-
-namespace sd::photomaker {
-
- static Tensor<float> load_legacy_embedding(const std::filesystem::path& path,
- std::vector<int64_t> shape,
- size_t bytes) {
- std::ifstream file(path, std::ios::binary | std::ios::ate);
- if (!file)
- throw std::runtime_error("cannot open PhotoMaker ID embedding");
- const std::streamoff file_size = file.tellg();
- file.seekg(0);
-
- int32_t header[3];
- if (!file.read(reinterpret_cast<char*>(header), sizeof(header)) ||
- header[0] < 2 || header[0] > 4 || header[1] < 0 || header[2] != GGML_TYPE_F32) {
- throw std::runtime_error("invalid legacy PhotoMaker ID embedding header");
- }
- int32_t dims[4]{1, 1, 1, 1};
- if (!file.read(reinterpret_cast<char*>(dims), header[0] * sizeof(int32_t)) ||
- dims[0] != shape[0] || dims[1] != shape[1] || dims[2] != 1 || dims[3] != 1) {
- throw std::runtime_error("legacy PhotoMaker ID embedding shape does not match the input images");
- }
-
- const auto payload = std::streamoff(sizeof(header) + header[0] * sizeof(int32_t)) + header[1];
- if (file_size < payload || uint64_t(file_size - payload) != bytes)
- throw std::runtime_error("invalid legacy PhotoMaker ID embedding payload size");
- file.seekg(payload);
- Tensor<float> result(std::move(shape));
- if (!file.read(reinterpret_cast<char*>(result.data()), bytes))
- throw std::runtime_error("cannot read legacy PhotoMaker ID embedding");
- return result;
- }
-
- Tensor<float> load_id_embedding(const std::string& path, int image_count) {
- constexpr size_t bytes_per_image = id_embedding_width * sizeof(float);
- if (image_count <= 0 || size_t(image_count) > std::numeric_limits<size_t>::max() / bytes_per_image)
- throw std::runtime_error("invalid PhotoMaker input image count");
- const auto bytes = size_t(image_count) * bytes_per_image;
- std::vector<int64_t> shape{id_embedding_width, image_count};
- const auto file_path = std::filesystem::u8path(path);
- auto extension = file_path.extension().u8string();
- std::transform(extension.begin(), extension.end(), extension.begin(), [](unsigned char c) { return char(std::tolower(c)); });
- if (extension != ".npy")
- return load_legacy_embedding(file_path, std::move(shape), bytes);
-
- npy::Reader reader(path, bytes);
- if (reader.type() != SD_TENSOR_F32 || reader.shape() != shape)
- throw std::runtime_error("PhotoMaker v2 expects a float32 NumPy array with shape (image_count, 512)");
- Tensor<float> result(std::move(shape));
- reader.read(result.data(), bytes);
- return result;
- }
-
-} // namespace sd::photomaker
diff --git a/src/extensions/photomaker_embedding.h b/src/extensions/photomaker_embedding.h
deleted file mode 100644
index befd8d7..0000000
--- a/src/extensions/photomaker_embedding.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __SD_EXTENSIONS_PHOTOMAKER_EMBEDDING_H__
-#define __SD_EXTENSIONS_PHOTOMAKER_EMBEDDING_H__
-
-#include "core/tensor.hpp"
-
-namespace sd::photomaker {
-
- inline constexpr int64_t id_embedding_width = 512;
-
- Tensor<float> load_id_embedding(const std::string& path, int image_count);
-
-} // namespace sd::photomaker
-
-#endif // __SD_EXTENSIONS_PHOTOMAKER_EMBEDDING_H__
diff --git a/src/extensions/pulid_embedding.cpp b/src/extensions/pulid_embedding.cpp
deleted file mode 100644
index 4485bab..0000000
--- a/src/extensions/pulid_embedding.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "extensions/pulid_embedding.h"
-
-#include <cstring>
-#include "core/tensor_ggml.hpp"
-#include "core/util.h"
-#include "gguf.h"
-
-sd::Tensor<float> load_pulid_id_embedding(const char* path) {
- sd::Tensor<float> empty;
- if (path == nullptr || strlen(path) == 0) {
- return empty;
- }
-
- struct ggml_context* ctx_data = nullptr;
- struct gguf_init_params gp = {/*.no_alloc =*/false, /*.ctx =*/&ctx_data};
- struct gguf_context* gguf_ctx = gguf_init_from_file(path, gp);
- if (gguf_ctx == nullptr || ctx_data == nullptr) {
- LOG_WARN("PuLID id-embedding: cannot read gguf '%s'", path);
- if (gguf_ctx != nullptr)
- gguf_free(gguf_ctx);
- if (ctx_data != nullptr)
- ggml_free(ctx_data);
- return empty;
- }
-
- struct ggml_tensor* t = ggml_get_tensor(ctx_data, "pulid_id");
- if (t == nullptr) {
- LOG_WARN("PuLID id-embedding: no 'pulid_id' tensor in '%s'", path);
- gguf_free(gguf_ctx);
- ggml_free(ctx_data);
- return empty;
- }
-
- const int64_t token_dim = t->ne[0];
- const int64_t num_tokens = t->ne[1];
- if (token_dim <= 0 || num_tokens <= 0 || token_dim > 65536 || num_tokens > 1024 ||
- t->ne[2] != 1 || t->ne[3] != 1) {
- LOG_WARN("PuLID id-embedding: implausible shape [%lld, %lld] in '%s'",
- (long long)token_dim, (long long)num_tokens, path);
- gguf_free(gguf_ctx);
- ggml_free(ctx_data);
- return empty;
- }
-
- const size_t n_elem = (size_t)token_dim * (size_t)num_tokens;
- sd::Tensor<float> out({token_dim, num_tokens, 1});
- float* dst = out.data();
- if (t->type == GGML_TYPE_F32) {
- memcpy(dst, t->data, n_elem * sizeof(float));
- } else if (t->type == GGML_TYPE_F16) {
- const ggml_fp16_t* src = reinterpret_cast<const ggml_fp16_t*>(t->data);
- for (size_t i = 0; i < n_elem; i++) {
- dst[i] = ggml_fp16_to_fp32(src[i]);
- }
- } else if (t->type == GGML_TYPE_BF16) {
- const ggml_bf16_t* src = reinterpret_cast<const ggml_bf16_t*>(t->data);
- for (size_t i = 0; i < n_elem; i++) {
- dst[i] = ggml_bf16_to_fp32(src[i]);
- }
- } else {
- LOG_WARN("PuLID id-embedding: unsupported tensor type %s in '%s'",
- ggml_type_name(t->type), path);
- gguf_free(gguf_ctx);
- ggml_free(ctx_data);
- return empty;
- }
-
- LOG_INFO("PuLID id-embedding: loaded [%lld, %lld] type=%s from '%s'",
- (long long)token_dim, (long long)num_tokens, ggml_type_name(t->type), path);
- gguf_free(gguf_ctx);
- ggml_free(ctx_data);
- return out;
-}
diff --git a/src/extensions/pulid_embedding.h b/src/extensions/pulid_embedding.h
deleted file mode 100644
index 8ff3c73..0000000
--- a/src/extensions/pulid_embedding.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __SD_EXTENSIONS_PULID_EMBEDDING_H__
-#define __SD_EXTENSIONS_PULID_EMBEDDING_H__
-
-#include "core/tensor.hpp"
-
-sd::Tensor<float> load_pulid_id_embedding(const char* path);
-
-#endif // __SD_EXTENSIONS_PULID_EMBEDDING_H__