ValueError: 4.39.0.dev0 不是有效的 SemVer 字符串
我在代码中遇到了一个错误,错误信息是 ValueError: 4.39.0.dev0 不是一个有效的 SemVer 字符串
:
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: transformers@huggingface.co
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.
我不知道这个错误的原因是什么,希望你们能帮我找出原因。
提前谢谢你们。
1 个回答
0
你的默认Python环境可能有一些依赖冲突。建议你为GliNER创建一个新的Python环境(版本要在3.8及以上),然后按照项目要求安装下面这些依赖,具体可以在这个链接中找到。
!pip install torch transformers huggingface_hub flair seqeval tqdm