(input_csv_folder_path, store_csv_folder_path, GPU_offset)
| 27 | |
| 28 | |
| 29 | def single_process(input_csv_folder_path, store_csv_folder_path, GPU_offset): |
| 30 | |
| 31 | |
| 32 | # Setting |
| 33 | store_freq = 10 |
| 34 | device = 'cuda' |
| 35 | |
| 36 | |
| 37 | |
| 38 | # Read the csv file |
| 39 | csv_idx = GPU_offset |
| 40 | csv_file_path = os.path.join(input_csv_folder_path, "sub" + str(csv_idx) + ".csv") |
| 41 | print("CSV file we read is ", csv_file_path) |
| 42 | |
| 43 | |
| 44 | # Prepare the store file path |
| 45 | store_file_path = os.path.join(store_csv_folder_path, "sub" + str(csv_idx) + ".csv") |
| 46 | if not resume and os.path.exists(store_file_path): |
| 47 | # Remove existing csv |
| 48 | os.remove(store_file_path) |
| 49 | |
| 50 | # Resume the store csv |
| 51 | find_resume = True |
| 52 | if resume: # Read the last store row |
| 53 | find_resume = False |
| 54 | with open(store_file_path, 'r') as file: |
| 55 | reader = csv.reader(file) |
| 56 | store_rows = list(reader) |
| 57 | last_store_row = store_rows[-1] |
| 58 | print("The number of rows we have processed in the store csv is ", len(store_rows)) |
| 59 | |
| 60 | |
| 61 | # Init the model |
| 62 | processor = AutoProcessor.from_pretrained(model_path) |
| 63 | # bnb_config = BitsAndBytesConfig( |
| 64 | # load_in_4bit=True, |
| 65 | # bnb_4bit_compute_dtype=torch.float16, # Use float16 for computations |
| 66 | # bnb_4bit_use_double_quant=True, |
| 67 | # bnb_4bit_quant_type='nf4', # NormalFloat4 quantization |
| 68 | # ) |
| 69 | model = Qwen2_5_VLForConditionalGeneration.from_pretrained( |
| 70 | model_path, torch_dtype="auto", device_map="auto", |
| 71 | # quantization_config=bnb_config, |
| 72 | ) |
| 73 | |
| 74 | |
| 75 | # Read all row in the csv file |
| 76 | start_time = time.time() |
| 77 | info_lists = [] # The order will be follow automatically |
| 78 | with open(csv_file_path) as file_obj: |
| 79 | reader_obj = csv.reader(file_obj) |
| 80 | |
| 81 | # Iterate over each row in the csv |
| 82 | for row_idx, row in enumerate(reader_obj): |
| 83 | |
| 84 | # For the first row case (With all title content) |
| 85 | if row_idx == 0: # The first line is the title of content |
| 86 | elements = dict() |
no test coverage detected