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

Refactor API code to base.py in RunInference #21801

Merged
merged 12 commits into from
Jun 13, 2022

Conversation

AnandInguva
Copy link
Contributor

@AnandInguva AnandInguva commented Jun 10, 2022

Refactor code from api to base.py. Delete api.py

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@asf-ci
Copy link

asf-ci commented Jun 10, 2022

Can one of the admins verify this patch?

4 similar comments
@asf-ci
Copy link

asf-ci commented Jun 10, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 10, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 10, 2022

Can one of the admins verify this patch?

@asf-ci
Copy link

asf-ci commented Jun 10, 2022

Can one of the admins verify this patch?

@AnandInguva
Copy link
Contributor Author

AnandInguva commented Jun 10, 2022

Copy link
Contributor

@ryanthompson591 ryanthompson591 left a comment

Choose a reason for hiding this comment

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

Looks good.
@ihji this will probably change what you do with your PR.

api.PredictionResult(numpy.array([1, 2, 3]), 6),
api.PredictionResult(numpy.array([4, 5, 6]), 15),
api.PredictionResult(numpy.array([7, 8, 9]), 24)
base.PredictionResult(numpy.array([1, 2, 3]), 6),
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT of just importing PredictionResult directly like we do in the pytorch test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. we can do that.

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

@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# mypy: ignore-errors
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the error here? was it something like Type variable is unbound?

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we understand why we hit that error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was addressed in this #17514 and commented on this issue #21441. I added a todo( link to github issue)

Copy link
Contributor

@tvalentyn tvalentyn Jun 13, 2022

Choose a reason for hiding this comment

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

I think #21441 describes a different problem: supporting type inference for RunInference API users. I believe some of the approaches, that it mentions, have been implemented (adding generics), and we have some type inference capabilities (that you plan to test in another test). I'd ask, what is the remaining work there?

The problem of having to disable mypy in this file seems to do with developer tooling. Do we know what causes mypy to complain? Does this problem need a separate issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the errors mypy complains about.

apache_beam/testing/load_tests/load_test_metrics_utils.py:51: error: unused 'type: ignore' comment
apache_beam/ml/inference/base.py:68: error: Type variable "apache_beam.ml.inference.base._INPUT_TYPE" is unbound  [valid-type]
apache_beam/ml/inference/base.py:68: note: (Hint: Use "Generic[_INPUT_TYPE]" or "Protocol[_INPUT_TYPE]" base class to bind "_INPUT_TYPE" inside a class)
apache_beam/ml/inference/base.py:68: note: (Hint: Use "_INPUT_TYPE" in function signature to bind "_INPUT_TYPE" inside a function)
apache_beam/ml/inference/base.py:69: error: Type variable "apache_beam.ml.inference.base._OUTPUT_TYPE" is unbound  [valid-type]
apache_beam/ml/inference/base.py:69: note: (Hint: Use "Generic[_OUTPUT_TYPE]" or "Protocol[_OUTPUT_TYPE]" base class to bind "_OUTPUT_TYPE" inside a class)
apache_beam/ml/inference/base.py:69: note: (Hint: Use "_OUTPUT_TYPE" in function signature to bind "_OUTPUT_TYPE" inside a function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Find an issue related to this. python/mypy#7520.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into these errors, this is more related to mypy and Dataclass[1]. Since we are moving to use NamedTuple instead of Dataclass, can we move forward with this?

[1] python/mypy#7520. To solve the current error of mypy with dataclass, PredictionResult should be modified as below

@dataclass
class PredictionResult(Generic[_INPUT_TYPE, _OUTPUT_TYPE]):
   ...

@ihji
Copy link
Contributor

ihji commented Jun 10, 2022

Looks good. @ihji this will probably change what you do with your PR.

Got it. Will update my PR accordingly after this PR gets merged.

@AnandInguva
Copy link
Contributor Author

PTAL @tvalentyn

If examples are paired with keys, it will output a tuple
(key, PredictionResult) for each (key, example) input.

Models for supported frameworks can be loaded via a URI. Supported services
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO in a separate PR:

  • proof-read these API bits by TW.
  • Supported services can also be used - what is this about?
  • TODO(BEAM-14046): Add and link to help documentation : Let's point to the examples directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. thanks

@tvalentyn
Copy link
Contributor

merging based on results from previous commit run.

@tvalentyn tvalentyn merged commit 4d04f50 into apache:master Jun 13, 2022
bullet03 pushed a commit to akvelon/beam that referenced this pull request Jun 20, 2022
* refactor code from api to base

* delete api.py

* modify imports

* Add todo to mypy github issue

* Refactor code to reflect changes of  apache#21777

* Refactor example with KeyedModelHandler

* remove explicit type hints from RunInference class

* Fixup : Lint

* remove TODO to github issue for mypy error

* Add mypy github issue as TODO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants