Skip to content

Unable to create branches with the --revision CLI flag #1841

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

Closed
AlpinDale opened this issue Nov 19, 2023 · 4 comments
Closed

Unable to create branches with the --revision CLI flag #1841

AlpinDale opened this issue Nov 19, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@AlpinDale
Copy link
Contributor

Describe the bug

The --revision flag for huggingface-cli seems to only take existing revisions. The expected behaviour should be the creation of a new branch if it doesn't exist, same as the repository positional argument.

Reproduction

huggingface-cli upload username/repo upload foo.bin --revision dev

Logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py", line 270, in hf_raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/api/datasets/alpindale/test-file/commit/dev

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

Traceback (most recent call last):
  File "/usr/local/bin/huggingface-cli", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/commands/huggingface_cli.py", line 49, in main
    service.run()
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/commands/upload.py", line 187, in run
    print(self._upload())
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/commands/upload.py", line 260, in _upload
    return self.api.upload_file(
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py", line 1045, in _inner
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py", line 3850, in upload_file
    commit_info = self.create_commit(
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py", line 1045, in _inner
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py", line 3237, in create_commit
    hf_raise_for_status(commit_resp, endpoint_name="commit")
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py", line 276, in hf_raise_for_status
    raise RevisionNotFoundError(message, response) from e
huggingface_hub.utils._errors.RevisionNotFoundError: 404 Client Error. (Request ID: Root=1-655a743e-7aea1a250b511830735caef7;6e6c3567-a10d-4891-843e-30d9a0e43b36)

Revision Not Found for url: https://huggingface.co/api/datasets/alpindale/test-file/commit/dev.
Invalid rev id: dev


### System info

```shell
- huggingface_hub version: 0.19.4
- Platform: Linux-5.15.0-84-generic-x86_64-with-glibc2.35
- Python version: 3.10.12
- 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 ?: alpindale
- Configured git credential helpers:
- FastAI: N/A
- Tensorflow: N/A
- Torch: 2.1.0+cu118
- Jinja2: 3.1.2
- Graphviz: N/A
- Pydot: N/A
- Pillow: 9.3.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.24.1
- pydantic: N/A
- aiohttp: N/A
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /root/.cache/huggingface/hub
- HF_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_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
@AlpinDale AlpinDale added the bug Something isn't working label Nov 19, 2023
@Wauplin
Copy link
Contributor

Wauplin commented Nov 20, 2023

@AlpinDale what would you think about having a --create-branch optional argument as described in #1657 (comment) instead? You would have to do

huggingface-cli upload username/repo upload foo.bin --revision dev --create-branch

I am still unsure whether branch creation should be automatic or not.

@AlpinDale
Copy link
Contributor Author

@Wauplin I don't see now this would be an issue, since the tool automatically creates repositories anyway. Creating a branch by default shouldn't be a problem compared to that. If the plan is to have a --create-branch flag, might as well have a --create-repo on top of it.

Also, I've always wondered why HF decided to call branches "revisions". A lot of people don't know they refer to branches from what I've gathered.

@Wauplin
Copy link
Contributor

Wauplin commented Nov 23, 2023

Creating a branch by default shouldn't be a problem compared to that. If the plan is to have a --create-branch flag, might as well have a --create-repo on top of it.

Fair point @AlpinDale. I wanted to think twice before implementing it but it's now done (see #1857).

Also, I've always wondered why HF decided to call branches "revisions". A lot of people don't know they refer to branches from what I've gathered.

Git revisions are broader than simply "branches". A git revision can be any ref: a commit hash, a tag, a branch, etc. Typically, PRs are pushed to a special ref refs/pr/<pr_num> (e.g. "refs/pr/1"). In the context of a push to a HF repository, it mainly refers to branches, PR refs and refs/convert/parquet for datasets. This is why it's safe to create a branch when the revision is not found + --create-pr is not set (see PR).

@Wauplin
Copy link
Contributor

Wauplin commented Nov 24, 2023

PR is merged! #1857

It will be shipped in next release. In the meantime feel free to install huggingface_hub from source to use it. Thanks for the discussion on this issue @AlpinDale!

@Wauplin Wauplin closed this as completed Nov 24, 2023
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
Development

No branches or pull requests

2 participants