Skip to content

Commit

Permalink
[Bugfix] Remove mutation of IRModule in ReorderTransformFunc (#1760)
Browse files Browse the repository at this point in the history
A pass must not mutate the `IRModule` that it receives as input.
Unlike most functions exposed through the python API, the
`IRModule.__setitem__` method mutates the underlying `IRModuleNode`.
This can impact other users of the shared `IRModule` object, which
expect mutation to be done using copy-on-write.

See apache/tvm#11372 for more details.
  • Loading branch information
Lunderberg authored Feb 14, 2024
1 parent 2d609b1 commit d3b07cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mlc_llm/transform/reorder_transform_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ def __init__(
}

def transform_module(
self, mod: IRModule, ctx: tvm.transform.PassContext
self,
mod: IRModule,
ctx: tvm.transform.PassContext,
) -> IRModule:
mod = mod.clone()
for gv, func in list(mod.functions.items()):
if isinstance(func, relax.Function):
assert gv.name_hint.endswith("transform_params")
Expand Down

0 comments on commit d3b07cb

Please sign in to comment.