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

[pybind] New Runtime pybind API #6063

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[pybind] New Runtime pybind API #6063

wants to merge 1 commit into from

Conversation

larryliu0820
Copy link
Contributor

@larryliu0820 larryliu0820 commented Oct 9, 2024

Summary:
Based on this proposal: https://docs.google.com/document/d/10Q4-pt97inQQtFf-FjjwhMaDXXCfk1zGy6V6EkygNUY/edit#heading=h.fcrpnrtb6cud

Historically our pybinding APIs are not following the same C++ modeling
(Program, Method etc) and hence it's hard to use and easy to hit
footguns - for example, if we load the program and return it from a
python method, it goes out of the scope and releases the memory.

This effort is to create Pybind APIs that resembles C++ objects so it's
less confusing to the users.

Add the following python classes:

  • Runtime: a singleton object hosting methods like load_program.
    Returns a Program object when calling load_program. Also exposes
    the operator registry
  • Program: each pte file should have one Program object. Most
    important method is load_method which returns a Method object. It
    has a property method_names where we can inspect what methods are
    inside this .pte file.
  • Method: one object per method name in a given Program. Exposes
    execute which takes in pytree flattened torch tensors as input and
    return pytree flattened output. It also exposes MethodMeta for users
    to inspect more information regarding input/output of this method.

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Copy link

pytorch-bot bot commented Oct 9, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6063

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures

As of commit 3e854de with merge base 69c2c76 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 9, 2024
@facebook-github-bot
Copy link
Contributor

@larryliu0820 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@dbort dbort left a comment

Choose a reason for hiding this comment

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

This looks great! Mostly small issues.

runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/test/test_runtime.py Outdated Show resolved Hide resolved
runtime/test/test_runtime.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

@larryliu0820 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@dbort dbort left a comment

Choose a reason for hiding this comment

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

A few final minor things, but looks great!

runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
runtime/__init__.py Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

@larryliu0820 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit that referenced this pull request Oct 10, 2024
Summary:
Based on this proposal: https://docs.google.com/document/d/10Q4-pt97inQQtFf-FjjwhMaDXXCfk1zGy6V6EkygNUY/edit#heading=h.fcrpnrtb6cud
    
Historically our pybinding APIs are not following the same C++ modeling
(Program, Method etc) and hence it's hard to use and easy to hit
footguns - for example, if we load the program and return it from a
python method, it goes out of the scope and releases the memory.

This effort is to create Pybind APIs that resembles C++ objects so it's
less confusing to the users.

Add the following python classes:
* `Runtime`: a singleton object hosting methods like `load_program`.
  Returns a `Program` object when calling `load_program`. Also exposes
  the operator registry
* `Program`: each pte file should have one `Program` object. Most
  important method is `load_method` which returns a `Method` object. It
  has a property `method_names` where we can inspect what methods are
  inside this .pte file.
* `Method`: one object per method name in a given `Program`. Exposes
  `execute` which takes in pytree flattened torch tensors as input and
  return pytree flattened output. It also exposes `MethodMeta` for users
  to inspect more information regarding input/output of this method.


Reviewed By: dbort

Differential Revision: D64132360

Pulled By: larryliu0820
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D64132360

Summary:
Based on this proposal: https://docs.google.com/document/d/10Q4-pt97inQQtFf-FjjwhMaDXXCfk1zGy6V6EkygNUY/edit#heading=h.fcrpnrtb6cud
    
Historically our pybinding APIs are not following the same C++ modeling
(Program, Method etc) and hence it's hard to use and easy to hit
footguns - for example, if we load the program and return it from a
python method, it goes out of the scope and releases the memory.

This effort is to create Pybind APIs that resembles C++ objects so it's
less confusing to the users.

Add the following python classes:
* `Runtime`: a singleton object hosting methods like `load_program`.
  Returns a `Program` object when calling `load_program`. Also exposes
  the operator registry
* `Program`: each pte file should have one `Program` object. Most
  important method is `load_method` which returns a `Method` object. It
  has a property `method_names` where we can inspect what methods are
  inside this .pte file.
* `Method`: one object per method name in a given `Program`. Exposes
  `execute` which takes in pytree flattened torch tensors as input and
  return pytree flattened output. It also exposes `MethodMeta` for users
  to inspect more information regarding input/output of this method.


Reviewed By: dbort

Differential Revision: D64132360

Pulled By: larryliu0820
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D64132360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants