Views
No views yet
DeepSeek-R1-Distill-Qwen-7B.transformers Librarytransformers library for text generation tasks. It is important to follow the specific prompt format, which includes <think> and <answer> tags, to get the best results.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Set the device
5device = "cuda" if torch.cuda.is_available() else "cpu"
6
7# Load the model and tokenizer
8model_name = "zjunlp/KnowRL-DeepSeek-R1-Distill-Qwen-7B"
9tokenizer = AutoTokenizer.from_pretrained(model_name)
10model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16).to(device)
11
12# Define the prompt using the model's template
13prompt = "What is the main function of the mitochondria?"
14messages = [
15 {"role": "user", "content": prompt}
16]
17text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
18
19# Generate a response
20inputs = tokenizer(text, return_tensors="pt").to(device)
21outputs = model.generate(**inputs, max_new_tokens=512)
22
23# Decode and print the output
24response = tokenizer.decode(outputs[0], skip_special_tokens=True)
25print(response)huggingface-clihuggingface-cli.bash
huggingface-cli download zjunlp/KnowRL-DeepSeek-R1-Distill-Qwen-7B --local-dir KnowRL-DeepSeek-R1-Distill-Qwen-7Bzjunlp/KnowRL-Train-Data dataset.knowrl_coldstart.json dataset. This stage helps the model adopt a fact-based, slow-thinking response structure.KnowRL_RLtrain_data_withknowledge.json and knowrl_RLdata.json files.@article{ren2025knowrl,
title={KnowRL: Exploring Knowledgeable Reinforcement Learning for Factuality},
author={Ren, Baochang and Qiao, Shuofei and Yu, Wenhao and Chen, Huajun and Zhang, Ningyu},
journal={arXiv preprint arXiv:2506.19807},
year={2025}
}