[GitHub] reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite

2018-05-31 Thread GitBox
reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite
URL: https://github.com/apache/incubator-mxnet/pull/11107#discussion_r192283086
 
 

 ##
 File path: cpp-lite/include/mxnet-lite/symbol_block.h
 ##
 @@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+/*!
+*  Copyright (c) 2016 by Contributors
+* \file symbol.h
+* \brief definition of symbol
+* \author Chuntao Hong, Zhang Chen
+*/
+
+#ifndef MXNET_LITE_SYMBOL_BLOCK_H_
+#define MXNET_LITE_SYMBOL_BLOCK_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace mxnet {
+namespace lite {
+
+class SymbolBlock {
+ public:
+  SymbolBlock(const Context& context,
+  const std::vector >& flags,
+  const Symbol& output,
+  const std::vector& data_names,
+  const std::map& params) {
+auto input_names = output.ListInputs();
+num_inputs_ = input_names.size();
+std::unordered_map name_to_idx;
+for (size_t i = 0; i < input_names.size(); ++i) {
+  name_to_idx[input_names[i]] = i;
+}
+for (const auto& i : data_names) {
+  const auto iter = name_to_idx.find(i);
+  CHECK(iter != name_to_idx.end()) << "Invalid input name " << i;
+  data_indices_.push_back(iter->second);
+}
+for (const auto& i : params) {
+  std::string name = i.first;
+  if (name.compare(0, 4, "arg:") || name.compare(0, 4, "aux:")) {
+name = name.substr(4);
+  }
+  const auto iter = name_to_idx.find(name);
+  CHECK(iter != name_to_idx.end()) << "Invalid parameter name " << i.first;
+  param_indices_.push_back(iter->second);
+  if (i.second.GetContext() != context) {
+params_.push_back(i.second.Copy(context));
+  } else {
+params_.push_back(i.second);
+  }
+}
+std::vector keys, vals;
+for (const auto& i : flags) {
+  keys.push_back(i.first.c_str());
+  vals.push_back(i.second.c_str());
+}
+std::stringstream stream_data_indices, stream_param_indices;
+stream_data_indices << "[";
+for (const auto& i : data_indices_) stream_data_indices << i << ", ";
+stream_data_indices << "]";
+stream_param_indices << "[";
+for (const auto& i : param_indices_) stream_param_indices << i << ", ";
+stream_param_indices << "]";
+std::string str_data_indices = stream_data_indices.str();
+std::string str_param_indices = stream_param_indices.str();
+keys.push_back("data_indices");
+vals.push_back(str_data_indices.c_str());
+keys.push_back("param_indices");
+vals.push_back(str_param_indices.c_str());
+
+CachedOpHandle handle;
+MXNET_CALL(MXCreateCachedOpEx(
+output.GetHandle(), keys.size(), keys.data(), vals.data(), ));
+blob_ptr_ = std::make_shared(handle);
+  }
+
+  std::vector Forward(const std::vector& data) {
 
 Review comment:
   How can we use `params` if we passed `{}` to `params` in the constructor?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite

2018-05-31 Thread GitBox
reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite
URL: https://github.com/apache/incubator-mxnet/pull/11107#discussion_r192230679
 
 

 ##
 File path: cpp-lite/include/mxnet-lite/symbol_block.h
 ##
 @@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+/*!
+*  Copyright (c) 2016 by Contributors
+* \file symbol.h
+* \brief definition of symbol
+* \author Chuntao Hong, Zhang Chen
+*/
+
+#ifndef MXNET_LITE_SYMBOL_BLOCK_H_
+#define MXNET_LITE_SYMBOL_BLOCK_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace mxnet {
+namespace lite {
+
+class SymbolBlock {
+ public:
+  SymbolBlock(const Context& context,
+  const std::vector >& flags,
+  const Symbol& output,
+  const std::vector& data_names,
+  const std::map& params) {
+auto input_names = output.ListInputs();
+num_inputs_ = input_names.size();
+std::unordered_map name_to_idx;
+for (size_t i = 0; i < input_names.size(); ++i) {
+  name_to_idx[input_names[i]] = i;
+}
+for (const auto& i : data_names) {
+  const auto iter = name_to_idx.find(i);
+  CHECK(iter != name_to_idx.end()) << "Invalid input name " << i;
+  data_indices_.push_back(iter->second);
+}
+for (const auto& i : params) {
+  std::string name = i.first;
+  if (name.compare(0, 4, "arg:") || name.compare(0, 4, "aux:")) {
+name = name.substr(4);
+  }
+  const auto iter = name_to_idx.find(name);
+  CHECK(iter != name_to_idx.end()) << "Invalid parameter name " << i.first;
+  param_indices_.push_back(iter->second);
+  if (i.second.GetContext() != context) {
+params_.push_back(i.second.Copy(context));
+  } else {
+params_.push_back(i.second);
+  }
+}
+std::vector keys, vals;
+for (const auto& i : flags) {
+  keys.push_back(i.first.c_str());
+  vals.push_back(i.second.c_str());
+}
+std::stringstream stream_data_indices, stream_param_indices;
+stream_data_indices << "[";
+for (const auto& i : data_indices_) stream_data_indices << i << ", ";
+stream_data_indices << "]";
+stream_param_indices << "[";
+for (const auto& i : param_indices_) stream_param_indices << i << ", ";
+stream_param_indices << "]";
+std::string str_data_indices = stream_data_indices.str();
+std::string str_param_indices = stream_param_indices.str();
+keys.push_back("data_indices");
+vals.push_back(str_data_indices.c_str());
+keys.push_back("param_indices");
+vals.push_back(str_param_indices.c_str());
+
+CachedOpHandle handle;
+MXNET_CALL(MXCreateCachedOpEx(
+output.GetHandle(), keys.size(), keys.data(), vals.data(), ));
+blob_ptr_ = std::make_shared(handle);
+  }
+
+  std::vector Forward(const std::vector& data) {
 
 Review comment:
   For some use cases, it would be useful to keep an interface `SetInput` for 
setting an input with a name/index, such as [this 
one](https://github.com/apache/incubator-mxnet/blob/master/src/c_api/c_predict_api.cc#L360)
 in C Predict API, and the `Forward` function can run without taking any inputs 
after the user set necessary inputs through `SetInput`.
   Or another way of doing this is `Forward` takes a dict of NDArrays with 
their names as keys.
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite

2018-05-31 Thread GitBox
reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite
URL: https://github.com/apache/incubator-mxnet/pull/11107#discussion_r192229227
 
 

 ##
 File path: cpp-lite/include/mxnet-lite/symbol_block.h
 ##
 @@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+/*!
+*  Copyright (c) 2016 by Contributors
+* \file symbol.h
+* \brief definition of symbol
+* \author Chuntao Hong, Zhang Chen
+*/
+
+#ifndef MXNET_LITE_SYMBOL_BLOCK_H_
+#define MXNET_LITE_SYMBOL_BLOCK_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace mxnet {
+namespace lite {
+
+class SymbolBlock {
+ public:
+  SymbolBlock(const Context& context,
 
 Review comment:
   As we discussed, we would need an interface without distinguishing `data` 
and `params`, something like this:
   ```cpp
   SymbolBlock(const Context& context,
   const std::vector >& flags,
   const Symbol& output,
   std::vector& inputs);  // the order of inputs follows 
output.ListInputNames(kAll)
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite

2018-05-31 Thread GitBox
reminisce commented on a change in pull request #11107: [WIP][PoC] mxnet-lite
URL: https://github.com/apache/incubator-mxnet/pull/11107#discussion_r192230679
 
 

 ##
 File path: cpp-lite/include/mxnet-lite/symbol_block.h
 ##
 @@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+/*!
+*  Copyright (c) 2016 by Contributors
+* \file symbol.h
+* \brief definition of symbol
+* \author Chuntao Hong, Zhang Chen
+*/
+
+#ifndef MXNET_LITE_SYMBOL_BLOCK_H_
+#define MXNET_LITE_SYMBOL_BLOCK_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace mxnet {
+namespace lite {
+
+class SymbolBlock {
+ public:
+  SymbolBlock(const Context& context,
+  const std::vector >& flags,
+  const Symbol& output,
+  const std::vector& data_names,
+  const std::map& params) {
+auto input_names = output.ListInputs();
+num_inputs_ = input_names.size();
+std::unordered_map name_to_idx;
+for (size_t i = 0; i < input_names.size(); ++i) {
+  name_to_idx[input_names[i]] = i;
+}
+for (const auto& i : data_names) {
+  const auto iter = name_to_idx.find(i);
+  CHECK(iter != name_to_idx.end()) << "Invalid input name " << i;
+  data_indices_.push_back(iter->second);
+}
+for (const auto& i : params) {
+  std::string name = i.first;
+  if (name.compare(0, 4, "arg:") || name.compare(0, 4, "aux:")) {
+name = name.substr(4);
+  }
+  const auto iter = name_to_idx.find(name);
+  CHECK(iter != name_to_idx.end()) << "Invalid parameter name " << i.first;
+  param_indices_.push_back(iter->second);
+  if (i.second.GetContext() != context) {
+params_.push_back(i.second.Copy(context));
+  } else {
+params_.push_back(i.second);
+  }
+}
+std::vector keys, vals;
+for (const auto& i : flags) {
+  keys.push_back(i.first.c_str());
+  vals.push_back(i.second.c_str());
+}
+std::stringstream stream_data_indices, stream_param_indices;
+stream_data_indices << "[";
+for (const auto& i : data_indices_) stream_data_indices << i << ", ";
+stream_data_indices << "]";
+stream_param_indices << "[";
+for (const auto& i : param_indices_) stream_param_indices << i << ", ";
+stream_param_indices << "]";
+std::string str_data_indices = stream_data_indices.str();
+std::string str_param_indices = stream_param_indices.str();
+keys.push_back("data_indices");
+vals.push_back(str_data_indices.c_str());
+keys.push_back("param_indices");
+vals.push_back(str_param_indices.c_str());
+
+CachedOpHandle handle;
+MXNET_CALL(MXCreateCachedOpEx(
+output.GetHandle(), keys.size(), keys.data(), vals.data(), ));
+blob_ptr_ = std::make_shared(handle);
+  }
+
+  std::vector Forward(const std::vector& data) {
 
 Review comment:
   For some use cases, it would useful to keep an interface `SetInput` for 
setting a input with a name/index, such as [this 
one](https://github.com/apache/incubator-mxnet/blob/master/src/c_api/c_predict_api.cc#L360)
 in C Predict API, and the `Forward` function can run without taking any inputs 
after the user set necessary inputs through `SetInput`.
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services