Files
gpt_from_scratch/practice.ipynb
T
2026-06-05 08:25:33 +08:00

129 lines
2.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "259a585b",
"metadata": {},
"outputs": [],
"source": [
"### heloo"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e18c006e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello world\n"
]
}
],
"source": [
"print(\"hello world\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fe7bf6eb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"cuda\n"
]
}
],
"source": [
"import torch\n",
"from torch._C import device\n",
"import torch.nn as nn\n",
"from torch.nn import functional as F\n",
"print(torch.cuda.is_available())\n",
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"print(device)\n",
"\n",
"if device == \"cuda\":\n",
" print(\"gpu\", torch.cuda.get_device_name(0))\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "4bddedb8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1115394\n",
"First Citizen:\n",
"Before we proceed any further, hear me speak.\n",
"\n",
"All:\n",
"Speak, speak.\n",
"\n",
"First Citizen:\n",
"You are all resolved rather to die than to famish?\n",
"\n",
"All:\n",
"Resolved. resolved.\n",
"\n",
"First Citizen:\n",
"First, you know Caius Marcius is chief enemy to the people.\n",
"\n"
]
}
],
"source": [
"with open(\"input.txt\", \"r\", encoding = \"utf-8\") as f:\n",
" text = f.read()\n",
"\n",
"print(len(text))\n",
"print(text[:250])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b33dcb00",
"metadata": {},
"outputs": [],
"source": [
"set(text)"
]
}
],
"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.12.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}