Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用官方huggingface代码推理报错 #108

Open
seanzhang-zhichen opened this issue Feb 1, 2024 · 4 comments
Open

使用官方huggingface代码推理报错 #108

seanzhang-zhichen opened this issue Feb 1, 2024 · 4 comments

Comments

@seanzhang-zhichen
Copy link

image
报错

@zhaoxudong01
Copy link
Collaborator

#72

@seanzhang-zhichen
Copy link
Author

#72

没有用的,我的代码:

` tokenizer = LlamaTokenizer.from_pretrained(model_path, add_eos_token=False, add_bos_token=False, eos_token='', trust_remote_code=True)
tokenizer.add_tokens(['', '', '', '', '<FIM_SUFFIX>', '<FIM_PREFIX>', '<FIM_MIDDLE>','<commit_before>','<commit_msg>','<commit_after>','<jupyter_start>','<jupyter_text>','<jupyter_code>','<jupyter_output>','<empty_output>'], special_tokens=True)
print("Creat model...")
model = AutoModelForCausalLM.from_pretrained(model_path, device_map='auto', torch_dtype=torch.bfloat16, trust_remote_code=True)

`

@zhaoxudong01
Copy link
Collaborator

看到你应该是离线使用的hf模型,离线使用可以参考在模型目录执行下面的脚本

import torch, transformers
import sys, os
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from transformers import AutoModelForCausalLM,AutoTokenizer,LlamaTokenizer
from yuan_hf_model import YuanForCausalLM
torch.set_printoptions(precision=12)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
print("Creat tokenizer...")
tokenizer = LlamaTokenizer.from_pretrained('./', add_eos_token=False, add_bos_token=False)
tokenizer.add_tokens(['<sep>', '<pad>', '<mask>', '<predict>', '<FIM_SUFFIX>', '<FIM_PREFIX>', '<FIM_MIDDLE>','<commit_before>','<commit_msg>','<commit_after>','<jupyter_start>','<jupyter_text>','<jupyter_code>','<jupyter_output>','<empty_output>'], special_tokens=True)

print("Creat model...")
input_text = ['请问目前最先进的机器学习算法有哪些?<sep>']
inputs = tokenizer(input_text, return_tensors="pt")["input_ids"].to("cuda:0")

model = YuanForCausalLM.from_pretrained('./',device_map='auto',torch_dtype=torch.half,trust_remote_code=True)
outputs = model.generate(inputs,do_sample=False,max_length=100)
print(tokenizer.decode(outputs[0]))
# 请问目前最先进的机器学习算法有哪些?<sep> 目前最先进的机器学习算法包括以下几种:\n1. 卷积神经网络(Convolutional Neural Networks,CNN):CNN是近年来在图像处理领域中广泛应用的一种神经网络,包含卷积层、池化层和全连接层,训练时需要大量标注数据以及自我调整参数。\n2. 循环神经网络(Recurrent Neural Networks,RNN):RNN指的是信息流模型,能够处理序列数据,

@seanzhang-zhichen
Copy link
Author

看到你应该是离线使用的hf模型,离线使用可以参考在模型目录执行下面的脚本

import torch, transformers
import sys, os
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from transformers import AutoModelForCausalLM,AutoTokenizer,LlamaTokenizer
from yuan_hf_model import YuanForCausalLM
torch.set_printoptions(precision=12)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
print("Creat tokenizer...")
tokenizer = LlamaTokenizer.from_pretrained('./', add_eos_token=False, add_bos_token=False)
tokenizer.add_tokens(['<sep>', '<pad>', '<mask>', '<predict>', '<FIM_SUFFIX>', '<FIM_PREFIX>', '<FIM_MIDDLE>','<commit_before>','<commit_msg>','<commit_after>','<jupyter_start>','<jupyter_text>','<jupyter_code>','<jupyter_output>','<empty_output>'], special_tokens=True)

print("Creat model...")
input_text = ['请问目前最先进的机器学习算法有哪些?<sep>']
inputs = tokenizer(input_text, return_tensors="pt")["input_ids"].to("cuda:0")

model = YuanForCausalLM.from_pretrained('./',device_map='auto',torch_dtype=torch.half,trust_remote_code=True)
outputs = model.generate(inputs,do_sample=False,max_length=100)
print(tokenizer.decode(outputs[0]))
# 请问目前最先进的机器学习算法有哪些?<sep> 目前最先进的机器学习算法包括以下几种:\n1. 卷积神经网络(Convolutional Neural Networks,CNN):CNN是近年来在图像处理领域中广泛应用的一种神经网络,包含卷积层、池化层和全连接层,训练时需要大量标注数据以及自我调整参数。\n2. 循环神经网络(Recurrent Neural Networks,RNN):RNN指的是信息流模型,能够处理序列数据,

其实不必这么麻烦的,主要是你们文件夹命名的问题,我将模型文件夹名称由Yuan2.0-51B-hf改成Yuan2-51B-hf就解决了问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants