Skip to content

Commit 83fe8d4

Browse files
authored
Merge pull request #469 from Kosinkadink/fp8-fix
Fix fp8 support for AD models
2 parents 34b7c52 + 3e3351a commit 83fe8d4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

animatediff/model_injection.py

+12
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ def load(self, device_to=None, lowvram_model_memory=0, *args, **kwargs):
815815
to_return = super().load(device_to=device_to, lowvram_model_memory=lowvram_model_memory, *args, **kwargs)
816816
if lowvram_model_memory > 0:
817817
self._patch_lowvram_extras(device_to=device_to)
818+
self._handle_float8_pe_tensors()
818819
return to_return
819820

820821
def _patch_lowvram_extras(self, device_to=None):
@@ -834,6 +835,17 @@ def _patch_lowvram_extras(self, device_to=None):
834835
if device_to is not None:
835836
comfy.utils.set_attr(self.model, key, comfy.utils.get_attr(self.model, key).to(device_to))
836837

838+
def _handle_float8_pe_tensors(self):
839+
remaining_tensors = list(self.model.state_dict().keys())
840+
pe_tensors = [x for x in remaining_tensors if '.pe' in x]
841+
is_first = True
842+
for key in pe_tensors:
843+
if is_first:
844+
is_first = False
845+
if comfy.utils.get_attr(self.model, key).dtype not in [torch.float8_e5m2, torch.float8_e4m3fn]:
846+
break
847+
comfy.utils.set_attr(self.model, key, comfy.utils.get_attr(self.model, key).half())
848+
837849
def pre_run(self, model: ModelPatcherAndInjector):
838850
self.cleanup()
839851
self.model.set_scale(self.scale_multival, self.per_block_list)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-animatediff-evolved"
33
description = "Improved AnimateDiff integration for ComfyUI."
4-
version = "1.2.2"
4+
version = "1.2.3"
55
license = { file = "LICENSE" }
66
dependencies = []
77

0 commit comments

Comments
 (0)