Skip to content

Commit fcbc37a

Browse files
authored
Minor xet changes: HF_HUB_DISABLE_XET flag, suppress logger.info (#3039)
* Add HF_HUB_DISABLE_XET env var * Emit warning if hf-hub too old for hf-xet * Add logger.info() for using hf-xet for upload * Removing version check * PR feedback
1 parent 83ba43c commit fcbc37a

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

docs/source/en/package_reference/environment_variables.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Integer value to define the number of seconds to wait for server response when d
8686
## Xet
8787

8888
### Other Xet environment variables
89+
* [`HF_HUB_DISABLE_XET`](../package_reference/environment_variables#hfhubdisablexet)
8990
* [`HF_XET_CACHE`](../package_reference/environment_variables#hfxetcache)
9091
* [`HF_XET_HIGH_PERFORMANCE`](../package_reference/environment_variables#hfxethighperformance)
9192
* [`HF_XET_RECONSTRUCT_WRITE_SEQUENTIALLY`](../package_reference/environment_variables#hfxetreconstructwritesequentially)
@@ -164,6 +165,10 @@ Each library defines its own policy (i.e. which usage to monitor) but the core i
164165

165166
You can set `HF_HUB_DISABLE_TELEMETRY=1` as environment variable to globally disable telemetry.
166167

168+
### HF_HUB_DISABLE_XET
169+
170+
Set to disable using `hf-xet`, even if it is available in your Python environment. This is since `hf-xet` will be used automatically if it is found, this allows explicitly disabling its usage.
171+
167172
### HF_HUB_ENABLE_HF_TRANSFER
168173

169174
Set to `True` for faster uploads and downloads from the Hub using `hf_transfer`.

src/huggingface_hub/commands/upload.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from huggingface_hub.errors import RevisionNotFoundError
6060
from huggingface_hub.hf_api import HfApi
6161
from huggingface_hub.utils import disable_progress_bars, enable_progress_bars
62+
from huggingface_hub.utils._runtime import is_xet_available
6263

6364

6465
logger = logging.get_logger(__name__)
@@ -215,7 +216,7 @@ def _upload(self) -> str:
215216
if self.delete is not None and len(self.delete) > 0:
216217
warnings.warn("Ignoring `--delete` since a single file is uploaded.")
217218

218-
if not HF_HUB_ENABLE_HF_TRANSFER:
219+
if not is_xet_available() and not HF_HUB_ENABLE_HF_TRANSFER:
219220
logger.info(
220221
"Consider using `hf_transfer` for faster uploads. This solution comes with some limitations. See"
221222
" https://huggingface.co/docs/huggingface_hub/hf_transfer for more details."

src/huggingface_hub/utils/_runtime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def get_hf_transfer_version() -> str:
154154

155155
# xet
156156
def is_xet_available() -> bool:
157+
# since hf_xet is automatically used if available, allow explicit disabling via environment variable
158+
if constants._is_true(os.environ.get("HF_HUB_DISABLE_XET")): # type: ignore
159+
return False
160+
157161
return is_package_available("hf_xet")
158162

159163

tests/test_xet_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest.mock import MagicMock
22

33
import pytest
4+
from _pytest.monkeypatch import MonkeyPatch
45

56
from huggingface_hub import constants
67
from huggingface_hub.utils._xet import (
@@ -252,3 +253,12 @@ def test_fetch_xet_metadata_with_url_invalid_response(mocker) -> None:
252253

253254
with pytest.raises(ValueError, match="Xet headers have not been correctly set by the server."):
254255
_fetch_xet_connection_info_with_url(url=url, headers=headers)
256+
257+
258+
def test_env_var_hf_hub_disable_xet() -> None:
259+
"""Test that setting HF_HUB_DISABLE_XET results in is_xet_available() returning False."""
260+
from huggingface_hub.utils._runtime import is_xet_available
261+
262+
monkeypatch = MonkeyPatch()
263+
monkeypatch.setenv("HF_HUB_DISABLE_XET", "1")
264+
assert not is_xet_available()

0 commit comments

Comments
 (0)