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

✨ support local cache for models #4374

Merged
merged 4 commits into from
Apr 27, 2024

Conversation

prashantgupta24
Copy link
Contributor

@prashantgupta24 prashantgupta24 commented Apr 25, 2024

Updates how files are pulled from HF Hub to support offline usage with cached files and a fallback in case of networking issues or if HF Hub is down.

(Without this change, you have to pass the explicit path to the model in your local HF cache as the model name.)

Taken bits from #3125

BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE


PR Checklist (Click to Expand)

Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Model] for adding a new model or improving an existing model. Model name should appear in the title.
  • [Frontend] For changes on the vLLM frontend (e.g., OpenAI API server, LLM class, etc.)
  • [Kernel] for changes affecting CUDA kernels or other compute kernels.
  • [Core] for changes in the core vLLM logic (e.g., LLMEngine, AsyncLLMEngine, Scheduler, etc.)
  • [Hardware][Vendor] for hardware-specific changes. Vendor name should appear in the prefix (e.g., [Hardware][AMD]).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to docs/source/ if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.

Notes for Large Changes

Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with rfc-required and might not go through the PR.

What to Expect for the Reviews

The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

Thank You

Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!

@prashantgupta24 prashantgupta24 marked this pull request as ready for review April 25, 2024 19:50
Copy link
Collaborator

@simon-mo simon-mo 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 pretty reasonable to me. Another place we use snapshot_download is when loading the tokenizer and other config. It would be useful to search for snapshot download or .from_pretrained call.

Any suggestion on how to test this?

@prashantgupta24
Copy link
Contributor Author

What I can do is create another function that does snapshot_download 2 times, one with local_files false, if that fails, try with local_files True. Then both download_weights_from_hf and get_quant_config can use that function to avoid duplication of code. I will remove the existing try catch from loader.py.

For the tokenizer, it uses modelscope.hub.snapshot_download, I will see if that has the same functionality as HF's snapshot_download for local_files mode.

@prashantgupta24
Copy link
Contributor Author

Or better yet, I can do this

 hf_folder = snapshot_download(
            model_name_or_path,
            allow_patterns=allow_patterns,
            cache_dir=cache_dir,
            tqdm_class=DisabledTqdm,
            revision=revision,
            local_files_only=HF_HUB_OFFLINE,
        )

?
That way, a network connection attempt is made ONLY if HF_HUB_OFFLINE is unset.

@prashantgupta24 prashantgupta24 force-pushed the support-local-cache branch 4 times, most recently from ca4ab24 to ef75382 Compare April 25, 2024 22:41
Copy link
Collaborator

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @prashantgupta24 (and to @tjohnson31415 for the original PR).

Not sure whether you tested this, but in theory the local_files_only=HF_HUB_OFFLINE shouldn't be necessary with HF's snapshot_download since it already honors this env var.

But it also doesn't harm I guess, and looks like it might still need to be passed like this to modelscope's snapshot_download.

There's another instance of that in loader.py which should be similarly updated I think?

@prashantgupta24
Copy link
Contributor Author

@njhill whoops forgot that one, updated it, thanks!

And yeah I added HF_HUB_OFFLINE to make it consistent across both.

@prashantgupta24
Copy link
Contributor Author

prashantgupta24 commented Apr 25, 2024

Will add a test case for this tomorrow!

Copy link
Collaborator

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

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

I think we should test it? why don't we download the model -> remove instance -> restart the instance with a local file?

@prashantgupta24
Copy link
Contributor Author

I think we should test it? why don't we download the model -> remove instance -> restart the instance with a local file?

Yes I am planning to add that

prashantgupta24 and others added 3 commits April 26, 2024 10:50
Co-authored-by: Travis Johnson <tjohnson31415@gmail.com>
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>

♻️ use HF_HUB_OFFLINE directly

Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Copy link
Collaborator

@njhill njhill left a comment

Choose a reason for hiding this comment

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

@njhill njhill merged commit d6e520e into vllm-project:main Apr 27, 2024
48 checks passed
@prashantgupta24 prashantgupta24 deleted the support-local-cache branch April 27, 2024 19:03
@saivarunk
Copy link

Is there any documentation on how to use the offline option for downloading Huggingface model?

@njhill @prashantgupta24 @tjohnson31415

@prashantgupta24
Copy link
Contributor Author

@saivarunk if offline mode is enabled, no networking calls are made and models are not downloaded from HF, instead vllm will try to look for that model in the local cache.

robertgshaw2-neuralmagic pushed a commit to neuralmagic/nm-vllm that referenced this pull request May 6, 2024
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Co-authored-by: Travis Johnson <tjohnson31415@gmail.com>
@rkooo567
Copy link
Collaborator

rkooo567 commented May 6, 2024

@prashantgupta24 maybe we can update this to the doc (model section) https://docs.vllm.ai/en/latest/?

z103cb pushed a commit to z103cb/opendatahub_vllm that referenced this pull request May 7, 2024
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Co-authored-by: Travis Johnson <tjohnson31415@gmail.com>
mawong-amd pushed a commit to ROCm/vllm that referenced this pull request Jun 3, 2024
Signed-off-by: Prashant Gupta <prashantgupta@us.ibm.com>
Co-authored-by: Travis Johnson <tjohnson31415@gmail.com>
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

5 participants