Open
Description
Describe the bug
When using AutoModelForSequenceClassification.from_pretrained
to download a model I got the following.
OSError: distilbert-base-uncased does not appear to have a file named pytorch_model.bin but there is a file for TensorFlow weights. Use `from_tf=True` to load this model from those weights.
.venv/lib/python3.12/site-packages/transformers/modeling_utils.
This seems to indicate that I needed to specify from_tf=True
but that was already set.
After much digging I found the issue was I had an older version of hf-xet
, specifically 1.0.0
.
This passes the is_package_available
used by is_xet_available
but then when xet_get is called it tries to load the dependency and fails, resulting in the above message.
Reproduction
Run the following with hf-xet v1.0.0 installed.
from transformers.models.auto.modeling_auto import AutoModelForSequenceClassification
AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased", from_tf=True)
Logs
.venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py:571: in from_pretrained
return model_class.from_pretrained(
.venv/lib/python3.12/site-packages/transformers/modeling_utils.py:279: in _wrapper
return func(*args, **kwargs)
.venv/lib/python3.12/site-packages/transformers/modeling_utils.py:4260: in from_pretrained
checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pretrained_model_name_or_path = 'distilbert-base-uncased', subfolder = ''
variant = None, gguf_file = None, from_tf = True, from_flax = False
use_safetensors = None, cache_dir = None, force_download = False, proxies = None
local_files_only = False, token = None
user_agent = {'file_type': 'model', 'framework': 'pytorch', 'from_auto_class': False}
revision = 'main', commit_hash = '12040accade4e8a0f71eabdb258fecc2e7e948be'
def _get_resolved_checkpoint_files(
pretrained_model_name_or_path: Optional[Union[str, os.PathLike]],
subfolder: str,
variant: Optional[str],
gguf_file: Optional[str],
from_tf: bool,
from_flax: bool,
use_safetensors: bool,
cache_dir: str,
force_download: bool,
proxies: Optional[Dict[str, str]],
local_files_only: bool,
token: Optional[Union[str, bool]],
user_agent: dict,
revision: str,
commit_hash: Optional[str],
) -> Tuple[Optional[List[str]], Optional[Dict]]:
"""Get all the checkpoint filenames based on `pretrained_model_name_or_path`, and optional metadata if the
checkpoints are sharded.
This function will download the data if necesary.
"""
is_sharded = False
if pretrained_model_name_or_path is not None and gguf_file is None:
pretrained_model_name_or_path = str(pretrained_model_name_or_path)
is_local = os.path.isdir(pretrained_model_name_or_path)
if is_local:
if from_tf and os.path.isfile(
os.path.join(pretrained_model_name_or_path, subfolder, TF_WEIGHTS_NAME + ".index")
):
# Load from a TF 1.0 checkpoint in priority if from_tf
archive_file = os.path.join(pretrained_model_name_or_path, subfolder, TF_WEIGHTS_NAME + ".index")
elif from_tf and os.path.isfile(os.path.join(pretrained_model_name_or_path, subfolder, TF2_WEIGHTS_NAME)):
# Load from a TF 2.0 checkpoint in priority if from_tf
archive_file = os.path.join(pretrained_model_name_or_path, subfolder, TF2_WEIGHTS_NAME)
elif from_flax and os.path.isfile(
os.path.join(pretrained_model_name_or_path, subfolder, FLAX_WEIGHTS_NAME)
):
# Load from a Flax checkpoint in priority if from_flax
archive_file = os.path.join(pretrained_model_name_or_path, subfolder, FLAX_WEIGHTS_NAME)
elif use_safetensors is not False and os.path.isfile(
os.path.join(pretrained_model_name_or_path, subfolder, _add_variant(SAFE_WEIGHTS_NAME, variant))
):
cached_file_kwargs = {
"cache_dir": cache_dir,
"force_download": force_download,
"local_files_only": local_files_only,
"user_agent": user_agent,
"subfolder": subfolder,
"_raise_exceptions_for_gated_repo": False,
"_raise_exceptions_for_missing_entries": False,
"_commit_hash": commit_hash,
**has_file_kwargs,
}
if not has_file(pretrained_model_name_or_path, safe_weights_name, **has_file_kwargs):
Thread(
target=auto_conversion,
args=(pretrained_model_name_or_path,),
kwargs={"ignore_errors_during_conversion": True, **cached_file_kwargs},
name="Thread-auto_conversion",
).start()
else:
# Otherwise, no PyTorch file was found, maybe there is a TF or Flax model file.
# We try those to give a helpful error message.
has_file_kwargs = {
"revision": revision,
"proxies": proxies,
"token": token,
"cache_dir": cache_dir,
"local_files_only": local_files_only,
}
if has_file(pretrained_model_name_or_path, TF2_WEIGHTS_NAME, **has_file_kwargs):
> raise EnvironmentError(
f"{pretrained_model_name_or_path} does not appear to have a file named"
f" {_add_variant(WEIGHTS_NAME, variant)} but there is a file for TensorFlow weights."
" Use `from_tf=True` to load this model from those weights."
E OSError: distilbert-base-uncased does not appear to have a file named pytorch_model.bin but there is a file for TensorFlow weights. Use `from_tf=True` to load this model from those weights.
.venv/lib/python3.12/site-packages/transformers/modeling_utils.py:1080: OSError
System info
huggingface-cli env
Copy-and-paste the text below in your GitHub issue.
- huggingface_hub version: 0.31.2
- Platform: macOS-15.5-arm64-arm-64bit
- Python version: 3.12.9
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Running in Google Colab Enterprise ?: No
- Token path ?: /Users/steve/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers: osxkeychain
- FastAI: N/A
- Tensorflow: N/A
- Torch: 2.7.0
- Jinja2: 3.1.6
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: 10.4.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 2.2.5
- pydantic: 2.11.4
- aiohttp: 3.11.18
- hf_xet: 1.0.0
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /Users/steve/.cache/huggingface/hub
- HF_ASSETS_CACHE: /Users/steve/.cache/huggingface/assets
- HF_TOKEN_PATH: /Users/steve/.cache/huggingface/token
- HF_STORED_TOKENS_PATH: /Users/steve/.cache/huggingface/stored_tokens
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10