From 00ee7a1ba49d71ffdcf571645c6f2d923de5d29c Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 31 Jan 2024 20:41:41 -0500 Subject: [PATCH 1/3] [CLEANUP] --- .../functioncalls.json | 0 functions.json => datasets/functions.json | 0 .../functionspast30k.json | 0 .../ogsshfunctions.json | 0 .../oldoldsshfunctions.json | 0 .../processed_images.json | 0 {vision_datasets => datasets}/responses.json | 0 example.py | 11 ++++ pyproject.toml | 3 +- requirements.txt | 1 + scripts/gguf.py | 32 ++++++----- scripts/phi.py | 18 ++++-- scripts/redo.py | 3 +- vision_datasets/correctsshfunctions.py | 8 ++- vision_datasets/functioncallgenerate.py | 24 +++++--- vision_datasets/functioncallgenerate2.py | 24 +++++--- vision_datasets/functioncallgenerate_mp_mt.py | 56 ++++++++++++++----- vision_datasets/iter_over_dataset.py | 4 +- vision_datasets/mergeresponsefunctions.py | 24 +++++--- vision_datasets/pulloutput.py | 16 ++++-- vision_datasets/requirements.txt | 4 -- vision_datasets/visionfeatures.py | 17 ++++-- 22 files changed, 166 insertions(+), 79 deletions(-) rename {vision_datasets => datasets}/functioncalls.json (100%) rename functions.json => datasets/functions.json (100%) rename functionspast30k.json => datasets/functionspast30k.json (100%) rename ogsshfunctions.json => datasets/ogsshfunctions.json (100%) rename oldoldsshfunctions.json => datasets/oldoldsshfunctions.json (100%) rename {vision_datasets => datasets}/processed_images.json (100%) rename {vision_datasets => datasets}/responses.json (100%) delete mode 100644 vision_datasets/requirements.txt diff --git a/vision_datasets/functioncalls.json b/datasets/functioncalls.json similarity index 100% rename from vision_datasets/functioncalls.json rename to datasets/functioncalls.json diff --git a/functions.json b/datasets/functions.json similarity index 100% rename from functions.json rename to datasets/functions.json diff --git a/functionspast30k.json b/datasets/functionspast30k.json similarity index 100% rename from functionspast30k.json rename to datasets/functionspast30k.json diff --git a/ogsshfunctions.json b/datasets/ogsshfunctions.json similarity index 100% rename from ogsshfunctions.json rename to datasets/ogsshfunctions.json diff --git a/oldoldsshfunctions.json b/datasets/oldoldsshfunctions.json similarity index 100% rename from oldoldsshfunctions.json rename to datasets/oldoldsshfunctions.json diff --git a/vision_datasets/processed_images.json b/datasets/processed_images.json similarity index 100% rename from vision_datasets/processed_images.json rename to datasets/processed_images.json diff --git a/vision_datasets/responses.json b/datasets/responses.json similarity index 100% rename from vision_datasets/responses.json rename to datasets/responses.json diff --git a/example.py b/example.py index 1202f1f..c44a5ad 100644 --- a/example.py +++ b/example.py @@ -2,7 +2,18 @@ from swarms import QwenVLMultiModal model = QwenVLMultiModal( +<<<<<<< HEAD system_prompt="You, as the model, are presented with a visual problem. This could be an image containing various elements that you need to analyze, a graph that requires interpretation, or a visual puzzle. Your task is to examine the visual information carefully and describe your process of understanding and solving the problem.", +======= + system_prompt=( + "You, as the model, are presented with a visual problem. This" + " could be an image containing various elements that you need" + " to analyze, a graph that requires interpretation, or a" + " visual puzzle. Your task is to examine the visual" + " information carefully and describe your process of" + " understanding and solving the problem." + ), +>>>>>>> a7d64d7 ([FEAT][create_base_retry_decorator]) ) iterator = ImageDatasetIterator("coco", model) diff --git a/pyproject.toml b/pyproject.toml index 5d4ac8e..33e2ad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,9 +25,8 @@ classifiers = [ python = "^3.6" swarms = "*" zetascale = "*" +transformers = "*" -[tool.poetry.dev-dependencies] -# Add development dependencies here [tool.poetry.group.lint.dependencies] diff --git a/requirements.txt b/requirements.txt index 236a195..195ee2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ torch zetascale swarms +transformers \ No newline at end of file diff --git a/scripts/gguf.py b/scripts/gguf.py index a9a8277..dae52b1 100644 --- a/scripts/gguf.py +++ b/scripts/gguf.py @@ -1,30 +1,30 @@ -import torch import json -from transformers.generation import GenerationConfig from transformers import ( AutoModelForCausalLM, AutoTokenizer, TextStreamer, ) -from llama_cpp import Llama import re import os import concurrent.futures import threading -from queue import Queue # Create a lock object lock = threading.Lock() model_name_or_path = "TheBloke/dolphin-2.6-mistral-7B-dpo-laser-AWQ" # Load the model and tokenizer -tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True) +tokenizer = AutoTokenizer.from_pretrained( + model_name_or_path, use_fast=True +) model = AutoModelForCausalLM.from_pretrained( model_name_or_path, low_cpu_mem_usage=True, device_map="cuda:0" ) # Using the text streamer to stream output one token at a time -streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) +streamer = TextStreamer( + tokenizer, skip_prompt=True, skip_special_tokens=True +) # File to store the responses functions_file = "functions.json" @@ -81,11 +81,9 @@ def expand_qa(features): {prompt}<|im_end|> <|im_start|>assistant""" print("before model") - input_ids = tokenizer(prompt_template, return_tensors="pt").input_ids.cuda() - messages = [ - {"role": "system", "content": system_message}, - {"role": "user", "content": prompt}, - ] + input_ids = tokenizer( + prompt_template, return_tensors="pt" + ).input_ids.cuda() generation_params = { "do_sample": True, "temperature": 0.7, @@ -95,7 +93,9 @@ def expand_qa(features): "repetition_penalty": 1.1, } try: - outputs = model.generate(input_ids, streamer=streamer, **generation_params) + outputs = model.generate( + input_ids, streamer=streamer, **generation_params + ) print(outputs) except Exception as e: print(f"Error during model processing: {e}") @@ -105,7 +105,9 @@ def expand_qa(features): # Use regex to find everything after "assistant" match = re.search(r"assistant\s*(.*)", outputs, re.DOTALL) if match: - response = match.group(1) # Extract everything after "assistant" + response = match.group( + 1 + ) # Extract everything after "assistant" else: response = "No response found after 'assistant'." @@ -133,7 +135,9 @@ def process_responses(file_path, output_file_path): def process_item(item): features = item.get("response", "") output = expand_qa(features) - item["new_response"] = output # Add the new response to the original object + item["new_response"] = ( + output # Add the new response to the original object + ) save_response(item) with concurrent.futures.ThreadPoolExecutor() as executor: diff --git a/scripts/phi.py b/scripts/phi.py index f0b60fc..b5d0551 100644 --- a/scripts/phi.py +++ b/scripts/phi.py @@ -1,12 +1,10 @@ import torch import json from transformers import AutoModelForCausalLM, AutoTokenizer -from transformers.generation import GenerationConfig import re import os import concurrent.futures import threading -from queue import Queue device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # Create a lock object @@ -16,7 +14,9 @@ tokenizer = AutoTokenizer.from_pretrained( model_name_or_path, torch_dtype="auto", trust_remote_code=True ) -model = AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_code=True) +model = AutoModelForCausalLM.from_pretrained( + model_name_or_path, trust_remote_code=True +) # File to store the responses functions_file = "functions.json" @@ -75,11 +75,15 @@ def expand_qa(features): input_ids = tokenizer(prompt_template, return_tensors="pt") outputs = model.generate(**input_ids, max_length=512) # Decode the generated tokens to a string - full_response = tokenizer.decode(outputs[0], skip_special_tokens=True) + full_response = tokenizer.decode( + outputs[0], skip_special_tokens=True + ) # Use regex to find everything after "assistant" match = re.search(r"assistant\s*(.*)", full_response, re.DOTALL) if match: - response = match.group(1) # Extract everything after "assistant" + response = match.group( + 1 + ) # Extract everything after "assistant" else: response = "No response found after 'assistant'." @@ -107,7 +111,9 @@ def process_responses(file_path, output_file_path): def process_item(item): features = item.get("response", "") output = expand_qa(features) - item["new_response"] = output # Add the new response to the original object + item["new_response"] = ( + output # Add the new response to the original object + ) save_response(item) with concurrent.futures.ThreadPoolExecutor() as executor: diff --git a/scripts/redo.py b/scripts/redo.py index 4a60402..249c08a 100644 --- a/scripts/redo.py +++ b/scripts/redo.py @@ -9,7 +9,8 @@ def create_image_json(response_file, images_file, output_file): # Create a mapping of image names to IDs image_id_map = { - os.path.basename(entry["image_path"]): entry["id"] for entry in response_data + os.path.basename(entry["image_path"]): entry["id"] + for entry in response_data } # Read the image file names from processed_images.txt diff --git a/vision_datasets/correctsshfunctions.py b/vision_datasets/correctsshfunctions.py index b77597d..51e7450 100644 --- a/vision_datasets/correctsshfunctions.py +++ b/vision_datasets/correctsshfunctions.py @@ -1,11 +1,12 @@ import json + def correct_json_file(input_file, output_file): # Initialize an empty list to store JSON objects corrected_data = [] # Open the file and read line by line - with open(input_file, 'r', encoding='utf-8') as file: + with open(input_file, "r", encoding="utf-8") as file: for line in file: # Convert each line to a JSON object and append to the list try: @@ -16,8 +17,9 @@ def correct_json_file(input_file, output_file): print(f"Error message: {e}") # Write the corrected data to a new file - with open(output_file, 'w', encoding='utf-8') as outfile: + with open(output_file, "w", encoding="utf-8") as outfile: json.dump(corrected_data, outfile, indent=4) + # Example usage -correct_json_file('sshfunctions.json', 'corrected_sshfunctions.json') \ No newline at end of file +correct_json_file("sshfunctions.json", "corrected_sshfunctions.json") diff --git a/vision_datasets/functioncallgenerate.py b/vision_datasets/functioncallgenerate.py index 38f180b..ed05274 100644 --- a/vision_datasets/functioncallgenerate.py +++ b/vision_datasets/functioncallgenerate.py @@ -1,17 +1,17 @@ import torch import json from transformers import AutoModelForCausalLM, AutoTokenizer -from transformers.generation import GenerationConfig import re import os import concurrent.futures import threading -from queue import Queue device = torch.set_default_device("cuda") # Create a lock object lock = threading.Lock() -model_name_or_path = "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" +model_name_or_path = ( + "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" +) # Load the model and tokenizer tokenizer = AutoTokenizer.from_pretrained( model_name_or_path, @@ -19,7 +19,7 @@ trust_remote_code=True, ) model = AutoModelForCausalLM.from_pretrained( - model_name_or_path, device_map=("auto"), trust_remote_code=True + model_name_or_path, device_map="auto", trust_remote_code=True ) # File to store the responses @@ -76,7 +76,9 @@ def expand_qa(features): <|im_start|>user {prompt}<|im_end|> <|im_start|>assistant""" - inputs = tokenizer(prompt_template, return_tensors="pt").inputs.cuda() + inputs = tokenizer( + prompt_template, return_tensors="pt" + ).inputs.cuda() print(inputs) outputs = model.generate( **inputs, @@ -90,11 +92,15 @@ def expand_qa(features): ).cuda() # Decode the generated tokens to a string print(outputs) - full_response = tokenizer.decode(outputs[0], skip_special_tokens=True) + full_response = tokenizer.decode( + outputs[0], skip_special_tokens=True + ) # Use regex to find everything after "assistant" match = re.search(r"assistant\s*(.*)", full_response, re.DOTALL) if match: - response = match.group(1) # Extract everything after "assistant" + response = match.group( + 1 + ) # Extract everything after "assistant" else: response = "No response found after 'assistant'." @@ -122,7 +128,9 @@ def process_responses(file_path, output_file_path): def process_item(item): features = item.get("response", "") output = expand_qa(features) - item["new_response"] = output # Add the new response to the original object + item["new_response"] = ( + output # Add the new response to the original object + ) save_response(item) with concurrent.futures.ThreadPoolExecutor() as executor: diff --git a/vision_datasets/functioncallgenerate2.py b/vision_datasets/functioncallgenerate2.py index e67499e..69d6e48 100644 --- a/vision_datasets/functioncallgenerate2.py +++ b/vision_datasets/functioncallgenerate2.py @@ -1,14 +1,14 @@ import torch import json -from accelerate import PartialState from transformers import AutoModelForCausalLM, AutoTokenizer -from transformers.generation import GenerationConfig import re import os device = torch.set_default_device("cuda") # Create a lock object -model_name_or_path = "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" +model_name_or_path = ( + "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" +) # Load the model and tokenizer tokenizer = AutoTokenizer.from_pretrained( model_name_or_path, @@ -18,7 +18,7 @@ ) model = AutoModelForCausalLM.from_pretrained( model_name_or_path, - device_map=("cuda"), + device_map="cuda", torch_dtype=torch.float16, trust_remote_code=True, use_safetensors=True, @@ -77,7 +77,9 @@ def expand_qa(features): <|im_start|>user {prompt}<|im_end|> <|im_start|>assistant""" - input_ids = tokenizer(prompt_template, return_tensors="pt").input_ids.cuda() + input_ids = tokenizer( + prompt_template, return_tensors="pt" + ).input_ids.cuda() model.to(device) outputs = model.generate( input_ids, @@ -87,11 +89,15 @@ def expand_qa(features): pad_token_id=tokenizer.pad_token_id, ) # Decode the generated tokens to a string - full_response = tokenizer.decode(outputs[0], skip_special_tokens=True) + full_response = tokenizer.decode( + outputs[0], skip_special_tokens=True + ) # Use regex to find everything after "assistant" match = re.search(r"assistant\s*(.*)", full_response, re.DOTALL) if match: - response = match.group(1) # Extract everything after "assistant" + response = match.group( + 1 + ) # Extract everything after "assistant" else: response = "No response found after 'assistant'." print(response) @@ -130,7 +136,9 @@ def process_responses(file_path, output_file_path): continue features = item.get("response", "") output = expand_qa(features) - item["new_response"] = output # Add the new response to the original object + item["new_response"] = ( + output # Add the new response to the original object + ) save_response(item) return data diff --git a/vision_datasets/functioncallgenerate_mp_mt.py b/vision_datasets/functioncallgenerate_mp_mt.py index a671e4a..337eef6 100644 --- a/vision_datasets/functioncallgenerate_mp_mt.py +++ b/vision_datasets/functioncallgenerate_mp_mt.py @@ -4,11 +4,12 @@ import torch.multiprocessing as mp from multiprocessing import Process, Queue, set_start_method from transformers import AutoModelForCausalLM, AutoTokenizer -from transformers.generation import GenerationConfig import re import os -os.environ["MASTER_ADDR"] = "localhost" # Use the appropriate master address +os.environ["MASTER_ADDR"] = ( + "localhost" # Use the appropriate master address +) os.environ["MASTER_PORT"] = "29500" # Use an appropriate port number torch.distributed.is_available() @@ -22,7 +23,9 @@ # Initialization of the model and tokenizer should be done inside the function that runs on each process to ensure they are correctly mapped to the respective device (GPU). def setup_model_and_tokenizer(device): - model_name_or_path = "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" + model_name_or_path = ( + "cognitivecomputations/dolphin-2.6-mistral-7b-dpo-laser" + ) tokenizer = AutoTokenizer.from_pretrained( model_name_or_path, torch_dtype=torch.float16, @@ -89,7 +92,9 @@ def generate_response(tokenizer, model, features): <|im_start|>user {prompt}<|im_end|> <|im_start|>assistant""" - input_ids = tokenizer(prompt_template, return_tensors="pt").input_ids.cuda() + input_ids = tokenizer( + prompt_template, return_tensors="pt" + ).input_ids.cuda() outputs = model.generate( input_ids, temperature=0.7, @@ -98,12 +103,16 @@ def generate_response(tokenizer, model, features): pad_token_id=tokenizer.pad_token_id, ) # Decode the generated tokens to a string - full_response = tokenizer.decode(outputs[0], skip_special_tokens=True) + full_response = tokenizer.decode( + outputs[0], skip_special_tokens=True + ) # Use regex to find everything after "assistant" match = re.search(r"assistant\s*(.*)", full_response, re.DOTALL) if match: - response = match.group(1) # Extract everything after "assistant" + response = match.group( + 1 + ) # Extract everything after "assistant" else: response = "No response found after 'assistant'." print(response) @@ -111,15 +120,21 @@ def generate_response(tokenizer, model, features): def expand_qa(rank, features_with_ids, output_queue, world_size): - torch.cuda.set_device(rank) # Set the current device to the specified GPU + torch.cuda.set_device( + rank + ) # Set the current device to the specified GPU device = torch.device(f"cuda:{rank}") dist.init_process_group("nccl", rank=rank, world_size=world_size) tokenizer, model = setup_model_and_tokenizer(device) print(f"Process {rank} is running on GPU {rank}") for feature in features_with_ids: if rank == (feature["id"] % world_size): - response = generate_response(tokenizer, model, feature["response"]) - output_queue.put({"id": feature["id"], "response": response}) + response = generate_response( + tokenizer, model, feature["response"] + ) + output_queue.put( + {"id": feature["id"], "response": response} + ) # Save the response if rank == 0: for _ in range(world_size): @@ -160,7 +175,9 @@ def process_responses(file_path, output_file_path): continue features = item.get("response", "") output = expand_qa(features) - item["new_response"] = output # Add the new response to the original object + item["new_response"] = ( + output # Add the new response to the original object + ) save_response(item) return data @@ -183,7 +200,9 @@ def load_features(features_path, responses_path): # Filter out features that have already been processed new_features = [ - feature for feature in features if feature["id"] not in processed_ids + feature + for feature in features + if feature["id"] not in processed_ids ] return new_features @@ -192,19 +211,26 @@ def load_features(features_path, responses_path): def write_outputs_from_queue(output_queue, functions_path): with open(functions_path, "a") as f: while True: - output = output_queue.get() # This will block until an item is available + output = ( + output_queue.get() + ) # This will block until an item is available if output == "DONE": break # Break the loop if a "DONE" signal is received f.write(json.dumps(output) + "\n") def main(): - set_start_method("spawn") # Recommended for PyTorch multiprocessing + set_start_method( + "spawn" + ) # Recommended for PyTorch multiprocessing world_size = torch.cuda.device_count() - unprocessed_features = load_features(features_file, functions_file) + unprocessed_features = load_features( + features_file, functions_file + ) output_queue = Queue() writer_process = Process( - target=write_outputs_from_queue, args=(output_queue, functions_file) + target=write_outputs_from_queue, + args=(output_queue, functions_file), ) writer_process.start() features_with_ids = [ diff --git a/vision_datasets/iter_over_dataset.py b/vision_datasets/iter_over_dataset.py index bcb9c31..3e4c13b 100644 --- a/vision_datasets/iter_over_dataset.py +++ b/vision_datasets/iter_over_dataset.py @@ -62,7 +62,9 @@ def process_images(self, task: str) -> Iterator[Any]: """ self.index = 0 # Reset index to start from the beginning for image in self: - output = self.model(task, image) # Pass image into the model + output = self.model( + task, image + ) # Pass image into the model yield output def process_images_to_json(self) -> None: diff --git a/vision_datasets/mergeresponsefunctions.py b/vision_datasets/mergeresponsefunctions.py index d2a5d81..6780777 100644 --- a/vision_datasets/mergeresponsefunctions.py +++ b/vision_datasets/mergeresponsefunctions.py @@ -1,29 +1,37 @@ import json + def merge_data(sshfunctions_file, responses_file, output_file): # Load sshfunctions data - with open(sshfunctions_file, 'r', encoding='utf-8') as file: + with open(sshfunctions_file, "r", encoding="utf-8") as file: sshfunctions_data = json.load(file) # Load responses data - with open(responses_file, 'r', encoding='utf-8') as file: + with open(responses_file, "r", encoding="utf-8") as file: responses_data = json.load(file) # Convert responses_data into a dict for faster lookups - responses_dict = {item['id']: item for item in responses_data} + responses_dict = {item["id"]: item for item in responses_data} # Merge data for item in sshfunctions_data: # Assuming 'id' is the field to match on - response_item = responses_dict.get(item['id']) + response_item = responses_dict.get(item["id"]) if response_item: # Add 'image_path' and 'response' to the sshfunctions item - item['image_path'] = response_item.get('image_path', 'No image path found') - item['response'] = response_item.get('response', 'No response found') + item["image_path"] = response_item.get( + "image_path", "No image path found" + ) + item["response"] = response_item.get( + "response", "No response found" + ) # Write the updated data to a new file - with open(output_file, 'w', encoding='utf-8') as outfile: + with open(output_file, "w", encoding="utf-8") as outfile: json.dump(sshfunctions_data, outfile, indent=4) + # Example usage -merge_data('sshfunctions.json', 'responses.json', 'updated_sshfunctions.json') \ No newline at end of file +merge_data( + "sshfunctions.json", "responses.json", "updated_sshfunctions.json" +) diff --git a/vision_datasets/pulloutput.py b/vision_datasets/pulloutput.py index 79d134d..38e1b71 100644 --- a/vision_datasets/pulloutput.py +++ b/vision_datasets/pulloutput.py @@ -1,25 +1,31 @@ import json import re + def extract_expected_output_as_string(input_file, output_file): # Read the JSON data - with open(input_file, 'r', encoding='utf-8') as file: + with open(input_file, "r", encoding="utf-8") as file: data = json.load(file) for obj in data: user_text = obj.get("user", "") # Use regex to find the expected output section, capturing until the next double quote # Assuming the entire expected output is in one line - match = re.search(r'\[EXPECTED OUTPUT\](.*?)$', user_text, re.DOTALL) + match = re.search( + r"\[EXPECTED OUTPUT\](.*?)$", user_text, re.DOTALL + ) if match: # Extract the matched expected output text expected_output_str = match.group(1).strip() # Assign the raw string of expected output to the 'output' key - obj['output'] = expected_output_str + obj["output"] = expected_output_str # Write the updated data to a new file - with open(output_file, 'w', encoding='utf-8') as outfile: + with open(output_file, "w", encoding="utf-8") as outfile: json.dump(data, outfile, indent=4) + # Example usage -extract_expected_output_as_string('sshfunctions.json', 'sshfunctions_updated.json') \ No newline at end of file +extract_expected_output_as_string( + "sshfunctions.json", "sshfunctions_updated.json" +) diff --git a/vision_datasets/requirements.txt b/vision_datasets/requirements.txt deleted file mode 100644 index 195ee2f..0000000 --- a/vision_datasets/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -torch -zetascale -swarms -transformers \ No newline at end of file diff --git a/vision_datasets/visionfeatures.py b/vision_datasets/visionfeatures.py index e120934..b2ce051 100644 --- a/vision_datasets/visionfeatures.py +++ b/vision_datasets/visionfeatures.py @@ -24,7 +24,9 @@ responses_file = "responses.json" -tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-VL-Chat", trust_remote_code=True) +tokenizer = AutoTokenizer.from_pretrained( + "Qwen/Qwen-VL-Chat", trust_remote_code=True +) # Instantiate the QwenVLMultiModal model model = AutoModelForCausalLM.from_pretrained( @@ -39,7 +41,11 @@ model.generation_config = GenerationConfig.from_pretrained( "Qwen/Qwen-VL-Chat", trust_remote_code=True ) -shortprompt = "Begin by describing what you see in the image. Extract as many features as you can in english. Make sure you are as descriptive as possible in english." +shortprompt = ( + "Begin by describing what you see in the image. Extract as many" + " features as you can in english. Make sure you are as" + " descriptive as possible in english." +) # Function to process an images and generate QA pairs @@ -51,7 +57,9 @@ def generate_qa_for_image(image_path): {"text": VISUAL_CHAIN_OF_THOUGHT}, ] ) - response, history = model.chat(tokenizer, query=query, history=None) + response, history = model.chat( + tokenizer, query=query, history=None + ) return response, history @@ -70,7 +78,8 @@ def save_image_id_map(processed_images, responses_file, output_file): with open(responses_file, "r") as file: response_data = json.load(file) image_id_map = { - entry["image_path"].split("\\")[-1]: entry["id"] for entry in response_data + entry["image_path"].split("\\")[-1]: entry["id"] + for entry in response_data } image_json_data = [ {"image_name": img, "id": image_id_map.get(img)} From 4b13e3b043a85accc302844bc98f544e31f12d8a Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 31 Jan 2024 20:44:00 -0500 Subject: [PATCH 2/3] [CLEANUP] --- vision_datasets/Dockerfile => Dockerfile | 0 {vision_datasets => logs}/processed_images.txt | 0 {scripts => logs}/processed_imagesold.txt | 0 {scripts => vision_datasets}/addid.py | 0 {scripts => vision_datasets}/gguf.py | 0 {scripts => vision_datasets}/phi.py | 0 {scripts => vision_datasets}/redo.py | 0 {scripts => vision_datasets}/renumber.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename vision_datasets/Dockerfile => Dockerfile (100%) rename {vision_datasets => logs}/processed_images.txt (100%) rename {scripts => logs}/processed_imagesold.txt (100%) rename {scripts => vision_datasets}/addid.py (100%) rename {scripts => vision_datasets}/gguf.py (100%) rename {scripts => vision_datasets}/phi.py (100%) rename {scripts => vision_datasets}/redo.py (100%) rename {scripts => vision_datasets}/renumber.py (100%) diff --git a/vision_datasets/Dockerfile b/Dockerfile similarity index 100% rename from vision_datasets/Dockerfile rename to Dockerfile diff --git a/vision_datasets/processed_images.txt b/logs/processed_images.txt similarity index 100% rename from vision_datasets/processed_images.txt rename to logs/processed_images.txt diff --git a/scripts/processed_imagesold.txt b/logs/processed_imagesold.txt similarity index 100% rename from scripts/processed_imagesold.txt rename to logs/processed_imagesold.txt diff --git a/scripts/addid.py b/vision_datasets/addid.py similarity index 100% rename from scripts/addid.py rename to vision_datasets/addid.py diff --git a/scripts/gguf.py b/vision_datasets/gguf.py similarity index 100% rename from scripts/gguf.py rename to vision_datasets/gguf.py diff --git a/scripts/phi.py b/vision_datasets/phi.py similarity index 100% rename from scripts/phi.py rename to vision_datasets/phi.py diff --git a/scripts/redo.py b/vision_datasets/redo.py similarity index 100% rename from scripts/redo.py rename to vision_datasets/redo.py diff --git a/scripts/renumber.py b/vision_datasets/renumber.py similarity index 100% rename from scripts/renumber.py rename to vision_datasets/renumber.py From 4ed0560d0991df699e859c66faf34cbbe5da174b Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 31 Jan 2024 20:45:06 -0500 Subject: [PATCH 3/3] cleanup --- example.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/example.py b/example.py index c44a5ad..dc297ff 100644 --- a/example.py +++ b/example.py @@ -2,9 +2,6 @@ from swarms import QwenVLMultiModal model = QwenVLMultiModal( -<<<<<<< HEAD - system_prompt="You, as the model, are presented with a visual problem. This could be an image containing various elements that you need to analyze, a graph that requires interpretation, or a visual puzzle. Your task is to examine the visual information carefully and describe your process of understanding and solving the problem.", -======= system_prompt=( "You, as the model, are presented with a visual problem. This" " could be an image containing various elements that you need" @@ -13,7 +10,6 @@ " information carefully and describe your process of" " understanding and solving the problem." ), ->>>>>>> a7d64d7 ([FEAT][create_base_retry_decorator]) ) iterator = ImageDatasetIterator("coco", model)