acrion commited on
Commit
0d4bd67
·
verified ·
1 Parent(s): 4ec7d5f

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitattributes +0 -80
  2. .hfignore +7 -2
  3. test-upload-all-to-hf.sh +98 -0
  4. upload-all-to-hf.sh +72 -29
.gitattributes CHANGED
@@ -57,83 +57,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
- wikidata-20260309-all-pruned-small/shards/left/chunk-000000.capnp-packed filter=lfs diff=lfs merge=lfs -text
61
- wikidata-20260309-all-pruned-small/shards/left/chunk-000001.capnp-packed filter=lfs diff=lfs merge=lfs -text
62
- wikidata-20260309-all-pruned-small/shards/left/chunk-000002.capnp-packed filter=lfs diff=lfs merge=lfs -text
63
- wikidata-20260309-all-pruned-small/shards/left/chunk-000003.capnp-packed filter=lfs diff=lfs merge=lfs -text
64
- wikidata-20260309-all-pruned-small/shards/left/chunk-000004.capnp-packed filter=lfs diff=lfs merge=lfs -text
65
- wikidata-20260309-all-pruned-small/shards/left/chunk-000005.capnp-packed filter=lfs diff=lfs merge=lfs -text
66
- wikidata-20260309-all-pruned-small/shards/left/chunk-000006.capnp-packed filter=lfs diff=lfs merge=lfs -text
67
- wikidata-20260309-all-pruned-small/shards/left/chunk-000007.capnp-packed filter=lfs diff=lfs merge=lfs -text
68
- wikidata-20260309-all-pruned-small/shards/left/chunk-000008.capnp-packed filter=lfs diff=lfs merge=lfs -text
69
- wikidata-20260309-all-pruned-small/shards/left/chunk-000009.capnp-packed filter=lfs diff=lfs merge=lfs -text
70
- wikidata-20260309-all-pruned-small/shards/left/chunk-000010.capnp-packed filter=lfs diff=lfs merge=lfs -text
71
- wikidata-20260309-all-pruned-small/shards/left/chunk-000011.capnp-packed filter=lfs diff=lfs merge=lfs -text
72
- wikidata-20260309-all-pruned-small/shards/left/chunk-000012.capnp-packed filter=lfs diff=lfs merge=lfs -text
73
- wikidata-20260309-all-pruned-small/shards/left/chunk-000013.capnp-packed filter=lfs diff=lfs merge=lfs -text
74
- wikidata-20260309-all-pruned-small/shards/left/chunk-000014.capnp-packed filter=lfs diff=lfs merge=lfs -text
75
- wikidata-20260309-all-pruned-small/shards/left/chunk-000015.capnp-packed filter=lfs diff=lfs merge=lfs -text
76
- wikidata-20260309-all-pruned-small/shards/left/chunk-000016.capnp-packed filter=lfs diff=lfs merge=lfs -text
77
- wikidata-20260309-all-pruned-small/shards/left/chunk-000017.capnp-packed filter=lfs diff=lfs merge=lfs -text
78
- wikidata-20260309-all-pruned-small/shards/left/chunk-000018.capnp-packed filter=lfs diff=lfs merge=lfs -text
79
- wikidata-20260309-all-pruned-small/shards/left/chunk-000019.capnp-packed filter=lfs diff=lfs merge=lfs -text
80
- wikidata-20260309-all-pruned-small/shards/left/chunk-000020.capnp-packed filter=lfs diff=lfs merge=lfs -text
81
- wikidata-20260309-all-pruned-small/shards/left/chunk-000021.capnp-packed filter=lfs diff=lfs merge=lfs -text
82
- wikidata-20260309-all-pruned-small/shards/left/chunk-000022.capnp-packed filter=lfs diff=lfs merge=lfs -text
83
- wikidata-20260309-all-pruned-small/shards/left/chunk-000023.capnp-packed filter=lfs diff=lfs merge=lfs -text
84
- wikidata-20260309-all-pruned-small/shards/left/chunk-000024.capnp-packed filter=lfs diff=lfs merge=lfs -text
85
- wikidata-20260309-all-pruned-small/shards/left/chunk-000025.capnp-packed filter=lfs diff=lfs merge=lfs -text
86
- wikidata-20260309-all-pruned-small/shards/left/chunk-000026.capnp-packed filter=lfs diff=lfs merge=lfs -text
87
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000000-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
88
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000001-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
89
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000002-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
90
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000003-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
91
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000004-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
92
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000005-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
93
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000006-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
94
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000007-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
95
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000008-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
96
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000009-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
97
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000010-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
98
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000011-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
99
- wikidata-20260309-all-pruned-small/shards/nameOfNode/chunk-000012-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
100
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000000-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
101
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000001-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
102
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000002-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
103
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000003-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
104
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000004-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
105
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000005-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
106
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000006-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
107
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000007-wikidata.capnp-packed filter=lfs diff=lfs merge=lfs -text
108
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000008-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
109
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000009-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
110
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000010-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
111
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000011-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
112
- wikidata-20260309-all-pruned-small/shards/nodeOfName/chunk-000012-en.capnp-packed filter=lfs diff=lfs merge=lfs -text
113
- wikidata-20260309-all-pruned-small/shards/right/chunk-000000.capnp-packed filter=lfs diff=lfs merge=lfs -text
114
- wikidata-20260309-all-pruned-small/shards/right/chunk-000001.capnp-packed filter=lfs diff=lfs merge=lfs -text
115
- wikidata-20260309-all-pruned-small/shards/right/chunk-000002.capnp-packed filter=lfs diff=lfs merge=lfs -text
116
- wikidata-20260309-all-pruned-small/shards/right/chunk-000003.capnp-packed filter=lfs diff=lfs merge=lfs -text
117
- wikidata-20260309-all-pruned-small/shards/right/chunk-000004.capnp-packed filter=lfs diff=lfs merge=lfs -text
118
- wikidata-20260309-all-pruned-small/shards/right/chunk-000005.capnp-packed filter=lfs diff=lfs merge=lfs -text
119
- wikidata-20260309-all-pruned-small/shards/right/chunk-000006.capnp-packed filter=lfs diff=lfs merge=lfs -text
120
- wikidata-20260309-all-pruned-small/shards/right/chunk-000007.capnp-packed filter=lfs diff=lfs merge=lfs -text
121
- wikidata-20260309-all-pruned-small/shards/right/chunk-000008.capnp-packed filter=lfs diff=lfs merge=lfs -text
122
- wikidata-20260309-all-pruned-small/shards/right/chunk-000009.capnp-packed filter=lfs diff=lfs merge=lfs -text
123
- wikidata-20260309-all-pruned-small/shards/right/chunk-000010.capnp-packed filter=lfs diff=lfs merge=lfs -text
124
- wikidata-20260309-all-pruned-small/shards/right/chunk-000011.capnp-packed filter=lfs diff=lfs merge=lfs -text
125
- wikidata-20260309-all-pruned-small/shards/right/chunk-000012.capnp-packed filter=lfs diff=lfs merge=lfs -text
126
- wikidata-20260309-all-pruned-small/shards/right/chunk-000013.capnp-packed filter=lfs diff=lfs merge=lfs -text
127
- wikidata-20260309-all-pruned-small/shards/right/chunk-000014.capnp-packed filter=lfs diff=lfs merge=lfs -text
128
- wikidata-20260309-all-pruned-small/shards/right/chunk-000015.capnp-packed filter=lfs diff=lfs merge=lfs -text
129
- wikidata-20260309-all-pruned-small/shards/right/chunk-000016.capnp-packed filter=lfs diff=lfs merge=lfs -text
130
- wikidata-20260309-all-pruned-small/shards/right/chunk-000017.capnp-packed filter=lfs diff=lfs merge=lfs -text
131
- wikidata-20260309-all-pruned-small/shards/right/chunk-000018.capnp-packed filter=lfs diff=lfs merge=lfs -text
132
- wikidata-20260309-all-pruned-small/shards/right/chunk-000019.capnp-packed filter=lfs diff=lfs merge=lfs -text
133
- wikidata-20260309-all-pruned-small/shards/right/chunk-000020.capnp-packed filter=lfs diff=lfs merge=lfs -text
134
- wikidata-20260309-all-pruned-small/shards/right/chunk-000021.capnp-packed filter=lfs diff=lfs merge=lfs -text
135
- wikidata-20260309-all-pruned-small/shards/right/chunk-000022.capnp-packed filter=lfs diff=lfs merge=lfs -text
136
- wikidata-20260309-all-pruned-small/shards/right/chunk-000023.capnp-packed filter=lfs diff=lfs merge=lfs -text
137
- wikidata-20260309-all-pruned-small/shards/right/chunk-000024.capnp-packed filter=lfs diff=lfs merge=lfs -text
138
- wikidata-20260309-all-pruned-small/shards/right/chunk-000025.capnp-packed filter=lfs diff=lfs merge=lfs -text
139
- wikidata-20260309-all-pruned-small/shards/right/chunk-000026.capnp-packed filter=lfs diff=lfs merge=lfs -text
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.hfignore CHANGED
@@ -1,7 +1,12 @@
 
 
 
 
1
  .DS_Store
2
- .idea
3
- *.log
4
  tmp/
 
5
  *.bz2
6
  *.pidx.*
7
  *.bak
 
1
+ # Read by upload-all-to-hf.sh: files that match these patterns are excluded
2
+ # from upload. The patterns use hf globs, not .gitignore rules: "*" also
3
+ # matches "/", and a trailing "/" covers a directory's contents. This file
4
+ # itself is uploaded, so restoring the dataset brings it back as well.
5
  .DS_Store
6
+ */.DS_Store
7
+ .idea/
8
  tmp/
9
+ *.log
10
  *.bz2
11
  *.pidx.*
12
  *.bak
test-upload-all-to-hf.sh ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Tests for upload-all-to-hf.sh.
3
+ #
4
+ # A `hf` that is fake and located on PATH logs its parameters rather than
5
+ # performing uploads, and each scenario operates within a scratch directory
6
+ # that does not constitute a git work tree, since the script must not rely
7
+ # on git.
8
+ #
9
+ # Usage: test-upload-all-to-hf.sh
10
+
11
+ set -uo pipefail
12
+ SCRIPT="$(cd "$(dirname "$0")" && pwd)/upload-all-to-hf.sh"
13
+ SCRATCH=$(mktemp -d)
14
+ trap 'rm -rf "$SCRATCH"' EXIT
15
+
16
+ FAILED=0
17
+ PASSED=0
18
+ pass() { PASSED=$((PASSED + 1)); echo "ok $1"; }
19
+ fail() { FAILED=$((FAILED + 1)); echo "FAIL $1"; [[ -n "${2:-}" ]] && sed 's/^/ /' <<< "$2"; }
20
+
21
+ FAKEBIN="$SCRATCH/bin"
22
+ mkdir -p "$FAKEBIN"
23
+ cat > "$FAKEBIN/hf" <<'EOF'
24
+ #!/usr/bin/env bash
25
+ printf '%s\n' "$@" > "$HF_ARGS_FILE"
26
+ EOF
27
+ chmod +x "$FAKEBIN/hf"
28
+ export PATH="$FAKEBIN:$PATH"
29
+
30
+ # A directory structured to mirror the actual layout: data files, files
31
+ # to retain locally, a nested directory pattern, and remnants from the
32
+ # git era.
33
+ dataset() {
34
+ local d
35
+ d=$(mktemp -d "$SCRATCH/ds.XXXX")
36
+ mkdir -p "$d/shards/left" "$d/tmp/deep" "$d/.git/lfs"
37
+ printf 'a' > "$d/data.bin"
38
+ printf 'b' > "$d/shards/left/chunk-000000.capnp-packed"
39
+ printf 'c' > "$d/README.md"
40
+ printf 'd' > "$d/data.bin.pidx.322"
41
+ printf 'e' > "$d/old.bak"
42
+ printf 'f' > "$d/tmp/deep/scratch.txt"
43
+ printf 'g' > "$d/upload-to-hf.sh"
44
+ printf 'h' > "$d/.gitattributes"
45
+ printf 'i' > "$d/.git/lfs/object"
46
+ printf '# comment\n\n*.pidx.*\n*.bak\ntmp/\nupload-*.sh\n.gitattributes\n.hfignore\n' > "$d/.hfignore"
47
+ echo "$d"
48
+ }
49
+
50
+ # Each line in .hfignore that is not a comment is transmitted to hf as a
51
+ # single --exclude argument, in the sequence they appear, while comments and
52
+ # blank lines are disregarded.
53
+ D=$(dataset)
54
+ export HF_ARGS_FILE="$SCRATCH/args1"
55
+ if out=$("$SCRIPT" acrion/test "$D" 2>&1) \
56
+ && [[ "$(grep -A1 -x -- '--exclude' "$HF_ARGS_FILE" | grep -v -x -- '--exclude' | grep -v -x -- '--')" == $'*.pidx.*\n*.bak\ntmp/\nupload-*.sh\n.gitattributes\n.hfignore' ]] \
57
+ && ! grep -q 'comment' "$HF_ARGS_FILE"; then
58
+ pass "each .hfignore pattern is passed as one --exclude, comments are not"
59
+ else
60
+ fail "each .hfignore pattern is passed as one --exclude, comments are not" "$out"$'\n'"$(cat "$HF_ARGS_FILE" 2>&1)"
61
+ fi
62
+
63
+ # The repository id, the whole directory, and the repo type reach
64
+ # hf.
65
+ if [[ "$(head -5 "$HF_ARGS_FILE")" == $'upload\nacrion/test\n.\n.\n--repo-type' ]] \
66
+ && grep -qx 'dataset' "$HF_ARGS_FILE"; then
67
+ pass "the repository, the directory and the repo type are passed"
68
+ else
69
+ fail "the repository, the directory and the repo type are passed" "$(cat "$HF_ARGS_FILE" 2>&1)"
70
+ fi
71
+
72
+ # If there is no .hfignore file, then nothing gets uploaded: having an empty
73
+ # exclude list would result in every local-only file being published.
74
+ D=$(dataset); rm "$D/.hfignore"
75
+ export HF_ARGS_FILE="$SCRATCH/args2"
76
+ out=$("$SCRIPT" acrion/test "$D" 2>&1); code=$?
77
+ if [[ $code -eq 1 && "$out" == *"no .hfignore"* && ! -e "$HF_ARGS_FILE" ]]; then
78
+ pass "a missing .hfignore stops the upload"
79
+ else
80
+ fail "a missing .hfignore stops the upload" "exit $code"$'\n'"$out"
81
+ fi
82
+
83
+ # The dry run reveals precisely what hf would take: data and shards,
84
+ # omitting all excluded files, excluding anything from .git, and it never
85
+ # calls hf.
86
+ D=$(dataset)
87
+ export HF_ARGS_FILE="$SCRATCH/args3"
88
+ out=$("$SCRIPT" --dry-run acrion/test "$D" 2>&1); code=$?
89
+ listed=$(sed -n '/^Excludes:/,$p' <<< "$out" | grep -v -e '^Excludes:' -e '^$' -e 'files, ' )
90
+ if [[ $code -eq 0 && "$listed" == $'README.md\ndata.bin\nshards/left/chunk-000000.capnp-packed' && ! -e "$HF_ARGS_FILE" ]]; then
91
+ pass "the dry run lists only what would be uploaded and uploads nothing"
92
+ else
93
+ fail "the dry run lists only what would be uploaded and uploads nothing" "exit $code"$'\n'"$out"
94
+ fi
95
+
96
+ echo
97
+ echo "$PASSED passed, $FAILED failed"
98
+ [[ $FAILED -eq 0 ]]
upload-all-to-hf.sh CHANGED
@@ -1,53 +1,96 @@
1
  #!/usr/bin/env bash
2
  #
3
- # Resumable mirror of the current Git working tree to a Hugging Face repo
4
- # via `hf upload`. Re-running is cheap: files already present on the Hub are
5
- # detected and skipped, and already-uploaded chunks are deduplicated by the
6
- # Xet backend, so only new or changed content is actually transferred.
7
- # Deletions are not handled here; remove remotely deleted files by hand
8
- # (e.g. in the Hugging Face web UI).
 
9
  #
10
- # Note: earlier versions of this script used `hf upload-large-folder`, which
11
- # is deprecated. `hf upload` now handles large folders natively (adaptive
12
- # commit batching, resume without local state).
13
  #
14
- # The exclude list comes straight from `git ls-files`, so it matches
15
- # .gitignore exactly.
 
 
16
  #
17
- # Usage: ./upload-all-to-hf.sh <repo_id> [local_dir] [repo_type]
 
18
 
19
  set -euo pipefail
20
 
21
- REPO_ID="${1:?Usage: $0 <repo_id> [local_dir] [repo_type]}"
 
 
 
 
 
 
22
  LOCAL_DIR="${2:-.}"
23
  REPO_TYPE="${3:-dataset}"
24
 
25
  cd "$LOCAL_DIR"
26
- command -v hf >/dev/null || { echo "error: 'hf' CLI not found" >&2; exit 1; }
27
- command -v git >/dev/null || { echo "error: 'git' not found" >&2; exit 1; }
28
- git rev-parse --is-inside-work-tree >/dev/null 2>&1 \
29
- || { echo "error: not inside a git work tree (needed to derive the .gitignore-based exclude list)" >&2; exit 1; }
30
 
31
- # Capture into a variable first so a git failure aborts via set -e
32
- # (a failure inside <(...) would NOT trip set -e).
33
- ignored="$(git ls-files --others --ignored --exclude-standard)"
 
 
 
 
 
 
 
34
 
35
- EXCLUDES=(--exclude ".git/*")
36
- while IFS= read -r f; do
37
- [ -n "$f" ] && EXCLUDES+=(--exclude "$f")
38
- done <<< "$ignored"
39
 
40
  echo "Target: $REPO_ID ($REPO_TYPE)"
41
  echo "Source: $(pwd)"
42
- echo "Excludes: ${EXCLUDES[*]:-(none)}"
43
  echo
44
 
45
- # High-performance mode saturates network bandwidth and all CPU cores during
46
- # hashing; recommended for machines with >=64GB RAM.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  export HF_XET_HIGH_PERFORMANCE=1
48
 
49
- # Write Xet transfer diagnostics (retries, server errors) to a log file, so
50
- # that a stalled upload can be diagnosed instead of failing silently.
 
51
  export RUST_LOG="${RUST_LOG:-warn}"
52
  export HF_XET_LOG_FILE="${HF_XET_LOG_FILE:-/tmp/hf-xet-upload.log}"
53
  echo "Xet log: $HF_XET_LOG_FILE (RUST_LOG=$RUST_LOG)"
 
1
  #!/usr/bin/env bash
2
  #
3
+ # A resumable mirror of a local directory to a Hugging Face repository using
4
+ # `hf upload`. Restarting the process is cheap: files already present on the
5
+ # Hub are detected and bypassed, while previously uploaded chunks are
6
+ # deduplicated by the Xet backend, ensuring only new or changed content is
7
+ # transmitted. Deletions are not managed by this mechanism; files deleted
8
+ # locally must be removed from the Hub by hand (via the Hugging Face web
9
+ # interface, or using `hf repos delete-files`).
10
  #
11
+ # The content that remains local is listed in the `.hfignore` file within the
12
+ # uploaded directory. There is no involvement of git.
 
13
  #
14
+ # To restore the directory on a different machine, download the
15
+ # dataset:
16
+ # hf download acrion/zelph --repo-type dataset --local-dir <dir>
17
+ # Everything is restored except the files that .hfignore keeps local.
18
  #
19
+ # Usage: upload-all-to-hf.sh [--dry-run] <repo_id> [local_dir] [repo_type]
20
+ # --dry-run print the files that would be offered for upload, upload nothing
21
 
22
  set -euo pipefail
23
 
24
+ DRY_RUN=0
25
+ if [[ "${1:-}" == "--dry-run" ]]; then
26
+ DRY_RUN=1
27
+ shift
28
+ fi
29
+
30
+ REPO_ID="${1:?Usage: $0 [--dry-run] <repo_id> [local_dir] [repo_type]}"
31
  LOCAL_DIR="${2:-.}"
32
  REPO_TYPE="${3:-dataset}"
33
 
34
  cd "$LOCAL_DIR"
35
+ [[ -f .hfignore ]] || { echo "error: no .hfignore in $(pwd)" >&2; exit 1; }
 
 
 
36
 
37
+ # One hf glob per line: Python fnmatch applied to the path relative to this
38
+ # directory, with `*` capable of matching `/` as well, and a pattern
39
+ # concluding with `/` encompassing everything beneath it. Blank lines and
40
+ # lines starting with `#` are skipped.
41
+ PATTERNS=()
42
+ while IFS= read -r line || [[ -n "$line" ]]; do
43
+ line="${line%$'\r'}"
44
+ [[ -z "${line//[[:space:]]/}" || "$line" == \#* ]] && continue
45
+ PATTERNS+=("$line")
46
+ done < .hfignore
47
 
48
+ EXCLUDES=()
49
+ for p in "${PATTERNS[@]}"; do
50
+ EXCLUDES+=(--exclude "$p")
51
+ done
52
 
53
  echo "Target: $REPO_ID ($REPO_TYPE)"
54
  echo "Source: $(pwd)"
55
+ echo "Excludes: ${PATTERNS[*]:-(none)}"
56
  echo
57
 
58
+ if [[ $DRY_RUN -eq 1 ]]; then
59
+ # The selection is made by huggingface_hub's internal filter, using
60
+ # identical patterns and its built-in defaults, meaning it is the one `hf
61
+ # upload` makes.
62
+ python3 - "${PATTERNS[@]}" <<'PY'
63
+ import os
64
+ import sys
65
+
66
+ from huggingface_hub.hf_api import DEFAULT_IGNORE_PATTERNS
67
+ from huggingface_hub.utils import filter_repo_objects
68
+
69
+ paths = []
70
+ for root, dirs, files in os.walk("."):
71
+ dirs[:] = [d for d in dirs if d != ".git"]
72
+ for f in files:
73
+ paths.append(os.path.relpath(os.path.join(root, f), ".").replace(os.sep, "/"))
74
+
75
+ keep = sorted(filter_repo_objects(paths, ignore_patterns=sys.argv[1:] + DEFAULT_IGNORE_PATTERNS))
76
+ for p in keep:
77
+ print(p)
78
+ total = sum(os.path.getsize(p) for p in keep)
79
+ print(f"\n{len(keep)} files, {total / 1e9:.2f} GB offered for upload; unchanged files are skipped by hf.")
80
+ PY
81
+ exit 0
82
+ fi
83
+
84
+ command -v hf >/dev/null || { echo "error: 'hf' CLI not found" >&2; exit 1; }
85
+
86
+ # In high-performance mode, the network bandwidth reaches its maximum and
87
+ # all CPU cores are fully utilized during hashing; recommended for systems
88
+ # equipped with >=64GB RAM.
89
  export HF_XET_HIGH_PERFORMANCE=1
90
 
91
+ # Write Xet transfer diagnostics -- including retry attempts and server
92
+ # errors -- into a log file, enabling the identification of a stalled
93
+ # upload rather than allowing it to fail without notice.
94
  export RUST_LOG="${RUST_LOG:-warn}"
95
  export HF_XET_LOG_FILE="${HF_XET_LOG_FILE:-/tmp/hf-xet-upload.log}"
96
  echo "Xet log: $HF_XET_LOG_FILE (RUST_LOG=$RUST_LOG)"