{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading parquet files...\n", "Processing dataframes...\n", "\n", "Merging dataframes...\n", "\n", "Formatting output...\n", "\n", "Total pairs found: 216775\n", "\n", "Saving to parquet file...\n", "\n", "Sample pairs:\n", " hip_filename \\\n", "0 fcd394853732933cc2ddcf59fa29d561f0263cb1.hip \n", "1 d654bdeca448d1a413a7cc87ccc3b4b7f18a965d.hip \n", "2 464e3d1584f0013dfda51116d9aaaf21bd91bc13.hip \n", "3 21a2390523ec5438ddf21ad9d91b04ae044ec944.hip \n", "4 2b375ca1064061439fdc87fb32d664cc9434d26e.hip \n", "\n", " cuda_filename \n", "0 fcd394853732933cc2ddcf59fa29d561f0263cb1.cu \n", "1 d654bdeca448d1a413a7cc87ccc3b4b7f18a965d.cu \n", "2 464e3d1584f0013dfda51116d9aaaf21bd91bc13.cu \n", "3 21a2390523ec5438ddf21ad9d91b04ae044ec944.cu \n", "4 2b375ca1064061439fdc87fb32d664cc9434d26e.cu \n" ] } ], "source": [ "import pandas as pd\n", "import multiprocessing as mp\n", "from tqdm import tqdm\n", "\n", "def create_paired_dataset(cuda_df, hip_df):\n", " print(\"Processing dataframes...\")\n", " \n", " # Create base names for both dataframes at once\n", " cuda_df['base_name'] = cuda_df['filename'].str.replace(r'\\.cu[h]?$', '', regex=True)\n", " hip_df['base_name'] = hip_df['filename'].str.replace(r'\\.hip$', '', regex=True)\n", " \n", " # Merge dataframes on base_name - this is much faster than iterative matching\n", " print(\"\\nMerging dataframes...\")\n", " paired_df = pd.merge(\n", " hip_df,\n", " cuda_df,\n", " on='base_name',\n", " suffixes=('_hip', '_cuda')\n", " )\n", " \n", " # Rename columns to match desired output format\n", " print(\"\\nFormatting output...\")\n", " result_df = pd.DataFrame({\n", " 'hip_filename': paired_df['filename_hip'],\n", " 'hip_content': paired_df['content_hip'],\n", " 'cuda_filename': paired_df['filename_cuda'],\n", " 'cuda_content': paired_df['content_cuda']\n", " })\n", " \n", " print(f\"\\nTotal pairs found: {len(result_df)}\")\n", " \n", " print(\"\\nSaving to parquet file...\")\n", " result_df.to_parquet('cuda_hip_paired.parquet')\n", " \n", " print(\"\\nSample pairs:\")\n", " print(result_df[['hip_filename', 'cuda_filename']].head())\n", " return result_df\n", "\n", "if __name__ == '__main__':\n", " print(\"Reading parquet files...\")\n", " cuda_df = pd.read_parquet('cuda_files.parquet')\n", " hip_df = pd.read_parquet('hip_files.parquet')\n", " create_paired_dataset(cuda_df, hip_df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "llava_med_v2", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.15" } }, "nbformat": 4, "nbformat_minor": 2 }