Skip to content

Initial builder#2808

Closed
gramalingam wants to merge 4 commits intomainfrom
rama/builder
Closed

Initial builder#2808
gramalingam wants to merge 4 commits intomainfrom
rama/builder

Conversation

@gramalingam
Copy link
Collaborator

No description provided.

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
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.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 81.58508% with 79 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.69%. Comparing base (d83d50b) to head (145afc2).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/_internal/builder.py 67.66% 43 Missing and 11 partials ⚠️
onnxscript/_internal/_inference.py 62.26% 15 Missing and 5 partials ⚠️
onnxscript/_internal/builder_test.py 97.60% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2808      +/-   ##
==========================================
+ Coverage   70.52%   70.69%   +0.17%     
==========================================
  Files         228      231       +3     
  Lines       27135    27564     +429     
  Branches     2727     2776      +49     
==========================================
+ Hits        19137    19487     +350     
- Misses       7065     7125      +60     
- Partials      933      952      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
dtype = ir.DataType.STRING
else:
raise TypeError(f"Unsupported scalar type: {type(value)}")
tensor = ir.Tensor(

Check failure

Code scanning / lintrunner

PYLINT/E1123 Error

Unexpected keyword argument 'data' in constructor call (unexpected-keyword-arg)
See unexpected-keyword-arg. To disable, use # pylint: disable=unexpected-keyword-arg
dtype = ir.DataType.STRING
else:
raise TypeError(f"Unsupported scalar type: {type(value)}")
tensor = ir.Tensor(

Check failure

Code scanning / lintrunner

PYLINT/E1120 Error

No value for argument 'value' in constructor call (no-value-for-parameter)
See no-value-for-parameter. To disable, use # pylint: disable=no-value-for-parameter

def _partition_inputs_attributes(
self,
schema: onnx.defs.OpSchema | None,

Check warning

Code scanning / lintrunner

PYLINT/W0613 Warning

Unused argument 'schema' (unused-argument)
See unused-argument. To disable, use # pylint: disable=unused-argument

def _cast_attributes(
self,
schema: onnx.defs.OpSchema | None,

Check warning

Code scanning / lintrunner

PYLINT/W0613 Warning

Unused argument 'schema' (unused-argument)
See unused-argument. To disable, use # pylint: disable=unused-argument
if attributes is None:
attrs: Sequence[ir.Attr] = ()
else:
attrs = ir._convenience.convert_attributes(attributes)

Check warning

Code scanning / lintrunner

PYLINT/W0212 Warning

Access to a protected member _convenience of a client class (protected-access)
See protected-access. To disable, use # pylint: disable=protected-access
return value
elif isinstance(value, (int, float, bool, str)):
# Scalar constant
import numpy as np

Check notice

Code scanning / lintrunner

PYLINT/C0415 Note

Import outside toplevel (numpy) (import-outside-toplevel)
See import-outside-toplevel. To disable, use # pylint: disable=import-outside-toplevel
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
t2 = op.CustomOp(t1, y, _domain="com.microsoft")

# Create another custom domain operation with different domain
t3 = op.AnotherOp(t2, x, _domain="com.custom")

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable t3 is not used.

Copilot Autofix

AI 3 days ago

In general, for an unused local variable whose assignment has side effects, keep the expression (to preserve side effects) but drop or rename the unused binding. Here, the call to op.AnotherOp must remain so that the third node is added to the graph, but we do not need to store its result.

The best minimal fix without changing functionality is to remove the t3 = part and just call op.AnotherOp(t2, x, _domain="com.custom") as a standalone statement. This preserves the graph mutation while eliminating the unused variable. No imports, helper methods, or additional definitions are needed, and no other lines in the file require modification.

Suggested changeset 1
onnxscript/_internal/builder_test.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/onnxscript/_internal/builder_test.py b/onnxscript/_internal/builder_test.py
--- a/onnxscript/_internal/builder_test.py
+++ b/onnxscript/_internal/builder_test.py
@@ -324,7 +324,7 @@
         t2 = op.CustomOp(t1, y, _domain="com.microsoft")
 
         # Create another custom domain operation with different domain
-        t3 = op.AnotherOp(t2, x, _domain="com.custom")
+        op.AnotherOp(t2, x, _domain="com.custom")
 
         # Verify all nodes were created with correct domains
         nodes = list(op.builder.graph)
EOF
@@ -324,7 +324,7 @@
t2 = op.CustomOp(t1, y, _domain="com.microsoft")

# Create another custom domain operation with different domain
t3 = op.AnotherOp(t2, x, _domain="com.custom")
op.AnotherOp(t2, x, _domain="com.custom")

# Verify all nodes were created with correct domains
nodes = list(op.builder.graph)
Copilot is powered by AI and may make mistakes. Always verify output.

# Use operations through the custom domain opset builder
t1 = ms_op.CustomOp(x, y)
t2 = ms_op.AnotherOp(t1, x)

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable t2 is not used.

Copilot Autofix

AI 3 days ago

In general, to fix an unused local variable where the right-hand side has side effects, you should keep the expression call and remove only the binding of its result, or rename the variable to an “unused” name if you want to explicitly mark it as intentionally unused. Here, the right-hand side ms_op.AnotherOp(t1, x) clearly has the desired side effect of adding a node to op.builder.graph, and the variable t2 is never subsequently used.

The best minimal fix without changing functionality is to drop the assignment and just call the method. In onnxscript/_internal/builder_test.py, within test_opset_builder_for_custom_domain, change line 351 from t2 = ms_op.AnotherOp(t1, x) to ms_op.AnotherOp(t1, x). No new imports or helper methods are required, and no other lines in this file need to be touched.

Suggested changeset 1
onnxscript/_internal/builder_test.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/onnxscript/_internal/builder_test.py b/onnxscript/_internal/builder_test.py
--- a/onnxscript/_internal/builder_test.py
+++ b/onnxscript/_internal/builder_test.py
@@ -348,7 +348,7 @@
 
         # Use operations through the custom domain opset builder
         t1 = ms_op.CustomOp(x, y)
-        t2 = ms_op.AnotherOp(t1, x)
+        ms_op.AnotherOp(t1, x)
 
         # Verify all nodes were created with the correct domain
         nodes = list(op.builder.graph)
EOF
@@ -348,7 +348,7 @@

# Use operations through the custom domain opset builder
t1 = ms_op.CustomOp(x, y)
t2 = ms_op.AnotherOp(t1, x)
ms_op.AnotherOp(t1, x)

# Verify all nodes were created with the correct domain
nodes = list(op.builder.graph)
Copilot is powered by AI and may make mistakes. Always verify output.
# Mix operations from different domains
t1 = op.Add(x, y) # Standard domain operation
t2 = ms_op.MsAdd(t1, y) # Custom domain operation
t3 = op.Mul(t2, x) # Back to standard domain

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable t3 is not used.

Copilot Autofix

AI 3 days ago

In general, to fix an unused local variable whose right-hand side has important side effects, you keep the expression but either remove the left-hand side entirely (if syntax allows) or bind it to a name that clearly indicates it is intentionally unused (such as _ or a name containing unused). This preserves behavior while silencing the warning and clarifying intent.

Here, we should not remove the op.Mul(t2, x) call, because its side effect (adding a node to the graph) is required for the later assertions about nodes[2]. The simplest, non-disruptive change is to rename t3 to _ on line 379. That makes it explicit that the result value is not used while leaving test logic unchanged. No imports or further definitions are required, and only that single line in onnxscript/_internal/builder_test.py needs modification.

Suggested changeset 1
onnxscript/_internal/builder_test.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/onnxscript/_internal/builder_test.py b/onnxscript/_internal/builder_test.py
--- a/onnxscript/_internal/builder_test.py
+++ b/onnxscript/_internal/builder_test.py
@@ -376,7 +376,7 @@
         # Mix operations from different domains
         t1 = op.Add(x, y)  # Standard domain operation
         t2 = ms_op.MsAdd(t1, y)  # Custom domain operation
-        t3 = op.Mul(t2, x)  # Back to standard domain
+        _ = op.Mul(t2, x)  # Back to standard domain
 
         # Verify nodes were created with correct domains
         nodes = list(op.builder.graph)
EOF
@@ -376,7 +376,7 @@
# Mix operations from different domains
t1 = op.Add(x, y) # Standard domain operation
t2 = ms_op.MsAdd(t1, y) # Custom domain operation
t3 = op.Mul(t2, x) # Back to standard domain
_ = op.Mul(t2, x) # Back to standard domain

# Verify nodes were created with correct domains
nodes = list(op.builder.graph)
Copilot is powered by AI and may make mistakes. Always verify output.
t2 = op.CustomOp(t1, y, _domain="com.microsoft")

# Create another custom domain operation with different domain
t3 = op.AnotherOp(t2, x, _domain="com.custom")

# Use operations through the custom domain opset builder
t1 = ms_op.CustomOp(x, y)
t2 = ms_op.AnotherOp(t1, x)
# Mix operations from different domains
t1 = op.Add(x, y) # Standard domain operation
t2 = ms_op.MsAdd(t1, y) # Custom domain operation
t3 = op.Mul(t2, x) # Back to standard domain


class GraphBuilder:
def __init__(self, graph: ir.Graph, is_function: bool) -> None:

Check warning

Code scanning / lintrunner

PYLINT/W0613 Warning

Unused argument 'is_function' (unused-argument)
See unused-argument. To disable, use # pylint: disable=unused-argument
t2 = op.CustomOp(t1, y, _domain="com.microsoft")

# Create another custom domain operation with different domain
t3 = op.AnotherOp(t2, x, _domain="com.custom")

Check warning

Code scanning / lintrunner

PYLINT/W0612 Warning

Unused variable 't3' (unused-variable)
See unused-variable. To disable, use # pylint: disable=unused-variable
t2 = op.CustomOp(t1, y, _domain="com.microsoft")

# Create another custom domain operation with different domain
t3 = op.AnotherOp(t2, x, _domain="com.custom")

Check warning

Code scanning / lintrunner

RUFF/F841 Warning

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

# Use operations through the custom domain opset builder
t1 = ms_op.CustomOp(x, y)
t2 = ms_op.AnotherOp(t1, x)

Check warning

Code scanning / lintrunner

PYLINT/W0612 Warning

Unused variable 't2' (unused-variable)
See unused-variable. To disable, use # pylint: disable=unused-variable

# Use operations through the custom domain opset builder
t1 = ms_op.CustomOp(x, y)
t2 = ms_op.AnotherOp(t1, x)

Check warning

Code scanning / lintrunner

RUFF/F841 Warning

Local variable t2 is assigned to but never used.
See https://docs.astral.sh/ruff/rules/unused-variable
# Mix operations from different domains
t1 = op.Add(x, y) # Standard domain operation
t2 = ms_op.MsAdd(t1, y) # Custom domain operation
t3 = op.Mul(t2, x) # Back to standard domain

Check warning

Code scanning / lintrunner

PYLINT/W0612 Warning

Unused variable 't3' (unused-variable)
See unused-variable. To disable, use # pylint: disable=unused-variable
# Mix operations from different domains
t1 = op.Add(x, y) # Standard domain operation
t2 = ms_op.MsAdd(t1, y) # Custom domain operation
t3 = op.Mul(t2, x) # Back to standard domain

Check warning

Code scanning / lintrunner

RUFF/F841 Warning

Local variable t3 is assigned to but never used.
See https://docs.astral.sh/ruff/rules/unused-variable
@gramalingam
Copy link
Collaborator Author

Hmmm ... interesting, I don't remember creating this PR (as it is still WIP) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant