From 773702b7e9a241fb70a7ca52e3fe087bec6a4308 Mon Sep 17 00:00:00 2001 From: Max Cotton Date: Sun, 4 Feb 2024 16:10:48 +0000 Subject: [PATCH] Add cpu vs gpu analysis notebook --- notebooks/cpu-vs-gpu-analysis.ipynb | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 notebooks/cpu-vs-gpu-analysis.ipynb diff --git a/notebooks/cpu-vs-gpu-analysis.ipynb b/notebooks/cpu-vs-gpu-analysis.ipynb new file mode 100644 index 0000000..d1948a5 --- /dev/null +++ b/notebooks/cpu-vs-gpu-analysis.ipynb @@ -0,0 +1,74 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following code trains a model on the XOR dataset using the CPU and then using the GPU to train, and then outputs the training time taken." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU Training Time: 160.45\n", + "GPU Training Time: 42.58\n" + ] + } + ], + "source": [ + "import os\n", + "\n", + "from school_project.models.cpu.cat_recognition import CatRecognitionModel as CPUModel\n", + "from school_project.models.gpu.cat_recognition import CatRecognitionModel as GPUModel\n", + "\n", + "# Change to root directory of project\n", + "os.chdir(os.getcwd())\n", + "\n", + "model = CPUModel(hidden_layers_shape=[100, 100],\n", + " train_dataset_size=209,\n", + " learning_rate=0.1,\n", + " use_relu=True)\n", + "model.create_model_values()\n", + "model.train(epoch_count=3_500)\n", + "\n", + "print(f\"CPU Training Time: {model.training_time}\")\n", + "\n", + "model = GPUModel(hidden_layers_shape=[100, 100],\n", + " train_dataset_size=209,\n", + " learning_rate=0.1,\n", + " use_relu=True)\n", + "model.create_model_values()\n", + "model.train(epoch_count=3_500)\n", + "\n", + "print(f\"GPU Training Time: {model.training_time}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "venv", + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}