This is an archive of the discontinued LLVM Phabricator instance.

[Printing] Add flag to not print resources.
ClosedPublic

Authored by AndrewZhaoLuo on Aug 14 2023, 3:32 PM.

Details

Summary

Often times, large weights for ML models will be stored as resources in MLIR. It is sometimes advantageous to control whether to print these resources for debugging purposes. For example, some models contain very big weights with millions of characters in printed size, which may slow down whatever text editor you are using.

This diff adds a flag which allows users to disable printing resources in these scenarios.

Diff Detail

Event Timeline

AndrewZhaoLuo created this revision.Aug 14 2023, 3:32 PM
Herald added a project: Restricted Project. · View Herald Transcript
AndrewZhaoLuo requested review of this revision.Aug 14 2023, 3:32 PM
AndrewZhaoLuo edited the summary of this revision. (Show Details)Aug 14 2023, 3:33 PM
Mogball added inline comments.
mlir/test/IR/pretty-resources-print.mlir
16

You could just have the resource references be dropped entirely. They are not required to be present in the IR.

AndrewZhaoLuo added inline comments.Aug 16 2023, 5:07 PM
mlir/test/IR/pretty-resources-print.mlir
16

If you feel super strongly about this I can do this. My thought around this was:

  1. didn't know you could drop the resources
  2. wanted to keep printing as close as possible to original text as possible
Mogball added inline comments.Aug 16 2023, 11:49 PM
mlir/test/IR/pretty-resources-print.mlir
16

Dropping them would make more sense to me.

AndrewZhaoLuo added inline comments.Aug 17 2023, 10:28 AM
mlir/test/IR/pretty-resources-print.mlir
16

IMO it may be sometimes helpful to have them anyway.

For example, you might store small "things" in resources which might want to know the values of for debugging.

See the use of "true" in the test which is not elided.

Mogball added inline comments.Aug 17 2023, 10:47 AM
mlir/test/IR/pretty-resources-print.mlir
16

I'm not suggesting that all resources be dropped, but that instead of replacing them with a garbage value that the elided ones be completely dropped from the IR. All resource references are potentially nullable which means this keeps the IR valid and roundtrippable.

AndrewZhaoLuo added inline comments.
mlir/test/IR/pretty-resources-print.mlir
16

Ah I see, I think that does make sense and is better. I guess the only argument against is it may be helpful to know what resources were defined in the original IR.

I have made your suggested changes.

Mogball added inline comments.Aug 17 2023, 1:57 PM
mlir/lib/IR/AsmPrinter.cpp
3193

As a minor optimization, can you skip the string buffer if charLimit is not defined?

Add path to not use string buffer if flag not there

AndrewZhaoLuo marked an inline comment as done.Aug 21 2023, 10:16 AM

Done

Mogball accepted this revision.Aug 21 2023, 10:28 AM
This revision is now accepted and ready to land.Aug 21 2023, 10:28 AM
This revision was automatically updated to reflect the committed changes.
jpienaar added inline comments.
mlir/lib/IR/AsmPrinter.cpp
3105

Why was this change needed?

AndrewZhaoLuo added inline comments.Aug 23 2023, 10:06 AM
mlir/lib/IR/AsmPrinter.cpp
3105

The old implementation didn't used the passed in ostream.

printEscapedString isn't in ostream so I just manually do the equivalent here.

Mogball added inline comments.Aug 23 2023, 10:06 AM
mlir/lib/IR/AsmPrinter.cpp
3105

printEscapedString does more than just wrap in quotes

AndrewZhaoLuo added inline comments.Aug 23 2023, 10:13 AM
mlir/lib/IR/AsmPrinter.cpp
3105

Ah darn you are right. Probably glossed it over. I'll fix and add a test later.

https://github.com/llvm/llvm-project/blob/8a779174134d7d01c6835cb0254b8a6dbf419150/mlir/lib/IR/AsmPrinter.cpp#L2673
AndrewZhaoLuo added inline comments.Aug 23 2023, 9:41 PM
mlir/lib/IR/AsmPrinter.cpp
3105

https://reviews.llvm.org/D158700 Fix. Sorry about that.