Enable caching of ACE step latents.

This commit is contained in:
Jaret Burkett
2026-04-28 13:39:20 -06:00
parent 77b8765939
commit af6458d1b5
4 changed files with 63 additions and 6 deletions

View File

@@ -1820,6 +1820,9 @@ class LatentCachingFileItemDTOMixin:
item["audio_normalize"] = True
if self.dataset_config.audio_preserve_pitch:
item["audio_preserve_pitch"] = True
if self.is_audio_model:
item["is_audio_model"] = True
item["sample_rate"] = self.sample_rate
return item
def get_latent_path(self: 'FileItemDTO', recalculate=False):
@@ -1882,8 +1885,6 @@ class LatentCachingMixin:
self.latent_cache = {}
def cache_latents_all_latents(self: 'AiToolkitDataset'):
if self.is_audio_model:
raise Exception("Audio models are not supported for latent caching yet")
with accelerator.main_process_first():
print_acc(f"Caching latents for {self.dataset_path}")
# cache all latents to disk
@@ -1949,8 +1950,8 @@ class LatentCachingMixin:
if to_disk:
state_dict['first_frame_latent'] = first_frame_latent.clone().detach().cpu()
# audio
if file_item.audio_data is not None:
# audio (video+audio models only — audio-only models already encoded above via encode_images)
if not self.is_audio_model and file_item.audio_data is not None:
audio_latent = self.sd.encode_audio([file_item.audio_data]).squeeze(0)
if to_disk:
state_dict['audio_latent'] = audio_latent.clone().detach().cpu()