Views
No views yet
<|im_end|> — which is not the eos_token_id (50256 = <|endoftext|>) and is not even a single token. You must stop on the <|im_end|> string or generation will not stop:1from transformers import AutoModelForCausalLM, AutoTokenizer
2mid = "sfanm/d24-sft-v1base-mathheavy-3.7B"
3tok = AutoTokenizer.from_pretrained(mid)
4model = AutoModelForCausalLM.from_pretrained(mid, torch_dtype="bfloat16", device_map="auto")
5
6msgs = [{"role": "user", "content": "Natalia sold clips to 48 friends in April and half as many in May. How many total?"}]
7ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
8out = model.generate(ids, max_new_tokens=512, do_sample=False, stop_strings=["<|im_end|>"], tokenizer=tok)
9print(tok.decode(out[0, ids.shape[1]:], skip_special_tokens=False))Withoutstop_strings=["<|im_end|>"]the model rambles tomax_new_tokens: the configuredeos_token_id(50256) is the GPT-2 document EOS, which a chat turn does not end with. For vLLM, passstop=["<|im_end|>"].