Views
No views yet
UbiquantAI/Fleming-R1-7BUbiquantAI/Fleming-R1-32B

1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "UbiquantAI/Fleming-R1-7B"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14prompt = "What should I do if I suddenly develop a fever?"
15messages = [
16 {"role": "user", "content": prompt}
17]
18text = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True,
22)
23
24model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
25
26# conduct text completion
27generated_ids = model.generate(
28 **model_inputs,
29 max_new_tokens=32768
30)
31output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
32
33# parsing thinking content
34output = tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n")
35thinking_content = output.split("<think>")[-1].split("</think>")[0]
36content = output.split("</think>")[-1]
37
38print("####thinking content:\n", thinking_content)
39print("\n")
40print("####answer:\n", content)1@misc{fleming-r1,
2 title = {Fleming-R1: Toward Expert-Level Medical Reasoning via Reinforcement Learning},
3 author = {Chi Liu and Derek Li and Yan Shu and Robin Chen and Derek Duan and Teng Fang and Bryan Dai},
4 year = {2025},
5 url = {https://github.com/UbiquantAI/Fleming-R1/blob/main/paper/Fleming-R1.pdf},
6}