Skip to content

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

vortex-captain
Copy link

@vortex-captain vortex-captain commented Mar 27, 2025

Description

Example usage in Olive workflow json:

  "passes": {
    "conversion": {
      "device": "cpu",
      "type": "OnnxConversion",
      "target_opset": 17,
      "use_dynamo_exporter": false
    },
    "to_fixed_shape": {
      "type": "DynamicToFixedShape",
      "dim_param": ["batch_size", "sequence_length"],
      "dim_value": [1, 77]
    },
    "quantization": {
      "type": "QuarkQuantization",
      "data_config": "calib_data",
      "config_template": "XINT8",
      "enable_npu_transformer": true,
      "extra_options": {
        "OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
        "ActivationSymmetric": true
      },
      "debug_mode": true,
      "log_severity_level": 0,
      "ignore_warnings": false
    }
  }

Please refer to https://quark.docs.amd.com/latest/onnx/user_guide_config_description.html for the complete list of config_template options. All the other quantization options are listed in https://quark.docs.amd.com/latest/onnx/appendix_full_quant_config_features.html .

Examples

2 ResNet examples are added to examples/vai, which convert the models using Quark then evaluate on VitisAIExecutionProvider (run on NPU, RyzenAI 1.3.1, onnxruntime-vitisai 1.19).

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

@vortex-captain vortex-captain marked this pull request as ready for review March 27, 2025 05:56
Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@vortex-captain vortex-captain requested a review from jambayk March 28, 2025 03:55
@ChaoLi-AMD
Copy link
Contributor

Describe your changes

Example usage in Olive workflow json:

  "passes": {
    "conversion": {
      "device": "cpu",
      "type": "OnnxConversion",
      "target_opset": 17,
      "use_dynamo_exporter": false
    },
    "quantization": {
      "type": "VitisAIQuantization",
      "data_config": "calib_data",
      "config_template": "INT8_TRANSFORMER_ACCURATE",
      "extra_options": {
        "OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
        "ActivationSymmetric": true
      },
      "debug_mode": true,
      "log_severity_level": 0,
      "ignore_warnings": false
    }
  }

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

please improve the example to refer to Quark documentation: https://quark.docs.amd.com/latest/supported_accelerators/ryzenai/index.html

@xiaoyu-work
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

olive/cache.py Outdated
@@ -40,6 +40,7 @@ class CacheSubDirs:
evaluations: Path
resources: Path
mlflow: Path
vitis_ai: Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain more about how will you use this folder? The cache folder is designed to be pass-agnostic so i want to double confirm the use case here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder will be created at the beginning of the evaluation step, upon the creation of a VitisAIExecutionProvider inference session (used as model cache by EP). Is evaluation considered an Olive pass?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if VitisAIEP will need to cache a model for evaluation, can we create a temporal folder for it? (and it will be deleted after all. I assume this model cache is not needed when the workflow finish.). We can create a temporary folder in cache.evaluations like temp_model_cache or something.

@shaahji
Copy link
Contributor

shaahji commented Apr 9, 2025

Update the entry in olive_config.json to point to the correct location of the pass implementation in the module. Many of the tests are failing because of the wrong entry.

@vortex-captain
Copy link
Author

Describe your changes

Example usage in Olive workflow json:

  "passes": {
    "conversion": {
      "device": "cpu",
      "type": "OnnxConversion",
      "target_opset": 17,
      "use_dynamo_exporter": false
    },
    "quantization": {
      "type": "VitisAIQuantization",
      "data_config": "calib_data",
      "config_template": "INT8_TRANSFORMER_ACCURATE",
      "extra_options": {
        "OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
        "ActivationSymmetric": true
      },
      "debug_mode": true,
      "log_severity_level": 0,
      "ignore_warnings": false
    }
  }

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

please improve the example to refer to Quark documentation: https://quark.docs.amd.com/latest/supported_accelerators/ryzenai/index.html

Added links of Quark documentation on quantization configurations

@vortex-captain vortex-captain requested review from shaahji and ChaoLi-AMD and removed request for ChaoLi-AMD April 17, 2025 07:31
@ChaoLi-AMD
Copy link
Contributor

Describe your changes

Example usage in Olive workflow json:

  "passes": {
    "conversion": {
      "device": "cpu",
      "type": "OnnxConversion",
      "target_opset": 17,
      "use_dynamo_exporter": false
    },
    "quantization": {
      "type": "VitisAIQuantization",
      "data_config": "calib_data",
      "config_template": "INT8_TRANSFORMER_ACCURATE",
      "extra_options": {
        "OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
        "ActivationSymmetric": true
      },
      "debug_mode": true,
      "log_severity_level": 0,
      "ignore_warnings": false
    }
  }

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

please improve the example to refer to Quark documentation: https://quark.docs.amd.com/latest/supported_accelerators/ryzenai/index.html

Added links of Quark documentation on quantization configurations

For a Ryzen AI example, please use XINT8 as the example instead of INT8_TRANSFORMER_ACCURATE. Just checking — does this example currently runnable on Olive?

@jambayk
Copy link
Contributor

jambayk commented Apr 17, 2025

@vortex-captain please create a copy of your branch directly in this repo and open a new PR to be able to run the CI without the login issue.

@xiaoyu-work xiaoyu-work mentioned this pull request Apr 17, 2025
6 tasks
@vortex-captain
Copy link
Author

Describe your changes

Example usage in Olive workflow json:

  "passes": {
    "conversion": {
      "device": "cpu",
      "type": "OnnxConversion",
      "target_opset": 17,
      "use_dynamo_exporter": false
    },
    "quantization": {
      "type": "VitisAIQuantization",
      "data_config": "calib_data",
      "config_template": "INT8_TRANSFORMER_ACCURATE",
      "extra_options": {
        "OpTypesToExcludeOutputQuantization": ["MatMul", "Gemm"],
        "ActivationSymmetric": true
      },
      "debug_mode": true,
      "log_severity_level": 0,
      "ignore_warnings": false
    }
  }

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.
  • Is this PR including examples changes? If yes, please remember to update example documentation in a follow-up PR.

(Optional) Issue link

please improve the example to refer to Quark documentation: https://quark.docs.amd.com/latest/supported_accelerators/ryzenai/index.html

Added links of Quark documentation on quantization configurations

For a Ryzen AI example, please use XINT8 as the example instead of INT8_TRANSFORMER_ACCURATE. Just checking — does this example currently runnable on Olive?

Updated example in description. And yes, such an example (BERT text model) is runnable on Olive, but in evaluation, the output model cannot run on NPU (all nodes assigned to CPU), unlike the ResNet examples. Any insights?

Comment on lines +157 to +163
elif provider == "VitisAIExecutionProvider":
import os

apu_type = get_vai_apu_type()
set_vai_environment_variable(apu_type)
install_dir = Path(os.environ["RYZEN_AI_INSTALLATION_PATH"])
provider_options[idx]["config_file"] = str(install_dir / "voe-4.0-win_amd64" / "vaip_config.json")
Copy link
Contributor

@VishalX VishalX May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding dependency to a specific version. I don't think we should add this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants