Skip to content

Commit

Permalink
make format happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobiw committed Oct 1, 2024
1 parent 0aef11c commit ccd5360
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
3 changes: 2 additions & 1 deletion aria/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from typing import Dict, Iterable, List

import torch
from datasets import DatasetDict, concatenate_datasets, load_dataset
from datasets.features import Features, Sequence, Value

from datasets import DatasetDict, concatenate_datasets, load_dataset


def apply_chat_template_and_tokenize(
messages_batch: List[List[Dict]],
Expand Down
10 changes: 6 additions & 4 deletions aria/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ def inference(
do_sample=True,
temperature=0.9,
)

for i in range(inputs['input_ids'].shape[0]):
prompt_len = len(inputs['input_ids'][i])
output_text = tokenizer.decode(output[i][prompt_len:], skip_special_tokens=True).replace("<|im_end|>", "")

for i in range(inputs["input_ids"].shape[0]):
prompt_len = len(inputs["input_ids"][i])
output_text = tokenizer.decode(
output[i][prompt_len:], skip_special_tokens=True
).replace("<|im_end|>", "")

return output_text

Expand Down
14 changes: 8 additions & 6 deletions examples/nextqa/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import argparse
import json
import os
import random

import numpy as np
import random
import torch
from peft import PeftConfig, PeftModel
from torch.utils.data import DataLoader, Dataset
from tqdm import tqdm
from transformers import AutoTokenizer

from aria.load_video import load_video
from aria.lora.layers import GroupedGemmLoraLayer
Expand Down Expand Up @@ -64,7 +63,7 @@ def load_model_and_tokenizer(args):
processor = AriaProcessor.from_pretrained(
args.base_model_path, tokenizer_path=args.tokenizer_path
)
processor.tokenizer.padding_side="left"
processor.tokenizer.padding_side = "left"
tokenizer = processor.tokenizer

model = AriaForConditionalGeneration.from_pretrained(
Expand Down Expand Up @@ -98,8 +97,10 @@ def process_batch(model, tokenizer, inputs, original_batch, prompts):
)

for i, prompt in enumerate(prompts):
prompt_len = len(inputs['input_ids'][i])
output_text = tokenizer.decode(output[i][prompt_len:], skip_special_tokens=True).replace("<|im_end|>", "")
prompt_len = len(inputs["input_ids"][i])
output_text = tokenizer.decode(
output[i][prompt_len:], skip_special_tokens=True
).replace("<|im_end|>", "")
original_batch[i]["pred"] = output_text

return original_batch
Expand All @@ -123,7 +124,8 @@ def collate_fn(batch, processor, tokenizer):
messages.append(item["messages"])

texts = [
processor.apply_chat_template(msg, add_generation_prompt=True) for msg in messages
processor.apply_chat_template(msg, add_generation_prompt=True)
for msg in messages
]
inputs = processor(
text=texts,
Expand Down
12 changes: 7 additions & 5 deletions examples/nlvr2/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from PIL import Image
from torch.utils.data import DataLoader, Dataset
from tqdm import tqdm
from transformers import AutoTokenizer

from aria.lora.layers import GroupedGemmLoraLayer
from aria.model import AriaForConditionalGeneration, AriaProcessor, GroupedGEMM
Expand Down Expand Up @@ -64,7 +63,7 @@ def load_model_and_tokenizer(args):
processor = AriaProcessor.from_pretrained(
args.base_model_path, tokenizer_path=args.tokenizer_path
)
processor.tokenizer.padding_side="left"
processor.tokenizer.padding_side = "left"
tokenizer = processor.tokenizer

model = AriaForConditionalGeneration.from_pretrained(
Expand Down Expand Up @@ -98,8 +97,10 @@ def process_batch(model, tokenizer, inputs, original_batch, prompts):
)

for i, prompt in enumerate(prompts):
prompt_len = len(inputs['input_ids'][i])
output_text = tokenizer.decode(output[i][prompt_len:], skip_special_tokens=True).replace("<|im_end|>", "")
prompt_len = len(inputs["input_ids"][i])
output_text = tokenizer.decode(
output[i][prompt_len:], skip_special_tokens=True
).replace("<|im_end|>", "")
original_batch[i]["pred"] = output_text

return original_batch
Expand All @@ -115,7 +116,8 @@ def collate_fn(batch, processor, tokenizer):
messages.append(item["messages"])

texts = [
processor.apply_chat_template(msg, add_generation_prompt=True) for msg in messages
processor.apply_chat_template(msg, add_generation_prompt=True)
for msg in messages
]
inputs = processor(
text=texts,
Expand Down
12 changes: 7 additions & 5 deletions examples/refcoco/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from torch.utils.data import DataLoader, Dataset
from torchvision.ops.boxes import box_area
from tqdm import tqdm
from transformers import AutoTokenizer

from aria.lora.layers import GroupedGemmLoraLayer
from aria.model import AriaForConditionalGeneration, AriaProcessor, GroupedGEMM
Expand Down Expand Up @@ -66,7 +65,7 @@ def load_model_and_tokenizer(args):
processor = AriaProcessor.from_pretrained(
args.base_model_path, tokenizer_path=args.tokenizer_path
)
processor.tokenizer.padding_side="left"
processor.tokenizer.padding_side = "left"
tokenizer = processor.tokenizer

model = AriaForConditionalGeneration.from_pretrained(
Expand Down Expand Up @@ -100,8 +99,10 @@ def process_batch(model, tokenizer, inputs, original_batch, prompts):
)

for i, prompt in enumerate(prompts):
prompt_len = len(inputs['input_ids'][i])
output_text = tokenizer.decode(output[i][prompt_len:], skip_special_tokens=True).replace("<|im_end|>", "")
prompt_len = len(inputs["input_ids"][i])
output_text = tokenizer.decode(
output[i][prompt_len:], skip_special_tokens=True
).replace("<|im_end|>", "")
original_batch[i]["pred"] = output_text

return original_batch
Expand All @@ -117,7 +118,8 @@ def collate_fn(batch, processor, tokenizer):
messages.append(item["messages"])

texts = [
processor.apply_chat_template(msg, add_generation_prompt=True) for msg in messages
processor.apply_chat_template(msg, add_generation_prompt=True)
for msg in messages
]
inputs = processor(
text=texts,
Expand Down
12 changes: 7 additions & 5 deletions examples/refcoco/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ def inference(
do_sample=True,
temperature=0.9,
)

for i in range(inputs['input_ids'].shape[0]):
prompt_len = len(inputs['input_ids'][i])
output_text = tokenizer.decode(output[i][prompt_len:], skip_special_tokens=True).replace("<|im_end|>", "")

return output_text
for i in range(inputs["input_ids"].shape[0]):
prompt_len = len(inputs["input_ids"][i])
output_text = tokenizer.decode(
output[i][prompt_len:], skip_special_tokens=True
).replace("<|im_end|>", "")

return output_text


def parse_bbox(model_output, img_wh):
Expand Down

0 comments on commit ccd5360

Please sign in to comment.