Skip to content

Commit ff3a8d0

Browse files
authored
Provide well-formed TIR in AttachMetadataWithMemoryUsage (#254)
The `"global_symbol"` attribute, provided by default from the `BlockBuilder.function` method, must match the name of the `GlobalVar` used in the `IRModule`.
1 parent 2a1d261 commit ff3a8d0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

python/mlc_llm/compiler_pass/estimate_memory_usage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def __init__(self, metadata: Dict[str, Any]):
2121

2222
def transform_module(self, mod: IRModule, _ctx: tvm.transform.PassContext) -> IRModule:
2323
"""Entrypoint"""
24+
mod = mod.clone()
2425

2526
def _emit_metadata(metadata):
2627
bb = relax.BlockBuilder() # pylint: disable=invalid-name
27-
with bb.function("main", params=[]):
28+
with bb.function("_metadata", params=[]):
2829
bb.emit_func_output(relax.StringImm(json.dumps(metadata)))
29-
return bb.finalize()["main"]
30+
return bb.finalize()["_metadata"]
3031

3132
self.metadata["memory_usage"] = _MemoryEstimator().run(mod)
3233
mod["_metadata"] = _emit_metadata(self.metadata)

0 commit comments

Comments
 (0)