ValueError:4.39.0.dev0 不是有效的 SemVer 字符串

问题描述 投票:0回答:1

我的代码中出现以下错误

ValueError: 4.39.0.dev0 is not valid SemVer string

from GLiNER.gliner_ner import GlinerNER

gli = GlinerNER()

完整的错误消息:

File ~/.../GLiNER/gliner_ner.py:8, in GlinerNER.__init__(self, labels)
      7 def __init__(self, labels = ["date","time", "club", "league"]):
----> 8     self.model = GLiNER.from_pretrained("urchade/gliner_base")
      9     self.labels = labels

File /opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:118, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    115 if check_use_auth_token:
    116     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 118 return fn(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/huggingface_hub/hub_mixin.py:157, in ModelHubMixin.from_pretrained(cls, pretrained_model_name_or_path, force_download, resume_download, proxies, token, cache_dir, local_files_only, revision, **model_kwargs)
    154         config = json.load(f)
    155     model_kwargs.update({"config": config})
--> 157 return cls._from_pretrained(
    158     model_id=str(model_id),
    159     revision=revision,
    160     cache_dir=cache_dir,
    161     force_download=force_download,
    162     proxies=proxies,
    163     resume_download=resume_download,
    164     local_files_only=local_files_only,
    165     token=token,
    166     **model_kwargs,
    167 )

File ~/.../GLiNER/model.py:355, in GLiNER._from_pretrained(cls, model_id, revision, cache_dir, force_download, proxies, resume_download, local_files_only, token, map_location, strict, **model_kwargs)
    353 model = cls(config)
    354 state_dict = torch.load(model_file, map_location=torch.device(map_location))
--> 355 model.load_state_dict(state_dict, strict=strict, 
    356                       #assign=True
    357                      )
    358 model.to(map_location)
    359 return model

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:2027, in Module.load_state_dict(self, state_dict, strict)
   2020         out = hook(module, incompatible_keys)
   2021         assert out is None, (
   2022             "Hooks registered with ``register_load_state_dict_post_hook`` are not"
   2023             "expected to return new values, if incompatible_keys need to be modified,"
   2024             "it should be done inplace."
   2025         )
-> 2027 load(self, state_dict)
   2028 del load
   2030 if strict:

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:2015, in Module.load_state_dict.<locals>.load(module, local_state_dict, prefix)
   2013         child_prefix = prefix + name + '.'
   2014         child_state_dict = {k: v for k, v in local_state_dict.items() if k.startswith(child_prefix)}
-> 2015         load(child, child_state_dict, child_prefix)
   2017 # Note that the hook can modify missing_keys and unexpected_keys.
   2018 incompatible_keys = _IncompatibleKeys(missing_keys, unexpected_keys)

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:2015, in Module.load_state_dict.<locals>.load(module, local_state_dict, prefix)
   2013         child_prefix = prefix + name + '.'
   2014         child_state_dict = {k: v for k, v in local_state_dict.items() if k.startswith(child_prefix)}
-> 2015         load(child, child_state_dict, child_prefix)
   2017 # Note that the hook can modify missing_keys and unexpected_keys.
   2018 incompatible_keys = _IncompatibleKeys(missing_keys, unexpected_keys)

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:2009, in Module.load_state_dict.<locals>.load(module, local_state_dict, prefix)
   2007 def load(module, local_state_dict, prefix=''):
   2008     local_metadata = {} if metadata is None else metadata.get(prefix[:-1], {})
-> 2009     module._load_from_state_dict(
   2010         local_state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs)
   2011     for name, child in module._modules.items():
   2012         if child is not None:

File /opt/conda/lib/python3.10/site-packages/flair/embeddings/transformer.py:1166, in TransformerEmbeddings._load_from_state_dict(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs)
   1163 def _load_from_state_dict(
   1164     self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs
   1165 ):
-> 1166     if transformers.__version__ >= Version(4, 31, 0):
   1167         assert isinstance(state_dict, dict)
   1168         state_dict.pop(f"{prefix}model.embeddings.position_ids", None)

File /opt/conda/lib/python3.10/site-packages/semver/version.py:51, in _comparator.<locals>.wrapper(self, other)
     49 if not isinstance(other, comparable_types):
     50     return NotImplemented
---> 51 return operator(self, other)

File /opt/conda/lib/python3.10/site-packages/semver/version.py:481, in Version.__le__(self, other)
    479 @_comparator
    480 def __le__(self, other: Comparable) -> bool:
--> 481     return self.compare(other) <= 0

File /opt/conda/lib/python3.10/site-packages/semver/version.py:396, in Version.compare(self, other)
    394 cls = type(self)
    395 if isinstance(other, String.__args__):  # type: ignore
--> 396     other = cls.parse(other)
    397 elif isinstance(other, dict):
    398     other = cls(**other)

File /opt/conda/lib/python3.10/site-packages/semver/version.py:646, in Version.parse(cls, version, optional_minor_and_patch)
    644     match = cls._REGEX.match(version)
    645 if match is None:
--> 646     raise ValueError(f"{version} is not valid SemVer string")
    648 matched_version_parts: Dict[str, Any] = match.groupdict()
    649 if not matched_version_parts["minor"]:

ValueError: 4.39.0.dev0 is not valid SemVer string

这是变压器版本:

Name: transformers
Version: 4.38.2
Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow
Home-page: https://github.com/huggingface/transformers
Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
Author-email: [email protected]
License: Apache 2.0 License
Location: /opt/conda/lib/python3.10/site-packages
Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm
Required-by: flair, sentence-transformers, transformer-smaller-training-vocab
Note: you may need to restart the kernel to use updated packages.

不知道是什么原因,希望大家帮忙查找原因。

提前致谢。

python pytorch huggingface-transformers large-language-model huggingface
1个回答
0
投票

可能与您的默认 python 环境中的依赖项存在一些冲突。您应该为 GliNER 创建一个 python 环境 (>=3.8) 并为项目安装以下依赖项,如 repo

中所示

!pip install torch transformers huggingface_hub flair seqeval tqdm

© www.soinside.com 2019 - 2024. All rights reserved.