-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
spacing problem. #2
Comments
Instead of awaiting token completion, awaiting word completion would solve this. Not an actual stream anymore, but still useful. |
Can You Please give us a Example script |
from transformers import AutoTokenizer, TextGenerationPipeline, TextStreamer, GenerationConfig
from auto_gptq import AutoGPTQForCausalLM
import torch
from transformers_stream_generator import init_stream_support
init_stream_support()
repo = "TheBloke/tulu-7B-GPTQ"
model_basename = "gptq_model-4bit-128g"
test_tokenizer = AutoTokenizer.from_pretrained(
repo,
use_fast=True,
)
test_model = AutoGPTQForCausalLM.from_quantized(
repo,
model_basename=model_basename,
use_triton=False,
use_safetensors=True,
device="cuda:0",
trust_remote_code=False,
quantize_config=None,
max_memory={i: "14GIB" for i in range(torch.cuda.device_count())}
def tulu_prompt(input):
return f'''### Human: {input}
### Assistant:'''
from transformers_stream_generator import init_stream_support
init_stream_support()
def tulu_prompt(input):
return f'''### Human: {input}
### Assistant:'''
text = "write a poem about AI"
tokens = test_tokenizer(tulu_prompt(input=text), return_tensors="pt", add_special_tokens=False).input_ids.cuda()
generator = (test_model.generate(inputs=tokens, max_new_tokens=256, temperature=0.5, top_k=35, top_p=0.90, do_sample=True, do_stream=True))
for token in generator:
word = tokenizer.decode(token)
print(word, end='', flush=True) The output is this:
So How can i format it correctly? @LowinLi Can you please Chim in? |
I had the same problem, but @LowinLi has put a solution in his examples. He uses the tokenizer to see several tokens at a time and detects the spaces that way. I have given a working example for you that has everything formatted correctly - you just need to substitute for your model_name_or_path in your case probably with "TheBloke/tulu-7B-GPTQ"
|
Thanks to your nice works!
but I met some problem as spacing each token.
for example...
...
'on'
'st'
'amps'
'and'
'sh'
'ipping'
'.'
...
stamps is one word and shipping is one word.
I can't distinguish the spacing between the words(tokens)
How can I solve that?
The text was updated successfully, but these errors were encountered: