-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
6976cd6
commit e31da14
Showing
24 changed files
with
98 additions
and
26 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
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,23 +1,58 @@ | ||
#!/bin/bash | ||
|
||
export CUDA_VISIBLE_DEVICES=3,4,5,6,7 | ||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--knowledge_file ../data/knowledge_v1.2.0_20231217.json \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 0 \ | ||
--model llama2 \ | ||
--model_dir ../models/dfm-2.0-13b \ | ||
--cuda_device cuda:5 \ | ||
--exp_name dfm-2.0-13b | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-70b \ | ||
--cuda_device auto | ||
|
||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--knowledge_file ../data/knowledge_v1.2.0_20231217.json \ | ||
--caption_file ../data/captions_v1.2.0_20231217.csv \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 1 \ | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-70b \ | ||
--cuda_device auto | ||
|
||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--caption_file ../data/ocr_v1.2.0_20231217.csv \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 1 \ | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-70b \ | ||
--cuda_device auto | ||
|
||
export CUDA_VISIBLE_DEVICES=0 | ||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 0 \ | ||
--model llama2 \ | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-13b \ | ||
--cuda_device cuda:6 \ | ||
--exp_name dfm-2.0-13b | ||
--cuda_device auto | ||
|
||
export CUDA_VISIBLE_DEVICES=1 | ||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--caption_file ../data/captions_v1.2.0_20231217.csv \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 1 \ | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-13b \ | ||
--cuda_device auto | ||
|
||
python eval.py --checkpoint_dir ../results/dfm-2.0-13b_llama2_input_0_shot_0_kn_20240125_191329 | ||
export CUDA_VISIBLE_DEVICES=2 | ||
python eval.py \ | ||
--problem_file ../data/problem_v1.2.0_20231217.json \ | ||
--caption_file ../data/ocr_v1.2.0_20231217.csv \ | ||
--questions_type 0,1,2,3 \ | ||
--input_type 1 \ | ||
--model dfm \ | ||
--model_dir ../models/dfm-2.0-13b \ | ||
--cuda_device auto |
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""dfm-2.0 evaluator with HuggingFace Transformers""" | ||
|
||
from transformers import AutoTokenizer, AutoModelForCausalLM | ||
import transformers | ||
import torch | ||
import pdb | ||
|
||
class DFMEvaluator: | ||
def __init__(self, model_dir="dfm-2.0-13b", max_tokens=200, device_map="cuda:0"): | ||
self.model_dir = model_dir | ||
self.sample_params = { | ||
"max_new_tokens": max_tokens, | ||
"do_sample": False, | ||
} | ||
self.device_map = device_map | ||
|
||
self.model = AutoModelForCausalLM.from_pretrained(self.model_dir, device_map=device_map, torch_dtype=torch.float16, trust_remote_code=True).half().eval() | ||
self.tokenizer = AutoTokenizer.from_pretrained(self.model_dir, trust_remote_code=True) | ||
|
||
self.model.generation_config.__dict__.update(self.sample_params) | ||
|
||
def prepare_inputs(self, content_sys, content): | ||
content = f"<|system|>:{content_sys.strip()}\n<|user|>:{content.strip()}<|assistant|>:" | ||
return content | ||
|
||
def generate_response(self, question): | ||
message = self.prepare_inputs(question["prompted_system_content"],question["prompted_content"]) | ||
inputs = self.tokenizer([message],add_special_tokens=False, return_tensors="pt") | ||
pred = self.model.generate(input_ids=inputs.input_ids[0, :4096].cuda().unsqueeze(0), eos_token_id=self.tokenizer.eos_token_id, pad_token_id=self.tokenizer.eos_token_id, **self.sample_params, ) | ||
input_length = inputs.input_ids.size(1) | ||
response = self.tokenizer.decode(pred[0][input_length:], skip_special_tokens=True).strip() | ||
return response, message | ||
|
||
def generate_answer(self, question): | ||
response, message = self.generate_response(question) | ||
question["input_message"] = message | ||
question["prediction"] = response | ||
question.pop("prompted_content") | ||
question.pop("prompted_system_content") | ||
return question |
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
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
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
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.