-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codeqwen.py and edit convertpy: A quick test for codeqwen that ha…
…s switched its tokenizer to SentencePiece, so I test it using Pybind11.
- Loading branch information
Showing
2 changed files
with
49 additions
and
5 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# quick test for codeqwen: use transformers tokenizer | ||
from transformers import AutoTokenizer | ||
import qwen_cpp | ||
|
||
device = "cpu" # the device to load the model onto | ||
|
||
pipeline = qwen_cpp.Pipeline("../codeqwen2_7b-ggml.bin", "../qwen.tiktoken", 2048) | ||
tokenizer = AutoTokenizer.from_pretrained("Qwen/CodeQwen1.5-7B-Chat") | ||
|
||
prompt = "Write a quicksort algorithm in python." | ||
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 | ||
) | ||
print(text) | ||
model_inputs = tokenizer([text], return_tensors="pt").to(device) | ||
|
||
input_ids = model_inputs.input_ids.tolist()[0] | ||
|
||
print(input_ids) | ||
|
||
gen_config = qwen_cpp._C.GenerationConfig( | ||
max_length=2048, | ||
# max_new_tokens=args.max_new_tokens, | ||
max_context_length=512, | ||
do_sample=False, | ||
top_k=1, | ||
top_p=1, | ||
temperature=1, | ||
repetition_penalty=0.9, | ||
num_threads = 0, | ||
) | ||
|
||
out_ids = pipeline._sync_generate_ids(input_ids, gen_config) | ||
print(out_ids) | ||
|
||
response = tokenizer.decode(out_ids, skip_special_tokens=True) | ||
|
||
print(response) |
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