@yuchenj ,here is my code example. I wanna run dynamic batch of customer model on gpu.
It seems like MetaSchedule can’t tune on dynmiac tasks.
from __future__ import annotations # must import to defer parsing of annotations
import numpy as np
import tvm
from tvm import relax, tir
from tvm.relax.testing import nn
import tempfile
from tvm import meta_schedule as ms
builder = relax.BlockBuilder()
input_size = 784
hidden_sizes = [128, 64]
output_size = 10
target = tvm.target.Target(
"cuda --host=llvm --max_threads_per_block=1024 --max_shared_memory_per_block=49152")
database = ms.database.MemoryDatabase()
with builder.function(name="main"):
model = nn.Sequential(
nn.Linear(input_size, hidden_sizes[0]),
nn.ReLU(),
nn.Linear(hidden_sizes[0], hidden_sizes[1]),
nn.ReLU(),
nn.Linear(hidden_sizes[1], output_size),
nn.LogSoftmax(),
)
# n is a symbolic variable to represent a dynamic batch size
n = tir.Var("n", "int64")
data = nn.Placeholder((n, input_size), name="data")
output = model(data)
params = [data] + model.parameters()
builder.emit_func_output(output, params=params)
mod = builder.get()
with tempfile.TemporaryDirectory() as work_dir:
db = ms.relax_integration.tune_relax(
mod=mod,
target=target,
params=None,
num_trials_per_iter=2,
max_trials_per_task=4,
max_trials_global=4,
work_dir=work_dir,
database=database,
)
relax_ex = ms.relax_integration.compile_relax(
db, mod=mod, target=target, params=None)
vm = relax.VirtualMachine(relax_ex, tvm.cuda())
params = nn.init_params(mod)
# init parameters
# the input data has a minibatch size of 3
data = tvm.nd.array(np.random.rand(3, input_size).astype(np.float32))
res = vm["main"](data, *params)
I got error like below:
2: tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>*)#4}::_FUN(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>*)
at /home/lei.zhang/src_code/cmccperf/relax/include/tvm/tir/stmt_functor.h:115
1: tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>*)#4}::operator()(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::TResult (tvm::tir::Stmt const&)>*) const
at /home/lei.zhang/src_code/cmccperf/relax/include/tvm/tir/stmt_functor.h:115
0: tvm::tir::FlopEstimator::VisitStmt_(tvm::tir::ForNode const*)
at /home/lei.zhang/src_code/cmccperf/relax/src/tir/analysis/estimate_flops.cc:143
File "/home/lei.zhang/src_code/cmccperf/relax/src/tir/analysis/estimate_flops.cc", line 143
TVMError:
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
Check failed: (int_imm) is false: TypeError: Expect the extent of a loop to be IntImm, but gets: tir.Var
Does that need dietcode to tune task for dynamic? And when will it be integrated in TVM?