-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
24 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,5 @@ official_runs* | |
*.pt | ||
*.pth | ||
/.idea | ||
prune.py | ||
prune.py | ||
/.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,34 @@ | ||
from transformers import pipeline | ||
import torch | ||
from datetime import datetime | ||
import torch | ||
from torch.nn.functional import mse_loss | ||
from torch.utils.data import Dataset, DataLoader | ||
from transformers import RobertaTokenizer, AdamW, RobertaForSequenceClassification, AutoTokenizer, \ | ||
AutoModelForSequenceClassification, FlaxLlamaForCausalLM, LlamaForSequenceClassification | ||
import pandas as pd | ||
from torch.utils.tensorboard import SummaryWriter | ||
from torch.utils.data.dataset import random_split | ||
from tqdm import tqdm | ||
import os | ||
import argparse | ||
import json | ||
import torch | ||
from peft import PeftModel,PeftModelForTokenClassification | ||
import os | ||
|
||
import torch.nn as nn | ||
from tools.order_metrics import * | ||
import transformers.models.qwen2 | ||
from peft import AutoPeftModelForCausalLM,AutoPeftModelForSequenceClassification,AutoPeftModelForTokenClassification | ||
|
||
from peft import AutoPeftModelForSequenceClassification | ||
from transformers import AutoTokenizer | ||
import torch | ||
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training, TaskType | ||
|
||
|
||
|
||
title = '''xxxx''' | ||
abstract = ''' xxx ''' | ||
|
||
|
||
|
||
|
||
model_pth = r"xxx" | ||
|
||
|
||
model_pth = r"xxx" # Warning, you have to modify the "base_model_name_or_path" in adapter_config.json. We will fix this error after the rebuttal. | ||
model = AutoPeftModelForSequenceClassification.from_pretrained(model_pth,num_labels=1, load_in_8bit=True,) | ||
tokenizer = AutoTokenizer.from_pretrained(model_pth) | ||
|
||
model = model.to("cuda") | ||
model.eval() | ||
# Default Prompt Template | ||
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):''' | ||
inputs = tokenizer(text, return_tensors="pt") | ||
|
||
outputs = model(input_ids=inputs["input_ids"].to("cuda")) | ||
print(outputs['logits']) | ||
|
||
while True: | ||
title = input("Enter a title: ") | ||
abstract = input("Enter a abstract: ") | ||
title = title.replace("\n", "").strip() | ||
abstract = abstract.replace("\n", "").strip() | ||
# Default Prompt Template | ||
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):''' | ||
inputs = tokenizer(text, return_tensors="pt") | ||
outputs = model(input_ids=inputs["input_ids"].to("cuda")) | ||
# If you haven't modify the LLaMA code. | ||
print(nn.Sigmoid()(outputs['logits'])) | ||
# Else print(outputs['logits']) |