routine
This commit is contained in:
		@@ -2,8 +2,54 @@
 | 
			
		||||
 "cells": [
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 4,
 | 
			
		||||
   "execution_count": 1,
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "ExecuteTime": {
 | 
			
		||||
     "end_time": "2025-01-20T07:32:36.354335Z",
 | 
			
		||||
     "start_time": "2025-01-20T07:32:35.224080Z"
 | 
			
		||||
    }
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "import torch\n",
 | 
			
		||||
    "import torch.nn as nn"
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": null,
 | 
			
		||||
   "metadata": {},
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "\n",
 | 
			
		||||
    "# 设置使用gpu7 cuda\n",
 | 
			
		||||
    "device = torch.device(\"cuda:7\" if torch.cuda.is_available() and torch.cuda.get_device_properties(0).total_memory >= 6*1024**3 else \"cpu\")"
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 2,
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "ExecuteTime": {
 | 
			
		||||
     "end_time": "2025-01-20T07:32:38.297401Z",
 | 
			
		||||
     "start_time": "2025-01-20T07:32:38.261009Z"
 | 
			
		||||
    }
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "# 设置使用mps mps设备当前未支持限制内存\n",
 | 
			
		||||
    "device = torch.device(\"mps\" if torch.backends.mps.is_available() else \"cpu\")"
 | 
			
		||||
   ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
   "cell_type": "code",
 | 
			
		||||
   "execution_count": 3,
 | 
			
		||||
   "metadata": {
 | 
			
		||||
    "ExecuteTime": {
 | 
			
		||||
     "end_time": "2025-01-20T07:32:39.972353Z",
 | 
			
		||||
     "start_time": "2025-01-20T07:32:39.958549Z"
 | 
			
		||||
    }
 | 
			
		||||
   },
 | 
			
		||||
   "outputs": [
 | 
			
		||||
    {
 | 
			
		||||
     "name": "stdout",
 | 
			
		||||
@@ -20,12 +66,6 @@
 | 
			
		||||
    }
 | 
			
		||||
   ],
 | 
			
		||||
   "source": [
 | 
			
		||||
    "import torch\n",
 | 
			
		||||
    "import torch.nn as nn\n",
 | 
			
		||||
    "\n",
 | 
			
		||||
    "# 设置使用gpu7\n",
 | 
			
		||||
    "device = torch.device(\"cuda:7\" if torch.cuda.is_available() else \"cpu\")\n",
 | 
			
		||||
    "\n",
 | 
			
		||||
    "# 定义一个简单的神经元层\n",
 | 
			
		||||
    "class MultiLayerPerceptron(nn.Module):\n",
 | 
			
		||||
    "    def __init__(self, input_size, hidden_size1, hidden_size2, output_size):\n",
 | 
			
		||||
@@ -55,7 +95,7 @@
 | 
			
		||||
    "mlp = MultiLayerPerceptron(input_size=10, hidden_size1=20, hidden_size2=10, output_size=2)\n",
 | 
			
		||||
    "\n",
 | 
			
		||||
    "# 打印模型结构\n",
 | 
			
		||||
    "print(mlp)\n"
 | 
			
		||||
    "print(mlp)"
 | 
			
		||||
   ]
 | 
			
		||||
  }
 | 
			
		||||
 ],
 | 
			
		||||
@@ -75,7 +115,7 @@
 | 
			
		||||
   "name": "python",
 | 
			
		||||
   "nbconvert_exporter": "python",
 | 
			
		||||
   "pygments_lexer": "ipython3",
 | 
			
		||||
   "version": "3.11.9"
 | 
			
		||||
   "version": "3.10.14"
 | 
			
		||||
  }
 | 
			
		||||
 },
 | 
			
		||||
 "nbformat": 4,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user