Skip to content

Commit ef3fcbb

Browse files
authored
Remove all local telemetry (#1702)
1 parent 7c823c2 commit ef3fcbb

File tree

6 files changed

+5
-60
lines changed

6 files changed

+5
-60
lines changed

docs/source/installation.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ Our library gathers telemetry information during `from_pretrained()` requests.
127127
This data includes the version of Diffusers and PyTorch/Flax, the requested model or pipeline class,
128128
and the path to a pretrained checkpoint if it is hosted on the Hub.
129129
This usage data helps us debug issues and prioritize new features.
130-
No private data, such as paths to models saved locally on disk, is ever collected.
130+
Telemetry is only sent when loading models and pipelines from the HuggingFace Hub,
131+
and is not collected during local usage.
131132

132133
We understand that not everyone wants to share additional information, and we respect your privacy,
133134
so you can disable telemetry collection by setting the `DISABLE_TELEMETRY` environment variable from your terminal:

src/diffusers/hub_utils.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from typing import Dict, Optional, Union
2121
from uuid import uuid4
2222

23-
import requests
2423
from huggingface_hub import HfFolder, whoami
2524

2625
from . import __version__
@@ -56,7 +55,7 @@ def http_user_agent(user_agent: Union[Dict, str, None] = None) -> str:
5655
Formats a user-agent string with basic info about a request.
5756
"""
5857
ua = f"diffusers/{__version__}; python/{sys.version.split()[0]}; session_id/{SESSION_ID}"
59-
if DISABLE_TELEMETRY:
58+
if DISABLE_TELEMETRY or HF_HUB_OFFLINE:
6059
return ua + "; telemetry/off"
6160
if is_torch_available():
6261
ua += f"; torch/{_torch_version}"
@@ -75,27 +74,6 @@ def http_user_agent(user_agent: Union[Dict, str, None] = None) -> str:
7574
return ua
7675

7776

78-
def send_telemetry(data: Dict, name: str):
79-
"""
80-
Sends logs to the Hub telemetry endpoint.
81-
82-
Args:
83-
data: the fields to track, e.g. {"example_name": "dreambooth"}
84-
name: a unique name to differentiate the telemetry logs, e.g. "diffusers_examples" or "diffusers_notebooks"
85-
"""
86-
if DISABLE_TELEMETRY or HF_HUB_OFFLINE:
87-
return
88-
89-
headers = {"user-agent": http_user_agent(data)}
90-
endpoint = HUGGINGFACE_CO_TELEMETRY + name
91-
try:
92-
r = requests.head(endpoint, headers=headers)
93-
r.raise_for_status()
94-
except Exception:
95-
# We don't want to error in case of connection errors of any kind.
96-
pass
97-
98-
9977
def get_full_repo_name(model_id: str, organization: Optional[str] = None, token: Optional[str] = None):
10078
if token is None:
10179
token = HfFolder.get_token()

src/diffusers/modeling_flax_utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from requests import HTTPError
2929

3030
from . import __version__, is_torch_available
31-
from .hub_utils import send_telemetry
3231
from .modeling_flax_pytorch_utils import convert_pytorch_state_dict_to_flax
3332
from .utils import (
3433
CONFIG_NAME,
@@ -340,10 +339,6 @@ def from_pretrained(
340339
f"Error no file named {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory "
341340
f"{pretrained_path_with_subfolder}."
342341
)
343-
send_telemetry(
344-
{"model_class": cls.__name__, "model_path": "local", "framework": "flax"},
345-
name="diffusers_from_pretrained",
346-
)
347342
else:
348343
try:
349344
model_file = hf_hub_download(
@@ -359,10 +354,6 @@ def from_pretrained(
359354
subfolder=subfolder,
360355
revision=revision,
361356
)
362-
send_telemetry(
363-
{"model_class": cls.__name__, "model_path": "hub", "framework": "flax"},
364-
name="diffusers_from_pretrained",
365-
)
366357

367358
except RepositoryNotFoundError:
368359
raise EnvironmentError(

src/diffusers/modeling_utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from requests import HTTPError
2727

2828
from . import __version__
29-
from .hub_utils import send_telemetry
3029
from .utils import (
3130
CONFIG_NAME,
3231
DIFFUSERS_CACHE,
@@ -594,10 +593,6 @@ def _get_model_file(
594593
raise EnvironmentError(
595594
f"Error no file named {weights_name} found in directory {pretrained_model_name_or_path}."
596595
)
597-
send_telemetry(
598-
{"model_class": cls.__name__, "model_path": "local", "framework": "pytorch"},
599-
name="diffusers_from_pretrained",
600-
)
601596
return model_file
602597
else:
603598
try:
@@ -615,10 +610,6 @@ def _get_model_file(
615610
subfolder=subfolder,
616611
revision=revision,
617612
)
618-
send_telemetry(
619-
{"model_class": cls.__name__, "model_path": "hub", "framework": "pytorch"},
620-
name="diffusers_from_pretrained",
621-
)
622613
return model_file
623614

624615
except RepositoryNotFoundError:

src/diffusers/pipeline_flax_utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from tqdm.auto import tqdm
3030

3131
from .configuration_utils import ConfigMixin
32-
from .hub_utils import http_user_agent, send_telemetry
32+
from .hub_utils import http_user_agent
3333
from .modeling_flax_utils import FLAX_WEIGHTS_NAME, FlaxModelMixin
3434
from .schedulers.scheduling_utils_flax import SCHEDULER_CONFIG_NAME, FlaxSchedulerMixin
3535
from .utils import CONFIG_NAME, DIFFUSERS_CACHE, BaseOutput, is_transformers_available, logging
@@ -346,16 +346,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
346346
ignore_patterns=ignore_patterns,
347347
user_agent=user_agent,
348348
)
349-
send_telemetry(
350-
{"pipeline_class": requested_pipeline_class, "pipeline_path": "hub", "framework": "flax"},
351-
name="diffusers_from_pretrained",
352-
)
353349
else:
354350
cached_folder = pretrained_model_name_or_path
355-
send_telemetry(
356-
{"pipeline_class": cls.__name__, "pipeline_path": "local", "framework": "flax"},
357-
name="diffusers_from_pretrained",
358-
)
359351

360352
config_dict = cls.load_config(cached_folder)
361353

src/diffusers/pipeline_utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from .configuration_utils import ConfigMixin
3535
from .dynamic_modules_utils import get_class_from_dynamic_module
36-
from .hub_utils import http_user_agent, send_telemetry
36+
from .hub_utils import http_user_agent
3737
from .modeling_utils import _LOW_CPU_MEM_USAGE_DEFAULT
3838
from .schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
3939
from .utils import (
@@ -509,16 +509,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
509509
ignore_patterns=ignore_patterns,
510510
user_agent=user_agent,
511511
)
512-
send_telemetry(
513-
{"pipeline_class": requested_pipeline_class, "pipeline_path": "hub", "framework": "pytorch"},
514-
name="diffusers_from_pretrained",
515-
)
516512
else:
517513
cached_folder = pretrained_model_name_or_path
518-
send_telemetry(
519-
{"pipeline_class": cls.__name__, "pipeline_path": "local", "framework": "pytorch"},
520-
name="diffusers_from_pretrained",
521-
)
522514

523515
config_dict = cls.load_config(cached_folder)
524516

0 commit comments

Comments
 (0)