[Hybrid script]Check failed: allow_alloc == false: Cannot find the Realization point of tensor Tensor(shape=[1, 6, 14, 14], op.name=PaddedData)

I’m a beginner and am learning hybrid tutorial,so I want to implement a conv2d using tvm.te.hybrid.script.Here is my snippet:

import tvm
from tvm import te
from tvm.te.hybrid import script
import numpy as np
@script
def Conv2D(data,conv1_weight):
  #s=0.000000
  PaddedData = output_tensor((1,6,14,14),"float32")
  conv1 = output_tensor((1,4,12,12),"float32")
  for n in range(1):
    for i0 in range(6):
      for i1 in range(14):
        for i2 in range(14):
          PaddedData[n,i0,i1,i2] = 0.000000 if i1<1 or 1+12<=i1 or i2<1 or 1+12<=i2 else data[n,i0,i1-1,i2-1]
  for n in range(1):
    for c in range(4):
      for i in range(12):
        for j in range(12):
          conv1[n,c,i,j] = 0.000000
          for ric in range(6):
            for rkh in range(3):
              for rkw in range(3):
                #s = 0.000000 if i+rkh<1 or 1+12<=i+rkh or j+rkw<1 or 1+12<=j+rkw else data[n,ric,i+rkh-1,j+rkw-1]
                #conv1[n,c,i,j] = conv1[n,c,i,j]+ s*conv1_weight[c,ric,rkh,rkw]
                conv1[n,c,i,j] = conv1[n,c,i,j]+ PaddedData[n,ric,i*1+rkh,j*1+rkw]*conv1_weight[c,ric,rkh,rkw]
  return conv1
data = te.placeholder(shape=(1,6,12,12),name="data",dtype="float32")
conv1_weight = te.placeholder(shape=(4,6,3,3),name="conv1_weight",dtype="float32")
res = Conv2D(data,conv1_weight)
sch = te.create_schedule(res.op)
mod = tvm.build(sch,(data,conv1_weight,res))

conv2d parameters : data[1,6,12,12] conv1_weight[4,6,3,3] with stride=1 and padding=1 My implementation is firstly implementing PaddedData part then conv1 part,but an error occured as below:

CRITICAL:root:[Warning] Not all the output buffers returned!
Traceback (most recent call last):
  File "conv2d.py", line 31, in <module>
    mod = tvm.build(sch,(data,conv1_weight,res))
  File "/home/sun/gitDownload/tvm/python/tvm/driver/build_module.py", line 375, in build
    input_mod = lower(inputs, args, name=name, binds=binds)
  File "/home/sun/gitDownload/tvm/python/tvm/driver/build_module.py", line 164, in lower
    mod = form_irmodule(sch, args, name, binds)
  File "/home/sun/gitDownload/tvm/python/tvm/driver/build_module.py", line 113, in form_irmodule
    func = schedule.SchedulePostProcToPrimFunc(arg_list, stmt, binds)
  File "tvm/_ffi/_cython/./packed_func.pxi", line 322, in tvm._ffi._cy3.core.PackedFuncBase.__call__
  File "tvm/_ffi/_cython/./packed_func.pxi", line 257, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./packed_func.pxi", line 246, in tvm._ffi._cy3.core.FuncCall3
  File "tvm/_ffi/_cython/./base.pxi", line 160, in tvm._ffi._cy3.core.CALL
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::VisitStmt(tvm::tir::Stmt const&)+0x85) [0x7fd727597015]
  [bt] (7) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)#4}::_FUN(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)+0x27) [0x7fd72758c467]
  [bt] (6) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtMutator::VisitStmt_(tvm::tir::ForNode const*)+0x5e) [0x7fd727a2df4e]
  [bt] (5) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtMutator::VisitStmt(tvm::tir::Stmt const&)+0x7b) [0x7fd727598cbb]
  [bt] (4) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::VisitStmt(tvm::tir::Stmt const&)+0x85) [0x7fd727597015]
  [bt] (3) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)#8}::_FUN(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)+0x27) [0x7fd72758c5a7]
  [bt] (2) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::te::TensorToBufferMapper::VisitStmt_(tvm::tir::ProducerStoreNode const*)+0x6e) [0x7fd7279b912e]
  [bt] (1) /home/sun/gitDownload/tvm/build/libtvm.so(tvm::te::TensorToBufferMapper::GetBuffer(tvm::te::Tensor const&, bool)+0x142) [0x7fd7279b7c22]
  [bt] (0) /home/sun/gitDownload/tvm/build/libtvm.so(+0x1081342) [0x7fd7279b4342]
  File "/home/sun/gitDownload/tvm/src/te/schedule/schedule_postproc_to_primfunc.cc", line 131
TVMError: 
---------------------------------------------------------------
An internal invariant was violated during the execution of TVM.
Please read TVM's error reporting guidelines.
More details can be found here: https://discuss.tvm.ai/t/error-reporting/7793.
---------------------------------------------------------------
  Check failed: allow_alloc == false: Cannot find the Realization point of tensor Tensor(shape=[1, 6, 14, 14], op.name=PaddedData)

I guess it must be something wrong with my code.If i inline PaddedData into conv1 part manually ,it would run normally.

how to do it correactly and any tips to write hybrid.scipt python function besides tutorials? Thanks a lot!

This error message is telling you the problem. Because PaddedData is an output_tensor, it needs to be returned from the function. Alternatively, you can use allocate to create an intermediate buffer. You can look at tests/python/unittest/test_te_hybrid_script.py for examples.