Skip to content

Commit

Permalink
Update copyright year on demo Diffusion
Browse files Browse the repository at this point in the history
Signed-off-by: Shuyue Lan <[email protected]>
  • Loading branch information
shuyuelan authored and kevinch-nv committed Mar 15, 2023
1 parent 3e5f6d8 commit 4af32ba
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TensorRT OSS Release Changelog

## [8.6.0 EA](https://docs.nvidia.com/deeplearning/tensorrt/release-notes/tensorrt-8.html#tensorrt-8) - 2023-03-10
## [8.6.0 EA](https://docs.nvidia.com/deeplearning/tensorrt/release-notes/tensorrt-8.html#tensorrt-8) - 2023-03-14

TensorRT OSS release corresponding to TensorRT 8.6.0.12 EA release.
- Updates since [TensorRT 8.5.3 GA release](https://docs.nvidia.com/deeplearning/tensorrt/release-notes/tensorrt-8.html#rel-8-5-3).
Expand Down
2 changes: 1 addition & 1 deletion demo/Diffusion/demo_img2img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
8 changes: 4 additions & 4 deletions demo/Diffusion/demo_inpaint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -55,13 +55,13 @@ def parseArgs():
else:
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
input_image = download_image(img_url)

if args.mask_image:
mask_image = Image.open(args.mask_image).convert("RGB")
else:
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
mask_image = download_image(mask_url)

image_width, image_height = input_image.size
mask_width, mask_height = mask_image.size

Expand Down Expand Up @@ -96,7 +96,7 @@ def parseArgs():
max_batch_size=max_batch_size)

# Load TensorRT engines and pytorch modules
demo.loadEngines(args.engine_dir, args.onnx_dir, args.onnx_opset,
demo.loadEngines(args.engine_dir, args.onnx_dir, args.onnx_opset,
opt_batch_size=len(prompt), opt_image_height=image_height, opt_image_width=image_width, \
force_export=args.force_onnx_export, force_optimize=args.force_onnx_optimize, \
force_build=args.force_engine_build, \
Expand Down
4 changes: 2 additions & 2 deletions demo/Diffusion/demo_txt2img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -73,7 +73,7 @@ def parseArgs():
max_batch_size=max_batch_size)

# Load TensorRT engines and pytorch modules
demo.loadEngines(args.engine_dir, args.onnx_dir, args.onnx_opset,
demo.loadEngines(args.engine_dir, args.onnx_dir, args.onnx_opset,
opt_batch_size=len(prompt), opt_image_height=image_height, opt_image_width=image_width, \
force_export=args.force_onnx_export, force_optimize=args.force_onnx_optimize, \
force_build=args.force_engine_build, \
Expand Down
2 changes: 1 addition & 1 deletion demo/Diffusion/img2img_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 2 additions & 3 deletions demo/Diffusion/inpaint_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(

if scheduler != "PNDM":
raise ValueError(f"Inpainting only supports PNDM scheduler")

super(InpaintPipeline, self).__init__(*args, **kwargs, \
inpaint=True, scheduler=scheduler, stages=[ 'vae_encoder', 'clip', 'unet', 'vae'])

Expand Down Expand Up @@ -132,4 +132,3 @@ def infer(
if not warmup:
self.print_summary(self.denoising_steps, e2e_tic, e2e_toc, vae_enc=True)
self.save_image(images, 'inpaint', prompt)

2 changes: 1 addition & 1 deletion demo/Diffusion/stable_diffusion_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions demo/Diffusion/txt2img_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -72,7 +72,7 @@ def infer(
Verbose in logging
"""
assert len(prompt) == len(negative_prompt)

with torch.inference_mode(), torch.autocast("cuda"), trt.Runtime(TRT_LOGGER):
# Pre-initialize latents
latents = self.initialize_latents( \
Expand Down
16 changes: 7 additions & 9 deletions demo/Diffusion/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Copyright 2022 The HuggingFace Inc. team.
# SPDX-FileCopyrightText: Copyright (c) 1993-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -711,7 +711,7 @@ def configure(self):

timestep_list = [self.timesteps[step_index - 1], timestep]
self.multistep_dpm_solver_second_order_coefs_precompute(timestep_list, prev_timestep)

timestep_list = [self.timesteps[step_index - 2], self.timesteps[step_index - 1], timestep]
self.multistep_dpm_solver_third_order_coefs_precompute(timestep_list, prev_timestep)

Expand All @@ -738,7 +738,7 @@ def multistep_dpm_solver_second_order_coefs_precompute(self, timestep_list, prev
h = lambda_t - lambda_s0
if self.algorithm_type == "dpmsolver++":
# See https://arxiv.org/abs/2211.01095 for detailed derivations
if self.solver_type == "midpoint":
if self.solver_type == "midpoint":
self.second_order_first_coef.append(sigma_t / sigma_s0)
self.second_order_second_coef.append((alpha_t * (torch.exp(-h) - 1.0)))
self.second_order_third_coef.append(0.5 * (alpha_t * (torch.exp(-h) - 1.0)))
Expand Down Expand Up @@ -1011,7 +1011,7 @@ def __init__(
alphas = 1.0 - betas
self.alphas_cumprod = torch.cumprod(alphas, dim=0).to(device=self.device)
self.final_alpha_cumprod = self.alphas_cumprod[0]

# standard deviation of the initial noise distribution
self.init_noise_sigma = 1.0
self.steps_offset = steps_offset
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def set_timesteps(self, steps):

def scale_model_input(self, sample: torch.FloatTensor, idx, *args, **kwargs) -> torch.FloatTensor:
return sample

def configure(self):
self.alphas_cumprod_prev = torch.roll(self.alphas_cumprod, shifts=self.step_ratio)
self.alphas_cumprod_prev[:self.step_ratio] = self.final_alpha_cumprod
Expand All @@ -1063,7 +1063,7 @@ def configure(self):
def step(self, output, sample, idx, timestep):
# step_plms: propagate the sample with the linear multi-step method. This has one forward pass with multiple
# times to approximate the solution.

# prev_timestep = timestep - self.step_ratio

if self.counter != 1:
Expand All @@ -1086,7 +1086,7 @@ def step(self, output, sample, idx, timestep):
output = (23 * self.ets[-1] - 16 * self.ets[-2] + 5 * self.ets[-3]) / 12
else:
output = (1 / 24) * (55 * self.ets[-1] - 59 * self.ets[-2] + 37 * self.ets[-3] - 9 * self.ets[-4])

if self.prediction_type == "v_prediction":
output = (self.alphas_cumprod[idx]**0.5) * output + (self.beta_cumprod[idx]**0.5) * sample
elif self.prediction_type != "epsilon":
Expand Down Expand Up @@ -1191,5 +1191,3 @@ def add_arguments(parser):
parser.add_argument('--hf-token', type=str, help="HuggingFace API access token for downloading model checkpoints")
parser.add_argument('-v', '--verbose', action='store_true', help="Show verbose output")
return parser


0 comments on commit 4af32ba

Please sign in to comment.