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

Message='BaiChuanTokenizer' object has no attribute 'sp_model' #9

Open
toniedeng opened this issue Apr 13, 2024 · 7 comments
Open

Message='BaiChuanTokenizer' object has no attribute 'sp_model' #9

toniedeng opened this issue Apr 13, 2024 · 7 comments

Comments

@toniedeng
Copy link

Message='BaiChuanTokenizer' object has no attribute 'sp_model'
Source=C:\Users\Administrator.cache\huggingface\modules\transformers_modules\Sunsimiao\tokenization_baichuan.py
StackTrace:
File "C:\Users\Administrator.cache\huggingface\modules\transformers_modules\Sunsimiao\tokenization_baichuan.py", line 104, in vocab_size
return self.sp_model.get_piece_size()
File "C:\Users\Administrator.cache\huggingface\modules\transformers_modules\Sunsimiao\tokenization_baichuan.py", line 108, in get_vocab (Current frame)
vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
File "C:\Users\Administrator.cache\huggingface\modules\transformers_modules\Sunsimiao\tokenization_baichuan.py", line 74, in init
super().init(
File "C:\Users\Administrator.cache\modelscope\modelscope_modules\Sunsimiao\ms_wrapper.py", line 41, in init
self.tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
File "C:\Users\Administrator.cache\modelscope\modelscope_modules\Sunsimiao\ms_wrapper.py", line 20, in init
model = SunsimiaoTextGeneration(model) if isinstance(model, str) else model
File "C:\Users\Administrator\source\repos\Sunsimiao\scripts\inference_ms.py", line 4, in
pipe = pipeline(task=Tasks.text_generation,

how can i deal?

@toniedeng
Copy link
Author

deal with change transformers==4.33.1

@jingnant
Copy link
Contributor

尝试降级transformers==4.33.3 或者修改tokenization_baichuan.py,super() 修改到最后执行

       self.vocab_file = vocab_file
       self.add_bos_token = add_bos_token
       self.add_eos_token = add_eos_token
       self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
       self.sp_model.Load(vocab_file)
       super().__init__(
           bos_token=bos_token,
           eos_token=eos_token,
           unk_token=unk_token,
           pad_token=pad_token,
           add_bos_token=add_bos_token,
           add_eos_token=add_eos_token,
           sp_model_kwargs=self.sp_model_kwargs,
           clean_up_tokenization_spaces=clean_up_tokenization_spaces,
           **kwargs,
       )
       # self.vocab_file = vocab_file
       # self.add_bos_token = add_bos_token
       # self.add_eos_token = add_eos_token
       # self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
       # self.sp_model.Load(vocab_file)

@Robtzz
Copy link

Robtzz commented Oct 17, 2024

我仍然抛出这个异常

@Robtzz
Copy link

Robtzz commented Oct 17, 2024

我仍然抛出这个异常

在魔塔降低版本之后需要重启免费的服务器内核,来保证生效,我重启后可以运行

@jingnant
Copy link
Contributor

jingnant commented Oct 18, 2024

尝试新模型Sunsimiao-7B的推理代码:

from modelscope import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "X-D-Lab/Sunsimiao-Qwen2-7B",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen2-1.5B-Instruct")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

@Robtzz
Copy link

Robtzz commented Oct 21, 2024

尝试新模型Sunsimiao-7B的推理代码:

from modelscope import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "X-D-Lab/Sunsimiao-Qwen2-7B",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen2-1.5B-Instruct")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

新的代码运行不但没有错误,推理的速度也快了很多,但是我看不出他和平常的LLM的区别,类似 GPT-4o

@Robtzz
Copy link

Robtzz commented Oct 21, 2024

尝试新模型Sunsimiao-7B的推理代码:

from modelscope import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "X-D-Lab/Sunsimiao-Qwen2-7B",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen2-1.5B-Instruct")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

新的代码运行不但没有错误,推理的速度也快了很多,但是我看不出他和平常的LLM的区别,类似 GPT-4o

甚至GPT-4o的返回更加令人容易理解和接受

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

3 participants