需要用到一个2022年的库,然后根据他的需求安装环境,结果报了以下两个错误
这个库:
- https://github.com/rajpurkarlab/CXR-Report-Metric
使用下面的命令安装环境(官方建议3.7的python):
conda create --name cxr python=3.7
conda install -c conda-forge \allennlp \allennlp-models \datasets \beautifulsoup4 \bert_score \lxml \numpy \pandas \python-levenshtein \optuna \scikit-learn \statsmodels \tqdm \transformers \tokenizers -y
报错1:
Traceback (most recent call last):File "/home/Guanjq/Work/RadCLIQ-CXR/test_metric.py", line 6, in <module>from CXRMetric.run_eval import calc_metricFile "/home/Guanjq/Work/RadCLIQ-CXR/CXRMetric/run_eval.py", line 7, in <module>import torchFile "/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/torch/__init__.py", line 199, in <module>from torch._C import * # noqa: F403
ImportError: /mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/pyarrow/../../../libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
GPT分析如下:
根据您提供的错误信息,您当前遇到的问题主要包括以下几个方面:
- GLIBCXX_3.4.30 版本缺失:这通常是由于系统的 libstdc++.so.6 库版本过低,无法满足 PyTorch 的依赖要求。
- CUDA 版本不兼容:您的系统安装了 CUDA 12.1,但当前的 PyTorch 安装版本可能不支持该 CUDA 版本,导致在使用 NVIDIA GeForce RTX 3090 GPU 时出现兼容性警告。
报错2:
运行命令之后,一直卡着不动,GPT说是不兼容3090显卡,然后报错:
(cxrmetric) Guanjq@server-L20-8:/home/Guanjq$ python /home/Guanjq/Work/RadCLIQ-CXR/test_metric.py/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/torch/cuda/__init__.py:145: UserWarning:
NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_35 sm_50 sm_60 sm_61 sm_70 sm_75 compute_75.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))
GPT这里说是警告,然后不支持3090,所以是CPU运行,其实不是卡着,而是运行太慢。
所以我们要怎么解决不能用3090加速这个问题
python 3.7 不能用torch 2.0.1
报错如下:
(cxr3) Guanjq@server-L20-8:/home/Guanjq$ pip install torch==2.0.1+cu121 torchvision==0.15.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://download.pytorch.org/whl/cu121
ERROR: Could not find a version that satisfies the requirement torch==2.0.1+cu121 (from versions: 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2, 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0, 2.0.1, 2.1.0, 2.1.0+cu121, 2.1.1, 2.1.1+cu121, 2.1.2, 2.1.2+cu121, 2.2.0, 2.2.0+cu121, 2.2.1, 2.2.1+cu121, 2.2.2, 2.2.2+cu121, 2.3.0, 2.3.0+cu121, 2.3.1, 2.3.1+cu121, 2.4.0, 2.4.0+cu121, 2.4.1, 2.4.1+cu121)
ERROR: No matching distribution found for torch==2.0.1+cu121
az,我发现还是只能安装torch=1.6,但是因为conda安装他是没有cuda的,所以要自己手动安装。。。。太久没配环境,脑子有点不好使了。
然后python3.7还有挺多坑的,比如:
(1)typing没有Literal
还有问题
这个库实在是难用,环境实在是难配
首先不说torch
就是transformers库的版本都很怪
我用官方环境,报错误如下 (加载不了模型,因为transofmers版本太低):
Traceback (most recent call last):File "/home/Guanjq/Work/CXR-Report-Metric/test_metric.py", line 22, in <module>calc_metric(gt_reports, predicted_reports, out_file, use_idf)File "/home/Guanjq/Work/CXR-Report-Metric/CXRMetric/run_eval.py", line 190, in calc_metricpred = add_bertscore_col(gt, pred, use_idf)File "/home/Guanjq/Work/CXR-Report-Metric/CXRMetric/run_eval.py", line 108, in add_bertscore_colidf_sents=test_reports)File "/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/bert_score/scorer.py", line 101, in __init__self._model = get_model(self.model_type, self.num_layers, self.all_layers)File "/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/bert_score/utils.py", line 205, in get_modelmodel = AutoModel.from_pretrained(model_type)File "/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/transformers/modeling_auto.py", line 502, in from_pretrainedreturn model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)File "/mnt/Guanjq/miniconda3/envs/cxrmetric/lib/python3.7/site-packages/transformers/modeling_utils.py", line 662, in from_pretrainedraise EnvironmentError(msg)
OSError: Can't load weights for 'roberta-large'. Make sure that:- 'roberta-large' is a correct model identifier listed on 'https://huggingface.co/models'- or 'roberta-large' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.
上面这个问题只能使用网络出国的方式解决,就是设置了 HF_ENDPOINT="https://hf-mirror.com"都没用。因为他直接去 'https://huggingface.co/models’搜索。。。
如果我用conda自动配的,allennlp=2.*,就又太高了,他只能在allennlp=1.1.0上面跑
贼坑。
还有问题-2
ok,之前的问题翻墙解决了。
那么又回来这个 torch=1.6无法运行的问题了我擦
Traceback (most recent call last):File "/home/Guanjq/Work/CXR-Report-Metric/test_metric.py", line 22, in <module>calc_metric(gt_reports, predicted_reports, out_file, use_idf)File "/home/Guanjq/Work/CXR-Report-Metric/CXRMetric/run_eval.py", line 190, in calc_metricpred = add_bertscore_col(gt, pred, use_idf)File "/home/Guanjq/Work/CXR-Report-Metric/CXRMetric/run_eval.py", line 109, in add_bertscore_col_, _, f1 = scorer.score(method_reports, test_reports)File "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/bert_score/scorer.py", line 222, in scoreall_layers=self.all_layers,File "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/bert_score/utils.py", line 529, in bert_cos_score_idfsen_batch, model, tokenizer, idf_dict, device=device, all_layers=all_layersFile "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/bert_score/utils.py", line 408, in get_bert_embeddingmodel, padded_sens[i : i + batch_size], attention_mask=mask[i : i + batch_size], all_layers=all_layers,File "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/bert_score/utils.py", line 318, in bert_encodeout = model(x, attention_mask=attention_mask, output_hidden_states=all_layers)File "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_implresult = self.forward(*input, **kwargs)File "/mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages/transformers/modeling_bert.py", line 728, in forwardtoken_type_ids = torch.zeros(input_shape, dtype=torch.long, device=device)
RuntimeError: CUDA error: no kernel image is available for execution on the device
(cxr3) Guanjq@server-L20-8:/home/Guanjq$ pip show torch
Name: torch
Version: 1.6.0+cu101
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /mnt/Guanjq/miniconda3/envs/cxr3/lib/python3.7/site-packages
Requires: future, numpy
Required-by: allennlp, bert-score, torchvision
但是我返回的是True
Python 3.7.16 (default, Jan 17 2023, 22:20:44)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
呃呃呃呃呃呃呃呃呃呃呃
我发现3090只支持CUDA1.11以上的
所以我下载了
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
尽管报错:
allennlp need torch<1.7
但是我安装了1.11也能够强行运行xxxxxxxxxxxx
我的评价是根据这个配置安装
conda创建python3.7版本
(1)首先是官方配置,你先安装一遍,我去掉了torch
allennlp==1.1.0
allennlp_models==1.1.0
beautifulsoup4==4.8.1
bert-score==0.3.11
fast-bleu==0.0.90
lxml
numpy==1.18.2
pandas==1.0.1
python-Levenshtein
optuna>=2.1.0
scikit-learn==0.22.1
statsmodels==0.13.0
torch==1.6.0
tqdm==4.38.0
transformers==3.0.1
tokenizers==0.8.0-rc4
在这个时候如果出现了什么错误,就根据错误解决就行
(2)然后安装torch
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
最后网络出国运行xxx