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

How to do multithreaded infer with onnxruntime #21419

Open
XiaBing992 opened this issue Jul 19, 2024 · 2 comments
Open

How to do multithreaded infer with onnxruntime #21419

XiaBing992 opened this issue Jul 19, 2024 · 2 comments
Labels
stale issues that have not been addressed in a while; categorized by a bot

Comments

@XiaBing992
Copy link

Describe the issue

When I do multithreaded infer via onnxruntime(python), I get an error. My onnx_session are all independent, model files are all read independently, for multithreaded reasoning what should I do?
1

To reproduce

...
def Infer(self, request, context):
# 推理
log.info('infer...')
model_path = os.path.join(MODEL_DIR, request.model_name)
input = np.array(request.input).astype(np.float32)
......
providers = [
('CUDAExecutionProvider', {
'device_id': 0,
}),
'CPUExecutionProvider',
]
onnx_session = onnxruntime.InferenceSession(model_path, providers = providers)
........

    output = onnx_session.run(output_name, input_feed=input_feed)

    .......

if name == 'main':

thread_num = 50
threads = []
start_time = time.time()
for index in range(thread_num):
    threads.append(threading.Thread(target = Infer, args=......))
    threads[index].start()

for th in threads:
    th.join()

end_time = time.time()

log.info('all time: {}'.format(end_time - start_time))

Urgency

No response

Platform

Linux

OS Version

ubuntu 20.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.18.1

ONNX Runtime API

Python

Architecture

X64

Execution Provider

CUDA

Execution Provider Library Version

12.4

@github-actions github-actions bot added the ep:CUDA issues related to the CUDA execution provider label Jul 19, 2024
@wejoncy
Copy link
Contributor

wejoncy commented Jul 22, 2024

Do you want multi-sessions in your senario?
Multiprocessing should work for you.

@sophies927 sophies927 removed the ep:CUDA issues related to the CUDA execution provider label Jul 25, 2024
Copy link
Contributor

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 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants