{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":7172307,"sourceType":"datasetVersion","datasetId":9}],"dockerImageVersionId":30627,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import traceback\n\nimport rmm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-14T15:17:43.904854Z","iopub.execute_input":"2023-12-14T15:17:43.905213Z","iopub.status.idle":"2023-12-14T15:17:44.065140Z","shell.execute_reply.started":"2023-12-14T15:17:43.905183Z","shell.execute_reply":"2023-12-14T15:17:44.064043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rmm.__version__","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:44.067355Z","iopub.execute_input":"2023-12-14T15:17:44.068094Z","iopub.status.idle":"2023-12-14T15:17:44.076700Z","shell.execute_reply.started":"2023-12-14T15:17:44.068052Z","shell.execute_reply":"2023-12-14T15:17:44.075654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cause_out_of_memory = False","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:44.078660Z","iopub.execute_input":"2023-12-14T15:17:44.079436Z","iopub.status.idle":"2023-12-14T15:17:44.084465Z","shell.execute_reply.started":"2023-12-14T15:17:44.079399Z","shell.execute_reply":"2023-12-14T15:17:44.083632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if not cause_out_of_memory:\n    # Set RMM to allocate all memory as managed memory (cudaMallocManaged underlying allocator)\n    rmm.reinitialize(managed_memory=True)\n    assert rmm.is_initialized()","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:44.087360Z","iopub.execute_input":"2023-12-14T15:17:44.088056Z","iopub.status.idle":"2023-12-14T15:17:44.259879Z","shell.execute_reply.started":"2023-12-14T15:17:44.088022Z","shell.execute_reply":"2023-12-14T15:17:44.258894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# cuDF","metadata":{}},{"cell_type":"code","source":"import cudf","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:44.261302Z","iopub.execute_input":"2023-12-14T15:17:44.261586Z","iopub.status.idle":"2023-12-14T15:17:49.313937Z","shell.execute_reply.started":"2023-12-14T15:17:44.261560Z","shell.execute_reply":"2023-12-14T15:17:49.312942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cudf.__version__","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:49.315580Z","iopub.execute_input":"2023-12-14T15:17:49.316202Z","iopub.status.idle":"2023-12-14T15:17:49.322901Z","shell.execute_reply.started":"2023-12-14T15:17:49.316162Z","shell.execute_reply":"2023-12-14T15:17:49.321399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if cause_out_of_memory:\n    try:\n        df = cudf.read_csv(\"/kaggle/input/meta-kaggle/UserAchievements.csv\")\n    except Exception as e:\n        traceback.print_exc()\n        print(e)\nelse:\n    df = cudf.read_csv(\"/kaggle/input/meta-kaggle/UserAchievements.csv\")\n    display(df.head())\n    \n    del df","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:17:49.324151Z","iopub.execute_input":"2023-12-14T15:17:49.324426Z","iopub.status.idle":"2023-12-14T15:19:06.091052Z","shell.execute_reply.started":"2023-12-14T15:17:49.324402Z","shell.execute_reply":"2023-12-14T15:19:06.090114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# pytorch","metadata":{}},{"cell_type":"code","source":"import torch","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:19:06.092453Z","iopub.execute_input":"2023-12-14T15:19:06.092818Z","iopub.status.idle":"2023-12-14T15:19:11.749370Z","shell.execute_reply.started":"2023-12-14T15:19:06.092784Z","shell.execute_reply":"2023-12-14T15:19:11.748458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.__version__","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:19:11.750608Z","iopub.execute_input":"2023-12-14T15:19:11.751147Z","iopub.status.idle":"2023-12-14T15:19:11.757730Z","shell.execute_reply.started":"2023-12-14T15:19:11.751116Z","shell.execute_reply":"2023-12-14T15:19:11.756641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"if cause_out_of_memory:\n    try:\n        tensor = torch.randn(size=(50000, 100000), device=\"cuda\")\n    except Exception as e:\n        traceback.print_exc()\n        print(e)\nelse:\n    from rmm.allocators.torch import rmm_torch_allocator\n    torch.cuda.memory.change_current_allocator(rmm_torch_allocator)\n    \n    tensor = torch.randn(size=(50000, 100000), device=\"cuda\")\n    print(tensor)","metadata":{"execution":{"iopub.status.busy":"2023-12-14T15:09:39.650966Z","iopub.execute_input":"2023-12-14T15:09:39.651245Z","iopub.status.idle":"2023-12-14T15:09:42.684962Z","shell.execute_reply.started":"2023-12-14T15:09:39.651222Z","shell.execute_reply":"2023-12-14T15:09:42.683967Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}