There was some discussion here about how properties might impact the Python bindings.
The wider issues might be better suited for this forum, as the PR seems to be independent of that question.
I’ve not been actively involved in the properties work, so I’ve been reading up.
Context I’ve been pointed to includes:
- MLIR Open Meeting: Properties design discussion and next steps
- MLIR Open Meeting: Properties design discussion and next steps
- [MLIR] Properties migration todo-list · Issue #155475 · llvm/llvm-project · GitHub
There’s specific mention of the bindings here.
I’ll try and keep the discussion here focused on the bindings, and not the wider properties discussion, though some things might overlap.
I’ll put forth a few assumptions I have:
- The generic attributes dict is currently the main way that people are accessing both discardable attributes and inherent properties.
- There is a
getDiscardableAttrDictionary()method onOperationthat returns a dictionary of discardable attributes. - There is a
getInherentAttr()method onOperationthat returns a given inherent attributes. At time of writing this is fetched by a StringRef name. - The method
getAttrDictionary()would return a union of both discardable and inherent attributes. - I view that a property will have a name, and it would be an MLIR Attribute type.
Currently, the Python bindings expose the generic attributes dict via op.attributes, which has both discardable attrs and inherent properties.
Some questions (will raise more as I think of them):
- Will a property dict always exist?
Almost: inherent properties aren’t necessarily a dictionary, it can be anything: it’s “raw C++” and may not offer a key-value pair easy access.
I rather see the bindings reflecting the split that was introduced two years ago in the core C++ APIs when accessing discardable attributes separately from inherent ones.
The Python bindings use the C API so I don’t see how we can support arbitrary “raw C++”.
[mlir][python] add dict-style to IR attributes by Wheest · Pull Request #163200 · llvm/llvm-project · GitHub
These three comments suggest there could be a problem or ambiguity with the inherent properties?
Discussion on this discourse commnet suggests that properties might not always be representable as a dictionary.
Does that mean that the assumption that there will always be a name and an attribute type might not hold?
- It could be in future that the
getAttrDictionary()method would be deprecated?
If that happens, the Python bindings could kick the can down the road by generating the union itself?
In the near-term, exposing getDiscardableAttrDictionary() might be a way to start that transition, e.g., with op.discardable_attributes.
If properties are guaranteed to be MLIR Attribute types, and have a name, then we could also expose op.inherent_properties as a dict-like object too.
- Properties might not always use the limited set of attribute types that attr-dicts currently
inherent properties aren’t necessarily a dictionary, it can be anything: it’s “raw C++” and may not offer a key-value pair easy access.
Also, this issue mentions C-bindings generated from ODS for properties.
In this case, how would a generic form op work? If I’ve got some unregistered dialect, but its properties are using something not representable using one of the attribute types?
Alternatively, for a performance cost, we could expose setPropertyFromAttr() and the like and have the Python and C users just construct the attributes corresponding to non-attribute properties.
From the Python side, I don’t think performance is of high concern. I’m unsure what other users of the C bindings are.