areusch commented on code in PR #13402:
URL: https://github.com/apache/tvm/pull/13402#discussion_r1044908822
##########
python/tvm/relay/frontend/common.py:
##########
@@ -997,3 +1002,167 @@ def try_resolve_var_to_const(x, graph_params):
return _op.const(value, dtype)
return x
+
+
+class _SpanFiller(ExprMutator):
+ """SpanFiller"""
+
+ def __init__(self, span):
+ ExprMutator.__init__(self)
+ if isinstance(span, tvm.relay.Span):
+ self._span = span
+ elif isinstance(span, str):
+ self._span = tvm.relay.Span(tvm.relay.SourceName(span), 0, 0, 0, 0)
+ elif isinstance(span, bytes):
+ self._span =
tvm.relay.Span(tvm.relay.SourceName(span.decode("utf-8")), 0, 0, 0, 0)
+ else:
+ assert False, f"unsupported span type: {type(span)}"
+
+ def visit(self, expr):
+ if hasattr(expr, "span") and expr.span:
+ return expr
+
+ return super().visit(expr)
+
+ def visit_function(self, fn):
+ new_params = [self.visit(x) for x in fn.params]
+ new_body = self.visit(fn.body)
+ return _function.Function(
Review Comment:
want to use FunctionWithFields here too? (and similar below)
##########
python/tvm/relay/frontend/common.py:
##########
@@ -997,3 +1002,167 @@ def try_resolve_var_to_const(x, graph_params):
return _op.const(value, dtype)
return x
+
+
+class _SpanFiller(ExprMutator):
Review Comment:
ok, given for now we want to invoke this after the import, we can keep it as
Python for now
##########
python/tvm/testing/utils.py:
##########
@@ -2081,3 +2081,28 @@ def pprint(name, obj):
f"or an instance of `tvm.tir.PrimFunc`. "
f"Instead, received {type(expected)}."
)
+
+
+class _control_span_filling:
+ def __init__(self, on=True):
+ self._old_state = os.environ["TVM_SPANFILLING"] if "TVM_SPANFILLING"
in os.environ else None
Review Comment:
right--sorry perhaps I should have commented on _should_fill_span in
python/tvm/relay/frontend/common.py. what I mean is--could we consider a global
variable or a PassContext option which can be initialized from the env should a
driver script want, rather than forcing this control to be in the environment?
##########
tests/python/relay/utils/tag_span.py:
##########
@@ -0,0 +1,106 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import tvm
+from tvm import relay, tir
+from tvm.relay.expr_functor import ExprVisitor
+
+
+def _set_span(expr, src):
Review Comment:
i think if you're going to do something like this, it would be great to just
add e.g. CallWithFields and TupleWithFields properly to the FFI now. no need to
migrate any other code, but keeping this code in test here seems like it's
asking for two implementations to surface. lmk if this is too much of a burden.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]