From 131b0c26e45f0a26ad301850da5aed5599e815d7 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Fri, 12 Sep 2025 12:23:38 +0200 Subject: [PATCH 1/4] Remove anything tensorflow-related + deps --- .github/workflows/python-tests.yml | 16 ---- docs/source/cn/installation.md | 8 +- docs/source/de/installation.md | 6 +- docs/source/en/guides/cli.md | 1 - docs/source/en/installation.md | 6 +- .../en/package_reference/serialization.md | 7 +- docs/source/fr/installation.md | 6 +- docs/source/hi/installation.md | 6 +- docs/source/ko/guides/cli.md | 1 - docs/source/ko/installation.md | 6 +- .../ko/package_reference/serialization.md | 6 +- docs/source/tm/installation.md | 6 +- setup.py | 10 -- src/huggingface_hub/__init__.py | 3 - src/huggingface_hub/serialization/__init__.py | 1 - .../serialization/_tensorflow.py | 95 ------------------- src/huggingface_hub/utils/_headers.py | 15 +-- tests/test_serialization.py | 9 -- tests/test_tf_import.py | 26 ----- tests/test_utils_headers.py | 12 +-- 20 files changed, 13 insertions(+), 233 deletions(-) delete mode 100644 src/huggingface_hub/serialization/_tensorflow.py delete mode 100644 tests/test_tf_import.py diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index f32527f67b..f30945a461 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -30,10 +30,6 @@ jobs: test_name: "fastai" - python-version: "3.10" # fastai not supported on 3.12 and 3.11 -> test it on 3.10 test_name: "fastai" - - python-version: "3.9" - test_name: "tensorflow" - - python-version: "3.10" # tensorflow not supported on 3.12 -> test it on 3.10 - test_name: "tensorflow" - python-version: "3.9" # test torch~=1.11 on python 3.9 only. test_name: "Python 3.9, torch_1.11" - python-version: "3.12" # test torch latest on python 3.12 only. @@ -83,12 +79,6 @@ jobs: uv pip install torch~=1.11 ;; - tensorflow) - sudo apt update - sudo apt install -y graphviz - uv pip install "huggingface_hub[tensorflow-testing] @ ." - ;; - esac # If not "Xet only", we want to test upload/download with regular LFS workflow @@ -127,12 +117,6 @@ jobs: eval "$PYTEST ../tests/test_fastai*" ;; - tensorflow) - # Cannot be on same line since '_tf*' checks if tensorflow is NOT imported by default - eval "$PYTEST ../tests/test_tf*" - eval "$PYTEST ../tests/test_serialization.py" - ;; - "Python 3.9, torch_1.11" | torch_latest) eval "$PYTEST ../tests/test_hub_mixin*" eval "$PYTEST ../tests/test_serialization.py" diff --git a/docs/source/cn/installation.md b/docs/source/cn/installation.md index ec899a2305..516d8b9f70 100644 --- a/docs/source/cn/installation.md +++ b/docs/source/cn/installation.md @@ -48,11 +48,7 @@ pip install --upgrade huggingface_hub 您可以通过`pip`安装可选依赖项,请运行以下代码: ```bash -# 安装 TensorFlow 特定功能的依赖项 -# /!\ 注意:这不等同于 `pip install tensorflow` -pip install 'huggingface_hub[tensorflow]' - -# 安装 TensorFlow 特定功能和 CLI 特定功能的依赖项 +# 安装 Torch 特定功能和 CLI 特定功能的依赖项 pip install 'huggingface_hub[cli,torch]' ``` @@ -60,7 +56,7 @@ pip install 'huggingface_hub[cli,torch]' - `cli`:为 `huggingface_hub` 提供更方便的命令行界面 -- `fastai`,` torch`, `tensorflow`: 运行框架特定功能所需的依赖项 +- `fastai`,` torch`: 运行框架特定功能所需的依赖项 - `dev`:用于为库做贡献的依赖项。包括 `testing`(用于运行测试)、`typing`(用于运行类型检查器)和 `quality`(用于运行 linter) diff --git a/docs/source/de/installation.md b/docs/source/de/installation.md index 4c2a907f04..a603d25558 100644 --- a/docs/source/de/installation.md +++ b/docs/source/de/installation.md @@ -44,10 +44,6 @@ Einige Abhängigkeiten von `huggingface_hub` sind [optional](https://setuptools. Sie können optionale Abhängigkeiten über `pip` installieren: ```bash -# Abhängigkeiten für spezifische TensorFlow-Funktionen installieren -# /!\ Achtung: dies entspricht nicht `pip install tensorflow` -pip install 'huggingface_hub[tensorflow]' - # Abhängigkeiten sowohl für torch-spezifische als auch für CLI-spezifische Funktionen installieren. pip install 'huggingface_hub[cli,torch]' ``` @@ -55,7 +51,7 @@ pip install 'huggingface_hub[cli,torch]' Hier ist die Liste der optionalen Abhängigkeiten in huggingface_hub: - `cli`: bietet eine komfortablere CLI-Schnittstelle für huggingface_hub. -- `fastai`, `torch`, `tensorflow`: Abhängigkeiten, um framework-spezifische Funktionen auszuführen. +- `fastai`, `torch`: Abhängigkeiten, um framework-spezifische Funktionen auszuführen. - `dev`: Abhängigkeiten, um zur Bibliothek beizutragen. Enthält `testing` (um Tests auszuführen), `typing` (um den Type Checker auszuführen) und `quality` (um Linters auszuführen). diff --git a/docs/source/en/guides/cli.md b/docs/source/en/guides/cli.md index a754e010b4..cd3e6cacfd 100644 --- a/docs/source/en/guides/cli.md +++ b/docs/source/en/guides/cli.md @@ -576,7 +576,6 @@ Copy-and-paste the text below in your GitHub issue. - Who am I ?: Wauplin - Configured git credential helpers: store - FastAI: N/A -- Tensorflow: 2.11.0 - Torch: 1.12.1 - Jinja2: 3.1.2 - Graphviz: 0.20.1 diff --git a/docs/source/en/installation.md b/docs/source/en/installation.md index 7d86b715d0..69701225d4 100644 --- a/docs/source/en/installation.md +++ b/docs/source/en/installation.md @@ -46,17 +46,13 @@ Some dependencies of `huggingface_hub` are [optional](https://setuptools.pypa.io You can install optional dependencies via `pip`: ```bash -# Install dependencies for tensorflow-specific features -# /!\ Warning: this is not equivalent to `pip install tensorflow` -pip install 'huggingface_hub[tensorflow]' - # Install dependencies for both torch-specific and CLI-specific features. pip install 'huggingface_hub[cli,torch]' ``` Here is the list of optional dependencies in `huggingface_hub`: - `cli`: provide a more convenient CLI interface for `huggingface_hub`. -- `fastai`, `torch`, `tensorflow`: dependencies to run framework-specific features. +- `fastai`, `torch`: dependencies to run framework-specific features. - `dev`: dependencies to contribute to the lib. Includes `testing` (to run tests), `typing` (to run type checker) and `quality` (to run linters). diff --git a/docs/source/en/package_reference/serialization.md b/docs/source/en/package_reference/serialization.md index f45ad58cd8..04ccfd2682 100644 --- a/docs/source/en/package_reference/serialization.md +++ b/docs/source/en/package_reference/serialization.md @@ -131,11 +131,7 @@ If you want to save a state dictionary (e.g. a mapping between layer names and r [[autodoc]] huggingface_hub.save_torch_state_dict -The `serialization` module also contains low-level helpers to split a state dictionary into several shards, while creating a proper index in the process. These helpers are available for `torch` and `tensorflow` tensors and are designed to be easily extended to any other ML frameworks. - -### split_tf_state_dict_into_shards - -[[autodoc]] huggingface_hub.split_tf_state_dict_into_shards +The `serialization` module also contains low-level helpers to split a state dictionary into several shards, while creating a proper index in the process. These helpers are available for `torch` tensors and are designed to be easily extended to any other ML frameworks. ### split_torch_state_dict_into_shards @@ -159,7 +155,6 @@ The loading helpers support both single-file and sharded checkpoints in either s [[autodoc]] huggingface_hub.load_state_dict_from_file - ## Tensors helpers ### get_torch_storage_id diff --git a/docs/source/fr/installation.md b/docs/source/fr/installation.md index 6e0f41ee6e..fe3a279102 100644 --- a/docs/source/fr/installation.md +++ b/docs/source/fr/installation.md @@ -48,17 +48,13 @@ Toutefois, certaines fonctionnalités de `huggingface_hub` ne seront pas disponi Vous pouvez installer des dépendances optionnelles via `pip`: ```bash -#Installation des dépendances pour les fonctionnalités spécifiques à Tensorflow. -#/!\ Attention : cette commande n'est pas équivalente à `pip install tensorflow`. -pip install 'huggingface_hub[tensorflow]' - #Installation des dépendances spécifiques à Pytorch et au CLI. pip install 'huggingface_hub[cli,torch]' ``` Voici une liste des dépendances optionnelles dans `huggingface_hub`: - `cli` fournit une interface d'invite de commande plus pratique pour `huggingface_hub`. -- `fastai`, `torch` et `tensorflow` sont des dépendances pour utiliser des fonctionnalités spécifiques à un framework. +- `fastai`, `torch` sont des dépendances pour utiliser des fonctionnalités spécifiques à un framework. - `dev` permet de contribuer à la librairie. Cette dépendance inclut `testing` (pour lancer des tests), `typing` (pour lancer le vérifieur de type) et `quality` (pour lancer des linters). diff --git a/docs/source/hi/installation.md b/docs/source/hi/installation.md index c5974a32f7..91d3702059 100644 --- a/docs/source/hi/installation.md +++ b/docs/source/hi/installation.md @@ -46,17 +46,13 @@ pip install --upgrade huggingface_hub आप `pip` के माध्यम से वैकल्पिक निर्भरताएँ स्थापित कर सकते हैं: ```bash -# Install dependencies for tensorflow-specific features -# /!\ Warning: this is not equivalent to `pip install tensorflow` -pip install 'huggingface_hub[tensorflow]' - # Install dependencies for both torch-specific and CLI-specific features. pip install 'huggingface_hub[cli,torch]' ``` यहां `huggingface_hub` में वैकल्पिक निर्भरताओं की सूची दी गई है: - `cli`: `huggingface_hub` के लिए अधिक सुविधाजनक CLI इंटरफ़ेस प्रदान करें। -- `fastai`, `torch`, `tensorflow`: फ्रेमवर्क-विशिष्ट सुविधाओं को चलाने के लिए निर्भरताएँ। +- `fastai`, `torch`: फ्रेमवर्क-विशिष्ट सुविधाओं को चलाने के लिए निर्भरताएँ। - `dev`: lib में योगदान करने के लिए निर्भरताएँ। इसमें 'परीक्षण' (परीक्षण चलाने के लिए), 'टाइपिंग' (टाइप चेकर चलाने के लिए) और 'गुणवत्ता' (लिंटर चलाने के लिए) शामिल हैं। diff --git a/docs/source/ko/guides/cli.md b/docs/source/ko/guides/cli.md index 71f03095dd..28472fcf72 100644 --- a/docs/source/ko/guides/cli.md +++ b/docs/source/ko/guides/cli.md @@ -455,7 +455,6 @@ Copy-and-paste the text below in your GitHub issue. - Who am I ?: Wauplin - Configured git credential helpers: store - FastAI: N/A -- Tensorflow: 2.11.0 - Torch: 1.12.1 - Jinja2: 3.1.2 - Graphviz: 0.20.1 diff --git a/docs/source/ko/installation.md b/docs/source/ko/installation.md index b222bef630..d9cd8a46dd 100644 --- a/docs/source/ko/installation.md +++ b/docs/source/ko/installation.md @@ -46,17 +46,13 @@ pip install --upgrade huggingface_hub 선택적 의존성은 `pip`을 통해 설치할 수 있습니다: ```bash -# TensorFlow 관련 기능에 대한 의존성을 설치합니다. -# /!\ 경고: `pip install tensorflow`와 동일하지 않습니다. -pip install 'huggingface_hub[tensorflow]' - # PyTorch와 CLI와 관련된 기능에 대한 의존성을 모두 설치합니다. pip install 'huggingface_hub[cli,torch]' ``` 다음은 `huggingface_hub`의 선택 의존성 목록입니다: - `cli`: 보다 편리한 `huggingface_hub`의 CLI 인터페이스입니다. -- `fastai`, `torch`, `tensorflow`: 프레임워크별 기능을 실행하려면 필요합니다. +- `fastai`, `torch`: 프레임워크별 기능을 실행하려면 필요합니다. - `dev`: 라이브러리에 기여하고 싶다면 필요합니다. 테스트 실행을 위한 `testing`, 타입 검사기 실행을 위한 `typing`, 린터 실행을 위한 `quality`가 포함됩니다. ### 소스에서 설치 [[install-from-source]] diff --git a/docs/source/ko/package_reference/serialization.md b/docs/source/ko/package_reference/serialization.md index 25901237bf..9dd7a6ce7b 100644 --- a/docs/source/ko/package_reference/serialization.md +++ b/docs/source/ko/package_reference/serialization.md @@ -8,11 +8,7 @@ rendered properly in your Markdown viewer. ## 상태 사전을 샤드로 나누기[[split-state-dict-into-shards]] -현재 이 모듈은 상태 딕셔너리(예: 레이어 이름과 관련 텐서 간의 매핑)를 받아 여러 샤드로 나누고, 이 과정에서 적절한 인덱스를 생성하는 단일 헬퍼를 포함하고 있습니다. 이 헬퍼는 `torch`, `tensorflow`, `numpy` 텐서에 사용 가능하며, 다른 ML 프레임워크로 쉽게 확장될 수 있도록 설계되었습니다. - -### split_tf_state_dict_into_shards[[huggingface_hub.split_tf_state_dict_into_shards]] - -[[autodoc]] huggingface_hub.split_tf_state_dict_into_shards +현재 이 모듈은 상태 딕셔너리(예: 레이어 이름과 관련 텐서 간의 매핑)를 받아 여러 샤드로 나누고, 이 과정에서 적절한 인덱스를 생성하는 단일 헬퍼를 포함하고 있습니다. 이 헬퍼는 `torch` 텐서에 사용 가능하며, 다른 ML 프레임워크로 쉽게 확장될 수 있도록 설계되었습니다. ### split_torch_state_dict_into_shards[[huggingface_hub.split_torch_state_dict_into_shards]] diff --git a/docs/source/tm/installation.md b/docs/source/tm/installation.md index 28134ed5b7..479b2c3e4c 100644 --- a/docs/source/tm/installation.md +++ b/docs/source/tm/installation.md @@ -43,17 +43,13 @@ pip install --upgrade huggingface_hub நீங்கள் விருப்பத் தேவைப்படும் சார்புகளை `pip` மூலம் நிறுவலாம்: ```bash -# டென்சர்‌ஃபிளோவுக்கான குறிப்பிட்ட அம்சங்களுக்கு சார்ந்த பொறுப்பு நிறுவவும் -# /!\ எச்சரிக்கை: இது `pip install tensorflow` க்கு சமமாகக் கருதப்படாது -pip install 'huggingface_hub[tensorflow]' - # டார்ச்-குறிப்பிட்ட மற்றும் CLI-குறிப்பிட்ட அம்சங்களுக்கு தேவையான பொறுப்புகளை நிறுவவும். pip install 'huggingface_hub[cli,torch]' ``` `huggingface_hub`-இல் உள்ள விருப்பத் தேவைப்படும் சார்புகளின் பட்டியல்: - `cli`: `huggingface_hub`-க்கு மிகவும் வசதியான CLI இடைமுகத்தை வழங்குகிறது. -- `fastai`, `torch`, `tensorflow`: வடிவமைப்பு குறிப்பிட்ட அம்சங்களை இயக்க தேவையான சார்புகள். +- `fastai`, `torch`: வடிவமைப்பு குறிப்பிட்ட அம்சங்களை இயக்க தேவையான சார்புகள். - `dev`: நூலகத்திற்கு பங்களிக்க தேவையான சார்புகள். இதில் சோதனை (சோதனைகளை இயக்க), வகை சோதனை (வகை சரிபார்ப்பு ஐ இயக்க) மற்றும் தரம் (லிண்டர்கள் ஐ இயக்க) உள்ளன. ### மூலத்திலிருந்து நிறுவல் diff --git a/setup.py b/setup.py index 6524423fb8..97fc2efbe8 100644 --- a/setup.py +++ b/setup.py @@ -54,16 +54,6 @@ def get_version() -> str: "fastcore>=1.3.27", ] -extras["tensorflow"] = [ - "tensorflow", - "pydot", - "graphviz", -] - -extras["tensorflow-testing"] = [ - "tensorflow", -] - extras["hf_xet"] = ["hf-xet>=1.1.2,<2.0.0"] extras["mcp"] = [ diff --git a/src/huggingface_hub/__init__.py b/src/huggingface_hub/__init__.py index 2d2d27c9db..cea4beea98 100644 --- a/src/huggingface_hub/__init__.py +++ b/src/huggingface_hub/__init__.py @@ -496,7 +496,6 @@ "save_torch_model", "save_torch_state_dict", "split_state_dict_into_shards_factory", - "split_tf_state_dict_into_shards", "split_torch_state_dict_into_shards", ], "serialization._dduf": [ @@ -950,7 +949,6 @@ "snapshot_download", "space_info", "split_state_dict_into_shards_factory", - "split_tf_state_dict_into_shards", "split_torch_state_dict_into_shards", "super_squash_history", "suspend_scheduled_job", @@ -1502,7 +1500,6 @@ def __dir__(): save_torch_model, # noqa: F401 save_torch_state_dict, # noqa: F401 split_state_dict_into_shards_factory, # noqa: F401 - split_tf_state_dict_into_shards, # noqa: F401 split_torch_state_dict_into_shards, # noqa: F401 ) from .serialization._dduf import ( diff --git a/src/huggingface_hub/serialization/__init__.py b/src/huggingface_hub/serialization/__init__.py index 8949a22a5f..6e624a7541 100644 --- a/src/huggingface_hub/serialization/__init__.py +++ b/src/huggingface_hub/serialization/__init__.py @@ -15,7 +15,6 @@ """Contains helpers to serialize tensors.""" from ._base import StateDictSplit, split_state_dict_into_shards_factory -from ._tensorflow import get_tf_storage_size, split_tf_state_dict_into_shards from ._torch import ( get_torch_storage_id, get_torch_storage_size, diff --git a/src/huggingface_hub/serialization/_tensorflow.py b/src/huggingface_hub/serialization/_tensorflow.py deleted file mode 100644 index affcaf4834..0000000000 --- a/src/huggingface_hub/serialization/_tensorflow.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2024 The HuggingFace Team. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Contains tensorflow-specific helpers.""" - -import math -import re -from typing import TYPE_CHECKING, Union - -from .. import constants -from ._base import MAX_SHARD_SIZE, StateDictSplit, split_state_dict_into_shards_factory - - -if TYPE_CHECKING: - import tensorflow as tf - - -def split_tf_state_dict_into_shards( - state_dict: dict[str, "tf.Tensor"], - *, - filename_pattern: str = constants.TF2_WEIGHTS_FILE_PATTERN, - max_shard_size: Union[int, str] = MAX_SHARD_SIZE, -) -> StateDictSplit: - """ - Split a model state dictionary in shards so that each shard is smaller than a given size. - - The shards are determined by iterating through the `state_dict` in the order of its keys. There is no optimization - made to make each shard as close as possible to the maximum size passed. For example, if the limit is 10GB and we - have tensors of sizes [6GB, 6GB, 2GB, 6GB, 2GB, 2GB] they will get sharded as [6GB], [6+2GB], [6+2+2GB] and not - [6+2+2GB], [6+2GB], [6GB]. - - - - If one of the model's tensor is bigger than `max_shard_size`, it will end up in its own shard which will have a - size greater than `max_shard_size`. - - - - Args: - state_dict (`dict[str, Tensor]`): - The state dictionary to save. - filename_pattern (`str`, *optional*): - The pattern to generate the files names in which the model will be saved. Pattern must be a string that - can be formatted with `filename_pattern.format(suffix=...)` and must contain the keyword `suffix` - Defaults to `"tf_model{suffix}.h5"`. - max_shard_size (`int` or `str`, *optional*): - The maximum size of each shard, in bytes. Defaults to 5GB. - - Returns: - [`StateDictSplit`]: A `StateDictSplit` object containing the shards and the index to retrieve them. - """ - return split_state_dict_into_shards_factory( - state_dict, - max_shard_size=max_shard_size, - filename_pattern=filename_pattern, - get_storage_size=get_tf_storage_size, - ) - - -def get_tf_storage_size(tensor: "tf.Tensor") -> int: - # Return `math.ceil` since dtype byte size can be a float (e.g., 0.125 for tf.bool). - # Better to overestimate than underestimate. - return math.ceil(tensor.numpy().size * _dtype_byte_size_tf(tensor.dtype)) - - -def _dtype_byte_size_tf(dtype) -> float: - """ - Returns the size (in bytes) occupied by one parameter of type `dtype`. - Taken from https://github.com/huggingface/transformers/blob/74d9d0cebb0263a3f8ab9c280569170cc74651d0/src/transformers/modeling_tf_utils.py#L608. - NOTE: why not `tensor.numpy().nbytes`? - Example: - ```py - >>> _dtype_byte_size(tf.float32) - 4 - ``` - """ - import tensorflow as tf - - if dtype == tf.bool: - return 1 / 8 - bit_search = re.search(r"[^\d](\d+)$", dtype.name) - if bit_search is None: - raise ValueError(f"`dtype` is not a valid dtype: {dtype}.") - bit_size = int(bit_search.groups()[0]) - return bit_size // 8 diff --git a/src/huggingface_hub/utils/_headers.py b/src/huggingface_hub/utils/_headers.py index d952d97121..cabdbd7c81 100644 --- a/src/huggingface_hub/utils/_headers.py +++ b/src/huggingface_hub/utils/_headers.py @@ -21,15 +21,9 @@ from .. import constants from ._auth import get_token from ._runtime import ( - get_fastai_version, - get_fastcore_version, get_hf_hub_version, get_python_version, - get_tf_version, get_torch_version, - is_fastai_available, - is_fastcore_available, - is_tf_available, is_torch_available, ) from ._validators import validate_hf_hub_args @@ -56,8 +50,7 @@ def build_hf_headers( `None` or token is an organization token (starting with `"api_org***"`). In addition to the auth header, a user-agent is added to provide information about - the installed packages (versions of python, huggingface_hub, torch, tensorflow, - fastai and fastcore). + the installed packages (versions of python, huggingface_hub, torch). Args: token (`str`, `bool`, *optional*): @@ -192,12 +185,6 @@ def _http_user_agent( if not constants.HF_HUB_DISABLE_TELEMETRY: if is_torch_available(): ua += f"; torch/{get_torch_version()}" - if is_tf_available(): - ua += f"; tensorflow/{get_tf_version()}" - if is_fastai_available(): - ua += f"; fastai/{get_fastai_version()}" - if is_fastcore_available(): - ua += f"; fastcore/{get_fastcore_version()}" if isinstance(user_agent, dict): ua += "; " + "; ".join(f"{k}/{v}" for k, v in user_agent.items()) diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 6bc74b9962..6b67ff00d4 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -9,7 +9,6 @@ from huggingface_hub import constants from huggingface_hub.serialization import ( - get_tf_storage_size, get_torch_storage_size, load_state_dict_from_file, load_torch_model, @@ -244,14 +243,6 @@ def test_tensor_same_storage(): assert state_dict_split.metadata == {"total_size": 3} # count them once -@requires("tensorflow") -def test_get_tf_storage_size(): - import tensorflow as tf # type: ignore[import] - - assert get_tf_storage_size(tf.constant([1, 2, 3, 4, 5], dtype=tf.float64)) == 5 * 8 - assert get_tf_storage_size(tf.constant([1, 2, 3, 4, 5], dtype=tf.float16)) == 5 * 2 - - @requires("torch") def test_get_torch_storage_size(): import torch # type: ignore[import] diff --git a/tests/test_tf_import.py b/tests/test_tf_import.py deleted file mode 100644 index a79c234a8c..0000000000 --- a/tests/test_tf_import.py +++ /dev/null @@ -1,26 +0,0 @@ -import sys -import unittest - -from huggingface_hub.utils import is_tf_available - - -def require_tf(test_case): - """ - Decorator marking a test that requires TensorFlow. - - These tests are skipped when TensorFlow is not installed. - - """ - if not is_tf_available(): - return unittest.skip("test requires Tensorflow")(test_case) - else: - return test_case - - -@require_tf -def test_import_huggingface_hub_does_not_import_tensorflow(): - # `import huggingface_hub` is not necessary since huggingface_hub is already imported at the top of this file, - # but let's keep it here anyway just in case - import huggingface_hub # noqa - - assert "tensorflow" not in sys.modules diff --git a/tests/test_utils_headers.py b/tests/test_utils_headers.py index d03f545095..3ebae72c6a 100644 --- a/tests/test_utils_headers.py +++ b/tests/test_utils_headers.py @@ -94,22 +94,14 @@ def test_default_user_agent( mock_is_torch_available.return_value = True self.assertEqual( self._get_user_agent(), - f"unknown/None; hf_hub/{get_hf_hub_version()};" - f" python/{get_python_version()}; torch/torch_version;" - " tensorflow/tf_version; fastai/fastai_version;" - " fastcore/fastcore_version", + f"unknown/None; hf_hub/{get_hf_hub_version()}; python/{get_python_version()}; torch/torch_version;", ) @patch("huggingface_hub.utils._headers.is_torch_available") - @patch("huggingface_hub.utils._headers.is_tf_available") @handle_injection_in_test - def test_user_agent_with_library_name_multiple_missing( - self, mock_is_torch_available: Mock, mock_is_tf_available: Mock - ) -> None: + def test_user_agent_with_library_name_multiple_missing(self, mock_is_torch_available: Mock) -> None: mock_is_torch_available.return_value = False - mock_is_tf_available.return_value = False self.assertNotIn("torch", self._get_user_agent()) - self.assertNotIn("tensorflow", self._get_user_agent()) def test_user_agent_with_library_name_and_version(self) -> None: self.assertTrue( From 243eebe10b18ad40952763ce0dd3994f8fd92fac Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Fri, 12 Sep 2025 12:27:01 +0200 Subject: [PATCH 2/4] init --- src/huggingface_hub/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/huggingface_hub/__init__.py b/src/huggingface_hub/__init__.py index cea4beea98..f8937a0580 100644 --- a/src/huggingface_hub/__init__.py +++ b/src/huggingface_hub/__init__.py @@ -488,7 +488,6 @@ ], "serialization": [ "StateDictSplit", - "get_tf_storage_size", "get_torch_storage_id", "get_torch_storage_size", "load_state_dict_from_file", @@ -868,7 +867,6 @@ "get_session", "get_space_runtime", "get_space_variables", - "get_tf_storage_size", "get_token", "get_torch_storage_id", "get_torch_storage_size", @@ -1492,7 +1490,6 @@ def __dir__(): ) from .serialization import ( StateDictSplit, # noqa: F401 - get_tf_storage_size, # noqa: F401 get_torch_storage_id, # noqa: F401 get_torch_storage_size, # noqa: F401 load_state_dict_from_file, # noqa: F401 From 7e30169079c2d9e56a50879dc7da6205f1d50a29 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Fri, 12 Sep 2025 13:54:34 +0200 Subject: [PATCH 3/4] fix tests --- tests/test_utils_headers.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/tests/test_utils_headers.py b/tests/test_utils_headers.py index 3ebae72c6a..849b9f063a 100644 --- a/tests/test_utils_headers.py +++ b/tests/test_utils_headers.py @@ -64,37 +64,19 @@ class TestUserAgentHeadersUtil(unittest.TestCase): def _get_user_agent(self, **kwargs) -> str: return build_hf_headers(**kwargs)["user-agent"] - @patch("huggingface_hub.utils._headers.get_fastai_version") - @patch("huggingface_hub.utils._headers.get_fastcore_version") - @patch("huggingface_hub.utils._headers.get_tf_version") @patch("huggingface_hub.utils._headers.get_torch_version") - @patch("huggingface_hub.utils._headers.is_fastai_available") - @patch("huggingface_hub.utils._headers.is_fastcore_available") - @patch("huggingface_hub.utils._headers.is_tf_available") @patch("huggingface_hub.utils._headers.is_torch_available") @handle_injection_in_test def test_default_user_agent( self, - mock_get_fastai_version: Mock, - mock_get_fastcore_version: Mock, - mock_get_tf_version: Mock, mock_get_torch_version: Mock, - mock_is_fastai_available: Mock, - mock_is_fastcore_available: Mock, - mock_is_tf_available: Mock, mock_is_torch_available: Mock, ) -> None: - mock_get_fastai_version.return_value = "fastai_version" - mock_get_fastcore_version.return_value = "fastcore_version" - mock_get_tf_version.return_value = "tf_version" mock_get_torch_version.return_value = "torch_version" - mock_is_fastai_available.return_value = True - mock_is_fastcore_available.return_value = True - mock_is_tf_available.return_value = True mock_is_torch_available.return_value = True self.assertEqual( self._get_user_agent(), - f"unknown/None; hf_hub/{get_hf_hub_version()}; python/{get_python_version()}; torch/torch_version;", + f"unknown/None; hf_hub/{get_hf_hub_version()}; python/{get_python_version()}; torch/torch_version", ) @patch("huggingface_hub.utils._headers.is_torch_available") From 4c7030088bc4db3542518cc4b9a73ae945087302 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Fri, 12 Sep 2025 14:18:12 +0200 Subject: [PATCH 4/4] fix conflicts in tests --- tests/test_hf_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py index bbd8decff1..935bdbb1d4 100644 --- a/tests/test_hf_api.py +++ b/tests/test_hf_api.py @@ -207,11 +207,10 @@ def test_delete_repo_missing_ok(self) -> None: self._api.delete_repo("repo-that-does-not-exist", missing_ok=True) def test_move_repo_normal_usage(self): - repo_id = f"{USER}/{repo_name()}" - new_repo_id = f"{USER}/{repo_name()}" - # Spaces not tested on staging (error 500) for repo_type in [None, constants.REPO_TYPE_MODEL, constants.REPO_TYPE_DATASET]: + repo_id = f"{USER}/{repo_name()}" + new_repo_id = f"{USER}/{repo_name()}" self._api.create_repo(repo_id=repo_id, repo_type=repo_type) self._api.move_repo(from_id=repo_id, to_id=new_repo_id, repo_type=repo_type) self._api.delete_repo(repo_id=new_repo_id, repo_type=repo_type)