-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from yu9824/dev
v2.2.0dev0
- Loading branch information
Showing
17 changed files
with
647 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# CPU vs GPU" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Device info\n", | ||
"\n", | ||
"- https://support.apple.com/kb/SP825" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from time import perf_counter\n", | ||
"\n", | ||
"from sklearn.datasets import fetch_california_housing\n", | ||
"\n", | ||
"# You need to install 'pytorch' when you use GPU\n", | ||
"import torch\n", | ||
"\n", | ||
"from kennard_stone import train_test_split\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"(20640, 8)" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"X = fetch_california_housing().data\n", | ||
"X.shape\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## CPU" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Calculating pairwise distances using scikit-learn.\n", | ||
"Calculating pairwise distances using scikit-learn.\n", | ||
"CPU: 178.731 sec\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"t_start = perf_counter()\n", | ||
"_ = train_test_split(\n", | ||
" X, test_size=0.2, n_jobs=-1, device=\"cpu\", metric=\"euclidean\"\n", | ||
")\n", | ||
"t_end = perf_counter()\n", | ||
"t_cpu = t_end - t_start\n", | ||
"print(f\"CPU: {t_cpu:.3f} sec\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## GPU" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Calculating pairwise distances using PyTorch on 'mps'.\n", | ||
"Calculating pairwise distances using PyTorch on 'mps'.\n", | ||
"mps: 33.525 sec\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# cuda\n", | ||
"if torch.cuda.is_available():\n", | ||
" device = \"cuda\"\n", | ||
"# mps (M1 Mac)\n", | ||
"elif torch.backends.mps.is_available():\n", | ||
" device = \"mps\"\n", | ||
"else:\n", | ||
" raise RuntimeError(\"GPU is not available.\")\n", | ||
"\n", | ||
"t_start = perf_counter()\n", | ||
"_ = train_test_split(\n", | ||
" X, test_size=0.2, n_jobs=-1, device=device, metric=\"euclidean\"\n", | ||
")\n", | ||
"t_end = perf_counter()\n", | ||
"t_gpu = t_end - t_start\n", | ||
"print(f\"{device}: {t_gpu:.3f} sec\")\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "kennard-stone", | ||
"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.9.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.