MOSS icon indicating copy to clipboard operation
MOSS copied to clipboard

部署报错提示 module 'torch' has no attribute 'float32'

Open zengxs opened this issue 2 years ago • 3 comments

严格按照 README 教程操作的,环境是 ananconda + python3.8,显卡是 A100 80G 版

依赖也是仓库中 requirements.txt 中的版本,但是运行到第三步的时候报错

Python 3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 16:01:55)
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
>>> tokenizer = AutoTokenizer.from_pretrained("fnlp/moss-moon-003-sft", trust_remote_code=True)
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
>>> model = AutoModelForCausalLM.from_pretrained("fnlp/moss-moon-003-sft", trust_remote_code=True).half().cuda()
Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/conda-envs/moss/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py", line 441, in from_pretrained
    config, kwargs = AutoConfig.from_pretrained(
  File "/mnt/conda-envs/moss/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py", line 935, in from_pretrained
    return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
  File "/mnt/conda-envs/moss/lib/python3.8/site-packages/transformers/configuration_utils.py", line 553, in from_pretrained
    return cls.from_dict(config_dict, **kwargs)
  File "/mnt/conda-envs/moss/lib/python3.8/site-packages/transformers/configuration_utils.py", line 696, in from_dict
    config = cls(**config_dict)
  File "/home/almalinux/.cache/huggingface/modules/transformers_modules/moss-moon-003-sft/configuration_moss.py", line 116, in __init__
    super().__init__(
  File "/mnt/conda-envs/moss/lib/python3.8/site-packages/transformers/configuration_utils.py", line 338, in __init__
    self.torch_dtype = getattr(torch, self.torch_dtype)
AttributeError: module 'torch' has no attribute 'float32'

zengxs avatar Apr 25 '23 13:04 zengxs

检查一下你的pytorch版本,或者手动测试一下torch_dtype = getattr(torch, 'float32')是不是会报错?

xyltt avatar Apr 25 '23 15:04 xyltt

检查一下你的pytorch版本,或者手动测试一下torch_dtype = getattr(torch, 'float32')是不是会报错?

你好,下面是检查结果:

torch 版本检查:(点击展开)
$ pip freeze
accelerate==0.18.0
aiofiles==23.1.0
aiohttp==3.8.4
aiosignal==1.3.1
altair==4.2.2
anyio==3.6.2
async-timeout==4.0.2
attrs==23.1.0
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
contourpy==1.0.7
cycler==0.11.0
datasets==2.11.0
dill==0.3.6
entrypoints==0.4
fastapi==0.95.1
ffmpy==0.3.0
filelock==3.12.0
fonttools==4.39.3
frozenlist==1.3.3
fsspec==2023.4.0
gradio==3.27.0
gradio_client==0.1.3
h11==0.14.0
httpcore==0.17.0
httpx==0.24.0
huggingface-hub==0.14.0
idna==3.4
importlib-resources==5.12.0
Jinja2==3.1.2
jsonschema==4.17.3
kiwisolver==1.4.4
linkify-it-py==2.0.0
markdown-it-py==2.2.0
MarkupSafe==2.1.2
matplotlib==3.7.1
mdit-py-plugins==0.3.3
mdurl==0.1.2
multidict==6.0.4
multiprocess==0.70.14
numpy==1.24.3
orjson==3.8.10
packaging==23.1
pandas==2.0.1
Pillow==9.5.0
pkgutil_resolve_name==1.3.10
psutil==5.9.5
pyarrow==11.0.0
pydantic==1.10.7
pydub==0.25.1
pyparsing==3.0.9
pyrsistent==0.19.3
python-dateutil==2.8.2
python-multipart==0.0.6
pytz==2023.3
PyYAML==6.0
regex==2023.3.23
requests==2.28.2
responses==0.18.0
semantic-version==2.10.0
sentencepiece==0.1.98
six==1.16.0
sniffio==1.3.0
starlette==0.26.1
tokenizers==0.13.3
toolz==0.12.0
torch==1.10.1
torchtext==0.2.3
tqdm==4.65.0
transformers==4.28.1
typing_extensions==4.5.0
tzdata==2023.3
uc-micro-py==1.0.1
urllib3==1.26.15
uvicorn==0.21.1
websockets==11.0.2
xxhash==3.2.0
yarl==1.9.1
zipp==3.15.0
手动测试 torch_dtype:(点击展开)
Python 3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 16:01:55)
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch_dtype = getattr(torch, 'float32')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'torch' has no attribute 'float32'

zengxs avatar Apr 26 '23 09:04 zengxs

I met this problem before, maybe you should try to re-install the torchtext module.

Lum1104 avatar Apr 27 '23 02:04 Lum1104