Skip to content

Add multi context binary package support#2369

Draft
xiaoyu-work wants to merge 3 commits intomainfrom
xiaoyu/context_binary
Draft

Add multi context binary package support#2369
xiaoyu-work wants to merge 3 commits intomainfrom
xiaoyu/context_binary

Conversation

@xiaoyu-work
Copy link
Collaborator

Describe your changes

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.

(Optional) Issue link

@@ -0,0 +1,168 @@
# -------------------------------------------------------------------------

Check warning

Code scanning / lintrunner

RUFF-FORMAT/format Warning

Run lintrunner -a to apply this patch.
@@ -0,0 +1,234 @@
# -------------------------------------------------------------------------

Check warning

Code scanning / lintrunner

RUFF-FORMAT/format Warning test

Run lintrunner -a to apply this patch.


def _create_source_dir(tmp_path, name, model_attributes, model_type="ONNXModel"):
"""Helper to create a fake context binary output directory with model_config.json."""

Check warning

Code scanning / lintrunner

RUFF/D401 Warning test

First line of docstring should be in imperative mood: "Helper to create a fake context binary output directory with model_config.json.".
See https://docs.astral.sh/ruff/rules/non-imperative-mood

class TestMergeContextBinaryCommand:
def _run_command(self, args):
"""Helper to parse args and run the command."""

Check warning

Code scanning / lintrunner

RUFF/D401 Warning test

First line of docstring should be in imperative mood: "Helper to parse args and run the command.".
See https://docs.astral.sh/ruff/rules/non-imperative-mood

p = self._create_packager()
output_path = str(tmp_path / "output.onnx")
result = p.run(mt, output_path)

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable result is not used.

Copilot Autofix

AI about 2 hours ago

To fix the problem, remove the unused local variable while preserving the side-effecting call to p.run. We should not delete the call itself because it is what generates the manifest file the test inspects. The minimal change is to replace result = p.run(mt, output_path) with p.run(mt, output_path), eliminating the unused variable.

Concretely, in test/passes/onnx/test_multi_target_context_binary.py, within TestEPContextBinaryPackager.test_packager_with_sdk_version, change line 182 so that it calls p.run(mt, output_path) without assigning its result to any variable. No new imports, methods, or definitions are required.

Suggested changeset 1
test/passes/onnx/test_multi_target_context_binary.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/passes/onnx/test_multi_target_context_binary.py b/test/passes/onnx/test_multi_target_context_binary.py
--- a/test/passes/onnx/test_multi_target_context_binary.py
+++ b/test/passes/onnx/test_multi_target_context_binary.py
@@ -179,7 +179,7 @@
 
         p = self._create_packager()
         output_path = str(tmp_path / "output.onnx")
-        result = p.run(mt, output_path)
+        p.run(mt, output_path)
 
         manifest_path = tmp_path / "output" / "manifest.json"
         with open(manifest_path) as f:
EOF
@@ -179,7 +179,7 @@

p = self._create_packager()
output_path = str(tmp_path / "output.onnx")
result = p.run(mt, output_path)
p.run(mt, output_path)

manifest_path = tmp_path / "output" / "manifest.json"
with open(manifest_path) as f:
Copilot is powered by AI and may make mistakes. Always verify output.


try:
import onnxruntime

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'onnxruntime' is not used.

Copilot Autofix

AI about 2 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@@ -0,0 +1,496 @@
# -------------------------------------------------------------------------

Check warning

Code scanning / lintrunner

RUFF/format Warning test

Run lintrunner -a to apply this patch.
@@ -0,0 +1,496 @@
# -------------------------------------------------------------------------

Check warning

Code scanning / lintrunner

RUFF-FORMAT/format Warning test

Run lintrunner -a to apply this patch.
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
import json

Check warning

Code scanning / lintrunner

RUFF/I001 Warning test

Import block is un-sorted or un-formatted.
See https://docs.astral.sh/ruff/rules/unsorted-imports

p = self._create_packager()
output_path = str(tmp_path / "output.onnx")
result = p.run(mt, output_path)

Check warning

Code scanning / lintrunner

PYLINT/W0612 Warning test

Unused variable 'result' (unused-variable)
See unused-variable.

p = self._create_packager()
output_path = str(tmp_path / "output.onnx")
result = p.run(mt, output_path)

Check warning

Code scanning / lintrunner

RUFF/F841 Warning test

Local variable result is assigned to but never used.
See https://docs.astral.sh/ruff/rules/unused-variable


try:
import onnxruntime

Check warning

Code scanning / lintrunner

PYLINT/W0611 Warning test

Unused import onnxruntime (unused-import)
See unused-import.


try:
import onnxruntime

Check warning

Code scanning / lintrunner

RUFF/F401 Warning test

onnxruntime imported but unused; consider using importlib.util.find_spec to test for availability.
See https://docs.astral.sh/ruff/rules/unused-import
assert mock_single.call_count == 2

# Check model_attributes on targets
for name, target in result.get_target_models():

Check warning

Code scanning / lintrunner

PYLINT/W0612 Warning test

Unused variable 'name' (unused-variable)
See unused-variable.
assert mock_single.call_count == 2

# Check model_attributes on targets
for name, target in result.get_target_models():

Check warning

Code scanning / lintrunner

RUFF/B007 Warning test

Loop control variable name not used within loop body.
See https://docs.astral.sh/ruff/rules/unused-loop-control-variable
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.

1 participant