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

Override mechanism #1417

Merged
merged 14 commits into from
Nov 29, 2024
Merged

Override mechanism #1417

merged 14 commits into from
Nov 29, 2024

Conversation

vcanicTT
Copy link
Contributor

Initial version of framework for overriding the models.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

include/ttmlir/Dialect/TTNN/Utils/OptimizerOverrides.h Outdated Show resolved Hide resolved
include/ttmlir/Dialect/TTNN/Utils/OptimizerOverrides.h Outdated Show resolved Hide resolved
include/ttmlir/Dialect/TTNN/Utils/OptimizerOverrides.h Outdated Show resolved Hide resolved
include/ttmlir/Dialect/TTNN/Utils/OptimizerOverrides.h Outdated Show resolved Hide resolved
@vcanicTT vcanicTT force-pushed the vcanic/override_mechanism branch from 6c756cc to 2f02d8c Compare November 27, 2024 13:36
@vcanicTT vcanicTT force-pushed the vcanic/override_mechanism branch from 2f02d8c to 295dc19 Compare November 27, 2024 15:04

private:
// Flags for enabling/disabling the optimizer passes
bool enableOptimizer = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

From where did you pull these defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you pass any override for optimizer pass, optimizer should be enabled.

Copy link
Contributor

@nobradovictt nobradovictt Nov 28, 2024

Choose a reason for hiding this comment

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

Maybe we should throw error instead if you do that(passing in override with optimizer set to false) and align defaults with current defaults in code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we pull defaults from the pass Options themselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, the answer is the same like here, #1417 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// override-output-layout=op1=2x2:dram:interleaved:tile:fp32,op2=4x4:l1:block_sharded:row_major:fp16
// Example:
// override-output-layout=add_1_2=1x1:dram:interleaved:row_major:f32"
if (outputLayoutOverrides.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you reuse OutputLayoutOverrideParser print method? Same applies for inputLayoutOverrides.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I need to change a little bit the method. I can write for each segment separate method and call it from toString.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

case mlir::tt::ttnn::TensorMemoryLayout::None:
options += "none";
break;
case mlir::tt::ttnn::TensorMemoryLayout::Interleaved:
Copy link
Contributor

@nobradovictt nobradovictt Nov 27, 2024

Choose a reason for hiding this comment

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

Do these attributes have toString or print methods? Would scale much better, similar for types below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check, if they don't exist I'll add. Also, this related to the answer on the previous question.

Copy link
Contributor

Choose a reason for hiding this comment

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

Look into OutputLayoutOverrideParser::print

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ASSERT_EQ(optimizerOverridesHandler.getMeshShape()[1], meshShape[1]);
}

// Test the toString method
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only true test here, rest are bit pointless. In rest of them you set some attr in memory on the class and then compare getter of the class and the source attr, imo that does not make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like we test everything what we write

Copy link
Contributor

Choose a reason for hiding this comment

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

I fully support that but would you call this a meaningful unit test:
x = 5;
assert(x == 5);
?

I mean some of them are setting non POD structs so you can leave them as well but for flags and ints Im not sure whats the value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just pack all POD ones in a single test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is meaningful test, especially if you work with floating points or registers, or in some concurrency mode, I don't know what the context around this example is.

Also, this is more like explicit statement, what I test here is interface, so I see only functions to be tested, when I write unittests I always try to separate process of developing and testing in my head.

If you still think all setters and getters should be inside one test function I can do that, but I think there is a lot functions, and probably in the future it will be more.

Copy link
Contributor

@odjuricicTT odjuricicTT left a comment

Choose a reason for hiding this comment

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

So these aren't optimizer pass overrides but TTIRToTTNNBackendPipeline overrides? This is what we need, but should be named differently? E.g. TTIRToTTNNBackendPipelineOverrideHandler?

case mlir::tt::ttnn::TensorMemoryLayout::None:
options += "none";
break;
case mlir::tt::ttnn::TensorMemoryLayout::Interleaved:
Copy link
Contributor

Choose a reason for hiding this comment

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

Look into OutputLayoutOverrideParser::print


private:
// Flags for enabling/disabling the optimizer passes
bool enableOptimizer = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we pull defaults from the pass Options themselves?

std::string options = "";

if (enableOptimizer) {
options += "enable-optimizer=true ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to read the string values of options directly from TTIRToTTNNBackendPipelineOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need new structures for overrides, everything is related to Optimizer, so it is optimizer override.

Copy link
Contributor Author

@vcanicTT vcanicTT Nov 28, 2024

Choose a reason for hiding this comment

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

Probably we can extract names and defaults, maybe I can instantiate object of TTIRToTTNNBackendPipelineOptions struct, and get what I need.

@vcanicTT vcanicTT requested a review from mrakitaTT as a code owner November 29, 2024 09:58
@vcanicTT vcanicTT force-pushed the vcanic/override_mechanism branch from 47e7e40 to a8b19cf Compare November 29, 2024 10:00
@@ -2,53 +2,106 @@
//
// SPDX-License-Identifier: Apache-2.0

#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

inputLayoutOverrides[opName] = params;
}
void OptimizerOverridesHandler::addInputLayoutOverride(
StringRef opName, SmallVector<int64_t> operandIdxes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Vectors should be passed in by ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

#include "ttmlir/Dialect/TT/IR/TTOpsTypes.h"
#include "ttmlir/Dialect/TTNN/IR/TTNNOpsAttrs.h"
#include "ttmlir/Dialect/TTNN/IR/TTNNOpsTypes.h"

namespace mlir::tt::ttnn {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create a new file in Utils directory for this instead of merging into this general existing one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Something like PassOptions.h or PassOverrides.h, same comment for cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

@@ -2,11 +2,13 @@
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifndef TTMLIR_DIALECT_TTNN_PIPELINES_TTNNPIPELINES_H
#define TTMLIR_DIALECT_TTNN_PIPELINES_TTNNPIPELINES_H
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ llvm-header-guard ⚠️
code/includes outside of area guarded by header guard; consider moving it

@@ -2,53 +2,106 @@
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifndef TTMLIR_DIALECT_TTNN_UTILS_OPTIMIZEROVERRIDES_H
#define TTMLIR_DIALECT_TTNN_UTILS_OPTIMIZEROVERRIDES_H
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ llvm-header-guard ⚠️
code/includes outside of area guarded by header guard; consider moving it

@vcanicTT vcanicTT force-pushed the vcanic/override_mechanism branch from a8b19cf to bdcde2f Compare November 29, 2024 11:11
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

include/ttmlir/Dialect/TTNN/Utils/PassOverrides.h Outdated Show resolved Hide resolved
include/ttmlir/Dialect/TTNN/Utils/PassOverrides.h Outdated Show resolved Hide resolved
@vcanicTT vcanicTT merged commit 99331c7 into main Nov 29, 2024
19 checks passed
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.

3 participants