-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add Python bindings for override mechanism. #1526
Conversation
1ef0a35
to
10b7547
Compare
void populatePassesModule(py::module &m); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit Extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
private: | ||
// Options for the TTIR to TTNN backend pipeline, | ||
// we use them to extract the names and the deafulat values. | ||
TTIRToTTNNBackendPipelineOptions pipelineOptions; | ||
// TTIRToTTNNBackendPipelineOptions pipelineOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Done.
@@ -13,6 +13,19 @@ | |||
|
|||
namespace mlir::tt::ttnn { | |||
|
|||
struct OptionNames { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit Extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -13,6 +13,19 @@ | |||
|
|||
namespace mlir::tt::ttnn { | |||
|
|||
struct OptionNames { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you switch to this helper struct for names? Names are already defined in pipeline options, previous solution was thus better it didn't require redefining in multiple places in code when adding new option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't bind LLVM structures (class) and their virtual methods. LLVM has separate RTTI. Done.
@@ -6,6 +6,18 @@ | |||
|
|||
namespace mlir::tt::ttnn { | |||
|
|||
const std::string OptionNames::optimizerPassEnabled = "enable-optimizer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment above for these new constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const std::string OptionNames::overrideOutputLayout = "override-output-layout"; | ||
const std::string OptionNames::memoryLayoutAnalysisEnabled = | ||
"memory-layout-analysis-enabled"; | ||
const std::string OptionNames::memReconfigEnabled = "memreconfig-enabled"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constexpr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@@ -65,10 +68,22 @@ class OptimizerOverridesHandler { | |||
TensorMemoryLayout, tt::ttnn::Layout, | |||
tt::DataType); | |||
|
|||
// Wrapper methods we use to expose the adders to the python bindings | |||
std::unordered_map<std::string, InputLayoutOverrideParams> | |||
getInputLayoutOverridesPybindWrapper() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to create wrappers instead of changing the existing methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ maps bind to Python dict, it's easier to bind and deal with C++ types instead of LLVM. I use wrappers only for bindings, within the MLIR C++ you can use both of them.
@@ -6,6 +6,18 @@ | |||
|
|||
namespace mlir::tt::ttnn { | |||
|
|||
const std::string OptionNames::optimizerPassEnabled = "enable-optimizer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that there is a problem when reading these from pipeline options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We can't bind class TTIRToTTNNBackendPipelineOptions, we build python lib with RTTI, and if the structure has or inherits some virtual methods, something wrong happens with the linker. We can talk more about this with Stefi and Topalko, about what we can do in the future, but I think we can't do too much. If we want to expose something from MLIR to Python in this way, we always need to have some simple(C++) structure, or to extend pybind and LLVM. There is also, llvmpy lib, but often they have the same issues with the linking.
@@ -6,6 +6,18 @@ | |||
|
|||
namespace mlir::tt::ttnn { | |||
|
|||
const std::string OptionNames::optimizerPassEnabled = "enable-optimizer"; | |||
const std::string OptionNames::overrideInputLayout = "insert-memreconfig"; | |||
const std::string OptionNames::overrideOutputLayout = "override-output-layout"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Might be cleaner just to have these set in the .h file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bindings LGTM, glad to see you got around the issues :) Unsure if we want to hold both overrides
and optimizer_overrides
, there isn't anything planned for the overrides
module at the moment.
I'm not sure about that module, you can remove it. Optimizer teams want to have separate module for all kinds of overrides we use through the optimizer. If we want to extend override mechanism, we need to design it better and write documentation before we start the implementation. |
a95db1d
to
458f00a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing feedback promptly! Enjoy your vacation!
* Add Python bindings for override mechanism. * Add Python bindings for override mechanism. * Add Python bindings for override mechanism.
Add initial version of Python lib for optimizer overrides. This library is just pybind wrapper around C++ class for optimizer overrides in MLIR.