Skip to content

Commit

Permalink
small refacto after #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Nov 5, 2024
1 parent 23ac74f commit aa79081
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4446,36 +4446,28 @@ def preupload_lfs_files(
"(ignored by gitignore file)."
)

# Check if the hf_xet library is installed
hf_xet_spec = importlib.util.find_spec("hf_xet")
if hf_xet_spec is None:
# Upload files as LFS files
_upload_lfs_files(
additions=new_lfs_additions_to_upload,
repo_type=repo_type,
repo_id=repo_id,
headers=headers,
endpoint=self.endpoint,
num_threads=num_threads,
# If `create_pr`, we don't want to check user permission on the revision as users with read permission
# should still be able to create PRs even if they don't have write permission on the target branch of the
# PR (i.e. `revision`).
revision=revision if not create_pr else None,
)
# Prepare upload parameters
upload_kwargs = {
"additions": new_lfs_additions_to_upload,
"repo_type": repo_type,
"repo_id": repo_id,
"headers": headers,
"endpoint": self.endpoint,
"num_threads": num_threads,
# If `create_pr`, we don't want to check user permission on the revision as users with read permission
# should still be able to create PRs even if they don't have write permission on the target branch of the
# PR (i.e. `revision`).
"revision": revision if not create_pr else None,
}

# Upload files using Xet protocol if the library is installed.
# Otherwise, default back to LFS.
if importlib.util.find_spec("hf_xet") is not None:
_upload_xet_files(**upload_kwargs)
else:
# Upload files as XET files.
_upload_xet_files(
additions=new_lfs_additions_to_upload,
repo_type=repo_type,
repo_id=repo_id,
headers=headers,
endpoint=self.endpoint,
# If `create_pr`, we don't want to check user permission on the revision as users with read permission
# should still be able to create PRs even if they don't have write permission on the target branch of the
# PR (i.e. `revision`).
revision=revision if not create_pr else None,
)
_upload_lfs_files(**upload_kwargs, num_threads=num_threads)

# Free memory if requested.
for addition in new_lfs_additions_to_upload:
addition._is_uploaded = True
if free_memory:
Expand Down

0 comments on commit aa79081

Please sign in to comment.