huggingface / huggingface/diffusers

Questions Regarding the style_fidelity Parameter

Open
#10,410 1 comment 0 reactions 0 assignees View on GitHub
stale
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### Discussed in https://github.com/huggingface/diffusers/discussions/10353

Originally posted by **ShowLo** December 23, 2024
In [stable_diffusion_reference.py](https://github.com/huggingface/diffusers/blob/main/examples/community/stable_diffusion_reference.py), there is the following code:
```
var, mean = torch.var_mean(hidden_states, dim=(2, 3), keepdim=True, correction=0)
std = torch.maximum(var, torch.zeros_like(var) + eps) ** 0.5
mean_acc = sum(self.mean_bank[i]) / float(len(self.mean_bank[i]))
var_acc = sum(self.var_bank[i]) / float(len(self.var_bank[i]))
std_acc = torch.maximum(var_acc, torch.zeros_like(var_acc) + eps) ** 0.5
hidden_states_uc = (((hidden_states - mean) / std) * std_acc) + mean_acc
hidden_states_c = hidden_states_uc.clone()
if do_classifier_free_guidance and style_fidelity > 0:
hidden_states_c[uc_mask] = hidden_states[uc_mask]
hidden_states = style_fidelity * hidden_states_c + (1.0 - style_fidelity) * hidden_states_uc
```
And there is a comment:
```
style fidelity of ref_uncond_xt. If style_fidelity=1.0, control more important,
elif style_fidelity=0.0, prompt more important, else balanced.
```
However, when style_fidelity=1.0, hidden_states is set to hidden_states_c. Because of the presence of uc_mask, half of hidden_states_c is unrelated to the reference image. In this case, isn’t the prompt more important? Conversely, when style_fidelity=0.0, hidden_states is set to hidden_states_uc, where both the first and second halves of hidden_states_uc are influenced by the reference image. In this scenario, isn’t the control from the reference image more important?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.