Views
No views yet
pip install transformers vllm torch accelerategenerate API:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "xl-zhao/PromptCoT-DS-1.5B"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForCausalLM.from_pretrained(model_name).to("cuda")
6
7problem_statement = (
8 "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?"
9)
10
11prompt = (
12 "<|begin▁of▁sentence|>Please reason step by step, and put your final answer within \\boxed{{}}."
13 "<|User|>" + problem_statement + "<|Assistant|>"
14)
15
16inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
17
18with torch.no_grad():
19 output = model.generate(**inputs, max_length=32768, temperature=0.6)
20
21generated_solution = tokenizer.decode(output[0], skip_special_tokens=True)
22print(generated_solution)vLLM:1from vllm import LLM, SamplingParams
2
3model_name = "xl-zhao/PromptCoT-DS-1.5B"
4llm = LLM(model=model_name, tensor_parallel_size=1)
5
6problem_statement = (
7 "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?"
8)
9
10prompt = (
11 "<|begin▁of▁sentence|>Please reason step by step, and put your final answer within \\boxed{{}}."
12 "<|User|>" + problem_statement + "<|Assistant|>"
13)
14
15sampling_params = SamplingParams(temperature=0.6, max_tokens=32768)
16outputs = llm.generate([prompt], sampling_params)
17
18print(outputs[0].outputs[0].text)@article{zhao2025promptcot,
author = {Zhao, Xueliang and Wu, Wei and Guan, Jian and Kong, Lingpeng},
title = {PromptCoT: Synthesizing Olympiad-Level Problems for Mathematical Reasoning in Large Language Models},
year = {2025},
journal = {arXiv preprint arXiv:2503.02324},
url = {http://arxiv.org/abs/2503.02324}
}