You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pull from Collab Guide [PR 65](Imageomics/Collaborative-distributed-science-guide#65)
* Initial re-organization of page, includes integrity checks and more links to docs
WIP refining
* Add in links, fix typos
* Additional notes in sections, refs out
* Add updated screenshot with arrow
match UI change to 'contribute'
* Remove extra outdated content, update URLs for new versions, run linting
* Clarify UI upload cases
Co-authored-by: Hilmar Lapp <hlapp@drycafe.net>
* Clarify CLI upload use case
Co-authored-by: Hilmar Lapp <hlapp@drycafe.net>
* Add pointer for considerations with large folder uploads
---------
Co-authored-by: Hilmar Lapp <hlapp@drycafe.net>
[Hugging Face](https://hf.co/) offers numerous methods for interacting with and creating datasets. This page provides a basic overview with some recommendations specifically targeting image dataset uploads, though the principles are transferrable to other data types. We list these options—in order of increasing complexity—with some guidance, recommendations, and links out to the appropriate parts of the Hugging Face docs for the most up-to-date information available.
4
4
5
-
When creating a new dataset repository, you can make the dataset **Public** (accessible to anyone on the internet) or **Private** (accessible only to members of the organization).
5
+
1.[Web interface (UI)](#upload-a-dataset-with-the-web-interface): For smaller, simpler uploads.
6
+
2.[Hugging Face Command Line Interface (CLI)](#upload-a-dataset-with-the-hugging-face-cli): For most use-cases, easy access from cluster.
7
+
3.[Hugging Face API (python package)](#upload-a-dataset-with-hfapi): For when more fine-grained control than is achievable with the CLI is needed.
8
+
4.[Git/Git LFS](#upload-a-dataset-with-git): Main use-case is when multiple PRs lead to merge conflicts—Hugging Face provides no other means for resolution.
Some sections of the Hugging Face docs, such as for the `huggingface_hub`, have only version specific links for stable versions. In this case, if the link directs to an older version, there will be a banner to alert you to a newer version available, so keep an eye out for that updated version banner.
12
+
13
+
Most of the content below is covered in various parts of [Hugging Face's Upload Guide](https://huggingface.co/docs/huggingface_hub/en/guides/upload); this page is provided as a summary reference mainly to determine which method might be best and link to the appropriate docs. Additionally, we include an [integrity check](#integrity-check) to help you ensure that your repo contains all the desired files after uploading through any of these methods.
14
+
15
+
[HF tips and tricks for large uploads](https://huggingface.co/docs/huggingface_hub/en/guides/upload#tips-and-tricks-for-large-uploads).
16
+
17
+
## Note on Authentication
18
+
19
+
All of these methods require authentication to edit datasets, ranging from passwords, to tokens, to SSH authentication, and all support editing **Public** (accessible to anyone on the internet) or **Private** (accessible only to members of the organization) repos. Two key notes on authentication:
20
+
21
+
1. Private repositories are only visible if you are authenticated.
22
+
2. If using tokens for access, be sure to create a [fine-grained token](https://huggingface.co/docs/hub/en/security-tokens#what-are-user-access-tokens), specifically for your needs.
10
23
11
24
## Upload a Dataset with the Web Interface
12
25
13
-
In the Files and versions tab of the Dataset card, you can choose to add file in the hugging web interface.
26
+
In the Files and Versions tab of the repository, you can select "Contribute" to add or create files or start a pull request directly from the web interface.
This method is fine for smaller files (<100MB), or data uploads from distributed sources, that have a relatively flat structure with few directories, and/or have few files. If you are uploading existing files, navigate to the target folder first.
31
+
32
+
## Upload a Dataset with the Hugging Face CLI
33
+
34
+
Hugging Face provides a comprehensive Command Line Interface (CLI) and corresponding [docs](https://huggingface.co/docs/huggingface_hub/en/guides/cli). Note that this is installed with the `huggingface_hub` python package, but can also be installed directly, then called with `hf <command>`.
35
+
36
+
The Hugging Face CLI is the ideal method for uploads that are large in volume, have more than a few files, and/or a folder structure with many or nested directories. It works directly from HPC clusters, such as OSC. Under the hood, [`hf upload`](https://huggingface.co/docs/huggingface_hub/en/guides/cli#hf-upload) uses the same upload functions described below, under [Upload a Dataset with HfApi](#upload-a-dataset-with-hfapi). Review [Hugging Face's guidance on large folder uploads](https://huggingface.co/docs/huggingface_hub/v1.10.1/guides/upload#upload-a-large-folder) before selecting a method for uploading large folders to a non-empty repository.
37
+
38
+
When uploading to a dataset, note that the repo type must be specified (`--repo-type=dataset`); this is also the case for spaces, since Hugging Face treats models as the default.
39
+
40
+
There are specific [`hf datasets`](https://huggingface.co/docs/huggingface_hub/en/guides/cli#hf-datasets) and [`hf repo`](https://huggingface.co/docs/huggingface_hub/en/guides/cli#hf-repo) commands for more general queries and repo initialization.
41
+
17
42
## Upload a Dataset with HfApi
18
43
44
+
When more complex dataset structures are involved or more fine-grained control (not exposed on CLI) over how a repo will be organized on Hugging Face is neeeded, the Hugging Face API may be the answer. For instance, if a glob pattern cannot sufficiently clarify necessary exclusions of subfolders or files, [`HfApi`](https://huggingface.co/docs/huggingface_hub/package_reference/hf_api) is likely the preferred choice. This is a class, accessible through the [`huggingface_hub` package](https://huggingface.co/docs/huggingface_hub/index), that acts as a Python wrapper for the API.
45
+
46
+
Please see the Hugging Face API docs for the most up-to-date guidance. For quick reference, to [upload by file](https://huggingface.co/docs/huggingface_hub/v1.10.1/package_reference/hf_api#huggingface_hub.HfApi.upload_file) or [upload by folder (structure maintained)](https://huggingface.co/docs/huggingface_hub/v1.10.1/package_reference/hf_api#huggingface_hub.HfApi.upload_folder).
47
+
19
48
```py linenums="1"
20
49
from huggingface_hub import login
21
50
@@ -24,70 +53,70 @@ login()
24
53
25
54
from huggingface_hub import HfApi
26
55
api = HfApi()
56
+
repo_id ="<ABC-Center/dataset name>"
27
57
28
-
api.upload_file (
58
+
# Upload by file
59
+
api.upload_file(
29
60
path_or_fileobj=<the local file path that you would like to upload>,
30
61
path_in_repo=<the path in the repo>,
31
-
repo_id=<ABC-Center/dataset name>,
62
+
repo_id=repo_id,
32
63
repo_type='dataset'
33
64
)
34
-
```
35
-
36
-
## Upload a Dataset with Git
37
-
38
-
### If the Dataset is Less Than 5GB
39
-
40
-
Navigate to the folder for the repository:
41
65
66
+
# Upload by folder (maintain structure)
67
+
api.upload_folder(
68
+
folder_path="/path/to/local/folder", # should end with folder containing data
69
+
path_in_repo="path/to/folder/", # path desired for folder in repo
70
+
repo_id= repo_id,
71
+
repo_type="dataset",
72
+
token_id="paste-token-here"# if you're not logged in, HF does **not** recommend this method
Repos can also be created through the Hugging Face API using the [create_repo method](https://huggingface.co/docs/huggingface_hub/v1.10.1/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo) with the following parameters:
50
77
78
+
```py linenums="1"
79
+
repo_id ="<HF-Org-name>/<dataset-name>"
80
+
repo_type ="dataset"
81
+
private =True# if you want the repo private
51
82
```
52
83
53
-
### If the Dataset is Larger Than 5GB
84
+
See also instructions using the [datasets package](https://huggingface.co/docs/datasets/create_dataset).
54
85
55
-
#### Install Git LFS
86
+
##Upload a Dataset with Git
56
87
57
-
Follow instructions at <https://git-lfs.com/>
88
+
Using Git to interact with Hugging Face requires installation of [Git LFS](https://git-lfs.com/), the [Hugging Face CLI](https://huggingface.co/docs/huggingface_hub/en/guides/cli), and then enabling large file upload for the repo
58
89
59
-
#### Install the Hugging Face CLI
90
+
Hugging Face provides details on [git vs http](https://huggingface.co/docs/huggingface_hub/en/concepts/git_vs_http), really using Git vs HfApi
60
91
61
-
```
62
-
brew install huggingface-cli
63
-
pip install -U "huggingface_hub[cli]"
64
-
```
92
+
Hugging Face has moved away from Git LFS, instead utilizing [Xet](https://huggingface.co/docs/hub/en/xet/index) for data storage and version control; this is [backwards compatible with LFS](https://huggingface.co/docs/hub/en/xet/legacy-git-lfs).
65
93
66
-
#### Enable the repository to upload large files
94
+
##Other Repo Considerations
67
95
68
-
```
69
-
huggingface-cli lfs-enable-largefiles <your local dataset>
70
-
```
96
+
One time where `git` may be needed, is if one encounters a [merge conflict](https://discuss.huggingface.co/t/how-to-fix-merge-conflicts-in-prs/160090). Unlike GitHub, Hugging Face ***does not*** have conflict resolution UI tools, nor does it provide merge conflict resolution capabilities in the CLI or HfApi. The only means for resolving merge conflicts is to manually update the pull request in a [local clone](The-Hugging-Face-Workflow.md#hugging-face-pull-requests-with-local-edits), pulling `main` into your PR branch and resolving the conflicts.
71
97
72
-
#### Initialize Git LFS
98
+
##Integrity Check
73
99
74
-
```
75
-
git lfs install
76
-
```
100
+
Sometimes uploads fail partway through, leaving one or more files un-uploaded. Unfortunately, it seems that there is not an easy solution to be alerted to these issues when not uploading through the UI. Additionally, using a glob pattern to set upload without a dry-run[^1] (in `git` terms, this would be running `git status` after adding files) can also lead to accidental exclusion. To catch these issues, we recommend the following integrity check after uploading a dataset[^1].
77
101
78
-
#### Track large files (e.g., .csv files)
102
+
[^1]: The Hugging Face CLI does have a [dry-run mode](https://huggingface.co/docs/huggingface_hub/en/guides/cli#dry-run-mode) for *downloading* datasets. Additionally, if working with Git LFS, there is a [preupload LFS](https://huggingface.co/docs/huggingface_hub/en/guides/upload#preupload-lfs-files-before-commit) option to ensure all files are properly preset and organized before committing. There are additional considerations for sharding noted in the Hugging Face docs.
79
103
80
-
```
81
-
# Adds a line to .gitattributes, which Git uses to determine files managed by LFS
df.shape[0] # this should match the number of expected images
89
119
```
90
-
git add
91
-
git commit -m 'comments'
92
-
git push
93
-
```
120
+
121
+
!!! tip "Pro tip"
122
+
If you don't have a metadata file for your images, use the [sum-buddy package](Helpful-Tools-for-your-Workflow.md#sum-buddy) to generate one in your local file system. This can also be used as a metadata file for the dataset viewer as needed (see [image datasets docs](https://huggingface.co/docs/hub/en/datasets-image) for more information on setting this up). Similar options are available for [audio](https://huggingface.co/docs/hub/en/datasets-audio) and [video](https://huggingface.co/docs/hub/en/datasets-video) datasets.
0 commit comments