davidlvxin commited on
Commit
db7b354
β€’
1 Parent(s): a74f280

add readme

Browse files
Files changed (4) hide show
  1. .mdl +0 -0
  2. .msc +0 -0
  3. .mv +0 -1
  4. README.md +91 -0
.mdl DELETED
Binary file (57 Bytes)
 
.msc DELETED
Binary file (1.11 kB)
 
.mv DELETED
@@ -1 +0,0 @@
1
- Revision:master,CreatedAt:1729485048
 
 
README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ library_name: transformers
6
+ tags:
7
+ - Long Context
8
+ - chatglm
9
+ - llama
10
+ datasets:
11
+ - THUDM/LongReward-10k
12
+ pipeline_tag: text-generation
13
+ ---
14
+ # LongReward-llama3.1-8b-DPO
15
+
16
+
17
+ <p align="center">
18
+ πŸ€— <a href="https://huggingface.co/datasets/THUDM/LongReward-10k" target="_blank">[LongReward Dataset] </a> β€’ πŸ’» <a href="https://github.com/THUDM/LongReward" target="_blank">[Github Repo]</a> β€’ πŸ“ƒ <a href="https://arxiv.org/abs/" target="_blank">[LongReward Paper]</a>
19
+ </p>
20
+
21
+ LongReward-llama3.1-8b-DPO is the DPO version of [LongReward-llama3.1-8b-SFT](https://huggingface.co/THUDM/LongReward-llama3.1-8b-SFT) and supports a maximum context window of up to 64K tokens. It is trained on the `dpo_llama3.1_8b` split of [LongReward-10k](https://huggingface.co/datasets/THUDM/LongReward-45) datasets, which is a long-context preference dataset constructed via LongReward.
22
+
23
+ Environment: `transforemrs>=4.43.0`.
24
+
25
+ A simple demo for deployment of the model:
26
+ ```python
27
+ import torch
28
+ from transformers import AutoTokenizer, AutoModelForCausalLM
29
+
30
+ model_path = "THUDM/LongReward-llama3.1-8b-DPO"
31
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
32
+ model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map='auto')
33
+ context = '''
34
+ W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
35
+ '''
36
+ query = "What was Robert Geddes' profession?"
37
+ prompt = context + '\n\n' + query
38
+ response, _ = model.chat(tokenizer, prompt, temprature=1, max_new_tokens=1024)
39
+ print(response)
40
+ ```
41
+
42
+ You can also deploy the model with [vllm](https://github.com/vllm-project/vllm) for faster inference:
43
+ ```python
44
+ import torch
45
+ from vllm import LLM, SamplingParams
46
+
47
+ model_path = "THUDM/LongReward-llama3.1-8b-DPO"
48
+ model = LLM(
49
+ model= model_path,
50
+ dtype=torch.bfloat16,
51
+ trust_remote_code=True,
52
+ tensor_parallel_size=1,
53
+ max_model_len=65536,
54
+ gpu_memory_utilization=1,
55
+ )
56
+ tokenizer = model.get_tokenizer()
57
+ context = '''
58
+ W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
59
+ '''
60
+ query = "What was Robert Geddes' profession?"
61
+ prompt = context + '\n\n' + query
62
+ inputs = tokenizer.build_chat_input(prompt, history=[], role='user')
63
+ eos_token_id = [tokenizer.eos_token_id, tokenizer.get_command("<|user|>"), tokenizer.get_command("<|observation|>")]
64
+ generation_params = SamplingParams(
65
+ temperature=0.95,
66
+ top_p=0.7,
67
+ max_tokens=1024,
68
+ stop_token_ids=eos_token_id,
69
+ )
70
+ input_ids = inputs.input_ids[0].tolist()
71
+ outputs = model.generate(sampling_params=generation_params, prompt_token_ids=[input_ids])
72
+ response = tokenizer.decode(outputs[0].outputs[0].token_ids[:-1])
73
+ print(response)
74
+ ```
75
+
76
+ ## License
77
+ [Llama-3.1 License](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B/blob/main/LICENSE)
78
+
79
+ ## Citation
80
+
81
+ If you find our work useful, please consider citing LongReward:
82
+
83
+ ```
84
+ @article{zhang2024longreward,
85
+ title = {LongReward: Improving Long-context Large Language Models
86
+ with AI Feedback}
87
+ author={Jiajie Zhang and Zhongni Hou and Xin Lv and Shulin Cao and Zhenyu Hou and Yilin Niu and Lei Hou and Lei Hou and Yuxiao Dong and Ling Feng and Juanzi Li},
88
+ journal={arXiv preprint arXiv:},
89
+ year={2024}
90
+ }
91
+ ```