Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/conditioning/conditioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,40 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
true,
true);
GGML_ASSERT(!chunk_hidden_states.empty());
if (sd_version_is_sdxl(version) && clip_skip < 2) {
// Many distributed SDXL checkpoints carry NaN weights in CLIP-L's
// final transformer layer, since SDXL's UNet was only ever trained
// against the penultimate layer and that last layer is otherwise
// unused. Detect it from the actual output rather than assuming
// every checkpoint is affected, so a valid override (e.g. --clip-l)
// still works at clip_skip=1.
bool has_nan = false;
for (float v : chunk_hidden_states.values()) {
if (std::isnan(v)) {
has_nan = true;
break;
}
}
if (has_nan) {
LOG_WARN(
"clip_skip=%d produced invalid output from this checkpoint's CLIP-L "
"text encoder (a common defect in merged SDXL checkpoints' unused "
"final layer); using clip_skip=2 instead",
clip_skip);
clip_skip = 2;
chunk_hidden_states = text_model->compute(n_threads,
input_ids,
num_custom_embeddings,
token_embed_custom.data(),
max_token_idx,
false,
clip_skip,
false,
true,
true);
GGML_ASSERT(!chunk_hidden_states.empty());
}
}
if (sd_version_is_sdxl(version)) {
auto chunk_hidden_states2 = text_model2->compute(n_threads,
input_ids2,
Expand Down