tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] MarisaKirisame commented on a change in pull request #5946: [RELAY][GRAD] handle Tuple/TupleGetItem in first order gradient
Date Mon, 29 Jun 2020 20:13:57 GMT

MarisaKirisame commented on a change in pull request #5946:
URL: https://github.com/apache/incubator-tvm/pull/5946#discussion_r447226104



##########
File path: src/relay/transforms/gradient.cc
##########
@@ -106,14 +106,67 @@ struct ADValueNode {
   }
 };
 
+Expr MultiZerosType(const Type& t) {

Review comment:
       can you unify MultiZeros with MultiOnes?

##########
File path: src/relay/transforms/gradient.cc
##########
@@ -106,14 +106,67 @@ struct ADValueNode {
   }
 };
 
+Expr MultiZerosType(const Type& t) {
+  if (auto* tt = t.as<TensorTypeNode>()) {
+    return Zeros(tt->shape, tt->dtype);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    std::vector<Expr> res;
+    for (size_t i = 0; i < tt->fields.size(); i++) {
+      res.push_back(MultiZerosType(tt->fields[i]));
+    }
+    return Tuple(res);
+  } else {
+    LOG(FATAL) << "unsupported type to zero: " << tt;
+    throw;
+  }
+}
+
+Expr MultiZerosLike(const Expr& e, const Type& t) {
+  if (t.as<TensorTypeNode>()) {
+    return ZerosLike(e);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    return MultiZerosType(t);
+  } else {
+    LOG(FATAL) << "unsupported type to create zeros: " << tt;
+    throw;
+  }
+}
+
+Expr MultiOnesType(const Type& t) {
+  if (auto* tt = t.as<TensorTypeNode>()) {
+    return Ones(tt->shape, tt->dtype);
+  } else if (auto* tt = t.as<TupleTypeNode>()) {
+    std::vector<Expr> res;
+    for (size_t i = 0; i < tt->fields.size(); i++) {
+      res.push_back(MultiOnesType(tt->fields[i]));
+    }
+    return Tuple(res);
+  } else {
+    LOG(FATAL) << "unsupported type to zero: " << tt;

Review comment:
       ```suggestion
       LOG(FATAL) << "unsupported type to ones: " << tt;
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message