def onload_(self):
        r"""Onloads the group of modules to the onload_device."""
        torch_accelerator_module = (
            getattr(torch, torch.accelerator.current_accelerator().type)
            if hasattr(torch, "accelerator")
            else torch.cuda
        )
        context = nullcontext() if self.stream is None else torch_accelerator_module.stream(self.stream)
        current_stream = torch_accelerator_module.current_stream() if self.record_stream else None

        if self.stream is not None:
            # Wait for previous Host->Device transfer to complete
            self.stream.synchronize()

        with context:
            if self.stream is not None:
                with self._pinned_memory_tensors() as pinned_memory:
                    for group_module in self.modules:
                        for param in group_module.parameters():
                            param.data = pinned_memory[param].to(self.onload_device, non_blocking=self.non_blocking)
                            if self.record_stream:
                                param.data.record_stream(current_stream)
                        for buffer in group_module.buffers():
                            buffer.data = pinned_memory[buffer].to(self.onload_device, non_blocking=self.non_blocking)
                            if self.record_stream:
                                buffer.data.record_stream(current_stream)

                    for param in self.parameters:
                        param.data = pinned_memory[param].to(self.onload_device, non_blocking=self.non_blocking)
                        if self.record_stream:
                            param.data.record_stream(current_stream)

                    for buffer in self.buffers:
                        buffer.data = pinned_memory[buffer].to(self.onload_device, non_blocking=self.non_blocking)
                        if self.record_stream:
                            buffer.data.record_stream(current_stream)

            else:
                for group_module in self.modules:
                    for param in group_module.parameters():
                        param.data = param.data.to(self.onload_device, non_blocking=self.non_blocking)
                    for buffer in group_module.buffers():
                        buffer.data = buffer.data.to(self.onload_device, non_blocking=self.non_blocking)

                for param in self.parameters:
                    param.data = param.data.to(self.onload_device, non_blocking=self.non_blocking)

                for buffer in self.buffers:
                    buffer.data = buffer.data.to(self.onload_device, non_blocking=self.non_blocking)
                    if self.record_stream:
                        buffer.data.record_stream(current_stream)
Onloads the group of modules to the onload_device.
src/diffusers/hooks/group_offloading.py