Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/tvm/script/parser/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def inspect_function_capture(func: Callable) -> Dict[str, Any]:
The function variables map with non-local or global variables.
"""
captured = {
**inspect.getclosurevars(func).nonlocals,
**func.__globals__, # type: ignore
**inspect.getclosurevars(func).nonlocals,
}
return captured

Expand Down
17 changes: 17 additions & 0 deletions tests/python/unittest/test_tvmscript_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,24 @@ def func_ref():
tvm.ir.assert_structural_equal(test_case, func_ref)


def test_var_capturing_order():
b = 2

@T.prim_func
def test_case():
k: T.int32 = b

@T.prim_func
def func_ref():
k: T.int32 = 2
T.evaluate(0)

tvm.ir.assert_structural_equal(test_case, func_ref)


if __name__ == "__main__":
a = numpy.zeros((10, 10), dtype="int8")
test_multi_element_array_in_outmost_namespace()
test_different_dtype_assignment_to_var()
b = 1
test_var_capturing_order()