| 752 | |
| 753 | |
| 754 | def collate_fn(examples): |
| 755 | pixel_values = torch.stack([example["pixel_values"] for example in examples]) |
| 756 | pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float() |
| 757 | |
| 758 | conditioning_pixel_values = torch.stack([example["conditioning_pixel_values"] for example in examples]) |
| 759 | conditioning_pixel_values = conditioning_pixel_values.to(memory_format=torch.contiguous_format).float() |
| 760 | |
| 761 | prompt_embeds = torch.stack([torch.tensor(example["prompt_embeds"]) for example in examples]) |
| 762 | pooled_prompt_embeds = torch.stack([torch.tensor(example["pooled_prompt_embeds"]) for example in examples]) |
| 763 | |
| 764 | return { |
| 765 | "pixel_values": pixel_values, |
| 766 | "conditioning_pixel_values": conditioning_pixel_values, |
| 767 | "prompt_embeds": prompt_embeds, |
| 768 | "pooled_prompt_embeds": pooled_prompt_embeds, |
| 769 | } |
| 770 | |
| 771 | |
| 772 | # Copied from dreambooth sd3 example |