Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion examples/unconditional_image_generation/train_unconditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def main(args):
"UpBlock2D",
),
)

if args.ort:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pytorch only training example, let's please not add onnxruntime here. The premise of the training scripts is to be very easy to run and understand. People should not have to know onnxruntime IMO to run the simplest training example that we have

from onnxruntime.training import ORTModule
model = ORTModule(model)

noise_scheduler = DDPMScheduler(num_train_timesteps=1000, tensor_format="pt")
optimizer = torch.optim.AdamW(
model.parameters(),
Expand Down Expand Up @@ -139,7 +144,10 @@ def transforms(examples):

with accelerator.accumulate(model):
# Predict the noise residual
noise_pred = model(noisy_images, timesteps).sample
if args.ort:
noise_pred = model(noisy_images, timesteps, return_dict=False)[0]
else:
noise_pred = model(noisy_images, timesteps).sample
loss = F.mse_loss(noise_pred, noise)
accelerator.backward(loss)

Expand Down Expand Up @@ -237,6 +245,7 @@ def transforms(examples):
"and an Nvidia Ampere GPU."
),
)
parser.add_argument("--ort", action="store_true")

args = parser.parse_args()
env_local_rank = int(os.environ.get("LOCAL_RANK", -1))
Expand Down
3 changes: 3 additions & 0 deletions src/diffusers/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"PreTrainedModel": ["save_pretrained", "from_pretrained"],
"FeatureExtractionMixin": ["save_pretrained", "from_pretrained"],
},
"onnxruntime.training": {
"ORTModule": ["save_pretrained", "from_pretrained"],
}
}

ALL_IMPORTABLE_CLASSES = {}
Expand Down