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

Adding support for HF_HUB_OFFLINE support in the router. #1789

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

Narsil
Copy link
Collaborator

@Narsil Narsil commented Apr 22, 2024

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@drbh
Copy link
Collaborator

drbh commented Apr 23, 2024

lgtm, tested locally (without internet) and works as expected

below are some small syntax changes in case any are helpful

diff --git a/router/src/main.rs b/router/src/main.rs
index 2ac61d1..d4ea338 100644
--- a/router/src/main.rs
+++ b/router/src/main.rs
@@ -187,12 +187,12 @@ async fn main() -> Result<(), RouterError> {
         None,
     }
     let api = if use_api {
-        tracing::info!("Using the Hugging Face API");
         if std::env::var("HF_HUB_OFFLINE") == Ok("1".to_string()) {
             let cache = Cache::default();
             tracing::warn!("Offline mode active using cache defaults");
             Type::Cache(cache)
         } else {
+            tracing::info!("Using the Hugging Face API");
             match api_builder().build() {
                 Ok(api) => Type::Api(api),
                 Err(_) => {
@@ -207,18 +207,12 @@ async fn main() -> Result<(), RouterError> {
 
     // Load tokenizer and model info
     let (tokenizer_filename, config_filename, tokenizer_config_filename, model_info) = match api {
-        Type::None => {
-            let tokenizer_filename = Some(local_path.join("tokenizer.json"));
-            let config_filename = Some(local_path.join("config.json"));
-            let tokenizer_config_filename = Some(local_path.join("tokenizer_config.json"));
-            let model_info = None;
-            (
-                tokenizer_filename,
-                config_filename,
-                tokenizer_config_filename,
-                model_info,
-            )
-        }
+        Type::None => (
+            Some(local_path.join("tokenizer.json")),
+            Some(local_path.join("config.json")),
+            Some(local_path.join("tokenizer_config.json")),
+            None,
+        ),
         Type::Api(api) => {
             let api_repo = api.repo(Repo::with_revision(
                 tokenizer_name.to_string(),
@@ -247,21 +241,16 @@ async fn main() -> Result<(), RouterError> {
             )
         }
         Type::Cache(cache) => {
-            let cache_repo = cache.repo(Repo::with_revision(
+            let repo = cache.repo(Repo::with_revision(
                 tokenizer_name.to_string(),
                 RepoType::Model,
                 revision.clone().unwrap_or_else(|| "main".to_string()),
             ));
-
-            let tokenizer_filename = cache_repo.get("tokenizer.json");
-            let config_filename = cache_repo.get("config.json");
-            let tokenizer_config_filename = cache_repo.get("tokenizer_config.json");
-            let model_info = None;
             (
-                tokenizer_filename,
-                config_filename,
-                tokenizer_config_filename,
-                model_info,
+                repo.get("tokenizer.json"),
+                repo.get("config.json"),
+                repo.get("tokenizer_config.json"),
+                None,
             )
         }
     };

drbh
drbh previously approved these changes Apr 23, 2024
@Narsil
Copy link
Collaborator Author

Narsil commented Apr 23, 2024

Thanks for the patch !

@Narsil Narsil merged commit 4c698fa into main Apr 23, 2024
4 of 5 checks passed
@Narsil Narsil deleted the add_offline_mode_router branch April 23, 2024 21:38
@drbh drbh mentioned this pull request May 1, 2024
Nilabhra pushed a commit to TII-AI-Research-Center/text-generation-inference that referenced this pull request May 14, 2024
…ce#1789)

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet
though.

Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.

Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.

Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @


@OlivierDehaene OR @Narsil

 -->
kdamaszk pushed a commit to kdamaszk/tgi-gaudi that referenced this pull request Jun 10, 2024
…ce#1789)

<!--
Congratulations! You've made it this far! You're not quite done yet
though.

Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.

Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.

Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)

- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?

Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @

@OlivierDehaene OR @Narsil

 -->
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