We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Bugfix] Disable SingleEnvThreadVerifier
During TensorIR scheduling, the `IterVar`s that represent environment threads may duplicate, i.e. it is legal to have two env threads with the same name tag, which may fail the `SingleEnvThreadVerifier` check during schedule creation. This PR disables this check in this case. In the future, it may be worthwhile to bring it back against post-scheduling TIR.

It's related to [this commit](https://github.com/apache/tvm/commit/eb15d04c3bff76062e26d5647fb8af0323de1bed). CC: @jinhongyii @Lunderberg 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/tvm/relax/backend/dispatch_sort_scan.py`
Content:
```
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements.  See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership.  The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License.  You may obtain a copy of the License at
8 #
9 #   http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied.  See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17 # pylint: disable=invalid-name, unused-argument, redefined-argument-from-local
18 """Dispatch sort and scan operators to platform dependent implementation."""
19 
20 from tvm import topi, dlight, relax
21 from tvm.ir import Op
22 from tvm.ir.module import IRModule
23 from tvm.ir.transform import PassContext, module_pass
24 from tvm.target import Target
25 from tvm.contrib.thrust import can_use_thrust
26 from tvm.relax import PyExprMutator, expr_functor
27 
28 
29 @expr_functor.mutator
30 class SortScanDispatcher(PyExprMutator):
31     """
32     Dispatcher to dispatch sort and scan.
33 
34     """
35 
36     def __init__(self, mod):
37         super().__init__(mod)
38 
39     def _get_target(self, sinfo: relax.StructInfo) -> Target:
40         # Get target information from TensorStructInfo
41         if isinstance(sinfo, relax.TensorStructInfo):
42             vdevice = sinfo.vdevice
43             if vdevice is not None:
44                 return vdevice.target
45         elif isinstance(sinfo, relax.TupleStructInfo):
46             for f in sinfo.fields:
47                 tgt = self._get_target(f)
48                 if tgt != Target.current():
49                     return tgt
50         # Return the target in current context
51         target = Target.current()
52         if target is None:
53             raise ValueError(
54                 "Target not found. Please ensure that the target is annotated within the module, "
55                 "or alternatively, execute this within a specified target context."
56             )
57         return target
58 
59     def _apply_dlight_gpu_fallback(self, target: Target, tir_call: relax.Call) -> None:
60         # Apply dlight.gpu.Fallback() on GPU
61         gvar = tir_call.args[0]
62         assert isinstance(gvar, relax.GlobalVar)
63         scan_prim_func = self.builder_.get()[gvar]
64         sch = dlight.base.transform._apply_rules(
65             scan_prim_func,
66             target,
67             [
68                 dlight.gpu.Fallback(),
69             ],
70             False,
71         )
72         if sch is not None:
73             assert len(sch) == 1
74             self.builder_.update_func(gvar, sch[0].mod["main"].with_attr("tir.is_scheduled", 1))
75 
76     def visit_call_(self, call: relax.Call) -> relax.Expr:
77         if not isinstance(call.op, Op):
78             return super().visit_call_(call)
79 
80         if call.op.name == "relax.sort":
81             tgt = self._get_target(call.struct_info)
82             te_func = topi.sort
83             with tgt:
84                 if can_use_thrust(tgt, "tvm.contrib.thrust.sort"):
85                     te_func = topi.cuda.sort_thrust
86                 elif tgt.kind.name == "cuda":
87                     te_func = topi.cuda.sort
88             return self.builder_.call_te(
89                 te_func,
90                 call.args[0],
91                 call.attrs.axis,
92                 not call.attrs.descending,
93             )
94         if call.op.name == "relax.argsort":
95             tgt = self._get_target(call.struct_info)
96             te_func = topi.argsort
97             with tgt:
98                 if can_use_thrust(tgt, "tvm.contrib.thrust.sort"):
99                     te_func = topi.cuda.argsort_thrust
100                 elif tgt.kind.name == "cuda":
101                     te_func = topi.cuda.argsort
102             return self.builder_.call_te(
103                 te_func,
104                 call.args[0],
105                 axis=call.attrs.axis,
106                 is_ascend=not call.attrs.descending,
107                 dtype=call.attrs.dtype,
108             )
109         if call.op.name == "relax.topk":
110             tgt = self._get_target(call.struct_info)
111             te_func = topi.topk
112             if can_use_thrust(tgt, "tvm.contrib.thrust.sort"):
113                 te_func = topi.cuda.topk_thrust
114             elif tgt.kind.name == "cuda":
115                 te_func = topi.cuda.topk
116             tir_call = self.builder_.call_te(
117                 te_func,
118                 call.args[0],
119                 axis=call.attrs.axis,
120                 ret_type=call.attrs.ret_type,
121                 is_ascend=not call.attrs.largest,
122                 dtype=call.attrs.dtype,
123             )
124             if tgt.kind.name != "cuda":
125                 return tir_call
126             # apply dlight gpu fallback
127             self._apply_dlight_gpu_fallback(tgt, tir_call)
128             return tir_call
129         if call.op.name in ("relax.cumprod", "relax.cumsum"):
130             tgt = self._get_target(call.struct_info)
131             axis = int(call.attrs.axis) if call.attrs.axis is not None else call.attrs.axis
132             te_func = topi.cuda.cumsum if tgt.kind.name == "cuda" else topi.cumsum
133             if call.op.name == "relax.cumprod":
134                 te_func = topi.cuda.cumprod if tgt.kind.name == "cuda" else topi.cumprod
135             tir_call = self.builder_.call_te(
136                 te_func,
137                 call.args[0],
138                 axis,
139                 call.attrs.dtype,
140                 call.attrs.exclusive,
141             )
142             if tgt.kind.name != "cuda":
143                 return tir_call
144             # apply dlight gpu fallback
145             self._apply_dlight_gpu_fallback(tgt, tir_call)
146             return tir_call
147         return super().visit_call_(call)
148 
149 
150 @module_pass(opt_level=0, name="DispatchSortScan")
151 class DispatchSortScan:
152     """
153     Pass to dispatch scan and sort operators to platform dependent implementation.
154     """
155 
156     def transform_module(self, mod: IRModule, ctx: PassContext) -> IRModule:
157         sort_scan_dispater = SortScanDispatcher(mod)
158         for gv, func in mod.functions_items():
159             if isinstance(func, relax.Function):
160                 func = sort_scan_dispater.visit_expr(func)
161                 sort_scan_dispater.builder_.update_func(gv, func)
162         return sort_scan_dispater.builder_.finalize()
163
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/python/tvm/relax/backend/dispatch_sort_scan.py b/python/tvm/relax/backend/dispatch_sort_scan.py
--- a/python/tvm/relax/backend/dispatch_sort_scan.py
+++ b/python/tvm/relax/backend/dispatch_sort_scan.py
@@ -116,6 +116,7 @@
             tir_call = self.builder_.call_te(
                 te_func,
                 call.args[0],
+                k=call.attrs.k,
                 axis=call.attrs.axis,
                 ret_type=call.attrs.ret_type,
                 is_ascend=not call.attrs.largest,

{"golden_diff": "diff --git a/python/tvm/relax/backend/dispatch_sort_scan.py b/python/tvm/relax/backend/dispatch_sort_scan.py\n--- a/python/tvm/relax/backend/dispatch_sort_scan.py\n+++ b/python/tvm/relax/backend/dispatch_sort_scan.py\n@@ -116,6 +116,7 @@\n             tir_call = self.builder_.call_te(\n                 te_func,\n                 call.args[0],\n+                k=call.attrs.k,\n                 axis=call.attrs.axis,\n                 ret_type=call.attrs.ret_type,\n                 is_ascend=not call.attrs.largest,\n", "issue": "[Bugfix] Disable SingleEnvThreadVerifier\nDuring TensorIR scheduling, the `IterVar`s that represent environment threads may duplicate, i.e. it is legal to have two env threads with the same name tag, which may fail the `SingleEnvThreadVerifier` check during schedule creation. This PR disables this check in this case. In the future, it may be worthwhile to bring it back against post-scheduling TIR.\r\n\r\nIt's related to [this commit](https://github.com/apache/tvm/commit/eb15d04c3bff76062e26d5647fb8af0323de1bed). CC: @jinhongyii @Lunderberg \n", "before_files": [{"content": "# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local\n\"\"\"Dispatch sort and scan operators to platform dependent implementation.\"\"\"\n\nfrom tvm import topi, dlight, relax\nfrom tvm.ir import Op\nfrom tvm.ir.module import IRModule\nfrom tvm.ir.transform import PassContext, module_pass\nfrom tvm.target import Target\nfrom tvm.contrib.thrust import can_use_thrust\nfrom tvm.relax import PyExprMutator, expr_functor\n\n\n@expr_functor.mutator\nclass SortScanDispatcher(PyExprMutator):\n    \"\"\"\n    Dispatcher to dispatch sort and scan.\n\n    \"\"\"\n\n    def __init__(self, mod):\n        super().__init__(mod)\n\n    def _get_target(self, sinfo: relax.StructInfo) -> Target:\n        # Get target information from TensorStructInfo\n        if isinstance(sinfo, relax.TensorStructInfo):\n            vdevice = sinfo.vdevice\n            if vdevice is not None:\n                return vdevice.target\n        elif isinstance(sinfo, relax.TupleStructInfo):\n            for f in sinfo.fields:\n                tgt = self._get_target(f)\n                if tgt != Target.current():\n                    return tgt\n        # Return the target in current context\n        target = Target.current()\n        if target is None:\n            raise ValueError(\n                \"Target not found. Please ensure that the target is annotated within the module, \"\n                \"or alternatively, execute this within a specified target context.\"\n            )\n        return target\n\n    def _apply_dlight_gpu_fallback(self, target: Target, tir_call: relax.Call) -> None:\n        # Apply dlight.gpu.Fallback() on GPU\n        gvar = tir_call.args[0]\n        assert isinstance(gvar, relax.GlobalVar)\n        scan_prim_func = self.builder_.get()[gvar]\n        sch = dlight.base.transform._apply_rules(\n            scan_prim_func,\n            target,\n            [\n                dlight.gpu.Fallback(),\n            ],\n            False,\n        )\n        if sch is not None:\n            assert len(sch) == 1\n            self.builder_.update_func(gvar, sch[0].mod[\"main\"].with_attr(\"tir.is_scheduled\", 1))\n\n    def visit_call_(self, call: relax.Call) -> relax.Expr:\n        if not isinstance(call.op, Op):\n            return super().visit_call_(call)\n\n        if call.op.name == \"relax.sort\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.sort\n            with tgt:\n                if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                    te_func = topi.cuda.sort_thrust\n                elif tgt.kind.name == \"cuda\":\n                    te_func = topi.cuda.sort\n            return self.builder_.call_te(\n                te_func,\n                call.args[0],\n                call.attrs.axis,\n                not call.attrs.descending,\n            )\n        if call.op.name == \"relax.argsort\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.argsort\n            with tgt:\n                if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                    te_func = topi.cuda.argsort_thrust\n                elif tgt.kind.name == \"cuda\":\n                    te_func = topi.cuda.argsort\n            return self.builder_.call_te(\n                te_func,\n                call.args[0],\n                axis=call.attrs.axis,\n                is_ascend=not call.attrs.descending,\n                dtype=call.attrs.dtype,\n            )\n        if call.op.name == \"relax.topk\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.topk\n            if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                te_func = topi.cuda.topk_thrust\n            elif tgt.kind.name == \"cuda\":\n                te_func = topi.cuda.topk\n            tir_call = self.builder_.call_te(\n                te_func,\n                call.args[0],\n                axis=call.attrs.axis,\n                ret_type=call.attrs.ret_type,\n                is_ascend=not call.attrs.largest,\n                dtype=call.attrs.dtype,\n            )\n            if tgt.kind.name != \"cuda\":\n                return tir_call\n            # apply dlight gpu fallback\n            self._apply_dlight_gpu_fallback(tgt, tir_call)\n            return tir_call\n        if call.op.name in (\"relax.cumprod\", \"relax.cumsum\"):\n            tgt = self._get_target(call.struct_info)\n            axis = int(call.attrs.axis) if call.attrs.axis is not None else call.attrs.axis\n            te_func = topi.cuda.cumsum if tgt.kind.name == \"cuda\" else topi.cumsum\n            if call.op.name == \"relax.cumprod\":\n                te_func = topi.cuda.cumprod if tgt.kind.name == \"cuda\" else topi.cumprod\n            tir_call = self.builder_.call_te(\n                te_func,\n                call.args[0],\n                axis,\n                call.attrs.dtype,\n                call.attrs.exclusive,\n            )\n            if tgt.kind.name != \"cuda\":\n                return tir_call\n            # apply dlight gpu fallback\n            self._apply_dlight_gpu_fallback(tgt, tir_call)\n            return tir_call\n        return super().visit_call_(call)\n\n\n@module_pass(opt_level=0, name=\"DispatchSortScan\")\nclass DispatchSortScan:\n    \"\"\"\n    Pass to dispatch scan and sort operators to platform dependent implementation.\n    \"\"\"\n\n    def transform_module(self, mod: IRModule, ctx: PassContext) -> IRModule:\n        sort_scan_dispater = SortScanDispatcher(mod)\n        for gv, func in mod.functions_items():\n            if isinstance(func, relax.Function):\n                func = sort_scan_dispater.visit_expr(func)\n                sort_scan_dispater.builder_.update_func(gv, func)\n        return sort_scan_dispater.builder_.finalize()\n", "path": "python/tvm/relax/backend/dispatch_sort_scan.py"}], "after_files": [{"content": "# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n# pylint: disable=invalid-name, unused-argument, redefined-argument-from-local\n\"\"\"Dispatch sort and scan operators to platform dependent implementation.\"\"\"\n\nfrom tvm import topi, dlight, relax\nfrom tvm.ir import Op\nfrom tvm.ir.module import IRModule\nfrom tvm.ir.transform import PassContext, module_pass\nfrom tvm.target import Target\nfrom tvm.contrib.thrust import can_use_thrust\nfrom tvm.relax import PyExprMutator, expr_functor\n\n\n@expr_functor.mutator\nclass SortScanDispatcher(PyExprMutator):\n    \"\"\"\n    Dispatcher to dispatch sort and scan.\n\n    \"\"\"\n\n    def __init__(self, mod):\n        super().__init__(mod)\n\n    def _get_target(self, sinfo: relax.StructInfo) -> Target:\n        # Get target information from TensorStructInfo\n        if isinstance(sinfo, relax.TensorStructInfo):\n            vdevice = sinfo.vdevice\n            if vdevice is not None:\n                return vdevice.target\n        elif isinstance(sinfo, relax.TupleStructInfo):\n            for f in sinfo.fields:\n                tgt = self._get_target(f)\n                if tgt != Target.current():\n                    return tgt\n        # Return the target in current context\n        target = Target.current()\n        if target is None:\n            raise ValueError(\n                \"Target not found. Please ensure that the target is annotated within the module, \"\n                \"or alternatively, execute this within a specified target context.\"\n            )\n        return target\n\n    def _apply_dlight_gpu_fallback(self, target: Target, tir_call: relax.Call) -> None:\n        # Apply dlight.gpu.Fallback() on GPU\n        gvar = tir_call.args[0]\n        assert isinstance(gvar, relax.GlobalVar)\n        scan_prim_func = self.builder_.get()[gvar]\n        sch = dlight.base.transform._apply_rules(\n            scan_prim_func,\n            target,\n            [\n                dlight.gpu.Fallback(),\n            ],\n            False,\n        )\n        if sch is not None:\n            assert len(sch) == 1\n            self.builder_.update_func(gvar, sch[0].mod[\"main\"].with_attr(\"tir.is_scheduled\", 1))\n\n    def visit_call_(self, call: relax.Call) -> relax.Expr:\n        if not isinstance(call.op, Op):\n            return super().visit_call_(call)\n\n        if call.op.name == \"relax.sort\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.sort\n            with tgt:\n                if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                    te_func = topi.cuda.sort_thrust\n                elif tgt.kind.name == \"cuda\":\n                    te_func = topi.cuda.sort\n            return self.builder_.call_te(\n                te_func,\n                call.args[0],\n                call.attrs.axis,\n                not call.attrs.descending,\n            )\n        if call.op.name == \"relax.argsort\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.argsort\n            with tgt:\n                if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                    te_func = topi.cuda.argsort_thrust\n                elif tgt.kind.name == \"cuda\":\n                    te_func = topi.cuda.argsort\n            return self.builder_.call_te(\n                te_func,\n                call.args[0],\n                axis=call.attrs.axis,\n                is_ascend=not call.attrs.descending,\n                dtype=call.attrs.dtype,\n            )\n        if call.op.name == \"relax.topk\":\n            tgt = self._get_target(call.struct_info)\n            te_func = topi.topk\n            if can_use_thrust(tgt, \"tvm.contrib.thrust.sort\"):\n                te_func = topi.cuda.topk_thrust\n            elif tgt.kind.name == \"cuda\":\n                te_func = topi.cuda.topk\n            tir_call = self.builder_.call_te(\n                te_func,\n                call.args[0],\n                k=call.attrs.k,\n                axis=call.attrs.axis,\n                ret_type=call.attrs.ret_type,\n                is_ascend=not call.attrs.largest,\n                dtype=call.attrs.dtype,\n            )\n            if tgt.kind.name != \"cuda\":\n                return tir_call\n            # apply dlight gpu fallback\n            self._apply_dlight_gpu_fallback(tgt, tir_call)\n            return tir_call\n        if call.op.name in (\"relax.cumprod\", \"relax.cumsum\"):\n            tgt = self._get_target(call.struct_info)\n            axis = int(call.attrs.axis) if call.attrs.axis is not None else call.attrs.axis\n            te_func = topi.cuda.cumsum if tgt.kind.name == \"cuda\" else topi.cumsum\n            if call.op.name == \"relax.cumprod\":\n                te_func = topi.cuda.cumprod if tgt.kind.name == \"cuda\" else topi.cumprod\n            tir_call = self.builder_.call_te(\n                te_func,\n                call.args[0],\n                axis,\n                call.attrs.dtype,\n                call.attrs.exclusive,\n            )\n            if tgt.kind.name != \"cuda\":\n                return tir_call\n            # apply dlight gpu fallback\n            self._apply_dlight_gpu_fallback(tgt, tir_call)\n            return tir_call\n        return super().visit_call_(call)\n\n\n@module_pass(opt_level=0, name=\"DispatchSortScan\")\nclass DispatchSortScan:\n    \"\"\"\n    Pass to dispatch scan and sort operators to platform dependent implementation.\n    \"\"\"\n\n    def transform_module(self, mod: IRModule, ctx: PassContext) -> IRModule:\n        sort_scan_dispater = SortScanDispatcher(mod)\n        for gv, func in mod.functions_items():\n            if isinstance(func, relax.Function):\n                func = sort_scan_dispater.visit_expr(func)\n                sort_scan_dispater.builder_.update_func(gv, func)\n        return sort_scan_dispater.builder_.finalize()\n", "path": "python/tvm/relax/backend/dispatch_sort_scan.py"}]}