MCPcopy Create free account
hub / github.com/apache/tvm / attr

Function attr

python/tvm/tirx/script/builder/ir.py:1595–1645  ·  view source on GitHub ↗

Create an attribute node, or multiple attribute nodes from a dict. Usage 1 — single attr:: with T.attr(node, key, value): ... Usage 2 — dict sugar (node defaults to ``T.int32(0)``):: with T.attr({"key1": value1, "key2": value2}): ... Parameter

(
    node_or_dict: Any, attr_key: str | None = None, value: PrimExpr | str | None = None
)

Source from the content-addressed store, hash-verified

1593
1594
1595def attr(
1596 node_or_dict: Any, attr_key: str | None = None, value: PrimExpr | str | None = None
1597) -> Union[frame.AttrFrame, "utils._FrameScope"]:
1598 """Create an attribute node, or multiple attribute nodes from a dict.
1599
1600 Usage 1 — single attr::
1601
1602 with T.attr(node, key, value):
1603 ...
1604
1605 Usage 2 — dict sugar (node defaults to ``T.int32(0)``)::
1606
1607 with T.attr({"key1": value1, "key2": value2}):
1608 ...
1609
1610 Parameters
1611 ----------
1612 node_or_dict : Any
1613 If a dict, each key-value pair becomes an AttrStmt with
1614 ``node=T.int32(0)``. Otherwise the node to annotate.
1615
1616 attr_key : str, optional
1617 Attribute type key (required when ``node_or_dict`` is not a dict).
1618
1619 value : Union[PrimExpr, str], optional
1620 The attribute value (required when ``node_or_dict`` is not a dict).
1621
1622 Returns
1623 -------
1624 res : Union[frame.AttrFrame, _FrameScope]
1625 A single AttrFrame, or a _FrameScope wrapping multiple AttrFrames.
1626 """
1627 if isinstance(node_or_dict, dict):
1628 frames = []
1629 for k, v in node_or_dict.items():
1630 if isinstance(v, bool):
1631 v = IntImm("bool", v)
1632 frames.append(
1633 _ffi_api.Attr( # type: ignore[attr-defined]
1634 convert(IntImm("int32", 0)), k, convert(v)
1635 )
1636 )
1637 if len(frames) == 1:
1638 return frames[0]
1639 return utils._FrameScope(frames)
1640 else:
1641 if attr_key is None or value is None:
1642 raise ValueError("T.attr(node, attr_key, value) requires all three arguments")
1643 node_or_dict = convert(node_or_dict)
1644 value = convert(value)
1645 return _ffi_api.Attr(node_or_dict, attr_key, value) # type: ignore[attr-defined] # pylint: disable=no-member
1646
1647
1648def hint(message: str = "", **attrs) -> frame.HintFrame:

Callers

nothing calls this directly

Calls 4

IntImmClass · 0.90
convertFunction · 0.50
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…