Instructions to use Maitreya152/AutoRev with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Maitreya152/AutoRev with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct") model = PeftModel.from_pretrained(base_model, "Maitreya152/AutoRev") - Notebooks
- Google Colab
- Kaggle
Upload autorev_inf.py
Browse files- autorev_inf.py +53 -0
autorev_inf.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
from peft import PeftModel
|
| 4 |
+
|
| 5 |
+
base_model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 6 |
+
adapter_id = "Maitreya152/AutoRev"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 9 |
+
num_added = tokenizer.add_special_tokens({"pad_token": "<PAD>"})
|
| 10 |
+
tokenizer.padding_side = "right"
|
| 11 |
+
|
| 12 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 13 |
+
base_model_id,
|
| 14 |
+
torch_dtype=torch.bfloat16,
|
| 15 |
+
device_map="auto"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
if num_added > 0:
|
| 19 |
+
base_model.resize_token_embeddings(len(tokenizer))
|
| 20 |
+
base_model.config.pad_token_id = tokenizer.pad_token_id
|
| 21 |
+
|
| 22 |
+
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 23 |
+
|
| 24 |
+
passages = """
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 28 |
+
### Instruction:
|
| 29 |
+
Generate a structured feedback for the research paper passages provided below. The feedback should include a summary of the paper, its strengths, weaknesses, and questions for the authors. Consider that the feedback is being given for a paper submitted to the ICLR conference.
|
| 30 |
+
### Research Paper Passages:
|
| 31 |
+
{passages.strip()}
|
| 32 |
+
### Feedback for the paper:
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
inputs = tokenizer(
|
| 36 |
+
prompt,
|
| 37 |
+
return_tensors="pt"
|
| 38 |
+
).to(model.device)
|
| 39 |
+
|
| 40 |
+
outputs = model.generate(
|
| 41 |
+
**inputs,
|
| 42 |
+
max_new_tokens=6000,
|
| 43 |
+
do_sample=True,
|
| 44 |
+
temperature=0.7,
|
| 45 |
+
top_p=0.9,
|
| 46 |
+
eos_token_id=tokenizer.eos_token_id
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
input_length = inputs.input_ids.shape[1]
|
| 50 |
+
generated_tokens = outputs[0][input_length:]
|
| 51 |
+
response = tokenizer.decode(generated_tokens, skip_special_tokens=True)
|
| 52 |
+
|
| 53 |
+
print(response)
|