-
Notifications
You must be signed in to change notification settings - Fork 174
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
where is mycode error? #33
Comments
Hi. Can you try LM Studio ? It works so easily. |
Hi. def ask(model, tokenizer, question, max_length=512, max_new_tokens=100):
inputs = tokenizer.encode_plus(question + tokenizer.eos_token, return_tensors='pt', max_length=max_length, truncation=True)
outputs = model.generate(
inputs['input_ids'],
attention_mask=inputs['attention_mask'],
max_new_tokens=max_new_tokens,
pad_token_id=tokenizer.eos_token_id,
no_repeat_ngram_size=3,
do_sample=True,
top_k=100,
top_p=0.7,
temperature=0.8
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response Here is an example usage! # After loading model and its tokenizer using HF hub:
question = "what are the latest treatments for type 2 diabetes?"
response = ask(model, tokenizer, question, max_length=512, max_new_tokens=250)
print(response) |
Dear cloner174: |
Can you provide the actual output that you are receiving ? |
there are not any output. where is mycode error?
import os
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed
tokenizer = AutoTokenizer.from_pretrained("/Users/yutao/Documents/MyCode/meditron_7b/model")
model = AutoModelForCausalLM.from_pretrained("/Users/yutao/Documents/MyCode/meditron_7b/model")
question = "What to do about high blood pressure?"
inputs = tokenizer(question, return_tensors="pt")
set_seed(42)
answers = []
with torch.inference_mode():
beam_output = model.generate(**inputs,
max_new_tokens=1024,
num_beams=1,
pad_token_id=2,
eos_token_id=2,
early_stopping=False,
do_sample=False,
)
answers.append(tokenizer.decode(beam_output[0], skip_special_tokens=True))
print("answers: "+answers)
The text was updated successfully, but these errors were encountered: