i have successfully converted ckpt model to onnx but running inference from it using cpu i want to use it on my amd 570 gpu. i am running it in wsl2
Assistant
User
my card wont support rocm so i want to use directml
Assistant
User
/home/vishv/anaconda3/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'DmlExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider'
warnings.warn(
Assistant
User
ERROR: Could not find a version that satisfies the requirement onnxruntime-directml (from versions: none)
ERROR: No matching distribution found for onnxruntime-directml
Assistant
Running an ONNX model on an AMD GPU within WSL2 involves several steps, including setting up the necessary environment and configuring the appropriate backends. Follow these steps to get started:
Prerequisites
WSL2: Ensure you're using WSL2 as it provides better compatibility with GPU functionalities.
AMD GPU: Verify you have an AMD Radeon RX 570.
ROCm: AMD's ROCm (Radeon Open Compute) platform is necessary for GPU computing.
Steps
Install ROCm on your WSL2 environment:
You’ll need to install the ROCm stack within your WSL2 environment. Follow the instructions from AMD ROCm Installation Guide.
Note: As of my knowledge cutoff in October 2023, ROCm may have specific Linux distribution requirements. Often, Ubuntu is recommended. Ensure WSL2 is running a supported version.
Install the necessary dependencies:
Make sure you have the following software installed:
Install ONNX and ROCm-specific packages:
Use pip to install ONNX and its runtime along with ROCm support.
sh
pip install onnx onnxruntime
Configure the ONNX Runtime to use ROCm:
In your Python script, you will need to configure the onnxruntime to use the ROCm Execution Provider.
python
import onnxruntime as ort
# Specify the ROCm Execution Provider
providers = [
('ROCMExecutionProvider', {
'device_id': 0,
'gpu_mem_limit': 2 * 1024 * 1024 * 1024 # 2GB GPU memory limit (adjust as needed)
})
]
# Load your model
model_path = 'path/to/your/model.onnx'
session = ort.InferenceSession(model_path, providers=providers)
# Prepare your inputs and run inference
inputs = {...}
result = session.run(None, inputs)
print(result)
Running the model on your GPU
Move your Model to GPU Memory:
Make sure your inputs and model are moved to GPU memory for execution.
Execute the Inference:
After configuring your onnxruntime with the ROCm Execution Provider and loading your model, you should be able to execute inference using AMD GPU.
Troubleshooting
Compatibility Check:
Ensure that your AMD GPU and WSL2 environment are compatible. Check ROCm's official compatibility list for supported GPU hardware.
Driver Issues:
Verify that all required drivers and ROCm components are correctly installed. Incorrect or outdated drivers can lead to failures in GPU computation.
Monitoring:
Use tools such as rocminfo and clinfo to verify the GPU is recognized and working correctly in ROCm.
sh
sudo apt install rocm-utils
rocminfo
clinfo
Hopefully, this guide helps you set up your environment to run ONNX models on an AMD GPU within WSL2. If you run into any specific issues, consider checking the ROCm documentation or forums for further assistance.
If your AMD GPU doesn't support ROCm, you can use DirectML to run your ONNX model on an AMD GPU within WSL2. DirectML is a hardware-accelerated machine learning API on Windows that is compatible with a broad range of GPUs, including those from AMD.
Here's a step-by-step guide to get you started:
Prerequisites
Windows 10/11 with the latest updates.
WSL2 installed with a compatible Linux distribution (e.g., Ubuntu).
AMD GPU with the latest drivers.
DirectML enabled in WSL2.
Steps
Ensure Windows and WSL2 are Up-to-Date:
Update Windows to the latest version.
Ensure WSL2 is enabled and up-to-date.
Install a compatible Linux distribution (e.g., Ubuntu 20.04 or later).
Install GPU drivers on Windows:
Install the latest AMD drivers from the AMD website. Ensure you have the appropriate drivers that support DirectML.
Enable GPU Compute for WSL2:
Make sure your WSL2 instance can access the GPU. You may need to join the Windows Insider Program and configure GPU access for WSL2 as per the DirectML setup guide for WSL2.
Install ONNX Runtime in WSL2:
Create a new environment and install the necessary libraries, including ONNX Runtime with DirectML support.
Use the DirectML execution provider in your Python script to run the ONNX model on your AMD GPU.
python
import onnxruntime as ort
# Load your model
model_path = 'path/to/your/model.onnx'
# Initialize session with DirectML Execution Provider
session = ort.InferenceSession(model_path, providers=['DmlExecutionProvider'])
# Prepare your inputs and run inference
inputs = {...} # Replace with your actual input data
result = session.run(None, inputs)
print(result)
Example Script
Here's a complete example script to run an ONNX model using DirectML on an AMD GPU within WSL2:
python
import onnxruntime as ort
import numpy as np
# Load your model
model_path = 'path/to/your/model.onnx'
# Initialize session with DirectML Execution Provider
session = ort.InferenceSession(model_path, providers=['DmlExecutionProvider'])
# Prepare dummy inputs for demonstration purposes
# Adjust these according to the input requirements of your model
input_name = session.get_inputs()[0].name
input_shape = session.get_inputs()[0].shape
inputs = {input_name: np.random.rand(*input_shape).astype(np.float32)}
# Run inference
result = session.run(None, inputs)
# Print the results
print(result)
Troubleshooting
Driver and DirectML Installation:
Ensure that you have the latest drivers installed and that DirectML is correctly set up.
Check Compatibility:
Verify that your specific GPU model is supported by DirectML.
Environment Configuration:
Ensure you are using a compatible Linux distribution within WSL2 and that onnxruntime-directml is properly installed.
By following these steps, you should be able to leverage DirectML to run your ONNX models on an AMD GPU within WSL2. If you encounter any specific errors, the DirectML and ONNXRuntime documentation, along with forums, can be valuable resources for troubleshooting.
You've encountered a warning indicating that the DmlExecutionProvider is not available in your current ONNX Runtime installation. This could be due to several reasons, including improper installation or missing dependencies. Let's walk through the steps to ensure you have everything set up correctly.
Steps to Ensure Proper Setup
Verify ONNX Runtime Installation:
Ensure that you have installed the ONNX Runtime with DirectML support. You should be using the onnxruntime-directml package.
sh
pip install onnxruntime-directml
Check Installed ONNX Runtime Package:
Verify which ONNX Runtime packages are currently installed.
sh
pip list | grep onnxruntime
Ensure you have onnxruntime-directml listed, not just onnxruntime.
Ensure Compatibility with DirectML:
DirectML is supported on Windows. Ensure that you are running your Python environment within WSL2 or a native Windows environment where WSL2 has GPU access enabled.
Enable Graphics Compute for WSL2:
You might need to manually enable GPU support in WSL2 and configure it to use DirectML.
Update WSL2 Kernel and Windows:
Make sure WSL2 and Windows are fully up to date. You may need to join the Windows Insider Program to access the latest features for GPU support in WSL2.
sh
wsl --update
Setup Windows for DirectML:
Follow the official DirectML setup guide for WSL2, which involves ensuring GPU compute support is enabled in WSL2.
Set Execution Provider Correctly:
Your script should be correct, but ensure no typographical errors:
python
import onnxruntime as ort
# Load your model
model_path = 'path/to/your/model.onnx'
# Initialize session with DirectML Execution Provider
session = ort.InferenceSession(model_path, providers=['DmlExecutionProvider'])
# Prepare your inputs and run inference
inputs = {...} # Replace with your actual input data
result = session.run(None, inputs)
print(result)
Example of Running in Native Windows Environment
If running within WSL2 proves challenging, consider testing in a native Windows Python environment to isolate the issue:
Execute your inference script in this native environment to check if DirectML is properly set up:
python
import onnxruntime as ort
# Load your model
model_path = 'path/to/your/model.onnx'
# Initialize session with DirectML Execution Provider
session = ort.InferenceSession(model_path, providers=['DmlExecutionProvider'])
# Prepare your inputs and run inference
inputs = {...} # Replace with your actual input data
result = session.run(None, inputs)
print(result)
Troubleshooting Tips
Double-Check Execution Provider Spelling:
Ensure there's no typo in the DmlExecutionProvider string.
Check Software Versions:
Ensure your ONNX Runtime version supports DirectML.
Ensure your GPU drivers are up to date and properly installed.
Validate GPU Access in WSL2:
Ensure that your WSL2 instance has access to the GPU. Run a simple script or tool that verifies GPU availability within WSL2.
Refer to Logs and Warnings:
Examine any log files or additional warnings provided by ONNX Runtime, DirectML, or WSL2.
By following these steps, you should be able to resolve the issue and successfully run ONNX inference with the DmlExecutionProvider on your AMD GPU. If problems persist, you may want to consult more specific documentation or forums related to ONNX Runtime, DirectML, and WSL2's GPU computing capabilities.
It looks like you're encountering difficulties finding the onnxruntime-directml package. This could be due to a few reasons, like Python version compatibility or package availability constraints. Here's a revised approach to resolve the issue:
1. Verify Python Version
Ensure that you are using Python 3.6 to Python 3.9, as these are the versions known to be compatible with onnxruntime-directml.
2. Install onnxruntime-directml from Source
If the package is not available via pip, you can try installing it directly from the source.
a. Clone the ONNX Runtime Repository
Open your terminal inside WSL2 or a native Windows command prompt, and clone the ONNX Runtime GitHub repository:
sh
git clone https://github.com/microsoft/onnxruntime.git
cd onnxruntime
b. Create and Activate a Virtual Environment
sh
python -m venv ort_env
source ort_env/bin/activate # For Linux/macOS
# ort_env\Scripts\activate # For Windows
c. Install onnxruntime-directml
Navigate to the onnxruntime repository directory, then run:
Once the build completes, navigate to the appropriate directory:
sh
cd build/Linux/Release # Adjust path according to your OS and configuration
pip install onnxruntime*.whl
4. Using ONNX Runtime with DirectML
After successfully installing or building onnxruntime-directml, you can use it in your Python script:
python
import onnxruntime as ort
# Path to your ONNX model
model_path = 'path/to/your/model.onnx'
# Create inference session with DirectML execution provider
session = ort.InferenceSession(model_path, providers=['DmlExecutionProvider'])
# Prepare your inputs and run inference
inputs = {...} # Replace with your actual input data
result = session.run(None, inputs)
print(result)
Final Notes
Check Your GPU Driver: Make sure your GPU driver is up-to-date and compatible with DirectML.
Using Correct Environment: Ensure you are using a compatible version of Python (3.6 to 3.9) and that you are in the correct virtual environment.
If you encounter specific errors during any of these steps, you can refer to the detailed logs or error messages, which can provide more insights into what might be going wrong.