Views
No views yet

transformers library. For more detailed instructions on training and evaluation, please refer to the official GitHub repository.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
3
4# Load the model and tokenizer
5# Replace "dongguanting/Llama3.1-8B-ARPO" with the specific ARPO checkpoint you want to use.
6model_name = "dongguanting/Llama3.1-8B-ARPO" # Example ARPO model
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype=torch.bfloat16, # Use bfloat16 for better performance on compatible hardware
10 device_map="auto",
11 trust_remote_code=True # Required for custom modeling if applicable
12).eval()
13tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
14
15# Set generation configuration based on model's generation_config.json
16model.generation_config = GenerationConfig.from_pretrained(
17 model_name,
18 temperature=0.6,
19 top_p=0.9,
20 do_sample=True,
21 eos_token_id=[128001, 128008, 128009], # From special_tokens_map.json and generation_config.json
22 pad_token_id=tokenizer.eos_token_id, # Common practice for LLMs
23)
24
25# Prepare messages using the chat template (e.g., Llama 3.1 or similar)
26messages = [
27 {"role": "system", "content": "You are a helpful AI assistant."},
28 {"role": "user", "content": "What is the capital of France?"}
29]
30
31# Apply chat template and tokenize input
32text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
33input_ids = tokenizer(text, return_tensors="pt").input_ids.to(model.device)
34
35# Generate response
36with torch.no_grad():
37 output_ids = model.generate(input_ids, max_new_tokens=256)
38
39# Decode and print the generated text, excluding the input prompt
40response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True).strip()
41
42print(f"Assistant: {response}")1@misc{dong2025arpo,
2 title={Agentic Reinforced Policy Optimization},
3 author={Guanting Dong and Hangyu Mao and Kai Ma and Licheng Bao and Yifei Chen and Zhongyuan Wang and Zhongxia Chen and Jiazhen Du and Huiyang Wang and Fuzheng Zhang and Guorui Zhou and Yutao Zhu and Ji-Rong Wen and Zhicheng Dou},
4 year={2025},
5 eprint={2507.19849},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2507.19849},
9}