mbs-octoml commented on a change in pull request #9130:
URL: https://github.com/apache/tvm/pull/9130#discussion_r716993659
##########
File path: python/tvm/parser/__init__.py
##########
@@ -26,8 +26,10 @@ def add(self, name, content):
return _ffi.get_global_func("SourceMapAdd")(self, name, content)
-def parse(source, source_name="from_string"):
- return _ffi_api.ParseModule(source_name, source)
+def parse(source, source_name="from_string", init_module=None,
init_meta_table=None):
+ if init_meta_table is None:
Review comment:
Done. (I had the obvious default but clion was warning about mutable
defaults and suggest this instead.)
##########
File path: src/relay/op/annotation/annotation.cc
##########
@@ -92,6 +91,7 @@ RELAY_REGISTER_OP("on_device")
.add_argument("data", "Tensor", "The input data.")
.set_support_level(10)
.add_type_rel("Identity", IdentityRel)
+ .set_attrs_type_key("relay.attrs.OnDeviceAttrs")
Review comment:
Yes, this is for the "on_device" operator which still uses OnDeviceAttrs
on every CallNode. The split only applies to Function DictAttrs attrs which
apply on definitions.
##########
File path: src/parser/parser.cc
##########
@@ -1886,43 +1890,58 @@ Parser InitParser(const std::string& file_name, const
std::string& file_content,
auto tokens_and_table = Tokenize(diag_ctx, source);
auto tokens = tokens_and_table.first;
- auto meta_data_table = tokens_and_table.second;
+ MetaTable meta_data_table = tokens_and_table.second.ToMetadata();
+
+ // Merge any entries in init_meta_table into anything captured in the
#[metadata] section
+ // of the file_content. Metadata references within file_content must use
indexes which account
+ // for this ordering.
+ for (const auto& pair : init_meta_table) {
+ Array<ObjectRef> items;
+ if (meta_data_table.count(pair.first)) {
+ items = meta_data_table[pair.first];
+ }
+ for (const auto& obj : pair.second) {
+ items.push_back(obj);
+ }
+ meta_data_table.Set(pair.first, items);
+ }
Review comment:
Good call - done.
##########
File path: include/tvm/relay/attrs/function.h
##########
@@ -1,66 +0,0 @@
-/*
- * 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.
- */
-
-/*!
- * \file tvm/relay/attrs/function.h
- * \brief Attributes for Relay Functions which don't make sense on PrimFuncs.
- */
-#ifndef TVM_RELAY_ATTRS_FUNCTION_H_
-#define TVM_RELAY_ATTRS_FUNCTION_H_
-
-namespace tvm {
-namespace relay {
-/*!
- * \brief Attributes for Relay function definitions which capture the devices
for the
- * function parameters and result.
- *
- * See also OnDeviceAttrs in include/tvm/relay/attrs/annotation.h for the
companion "on_device"
- * call attributes.
- */
-struct FunctionOnDeviceAttrs : public tvm::AttrsNode<FunctionOnDeviceAttrs> {
Review comment:
On principle it would be nice if IRModule can be round tripped via the
text form (both starting from text and starting from IRModule), so we'll need
to push the attrs field addition into the parser/pretty printer. Ideally that
would just be a matter of calling ParseAttrs as we already do for function
calls, but yeah there's no support for anything other than primitive literals
in that.
I'll admit that pushes me more towards introducing a CompilerConfig class to
collect targets etc and passing it explicitly rather than embedding it in the
IRModule. Maybe take that back to #29?
##########
File path: python/tvm/parser/__init__.py
##########
@@ -26,8 +26,10 @@ def add(self, name, content):
return _ffi.get_global_func("SourceMapAdd")(self, name, content)
-def parse(source, source_name="from_string"):
- return _ffi_api.ParseModule(source_name, source)
+def parse(source, source_name="from_string", init_module=None,
init_meta_table=None):
+ if init_meta_table is None:
Review comment:
Oh, the linter complains about it too "Dangerous default value {} as
argument" - I'll go back to the silly form.
##########
File path: python/tvm/parser/__init__.py
##########
@@ -26,8 +26,10 @@ def add(self, name, content):
return _ffi.get_global_func("SourceMapAdd")(self, name, content)
-def parse(source, source_name="from_string"):
- return _ffi_api.ParseModule(source_name, source)
+def parse(source, source_name="from_string", init_module=None,
init_meta_table=None):
+ if init_meta_table is None:
Review comment:
Ah, thanks! Not so silly a rule after all.
--
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]