Skip to content
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

[DRAFT] Create ModuleCache, load ModuleCache into FB, Use to load FB + Golden Data in Explorer #1882

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vprajapati-tt
Copy link
Contributor

@vprajapati-tt vprajapati-tt commented Jan 17, 2025

  • This is a draft PR to keep track of progress / breaking issues with this larger change.
  • Currently testing with tt-torch frontend, view changes to make this possible there @ https://github.com/tenstorrent/tt-torch/tree/vprajapati/module-cache
  • Currently Implemented:
    • Created the MLIRModuleCacher struct to trigger actions and cache modules.
    • Added ModuleCache to debug_info.fbs so it gets stored there.
  • To-do:
    • Implement loading from FB in Explorer
    • Preserve GoldenData + ModuleCache in Explorer runner
    • Render Explorer graph from ModuleCache @
    • Compare against stored GoldenData when executing model to allow Golden Comparisons
    • Show Accuracy Data using NodeData Overlays.

Copy link
Contributor

@nsmithtt nsmithtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into and discovering this neat way of solving the problem! Minor naming/convention changes, otherwise looks great.

table ModuleCache {
module_cache: [ModuleCacheItem];
}

table DebugInfo {
mlir: MLIR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just turn this field into mlir_stages: [MLIR].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I didn't think to leverage the source property of MLIR as the source pass, but that makes sense.

std::unordered_map<std::string, GoldenTensor> goldenMap = {});
std::shared_ptr<void> ttnnToFlatbuffer(
Operation *op, std::unordered_map<std::string, GoldenTensor> goldenMap = {},
std::vector<std::pair<std::string, std::string>> moduleCache = {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably pass by const&, and update goldenMap to do the same.

passName) != passNamesToCache.end()) {
this->moduleCache.emplace_back(passName, outString);
} else if (passNamesToCache.empty()) {
this->moduleCache.emplace_back(passName, outString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's restructure this, because printing the IR is relatively expensive, so let's only print if we need to:

bool shouldCache =
  passNamesToCache.empty() || 
  (std::find(passNamesToCache.begin(), passNamesToCache.end(), passName) != passNamesToCache.end());

if (shouldCache) {
  ... passAction.getOp()->print(os, flags); ...
}

transform();

I'm also not sure if we want to default print all passes, we probably want the default to do nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that looks much better, I left the default on all passes as a bit of a debug while I add this functionality into explorer. I will remove it by the time I finish drafting this PR.

@@ -26,6 +26,44 @@ namespace mlir::tt {
#define GEN_PASS_REGISTRATION
#include "ttmlir/Conversion/Passes.h.inc"

struct MLIRModuleCacher {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this MLIRModuleLogger

@tapspatel tapspatel mentioned this pull request Jan 22, 2025
21 tasks
Copy link
Contributor

@nsmithtt nsmithtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vraj this looks great! I think we can probably move it out of being a draft if you're ready.

@vprajapati-tt
Copy link
Contributor Author

Vraj this looks great! I think we can probably move it out of being a draft if you're ready.

Glad to hear it! I'm still adding support into explorer for actually loading from a FB stored this way. Running into a weird issue where ttrt doesn't recognize the new FB schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants