Skip to content

Commit df5b723

Browse files
gramalingamCopilot
andcommitted
Add assertion for outputs type and document dtype=None behavior
- Assert isinstance(outputs, int) in call_op else branch. - Document that dtype=None causes ir.tensor to infer dtype from value. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0db0320 commit df5b723

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

onnxscript/_internal/tape_builder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ def _promote_constant(self, value: Any, dtype: ir.DataType | None) -> ir.Value:
258258
This avoids initializer-name collisions when the builder is used
259259
inside the rewriter/optimizer.
260260
261+
When *dtype* is None, ``ir.tensor`` infers the dtype from the Python
262+
value (e.g. float → FLOAT, int → INT64).
263+
261264
GraphBuilder overrides this with a cache-based initializer strategy.
262265
"""
263266
tensor = ir.tensor(value, dtype=dtype)
@@ -392,13 +395,13 @@ def call_op(
392395
name=name,
393396
)
394397
else:
395-
num_outputs = len(outputs) if isinstance(outputs, Sequence) else outputs
398+
assert isinstance(outputs, int), f"Expected int, got {type(outputs)}"
396399
node = ir.Node(
397400
domain,
398401
op_type,
399402
args,
400403
attributes=attrs,
401-
num_outputs=num_outputs,
404+
num_outputs=outputs,
402405
version=version,
403406
name=name,
404407
)

0 commit comments

Comments
 (0)