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

Add the ability to specify a local or S3 HF mirror for more guaranteed loading of pre-trained HF models. #3211

Merged
merged 8 commits into from
Mar 8, 2023

Conversation

justinxzhao
Copy link
Collaborator

@justinxzhao justinxzhao commented Mar 6, 2023

Overview

We've seen that HF servers can go down sometimes. This PR adds the ability to specify a local or S3 HF mirror for more guaranteed loading of pre-trained HF models by setting a LUDWIG_PRETRAINED_MODELS_DIR env variable.

Implementation

If the LUDWIG_PRETRAINED_MODELS_DIR environment variable is set, we attempt to load the HF model from this directory, falling back to downloading from the HF hub if the model is not found, downloading fails, or if model initialization fails.

LUDWIG_PRETRAINED_MODELS_DIR can be an s3 path. Weights are copied to a local temporary directory, and the model is loaded from there.

The expected structure of the LUDWIG_PRETRAINED_MODELS_DIR directory is:

{LUDWIG_PRETRAINED_MODELS_DIR}/{pretrained_model_name_or_path}/pytorch_model.bin
{LUDWIG_PRETRAINED_MODELS_DIR}/{pretrained_model_name_or_path}/config.json

For example, if LUDWIG_PRETRAINED_MODELS_DIR is set to s3://my-bucket/pretrained-models, and pretrained_model_name_or_path is set to bert-base-uncased, we expect to find the following files:

s3://my-bucket/bert-base-uncased/
- pytorch_model.bin
- config.json

If the LUDWIG_PRETRAINED_MODELS_DIR environment variable is not set, we download the model from the HF hub.

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

Unit Test Results

         6 files           6 suites   6h 45m 55s ⏱️
  4 046 tests   4 003 ✔️   43 💤 0
12 107 runs  11 975 ✔️ 132 💤 0

Results for commit 5f815ad.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@tgaddair tgaddair 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, just a few nits.

Copy link
Contributor

@arnavgarg1 arnavgarg1 left a comment

Choose a reason for hiding this comment

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

LGTM! Agree with @tgaddair's comments around the tests :) Great addition!

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

3 participants