Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
26010da
Removable castable field
gramalingam Nov 7, 2025
e4d8b8f
Prepare to replace Variable by ir.Value
gramalingam Nov 7, 2025
c8708ef
Create ir.Values, first pass
gramalingam Nov 8, 2025
2738841
A minor fix
gramalingam Nov 8, 2025
0e8efef
Various bug fixes
gramalingam Nov 8, 2025
a577f1a
Final cleanup
gramalingam Nov 8, 2025
dbda8e4
Fix matmul fusion testcase
gramalingam Nov 8, 2025
85937ed
First updates to builder
gramalingam Nov 8, 2025
9534b95
Create nodes
gramalingam Nov 11, 2025
957be40
Adding ir Graph step 1
gramalingam Nov 15, 2025
09a0c16
IRFunction cleanup docstring
gramalingam Nov 15, 2025
1d73d52
Further partial cleanup of IR
gramalingam Nov 15, 2025
ddce3b3
Ir builder cleanup
gramalingam Nov 15, 2025
7b8cd9b
IR cleanup
gramalingam Nov 15, 2025
fae6609
IR builder cleanup
gramalingam Nov 15, 2025
6b87407
IR builder cleanup
gramalingam Nov 15, 2025
0047814
Fix attribute error
gramalingam Nov 15, 2025
1917af1
Default value for attr parameter
gramalingam Nov 16, 2025
6b01c98
Fix to-graph-proto
gramalingam Nov 16, 2025
74ca996
Opset imports
gramalingam Nov 16, 2025
d855c2c
Minor fix
gramalingam Nov 16, 2025
4372082
Run lint
gramalingam Nov 16, 2025
cf1c12a
More cleanup
gramalingam Nov 16, 2025
29ec139
More cleanup
gramalingam Nov 17, 2025
95a76a2
More cleanup
gramalingam Nov 17, 2025
053e7c5
Remove unused
gramalingam Nov 17, 2025
46239f1
Minor cleanup
gramalingam Nov 17, 2025
f7eb6d1
Merge branch 'main' into rama/converter
gramalingam Nov 17, 2025
dda7977
Move to_model_proto
gramalingam Nov 17, 2025
4527f92
More cleanup
gramalingam Nov 17, 2025
fd3c14a
More cleanup
gramalingam Nov 17, 2025
09bc3d3
More cleanup
gramalingam Nov 17, 2025
5e17ae1
Address lint warning
gramalingam Nov 17, 2025
3e4b59c
Remove unused code
gramalingam Nov 17, 2025
cdfc749
More cleanup
gramalingam Nov 17, 2025
a46dcc2
Fix lint issue
gramalingam Nov 17, 2025
e0281a3
Add support for type annotation
gramalingam Nov 19, 2025
c7d1eb5
ir builder cleanup
gramalingam Nov 19, 2025
fa95a93
Cleanup IRBuilder
gramalingam Nov 20, 2025
86e10dd
More cleanup
gramalingam Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions onnxscript/_internal/autocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,27 @@ def get_type_info(x):
def static_cast_inputs(
converter_: converter.Converter,
op_schema: Optional[OpSchema],
args: Sequence[Optional[converter.Variable]],
args: Sequence[Optional[ir.Value]],
) -> tuple[str, ...]:
"""Used for autocast during script-translation.
This is meant to transform expressions like "Add(X, 1)" to "Add(X, CastLike(1, X))"
Polymorphic constants (like 0 and 1) are cast to the type of other operands as needed.
"""

def get_type_info(x: Optional[converter.Variable]) -> Optional[converter.Variable]:
def get_type_info(x: Optional[ir.Value]) -> Optional[ir.Value]:
"""Returns x back if x can serve as the target-type for a cast (as the second
argument of CastLike) and None otherwise. In the expression "Add(X, 1), 1 is
castable, while X can serve as the target-type.
"""
return None if x is None or x.is_castable else x
return None if x is None or converter_.is_castable(x.name) else x

def cast_like(
x: Optional[converter.Variable], y: Optional[converter.Variable]
) -> Optional[str]:
def cast_like(x: Optional[ir.Value], y: Optional[ir.Value]) -> Optional[str]:
if x is None:
return None
if x.is_castable and y is not None:
if converter_.is_castable(x.name) and y is not None:
# Polymorphic constant x is cast to the type of y:
x_cast = converter_.generate_unique_name(f"{x.name}_cast")
converter_.emit([x_cast], "CastLike", [x.name, y.name])
return x_cast
return x.name
return converter_.emit1([x_cast], "CastLike", [x, y])
return x

return cast_inputs(get_type_info, cast_like, op_schema, args)
Loading
Loading