-
Notifications
You must be signed in to change notification settings - Fork 48
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
fix llm_runner for tinyllama #407
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,7 @@ | |
parser.add_argument( | ||
"--prompt", | ||
type=str, | ||
default="""<s>[INST] <<SYS>> | ||
Be concise. You are a helpful, respectful and honest assistant. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. <</SYS>> hi what are you? [/INST] | ||
""", | ||
default="hi what are you?", | ||
help="prompt for llm model", | ||
) | ||
parser.add_argument( | ||
|
@@ -183,14 +181,14 @@ def run_llm( | |
streaming_llm=streaming_llm, | ||
) | ||
if not chat_mode: | ||
prompt = append_user_prompt(chat_sys_prompt, prompt) | ||
initial_input = tokenizer(prompt, return_tensors="pt") | ||
example_input_id = initial_input.input_ids | ||
turbine_results = llm.generate(example_input_id) | ||
return tokenizer.decode(turbine_results) | ||
prompt = chat_sys_prompt | ||
while True: | ||
user_prompt = input("User prompt: ") | ||
prompt = append_user_prompt(prompt, user_prompt) | ||
prompt = append_user_prompt(chat_sys_prompt, user_prompt) | ||
initial_input = tokenizer(prompt, return_tensors="pt") | ||
example_input_id = initial_input.input_ids | ||
result = llm.generate(example_input_id) | ||
|
@@ -199,7 +197,13 @@ def run_llm( | |
prompt = append_bot_prompt(prompt, bot_response) | ||
|
||
|
||
def run_torch_llm(hf_model_name, hf_auth_token, prompt, streaming_llm=False): | ||
def run_torch_llm( | ||
hf_model_name, | ||
hf_auth_token, | ||
prompt, | ||
streaming_llm=False, | ||
chat_sys_prompt=DEFAULT_CHAT_SYS_PROMPT, | ||
): | ||
from turbine_models.model_builder import HFTransformerBuilder | ||
from transformers import AutoModelForCausalLM | ||
|
||
|
@@ -210,13 +214,13 @@ def run_torch_llm(hf_model_name, hf_auth_token, prompt, streaming_llm=False): | |
hf_auth_token=hf_auth_token, | ||
auto_tokenizer=AutoTokenizer, | ||
) | ||
model_builder.build_model() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch |
||
if streaming_llm is True: | ||
enable_llama_pos_shift_attention(model_builder.model) | ||
|
||
def get_token_from_logits(logits): | ||
return torch.argmax(logits[:, -1, :], dim=1) | ||
|
||
prompt = append_user_prompt(chat_sys_prompt, prompt) | ||
initial_input = model_builder.tokenizer(prompt, return_tensors="pt") | ||
example_input_id = initial_input.input_ids | ||
|
||
|
@@ -256,6 +260,10 @@ def get_token_from_logits(logits): | |
if args.compare_vs_torch: | ||
print("generating torch output: ") | ||
torch_output = run_torch_llm( | ||
args.hf_model_name, args.hf_auth_token, args.prompt | ||
args.hf_model_name, | ||
args.hf_auth_token, | ||
args.prompt, | ||
args.streaming_llm, | ||
args.chat_sys_prompt, | ||
) | ||
print(torch_output) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually no bueno for chat because doing this you lose track of your chat history/context.