-
Notifications
You must be signed in to change notification settings - Fork 507
Is there a way to attach metadata to a layer in a way that is included in the StableHLO export? #8993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you be more specific on why you would want to do that? I don't think StableHLO preserves that kind of metadata for each @qihqi @lsy323 @tengyifei Any thoughts? |
My specific use case is to include, in the exported IR, an empirical distribution of individual layer outputs (think range bounds), and then have a downstream compiler use them for optimizations. An trivial example model might look like
And the exported stableHLO is something like
And I'd want the custom metadata to be attached to op's that correspond to layer outputs. E.g. (the last two lines of)
I know that MLIR can support adding arbitrary attributes to ops without having to modify the op definition, and I can probably ensure those attributes are preserved by downstream passes in Otherwise, the alternative is side-loading the attributes in MLIR, which is difficult for the reason mentioned above: the exported stablehlo does not preserve the node names as far as I can tell. So if we could also just export node names as attributes, that would probably suffice. |
Right. I don't think there's a way to straight-forwardly add this kind of metadata to the StableHLO we generate. But, I'm not super familiar with it. Maybe @tengyifei @qihqi @lsy323 could clarify a bit more. |
❓ Questions and Help
I am looking at a use case where metadata about a trained model's layers needs to be attached to the StableHLO export. I am using
exported_program_to_stablehlo
One option I had considered is exporting the data completely separately from
exported_program_to_stablehlo
(say, by writing some random json to disk), but then I don't know how to connect the written metadata back to the stableHLO export, because the layer names do not appear to be attached to the generated StableHLO ops such.Another option I tried was to attach the metadata directly to the torch nodes before calling
exported_program_to_stablehlo
, but I can't figure out how to do so in a way that results in the metadata being exported as MLIR attributes. It would suffice to export the attributes as, e.g., an op attribute with a given string name and value.Could someone advise on whether this is possible, or suggest an alternative? (Or add a feature that would support this?)
The text was updated successfully, but these errors were encountered: