Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DML EP takes very long time and not exit compiling #21255

Open
Jay19751103 opened this issue Jul 4, 2024 · 4 comments
Open

DML EP takes very long time and not exit compiling #21255

Jay19751103 opened this issue Jul 4, 2024 · 4 comments
Labels
ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot

Comments

@Jay19751103
Copy link

Describe the issue

When use test data to do ort.InferenceSession, takes time and not exit

To reproduce

use the onnx file put in google drive
https://drive.google.com/file/d/1y-evMcenYe-Q0JpyQvuwO0YHBX8gSSBE/view?usp=sharing
import numpy as np
import onnxruntime as ort

EP_list = ['DmlExecutionProvider']
sess_opt = ort.SessionOptions()
sess_opt.log_severity_level = 0
sess_opt.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_BASIC
sess = ort.InferenceSession("text_encoder_3.onnx", sess_opt, providers=EP_list)

use win debug see that the system is doing TryCreateCompiledOperator (see attached picture)
No matter use Nvida 3080TI or AMD 7900XTX, the problem is same.
image

Urgency

Urgent

Platform

Windows

OS Version

Windows 11 Pro OS build 22631.3593

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.18.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

DirectML

Execution Provider Library Version

No response

@github-actions github-actions bot added ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform labels Jul 4, 2024
@xadupre
Copy link
Member

xadupre commented Jul 5, 2024

Did you try to disable all optimizations? You may also try to run shape inference on the model and save it https://onnx.ai/onnx/api/shape_inference.html with shape information before loading it into onnxruntime. The function taking time seems to be related to graph fusion. You can disable it with one the session option listed here https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/dml/dml_session_options_config_keys.h and this method https://onnxruntime.ai/docs/api/python/api_summary.html#onnxruntime.SessionOptions.add_session_config_entry. How did you generate the model? Maybe it can be optimized before onnxruntime gets it. About the file you shared, you don't need to share the weights as well, only the file *.onnx is needed.

@Jay19751103
Copy link
Author

Jay19751103 commented Jul 8, 2024

Hi @xadupre

I tried to add this config
sess_opt.add_session_config_entry("ep.dml.disable_graph_fusion", "1")
sess = ort.InferenceSession("text_encoder_3.onnx", sess_opt, providers=EP_list)
can run and run also can PASS

We use the torch export , I'm not sure it can be optimized by torch export or not and the original model downloaded from huggingface with following code

import torch
from diffusers import AutoencoderKL, UNet2DConditionModel, SD3Transformer2DModel
from transformers import CLIPTextModel, CLIPTextModelWithProjection, PreTrainedModel, PreTrainedTokenizer, CLIPTokenizer, T5EncoderModel
text_input_ids = torch.zeros((1, 256), dtype=torch.long).to("cuda")
model = T5EncoderModel.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", subfolder="text_encoder_3", torch_dtype=torch.float16)
model.to("cuda")
torch.onnx.export(model, (text_input_ids, {"output_hidden_states" : True}), "text_encoder_3.onnx",input_names=['in1'])

@Jay19751103
Copy link
Author

Hi @xadupre

Is this compiling issue can be fixed ?

Copy link
Contributor

github-actions bot commented Aug 9, 2024

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

2 participants