-
Notifications
You must be signed in to change notification settings - Fork 223
Update VitisAIQuantization to use Quark #1715
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
56b873d
469e225
1646eb7
32f22ae
e5cb11d
c569355
c4d1543
9c36257
9844278
36c5ea9
b7fc958
c426989
a170058
01012af
b158fff
1d62630
3b62d9b
40ad7d5
498b59a
7c62a0c
6645663
40541c8
d1ebcca
42c8620
9763389
042c553
a80f9e1
0a4b9ab
1b5d4d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,44 @@ | |
"""Raised when the onnxruntime fallback happens.""" | ||
|
||
|
||
def get_vai_apu_type(): | ||
# based on amd-quark examples | ||
import subprocess | ||
# Run pnputil as a subprocess to enumerate PCI devices | ||
command = r'pnputil /enum-devices /bus PCI /deviceids ' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
stdout, stderr = process.communicate() | ||
|
||
# Check for supported Hardware IDs | ||
apu_type = '' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
if 'PCI\\VEN_1022&DEV_1502&REV_00' in stdout.decode(): apu_type = 'PHX/HPT' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/E701 Warning
Multiple statements on one line (colon).
See https://docs.astral.sh/ruff/rules/multiple-statements-on-one-line-colon Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
if 'PCI\\VEN_1022&DEV_17F0&REV_00' in stdout.decode(): apu_type = 'STX' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/E701 Warning
Multiple statements on one line (colon).
See https://docs.astral.sh/ruff/rules/multiple-statements-on-one-line-colon Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
if 'PCI\\VEN_1022&DEV_17F0&REV_10' in stdout.decode(): apu_type = 'STX' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/E701 Warning
Multiple statements on one line (colon).
See https://docs.astral.sh/ruff/rules/multiple-statements-on-one-line-colon Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
if 'PCI\\VEN_1022&DEV_17F0&REV_11' in stdout.decode(): apu_type = 'STX' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/E701 Warning
Multiple statements on one line (colon).
See https://docs.astral.sh/ruff/rules/multiple-statements-on-one-line-colon Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
return apu_type | ||
|
||
def set_vai_environment_variable(apu_type, benchmark_mode=True): | ||
# based on amd-quark examples | ||
import os | ||
install_dir = os.environ['RYZEN_AI_INSTALLATION_PATH'] | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
match apu_type: | ||
Check failureCode scanning / lintrunner PYLINT/E0001 Error
Parsing failed: 'invalid syntax (olive.common.ort_inference, line 47)' (syntax-error)
See syntax-error. |
||
|
||
case 'PHX/HPT': | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
print("Setting environment for PHX/HPT") | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print |
||
|
||
os.environ['XLNX_VART_FIRMWARE'] = os.path.join(install_dir, 'voe-4.0-win_amd64', 'xclbins', 'phoenix', '1x4.xclbin') | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check noticeCode scanning / lintrunner RUFF/E501 Note
Line too long (129 > 120).
See https://docs.astral.sh/ruff/rules/line-too-long |
||
vortex-captain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
os.environ['NUM_OF_DPU_RUNNERS'] = '1' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
os.environ['XLNX_TARGET_NAME'] = 'AMD_AIE2_Nx4_Overlay' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
case 'STX': | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
print("Setting environment for STX") | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print |
||
|
||
name = '4x4' if benchmark_mode else 'Nx4' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
os.environ['XLNX_VART_FIRMWARE'] = os.path.join(install_dir, 'voe-4.0-win_amd64', 'xclbins', 'strix', f'AMD_AIE2P_{name}_Overlay.xclbin') | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check noticeCode scanning / lintrunner RUFF/E501 Note
Line too long (149 > 120).
See https://docs.astral.sh/ruff/rules/line-too-long |
||
os.environ['NUM_OF_DPU_RUNNERS'] = '1' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
os.environ['XLNX_TARGET_NAME'] = f'AMD_AIE2_{name}_Overlay' | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
case _: | ||
raise ValueError(f"Unrecognized APU type: {apu_type}. Supported types are 'PHX/HPT' and 'STX'.") | ||
print('XLNX_VART_FIRMWARE=', os.environ['XLNX_VART_FIRMWARE']) | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
print('NUM_OF_DPU_RUNNERS=', os.environ['NUM_OF_DPU_RUNNERS']) | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
print('XLNX_TARGET_NAME=', os.environ['XLNX_TARGET_NAME']) | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
|
||
|
||
# NOTE: `device_id` is only used internally for inference with Distributed ONNX models. | ||
# For regular ONNX models, the recommended way to specify the device is to set the environment variable | ||
# `CUDA_VISIBLE_DEVICES` before runnning a workflow. | ||
|
@@ -112,6 +150,25 @@ | |
elif provider == "QNNExecutionProvider": | ||
# add backend_path for QNNExecutionProvider | ||
provider_options[idx]["backend_path"] = "QnnHtp.dll" | ||
elif provider == "VitisAIExecutionProvider": | ||
|
||
import os, shutil | ||
Check warningCode scanning / lintrunner RUFF/E401 Warning
Multiple imports on one line.
See https://docs.astral.sh/ruff/rules/multiple-imports-on-one-line |
||
current_directory = os.getcwd() | ||
Check warningCode scanning / lintrunner RUFF/PTH109 Warning
os.getcwd() should be replaced by Path.cwd().
See https://docs.astral.sh/ruff/rules/os-getcwd |
||
directory_path = os.path.join(current_directory, 'cache', 'olive_model_cache') | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
vortex-captain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cache_directory = os.path.join(current_directory, 'cache') | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
|
||
# Check if the directory exists and delete it if it does. | ||
if os.path.exists(directory_path): | ||
shutil.rmtree(directory_path) | ||
print(f"Directory deleted successfully. Starting Fresh.") | ||
Check warningCode scanning / lintrunner RUFF/T201 Warning
print found.
See https://docs.astral.sh/ruff/rules/print Check warningCode scanning / lintrunner RUFF/F541 Warning
f-string without any placeholders.
See https://docs.astral.sh/ruff/rules/f-string-missing-placeholders |
||
else: | ||
print(f"Directory '{directory_path}' does not exist.") | ||
|
||
apu_type = get_vai_apu_type() | ||
set_vai_environment_variable(apu_type) | ||
install_dir = os.environ['RYZEN_AI_INSTALLATION_PATH'] | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
provider_options[idx]["config_file"] = os.path.join(install_dir, 'voe-4.0-win_amd64', 'vaip_config.json') | ||
Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warningCode scanning / lintrunner RUFF/Q000 Warning
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
provider_options[idx]["cacheDir"] = cache_directory | ||
provider_options[idx]["cacheKey"] = "olive_model_cache" | ||
logger.debug("Normalized providers: %s, provider_options: %s", providers, provider_options) | ||
|
||
# dml specific settings | ||
|
Uh oh!
There was an error while loading. Please reload this page.