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

[WIP] subprocess version of python/lean communication #25

Closed
wants to merge 1 commit into from

Conversation

seanmcl
Copy link
Collaborator

@seanmcl seanmcl commented Feb 4, 2025

Had to comment out the assert statements which aren't supported yet, but this makes the getting-started example go through

 $ interop/test.sh
 json file: /var/folders/hz/hgkdl8pj5fg_zlm2qh8x8fy40000gr/T/tmp6iaqtmi8.json
   4 = nki.language.load(%a_input<float64:128,512>)
   5 = nki.language.load(%b_input<float64:128,512>)
   6 = nki.language.add(4,5)
   7 = nki.language.store(%c_output<float64:128,512>,value=6)

Just an idea.

Had to comment out the `assert` statements which aren't supported
yet, but this makes the getting-started example go through

     $ interop/test.sh
     json file: /var/folders/hz/hgkdl8pj5fg_zlm2qh8x8fy40000gr/T/tmp6iaqtmi8.json
       4 = nki.language.load(%a_input<float64:128,512>)
       5 = nki.language.load(%b_input<float64:128,512>)
       6 = nki.language.add(4,5)
       7 = nki.language.store(%c_output<float64:128,512>,value=6)

Just an idea.
Copy link
Collaborator

@govereau govereau left a comment

Choose a reason for hiding this comment

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

In general, I think this approach better, it is easier to maintain. I am not entirely convinced that we won't need to integrate more closely with python in the future, but we can cross that bridge if we come to it.

1. Python parser parses kernel.py to JSON (using reflection)
2. Python writes kernel.json
3. KLR reads kernel.json
4. KLR writes klr.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, technically you are not writing KLR.json, right?
Do you just need to derive Lean.ToJson on the KLR types and call toJson?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I just copied the text format back to Python for the poc. I'll call toJson.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now the example test writes

$ python3 test/test_examples.py
[{"assign":
  {"x": "4",
   "e":
   {"call":
    {"kwargs": [],
     "f": {"var": {"x": "nki.language.load"}},
     "args":
     [{"tensor":
       {"t":
        {"shape": [128, 512], "name": "a_input", "dtype": "float64"}}}]}}}},
 {"assign":
  {"x": "5",
   "e":
   {"call":
    {"kwargs": [],
     "f": {"var": {"x": "nki.language.load"}},
     "args":
     [{"tensor":
       {"t":
        {"shape": [128, 512], "name": "b_input", "dtype": "float64"}}}]}}}},
 {"assign":
  {"x": "6",
   "e":
   {"call":
    {"kwargs": [],
     "f": {"var": {"x": "nki.language.add"}},
     "args": [{"var": {"x": "4"}}, {"var": {"x": "5"}}]}}}},
 {"assign":
  {"x": "7",
   "e":
   {"call":
    {"kwargs": [["value", {"var": {"x": "6"}}]],
     "f": {"var": {"x": "nki.language.store"}},
     "args":
     [{"tensor":
       {"t":
        {"shape": [128, 512], "name": "c_output", "dtype": "float64"}}}]}}}}]

Good enough for now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems ok. I am working out the BIR output now, it will be similar.

@seanmcl seanmcl closed this Feb 6, 2025
@seanmcl seanmcl deleted the sm/cli-poc branch February 6, 2025 13:06
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