huggingface / huggingface/diffusers
Questions Regarding the style_fidelity Parameter
- Vorherrschende Sprache
- Python
- Sterne
- 34.5k
- Forks
- 7.3k
- Ø Merge
- 3 T. 3 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
### 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?
Beitragsleitfaden
Rechercherichtung
Start with examples/community/stable_diffusion_reference.py and inspect the style_fidelity block, especially the uc_mask assignment and the final hidden_states blend. Trace the resulting values for style_fidelity=0.0 and 1.0 against the accompanying comment. Done means the intended control-versus-prompt behavior is established and any mismatch is clearly resolved.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python, pytorch
- Bereich
- machine-learning
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 32/100