This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new 2772fb072a [Unity] Fix upstream tests that fail on unity branch
(#16196)
2772fb072a is described below
commit 2772fb072a228d02b7c001d41ed2c845e9574d6c
Author: Siyuan Feng <[email protected]>
AuthorDate: Tue Dec 12 22:09:16 2023 +0800
[Unity] Fix upstream tests that fail on unity branch (#16196)
---
include/tvm/topi/transform.h | 23 +++++++++++++++------
rust/tvm/src/ir/module.rs | 14 ++++++++++---
src/ir/module.cc | 16 +++++++++++++--
tests/python/relay/test_json_compact.py | 20 +++++++------------
tests/python/relay/test_py_converter.py | 16 +++++++++++----
tests/python/relay/test_vm.py | 34 +++++++++++++++-----------------
tests/scripts/task_python_integration.sh | 2 +-
7 files changed, 78 insertions(+), 47 deletions(-)
diff --git a/include/tvm/topi/transform.h b/include/tvm/topi/transform.h
index 009f8cdd30..68f5d36c82 100644
--- a/include/tvm/topi/transform.h
+++ b/include/tvm/topi/transform.h
@@ -43,6 +43,8 @@
#include <unordered_set>
#include <vector>
+#include "tvm/tir/expr.h"
+
namespace tvm {
namespace topi {
@@ -716,8 +718,13 @@ inline Tensor dynamic_strided_slice(const Tensor& x, const
Array<PrimExpr>& begi
arith::Analyzer analyzer;
for (size_t i = 0; i < num_slice_axes; ++i) {
- auto d = analyzer.Simplify(indexdiv(end[i] - begin[i], strides[i]));
- out_shape.push_back(d);
+ // Check ProducerLoad to keep backward compatibility for Relay.
+ if (!begin[i]->IsInstance<ProducerLoadNode>() &&
!end[i]->IsInstance<ProducerLoadNode>() &&
+ !strides[i]->IsInstance<ProducerLoadNode>()) {
+ out_shape.push_back(analyzer.Simplify(indexdiv(end[i] - begin[i],
strides[i])));
+ } else {
+ out_shape.push_back(tvm::tir::Var("dim"));
+ }
}
for (size_t i = num_slice_axes; i < src_tensor_dim; ++i) {
@@ -1584,16 +1591,20 @@ inline Tensor tensordot(const Tensor& A, const
tvm::te::Tensor& B, Array<PrimExp
inline Tensor arange(const PrimExpr& start, const PrimExpr& stop, const
PrimExpr& step,
DataType dtype, std::string name = "T_arange",
std::string tag = kInjective) {
+ arith::Analyzer analyzer;
PrimExpr num_elem;
- if (start.dtype().is_int() && stop.dtype().is_int() &&
step.dtype().is_int()) {
- // fast path for integer arange
+ bool is_all_int = start.dtype().is_int() && stop.dtype().is_int() &&
step.dtype().is_int();
+ if (is_all_int && analyzer.CanProveGreaterEqual(step, 1)) {
+ // fast path for integer arange when step is positive
num_elem = tvm::floordiv((stop - start + step - 1), step);
+ } else if (is_all_int && analyzer.CanProveLess(step, 0)) {
+ // fast path for integer arange when step is negative
+ num_elem = tvm::floordiv((start - stop - step - 1), -step);
} else {
+ // fallback path for non-integer or step of unknown sign
num_elem = tvm::cast(DefaultIndexType(),
tvm::ceil(tvm::cast(tvm::DataType::Float(32), stop -
start) / step));
}
-
- arith::Analyzer analyzer;
num_elem = analyzer.Simplify(num_elem);
return compute(
diff --git a/rust/tvm/src/ir/module.rs b/rust/tvm/src/ir/module.rs
index 4cdca826ec..bb1d2b730d 100644
--- a/rust/tvm/src/ir/module.rs
+++ b/rust/tvm/src/ir/module.rs
@@ -62,7 +62,7 @@ external! {
#[name("relay.parser.ParseExpr")]
fn parse_expression(file_name: TVMString, source: TVMString) -> IRModule;
#[name("ir.IRModule")]
- fn module_new(funcs: Map<GlobalVar, BaseFunc>, types: Map<GlobalTypeVar,
TypeData>, attrs: Map<TVMString, ObjectRef>) -> IRModule;
+ fn module_new(funcs: Map<GlobalVar, BaseFunc>, types: Map<GlobalTypeVar,
TypeData>, attrs: Map<TVMString, ObjectRef>, global_infos: Map<TVMString,
Array<ObjectRef>>) -> IRModule;
// Module methods
#[name("ir.Module_Add")]
fn module_add(module: IRModule, type_name: GlobalVar, expr: BaseFunc,
update: bool) -> IRModule;
@@ -99,16 +99,18 @@ external! {
// Note: we don't expose update here as update is going to be removed.
impl IRModule {
- pub fn new<'a, F, T, A>(funcs: F, types: T, attrs: A) -> Result<IRModule>
+ pub fn new<'a, F, T, A, G>(funcs: F, types: T, attrs: A, global_infos: G)
-> Result<IRModule>
where
F: IntoIterator<Item = (&'a GlobalVar, &'a BaseFunc)>,
T: IntoIterator<Item = (&'a GlobalTypeVar, &'a TypeData)>,
A: IntoIterator<Item = (&'a TVMString, &'a ObjectRef)>,
+ G: IntoIterator<Item = (&'a TVMString, &'a Array<ObjectRef>)>,
{
module_new(
Map::from_iter(funcs),
Map::from_iter(types),
Map::from_iter(attrs),
+ Map::from_iter(global_infos),
)
}
@@ -116,7 +118,13 @@ impl IRModule {
let funcs = HashMap::<GlobalVar, BaseFunc>::new();
let types = HashMap::<GlobalTypeVar, TypeData>::new();
let attrs = HashMap::<TVMString, ObjectRef>::new();
- IRModule::new(funcs.iter(), types.iter(), attrs.iter())
+ let global_infos = HashMap::<TVMString, Array<ObjectRef>>::new();
+ IRModule::new(
+ funcs.iter(),
+ types.iter(),
+ attrs.iter(),
+ global_infos.iter(),
+ )
}
pub fn parse<N, S>(file_name: N, source: S) -> Result<IRModule>
diff --git a/src/ir/module.cc b/src/ir/module.cc
index d9d1586989..c016612c15 100644
--- a/src/ir/module.cc
+++ b/src/ir/module.cc
@@ -397,8 +397,20 @@ TVM_REGISTER_NODE_TYPE(IRModuleNode);
TVM_REGISTER_GLOBAL("ir.IRModule")
.set_body_typed([](tvm::Map<GlobalVar, BaseFunc> funcs,
tvm::Map<GlobalTypeVar, TypeData> types,
- tvm::DictAttrs attrs, Map<String, Array<GlobalInfo>>
global_infos) {
- return IRModule(funcs, types, {}, {}, attrs, global_infos);
+ tvm::ObjectRef attrs, Map<String, Array<GlobalInfo>>
global_infos) {
+ auto dict_attrs = [&attrs]() {
+ if (!attrs.defined()) {
+ return DictAttrs();
+ } else if (auto* as_dict_attrs = attrs.as<tvm::DictAttrsNode>()) {
+ return GetRef<tvm::DictAttrs>(as_dict_attrs);
+ } else if (attrs.as<tvm::MapNode>()) {
+ return tvm::DictAttrs(Downcast<Map<String, ObjectRef>>(attrs));
+ } else {
+ LOG(FATAL) << "Expected attrs argument to be either DictAttrs or
Map<String,ObjectRef>";
+ }
+ }();
+
+ return IRModule(funcs, types, {}, {}, dict_attrs, global_infos);
});
TVM_REGISTER_GLOBAL("ir.Module_Add")
diff --git a/tests/python/relay/test_json_compact.py
b/tests/python/relay/test_json_compact.py
index 56e82862bc..148587e3c9 100644
--- a/tests/python/relay/test_json_compact.py
+++ b/tests/python/relay/test_json_compact.py
@@ -15,11 +15,11 @@
# specific language governing permissions and limitations
# under the License.
-import tvm
-from tvm import relay
-from tvm import te
import json
+import tvm
+import tvm.testing
+from tvm import relay
# 0.6 BACKWARDS COMPATIBILITY TESTS
@@ -125,7 +125,7 @@ def test_global_var():
{"type_key": ""},
{
"type_key": "relay.GlobalVar",
- "attrs": {"_checked_type_": "0", "name_hint": "x", "span": "0"},
+ "attrs": {"_checked_type_": "0", "name_hint": "x", "span": "0",
"struct_info_": "0"},
},
]
data = {
@@ -140,7 +140,7 @@ def test_global_var():
{"type_key": ""},
{
"type_key": "GlobalVar",
- "attrs": {"_checked_type_": "0", "name_hint": "x", "span": "0"},
+ "attrs": {"_checked_type_": "0", "name_hint": "x", "span": "0",
"struct_info_": "0"},
},
]
data = {
@@ -231,6 +231,7 @@ def test_irmodule_attributes():
"global_var_map_": "0",
"source_map": "0",
"type_definitions": "0",
+ "global_infos": "0",
},
},
]
@@ -277,11 +278,4 @@ def test_virtual_device():
if __name__ == "__main__":
- test_op()
- test_type_var()
- test_var()
- test_incomplete_type()
- test_func_tuple_type()
- test_global_var()
- test_tir_var()
- test_str_map()
+ tvm.testing.main()
diff --git a/tests/python/relay/test_py_converter.py
b/tests/python/relay/test_py_converter.py
index d43ec5861b..24bec7251e 100644
--- a/tests/python/relay/test_py_converter.py
+++ b/tests/python/relay/test_py_converter.py
@@ -15,13 +15,15 @@
# specific language governing permissions and limitations
# under the License.
import numpy as np
+
import tvm
-from tvm import te
+import tvm.testing
from tvm import relay
-from tvm.relay.testing import run_as_python
+from tvm.relay.backend.interpreter import ConstructorValue, RefValue
from tvm.relay.prelude import Prelude
+from tvm.relay.testing import run_as_python
from tvm.runtime.container import ADT
-from tvm.relay.backend.interpreter import RefValue, ConstructorValue
+
# helper: uses a dummy let binding to sequence a list
# of expressions: expr1; expr2; expr3, etc.
@@ -668,7 +670,13 @@ def test_compiling_with_main():
mod = tvm.IRModule()
mod["unit"] = unit
mod["main"] = identity
+ gv_main = mod.get_global_var("main")
+ gv_unit = mod.get_global_var("unit")
- res =
run_as_python(mod.get_global_var("main")(mod.get_global_var("unit")()), mod=mod)
+ res = run_as_python(gv_main(relay.Call(gv_unit, ())), mod=mod)
assert isinstance(res, ADT)
assert len(res) == 0
+
+
+if __name__ == "__main__":
+ tvm.testing.main()
diff --git a/tests/python/relay/test_vm.py b/tests/python/relay/test_vm.py
index 63ff66eaa2..270de831e5 100644
--- a/tests/python/relay/test_vm.py
+++ b/tests/python/relay/test_vm.py
@@ -14,26 +14,24 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from unittest.mock import patch
+
import numpy as np
import pytest
-import time
-from unittest.mock import patch
import tvm
-from tvm import runtime
-from tvm import relay, IRModule
+import tvm.testing
+from tvm import IRModule, relay, rpc, runtime
+from tvm.contrib import utils
+from tvm.relay import testing
from tvm.relay.backend import vm
-from tvm.relay.scope_builder import ScopeBuilder
-from tvm.relay.prelude import Prelude
+from tvm.relay.backend.vm import VMCompiler
+from tvm.relay.dataflow_pattern import is_op, wildcard
from tvm.relay.loops import while_loop
-from tvm.relay import testing
-from tvm.contrib import utils
-from tvm import rpc
-import tvm.testing
-from tvm.relay.transform import InferType
+from tvm.relay.prelude import Prelude
+from tvm.relay.scope_builder import ScopeBuilder
from tvm.relay.testing import mlp
-from tvm.relay.dataflow_pattern import wildcard, is_op
-from tvm.relay.backend.vm import VMCompiler
+from tvm.relay.transform import InferType
def check_result(target, dev, args, expected_result, mod):
@@ -862,7 +860,7 @@ def prepare_vm_model(path, tensor_shape):
vm_exec = vm.compile(mod, target=target)
# Export to Disk
- vm_exec.export_library(path)
+ vm_exec.mod.export_library(path)
def test_vm_rpc():
@@ -1393,7 +1391,7 @@ def test_large_constants():
path_consts = temp.relpath("consts")
vm_exec.move_late_bound_consts(path_consts, byte_limit=256)
path_dso = temp.relpath("lib.so")
- vm_exec.export_library(path_dso)
+ vm_exec.mod.export_library(path_dso)
# Load library files and constants
mod = runtime.load_module(path_dso)
@@ -1442,7 +1440,7 @@ def
test_load_late_bound_consts_with_no_late_bound_consts():
# Ensure const_data is below the byte threshold for a late-bound const.
byte_limit = len(const_data.tobytes()) + 1
vm_exec.move_late_bound_consts(path_consts, byte_limit=byte_limit)
- vm_exec.export_library(path_dso)
+ vm_exec.mod.export_library(path_dso)
mod = runtime.load_module(path_dso)
mod["load_late_bound_consts"](path_consts)
@@ -1503,7 +1501,7 @@ def test_load_and_save_constants_via_map():
# Save to constants and library files
temp = utils.tempdir()
path_dso = temp.relpath("lib.so")
- vm_exec.export_library(path_dso)
+ vm_exec.mod.export_library(path_dso)
# Load library files and constants
mod = runtime.load_module(path_dso)
@@ -1551,7 +1549,7 @@ def
test_load_late_bound_consts_via_map_with_no_late_bound_consts():
# Ensure const_data is below the byte threshold for a late-bound const.
byte_limit = len(const_data.tobytes()) + 1
consts_map = vm_exec.get_late_bound_consts(byte_limit=byte_limit)
- vm_exec.export_library(path_dso)
+ vm_exec.mod.export_library(path_dso)
mod = runtime.load_module(path_dso)
mod["load_late_bound_consts_from_map"](consts_map)
diff --git a/tests/scripts/task_python_integration.sh
b/tests/scripts/task_python_integration.sh
index a19752ca16..8852898986 100755
--- a/tests/scripts/task_python_integration.sh
+++ b/tests/scripts/task_python_integration.sh
@@ -61,7 +61,7 @@ run_pytest cython
${TVM_INTEGRATION_TESTSUITE_NAME}-dso_plugin_module-1 apps/dso
run_pytest ctypes ${TVM_INTEGRATION_TESTSUITE_NAME}-integration
tests/python/integration
# Ignoring Arm(R) Ethos(TM)-U NPU tests in the collective to run to run them
in parallel in the next step.
-run_pytest ctypes ${TVM_INTEGRATION_TESTSUITE_NAME}-contrib
tests/python/contrib --ignore=tests/python/contrib/test_ethosu
--ignore=tests/python/contrib/test_cmsisnn
+run_pytest ctypes ${TVM_INTEGRATION_TESTSUITE_NAME}-contrib
tests/python/contrib --ignore=tests/python/contrib/test_ethosu
--ignore=tests/python/contrib/test_cmsisnn
--ignore=tests/python/contrib/test_msc
# forked is needed because the global registry gets contaminated
TVM_TEST_TARGETS="${TVM_RELAY_TEST_TARGETS:-llvm;cuda}" \
run_pytest ctypes ${TVM_INTEGRATION_TESTSUITE_NAME}-relay
tests/python/relay --ignore=tests/python/relay/aot