Skip to content

Retire get_schema in Op | chore!(api) #698

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

Merged
merged 18 commits into from
May 1, 2023
Merged

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Apr 28, 2023

Stack from ghstack (oldest at bottom):

Remove get_schema in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

Rename opschema to op_schema for naming consistency.

@gramalingam
Copy link
Collaborator

The cleanup is a good idea. However, I wonder if it is incomplete. Perhaps the lookup in the opset should be moved into __init__ ? Or, perhaps it would be better to have some lookup-mechanism to get the Op corresponding to a given (opset, opname)? I feel I don't have an accurate mental-model here, as things have changed over time, especially, with the switch to explicit classes being introduced for every standard-op vs. having a lightweight proxy representing it earlier. Not sure if the entire code-base is consistent regarding this.

@justinchuby
Copy link
Collaborator Author

Perhaps the lookup in the opset should be moved into __init__ ?

I think it is done in the generated code:

schema = get_schema("BitwiseAnd", 18, "")
op: Callable[
..., Union[INT16, INT32, INT64, INT8, UINT16, UINT32, UINT64, UINT8]
] = Op(self, "BitwiseAnd", schema)
return op(*self._prepare_inputs(schema, A, B))

Although this will mean if anything is not yet generated (e.g. opset20), it will no longer find the opschema after this change, which I think is ok.

Or, perhaps it would be better to have some lookup-mechanism to get the Op corresponding to a given (opset, opname)?

Is this it, in Opset?

def __getitem__(self, opname):
try:
return onnx.defs.get_schema(opname, self.version, self.domain)
except Exception: # pylint: disable=broad-except # TODO: more specific exception
return None

@gramalingam
Copy link
Collaborator

Is this it, in Opset?

No, that just returns the schema. (That should probably be cleaned up too, at some point.) I mean, a method to get the Op representation of, say, the Gemm op in opset 18. I guess right now we need to call the Op constructor, and specify the schema when we call the constructor? That seems redundant, since for standard ops, the schema can be picked up automatically.

@justinchuby
Copy link
Collaborator Author

Since the code is auto generated I think that's ok? The op can be obtained by getattr(opset18, "Gemm")

@justinchuby justinchuby changed the base branch from gh/justinchuby/24/base to main April 28, 2023 18:52
@justinchuby
Copy link
Collaborator Author

With this change I am getting the stack below. I can't seem to locate the error. Does this stack make sense to you?

================================================= ERRORS =================================================
_________________ ERROR collecting onnxscript/tests/function_libs/torch_lib/ops_test.py __________________
onnxscript/tests/function_libs/torch_lib/ops_test.py:33: in <module>
    from onnxscript.tests.function_libs.torch_lib import ops_test_common, ops_test_data
onnxscript/tests/function_libs/torch_lib/ops_test_data.py:41: in <module>
    from onnxscript.function_libs.torch_lib.ops import core as core_ops
onnxscript/function_libs/torch_lib/ops/__init__.py:12: in <module>
    from . import core, fft, linalg, nested, nn, prims, sparse, special
onnxscript/function_libs/torch_lib/ops/core.py:1088: in <module>
    def aten_clamp_max(self: TReal, max_: TReal) -> TReal:
onnxscript/function_libs/torch_lib/registration.py:91: in wrapper
    processed_func = onnxscript.script(opset=custom_opset)(func)
onnxscript/main.py:116: in transform
    result = script_check(
onnxscript/main.py:60: in script_check
    return convert.top_level_stmt(f)
onnxscript/converter.py:1383: in top_level_stmt
    fn_ir = self.translate_function_def(stmt)
onnxscript/converter.py:1372: in translate_function_def
    self.translate_stmt(s, index_of_stmt=i)
onnxscript/converter.py:938: in translate_stmt
    return self.translate_if_stmt(node)
onnxscript/converter.py:1048: in translate_if_stmt
    elseGraph, sub_fct_else = self.translate_block(
onnxscript/converter.py:1252: in translate_block
    self.translate_stmt(s)
onnxscript/converter.py:938: in translate_stmt
    return self.translate_if_stmt(node)
onnxscript/converter.py:1044: in translate_if_stmt
    thenGraph, sub_fct_then = self.translate_block(
onnxscript/converter.py:1293: in translate_block
    return graph.to_graph_and_functions()
onnxscript/irbuilder.py:392: in to_graph_and_functions
    [s.to_node_proto(f"n{i}") for i, s in enumerate(self.stmts)],
onnxscript/irbuilder.py:392: in <listcomp>
    [s.to_node_proto(f"n{i}") for i, s in enumerate(self.stmts)],
onnxscript/irbuilder.py:216: in to_node_proto
    [_opt_var_to_str(x) for x in self.args],
onnxscript/irbuilder.py:216: in <listcomp>
    [_opt_var_to_str(x) for x in self.args],
onnxscript/irbuilder.py:108: in _opt_var_to_str
    return "" if x is None else str(x)
E   TypeError: __str__ returned non-string (type NoneType)

Debug info:

------------------------------------------ live log collection -------------------------------------------
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_abs
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_acos
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_acosh
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_add
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:279 Converter:bind:alpha
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:279 Converter:bind:alpha
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_addmm
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:mat1
DEBUG    onnxscript:converter.py:279 Converter:bind:mat2
DEBUG    onnxscript:converter.py:279 Converter:bind:beta
DEBUG    onnxscript:converter.py:279 Converter:bind:alpha
DEBUG    onnxscript:converter.py:279 Converter:bind:mat1_mat2
DEBUG    onnxscript:converter.py:279 Converter:bind:scaled_mat1_mat2
DEBUG    onnxscript:converter.py:279 Converter:bind:scaled_self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_alias
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_all
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self_bool
DEBUG    onnxscript:converter.py:279 Converter:bind:self_int
DEBUG    onnxscript:converter.py:279 Converter:bind:result_int
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_all_dim
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self_bool
DEBUG    onnxscript:converter.py:279 Converter:bind:self_int
DEBUG    onnxscript:converter.py:279 Converter:bind:dims
DEBUG    onnxscript:converter.py:279 Converter:bind:result_int
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_allclose
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:279 Converter:bind:rtol
DEBUG    onnxscript:converter.py:279 Converter:bind:atol
DEBUG    onnxscript:converter.py:279 Converter:bind:equal_nan
DEBUG    onnxscript:converter.py:279 Converter:bind:left_part
DEBUG    onnxscript:converter.py:279 Converter:bind:right_part
DEBUG    onnxscript:converter.py:279 Converter:bind:is_close
DEBUG    onnxscript:converter.py:279 Converter:bind:is_close_int
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_amax
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_amin
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_any
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:279 Converter:bind:self_rank
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self_bool
DEBUG    onnxscript:converter.py:279 Converter:bind:self_int
DEBUG    onnxscript:converter.py:279 Converter:bind:result_max
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_any_dim
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:279 Converter:bind:self_rank
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self_bool
DEBUG    onnxscript:converter.py:279 Converter:bind:self_int
DEBUG    onnxscript:converter.py:279 Converter:bind:dims
DEBUG    onnxscript:converter.py:279 Converter:bind:result_max
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_argmax_dim
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:279 Converter:bind:self_is_scaler
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_argmin_dim
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:keepdim
DEBUG    onnxscript:converter.py:279 Converter:bind:self_is_scaler
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:_aten_as_strided_onnx
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:size
DEBUG    onnxscript:converter.py:279 Converter:bind:stride
DEBUG    onnxscript:converter.py:279 Converter:bind:storage_offset
DEBUG    onnxscript:converter.py:279 Converter:bind:rank
DEBUG    onnxscript:converter.py:279 Converter:bind:neg_1
DEBUG    onnxscript:converter.py:279 Converter:bind:rank_tensor
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:one_seq
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'ast.For'>
DEBUG    onnxscript:converter.py:279 Converter:bind:i
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:one_seq
DEBUG    onnxscript:converter.py:279 Converter:bind:j
DEBUG    onnxscript:converter.py:279 Converter:bind:j_tensor
DEBUG    onnxscript:converter.py:279 Converter:bind:size_dim_j
DEBUG    onnxscript:converter.py:279 Converter:bind:size_after_j
DEBUG    onnxscript:converter.py:279 Converter:bind:stride_dim_j
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:add_value
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:3:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:shape
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:3
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:3:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:ones
DEBUG    onnxscript:converter.py:279 Converter:bind:shape
DEBUG    onnxscript:converter.py:279 Converter:bind:shape
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:3
DEBUG    onnxscript:converter.py:279 Converter:bind:shape
DEBUG    onnxscript:converter.py:279 Converter:bind:add_value
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:one_seq
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:one_seq
DEBUG    onnxscript:converter.py:279 Converter:bind:self_flatten
DEBUG    onnxscript:converter.py:279 Converter:bind:indices
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_asin
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_asinh
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_atan
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_atan2
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:279 Converter:bind:slope
DEBUG    onnxscript:converter.py:279 Converter:bind:atan
DEBUG    onnxscript:converter.py:279 Converter:bind:second_third_quadrant
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_atanh
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_baddbmm
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:batch1
DEBUG    onnxscript:converter.py:279 Converter:bind:batch2
DEBUG    onnxscript:converter.py:279 Converter:bind:beta
DEBUG    onnxscript:converter.py:279 Converter:bind:alpha
DEBUG    onnxscript:converter.py:279 Converter:bind:batch_mul
DEBUG    onnxscript:converter.py:279 Converter:bind:alpha_cast
DEBUG    onnxscript:converter.py:279 Converter:bind:mul_a
DEBUG    onnxscript:converter.py:279 Converter:bind:beta_cast
DEBUG    onnxscript:converter.py:279 Converter:bind:mul_b
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_and
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_left_shift
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_not
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_not_bool
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_or
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_right_shift
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bitwise_xor
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:other
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_bmm
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:mat2
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_broadcast_to
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:size
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_cat
DEBUG    onnxscript:converter.py:279 Converter:bind:tensors
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_ceil
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_chunk
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:chunks
DEBUG    onnxscript:converter.py:279 Converter:bind:dim
DEBUG    onnxscript:converter.py:279 Converter:bind:neg_1
DEBUG    onnxscript:converter.py:279 Converter:bind:self_shape
DEBUG    onnxscript:converter.py:279 Converter:bind:dim_size
DEBUG    onnxscript:converter.py:279 Converter:bind:num_per_chunk
DEBUG    onnxscript:converter.py:279 Converter:bind:num_per_chunk
DEBUG    onnxscript:converter.py:279 Converter:bind:num_chunk
DEBUG    onnxscript:converter.py:279 Converter:bind:list_split
DEBUG    onnxscript:converter.py:279 Converter:bind:remainder
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:list_split
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:279 Converter:bind:list_split
DEBUG    onnxscript:converter.py:1369 Converter:translate_function_def:aten_clamp_max
DEBUG    onnxscript:converter.py:279 Converter:bind:self
DEBUG    onnxscript:converter.py:279 Converter:bind:max_
DEBUG    onnxscript:converter.py:279 Converter:bind:self_size
DEBUG    onnxscript:converter.py:279 Converter:bind:max_shape
DEBUG    onnxscript:converter.py:279 Converter:bind:max_rank
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:2
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:2:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:265 Converter:enter_scope:3:node:<class 'NoneType'>
DEBUG    onnxscript:converter.py:279 Converter:bind:max_
DEBUG    onnxscript:converter.py:279 Converter:bind:result
DEBUG    onnxscript:converter.py:269 Converter:exit_scope:3
collected 0 items / 1 error           

Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: 771b415
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby changed the base branch from main to gh/justinchuby/24/base April 28, 2023 19:00
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: 771b415
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: e894b25
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: 1178555
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
justinchuby added a commit that referenced this pull request Apr 28, 2023
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* #698
* __->__ #674

This PR implements auto OpSchema generation for trace_only function as
well. It leverages onnxscript's converter to create the same function IR
as we do in `OnnxFunction`, but without translating the body.

We created an `TracedOnnxFunction` class to expose a similar interface
as `OnnxFunction`, and an `OpLike` protocol to standardize them.

- Creates the `OpLike` protocol that defines common attributes and
methods for `Op`, `OnnxFunction` and `TracedOnnxFunction` so we can
assume a common interface.
- Implement `param_schemas` for `TracedOnnxFunction`
- Refactor `param_schemas` to extract common logic.
- Removes `is_single_op` from `Op` because it is unused.
- Refactor ast logic from `main.py` to
`onnxscript/_internal/ast_utils.py`
- The change is tested on all the existing trace_only functions.

Fixes #630
@justinchuby justinchuby changed the base branch from gh/justinchuby/24/base to main April 28, 2023 19:55
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: 1bc5d2c
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
@@ -135,7 +135,7 @@ def __init__(self, name: Optional[Union[str, List[str]]], kind: ConverterExpress
def is_const(self):
return self.kind == ConverterExpressionKind.CONST

def __str__(self):
def __str__(self) -> str:
return self.name
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gramalingam name is Optional[Union[str, List[str]]]. Should we change this or the type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the type to optional[str] ... that's what translation of None seems to generate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean changing the name's type to optional[str]? __str__ always needs to return a string. should we do something to self.name when is it None in this function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could do "" if self.name is None else self.name. Not sure if and where this is used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add an assert for now since it looks like we don't expect it to be None or anything other than str.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a recollection that this may be used in the translation of None ... in other words, I suspect we might be creating a ConverterExpression that has no name (that is, self.name is None). However, we likely don't invoke the str method on it. So, it's fine in that sense. (Anyway, I suspect a bigger cleanup of ConverterExpression is due at some point, so that's another reason not to bother much for now.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SG!

Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

Rename `opschema` to `op_schema` for naming consistency. 

[ghstack-poisoned]
Remove `get_schema` in Op because (1) if an op does not have schema, it will not be in its opset either. (2) If an op does have schema, we don't need to consult with the opset. This change ensures a single correct way of accessing OpSchema.

Rename `opschema` to `op_schema` for naming consistency. 

[ghstack-poisoned]
justinchuby added a commit that referenced this pull request Apr 28, 2023
ghstack-source-id: ef95fd1
Pull Request resolved: #698

Signed-off-by: Justin Chu <[email protected]>
if op_schema is None:
self._op_schema = opset[opname]
else:
self._op_schema = op_schema
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I believe self._op_schema = op_schema or opset[opname] does the same thing more compactly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@justinchuby justinchuby merged commit 92d5d71 into main May 1, 2023
@justinchuby justinchuby deleted the gh/justinchuby/24/head branch May 1, 2023 21:40
justinchuby added a commit that referenced this pull request May 2, 2023
…700)

This requires ONNX 1.14. I am skipping the op test for ONNX<1.14
altogether.

I tested locally to make sure no float32 test is skipped with this
mechanism, and that it skips properly according to the type annotation.

Currently no new dtypes are enabled because there are too many failures.

Requires 
- #701 
- #698
Indie365 pushed a commit to Indie365/onnxscript that referenced this pull request Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change base before merge Remember to change the merge base to main when the PR is ready to merge topic: api topic: breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants