Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/pytorch/summarization/run_summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import numpy as np
from datasets import load_dataset
from filelock import FileLock
from huggingface_hub import is_offline_mode

import transformers
from transformers import (
Expand All @@ -61,7 +62,7 @@
Seq2SeqTrainingArguments,
set_seed,
)
from transformers.utils import check_min_version, is_offline_mode
from transformers.utils import check_min_version
from transformers.utils.versions import require_version


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from accelerate.utils import set_seed
from datasets import load_dataset
from filelock import FileLock
from huggingface_hub import HfApi
from huggingface_hub import HfApi, is_offline_mode
from torch.utils.data import DataLoader
from tqdm.auto import tqdm

Expand All @@ -66,7 +66,7 @@
SchedulerType,
get_scheduler,
)
from transformers.utils import check_min_version, is_offline_mode
from transformers.utils import check_min_version
from transformers.utils.versions import require_version


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"GitPython<3.1.19",
"hf-doc-builder>=0.3.0",
"hf_xet",
"huggingface-hub>=1.0.0,<2.0",
"huggingface-hub>=1.2.1,<2.0",
"importlib_metadata",
"ipadic>=1.0.0,<2.0",
"jinja2>=3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/dependency_versions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"GitPython": "GitPython<3.1.19",
"hf-doc-builder": "hf-doc-builder>=0.3.0",
"hf_xet": "hf_xet",
"huggingface-hub": "huggingface-hub>=1.0.0,<2.0",
"huggingface-hub": "huggingface-hub>=1.2.1,<2.0",
"importlib_metadata": "importlib_metadata",
"ipadic": "ipadic>=1.0.0,<2.0",
"jinja2": "jinja2>=3.1.0",
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/dynamic_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
from types import ModuleType
from typing import Any, Optional, Union

from huggingface_hub import try_to_load_from_cache
from huggingface_hub import is_offline_mode, try_to_load_from_cache
from packaging import version

from .utils import (
HF_MODULES_CACHE,
TRANSFORMERS_DYNAMIC_MODULE_NAME,
cached_file,
extract_commit_hash,
is_offline_mode,
logging,
)
from .utils.import_utils import VersionComparison, split_package_version
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/feature_extraction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union

import numpy as np
from huggingface_hub import create_repo
from huggingface_hub import create_repo, is_offline_mode

from .dynamic_module_utils import custom_object_save
from .utils import (
Expand All @@ -32,7 +32,6 @@
TensorType,
copy_func,
is_numpy_array,
is_offline_mode,
is_torch_available,
is_torch_device,
is_torch_dtype,
Expand Down
1 change: 0 additions & 1 deletion src/transformers/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
is_in_notebook,
is_ipex_available,
is_librosa_available,
is_offline_mode,
is_onnx_available,
is_pandas_available,
is_phonemizer_available,
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/image_processing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Any, Optional, TypeVar, Union

import numpy as np
from huggingface_hub import create_repo
from huggingface_hub import create_repo, is_offline_mode

from .dynamic_module_utils import custom_object_save
from .feature_extraction_utils import BatchFeature as BaseBatchFeature
Expand All @@ -28,7 +28,6 @@
PROCESSOR_NAME,
PushToHubMixin,
copy_func,
is_offline_mode,
logging,
safe_load_json_file,
)
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/modelcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import httpx
import yaml
from huggingface_hub import model_info
from huggingface_hub import is_offline_mode, model_info
from huggingface_hub.errors import OfflineModeIsEnabled
from huggingface_hub.utils import HFValidationError

Expand All @@ -50,7 +50,6 @@
MODEL_CARD_NAME,
cached_file,
is_datasets_available,
is_offline_mode,
is_tokenizers_available,
is_torch_available,
logging,
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from zipfile import is_zipfile

import torch
from huggingface_hub import create_repo, split_torch_state_dict_into_shards
from huggingface_hub import create_repo, is_offline_mode, split_torch_state_dict_into_shards
from packaging import version
from safetensors import safe_open
from safetensors.torch import save_file as safe_save_file
Expand Down Expand Up @@ -110,7 +110,6 @@
is_flash_attn_2_available,
is_flash_attn_3_available,
is_kernels_available,
is_offline_mode,
is_torch_flex_attn_available,
is_torch_greater_or_equal,
is_torch_mlu_available,
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional, Union

from huggingface_hub import model_info
from huggingface_hub import is_offline_mode, model_info

from ..configuration_utils import PreTrainedConfig
from ..dynamic_module_utils import get_class_from_dynamic_module
Expand All @@ -38,7 +38,6 @@
extract_commit_hash,
find_adapter_config_file,
is_kenlm_available,
is_offline_mode,
is_peft_available,
is_pyctcdecode_available,
is_torch_available,
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import numpy as np
import typing_extensions
from huggingface_hub import create_repo
from huggingface_hub import create_repo, is_offline_mode
from huggingface_hub.dataclasses import validate_typed_dict
from huggingface_hub.errors import EntryNotFoundError

Expand All @@ -54,7 +54,6 @@
cached_file,
copy_func,
direct_transformers_import,
is_offline_mode,
is_torch_available,
list_repo_templates,
logging,
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/tokenization_utils_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import TYPE_CHECKING, Any, NamedTuple, Optional, Union

import numpy as np
from huggingface_hub import create_repo, list_repo_files
from huggingface_hub import create_repo, is_offline_mode, list_repo_files
from packaging import version

from . import __version__
Expand All @@ -51,7 +51,6 @@
extract_commit_hash,
is_mlx_available,
is_numpy_array,
is_offline_mode,
is_protobuf_available,
is_tokenizers_available,
is_torch_available,
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/tokenization_utils_tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing import Any, Optional, Union

import tokenizers.pre_tokenizers as pre_tokenizers_fast
from huggingface_hub import is_offline_mode
from tokenizers import AddedToken, processors
from tokenizers import Encoding as EncodingFast
from tokenizers import Tokenizer as TokenizerFast
Expand All @@ -42,7 +43,7 @@
TextInput,
TruncationStrategy,
)
from .utils import PaddingStrategy, add_end_docstrings, is_offline_mode, logging
from .utils import PaddingStrategy, add_end_docstrings, logging


logger = logging.get_logger(__name__)
Expand Down
1 change: 0 additions & 1 deletion src/transformers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
extract_commit_hash,
has_file,
http_user_agent,
is_offline_mode,
list_repo_templates,
try_to_load_from_cache,
)
Expand Down
8 changes: 1 addition & 7 deletions src/transformers/utils/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
create_repo,
hf_hub_download,
hf_hub_url,
is_offline_mode,
list_repo_tree,
snapshot_download,
try_to_load_from_cache,
Expand Down Expand Up @@ -83,13 +84,6 @@ class DownloadKwargs(TypedDict, total=False):
commit_hash: str | None


def is_offline_mode():
# Import inside the function so test patches on `huggingface_hub.constants` are picked up.
from huggingface_hub import constants as hf_hub_constants

return hf_hub_constants.HF_HUB_OFFLINE


Comment on lines -86 to -92
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than forcing an upgrade to hfh 1.2.1, could a try/except ImportError be better and still maintain a separate definition here with a deprecation warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be live in transformers v5 which is not out yet. I do think it's the best timing to bump huggingface_hub minimal version without damage (in practice v5 will bump huggingface_hub from 0.x to 1.x, so it doesn't matter much if it's 1.0 or 1.2).

# Determine default cache directory.
# The best way to set the cache path is with the environment variable HF_HOME. For more details, check out this
# documentation page: https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables.
Expand Down
3 changes: 1 addition & 2 deletions src/transformers/video_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Any, Optional, Union

import numpy as np
from huggingface_hub import create_repo
from huggingface_hub import create_repo, is_offline_mode
from huggingface_hub.dataclasses import validate_typed_dict

from .dynamic_module_utils import custom_object_save
Expand All @@ -44,7 +44,6 @@
TensorType,
add_start_docstrings,
copy_func,
is_offline_mode,
is_torch_available,
is_torchcodec_available,
is_torchvision_v2_available,
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ class TestOffline(unittest.TestCase):
def test_offline(self):
with tempfile.TemporaryDirectory() as tmpdir:
# First offline load should fail
with patch("transformers.utils.hub.is_offline_mode", return_value=True):
with patch("huggingface_hub.constants.HF_HUB_OFFLINE", True):
with pytest.raises(OSError):
AutoModelForImageClassification.from_pretrained(TINY_IMAGE_CLASSIF, cache_dir=tmpdir)

# Enable online mode for download
with patch("transformers.utils.hub.is_offline_mode", return_value=False):
with patch("huggingface_hub.constants.HF_HUB_OFFLINE", False):
snapshot_download(TINY_IMAGE_CLASSIF, cache_dir=tmpdir)

# Load again in offline mode - should work now
with patch("transformers.utils.hub.is_offline_mode", return_value=True):
with patch("huggingface_hub.constants.HF_HUB_OFFLINE", True):
AutoModelForImageClassification.from_pretrained(TINY_IMAGE_CLASSIF, cache_dir=tmpdir)

def test_local_files_only(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_is_offline_mode(self):
"""
Test `is_offline_mode` helper (should respect both HF_HUB_OFFLINE and legacy TRANSFORMERS_OFFLINE env vars)
"""
load = "from transformers.utils import is_offline_mode"
load = "from huggingface_hub import is_offline_mode"
run = "print(is_offline_mode())"

stdout, _ = self._execute_with_env(load, run)
Expand Down