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

Internal Server Error when pushing local folder to repo branch #1401

Closed
lewtun opened this issue Mar 21, 2023 · 5 comments · Fixed by #1408
Closed

Internal Server Error when pushing local folder to repo branch #1401

lewtun opened this issue Mar 21, 2023 · 5 comments · Fixed by #1408
Labels
bug Something isn't working

Comments

@lewtun
Copy link
Member

lewtun commented Mar 21, 2023

Describe the bug

When trying to push a local Hub repo to another Hub repo's branch with upload_folder(), I am hitting an error like the following:

HfHubHTTPError: 500 Server Error: Internal Server Error for url: https://huggingface.co/api/models/lewtun/test-upload-folder/commit/test-branch?create_pr=1 (Request ID: Root=1-641989f5-38dfc6d84e63800f08d7fede)

Curiously, the error is resolved if I copy the local Hub repo to another directory and point upload_folder() to that. Concretely:

from huggingface_hub import Repository, upload_folder, create_branch, create_repo

# Create dummy repo we want to push files to
create_repo("test-upload-folder", repo_type="model")

# Create branch we want to push to
create_branch(repo_id="lewtun/test-upload-folder", branch="test-branch")

# Clone a Hub repo we want to push the contents to `test-upload-folder`
!mkdir -p dummy-model
repo = Repository(local_dir="dummy-model", clone_from="lewtun/dummy-trl-model")

# Push to branch - fails
upload_folder(repo_id="lewtun/test-upload-folder", folder_path="dummy-model", revision="test-branch", create_pr=True)

# Copy the local repo
!mkdir -p dummy-model-2
!cp -r dummy-model/* dummy-model-2

# Works?
upload_folder(repo_id="lewtun/test-upload-folder", folder_path="dummy-model-2", revision="test-branch", create_pr=True)

Perhaps there's some weird interaction with Git LFS at play here?

Reproduction

Run the cells in this Colab to reproduce the error: https://colab.research.google.com/drive/1lhiiw22EmIypYChZpbwVWwHcSNJpmqXh?usp=sharing

Logs

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py:259, in hf_raise_for_status(response, endpoint_name)
    258 try:
--> 259     response.raise_for_status()
    260 except HTTPError as e:

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 500 Server Error: Internal Server Error for url: https://huggingface.co/api/models/lewtun/distilgpt2-ift/commit/alpaca?create_pr=1

The above exception was the direct cause of the following exception:

HfHubHTTPError                            Traceback (most recent call last)
Cell In[54], line 1
----> 1 api.upload_folder(repo_id=TARGET_MODEL_ID, folder_path="distilgpt-ift/", revision="alpaca", create_pr=True)

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:120, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    117 if check_use_auth_token:
    118     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 120 return fn(*args, **kwargs)

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/hf_api.py:2790, in HfApi.upload_folder(self, repo_id, folder_path, path_in_repo, commit_message, commit_description, token, repo_type, revision, create_pr, parent_commit, allow_patterns, ignore_patterns, delete_patterns)
   2785     delete_operations = [
   2786         delete_op for delete_op in delete_operations if delete_op.path_in_repo not in added_paths
   2787     ]
   2788 commit_operations = delete_operations + add_operations
-> 2790 commit_info = self.create_commit(
   2791     repo_type=repo_type,
   2792     repo_id=repo_id,
   2793     operations=commit_operations,
   2794     commit_message=commit_message,
   2795     commit_description=commit_description,
   2796     token=token,
   2797     revision=revision,
   2798     create_pr=create_pr,
   2799     parent_commit=parent_commit,
   2800 )
   2802 if commit_info.pr_url is not None:
   2803     revision = quote(_parse_revision_from_pr_url(commit_info.pr_url), safe="")

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:120, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    117 if check_use_auth_token:
    118     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 120 return fn(*args, **kwargs)

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/hf_api.py:2443, in HfApi.create_commit(self, repo_id, operations, commit_message, commit_description, token, repo_type, revision, create_pr, num_threads, parent_commit)
   2441 try:
   2442     commit_resp = requests.post(url=commit_url, headers=headers, data=data, params=params)
-> 2443     hf_raise_for_status(commit_resp, endpoint_name="commit")
   2444 except RepositoryNotFoundError as e:
   2445     e.append_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)

File /fsx/lewis/miniconda/envs/h4/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py:301, in hf_raise_for_status(response, endpoint_name)
    297     raise BadRequestError(message, response=response) from e
    299 # Convert `HTTPError` into a `HfHubHTTPError` to display request information
    300 # as well (request id and/or server error message)
--> 301 raise HfHubHTTPError(str(e), response=response) from e

HfHubHTTPError: 500 Server Error: Internal Server Error for url: https://huggingface.co/api/models/lewtun/distilgpt2-ift/commit/alpaca?create_pr=1 (Request ID: Root=1-641987ae-38aa33eb3d1ef701354c2471)

Internal Error - We're working hard to fix that as soon as possible!


### System info

```shell
- huggingface_hub version: 0.13.3
- Platform: Linux-5.10.147+-x86_64-with-glibc2.31
- Python version: 3.9.16
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Token path ?: /root/.cache/huggingface/token
- Has saved token ?: True
- Who am I ?: lewtun
- Configured git credential helpers: store
- FastAI: 2.7.11
- Tensorflow: 2.11.0
- Torch: 1.13.1+cu116
- Jinja2: 3.1.2
- Graphviz: 0.20.1
- Pydot: 1.4.2
- Pillow: 8.4.0
- hf_transfer: N/A
- ENDPOINT: https://huggingface.co
- HUGGINGFACE_HUB_CACHE: /root/.cache/huggingface/hub
- HUGGINGFACE_ASSETS_CACHE: /root/.cache/huggingface/assets
- HF_TOKEN_PATH: /root/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
@lewtun lewtun added the bug Something isn't working label Mar 21, 2023
@Wauplin
Copy link
Contributor

Wauplin commented Mar 21, 2023

Thanks for pointing that out @lewtun. I'll have a look in a bit

@lewtun
Copy link
Member Author

lewtun commented Mar 21, 2023

Ah, I wonder if the problem is that the local repo has its own Git history in .git and that conflicts with the target repo?

@Wauplin
Copy link
Contributor

Wauplin commented Mar 21, 2023

That's what I wondered as well but then why the cp -r dummy-model/* dummy-model-2 doesn't copy the .git folder? It should happen in both cases, right?

But yes, it's a good explanation.

@Wauplin
Copy link
Contributor

Wauplin commented Mar 21, 2023

(in general, I was also thinking of respecting the .gitignore file when doing a upload_folder)

@Wauplin
Copy link
Contributor

Wauplin commented Mar 21, 2023

@lewtun you were right, it is indeed an issue raised when pushing the .git folder. I created a proper issue to track that in huggingface_hub (#1402) along with the .gitignore stuff + an issue in moon-landing to fix it server-side (i.e. return a HTTP 400 with message). Thanks for noticing and reported it :)

FYI doing cp -r dummy-model/* dummy-model-2 doesn't copy the hidden files, that why copying the folder "solved" your problem. If you want to copy a folder with its hidden files, you must do cp -r dummy-model/. dummy-model-2.


As a side note for the script itself:

  • it's more recommended to use from huggingface_hub import login). Internally it's the same but the later will work if the notebook is converted to a script. In this case, the token will be prompted in the terminal. Also you can provide the token manually (i.e. login(token="hf_***") which is not the case with notebook_login).
  • creating a repo with create_repo outputs a RepoUrl object. It is a str with other properties, especially repo_id. That way you can do repo_id = create_repo("test-upload-folder").repo_id => repo_id is set to "lewtun/test-upload-folder" automatically. It's helpful if you want to share a notebook and don't want to care about the implicit username.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants