cxx122 opened a new issue, #15197:
URL: https://github.com/apache/tvm/issues/15197

   The te programs before schedule optimizations didn't report any problems. 
But after the schedule optimization, it will report the error message "`Check 
failed: (!use_count_.count(v)) is false: variable i1.outer.inner has been used 
before definition!`"
   
   ```
   def te_test():
       T_softmax_exp = te.placeholder([1, 16, 256, 256], name='T_softmax_exp')
       k = te.reduce_axis([0, 16], name='k')
       T_softmax_expsum = te.compute([1, 256, 256], lambda i0, i1, i2 : 
te.sum(T_softmax_exp[i0, k, i1, i2], axis=[k]), name='T_softmax_expsum')
       inline_tensor = te.compute([1, 256, 256], lambda ax0, ax1, ax2 : 
tir.acos(T_softmax_expsum[ax0, ax1, ax2]), name='inline_tensor')
       T_softmax_norm = te.compute([1, 16, 256, 256], lambda i0, i1, i2, i3 : 
(inline_tensor[i0, i1, i2]/T_softmax_expsum[i0, i2, i3]), name='T_softmax_norm')
       return [T_softmax_exp, T_softmax_norm]
   ```
   
   ### Expected behavior
   
   There is no error message after the schedule optimization.
   
   ### Actual behavior
   
   `Check failed: (!use_count_.count(v)) is false: variable i1.inner has been 
used before definition!`
   
   ### Environment
   
   Operating System: Ubuntu 18.04
   TVM version: v0.10.dev0
   
   ### Steps to reproduce
   
   ```
   import tvm
   import json
   import random
   import numpy as np
   from tvm import te
   from tvm import tir
   from tvm import testing
   from tvm import auto_scheduler
   from tvm.auto_scheduler.workload_registry import register_workload_tensors
   
   POLICY_PARAMS = {
       "eps_greedy": 0.05,
       "retry_search_one_round_on_empty": 1,
       "sample_init_min_population": 3,
       "sample_init_use_measured_ratio": 0.2,
       "evolutionary_search_population": 5,
       "evolutionary_search_num_iters": 4,
       "evolutionary_search_mutation_prob": 0.85,
       "cpu_multi_level_tiling_structure": "SSRSRS",
       "gpu_multi_level_tiling_structure": "SSSRRSRS",
       # Notice: the default thread bind policy of GPU assumes the tiling 
structure to have at
       # least 3 spatial tiling levels in outermost
       "max_innermost_split_factor": 64,
       "max_vectorize_size": 16,
       "disable_change_compute_location": 0,
   } 
   
   def te_test():
       T_softmax_exp = te.placeholder([1, 16, 256, 256], name='T_softmax_exp')
       k = te.reduce_axis([0, 16], name='k')
       T_softmax_expsum = te.compute([1, 256, 256], lambda i0, i1, i2 : 
te.sum(T_softmax_exp[i0, k, i1, i2], axis=[k]), name='T_softmax_expsum')
       inline_tensor = te.compute([1, 256, 256], lambda ax0, ax1, ax2 : 
tir.acos(T_softmax_expsum[ax0, ax1, ax2]), name='inline_tensor')
       T_softmax_norm = te.compute([1, 16, 256, 256], lambda i0, i1, i2, i3 : 
(inline_tensor[i0, i1, i2]/T_softmax_expsum[i0, i2, i3]), name='T_softmax_norm')
       return [T_softmax_exp, T_softmax_norm]
   
   # Get dag and print it.
   
   tensors = te_test()
   dag = auto_scheduler.ComputeDAG(tensors)
   dict = json.loads(tvm.ir.save_json(tensors))
   with open("./saved_json.txt", "w") as file:
       file.write(tvm.ir.save_json(tensors))
   print(dag)
   
   # Get inputs.
   
   inputs = []
   for tensor in dag.tensors:
       shape = [x.value if 'value' in dir(x) and isinstance(x.value, int) else 
1 for x in tensor.shape]
       inputs.append((2 * np.random.uniform(size=shape)+1).astype(tensor.dtype))
   
   # Get program with no schedule.
   
   results = []
   mod_list = []
   pre_schedule_list = dag.apply_steps_from_state(dag.get_init_state())
   pre_mod = tvm.lower(pre_schedule_list[0], pre_schedule_list[1], 
simple_mode=True)
   mod_list.append(pre_mod)
   with tvm.transform.PassContext(opt_level=0):
       mod_exec = tvm.build(pre_mod)
       print(pre_mod)
   
   new_inputs = [tvm.nd.array(x, tvm.cpu()) for x in inputs.copy()]
   mod_exec(*new_inputs)
   result = []
   for x in new_inputs:
       try:
           result.append(x.numpy() if isinstance(
               x, tvm.runtime.NDArray) else x)
       except (ValueError, tvm.TVMError):
           result.append(None)
   results.append(result)
   
   # Get program with schedule.
   
   register_workload_tensors(dag.workload_key(), tensors)
   task = auto_scheduler.SearchTask(workload_key=dag.workload_key(), 
target=tvm.target.Target("llvm"))
   policy = auto_scheduler.SketchPolicy(task, verbose=0, params=POLICY_PARAMS)
   states = policy.sample_initial_population()
   
   for state in states:
       schedule_list = dag.apply_steps_from_state(state)
       mod = tvm.lower(schedule_list[0], schedule_list[1], simple_mode=True)
       print(mod)
       mod_list.append(mod)
       with tvm.transform.PassContext(opt_level=0):
           mod_exec = tvm.build(mod)
       
       new_inputs = [tvm.nd.array(x, tvm.cpu()) for x in inputs.copy()]
       mod_exec(*new_inputs)
       result = []
       for x in new_inputs:
           try:
               result.append(x.numpy() if isinstance(
                   x, tvm.runtime.NDArray) else x)
           except (ValueError, tvm.TVMError):
               result.append(None)
       results.append(result)
   ```
   
   ### Triage
   
   * tune:auto_scheduler
   * tir:schedule 
   * tir:transform      


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to