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

Added Integration test for Fasttext #1221

Merged
merged 3 commits into from
Nov 11, 2020

Conversation

telescopic
Copy link
Contributor

@telescopic telescopic commented Nov 3, 2020

Description

This PR adds an integration test for the Fasttext artifact code.

Changes:

  • Added a simple Fasttext Classifier class in tests/bento_service_examples
  • Added Fasttext save/load/inference test in tests/integration

Motivation and Context

This change is required as Fasttext artifact code is currently not tested.

This PR solves #1195

How Has This Been Tested?

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature and improvements (non-breaking change which adds/improves functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Code Refactoring (internal change which is not user facing)
  • Documentation
  • Test, CI, or build

Component(s) if applicable

  • BentoService (service definition, dependency management, API input/output adapters)
  • Model Artifact (model serialization, multi-framework support)
  • Model Server (mico-batching, dockerisation, logging, OpenAPI, instruments)
  • YataiService gRPC server (model registry, cloud deployment automation)
  • YataiService web server (nodejs HTTP server and web UI)
  • Internal (BentoML's own configuration, logging, utility, exception handling)
  • BentoML CLI

Checklist:

  • My code follows the bentoml code style, both ./dev/format.sh and
    ./dev/lint.sh script have passed
    (instructions).
  • My change reduces project test coverage and requires unit tests to be added
  • I have added unit tests covering my code change
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@codecov
Copy link

codecov bot commented Nov 3, 2020

Codecov Report

Merging #1221 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1221   +/-   ##
=======================================
  Coverage   65.98%   65.98%           
=======================================
  Files         135      135           
  Lines        8563     8563           
=======================================
  Hits         5650     5650           
  Misses       2913     2913           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c32c36d...16639b1. Read the comment docs.

@telescopic
Copy link
Contributor Author

@flosincapite @parano Please review my pull request.

class FasttextClassifier(bentoml.BentoService):
@bentoml.api(input=JsonInput(), batch=False)
def predict(self, parsed_json):
# parsed_json is of type str - make it a dict
Copy link
Contributor

Choose a reason for hiding this comment

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

Check out this similar test implementation and the corresponding test. I think something else is causing parsed_json to be a string.

return FasttextClassifier


test_json = json.dumps({"text": "foo"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh. I think if you just omit json.dumps here, you should be fine :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that! I've made the changes accordingly!.

temporary_file = tempfile.NamedTemporaryFile(suffix=".txt", mode="w+")
temporary_file.write("__label__bar foo")
# Set file pointer to begging to ensure correct read
temporary_file.seek(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just close the temporary file here--no need for seek.

Copy link
Contributor Author

@telescopic telescopic Nov 4, 2020

Choose a reason for hiding this comment

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

The temporary file ends up being automatically destroyed once it is closed.
Would you suggest using a function such as mkstemp?
File deletion would have to be handled explicitly in that case!

Copy link
Contributor

Choose a reason for hiding this comment

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

I lied! I assumed tempfile worked like mkstemp, but it doesn't. You did the right thing.

Copy link
Contributor

@flosincapite flosincapite left a comment

Choose a reason for hiding this comment

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

Please get approval from @bojiang or @parano before submitting.

temporary_file = tempfile.NamedTemporaryFile(suffix=".txt", mode="w+")
temporary_file.write("__label__bar foo")
# Set file pointer to begging to ensure correct read
temporary_file.seek(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I lied! I assumed tempfile worked like mkstemp, but it doesn't. You did the right thing.

@telescopic
Copy link
Contributor Author

telescopic commented Nov 5, 2020

@bojiang / @parano , please review my pull request!
Thanks in advance :D

# Set file pointer to beginning to ensure correct read
temporary_file.seek(0)
yield temporary_file.name
temporary_file.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeahhhhh loving this contextmanager version!

@parano parano merged commit 5f576cc into bentoml:master Nov 11, 2020
aarnphm pushed a commit to aarnphm/BentoML that referenced this pull request Jul 29, 2022
* Add Fasttext Classifier class

* Add Fasttext integration test

* Add .sh file for fasttext integration test
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.

None yet

4 participants