Update README.md
Browse files
README.md
CHANGED
@@ -21,6 +21,7 @@ Figure 2: PRefLexOR Recursive Reasoning Algorithm: An iterative approach leverag
|
|
21 |
|
22 |
```python
|
23 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
24 |
model_name='lamm-mit/PRefLexOR_ORPO_DPO_EXO_10242024'
|
25 |
model = AutoModelForCausalLM.from_pretrained(model_name,
|
26 |
torch_dtype =torch.bfloat16,
|
@@ -31,8 +32,13 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True,
|
|
31 |
)
|
32 |
```
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
```python
|
|
|
|
|
36 |
txt = 'What is the relationship between materials and music? Brief answer.' + f' Use {think_start}.'
|
37 |
|
38 |
output_text, messages = generate_local_model(
|
@@ -59,6 +65,60 @@ print ("THINKING:\n\n", thinking)
|
|
59 |
print ("ANSWER:\n\n", answer_only)
|
60 |
```
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
## Citation
|
63 |
|
64 |
```bibtex
|
|
|
21 |
|
22 |
```python
|
23 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
24 |
+
|
25 |
model_name='lamm-mit/PRefLexOR_ORPO_DPO_EXO_10242024'
|
26 |
model = AutoModelForCausalLM.from_pretrained(model_name,
|
27 |
torch_dtype =torch.bfloat16,
|
|
|
32 |
)
|
33 |
```
|
34 |
|
35 |
+
## Inference example
|
36 |
+
|
37 |
+
### Simple inference:
|
38 |
+
|
39 |
```python
|
40 |
+
from PRefLexOR import *
|
41 |
+
|
42 |
txt = 'What is the relationship between materials and music? Brief answer.' + f' Use {think_start}.'
|
43 |
|
44 |
output_text, messages = generate_local_model(
|
|
|
65 |
print ("ANSWER:\n\n", answer_only)
|
66 |
```
|
67 |
|
68 |
+
### Recursive inference usingh multi-agentic modeling
|
69 |
+
|
70 |
+
```python
|
71 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
72 |
+
|
73 |
+
# Load reasoning model
|
74 |
+
model_name='lamm-mit/PRefLexOR_ORPO_DPO_EXO_10242024'
|
75 |
+
model = AutoModelForCausalLM.from_pretrained(model_name,
|
76 |
+
torch_dtype =torch.bfloat16,
|
77 |
+
attn_implementation="flash_attention_2",device_map="auto",trust_remote_code=True,
|
78 |
+
)
|
79 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True,
|
80 |
+
use_fast=False,
|
81 |
+
)
|
82 |
+
# Load critic model
|
83 |
+
model_name_base = "meta-llama/Llama-3.2-3B-Instruct"
|
84 |
+
|
85 |
+
critic_model = AutoModelForCausalLM.from_pretrained(
|
86 |
+
model_name_base,
|
87 |
+
torch_dtype=torch.bfloat16,
|
88 |
+
attn_implementation="flash_attention_2",
|
89 |
+
device_map="auto",
|
90 |
+
trust_remote_code=True
|
91 |
+
)
|
92 |
+
```
|
93 |
+
|
94 |
+
Example inference
|
95 |
+
```python
|
96 |
+
output_text, output_list, output_text_integrated = recursive_response_from_thinking(
|
97 |
+
model=model,
|
98 |
+
tokenizer=tokenizer,
|
99 |
+
model_critic=critic_model,
|
100 |
+
tokenizer_critic=tokenizer, #same tokenizer in our case
|
101 |
+
question="Develop an idea of how graphene can be combined with silk fibers to create a filtration membrane.",
|
102 |
+
N=3,
|
103 |
+
temperature=0.1,
|
104 |
+
temperature_improvement=0.1,
|
105 |
+
system_prompt="You are a helpful assistant.",
|
106 |
+
system_prompt_critic="You carefully improve responses, with attention to detail, and following all directions.",
|
107 |
+
verbatim=False,
|
108 |
+
```
|
109 |
+
Printing the output:
|
110 |
+
```python
|
111 |
+
for i, item in enumerate(output_list):
|
112 |
+
print (f"i={i}", 64*"-")
|
113 |
+
print (item)
|
114 |
+
|
115 |
+
print (64*"#")
|
116 |
+
print ("INTEGRATED RESPONSE:")
|
117 |
+
print (output_text_integrated)
|
118 |
+
print (64*"#")
|
119 |
+
|
120 |
+
```
|
121 |
+
|
122 |
## Citation
|
123 |
|
124 |
```bibtex
|