d8ahazard / sd_dreambooth_extension

Other
1.85k stars 281 forks source link

Use float32 for EMA model #1415

Closed RossM closed 7 months ago

RossM commented 7 months ago

Describe your changes

This affects models that have weight_dtype set to float16 or bfloat16, and use_ema is true.

Due to fp16/bf16 not having enough precision to represent differences to a weight on the order of 0.001 times the current value, almost all EMA weight updates get rounded down to 0. This means that the ema model never actually gets updated from the running weights.

The solution is to always keep the EMA model in float32, regardless of weight_dtype.

Issue ticket number and link (if applicable)

Checklist before requesting a review