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

Propagate parameter names #1420

Merged
merged 6 commits into from
Sep 29, 2022

Conversation

antoniojkim
Copy link
Collaborator

@antoniojkim antoniojkim commented Sep 26, 2022

We need to propagate parameter names into the MLIR graph in order to create proper tensor mappings for the Cerebras backend.

CC: @ke1337 @glebk-cerebras @vaibhavc-cerebras @prateekgu-cerebras

@antoniojkim antoniojkim self-assigned this Sep 26, 2022
Copy link
Contributor

@silvasean silvasean left a comment

Choose a reason for hiding this comment

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

This changes the semantics of the external calling convention of the MLIR module, which is one of the most complicated parts of the compiler (or any compiler). We currently provide guarantees about positional arguments. Is there no way for you to pass this information directly to the lower-level compiler you are calling into, since Torch-MLIR doesn't use this information, and we guarantee the order of positional arguments?

@silvasean
Copy link
Contributor

Also, conceptually, I don't understand why an LTC backend would need this information. Can you explain what your backend does with it?

@antoniojkim
Copy link
Collaborator Author

@silvasean This will not affect the MLIR graph generated by Torch-MLIR LTC unless the parameter names are explicitly set
https://github.com/antoniojkim/torch-mlir/blob/5b41855c4d71d885751583700f1f33b9d51bb77d/python/torch_mlir/csrc/base_lazy_backend/mlir_lowering_context.cpp#L252-L254

If not set it will return a null attribute same as before
https://github.com/antoniojkim/torch-mlir/blob/5b41855c4d71d885751583700f1f33b9d51bb77d/python/torch_mlir/csrc/base_lazy_backend/mlir_lowering_context.cpp#L164-L166

Also, conceptually, I don't understand why an LTC backend would need this information. Can you explain what your backend does with it?

This is something specifically required for the Cerebras LTC backend. We require the parameter names be present in the MLIR graph in order to be able to generate our internal tensor mappings.

@silvasean
Copy link
Contributor

Can you handle this outside Torch-MLIR? E.g. after lowering the Torch-MLIR graph you will add your Cerebras-specific attributes afterward.

@antoniojkim
Copy link
Collaborator Author

Can you handle this outside Torch-MLIR? E.g. after lowering the Torch-MLIR graph you will add your Cerebras-specific attributes afterward.

I don't think so. Just from the fact that we need this change to the Torch dialect to be able to lowering it from TS Jit to MLIR
https://github.com/llvm/torch-mlir/pull/1420/files#diff-ffff07df977e36de0f9b7d08dc8c5e5c7ed38edba455c1e177d0558c029c468d

Is it such a great concern to add this in Torch-MLIR, seeing as the parameter's name needs to explicitly be set in order for it to show up in the MLIR graph to begin with. This is something we're only doing in the Cerebras backend

@silvasean
Copy link
Contributor

Yes, this is a huge concern since it changes the external calling convention of the module. Please find a way to do it outside Conceptually this seems like it should be not very difficult -- it should be possible to build a map associating the parameter names to function argument numbers, and then after you lower the graph with Torch-MLIR, you apply those attributes on the parameters.

@antoniojkim
Copy link
Collaborator Author

@silvasean I was able to attach the parameter name attribute after lowering into MLIR, so I've cleaned up and removed that change. Please review again to see if the external calling conventions are now preserved

Copy link
Contributor

@silvasean silvasean left a comment

Choose a reason for hiding this comment

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

LG -- make sure to update the commit message to the latest version of the patch

@antoniojkim antoniojkim force-pushed the antoniojkim/parameter_names branch from cb84d49 to 3e4ec62 Compare September 29, 2022 13:29
@antoniojkim antoniojkim merged commit fa5a8e2 into llvm:main Sep 29, 2022
AmosLewis pushed a commit to AmosLewis/torch-mlir that referenced this pull request Sep 29, 2022
* Propagate parameter name to MLIR

* Add TorchMlirNode Constructor Hook

* Make func_op mutable

- Purpose of this is to allow modification of func_op by subclass
  backend

* Clean up unnecessary changes

* Remove unnecessary attribute case

* Address PR comments
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