❓ [Question] Is it possible to export unet's tensorrt engine as a file in stable diffusion?
@gs-olive is already working on this.
Since Dec 15, 2023.
- Dominant language
- Python
- Stars
- 3k
- Forks
- 410
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 78
Description
❓ Question
Hello. I am currently trying to infer the stable diffusion XL inpaint model using your package.
model link : https://huggingface.co/diffusers/stable-diffusion-xl-1.0-inpainting-0.1
I referred to your example code and modified it as follows.
import torch
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image
import torch_tensorrt
model_id = "diffusers/stable-diffusion-xl-1.0-inpainting-0.1"
device = "cuda"
# Instantiate Stable Diffusion Pipeline with FP16 weights
pipe = AutoPipelineForInpainting.from_pretrained(
model_id, variant="fp16", torch_dtype=torch.float16
)
pipe = pipe.to(device)
backend = "torch_tensorrt"
# Optimize the UNet portion with Torch-TensorRT
pipe.unet = torch.compile(
pipe.unet,
backend=backend,
options={
"truncate_long_and_double": True,
"precision": torch.float16,
},
dynamic=False,
)
# %%
# Inference
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
image = load_image(img_url).resize((1024, 1024))
mask_image = load_image(mask_url).resize((1024, 1024))
prompt = "a tiger sitting on a park bench"
image = pipe(
prompt=prompt,
image=image,
mask_image=mask_image,
guidance_scale=8.0,
num_inference_steps=20,
strength=0.99,
).images[0]
image.save("inpaint-result.png")
On my gpu machine the conversion to tensorrt takes over 15 minutes. Since I can't do this conversion every time, I'm trying to find a way to save it in file format such as ".trt" file and use it.
When looking in your documentation, it was difficult to find such a feature. Do you support these features? If so, please let me know.
What you have already tried
Described above
Environment
docker container : nvcr.io/nvidia/pytorch:23.11-py3
gpu : p40
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.