[GitHub] [incubator-tvm] siju-samuel commented on pull request #5834: Improve type handling in PyTorch frontend
siju-samuel commented on pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#issuecomment-646437081 @t-vi please rebase. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tmoreau89 commented on pull request #5842: [VTA][OpenCL] Cloud FPGA support
tmoreau89 commented on pull request #5842: URL: https://github.com/apache/incubator-tvm/pull/5842#issuecomment-646427274 CC-ing @vegaluisjose @huajsj @pasqoc 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: us...@infra.apache.org
[GitHub] [incubator-tvm-vta] tmoreau89 commented on pull request #9: [Hardware][OpenCL] Intelfocl support
tmoreau89 commented on pull request #9: URL: https://github.com/apache/incubator-tvm-vta/pull/9#issuecomment-646427173 CC-ing @vegaluisjose @huajsj @pasqoc 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: us...@infra.apache.org
[GitHub] [incubator-tvm-vta] tmoreau89 commented on pull request #9: [Hardware][OpenCL] Intelfocl support
tmoreau89 commented on pull request #9: URL: https://github.com/apache/incubator-tvm-vta/pull/9#issuecomment-646427144 CC-ing @vegaluisjose @huajsj @pasqoc 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: us...@infra.apache.org
[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #5754: [RFC] Improve quantized convolution performance for armv8 architectures
FrozenGene commented on a change in pull request #5754: URL: https://github.com/apache/incubator-tvm/pull/5754#discussion_r442604112 ## File path: src/relay/op/nn/convolution.h ## @@ -383,6 +383,38 @@ inline bool Conv2DWinogradWeightTransformRel(const Array& types, int num_i return true; } +// Gemm convolution shape relations +inline bool Conv2DGemmWeightTransformRel(const Array& types, int num_inputs, + const Attrs& attrs, const TypeReporter& reporter) { + CHECK_EQ(types.size(), 2); + const auto* data = types[0].as(); Review comment: Sugget naming `data` to `weight` ## File path: python/tvm/relay/qnn/op/legalizations.py ## @@ -237,17 +237,23 @@ def is_fast_int8_on_arm(): target = tvm.target.Target.current(allow_none=False) return '+v8.2a,+dotprod' in ' '.join(target.options) +def is_aarch64_arm(): +""" Checks whether the hardware has support for fast Int8 arithmetic operations. """ +target = tvm.target.Target.current(allow_none=False) +return 'aarch64' in ' '.join(target.options) + # ARM CPU legalizations. @qnn_conv2d_legalize.register('arm_cpu') def _qnn_conv2d_legalize_arm_cpu(attrs, inputs, types): # ARM prefers the dtypes to be same. -if is_fast_int8_on_arm(): +if is_aarch64_arm() and attrs["data_layout"] == "NHWC" or is_fast_int8_on_arm(): Review comment: Let us add `parentheses`. i.e. `if (is_aarch64_arm() and attrs["data_layout"] == "NHWC") or is_fast_int8_on_arm()` ## File path: topi/python/topi/arm_cpu/conv2d_gemm.py ## @@ -0,0 +1,176 @@ +# 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. +# pylint: disable=invalid-name, unused-variable, too-many-locals +# pylint: disable=unused-argument, redefined-builtin +"""GEMM Convolution schedule on ARM""" +import tvm +from tvm import te +from topi import nn +from ..util import get_const_tuple +from ..nn.util import get_pad_tuple +from .tensor_intrin import gemv_quantized, gemv_quantized_impl + + +# Compute function +def compute_conv2d_gemm_without_weight_transform(cfg, + data, B_interleaved_t, strides, padding, dilation, + out_dtype, kernel_size, output_channels): +"""Compute conv2d by transforming the input, +executing GEMM and transforming the output back""" +batches, IH, IW, IC = get_const_tuple(data.shape) + +KH, KW = kernel_size +OC = output_channels + +K_AREA = KH * KW + +if isinstance(dilation, int): +dilation_h = dilation_w = dilation +else: +dilation_h, dilation_w = dilation + +dilated_kernel_h = (KH - 1) * dilation_h + 1 +dilated_kernel_w = (KW - 1) * dilation_w + 1 + +pad_top, pad_left, pad_down, pad_right = \ +get_pad_tuple(padding, (dilated_kernel_h, dilated_kernel_w)) +HSTR, WSTR = strides if isinstance(strides, (tuple, list)) else (strides, strides) + +OH = (IH + pad_top + pad_down - dilated_kernel_h) // HSTR + 1 +OW = (IW + pad_left + pad_right - dilated_kernel_w) // WSTR + 1 +if pad_top or pad_left: +data_pad = nn.pad(data, [0, pad_top, pad_left, 0], [0, pad_down, pad_right, 0], + name="data_pad") +else: +data_pad = data + +# --- Im2col +M = OH * OW +K = IC * K_AREA +N = OC + +A_shape = (batches, M, K) +if K_AREA == 1: +A = te.compute(A_shape, lambda n, x, y: data_pad[n, HSTR * (x // OW), WSTR * (x % OW), y], + name='data_flatten') +else: +A = te.compute(A_shape, lambda n, x, y: + data_pad[n, +HSTR * (x // OW) + dilation_h * (y // IC) // KW, +WSTR * (x % OW) + dilation_w * (y // IC) % KW, y % IC], + name='data_im2col') +N_transformed = B_interleaved_t.shape[0] + +# --- Pad if necessary +idxm = tvm.tir.indexmod + +pad_m = 0 +pad_k = 0 + +if M % 4 != 0: +pad_m = 4 - (M % 4) + +if K % 16 != 0: +pad_k = 16 - (K % 16) + +M_padded = M + pad_m +
[GitHub] [incubator-tvm-vta] liangfu commented on a change in pull request #9: [Hardware][OpenCL] Intelfocl support
liangfu commented on a change in pull request #9: URL: https://github.com/apache/incubator-tvm-vta/pull/9#discussion_r442601905 ## File path: config/intelfocl_sample.json ## @@ -0,0 +1,13 @@ +{ + "TARGET" : "intelfocl", Review comment: I think this should be the specific cloud fpga, instead of intelfocl or aocl. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] masahi opened a new pull request #5850: [BACKPORT-0.6][Quantization] Fix annotation for multiply op (#4458)
masahi opened a new pull request #5850: URL: https://github.com/apache/incubator-tvm/pull/5850 https://github.com/apache/incubator-tvm/pull/4458 @yzhliu 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen merged pull request #5849: [BACKPORT-0.6][BUGFIX] Fixed process termination routine in windows
tqchen merged pull request #5849: URL: https://github.com/apache/incubator-tvm/pull/5849 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: us...@infra.apache.org
[incubator-tvm] branch v0.6 updated: [BACKPORT-0.6][BUGFIX] Fixed process termination routine in windows (#5849)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch v0.6 in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git The following commit(s) were added to refs/heads/v0.6 by this push: new 09cedf6 [BACKPORT-0.6][BUGFIX] Fixed process termination routine in windows (#5849) 09cedf6 is described below commit 09cedf6847a81d53c09466cc9f1126f5d3b50fd9 Author: Yizhi Liu AuthorDate: Thu Jun 18 19:15:06 2020 -0700 [BACKPORT-0.6][BUGFIX] Fixed process termination routine in windows (#5849) Co-authored-by: Seyyed Hossein Hasanpour Co-authored-by: Seyyed Hossein Hasanpour --- python/tvm/rpc/server.py | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/tvm/rpc/server.py b/python/tvm/rpc/server.py index 9e03097..3fff530 100644 --- a/python/tvm/rpc/server.py +++ b/python/tvm/rpc/server.py @@ -402,7 +402,10 @@ class Server(object): """Terminate the server process""" if self.use_popen: if self.proc: -os.killpg(self.proc.pid, signal.SIGTERM) +if platform.system() == "Windows": +os.kill(self.proc.pid, signal.CTRL_C_EVENT) +else: +os.killpg(self.proc.pid, signal.SIGTERM) self.proc = None else: if self.proc:
[GitHub] [incubator-tvm] junrushao1994 commented on pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#issuecomment-646395649 @zhiics Could you take another look? Thanks! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] kazum commented on pull request #5830: Rust Refactor Stage 4: Rewrite Rust graph runtime to use new APIs
kazum commented on pull request #5830: URL: https://github.com/apache/incubator-tvm/pull/5830#issuecomment-646390576 @jroesch Can we enable derive_default for bindgen? Otherwise, test_wasm32 fails with tvm-sys because of the generated padding field. The following change looks necessary which existed in the previous implementation. ```diff diff --git a/rust/tvm-graph-rt/src/array.rs b/rust/tvm-graph-rt/src/array.rs index 38519bd..8209b59 100644 --- a/rust/tvm-graph-rt/src/array.rs +++ b/rust/tvm-graph-rt/src/array.rs @@ -288,6 +288,7 @@ impl<'a> Tensor<'a> { self.strides.as_ref().unwrap().as_ptr() } as *mut i64, byte_offset: 0, +..Default::default() } } } diff --git a/rust/tvm-sys/build.rs b/rust/tvm-sys/build.rs index 85e16be..01d2934 100644 --- a/rust/tvm-sys/build.rs +++ b/rust/tvm-sys/build.rs @@ -54,6 +54,7 @@ fn main() { .layout_tests(false) .derive_partialeq(true) .derive_eq(true) +.derive_default(true) .generate() .expect("unable to generate bindings") .write_to_file(PathBuf::from("src/c_runtime_api.rs")) diff --git a/rust/tvm-sys/src/array.rs b/rust/tvm-sys/src/array.rs index 1627e9e..5d09d86 100644 --- a/rust/tvm-sys/src/array.rs +++ b/rust/tvm-sys/src/array.rs @@ -48,6 +48,7 @@ macro_rules! impl_dltensor_from_ndarray { shape: arr.shape().as_ptr() as *const i64 as *mut i64, strides: arr.strides().as_ptr() as *const i64 as *mut i64, byte_offset: 0, +..Default::default() } } } ``` 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: us...@infra.apache.org
[GitHub] [incubator-tvm] leonwanghui commented on a change in pull request #5830: Rust Refactor Stage 4: Rewrite Rust graph runtime to use new APIs
leonwanghui commented on a change in pull request #5830: URL: https://github.com/apache/incubator-tvm/pull/5830#discussion_r442579653 ## File path: rust/tvm-graph-rt/src/array.rs ## @@ -0,0 +1,400 @@ +/* + * 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. + */ + +use std::{convert::TryFrom, mem, os::raw::c_void, ptr, slice}; + +use failure::{ensure, Error}; +use ndarray; +use tvm_sys::{ffi::DLTensor, Context, DataType}; + +use crate::allocator::Allocation; + +/// A `Storage` is a container which holds `Tensor` data. +#[derive(PartialEq)] +pub enum Storage<'a> { +/// A `Storage` which owns its contained bytes. +Owned(Allocation), + +/// A view of an existing `Storage`. +View(&'a mut [u8], usize), // ptr, align +} + +impl<'a> Storage<'a> { +pub fn new(size: usize, align: Option) -> Result, Error> { +Ok(Storage::Owned(Allocation::new(size, align)?)) +} + +pub fn as_mut_ptr() -> *mut u8 { +match self { +Storage::Owned(alloc) => alloc.as_mut_ptr(), +Storage::View(slice, _) => slice.as_ptr() as *mut u8, +} +} + +pub fn size() -> usize { +match self { +Storage::Owned(alloc) => alloc.size(), +Storage::View(slice, _) => slice.len(), +} +} + +pub fn align() -> usize { +match self { +Storage::Owned(alloc) => alloc.align(), +Storage::View(_, align) => *align, +} +} + +pub fn as_ptr() -> *const u8 { +self.as_mut_ptr() as *const _ +} + +/// Returns a `Storage::View` which points to an owned `Storage::Owned`. +pub fn view() -> Storage<'a> { +match self { +Storage::Owned(alloc) => Storage::View( +unsafe { slice::from_raw_parts_mut(alloc.as_mut_ptr(), self.size()) }, +self.align(), +), +Storage::View(slice, _) => Storage::View( +unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), slice.len()) }, +self.align(), +), +} +} + +pub fn is_owned() -> bool { +match self { +Storage::Owned(_) => true, +_ => false, +} +} + +/// Returns an owned version of this storage via cloning. +pub fn to_owned() -> Storage<'static> { +let s = Storage::new(self.size(), Some(self.align())).unwrap(); +unsafe { +s.as_mut_ptr() +.copy_from_nonoverlapping(self.as_ptr(), self.size()); +} +s +} + +/// Returns a view of the stored data. +pub fn as_slice() -> &[u8] { +match self { +Storage::Owned(alloc) => alloc.as_slice(), +Storage::View(slice, _) => &*slice, +} +} + +/// Returns a mutable view of the stored data. +pub fn as_mut_slice( self) -> [u8] { +match self { +Storage::Owned(alloc) => alloc.as_mut_slice(), +Storage::View(slice, _) => slice, +} +} +} + +impl<'d, 's, T> From<&'d [T]> for Storage<'s> { +fn from(data: &'d [T]) -> Self { +let data = unsafe { +slice::from_raw_parts_mut( +data.as_ptr() as *const u8 as *mut u8, +data.len() * mem::size_of::() as usize, +) +}; +Storage::View(data, mem::align_of::()) +} +} + +/// A n-dimensional array type which can be converted to/from `tvm::DLTensor` and `ndarray::Array`. +/// `Tensor` is primarily a holder of data which can be operated on via TVM (via `DLTensor`) or +/// converted to `ndarray::Array` for non-TVM processing. +/// +/// # Examples +/// +/// ``` +/// extern crate ndarray; +/// use std::convert::TryInto; +/// use tvm_runtime::{call_packed, DLTensor, ArgValue, RetValue, Tensor}; +/// +/// let mut a_nd: ndarray::Array1 = ndarray::Array::from_vec(vec![1f32, 2., 3., 4.]); +/// let mut a: Tensor = a_nd.into(); +/// let mut a_dl: DLTensor = ( a).into(); +/// +/// let tvm_fn = |args: &[ArgValue]| -> Result { Ok(RetValue::default()) }; +/// call_packed!(tvm_fn, a_dl); +/// +/// // Array -> Tensor is mostly useful when post-processing TVM graph outputs. +/// let mut a_nd: ndarray::ArrayD =
[GitHub] [incubator-tvm] yzhliu opened a new pull request #5849: [BACKPORT-0.6][BUGFIX] Fixed process termination routine in windows
yzhliu opened a new pull request #5849: URL: https://github.com/apache/incubator-tvm/pull/5849 #4844 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: us...@infra.apache.org
[GitHub] [incubator-tvm] xqdan commented on a change in pull request #5772: [ARITH]add simplify rule for div
xqdan commented on a change in pull request #5772: URL: https://github.com/apache/incubator-tvm/pull/5772#discussion_r442577797 ## File path: src/arith/rewrite_simplify.cc ## @@ -353,6 +353,25 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { truncdiv(x + c1, c3) - truncdiv(x, c3), truncdiv(truncmod(x, c3) + c1, c3), CanProveGreaterEqual(x.Eval(), 0) && c1.Eval()->value >= 0 && c3.Eval()->value > 0); +TVM_TRY_REWRITE_IF(truncdiv(x * c1 + c2, c3) - truncdiv(x * c1 + c4, c3), truncdiv(c2 - c4, c3), + c1.Eval()->value >= 0 && c2.Eval()->value > 0 && c3.Eval()->value > 0 && + c4.Eval()->value >= 0 && CanProveGreaterEqual(x.Eval(), 0) && + std::abs(c4.Eval()->value - c2.Eval()->value) >= c3.Eval()->value); Review comment: truncdiv(6, y) - truncdiv(2, y) if y=3 will break the rule, remove y related rule for now. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442577192 ## File path: include/tvm/node/container.h ## @@ -43,51 +44,1200 @@ using runtime::Downcast; using runtime::IterAdapter; using runtime::make_object; using runtime::Object; +using runtime::ObjectEqual; +using runtime::ObjectHash; using runtime::ObjectPtr; using runtime::ObjectPtrEqual; using runtime::ObjectPtrHash; using runtime::ObjectRef; using runtime::String; using runtime::StringObj; -/*! \brief String-aware ObjectRef hash functor */ -struct ObjectHash { - size_t operator()(const ObjectRef& a) const { -if (const auto* str = a.as()) { - return String::HashBytes(str->data, str->size); -} -return ObjectPtrHash()(a); +#if (USE_FALLBACK_STL_MAP != 0) + +/*! \brief Shared content of all specializations of hash map */ +class MapNode : public Object { + public: + /*! \brief Type of the keys in the hash map */ + using key_type = ObjectRef; + /*! \brief Type of the values in the hash map */ + using mapped_type = ObjectRef; + /*! \brief Type of the actual underlying container */ + using ContainerType = std::unordered_map; + /*! \brief Iterator class */ + using iterator = ContainerType::iterator; + /*! \brief Iterator class */ + using const_iterator = ContainerType::const_iterator; + /*! \brief Type of value stored in the hash map */ + using KVType = ContainerType::value_type; + + static_assert(std::is_standard_layout::value, "KVType is not standard layout"); + static_assert(sizeof(KVType) == 16 || sizeof(KVType) == 8, "sizeof(KVType) incorrect"); + + static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeMap; + static constexpr const char* _type_key = "Map"; + TVM_DECLARE_FINAL_OBJECT_INFO(MapNode, Object); + + /*! + * \brief Number of elements in the SmallMapNode + * \return The result + */ + size_t size() const { return data_.size(); } + /*! + * \brief Count the number of times a key exists in the hash map + * \param key The indexing key + * \return The result, 0 or 1 + */ + size_t count(const key_type& key) const { return data_.count(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The const reference to the value + */ + const mapped_type& at(const key_type& key) const { return data_.at(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The mutable reference to the value + */ + mapped_type& at(const key_type& key) { return data_.at(key); } + /*! \return begin iterator */ + iterator begin() { return data_.begin(); } + /*! \return const begin iterator */ + const_iterator begin() const { return data_.begin(); } + /*! \return end iterator */ + iterator end() { return data_.end(); } + /*! \return end iterator */ + const_iterator end() const { return data_.end(); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + const_iterator find(const key_type& key) const { return data_.find(key); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + iterator find(const key_type& key) { return data_.find(key); } + /*! + * \brief Erase the entry associated with the iterator + * \param position The iterator + */ + void erase(const iterator& position) { data_.erase(position); } + /*! + * \brief Erase the entry associated with the key, do nothing if not exists + * \param key The indexing key + */ + void erase(const key_type& key) { data_.erase(key); } + /*! + * \brief Create an empty container + * \return The object created + */ + static ObjectPtr Empty() { return make_object(); } + + protected: + /*! + * \brief Create the map using contents from the given iterators. + * \param first Begin of iterator + * \param last End of iterator + * \tparam IterType The type of iterator + * \return ObjectPtr to the map created + */ + template + static ObjectPtr CreateFromRange(IterType first, IterType last) { +ObjectPtr p = make_object(); +p->data_ = ContainerType(first, last); +return p; + } + /*! + * \brief InsertMaybeReHash an entry into the given hash map + * \param kv The entry to be inserted + * \param map The pointer to the map, can be changed if re-hashing happens + */ + static void InsertMaybeReHash(const KVType& kv, ObjectPtr* map) { +MapNode* map_node = static_cast(map->get()); +map_node->data_[kv.first] = kv.second; + } + /*! + * \brief Create an empty container with elements copying from another MapNode + * \param from The
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442576289 ## File path: tests/cpp/container_test.cc ## @@ -324,6 +324,29 @@ TEST(Map, Iterator) { CHECK(map2[a].as()->value == 2); } +TEST(Map, Insert) { + using namespace tvm; + auto check = [](const Map& result, + std::unordered_map expected) { +CHECK_EQ(result.size(), expected.size()); +for (const auto& kv : result) { + CHECK(expected.count(kv.first)); + CHECK_EQ(expected[kv.first], kv.second.operator int64_t()); + expected.erase(kv.first); +} + }; + Map result; + std::unordered_map expected; + char key = 'a'; + int64_t val = 1; + for (int i = 0; i < 26; ++i, ++key, ++val) { +std::string s(1, key); +result.Set(s, val); +expected[s] = val; +check(result, expected); + } +} + Review comment: Done :-) 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442576113 ## File path: tests/cpp/container_test.cc ## @@ -310,7 +310,7 @@ TEST(Map, Mutate) { CHECK(it != dict.end() && (*it).second.same_as(x)); it = dict2.find(zz); - CHECK(it == dict.end()); + CHECK(it == dict2.end()); LOG(INFO) << dict; Review comment: Sure 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: us...@infra.apache.org
[GitHub] [incubator-tvm] xqdan commented on a change in pull request #5772: [ARITH]add simplify rule for div
xqdan commented on a change in pull request #5772: URL: https://github.com/apache/incubator-tvm/pull/5772#discussion_r442573174 ## File path: src/arith/rewrite_simplify.cc ## @@ -353,6 +353,25 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { truncdiv(x + c1, c3) - truncdiv(x, c3), truncdiv(truncmod(x, c3) + c1, c3), CanProveGreaterEqual(x.Eval(), 0) && c1.Eval()->value >= 0 && c3.Eval()->value > 0); +TVM_TRY_REWRITE_IF(truncdiv(x * c1 + c2, c3) - truncdiv(x * c1 + c4, c3), truncdiv(c2 - c4, c3), + c1.Eval()->value >= 0 && c2.Eval()->value > 0 && c3.Eval()->value > 0 && + c4.Eval()->value >= 0 && CanProveGreaterEqual(x.Eval(), 0) && + std::abs(c4.Eval()->value - c2.Eval()->value) >= c3.Eval()->value); Review comment: I add your case in unitest. truncdiv(6, 3) will be simplified to 2 first, so what we catch here is '2-tdiv(2,3)'. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] xqdan commented on a change in pull request #5772: [ARITH]add simplify rule for div
xqdan commented on a change in pull request #5772: URL: https://github.com/apache/incubator-tvm/pull/5772#discussion_r442573174 ## File path: src/arith/rewrite_simplify.cc ## @@ -353,6 +353,25 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { truncdiv(x + c1, c3) - truncdiv(x, c3), truncdiv(truncmod(x, c3) + c1, c3), CanProveGreaterEqual(x.Eval(), 0) && c1.Eval()->value >= 0 && c3.Eval()->value > 0); +TVM_TRY_REWRITE_IF(truncdiv(x * c1 + c2, c3) - truncdiv(x * c1 + c4, c3), truncdiv(c2 - c4, c3), + c1.Eval()->value >= 0 && c2.Eval()->value > 0 && c3.Eval()->value > 0 && + c4.Eval()->value >= 0 && CanProveGreaterEqual(x.Eval(), 0) && + std::abs(c4.Eval()->value - c2.Eval()->value) >= c3.Eval()->value); Review comment: I add your case in unitest. truncdiv(6, 3) will be simplified to 2 first, what we catch here is '2-tdiv(2,3)'. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] anijain2305 commented on pull request #5805: [QUANTIZE] Add nn.batch_flatten as quantizable.
anijain2305 commented on pull request #5805: URL: https://github.com/apache/incubator-tvm/pull/5805#issuecomment-646373994 @vinx13 Can you PTAL? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5772: [ARITH]add simplify rule for div
zhiics commented on a change in pull request #5772: URL: https://github.com/apache/incubator-tvm/pull/5772#discussion_r442565117 ## File path: src/arith/rewrite_simplify.cc ## @@ -353,6 +353,25 @@ PrimExpr RewriteSimplifier::Impl::VisitExpr_(const SubNode* op) { truncdiv(x + c1, c3) - truncdiv(x, c3), truncdiv(truncmod(x, c3) + c1, c3), CanProveGreaterEqual(x.Eval(), 0) && c1.Eval()->value >= 0 && c3.Eval()->value > 0); +TVM_TRY_REWRITE_IF(truncdiv(x * c1 + c2, c3) - truncdiv(x * c1 + c4, c3), truncdiv(c2 - c4, c3), + c1.Eval()->value >= 0 && c2.Eval()->value > 0 && c3.Eval()->value > 0 && + c4.Eval()->value >= 0 && CanProveGreaterEqual(x.Eval(), 0) && + std::abs(c4.Eval()->value - c2.Eval()->value) >= c3.Eval()->value); Review comment: hmm, is this always true again? say `c1 = 0, c2 = 6, c3 = 3, c4 = 2`, `c4 - c2 = 4 > 3` `truncdiv(x * c1 + c2, c3) - truncdiv(x * c1 + c4, c3) = truncdiv(6, 3) - truncdiv(2, 3)` `truncdiv(c2 - c4, c3) = truncdiv(4, 3)` 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5601: [DataType] Add bfloat16
junrushao1994 commented on a change in pull request #5601: URL: https://github.com/apache/incubator-tvm/pull/5601#discussion_r442561558 ## File path: include/tvm/runtime/data_type.h ## @@ -72,6 +73,9 @@ class DataType { data_.code = static_cast(code); data_.bits = static_cast(bits); data_.lanes = static_cast(lanes); +if (code == kBFloat) { + CHECK_EQ(bits, 16); Review comment: @tqchen This is just a nitpick. What do you think? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
zhiics commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442559193 ## File path: tests/cpp/container_test.cc ## @@ -324,6 +324,29 @@ TEST(Map, Iterator) { CHECK(map2[a].as()->value == 2); } +TEST(Map, Insert) { + using namespace tvm; + auto check = [](const Map& result, + std::unordered_map expected) { +CHECK_EQ(result.size(), expected.size()); +for (const auto& kv : result) { + CHECK(expected.count(kv.first)); + CHECK_EQ(expected[kv.first], kv.second.operator int64_t()); + expected.erase(kv.first); +} + }; + Map result; + std::unordered_map expected; + char key = 'a'; + int64_t val = 1; + for (int i = 0; i < 26; ++i, ++key, ++val) { +std::string s(1, key); +result.Set(s, val); +expected[s] = val; +check(result, expected); + } +} + Review comment: Add a test for `erase` as well? ## File path: tests/cpp/container_test.cc ## @@ -310,7 +310,7 @@ TEST(Map, Mutate) { CHECK(it != dict.end() && (*it).second.same_as(x)); it = dict2.find(zz); - CHECK(it == dict.end()); + CHECK(it == dict2.end()); LOG(INFO) << dict; Review comment: remove this log ## File path: include/tvm/node/container.h ## @@ -43,51 +44,1200 @@ using runtime::Downcast; using runtime::IterAdapter; using runtime::make_object; using runtime::Object; +using runtime::ObjectEqual; +using runtime::ObjectHash; using runtime::ObjectPtr; using runtime::ObjectPtrEqual; using runtime::ObjectPtrHash; using runtime::ObjectRef; using runtime::String; using runtime::StringObj; -/*! \brief String-aware ObjectRef hash functor */ -struct ObjectHash { - size_t operator()(const ObjectRef& a) const { -if (const auto* str = a.as()) { - return String::HashBytes(str->data, str->size); -} -return ObjectPtrHash()(a); +#if (USE_FALLBACK_STL_MAP != 0) + +/*! \brief Shared content of all specializations of hash map */ +class MapNode : public Object { + public: + /*! \brief Type of the keys in the hash map */ + using key_type = ObjectRef; + /*! \brief Type of the values in the hash map */ + using mapped_type = ObjectRef; + /*! \brief Type of the actual underlying container */ + using ContainerType = std::unordered_map; + /*! \brief Iterator class */ + using iterator = ContainerType::iterator; + /*! \brief Iterator class */ + using const_iterator = ContainerType::const_iterator; + /*! \brief Type of value stored in the hash map */ + using KVType = ContainerType::value_type; + + static_assert(std::is_standard_layout::value, "KVType is not standard layout"); + static_assert(sizeof(KVType) == 16 || sizeof(KVType) == 8, "sizeof(KVType) incorrect"); + + static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeMap; + static constexpr const char* _type_key = "Map"; + TVM_DECLARE_FINAL_OBJECT_INFO(MapNode, Object); + + /*! + * \brief Number of elements in the SmallMapNode + * \return The result + */ + size_t size() const { return data_.size(); } + /*! + * \brief Count the number of times a key exists in the hash map + * \param key The indexing key + * \return The result, 0 or 1 + */ + size_t count(const key_type& key) const { return data_.count(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The const reference to the value + */ + const mapped_type& at(const key_type& key) const { return data_.at(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The mutable reference to the value + */ + mapped_type& at(const key_type& key) { return data_.at(key); } + /*! \return begin iterator */ + iterator begin() { return data_.begin(); } + /*! \return const begin iterator */ + const_iterator begin() const { return data_.begin(); } + /*! \return end iterator */ + iterator end() { return data_.end(); } + /*! \return end iterator */ + const_iterator end() const { return data_.end(); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + const_iterator find(const key_type& key) const { return data_.find(key); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + iterator find(const key_type& key) { return data_.find(key); } + /*! + * \brief Erase the entry associated with the iterator + * \param position The iterator + */ + void erase(const iterator& position) { data_.erase(position); } + /*! + * \brief Erase the entry associated with the key, do nothing if not exists + * \param key The indexing
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5838: [Target] Introduce Target Id Registry
junrushao1994 commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442558981 ## File path: include/tvm/target/target_id.h ## @@ -0,0 +1,228 @@ +/* + * 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/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tvm { + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { +std::string type_key; +uint32_t type_index; + }; + /*! + * \brief Register an attribute with the type specified by the type_index + * \param key The name of the attribute + * \param value_type_index The type index of the value of the attribute + */ + void RegisterAttrOption(const std::string& key, uint32_t value_type_index); + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } + + /*! \brief Get the attribute map given the attribute name. */ + template + static inline TargetIdAttrMap GetAttrMap(const String& attr_name); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetId, ObjectRef, TargetIdNode); + + private: + static const AttrRegistryMapContainerMap& GetAttrMapContainer(const String& attr_name); + template + friend class AttrRegistry; +}; + +/*! + * \brief Map used to store meta-information about TargetId + * \tparam ValueType The type of the value stored in map + */ +template +class TargetIdAttrMap : public AttrRegistryMap { + public: + using TParent = AttrRegistryMap; + using TParent::count; + using TParent::get; + using TParent::operator[]; + explicit TargetIdAttrMap(const AttrRegistryMapContainerMap& map) : TParent(map) {} +}; + +/*! + * \brief Helper structure to register TargetId + * \sa TVM_REGISTER_TARGET_ID + */ +class TargetIdRegEntry { + public: + /*! + * \brief Register additional attributes to target_id. + * \param attr_name The name of the attribute. + * \param value The value to be set. + * \param plevel The priority level of this set, + * an higher priority level attribute + * will replace lower priority level attribute. + * Must be bigger than 0. + * + * Cannot set with same plevel twice in the code. + * + * \tparam ValueType The type of the value to be set. + */ + template + inline TargetIdRegEntry& set_attr(const String& attr_name, const ValueType& value, +int plevel = 10); + /*! + * \brief Register a valid configuration option and its ValueType for validation + * \param key The configuration key + * \tparam ValueType The value type to be registered + */ + template + inline TargetIdRegEntry& add_attr_option(const std::string& key); + /*! \brief Set name of the TargetId to be the same as registry if it is empty */ + inline TargetIdRegEntry& set_name(); + /*! + * \brief Register or get a new entry. + * \param name The name of the TargetId. + * \return the corresponding entry. + */ + static TargetIdRegEntry& RegisterOrGet(const String& name); + + private: + TargetId id_; + String name; + + /*! \brief private
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5838: [Target] Introduce Target Id Registry
tqchen commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442558792 ## File path: include/tvm/target/target_id.h ## @@ -0,0 +1,228 @@ +/* + * 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/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tvm { + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { +std::string type_key; +uint32_t type_index; + }; + /*! + * \brief Register an attribute with the type specified by the type_index + * \param key The name of the attribute + * \param value_type_index The type index of the value of the attribute + */ + void RegisterAttrOption(const std::string& key, uint32_t value_type_index); + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } + + /*! \brief Get the attribute map given the attribute name. */ + template + static inline TargetIdAttrMap GetAttrMap(const String& attr_name); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetId, ObjectRef, TargetIdNode); + + private: + static const AttrRegistryMapContainerMap& GetAttrMapContainer(const String& attr_name); + template + friend class AttrRegistry; +}; + +/*! + * \brief Map used to store meta-information about TargetId + * \tparam ValueType The type of the value stored in map + */ +template +class TargetIdAttrMap : public AttrRegistryMap { + public: + using TParent = AttrRegistryMap; + using TParent::count; + using TParent::get; + using TParent::operator[]; + explicit TargetIdAttrMap(const AttrRegistryMapContainerMap& map) : TParent(map) {} +}; + +/*! + * \brief Helper structure to register TargetId + * \sa TVM_REGISTER_TARGET_ID + */ +class TargetIdRegEntry { + public: + /*! + * \brief Register additional attributes to target_id. + * \param attr_name The name of the attribute. + * \param value The value to be set. + * \param plevel The priority level of this set, + * an higher priority level attribute + * will replace lower priority level attribute. + * Must be bigger than 0. + * + * Cannot set with same plevel twice in the code. + * + * \tparam ValueType The type of the value to be set. + */ + template + inline TargetIdRegEntry& set_attr(const String& attr_name, const ValueType& value, +int plevel = 10); + /*! + * \brief Register a valid configuration option and its ValueType for validation + * \param key The configuration key + * \tparam ValueType The value type to be registered + */ + template + inline TargetIdRegEntry& add_attr_option(const std::string& key); + /*! \brief Set name of the TargetId to be the same as registry if it is empty */ + inline TargetIdRegEntry& set_name(); + /*! + * \brief Register or get a new entry. + * \param name The name of the TargetId. + * \return the corresponding entry. + */ + static TargetIdRegEntry& RegisterOrGet(const String& name); + + private: + TargetId id_; + String name; + + /*! \brief private constructor
[GitHub] [incubator-tvm] tqchen commented on pull request #5601: [DataType] Add bfloat16
tqchen commented on pull request #5601: URL: https://github.com/apache/incubator-tvm/pull/5601#issuecomment-646355311 @junrushao1994 @ZhennanQin please followup and https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen merged pull request #5821: [AutoTVM] Suppress the warning messages when compile engine selects impls
tqchen merged pull request #5821: URL: https://github.com/apache/incubator-tvm/pull/5821 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: us...@infra.apache.org
[incubator-tvm] branch master updated (24df0ba -> 64766c2)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. from 24df0ba Additional canonicalization added for AddNode (#5846) add 64766c2 [AutoTVM] Suppress the warning messages when compile engine selects impls (#5821) No new revisions were added by this update. Summary of changes: python/tvm/autotvm/env.py | 1 + python/tvm/autotvm/task/dispatcher.py | 13 ++--- python/tvm/relay/backend/compile_engine.py | 18 -- tests/python/integration/test_winograd_nnpack.py | 5 +++-- topi/tests/python/test_topi_group_conv2d_NCHWc_int8.py | 3 ++- 5 files changed, 28 insertions(+), 12 deletions(-)
[GitHub] [incubator-tvm] tqchen commented on pull request #5795: [Relay] Keep fixed dim when unifying dynamic shape
tqchen commented on pull request #5795: URL: https://github.com/apache/incubator-tvm/pull/5795#issuecomment-646354939 @icemelon9 please manage this PR 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on pull request #5805: [QUANTIZE] Add nn.batch_flatten as quantizable.
tqchen commented on pull request #5805: URL: https://github.com/apache/incubator-tvm/pull/5805#issuecomment-646354778 @anijain2305 please help to manage this PR 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on pull request #5772: [ARITH]add simplify rule for div
tqchen commented on pull request #5772: URL: https://github.com/apache/incubator-tvm/pull/5772#issuecomment-646354577 cc @zhiics @yongfeng-nv @merrymercy @jroesch please help to take a look 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
tqchen commented on pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#issuecomment-646353977 @zhiics please take another look and https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly cc @wweic @spectrometerHBH @comaniac @antinucleon 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5838: [Target] Introduce Target Id Registry
junrushao1994 commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442552581 ## File path: include/tvm/target/target_id.h ## @@ -0,0 +1,228 @@ +/* + * 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/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tvm { + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { +std::string type_key; +uint32_t type_index; + }; + /*! + * \brief Register an attribute with the type specified by the type_index + * \param key The name of the attribute + * \param value_type_index The type index of the value of the attribute + */ + void RegisterAttrOption(const std::string& key, uint32_t value_type_index); + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } + + /*! \brief Get the attribute map given the attribute name. */ + template + static inline TargetIdAttrMap GetAttrMap(const String& attr_name); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetId, ObjectRef, TargetIdNode); + + private: + static const AttrRegistryMapContainerMap& GetAttrMapContainer(const String& attr_name); + template + friend class AttrRegistry; +}; + +/*! + * \brief Map used to store meta-information about TargetId + * \tparam ValueType The type of the value stored in map + */ +template +class TargetIdAttrMap : public AttrRegistryMap { + public: + using TParent = AttrRegistryMap; + using TParent::count; + using TParent::get; + using TParent::operator[]; + explicit TargetIdAttrMap(const AttrRegistryMapContainerMap& map) : TParent(map) {} +}; + +/*! + * \brief Helper structure to register TargetId + * \sa TVM_REGISTER_TARGET_ID + */ +class TargetIdRegEntry { + public: + /*! + * \brief Register additional attributes to target_id. + * \param attr_name The name of the attribute. + * \param value The value to be set. + * \param plevel The priority level of this set, + * an higher priority level attribute + * will replace lower priority level attribute. + * Must be bigger than 0. + * + * Cannot set with same plevel twice in the code. + * + * \tparam ValueType The type of the value to be set. + */ + template + inline TargetIdRegEntry& set_attr(const String& attr_name, const ValueType& value, +int plevel = 10); + /*! + * \brief Register a valid configuration option and its ValueType for validation + * \param key The configuration key + * \tparam ValueType The value type to be registered + */ + template + inline TargetIdRegEntry& add_attr_option(const std::string& key); + /*! \brief Set name of the TargetId to be the same as registry if it is empty */ + inline TargetIdRegEntry& set_name(); + /*! + * \brief Register or get a new entry. + * \param name The name of the TargetId. + * \return the corresponding entry. + */ + static TargetIdRegEntry& RegisterOrGet(const String& name); + + private: + TargetId id_; + String name; + + /*! \brief private
[GitHub] [incubator-tvm] anijain2305 opened a new pull request #5848: [TFLite] TFLite 2.x parser quantization support.
anijain2305 opened a new pull request #5848: URL: https://github.com/apache/incubator-tvm/pull/5848 This is by no way ready (lots of hack and duplication currently). This is to kick start the discussion for TFLite2.x quantization model ingestion Checked on MNIST model - https://www.tensorflow.org/lite/performance/post_training_integer_quant @u99127 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5838: [Target] Introduce Target Id Registry
tqchen commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442552150 ## File path: include/tvm/target/target_id.h ## @@ -0,0 +1,228 @@ +/* + * 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/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tvm { + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { +std::string type_key; +uint32_t type_index; + }; + /*! + * \brief Register an attribute with the type specified by the type_index + * \param key The name of the attribute + * \param value_type_index The type index of the value of the attribute + */ + void RegisterAttrOption(const std::string& key, uint32_t value_type_index); + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } + + /*! \brief Get the attribute map given the attribute name. */ + template + static inline TargetIdAttrMap GetAttrMap(const String& attr_name); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetId, ObjectRef, TargetIdNode); + + private: + static const AttrRegistryMapContainerMap& GetAttrMapContainer(const String& attr_name); + template + friend class AttrRegistry; +}; + +/*! + * \brief Map used to store meta-information about TargetId + * \tparam ValueType The type of the value stored in map + */ +template +class TargetIdAttrMap : public AttrRegistryMap { + public: + using TParent = AttrRegistryMap; + using TParent::count; + using TParent::get; + using TParent::operator[]; + explicit TargetIdAttrMap(const AttrRegistryMapContainerMap& map) : TParent(map) {} +}; + +/*! + * \brief Helper structure to register TargetId + * \sa TVM_REGISTER_TARGET_ID + */ +class TargetIdRegEntry { + public: + /*! + * \brief Register additional attributes to target_id. + * \param attr_name The name of the attribute. + * \param value The value to be set. + * \param plevel The priority level of this set, + * an higher priority level attribute + * will replace lower priority level attribute. + * Must be bigger than 0. + * + * Cannot set with same plevel twice in the code. + * + * \tparam ValueType The type of the value to be set. + */ + template + inline TargetIdRegEntry& set_attr(const String& attr_name, const ValueType& value, +int plevel = 10); + /*! + * \brief Register a valid configuration option and its ValueType for validation + * \param key The configuration key + * \tparam ValueType The value type to be registered + */ + template + inline TargetIdRegEntry& add_attr_option(const std::string& key); + /*! \brief Set name of the TargetId to be the same as registry if it is empty */ + inline TargetIdRegEntry& set_name(); + /*! + * \brief Register or get a new entry. + * \param name The name of the TargetId. + * \return the corresponding entry. + */ + static TargetIdRegEntry& RegisterOrGet(const String& name); + + private: + TargetId id_; + String name; + + /*! \brief private constructor
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5838: [Target] Introduce Target Id Registry
tqchen commented on a change in pull request #5838: URL: https://github.com/apache/incubator-tvm/pull/5838#discussion_r442552006 ## File path: include/tvm/target/target_id.h ## @@ -0,0 +1,228 @@ +/* + * 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/target/target_id.h + * \brief Target id registry + */ +#ifndef TVM_TARGET_TARGET_ID_H_ +#define TVM_TARGET_TARGET_ID_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace tvm { + +template +class TargetIdAttrMap; + +/*! \brief Target Id, specifies the kind of the target */ +class TargetIdNode : public Object { + public: + /*! \brief Name of the target id */ + String name; + static constexpr const char* _type_key = "TargetId"; + TVM_DECLARE_FINAL_OBJECT_INFO(TargetIdNode, Object); + + private: + uint32_t AttrRegistryIndex() const { return index_; } + std::string AttrRegistryName() const { return name; } + /*! \brief Stores the required type_key and type_index of a specific attr of a target */ + struct ValueTypeInfo { +std::string type_key; +uint32_t type_index; + }; + /*! + * \brief Register an attribute with the type specified by the type_index + * \param key The name of the attribute + * \param value_type_index The type index of the value of the attribute + */ + void RegisterAttrOption(const std::string& key, uint32_t value_type_index); + /*! \brief A hash table that stores the type information of each attr of the target key */ + std::unordered_map key2vtype_; + /*! \brief Index used for internal lookup of attribute registry */ + uint32_t index_; + template + friend class AttrRegistry; + friend class TargetIdRegEntry; +}; + +/*! + * \brief Managed reference class to TargetIdNode + * \sa TargetIdNode + */ +class TargetId : public ObjectRef { + public: + /*! \brief Mutable access to the container class */ + TargetIdNode* operator->() { return static_cast(data_.get()); } Review comment: Why do we need mutable access? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen merged pull request #5846: Additional canonicalization added for AddNode
tqchen merged pull request #5846: URL: https://github.com/apache/incubator-tvm/pull/5846 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: us...@infra.apache.org
[incubator-tvm] branch master updated (d85efa1 -> 24df0ba)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. from d85efa1 fix batchnorm infer_value error, add regression test and unit test (#5845) add 24df0ba Additional canonicalization added for AddNode (#5846) No new revisions were added by this update. Summary of changes: python/tvm/tir/expr.py | 2 +- src/arith/rewrite_simplify.cc| 1 + tests/python/unittest/test_arith_rewrite_simplify.py | 10 ++ 3 files changed, 12 insertions(+), 1 deletion(-)
[GitHub] [incubator-tvm] tqchen commented on pull request #5846: Additional canonicalization added for AddNode
tqchen commented on pull request #5846: URL: https://github.com/apache/incubator-tvm/pull/5846#issuecomment-646352898 thanks @ANSHUMAN87 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: us...@infra.apache.org
[GitHub] [incubator-tvm] comaniac opened a new pull request #5847: [DOCS] Update has_dtype/has_shape to pattern lang doc
comaniac opened a new pull request #5847: URL: https://github.com/apache/incubator-tvm/pull/5847 #5760 introduces new patterns (dtype and shape). This PR updates the document to reflect those updates. cc @mbrookhart 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: us...@infra.apache.org
[GitHub] [incubator-tvm] mbrookhart commented on pull request #5826: [DYNAMIC] Add Dynamic reshape to a dynamic namespace and add DynamicToStatic Pass
mbrookhart commented on pull request #5826: URL: https://github.com/apache/incubator-tvm/pull/5826#issuecomment-646347835 Hitting an issue with dynamic shapes on GPU with the VM. 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: us...@infra.apache.org
[incubator-tvm] branch master updated (d8c80c3 -> eacfe89)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. from d8c80c3 `tvm` crate stage 3 of Rust refactor (#5769) add eacfe89 [RUNTIME] Introduce MetadataModule to separate code compilation/interpretation and weight initialization (#5770) No new revisions were added by this update. Summary of changes: python/tvm/contrib/graph_runtime.py| 7 +- python/tvm/runtime/vm.py | 13 +- src/relay/backend/build_module.cc | 7 +- src/relay/backend/compile_engine.cc| 38 ++-- src/relay/backend/contrib/codegen_c/codegen.cc | 85 src/relay/backend/contrib/codegen_c/codegen_c.h| 83 +++- src/relay/backend/contrib/dnnl/codegen.cc | 73 --- src/relay/backend/graph_runtime_codegen.cc | 8 + src/relay/backend/utils.h | 20 ++ src/relay/backend/vm/compiler.cc | 24 +-- src/runtime/graph/graph_runtime.cc | 9 +- src/runtime/meta_data.h| 16 ++ src/runtime/metadata_module.cc | 222 + src/target/source/codegen_source_base.h| 21 +- src/target/source/source_module.cc | 70 ++- tests/python/frontend/onnx/test_forward.py | 5 +- tests/python/relay/test_external_codegen.py| 43 tests/python/relay/test_external_runtime.py| 6 +- .../python/unittest/test_runtime_module_export.py | 3 +- 19 files changed, 609 insertions(+), 144 deletions(-) create mode 100644 src/runtime/metadata_module.cc
[GitHub] [incubator-tvm] tqchen merged pull request #5845: [ONNX] Fix an issue with #5755 and add Batch norm unit tests.
tqchen merged pull request #5845: URL: https://github.com/apache/incubator-tvm/pull/5845 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: us...@infra.apache.org
[incubator-tvm] branch master updated (eacfe89 -> d85efa1)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. from eacfe89 [RUNTIME] Introduce MetadataModule to separate code compilation/interpretation and weight initialization (#5770) add d85efa1 fix batchnorm infer_value error, add regression test and unit test (#5845) No new revisions were added by this update. Summary of changes: python/tvm/relay/frontend/onnx.py | 7 +-- tests/python/frontend/onnx/test_forward.py | 85 ++ 2 files changed, 89 insertions(+), 3 deletions(-)
[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #5753: [Draft] Support Module based interface runtime
FrozenGene commented on a change in pull request #5753: URL: https://github.com/apache/incubator-tvm/pull/5753#discussion_r442534625 ## File path: python/tvm/runtime/module.py ## @@ -41,6 +41,10 @@ def __init__(self, handle): self.handle = handle self._entry = None self.entry_name = "__tvm_main__" +# TODO:(FrozenGene): support rpc +if self.type_key == 'GraphRuntimeFactory': +#from tvm.runtime.graph_runtime_factory import GraphRuntimeFactoryModule +self._entry = self.runtime_create Review comment: Yes. This is easy to be done when we use `relay.build`. However, when we complete `export_library` and use `tvm.runtime.load_module` / `remote.load_module` (remote is rpc) , it is not easy. Because when we load it, its type is `module`. So, my previous reply means maybe we could use automatic type wrapper mentioned in original rfc , check the type key when we `load_module` and go to `GraphRuntimeFactoryModule` directly, then we don’t modify `module`. How about it? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #5753: [Draft] Support Module based interface runtime
FrozenGene commented on a change in pull request #5753: URL: https://github.com/apache/incubator-tvm/pull/5753#discussion_r442534625 ## File path: python/tvm/runtime/module.py ## @@ -41,6 +41,10 @@ def __init__(self, handle): self.handle = handle self._entry = None self.entry_name = "__tvm_main__" +# TODO:(FrozenGene): support rpc +if self.type_key == 'GraphRuntimeFactory': +#from tvm.runtime.graph_runtime_factory import GraphRuntimeFactoryModule +self._entry = self.runtime_create Review comment: Yes. This is easy to be done when we use `relay.build`. However, when we complete `export_library` and use `tvm.runtime.load_module` / `remote.load_module` (remote is rpc) , it is not easy. Because when we load it, its type is module. So, my previous reply means maybe we could use automatic type wrapper mentioned in original rfc , check the type key when we `load_module` and go to `GraphRuntimeFactoryModule` directly, then we don’t modify `module`. How about it? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #5753: [Draft] Support Module based interface runtime
FrozenGene commented on a change in pull request #5753: URL: https://github.com/apache/incubator-tvm/pull/5753#discussion_r442534625 ## File path: python/tvm/runtime/module.py ## @@ -41,6 +41,10 @@ def __init__(self, handle): self.handle = handle self._entry = None self.entry_name = "__tvm_main__" +# TODO:(FrozenGene): support rpc +if self.type_key == 'GraphRuntimeFactory': +#from tvm.runtime.graph_runtime_factory import GraphRuntimeFactoryModule +self._entry = self.runtime_create Review comment: Yes. This is easy to be done when we use `relay.build`. However, when we complete `export_library` and use `tvm.runtime.load_module` / `remote.load_module` (remote is rpc) is not easy. Because when we load it, its type is module. So, my previous reply means maybe we could use automatic type wrapper mentioned in original rfc , check the type key when we `load_module` and go to `GraphRuntimeFactoryModule` directly, then we don’t modify `module`. How about it? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen merged pull request #5770: [RUNTIME] Introduce MetadataModule to separate code compilation/interpretation and weight initialization
tqchen merged pull request #5770: URL: https://github.com/apache/incubator-tvm/pull/5770 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442509398 ## File path: include/tvm/node/container.h ## @@ -43,51 +44,1188 @@ using runtime::Downcast; using runtime::IterAdapter; using runtime::make_object; using runtime::Object; +using runtime::ObjectEqual; +using runtime::ObjectHash; using runtime::ObjectPtr; using runtime::ObjectPtrEqual; using runtime::ObjectPtrHash; using runtime::ObjectRef; using runtime::String; using runtime::StringObj; -/*! \brief String-aware ObjectRef hash functor */ -struct ObjectHash { - size_t operator()(const ObjectRef& a) const { -if (const auto* str = a.as()) { - return String::HashBytes(str->data, str->size); -} -return ObjectPtrHash()(a); +#if (TVM_USE_STL_MAP != 0) + +/*! \brief Shared content of all specializations of hash map */ +class MapNode : public Object { + public: + /*! \brief Type of the keys in the hash map */ + using key_type = ObjectRef; + /*! \brief Type of the values in the hash map */ + using mapped_type = ObjectRef; + /*! \brief Type of the actual underlying container */ + using ContainerType = std::unordered_map; + /*! \brief Iterator class */ + using iterator = ContainerType::iterator; + /*! \brief Iterator class */ + using const_iterator = ContainerType::const_iterator; + /*! \brief Type of value stored in the hash map */ + using KVType = ContainerType::value_type; + + static_assert(std::is_standard_layout::value, "KVType is not standard layout"); + static_assert(sizeof(KVType) == 16 || sizeof(KVType) == 8, "sizeof(KVType) incorrect"); + + static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeMap; + static constexpr const char* _type_key = "Map"; + TVM_DECLARE_FINAL_OBJECT_INFO(MapNode, Object); + + /*! + * \brief Number of elements in the SmallMapNode + * \return The result + */ + size_t size() const { return data_.size(); } + /*! + * \brief Count the number of times a key exists in the hash map + * \param key The indexing key + * \return The result, 0 or 1 + */ + size_t count(const key_type& key) const { return data_.count(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The const reference to the value + */ + const mapped_type& at(const key_type& key) const { return data_.at(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The mutable reference to the value + */ + mapped_type& at(const key_type& key) { return data_.at(key); } + /*! \return begin iterator */ + iterator begin() { return data_.begin(); } + /*! \return const begin iterator */ + const_iterator begin() const { return data_.begin(); } + /*! \return end iterator */ + iterator end() { return data_.end(); } + /*! \return end iterator */ + const_iterator end() const { return data_.end(); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + const_iterator find(const key_type& key) const { return data_.find(key); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + iterator find(const key_type& key) { return data_.find(key); } + /*! + * \brief Erase the entry associated with the iterator + * \param position The iterator + */ + void erase(const iterator& position) { data_.erase(position); } + /*! + * \brief Erase the entry associated with the key, do nothing if not exists + * \param key The indexing key + */ + void erase(const key_type& key) { data_.erase(key); } + + protected: + /*! + * \brief Create an empty container + * \return The object created + */ + static ObjectPtr Empty() { return make_object(); } + /*! + * \brief Create the map using contents from the given iterators. + * \param first Begin of iterator + * \param last End of iterator + * \tparam IterType The type of iterator + * \return ObjectPtr to the map created + */ + template + static ObjectPtr CreateFromRange(IterType first, IterType last) { +ObjectPtr p = make_object(); +p->data_ = std::unordered_map(first, last); +return p; + } + /*! + * \brief InsertMaybeReHash an entry into the given hash map + * \param kv The entry to be inserted + * \param map The pointer to the map, can be changed if re-hashing happens + */ + static void InsertMaybeReHash(const KVType& kv, ObjectPtr* map) { +MapNode* m = static_cast(map->get()); +m->data_[kv.first] = kv.second; } + /*! + * \brief Create an empty container with elements copying from another MapNode + * \param m The source container
[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5770: [RUNTIME] Introduce MetadataModule to separate code compilation/interpretation and weight initialization
zhiics commented on a change in pull request #5770: URL: https://github.com/apache/incubator-tvm/pull/5770#discussion_r442490987 ## File path: python/tvm/contrib/graph_runtime.py ## @@ -162,7 +162,12 @@ def set_input(self, key=None, value=None, **params): keys = list(params.keys()) keys.sort(key=lambda x: -np.prod(params[x].shape)) for k in keys: -self._get_input(k).copyfrom(params[k]) +# TODO(zhiics) Skip the weights for submodule in a better way. +# We should use MetadataModule for initialization and remove Review comment: Yes, there is a warning in the C++ side. https://github.com/apache/incubator-tvm/blob/d8c80c382f02052b07da1235190a5b6c7acea994/src/runtime/graph/graph_runtime.cc#L93 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442488594 ## File path: include/tvm/node/container.h ## @@ -43,51 +44,1188 @@ using runtime::Downcast; using runtime::IterAdapter; using runtime::make_object; using runtime::Object; +using runtime::ObjectEqual; +using runtime::ObjectHash; using runtime::ObjectPtr; using runtime::ObjectPtrEqual; using runtime::ObjectPtrHash; using runtime::ObjectRef; using runtime::String; using runtime::StringObj; -/*! \brief String-aware ObjectRef hash functor */ -struct ObjectHash { - size_t operator()(const ObjectRef& a) const { -if (const auto* str = a.as()) { - return String::HashBytes(str->data, str->size); -} -return ObjectPtrHash()(a); +#if (TVM_USE_STL_MAP != 0) + +/*! \brief Shared content of all specializations of hash map */ +class MapNode : public Object { + public: + /*! \brief Type of the keys in the hash map */ + using key_type = ObjectRef; + /*! \brief Type of the values in the hash map */ + using mapped_type = ObjectRef; + /*! \brief Type of the actual underlying container */ + using ContainerType = std::unordered_map; + /*! \brief Iterator class */ + using iterator = ContainerType::iterator; + /*! \brief Iterator class */ + using const_iterator = ContainerType::const_iterator; + /*! \brief Type of value stored in the hash map */ + using KVType = ContainerType::value_type; + + static_assert(std::is_standard_layout::value, "KVType is not standard layout"); + static_assert(sizeof(KVType) == 16 || sizeof(KVType) == 8, "sizeof(KVType) incorrect"); + + static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeMap; + static constexpr const char* _type_key = "Map"; + TVM_DECLARE_FINAL_OBJECT_INFO(MapNode, Object); + + /*! + * \brief Number of elements in the SmallMapNode + * \return The result + */ + size_t size() const { return data_.size(); } + /*! + * \brief Count the number of times a key exists in the hash map + * \param key The indexing key + * \return The result, 0 or 1 + */ + size_t count(const key_type& key) const { return data_.count(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The const reference to the value + */ + const mapped_type& at(const key_type& key) const { return data_.at(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The mutable reference to the value + */ + mapped_type& at(const key_type& key) { return data_.at(key); } + /*! \return begin iterator */ + iterator begin() { return data_.begin(); } + /*! \return const begin iterator */ + const_iterator begin() const { return data_.begin(); } + /*! \return end iterator */ + iterator end() { return data_.end(); } + /*! \return end iterator */ + const_iterator end() const { return data_.end(); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + const_iterator find(const key_type& key) const { return data_.find(key); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + iterator find(const key_type& key) { return data_.find(key); } + /*! + * \brief Erase the entry associated with the iterator + * \param position The iterator + */ + void erase(const iterator& position) { data_.erase(position); } + /*! + * \brief Erase the entry associated with the key, do nothing if not exists + * \param key The indexing key + */ + void erase(const key_type& key) { data_.erase(key); } + + protected: + /*! + * \brief Create an empty container + * \return The object created + */ + static ObjectPtr Empty() { return make_object(); } + /*! + * \brief Create the map using contents from the given iterators. + * \param first Begin of iterator + * \param last End of iterator + * \tparam IterType The type of iterator + * \return ObjectPtr to the map created + */ + template + static ObjectPtr CreateFromRange(IterType first, IterType last) { +ObjectPtr p = make_object(); +p->data_ = std::unordered_map(first, last); +return p; + } + /*! + * \brief InsertMaybeReHash an entry into the given hash map + * \param kv The entry to be inserted + * \param map The pointer to the map, can be changed if re-hashing happens + */ + static void InsertMaybeReHash(const KVType& kv, ObjectPtr* map) { +MapNode* m = static_cast(map->get()); +m->data_[kv.first] = kv.second; } + /*! + * \brief Create an empty container with elements copying from another MapNode + * \param m The source container
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
tqchen commented on a change in pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#discussion_r442478436 ## File path: include/tvm/node/container.h ## @@ -43,51 +44,1188 @@ using runtime::Downcast; using runtime::IterAdapter; using runtime::make_object; using runtime::Object; +using runtime::ObjectEqual; +using runtime::ObjectHash; using runtime::ObjectPtr; using runtime::ObjectPtrEqual; using runtime::ObjectPtrHash; using runtime::ObjectRef; using runtime::String; using runtime::StringObj; -/*! \brief String-aware ObjectRef hash functor */ -struct ObjectHash { - size_t operator()(const ObjectRef& a) const { -if (const auto* str = a.as()) { - return String::HashBytes(str->data, str->size); -} -return ObjectPtrHash()(a); +#if (TVM_USE_STL_MAP != 0) + +/*! \brief Shared content of all specializations of hash map */ +class MapNode : public Object { + public: + /*! \brief Type of the keys in the hash map */ + using key_type = ObjectRef; + /*! \brief Type of the values in the hash map */ + using mapped_type = ObjectRef; + /*! \brief Type of the actual underlying container */ + using ContainerType = std::unordered_map; + /*! \brief Iterator class */ + using iterator = ContainerType::iterator; + /*! \brief Iterator class */ + using const_iterator = ContainerType::const_iterator; + /*! \brief Type of value stored in the hash map */ + using KVType = ContainerType::value_type; + + static_assert(std::is_standard_layout::value, "KVType is not standard layout"); + static_assert(sizeof(KVType) == 16 || sizeof(KVType) == 8, "sizeof(KVType) incorrect"); + + static constexpr const uint32_t _type_index = runtime::TypeIndex::kRuntimeMap; + static constexpr const char* _type_key = "Map"; + TVM_DECLARE_FINAL_OBJECT_INFO(MapNode, Object); + + /*! + * \brief Number of elements in the SmallMapNode + * \return The result + */ + size_t size() const { return data_.size(); } + /*! + * \brief Count the number of times a key exists in the hash map + * \param key The indexing key + * \return The result, 0 or 1 + */ + size_t count(const key_type& key) const { return data_.count(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The const reference to the value + */ + const mapped_type& at(const key_type& key) const { return data_.at(key); } + /*! + * \brief Index value associated with a key, throw exception if the key does not exist + * \param key The indexing key + * \return The mutable reference to the value + */ + mapped_type& at(const key_type& key) { return data_.at(key); } + /*! \return begin iterator */ + iterator begin() { return data_.begin(); } + /*! \return const begin iterator */ + const_iterator begin() const { return data_.begin(); } + /*! \return end iterator */ + iterator end() { return data_.end(); } + /*! \return end iterator */ + const_iterator end() const { return data_.end(); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + const_iterator find(const key_type& key) const { return data_.find(key); } + /*! + * \brief Index value associated with a key + * \param key The indexing key + * \return The iterator of the entry associated with the key, end iterator if not exists + */ + iterator find(const key_type& key) { return data_.find(key); } + /*! + * \brief Erase the entry associated with the iterator + * \param position The iterator + */ + void erase(const iterator& position) { data_.erase(position); } + /*! + * \brief Erase the entry associated with the key, do nothing if not exists + * \param key The indexing key + */ + void erase(const key_type& key) { data_.erase(key); } + + protected: + /*! + * \brief Create an empty container + * \return The object created + */ + static ObjectPtr Empty() { return make_object(); } + /*! + * \brief Create the map using contents from the given iterators. + * \param first Begin of iterator + * \param last End of iterator + * \tparam IterType The type of iterator + * \return ObjectPtr to the map created + */ + template + static ObjectPtr CreateFromRange(IterType first, IterType last) { +ObjectPtr p = make_object(); +p->data_ = std::unordered_map(first, last); +return p; + } + /*! + * \brief InsertMaybeReHash an entry into the given hash map + * \param kv The entry to be inserted + * \param map The pointer to the map, can be changed if re-hashing happens + */ + static void InsertMaybeReHash(const KVType& kv, ObjectPtr* map) { +MapNode* m = static_cast(map->get()); +m->data_[kv.first] = kv.second; } + /*! + * \brief Create an empty container with elements copying from another MapNode + * \param m The source container + *
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5770: [RUNTIME] Introduce MetadataModule to separate code compilation/interpretation and weight initialization
tqchen commented on a change in pull request #5770: URL: https://github.com/apache/incubator-tvm/pull/5770#discussion_r442477655 ## File path: python/tvm/contrib/graph_runtime.py ## @@ -162,7 +162,12 @@ def set_input(self, key=None, value=None, **params): keys = list(params.keys()) keys.sort(key=lambda x: -np.prod(params[x].shape)) for k in keys: -self._get_input(k).copyfrom(params[k]) +# TODO(zhiics) Skip the weights for submodule in a better way. +# We should use MetadataModule for initialization and remove Review comment: Shall we shoot an warning at least if val is not available? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] ANSHUMAN87 opened a new pull request #5846: Additional canonicalization added for AddNode
ANSHUMAN87 opened a new pull request #5846: URL: https://github.com/apache/incubator-tvm/pull/5846 The PR has 2 issue fix: 1: 2 + x was always operated as x + 2. It hides certain match condition. 2: Canonicalize (c1 - y) + x --> (x - y) + c1 cc @yzhliu , @zhiics , @tqchen 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: us...@infra.apache.org
[incubator-tvm] branch egg created (now d8c80c3)
This is an automated email from the ASF dual-hosted git repository. jroesch pushed a change to branch egg in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. at d8c80c3 `tvm` crate stage 3 of Rust refactor (#5769) No new revisions were added by this update.
[GitHub] [incubator-tvm] jroesch commented on pull request #5830: Rust Refactor Stage 4: Rewrite Rust graph runtime to use new APIs
jroesch commented on pull request #5830: URL: https://github.com/apache/incubator-tvm/pull/5830#issuecomment-646242260 @robo-corg @tqchen this is like a straight copy of the old `runtime` crate with slight modifications to use the new `tvm-sys`. After this patch lands I can send a final one to switch CI over to the new bindings and drop support for the old ones. 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: us...@infra.apache.org
[incubator-tvm] branch master updated: `tvm` crate stage 3 of Rust refactor (#5769)
This is an automated email from the ASF dual-hosted git repository. jroesch pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git The following commit(s) were added to refs/heads/master by this push: new d8c80c3 `tvm` crate stage 3 of Rust refactor (#5769) d8c80c3 is described below commit d8c80c382f02052b07da1235190a5b6c7acea994 Author: Jared Roesch AuthorDate: Thu Jun 18 11:33:25 2020 -0700 `tvm` crate stage 3 of Rust refactor (#5769) * Adapt to new macro * Add tvm crate * Fix out of tree pass with new bindings * Super slick API working * Add examples * Delay egg example and add ASF headers * Move array.rs around * Remove outdated tests will restore in CI PR * Fix some memory issues * Fix ref counting issue * Formatting and cleanup * Remove out-of-tree for now * Remove out-of-tree --- rust/Cargo.toml| 4 +- rust/runtime/tests/test_wasm32/Cargo.toml | 4 + rust/runtime/tests/test_wasm32/build.rs| 14 +- rust/tvm-macros/src/external.rs| 6 +- rust/tvm-macros/src/object.rs | 31 ++- rust/tvm-rt/src/array.rs | 79 ++ rust/tvm-rt/src/errors.rs | 2 + rust/tvm-rt/src/function.rs| 20 +- rust/tvm-rt/src/lib.rs | 4 +- rust/tvm-rt/src/ndarray.rs | 22 +- rust/tvm-rt/src/object/mod.rs | 53 ++-- rust/tvm-rt/src/object/object_ptr.rs | 101 ++-- rust/tvm-rt/src/string.rs | 42 +-- rust/tvm-rt/src/to_function.rs | 56 ++-- rust/tvm-sys/src/lib.rs| 12 + rust/tvm/.gitignore| 7 + .../test_wasm32/Cargo.toml => tvm/.travis.yml} | 14 +- rust/{runtime/tests/test_wasm32 => tvm}/Cargo.toml | 27 +- rust/tvm/README.md | 235 + rust/tvm/src/ir/mod.rs | 50 rust/tvm/src/ir/relay/mod.rs | 282 + rust/tvm/src/lib.rs| 47 rust/tvm/src/runtime/mod.rs| 20 ++ rust/tvm/src/transform.rs | 93 +++ src/printer/relay_text_printer.cc | 2 - 25 files changed, 1075 insertions(+), 152 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 6849c03..d9bb3ab 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -29,5 +29,7 @@ members = [ "frontend/tests/callback", "frontend/examples/resnet", "tvm-sys", - "tvm-rt" + "tvm-macros", + "tvm-rt", + "tvm", ] diff --git a/rust/runtime/tests/test_wasm32/Cargo.toml b/rust/runtime/tests/test_wasm32/Cargo.toml index 1d3373a..eeead45 100644 --- a/rust/runtime/tests/test_wasm32/Cargo.toml +++ b/rust/runtime/tests/test_wasm32/Cargo.toml @@ -20,7 +20,11 @@ name = "test-wasm32" version = "0.0.0" license = "Apache-2.0" authors = ["TVM Contributors"] +edition = "2018" [dependencies] ndarray="0.12" tvm-runtime = { path = "../../" } + +[build-dependencies] +anyhow = "^1.0" diff --git a/rust/runtime/tests/test_wasm32/build.rs b/rust/runtime/tests/test_wasm32/build.rs index 8b72be2..5c816c3 100644 --- a/rust/runtime/tests/test_wasm32/build.rs +++ b/rust/runtime/tests/test_wasm32/build.rs @@ -19,12 +19,14 @@ use std::{path::PathBuf, process::Command}; -fn main() { +use anyhow::{Context, Result}; + +fn main() -> Result<()> { let mut out_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); out_dir.push("lib"); if !out_dir.is_dir() { -std::fs::create_dir(_dir).unwrap(); +std::fs::create_dir(_dir).context("failed to create directory for WASM outputs")?; } let obj_file = out_dir.join("test.o"); @@ -36,7 +38,8 @@ fn main() { )) .arg(_dir) .output() -.expect("Failed to execute command"); +.context("failed to execute Python script for generating TVM library")?; + assert!( obj_file.exists(), "Could not build tvm lib: {}", @@ -49,12 +52,14 @@ fn main() { ); let ar = option_env!("LLVM_AR").unwrap_or("llvm-ar-8"); + let output = Command::new(ar) .arg("rcs") .arg(_file) .arg(_file) .output() -.expect("Failed to execute command"); +.context("failed to run LLVM_AR command")?; + assert!( lib_file.exists(), "Could not create archive: {}", @@ -68,4 +73,5 @@ fn main() { println!("cargo:rustc-link-lib=static=test_wasm32"); println!("cargo:rustc-link-search=native={}", out_dir.display()); +Ok(()) } diff --git a/rust/tvm-macros/src/external.rs
[GitHub] [incubator-tvm] jroesch merged pull request #5769: `tvm` crate stage 3 of Rust refactor
jroesch merged pull request #5769: URL: https://github.com/apache/incubator-tvm/pull/5769 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 commented on pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 commented on pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#issuecomment-646226758 @tqchen Just responded to all the review comments, added test cases and code comments, could you take another look? 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: us...@infra.apache.org
[incubator-tvm] branch master updated (082874c -> 9ba98be)
This is an automated email from the ASF dual-hosted git repository. tqchen pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git. from 082874c [Torch][Quantized] Fix converting serialized quantized models (#5839) add 9ba98be ffi (Object): make class dict visible in instances (#5843) No new revisions were added by this update. Summary of changes: python/tvm/runtime/object.py | 3 ++- tests/python/unittest/test_node_reflection.py | 7 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
[GitHub] [incubator-tvm] tqchen merged pull request #5843: ffi (Object): make class dict visible in instances
tqchen merged pull request #5843: URL: https://github.com/apache/incubator-tvm/pull/5843 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on pull request #5843: ffi (Object): make class dict visible in instances
tqchen commented on pull request #5843: URL: https://github.com/apache/incubator-tvm/pull/5843#issuecomment-646226767 Thanks @t-vi ! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] junrushao1994 edited a comment on pull request #5740: [Object] Introduce POD-C Compliant tvm::Map
junrushao1994 edited a comment on pull request #5740: URL: https://github.com/apache/incubator-tvm/pull/5740#issuecomment-644613259 Summary of the change: - Remove most of the short names (i, n, m, d, b) and use more informative ones instead. - Added comments between important code blocks (insert vs rehash) - Add test cases to cover the switch between SmallMapNode and DenseMapNode 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: us...@infra.apache.org
[GitHub] [incubator-tvm] alexwong edited a comment on issue #5835: Darknet library support out of date/inconsistent with master?
alexwong edited a comment on issue #5835: URL: https://github.com/apache/incubator-tvm/issues/5835#issuecomment-646220264 That makes sense. I'm wondering if you're updating the parser to support that fork of Darknet and it seems to have diverged slightly from the upstream master, it could potentially face similar parsing issues when using the master repo's Darknet which is what I would think most users of Darknet would try to use. Or will that branch try and maintain important updates/merge their implementation upstream. Do you have a rough idea of when you think you'll finish the update? Thanks! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] alexwong edited a comment on issue #5835: Darknet library support out of date/inconsistent with master?
alexwong edited a comment on issue #5835: URL: https://github.com/apache/incubator-tvm/issues/5835#issuecomment-646220264 That makes sense. I'm wondering if you're updating the parser to support that fork of Darknet and it seems to have diverged slightly from master, it could potentially face similar parsing issues when using the master repo's Darknet. Do you have a rough idea of when you think you'll finish the update? Thanks! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] alexwong commented on issue #5835: Darknet library support out of date/inconsistent with master?
alexwong commented on issue #5835: URL: https://github.com/apache/incubator-tvm/issues/5835#issuecomment-646220264 That makes sense. Do you have a rough idea of when you think you'll finish the update? Thanks! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] jwfromm commented on pull request #5845: [ONNX] Fix an issue with #5755 and add Batch norm unit tests.
jwfromm commented on pull request #5845: URL: https://github.com/apache/incubator-tvm/pull/5845#issuecomment-646216494 thanks for the fix, LGTM. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] mbrookhart opened a new pull request #5845: [ONNX] Fix an issue with #5755 and add Batch norm unit tests.
mbrookhart opened a new pull request #5845: URL: https://github.com/apache/incubator-tvm/pull/5845 @masahi @jwfromm discovered an issue with #5755 , infer_value chokes on ops with multiple outputs. I already knew this for Tuple, this adds a work around to infer batch_norm with the following TupleGetItem node instead of by itself. In adding a regression test, I discovered that the Onnx importer for batch norm wasn't tested, so I added a unit test for it. Are you guys aware of any other multi-output ops that might suffer the same problem? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] kevinthesun commented on a change in pull request #5844: [Relay] symbolic max_output_size
kevinthesun commented on a change in pull request #5844: URL: https://github.com/apache/incubator-tvm/pull/5844#discussion_r442390568 ## File path: topi/python/topi/vision/nms.py ## @@ -326,30 +329,40 @@ def hybrid_nms(data, sorted_index, valid_count, indices, batch_size, num_anchors # Apply nms box_start_idx = coord_start batch_idx = i +num_valid_boxes = 0 for j in range(valid_count[i]): -if output[i, j, score_index] > 0 and (id_index < 0 or output[i, j, id_index] >= 0): +if num_valid_boxes == max_output_size: +for k in range(box_data_length): +output[i, j, k] = -one +box_indices[i, j] = -1 + +elif output[i, j, score_index] > 0: box_a_idx = j -for k in parallel(valid_count[i]): +is_valid_box = 1 + +# a_l: left, a_t: top, a_r: right, a_b: bottom +a_l = min(output[batch_idx, box_a_idx, box_start_idx], + output[batch_idx, box_a_idx, box_start_idx + 2]) +a_t = min(output[batch_idx, box_a_idx, box_start_idx + 1], + output[batch_idx, box_a_idx, box_start_idx + 3]) +a_r = max(output[batch_idx, box_a_idx, box_start_idx], + output[batch_idx, box_a_idx, box_start_idx + 2]) +a_b = max(output[batch_idx, box_a_idx, box_start_idx + 1], + output[batch_idx, box_a_idx, box_start_idx + 3]) + +# check if current box j is valid by calculating iou with +# all existing valid boxes +for k in parallel(j): Review comment: ```suggestion for k in range(j): ``` I found use serial loop here can actually improve performance a bit. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] maheshambule commented on pull request #5528: POC refactor tflite frontend
maheshambule commented on pull request #5528: URL: https://github.com/apache/incubator-tvm/pull/5528#issuecomment-646202822 @anijain2305, it would be great to hear your feedback/review on this proposed refactoring. @u99127 Do you want to add further comments/suggestions here. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] anijain2305 commented on pull request #5528: POC refactor tflite frontend
anijain2305 commented on pull request #5528: URL: https://github.com/apache/incubator-tvm/pull/5528#issuecomment-646176715 @u99127 @maheshambule Are we following up on this? 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: us...@infra.apache.org
[incubator-tvm] branch master updated: [Torch][Quantized] Fix converting serialized quantized models (#5839)
This is an automated email from the ASF dual-hosted git repository. masahi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git The following commit(s) were added to refs/heads/master by this push: new 082874c [Torch][Quantized] Fix converting serialized quantized models (#5839) 082874c is described below commit 082874c51f728d8ff12a9cd2eed4d2734e71eb8f Author: masahi AuthorDate: Fri Jun 19 01:24:03 2020 +0900 [Torch][Quantized] Fix converting serialized quantized models (#5839) * [Torch] Fix converting serialized quantized models * clean up dtype check * comment clean up --- python/tvm/relay/frontend/pytorch.py | 42 + tests/python/frontend/pytorch/qnn_test.py | 45 --- 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index d2451cd..d3b6510 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -115,6 +115,14 @@ def _should_construct_dynamic_list(list_construct_node): return False +def _is_quantized_tensor(data, prelude): +# If a quantized Torch module is saved and loaded back, dtype will be dropped +# Since dtypes from Torch tensors are not reliable in such cases, we use +# Relay's type inference result to decide if an input tensor is quantized +ty = _infer_type_with_prelude(data, prelude) +return ty.dtype == "uint8" + + # operator implementation def _elemwise(name): def _impl(inputs, input_types): @@ -530,10 +538,10 @@ def _linspace(): return _impl -def _relu(): +def _relu(prelude): def _impl(inputs, input_types): data = inputs[0] -if input_types[0] == "quint8": +if _is_quantized_tensor(data, prelude): assert len(inputs) == 3, "Input quant param not found in op inputs" input_zero_point = _expr.const(inputs[2], dtype="int32") return qnn_torch.quantized_relu(data, input_zero_point) @@ -595,7 +603,7 @@ def _log_sigmoid(): return _op.log(_op.tensor.sigmoid(data)) return _impl -def _adaptive_avg_pool_2d(): +def _adaptive_avg_pool_2d(prelude): def _impl(inputs, input_types): data = inputs[0] output_size = _infer_shape(inputs[1]) @@ -603,7 +611,7 @@ def _adaptive_avg_pool_2d(): def func(x): return _op.nn.adaptive_avg_pool2d(x, output_size=output_size) -if input_types[0] == "quint8": +if _is_quantized_tensor(data, prelude): return qnn_torch.apply_with_upcast(data, func) return func(data) @@ -1108,7 +1116,7 @@ def _softplus(): return _op.log(_op.exp(inputs[0] * beta) + _expr.const(1.)) / beta return _impl -def _avg_pool2d(): +def _avg_pool2d(prelude): def _impl(inputs, input_types): data = inputs[0] @@ -1130,7 +1138,7 @@ def _avg_pool2d(): ceil_mode=ceil_mode, count_include_pad=count_include_pad) -if input_types[0] == "quint8": +if _is_quantized_tensor(data, prelude): return qnn_torch.apply_with_upcast(data, func) return func(data) @@ -1254,7 +1262,7 @@ def _variance(): return _impl -def _mean(): +def _mean(prelude): def _impl(inputs, input_types): data = inputs[0] @@ -1274,7 +1282,7 @@ def _mean(): def func(x): return _op.mean(x, axis, keepdims, exclude) -if input_types[0] == "quint8": +if _is_quantized_tensor(data, prelude): assert len(inputs) == 6, "Input quant param not found in op inputs" input_scale = _expr.const(inputs[4]) input_zero_point = _expr.const(inputs[5]) @@ -1492,7 +1500,7 @@ def _to(): return _impl -def _upsample(method): +def _upsample(method, prelude): def _impl(inputs, input_types): if isinstance(inputs[1], _expr.Var): out_size = _infer_shape(inputs[1]) @@ -1516,7 +1524,7 @@ def _upsample(method): def func(x): return _op.image.resize(x, out_size, "NCHW", method, coord_trans) -if input_types[0] == "quint8": +if _is_quantized_tensor(data, prelude): import torch from packaging import version @@ -1835,8 +1843,8 @@ def _get_convert_map(prelude): "aten::take": _take(), "aten::where" : _where(), "aten::topk": _topk(), -"aten::relu": _relu(), -"aten::relu_" : _relu(), +"aten::relu": _relu(prelude), +"aten::relu_" : _relu(prelude), "aten::prelu" : _prelu(),
[GitHub] [incubator-tvm] masahi merged pull request #5839: [Torch][Quantized] Fix converting serialized quantized models
masahi merged pull request #5839: URL: https://github.com/apache/incubator-tvm/pull/5839 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: us...@infra.apache.org
[GitHub] [incubator-tvm] yongwww commented on pull request #5844: [Relay] symbolic max_output_size
yongwww commented on pull request #5844: URL: https://github.com/apache/incubator-tvm/pull/5844#issuecomment-646139868 Tested with 2 random boxes (score_threshold=0, iou_threshold=0.6, max_output_size=7) on my local env., the execution time of nms decreased to 0.003057119846343994 second from 0.39738729953765867 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on issue #5841: When I use Julia to call tvm at arm server, find the error : CommandLine Error: Option 'aarch64-enable-ccmp' registered more than once! LLVM E
tqchen commented on issue #5841: URL: https://github.com/apache/incubator-tvm/issues/5841#issuecomment-646135212 Please open a new trouble shooting thread on https://discuss.tvm.ai/ 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: us...@infra.apache.org
[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5753: [Draft] Support Module based interface runtime
tqchen commented on a change in pull request #5753: URL: https://github.com/apache/incubator-tvm/pull/5753#discussion_r442344555 ## File path: python/tvm/runtime/module.py ## @@ -41,6 +41,10 @@ def __init__(self, handle): self.handle = handle self._entry = None self.entry_name = "__tvm_main__" +# TODO:(FrozenGene): support rpc +if self.type_key == 'GraphRuntimeFactory': +#from tvm.runtime.graph_runtime_factory import GraphRuntimeFactoryModule +self._entry = self.runtime_create Review comment: Oh, what i mean is that user can directly use `mod["default"](ctx)` to create the model, of course `mod["resnet18"](ctx)` still works 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: us...@infra.apache.org
[GitHub] [incubator-tvm] yongwww opened a new pull request #5844: [Relay] symbolic max_output_size
yongwww opened a new pull request #5844: URL: https://github.com/apache/incubator-tvm/pull/5844 - modify nms to support symbolic max_output_size - stop iou computation once get enough boxes @kevinthesun @zhiics @icemelon9 @lixiaoquan 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on pull request #5843: ffi (Object): make class dict visible in instances
t-vi commented on pull request #5843: URL: https://github.com/apache/incubator-tvm/pull/5843#issuecomment-646121900 @tqchen / @zhiics I think you're closest to this code. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi opened a new pull request #5843: ffi (Object): make class dict visible in instances
t-vi opened a new pull request #5843: URL: https://github.com/apache/incubator-tvm/pull/5843 In Python, generic objects (i.e. non-types/classes) inherit the `__dir__` elements from their class. This enable tab completion in interactive environments like Jupyter notebooks. Reference for this behaviour is Python's `__dir__` for objects: https://github.com/python/cpython/blob/8f192d12af82c4dc40730bf59814f6a68f68f950/Objects/typeobject.c#L4854-L4899 I'll readily admit that I don't know whether the location for the test I offer is a good one. It seemed to be a place where low-level stuff is tested and where this can blend in. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] zhanghaohit opened a new pull request #5842: [VTA][OpenCL] Cloud FPGA support
zhanghaohit opened a new pull request #5842: URL: https://github.com/apache/incubator-tvm/pull/5842 This PR, coupled with [this](https://github.com/apache/incubator-tvm-vta/pull/9) on tvm-vta repo, is the basic implementation of RFC #4958 Some notes: - this is just a basic version without much performance optimization. We've done some optimization, and achieved significant improvement (but this part of code is not ready; has to be organized and cleaned up further). - there are some experimental features, which are also included in this PR, including - sync all the instructions per model (instead of per layer) - static auto-tune using profiling results These codes are not well styled (using some environmental variables), and we have to think about how to format/implement nicely. But we think these features are useful so we also commit. We can discuss if we should include these codes in this PR, or leave it for other PRs. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442174045 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: OK. So I think I have the other bits covered. ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: Thank you! 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: us...@infra.apache.org
[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5834: Improve type handling in PyTorch frontend
siju-samuel commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442164092 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: Its not related to this PR. So u can leave it for now and raise another followup PR to support broadcasting for `where`. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442163343 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: I would have a tendency to leave it (and also not raise in the frontend but leave _op.where to complain because broadcasting is substantial to test for) and then I can do a followup PR for where broadcasting. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442162253 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: Ah, OK. :sweat_smile: Well, do you want the broadcasting for where to go in this patch or should I just leave it. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5834: Improve type handling in PyTorch frontend
siju-samuel commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442146948 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: Other erros are there. Its ok. im still working on that. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442145084 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: So I fixed the where, but I then get errors in other obscure corners (that reach beyond the frontend/pytoch.py). Did the GPT2 model translate correctly with the old code? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442145084 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: So I fixed the where, but I then get errors in other obscure corners. Did the GPT2 model translate correctly with the old code? 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: us...@infra.apache.org
[GitHub] [incubator-tvm-vta] zhanghaohit opened a new pull request #9: Intelfocl support
zhanghaohit opened a new pull request #9: URL: https://github.com/apache/incubator-tvm-vta/pull/9 This PR relates to this [RFC](https://github.com/apache/incubator-tvm/issues/5840). Main changes are: - OpenCL driver - intelfocl implementation for VTA - add ALU MUL and Load INT_8 This is a basic version as a POC, without much performance optimization. We're still optimizing some parts, and will be submitted as a new PR later. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] agdkyang opened a new issue #5841: When I use tvm at arm server, find the error : CommandLine Error: Option 'aarch64-enable-ccmp' registered more than once! LLVM ERROR: incons
agdkyang opened a new issue #5841: URL: https://github.com/apache/incubator-tvm/issues/5841 When I use tvm at arm server, find the error: : CommandLine Error: Option 'aarch64-enable-ccmp' registered more than once! LLVM ERROR: inconsistency in registered CommandLine options 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: us...@infra.apache.org
[GitHub] [incubator-tvm] masahi commented on a change in pull request #5839: [Torch][Quantized] Fix converting serialized quantized models
masahi commented on a change in pull request #5839: URL: https://github.com/apache/incubator-tvm/pull/5839#discussion_r442127672 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -595,15 +601,18 @@ def _impl(inputs, input_types): return _op.log(_op.tensor.sigmoid(data)) return _impl -def _adaptive_avg_pool_2d(): +def _adaptive_avg_pool_2d(prelude): def _impl(inputs, input_types): data = inputs[0] output_size = _infer_shape(inputs[1]) def func(x): return _op.nn.adaptive_avg_pool2d(x, output_size=output_size) -if input_types[0] == "quint8": +# If a quantized Torch module is saved and loaded back, dtype will be dropped +# input_types[0] can be float even though the input is a quantized tensor +# To reliably determine input types, we use Relay's type inference result +if _is_quantized_tensor(data, prelude): Review comment: done 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: us...@infra.apache.org
[GitHub] [incubator-tvm] zhanghaohit opened a new issue #5840: [RFC][VTA] Support for Cloud Devices (OpenCL-compatible)
zhanghaohit opened a new issue #5840: URL: https://github.com/apache/incubator-tvm/issues/5840 # Motivation Cloud devices are more powerful than Edge devices, which provides higher computation capabilities for deep learning workloads. For example, for the VTA core, with Cloud devices, we have more resources to support larger GEMM cores (e.g., 32\*32 or even 64\*64) and device buffers, thus making it possible to boost the performance to great extent. Therefore, it is worthwhile to provide a generic framework to support cloud devices under TVM/VTA architecture. However, it is non-trivial to extend VTA to Cloud devices. Because the original Xilinx HLS VTA core only works on Xilinx Edge FPGA devices, and Cloud devices exposes different communication models (i.e., shared memory between ARM cores and FPGA device for Edge, vs., PCIe between host and FPGA device for Cloud), and different programming models. In this work, we propose to design a unified framework that can be adapted to any OpenCL-compatible hardware accelerators, e.g., FPGA, ASICs, to seamlessly work with the TVM-VTA architecture. Meanwhile, we provide an example of OpenCL-based VTA implementation that has been tested on the Intel's high-end FPGAs. # Proposal We would like to extend VTA to OpenCL-compatible devices (e.g. Intel Programmable Acceleration Card). In particular, we provide a framework where any OpenCL-compatible devices can be easily integrated. The reason we choose OpenCL-compatible devices are: - OpenCL is generic enough to support a group of devices. For example, both Xilinx and Intel are now in transition towards OpenCL based HLS approaches. - Vendor-specific optimizations are built-in within their respective OpenCL SDKs (e.g., pack two 8-bit multiply-add units into 1 DSP slice), but the framework we're providing does not limit to specific SDKs. In addition to the generic OpenCL framework, as a first attempt for the hardware implementation, we would like to base on Intel Cloud FPGA (e.g. Intel Programmable Acceleration Card) using Intel® FPGA SDK for OpenCL, which has proven portability and scalability for both Intel® Programmable Acceleration (PAC) cards and other custom Intel-FPGA-based acceleration cards. But the overall framework is generic, meaning that any OpenCL-compatible devices can be plugged in with only little extra hardware-specific implementation. ### Major works - Efficient communication between host and PCIe devices as PCIe transmission is costly compared to memory copy - To avoid frequent PCIe copies, we propose to let all middle layers of a computation graph to completely run in FPGA devices, without interleaved CPU layers. In particular, originally, residual block in Resnet run in CPU (ARM cores), which may cause copy in and out from device memory frequently. The addition of extra VTA instructions are intended to move this kind of residual block to FPGA device. - Do copy of uops and instructions in a batch. In particular, only do synchronization after all on-device layers are queued, or queues are overflowed. - Support auto-copy between layers running on different devices. We propose to add a few more IR passes: - annotate device types for computation graph - tag and propagate device types among layers - add copy operations (device_copy) automatically if adjacent layers are not in the same devices - Driver development for OpenCL-compatible devices - The original pynq driver could not be used as we do not have direct access to h/w registers - We implemented a middle layer driver for OpenCL-compatible devices - The layer sits on devices' native driver stack, which implemented an interrupt based device driver - OpenCL hardware implementation - Addition of extra Load/ALU instructions, such as Load int8 to ACC buffer (to support ALU-only nodes), ALU Multiply and Left-shift, to support more continued calculations on FPGA - Refactored the hardware implementation code to conform to Intel® FPGA SDK for OpenCL as a sample hardware implementation ### Major changes to the existing TVM/VTA framework - To run a workload on cloud FPGA, there is no need to launch additional service on the device side (e.g., rpc server). All the driver and runtime programs are running in the host side. - Change VTA runtime to support batch queue synchronization. We intend to only queue the instructions/uops when running a layer and return immediately without doing device synchronization. We only do synchronization and device run when queues are overflowed or the next layer is not on-device。 - We have to modify the device propagation behaviour from post DFS traversal to recursive method. Originally, device type is propagated based on the post DFS traversed graph, which may not be consistent if the argument
[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5834: Improve type handling in PyTorch frontend
siju-samuel commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442033597 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -1755,12 +1809,21 @@ def _convert_data_type(input_type): return "int8" Review comment: Add "int64" here ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -1733,12 +1780,19 @@ def _convert_dtype_value(val): 0:"torch.unit8", None:"torch.int64"} # Default is torch.int64 if val in convert_torch_dtype_map: -return convert_torch_dtype_map[val] +return _convert_data_type(convert_torch_dtype_map[val]) else: msg = "Torch data type value %d is not handled yet." % (val) raise NotImplementedError(msg) -def _convert_data_type(input_type): +def _convert_data_type(input_type, default_dtype=None): +"""converts the PyTorch scalar type input_type to a TVM dtype. + optionally, default_dtype can be a TVM dtype that is used + if input_type is None (but not when it is unknown)""" +if input_type is None and default_dtype is not None: +return default_dtype + +input_type = input_type.lower() if input_type in ["double", "torch.float64"]: return "float64" elif input_type in ["float", "torch.float32"]: Review comment: You can ignore this. this is not an issue 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442105064 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -1733,12 +1780,19 @@ def _convert_dtype_value(val): 0:"torch.unit8", None:"torch.int64"} # Default is torch.int64 if val in convert_torch_dtype_map: -return convert_torch_dtype_map[val] +return _convert_data_type(convert_torch_dtype_map[val]) else: msg = "Torch data type value %d is not handled yet." % (val) raise NotImplementedError(msg) -def _convert_data_type(input_type): +def _convert_data_type(input_type, default_dtype=None): +"""converts the PyTorch scalar type input_type to a TVM dtype. + optionally, default_dtype can be a TVM dtype that is used + if input_type is None (but not when it is unknown)""" +if input_type is None and default_dtype is not None: +return default_dtype + +input_type = input_type.lower() if input_type in ["double", "torch.float64"]: return "float64" elif input_type in ["float", "torch.float32"]: Review comment: You mean the the GPT2 example? It doesn't throw that for me. What is your PyTorch version and the stack trace you are getting? 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442105064 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -1733,12 +1780,19 @@ def _convert_dtype_value(val): 0:"torch.unit8", None:"torch.int64"} # Default is torch.int64 if val in convert_torch_dtype_map: -return convert_torch_dtype_map[val] +return _convert_data_type(convert_torch_dtype_map[val]) else: msg = "Torch data type value %d is not handled yet." % (val) raise NotImplementedError(msg) -def _convert_data_type(input_type): +def _convert_data_type(input_type, default_dtype=None): +"""converts the PyTorch scalar type input_type to a TVM dtype. + optionally, default_dtype can be a TVM dtype that is used + if input_type is None (but not when it is unknown)""" +if input_type is None and default_dtype is not None: +return default_dtype + +input_type = input_type.lower() if input_type in ["double", "torch.float64"]: return "float64" elif input_type in ["float", "torch.float32"]: Review comment: You mean the the GPT2 example? It doesn't throw that for me. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5834: Improve type handling in PyTorch frontend
siju-samuel commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442088235 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: i think now you can throw error from frontend. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] siju-samuel edited a comment on issue #5835: Darknet library support out of date/inconsistent with master?
siju-samuel edited a comment on issue #5835: URL: https://github.com/apache/incubator-tvm/issues/5835#issuecomment-645889680 @alexwong This error is because the `network` and `layer` datastructure is not same between master and tvmbranch. So the parsing have issues. Im currently updating the whole code based on 'https://github.com/AlexeyAB/darknet' to support yolov4 and this can support previous versions as well. Since we have to rely on their library (`.so` we have to build locally ) to parse darknet cfg and weight, maintenance is high for this framework. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] siju-samuel commented on issue #5835: Darknet library support out of date/inconsistent with master?
siju-samuel commented on issue #5835: URL: https://github.com/apache/incubator-tvm/issues/5835#issuecomment-645889680 @alexwong This error is because the `network` and `layer` datastructure is not same. So the parsing have issues. Im currently updating the whole code based on 'https://github.com/AlexeyAB/darknet' to support yolov4 and this can support previous versions as well. Since we have to rely on their library (`.so` we have to build locally ) to parse darknet cfg and weight, maintenance is high for this framework. 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442079677 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: So the immediate error was caused by numpy scalars instead of Python number. :confused: That is easily fixed by replacing isinstance(..., (float, int, bool))` with `np.isscalar(...)`. I do bump into something about the shape in a where statement not being broadcast. That's probably unrelated to the dtype fixes, but I can throw in broadcasting for where (the question being whether we want it in relay, too, or just in the frontend). 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442079677 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: So the immediate error was caused by numpy scalars instead of Python number. :confused: That is easily fixed by replacing `isinstance(..., (float, int, bool))` with `np.isscalar(...)`. I do bump into something about the shape in a where statement not being broadcast. That's probably unrelated to the dtype fixes, but I can throw in broadcasting for where (the question being whether we want it in relay, too, or just in the frontend). 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: us...@infra.apache.org
[GitHub] [incubator-tvm] t-vi commented on a change in pull request #5834: Improve type handling in PyTorch frontend
t-vi commented on a change in pull request #5834: URL: https://github.com/apache/incubator-tvm/pull/5834#discussion_r442079677 ## File path: python/tvm/relay/frontend/pytorch.py ## @@ -115,64 +115,70 @@ def inplace_add_to_add(op_name): return False + # operator implementation def _elemwise(name): def _impl(inputs, input_types): -# TODO: Figure out a better way to get typing to work for tensor + scalar -type0 = input_types[0] -if isinstance(inputs[1], _expr.Expr): -type0 = input_types[1] - -type1 = input_types[1] -if isinstance(inputs[0], _expr.Expr): -type1 = input_types[0] - -data0 = _convert_elemwise_input(inputs[0], type0) -data1 = _convert_elemwise_input(inputs[1], type1) - +data0, data1 = _pytorch_promote_types(inputs[:2], input_types[:2]) Review comment: So the immediate error was caused by numpy scalars instead of Python number. :confused: That is easily fixed. I do bump into something about the shape in a where statement not being broadcast. That's probably unrelated to the dtype fixes, but I can throw in broadcasting for where (the question being whether we want it in relay, too, or just in the frontend). 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: us...@infra.apache.org