Skip to content

model download function bugfix and the README - #1

Open
daishengyu1993 wants to merge 9 commits into
ml-service-wrapper:masterfrom
daishengyu1993:master
Open

model download function bugfix and the README#1
daishengyu1993 wants to merge 9 commits into
ml-service-wrapper:masterfrom
daishengyu1993:master

Conversation

@daishengyu1993

@daishengyu1993 daishengyu1993 commented Sep 26, 2020

Copy link
Copy Markdown

PR Type

model download function Bugfix

Description of the changes

It was identified that the model download failed to complete without parent path exist. This fix the download function with the path exist or not.

Comment thread src/service.py Outdated

def get_model_url(self, ctx: mlservicewrapper.core.contexts.ServiceContext):
return ctx.get_parameter_value("ModelUrl", required=True)
return ctx.get_parameter_value("https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin", required=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line is kinda funny--notice how this is a base class for two inheritors? The language detection one is just one of them, and it overrides this function with the hard-coded URL. Because of that, this function actually doesn't get called at all for language detection, and only runs for the vectorization version.

Additionally, this change is renaming the parameter, not changing the return value. So for the vectorization endpoint, it'd actually be searching for an environment variable, for example, named SERVICE_https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin, compared to before, where it was SERVICE_ModelUrl.

Suffice to say, you could verify this by adding a print call in there, but this line doesn't actually get called at all for language detection.

Comment thread src/service.py Outdated
if not os.path.exists(model_path):
url = self.get_model_url(ctx)

os.mkdir(model_path.rsplit('/', 1)[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, but, a few scenarios to think about or test:

  1. How would this work if the directory already exists?
  2. What if it doesn't exist, but its parent also doesn't exist?
  3. Would it work on Windows?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

all the three items should be fix now

Comment thread README.md
@daishengyu1993 daishengyu1993 changed the title fix the download function bug and the README model download function bugfix and the README Oct 2, 2020

@MaJaHa95 MaJaHa95 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Functionality is perfect, I just offered a couple built-in options for doing the steps a tad more cleanly.

Comment thread src/service.py

if not os.path.exists(model_path):
model_parent_path = model_path.rsplit(os.sep, 1)[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better, but I can do you one better yet! Check out os.path.dirname. The functionality is the same, but it's purpose-built for doing this exact thing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Awesome!

Comment thread src/service.py
if not os.path.exists(model_path):
model_parent_path = model_path.rsplit(os.sep, 1)[0]
if not os.path.exists(model_parent_path):
os.makedirs(model_parent_path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And same here, functionality is identical, but the exist_ok parameter will eliminate the need for the extra if block.

@MaJaHa95 MaJaHa95 self-assigned this Oct 2, 2020
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