mirror of
https://github.com/vale981/ray
synced 2025-03-06 18:41:40 -05:00

Removes all ML related code from `ray.util` Removes: - `ray.util.xgboost` - `ray.util.lightgbm` - `ray.util.horovod` - `ray.util.ray_lightning` Moves `ray.util.ml_utils` to other locations Closes #23900 Signed-off-by: Amog Kamsetty <amogkamsetty@yahoo.com> Signed-off-by: Kai Fricke <kai@anyscale.com> Co-authored-by: Kai Fricke <kai@anyscale.com>
1061 lines
56 KiB
Text
1061 lines
56 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "586737af",
|
|
"metadata": {},
|
|
"source": [
|
|
"# How to use Tune with PyTorch\n",
|
|
"\n",
|
|
"(tune-pytorch-cifar-ref)=\n",
|
|
"\n",
|
|
"In this walkthrough, we will show you how to integrate Tune into your PyTorch\n",
|
|
"training workflow. We will follow [this tutorial from the PyTorch documentation](https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html)\n",
|
|
"for training a CIFAR10 image classifier.\n",
|
|
"\n",
|
|
"```{image} /images/pytorch_logo.png\n",
|
|
":align: center\n",
|
|
"```\n",
|
|
"\n",
|
|
"Hyperparameter tuning can make the difference between an average model and a highly\n",
|
|
"accurate one. Often simple things like choosing a different learning rate or changing\n",
|
|
"a network layer size can have a dramatic impact on your model performance. Fortunately,\n",
|
|
"Tune makes exploring these optimal parameter combinations easy - and works nicely\n",
|
|
"together with PyTorch.\n",
|
|
"\n",
|
|
"As you will see, we only need to add some slight modifications. In particular, we\n",
|
|
"need to\n",
|
|
"\n",
|
|
"1. wrap data loading and training in functions,\n",
|
|
"2. make some network parameters configurable,\n",
|
|
"3. add checkpointing (optional),\n",
|
|
"4. and define the search space for the model tuning\n",
|
|
"\n",
|
|
":::{note}\n",
|
|
"To run this example, you will need to install the following:\n",
|
|
"\n",
|
|
"```bash\n",
|
|
"$ pip install ray torch torchvision\n",
|
|
"```\n",
|
|
":::\n",
|
|
"\n",
|
|
"```{contents}\n",
|
|
":backlinks: none\n",
|
|
":local: true\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7e8650d1",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Setup / Imports\n",
|
|
"\n",
|
|
"Let's start with the imports:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "55529285",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"import os\n",
|
|
"import torch\n",
|
|
"import torch.nn as nn\n",
|
|
"import torch.nn.functional as F\n",
|
|
"import torch.optim as optim\n",
|
|
"from filelock import FileLock\n",
|
|
"from torch.utils.data import random_split\n",
|
|
"import torchvision\n",
|
|
"import torchvision.transforms as transforms\n",
|
|
"import ray\n",
|
|
"from ray import tune\n",
|
|
"from ray.air import session\n",
|
|
"from ray.air.checkpoint import Checkpoint\n",
|
|
"from ray.tune.schedulers import ASHAScheduler"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f59e551d",
|
|
"metadata": {},
|
|
"source": [
|
|
"Most of the imports are needed for building the PyTorch model. Only the last three\n",
|
|
"imports are for Ray Tune.\n",
|
|
"\n",
|
|
"## Data loaders\n",
|
|
"\n",
|
|
"We wrap the data loaders in their own function and pass a global data directory.\n",
|
|
"This way we can share a data directory between different trials."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "01471556",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def load_data(data_dir=\"./data\"):\n",
|
|
" transform = transforms.Compose([\n",
|
|
" transforms.ToTensor(),\n",
|
|
" transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))\n",
|
|
" ])\n",
|
|
"\n",
|
|
" # We add FileLock here because multiple workers will want to\n",
|
|
" # download data, and this may cause overwrites since\n",
|
|
" # DataLoader is not threadsafe.\n",
|
|
" with FileLock(os.path.expanduser(\"~/.data.lock\")):\n",
|
|
" trainset = torchvision.datasets.CIFAR10(\n",
|
|
" root=data_dir, train=True, download=True, transform=transform)\n",
|
|
"\n",
|
|
" testset = torchvision.datasets.CIFAR10(\n",
|
|
" root=data_dir, train=False, download=True, transform=transform)\n",
|
|
"\n",
|
|
" return trainset, testset"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "80958cf3",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Configurable neural network\n",
|
|
"\n",
|
|
"We can only tune those parameters that are configurable. In this example, we can specify\n",
|
|
"the layer sizes of the fully connected layers:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "fff6bd0d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Net(nn.Module):\n",
|
|
" def __init__(self, l1=120, l2=84):\n",
|
|
" super(Net, self).__init__()\n",
|
|
" self.conv1 = nn.Conv2d(3, 6, 5)\n",
|
|
" self.pool = nn.MaxPool2d(2, 2)\n",
|
|
" self.conv2 = nn.Conv2d(6, 16, 5)\n",
|
|
" self.fc1 = nn.Linear(16 * 5 * 5, l1)\n",
|
|
" self.fc2 = nn.Linear(l1, l2)\n",
|
|
" self.fc3 = nn.Linear(l2, 10)\n",
|
|
"\n",
|
|
" def forward(self, x):\n",
|
|
" x = self.pool(F.relu(self.conv1(x)))\n",
|
|
" x = self.pool(F.relu(self.conv2(x)))\n",
|
|
" x = x.view(-1, 16 * 5 * 5)\n",
|
|
" x = F.relu(self.fc1(x))\n",
|
|
" x = F.relu(self.fc2(x))\n",
|
|
" x = self.fc3(x)\n",
|
|
" return x"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fb619875",
|
|
"metadata": {},
|
|
"source": [
|
|
"## The train function\n",
|
|
"\n",
|
|
"Now it gets interesting, because we introduce some changes to the example [from the PyTorch\n",
|
|
"documentation](https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html).\n",
|
|
"\n",
|
|
"(communicating-with-ray-tune)=\n",
|
|
"\n",
|
|
"The full code example looks like this:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "fa0bdae0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def train_cifar(config):\n",
|
|
" net = Net(config[\"l1\"], config[\"l2\"])\n",
|
|
"\n",
|
|
" device = \"cpu\"\n",
|
|
" if torch.cuda.is_available():\n",
|
|
" device = \"cuda:0\"\n",
|
|
" if torch.cuda.device_count() > 1:\n",
|
|
" net = nn.DataParallel(net)\n",
|
|
" net.to(device)\n",
|
|
"\n",
|
|
" criterion = nn.CrossEntropyLoss()\n",
|
|
" optimizer = optim.SGD(net.parameters(), lr=config[\"lr\"], momentum=0.9)\n",
|
|
"\n",
|
|
" # To restore a checkpoint, use `session.get_checkpoint()`.\n",
|
|
" loaded_checkpoint = session.get_checkpoint()\n",
|
|
" if loaded_checkpoint:\n",
|
|
" with loaded_checkpoint.as_directory() as loaded_checkpoint_dir:\n",
|
|
" model_state, optimizer_state = torch.load(os.path.join(loaded_checkpoint_dir, \"checkpoint.pt\"))\n",
|
|
" net.load_state_dict(model_state)\n",
|
|
" optimizer.load_state_dict(optimizer_state)\n",
|
|
"\n",
|
|
" data_dir = os.path.abspath(\"./data\")\n",
|
|
" trainset, testset = load_data(data_dir)\n",
|
|
"\n",
|
|
" test_abs = int(len(trainset) * 0.8)\n",
|
|
" train_subset, val_subset = random_split(\n",
|
|
" trainset, [test_abs, len(trainset) - test_abs])\n",
|
|
"\n",
|
|
" trainloader = torch.utils.data.DataLoader(\n",
|
|
" train_subset,\n",
|
|
" batch_size=int(config[\"batch_size\"]),\n",
|
|
" shuffle=True,\n",
|
|
" num_workers=8)\n",
|
|
" valloader = torch.utils.data.DataLoader(\n",
|
|
" val_subset,\n",
|
|
" batch_size=int(config[\"batch_size\"]),\n",
|
|
" shuffle=True,\n",
|
|
" num_workers=8)\n",
|
|
"\n",
|
|
" for epoch in range(10): # loop over the dataset multiple times\n",
|
|
" running_loss = 0.0\n",
|
|
" epoch_steps = 0\n",
|
|
" for i, data in enumerate(trainloader, 0):\n",
|
|
" # get the inputs; data is a list of [inputs, labels]\n",
|
|
" inputs, labels = data\n",
|
|
" inputs, labels = inputs.to(device), labels.to(device)\n",
|
|
"\n",
|
|
" # zero the parameter gradients\n",
|
|
" optimizer.zero_grad()\n",
|
|
"\n",
|
|
" # forward + backward + optimize\n",
|
|
" outputs = net(inputs)\n",
|
|
" loss = criterion(outputs, labels)\n",
|
|
" loss.backward()\n",
|
|
" optimizer.step()\n",
|
|
"\n",
|
|
" # print statistics\n",
|
|
" running_loss += loss.item()\n",
|
|
" epoch_steps += 1\n",
|
|
" if i % 2000 == 1999: # print every 2000 mini-batches\n",
|
|
" print(\"[%d, %5d] loss: %.3f\" % (epoch + 1, i + 1,\n",
|
|
" running_loss / epoch_steps))\n",
|
|
" running_loss = 0.0\n",
|
|
"\n",
|
|
" # Validation loss\n",
|
|
" val_loss = 0.0\n",
|
|
" val_steps = 0\n",
|
|
" total = 0\n",
|
|
" correct = 0\n",
|
|
" for i, data in enumerate(valloader, 0):\n",
|
|
" with torch.no_grad():\n",
|
|
" inputs, labels = data\n",
|
|
" inputs, labels = inputs.to(device), labels.to(device)\n",
|
|
"\n",
|
|
" outputs = net(inputs)\n",
|
|
" _, predicted = torch.max(outputs.data, 1)\n",
|
|
" total += labels.size(0)\n",
|
|
" correct += (predicted == labels).sum().item()\n",
|
|
"\n",
|
|
" loss = criterion(outputs, labels)\n",
|
|
" val_loss += loss.cpu().numpy()\n",
|
|
" val_steps += 1\n",
|
|
"\n",
|
|
" # Here we save a checkpoint. It is automatically registered with\n",
|
|
" # Ray Tune and can be accessed through `session.get_checkpoint()`\n",
|
|
" # API in future iterations.\n",
|
|
" os.makedirs(\"my_model\", exist_ok=True)\n",
|
|
" torch.save(\n",
|
|
" (net.state_dict(), optimizer.state_dict()), \"my_model/checkpoint.pt\")\n",
|
|
" checkpoint = Checkpoint.from_directory(\"my_model\")\n",
|
|
" session.report({\"loss\": (val_loss / val_steps), \"accuracy\": correct / total}, checkpoint=checkpoint)\n",
|
|
" print(\"Finished Training\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "918d8baf",
|
|
"metadata": {},
|
|
"source": [
|
|
"As you can see, most of the code is adapted directly from the example.\n",
|
|
"\n",
|
|
"## Test set accuracy\n",
|
|
"\n",
|
|
"Commonly the performance of a machine learning model is tested on a hold-out test\n",
|
|
"set with data that has not been used for training the model. We also wrap this in a\n",
|
|
"function:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "93b5b4af",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def test_best_model(best_result):\n",
|
|
" best_trained_model = Net(best_result.config[\"l1\"], best_result.config[\"l2\"])\n",
|
|
" device = \"cuda:0\" if torch.cuda.is_available() else \"cpu\"\n",
|
|
" best_trained_model.to(device)\n",
|
|
"\n",
|
|
" checkpoint_path = os.path.join(best_result.checkpoint.to_directory(), \"checkpoint.pt\")\n",
|
|
"\n",
|
|
" model_state, optimizer_state = torch.load(checkpoint_path)\n",
|
|
" best_trained_model.load_state_dict(model_state)\n",
|
|
"\n",
|
|
" trainset, testset = load_data()\n",
|
|
"\n",
|
|
" testloader = torch.utils.data.DataLoader(\n",
|
|
" testset, batch_size=4, shuffle=False, num_workers=2)\n",
|
|
"\n",
|
|
" correct = 0\n",
|
|
" total = 0\n",
|
|
" with torch.no_grad():\n",
|
|
" for data in testloader:\n",
|
|
" images, labels = data\n",
|
|
" images, labels = images.to(device), labels.to(device)\n",
|
|
" outputs = best_trained_model(images)\n",
|
|
" _, predicted = torch.max(outputs.data, 1)\n",
|
|
" total += labels.size(0)\n",
|
|
" correct += (predicted == labels).sum().item()\n",
|
|
"\n",
|
|
"\n",
|
|
" print(\"Best trial test set accuracy: {}\".format(correct / total))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "85f8230e",
|
|
"metadata": {},
|
|
"source": [
|
|
"As you can see, the function also expects a `device` parameter, so we can do the\n",
|
|
"test set validation on a GPU.\n",
|
|
"\n",
|
|
"## Configuring the search space\n",
|
|
"\n",
|
|
"Lastly, we need to define Tune's search space. Here is an example:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "5416cece",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"config = {\n",
|
|
" \"l1\": tune.sample_from(lambda _: 2**np.random.randint(2, 9)),\n",
|
|
" \"l2\": tune.sample_from(lambda _: 2**np.random.randint(2, 9)),\n",
|
|
" \"lr\": tune.loguniform(1e-4, 1e-1),\n",
|
|
" \"batch_size\": tune.choice([2, 4, 8, 16]),\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "20af95cc",
|
|
"metadata": {},
|
|
"source": [
|
|
"The `tune.sample_from()` function makes it possible to define your own sample\n",
|
|
"methods to obtain hyperparameters. In this example, the `l1` and `l2` parameters\n",
|
|
"should be powers of 2 between 4 and 256, so either 4, 8, 16, 32, 64, 128, or 256.\n",
|
|
"The `lr` (learning rate) should be uniformly sampled between 0.0001 and 0.1. Lastly,\n",
|
|
"the batch size is a choice between 2, 4, 8, and 16.\n",
|
|
"\n",
|
|
"At each trial, Tune will now randomly sample a combination of parameters from these\n",
|
|
"search spaces. It will then train a number of models in parallel and find the best\n",
|
|
"performing one among these. We also use the `ASHAScheduler` which will terminate bad\n",
|
|
"performing trials early.\n",
|
|
"\n",
|
|
"You can specify the number of CPUs, which are then available e.g.\n",
|
|
"to increase the `num_workers` of the PyTorch `DataLoader` instances. The selected\n",
|
|
"number of GPUs are made visible to PyTorch in each trial. Trials do not have access to\n",
|
|
"GPUs that haven't been requested for them - so you don't have to care about two trials\n",
|
|
"using the same set of resources.\n",
|
|
"\n",
|
|
"Here we can also specify fractional GPUs, so something like `gpus_per_trial=0.5` is\n",
|
|
"completely valid. The trials will then share GPUs among each other.\n",
|
|
"You just have to make sure that the models still fit in the GPU memory.\n",
|
|
"\n",
|
|
"After training the models, we will find the best performing one and load the trained\n",
|
|
"network from the checkpoint file. We then obtain the test set accuracy and report\n",
|
|
"everything by printing.\n",
|
|
"\n",
|
|
"The full main function looks like this:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "91d83380",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2022-07-22 16:38:53,384\tINFO services.py:1483 -- View the Ray dashboard at \u001b[1m\u001b[32mhttp://127.0.0.1:8273\u001b[39m\u001b[22m\n",
|
|
"2022-07-22 16:38:56,785\tWARNING function_trainable.py:619 -- Function checkpointing is disabled. This may result in unexpected behavior when using checkpointing features or certain schedulers. To enable, set the train function arguments to be `func(config, checkpoint_dir=None)`.\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"== Status ==<br>Current time: 2022-07-22 16:40:13 (running for 00:01:16.43)<br>Memory usage on this node: 10.7/16.0 GiB<br>Using AsyncHyperBand: num_stopped=2\n",
|
|
"Bracket: Iter 2.000: -1.421571186053753 | Iter 1.000: -1.7652838359832763<br>Resources requested: 0/16 CPUs, 0/0 GPUs, 0.0/5.63 GiB heap, 0.0/2.0 GiB objects<br>Current best trial: 66098_00000 with loss=1.421571186053753 and parameters={'l1': 128, 'l2': 128, 'lr': 0.00046907397024184945, 'batch_size': 4}<br>Result logdir: /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50<br>Number of trials: 2/2 (2 TERMINATED)<br><table>\n",
|
|
"<thead>\n",
|
|
"<tr><th>Trial name </th><th>status </th><th>loc </th><th style=\"text-align: right;\"> batch_size</th><th style=\"text-align: right;\"> l1</th><th style=\"text-align: right;\"> l2</th><th style=\"text-align: right;\"> lr</th><th style=\"text-align: right;\"> iter</th><th style=\"text-align: right;\"> total time (s)</th><th style=\"text-align: right;\"> loss</th><th style=\"text-align: right;\"> accuracy</th></tr>\n",
|
|
"</thead>\n",
|
|
"<tbody>\n",
|
|
"<tr><td>train_cifar_66098_00000</td><td>TERMINATED</td><td>127.0.0.1:53065</td><td style=\"text-align: right;\"> 4</td><td style=\"text-align: right;\"> 128</td><td style=\"text-align: right;\"> 128</td><td style=\"text-align: right;\">0.000469074</td><td style=\"text-align: right;\"> 2</td><td style=\"text-align: right;\"> 72.6176</td><td style=\"text-align: right;\">1.42157</td><td style=\"text-align: right;\"> 0.4877</td></tr>\n",
|
|
"<tr><td>train_cifar_66098_00001</td><td>TERMINATED</td><td>127.0.0.1:53078</td><td style=\"text-align: right;\"> 4</td><td style=\"text-align: right;\"> 128</td><td style=\"text-align: right;\"> 64</td><td style=\"text-align: right;\">0.00993903 </td><td style=\"text-align: right;\"> 1</td><td style=\"text-align: right;\"> 64.9721</td><td style=\"text-align: right;\">1.90462</td><td style=\"text-align: right;\"> 0.2915</td></tr>\n",
|
|
"</tbody>\n",
|
|
"</table><br><br>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2022-07-22 16:38:57,794\tINFO plugin_schema_manager.py:52 -- Loading the default runtime env schemas: ['/Users/kai/coding/ray/python/ray/_private/runtime_env/../../runtime_env/schemas/working_dir_schema.json', '/Users/kai/coding/ray/python/ray/_private/runtime_env/../../runtime_env/schemas/pip_schema.json'].\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00000_0_batch_size=4,l1=128,l2=128,lr=0.0005_2022-07-22_16-38-57/data/cifar-10-python.tar.gz\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0%| | 0/170498071 [00:00<?, ?it/s]\n",
|
|
" 0%| | 33792/170498071 [00:00<14:09, 200766.21it/s]\n",
|
|
" 0%| | 197632/170498071 [00:00<04:21, 650251.40it/s]\n",
|
|
" 0%| | 492544/170498071 [00:00<02:02, 1393215.11it/s]\n",
|
|
" 1%| | 1082368/170498071 [00:00<01:00, 2821583.21it/s]\n",
|
|
" 1%| | 1950720/170498071 [00:00<00:36, 4640856.44it/s]\n",
|
|
" 2%|▏ | 2835456/170498071 [00:00<00:28, 5924997.25it/s]\n",
|
|
" 2%|▏ | 3965952/170498071 [00:00<00:22, 7537390.37it/s]\n",
|
|
" 3%|▎ | 5063680/170498071 [00:00<00:19, 8499565.01it/s]\n",
|
|
" 4%|▎ | 6128640/170498071 [00:01<00:17, 9134765.49it/s]\n",
|
|
" 4%|▍ | 7406592/170498071 [00:01<00:15, 10222961.60it/s]\n",
|
|
" 5%|▌ | 8553472/170498071 [00:01<00:15, 10510446.68it/s]\n",
|
|
" 6%|▌ | 9700352/170498071 [00:01<00:14, 10735559.18it/s]\n",
|
|
" 6%|▋ | 10863616/170498071 [00:01<00:14, 11000864.50it/s]\n",
|
|
" 7%|▋ | 11971584/170498071 [00:01<00:14, 10807721.84it/s]\n",
|
|
" 8%|▊ | 13059072/170498071 [00:01<00:14, 10666283.43it/s]\n",
|
|
" 8%|▊ | 14130176/170498071 [00:01<00:14, 10574609.87it/s]\n",
|
|
" 9%|▉ | 15303680/170498071 [00:01<00:14, 10892197.45it/s]\n",
|
|
" 10%|▉ | 16396288/170498071 [00:01<00:14, 10675729.31it/s]\n",
|
|
" 10%|█ | 17548288/170498071 [00:02<00:14, 10904960.72it/s]\n",
|
|
" 11%|█ | 18641920/170498071 [00:02<00:15, 9863782.34it/s] \n",
|
|
" 12%|█▏ | 20268032/170498071 [00:02<00:12, 11570721.42it/s]\n",
|
|
" 13%|█▎ | 21452800/170498071 [00:02<00:12, 11541443.91it/s]\n",
|
|
" 13%|█▎ | 22742016/170498071 [00:02<00:12, 11907361.68it/s]\n",
|
|
" 14%|█▍ | 23948288/170498071 [00:02<00:12, 11767051.50it/s]\n",
|
|
" 15%|█▍ | 25136128/170498071 [00:02<00:12, 11573913.54it/s]\n",
|
|
" 15%|█▌ | 26362880/170498071 [00:02<00:12, 11761937.08it/s]\n",
|
|
" 16%|█▌ | 27545600/170498071 [00:02<00:12, 11044330.05it/s]\n",
|
|
" 17%|█▋ | 28662784/170498071 [00:03<00:12, 11026608.99it/s]\n",
|
|
" 17%|█▋ | 29819904/170498071 [00:03<00:12, 11138417.94it/s]\n",
|
|
" 18%|█▊ | 30940160/170498071 [00:03<00:12, 11010962.50it/s]\n",
|
|
" 19%|█▉ | 32046080/170498071 [00:03<00:13, 10129993.91it/s]\n",
|
|
" 19%|█▉ | 33074176/170498071 [00:03<00:13, 9943367.80it/s] \n",
|
|
" 20%|██ | 34259968/170498071 [00:03<00:13, 10448733.26it/s]\n",
|
|
" 21%|██ | 35521536/170498071 [00:03<00:12, 11062770.09it/s]\n",
|
|
" 22%|██▏ | 36799488/170498071 [00:03<00:11, 11524350.69it/s]\n",
|
|
" 22%|██▏ | 37961728/170498071 [00:03<00:11, 11438058.60it/s]\n",
|
|
" 23%|██▎ | 39112704/170498071 [00:04<00:11, 11458573.52it/s]\n",
|
|
" 24%|██▎ | 40263680/170498071 [00:04<00:11, 11424542.73it/s]\n",
|
|
" 24%|██▍ | 41409536/170498071 [00:04<00:11, 11346691.19it/s]\n",
|
|
" 25%|██▌ | 42697728/170498071 [00:04<00:10, 11786332.70it/s]\n",
|
|
" 26%|██▌ | 43879424/170498071 [00:04<00:11, 11446463.24it/s]\n",
|
|
" 26%|██▋ | 45028352/170498071 [00:04<00:11, 10783870.46it/s]\n",
|
|
" 27%|██▋ | 46115840/170498071 [00:04<00:11, 10678464.51it/s]\n",
|
|
" 28%|██▊ | 47190016/170498071 [00:04<00:11, 10442301.65it/s]\n",
|
|
" 28%|██▊ | 48350208/170498071 [00:04<00:11, 10759276.29it/s]\n",
|
|
" 29%|██▉ | 49447936/170498071 [00:04<00:11, 10792782.74it/s]\n",
|
|
" 30%|██▉ | 50731008/170498071 [00:05<00:10, 11385649.79it/s]\n",
|
|
" 31%|███ | 52003840/170498071 [00:05<00:10, 11752264.60it/s]\n",
|
|
" 31%|███ | 53183488/170498071 [00:05<00:10, 11665484.87it/s]\n",
|
|
" 32%|███▏ | 54360064/170498071 [00:05<00:09, 11694832.15it/s]\n",
|
|
" 33%|███▎ | 55531520/170498071 [00:05<00:10, 11476978.86it/s]\n",
|
|
" 33%|███▎ | 56681472/170498071 [00:05<00:10, 11202902.06it/s]\n",
|
|
" 35%|███▍ | 59196416/170498071 [00:05<00:09, 11613442.08it/s]\n",
|
|
" 35%|███▌ | 60392448/170498071 [00:05<00:09, 11697365.01it/s]\n",
|
|
" 36%|███▌ | 61568000/170498071 [00:05<00:09, 11682261.49it/s]\n",
|
|
" 37%|███▋ | 62740480/170498071 [00:06<00:09, 11452394.76it/s]\n",
|
|
" 37%|███▋ | 63889408/170498071 [00:06<00:09, 11380145.84it/s]\n",
|
|
" 38%|███▊ | 65030144/170498071 [00:06<00:09, 10851178.13it/s]\n",
|
|
" 39%|███▉ | 66126848/170498071 [00:06<00:09, 10801561.44it/s]\n",
|
|
" 39%|███▉ | 67224576/170498071 [00:06<00:09, 10829254.00it/s]\n",
|
|
" 40%|████ | 68322304/170498071 [00:06<00:09, 10860535.53it/s]\n",
|
|
" 41%|████ | 69410816/170498071 [00:06<00:09, 10588112.87it/s]\n",
|
|
" 41%|████▏ | 70472704/170498071 [00:06<00:09, 10246538.71it/s]\n",
|
|
" 42%|████▏ | 71500800/170498071 [00:06<00:09, 9998803.68it/s] \n",
|
|
" 43%|████▎ | 72631296/170498071 [00:07<00:09, 10246250.37it/s]\n",
|
|
" 43%|████▎ | 73746432/170498071 [00:07<00:09, 10505166.41it/s]\n",
|
|
" 44%|████▍ | 74843136/170498071 [00:07<00:09, 10607834.22it/s]\n",
|
|
" 45%|████▍ | 75907072/170498071 [00:07<00:09, 10449028.08it/s]\n",
|
|
" 45%|████▌ | 76954624/170498071 [00:07<00:08, 10432352.97it/s]\n",
|
|
" 46%|████▌ | 78021632/170498071 [00:07<00:08, 10390722.73it/s]\n",
|
|
" 46%|████▋ | 79119360/170498071 [00:07<00:08, 10527472.73it/s]\n",
|
|
" 47%|████▋ | 80173056/170498071 [00:07<00:08, 10185476.35it/s]\n",
|
|
" 48%|████▊ | 81265664/170498071 [00:07<00:08, 10271324.45it/s]\n",
|
|
" 48%|████▊ | 82396160/170498071 [00:07<00:08, 10568711.71it/s]\n",
|
|
" 49%|████▉ | 83456000/170498071 [00:08<00:08, 10544461.91it/s]\n",
|
|
" 50%|████▉ | 84624384/170498071 [00:08<00:07, 10847079.54it/s]\n",
|
|
" 50%|█████ | 85754880/170498071 [00:08<00:07, 10930136.27it/s]\n",
|
|
" 51%|█████ | 86934528/170498071 [00:08<00:07, 11111543.18it/s]\n",
|
|
" 52%|█████▏ | 88179712/170498071 [00:08<00:07, 11438251.85it/s]\n",
|
|
" 52%|█████▏ | 89375744/170498071 [00:08<00:07, 11528186.37it/s]\n",
|
|
" 53%|█████▎ | 90620928/170498071 [00:08<00:06, 11741163.72it/s]\n",
|
|
" 54%|█████▍ | 91833344/170498071 [00:08<00:06, 11844882.32it/s]\n",
|
|
" 55%|█████▍ | 93019136/170498071 [00:08<00:07, 10859729.47it/s]\n",
|
|
" 55%|█████▌ | 94120960/170498071 [00:09<00:07, 10842087.69it/s]\n",
|
|
" 56%|█████▌ | 95216640/170498071 [00:09<00:07, 10396612.64it/s]\n",
|
|
" 56%|█████▋ | 96266240/170498071 [00:09<00:07, 10348003.47it/s]\n",
|
|
" 57%|█████▋ | 97354752/170498071 [00:09<00:06, 10497379.20it/s]\n",
|
|
" 58%|█████▊ | 98550784/170498071 [00:09<00:06, 10859176.06it/s]\n",
|
|
" 59%|█████▊ | 99746816/170498071 [00:09<00:06, 11154133.97it/s]\n",
|
|
" 59%|█████▉ | 101041152/170498071 [00:09<00:05, 11656717.30it/s]\n",
|
|
" 61%|██████ | 103482368/170498071 [00:09<00:05, 11894491.00it/s]\n",
|
|
" 61%|██████▏ | 104776704/170498071 [00:09<00:05, 12198050.59it/s]\n",
|
|
" 62%|██████▏ | 106021888/170498071 [00:10<00:05, 12267825.95it/s]\n",
|
|
" 63%|██████▎ | 107250688/170498071 [00:10<00:05, 12168871.59it/s]\n",
|
|
" 64%|██████▎ | 108469248/170498071 [00:10<00:05, 11595891.87it/s]\n",
|
|
" 64%|██████▍ | 109635584/170498071 [00:10<00:05, 11559630.86it/s]\n",
|
|
" 65%|██████▍ | 110795776/170498071 [00:10<00:05, 11349017.87it/s]\n",
|
|
" 66%|██████▌ | 111943680/170498071 [00:10<00:05, 11386490.70it/s]\n",
|
|
" 66%|██████▋ | 113085440/170498071 [00:10<00:05, 11297820.57it/s]\n",
|
|
" 67%|██████▋ | 114216960/170498071 [00:10<00:05, 11067298.70it/s]\n",
|
|
" 68%|██████▊ | 115325952/170498071 [00:10<00:05, 10487747.55it/s]\n",
|
|
" 68%|██████▊ | 116442112/170498071 [00:11<00:05, 10659499.65it/s]\n",
|
|
" 69%|██████▉ | 117720064/170498071 [00:11<00:04, 11250043.47it/s]\n",
|
|
" 70%|██████▉ | 118981632/170498071 [00:11<00:04, 11635244.90it/s]\n",
|
|
" 70%|███████ | 120151040/170498071 [00:11<00:04, 11648387.01it/s]\n",
|
|
" 71%|███████ | 121357312/170498071 [00:11<00:04, 11768670.42it/s]\n",
|
|
" 72%|███████▏ | 122586112/170498071 [00:11<00:04, 11905710.02it/s]\n",
|
|
" 73%|███████▎ | 123779072/170498071 [00:11<00:03, 11731120.04it/s]\n",
|
|
" 73%|███████▎ | 124954624/170498071 [00:11<00:03, 11738276.15it/s]\n",
|
|
" 74%|███████▍ | 126130176/170498071 [00:11<00:03, 11630197.21it/s]\n",
|
|
" 75%|███████▍ | 127370240/170498071 [00:11<00:03, 11827478.91it/s]\n",
|
|
" 75%|███████▌ | 128631808/170498071 [00:12<00:03, 12036486.08it/s]\n",
|
|
" 76%|███████▌ | 129860608/170498071 [00:12<00:03, 12070353.14it/s]\n",
|
|
" 77%|███████▋ | 131068928/170498071 [00:12<00:03, 11930703.88it/s]\n",
|
|
" 78%|███████▊ | 132262912/170498071 [00:12<00:03, 11640168.06it/s]\n",
|
|
" 78%|███████▊ | 133429248/170498071 [00:12<00:03, 11474541.42it/s]\n",
|
|
" 79%|███████▉ | 134611968/170498071 [00:12<00:03, 11412959.43it/s]\n",
|
|
" 80%|████████ | 137004032/170498071 [00:12<00:02, 11687905.40it/s]\n",
|
|
" 81%|████████ | 138174464/170498071 [00:13<00:05, 5764496.82it/s] \n",
|
|
" 83%|████████▎ | 141067264/170498071 [00:13<00:03, 9739825.72it/s]\n",
|
|
" 84%|████████▎ | 142558208/170498071 [00:13<00:02, 9526524.50it/s]\n",
|
|
" 84%|████████▍ | 143872000/170498071 [00:13<00:03, 6741235.46it/s]\n",
|
|
" 86%|████████▌ | 146703360/170498071 [00:13<00:02, 10136683.18it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 87%|████████▋ | 148267008/170498071 [00:14<00:02, 10106749.67it/s]\n",
|
|
" 88%|████████▊ | 149662720/170498071 [00:14<00:02, 10207494.38it/s]\n",
|
|
" 89%|████████▊ | 150955008/170498071 [00:14<00:01, 10359984.46it/s]\n",
|
|
" 89%|████████▉ | 152185856/170498071 [00:14<00:01, 10695074.47it/s]\n",
|
|
" 90%|████████▉ | 153402368/170498071 [00:14<00:01, 10797069.40it/s]\n",
|
|
" 91%|█████████ | 154587136/170498071 [00:14<00:01, 10637510.80it/s]\n",
|
|
" 91%|█████████▏| 155722752/170498071 [00:14<00:01, 10801079.07it/s]\n",
|
|
" 92%|█████████▏| 156895232/170498071 [00:14<00:01, 11046731.64it/s]\n",
|
|
" 93%|█████████▎| 158041088/170498071 [00:14<00:01, 11153902.38it/s]\n",
|
|
" 93%|█████████▎| 159286272/170498071 [00:15<00:00, 11495953.86it/s]\n",
|
|
" 94%|█████████▍| 160531456/170498071 [00:15<00:00, 11759881.01it/s]\n",
|
|
" 95%|█████████▍| 161809408/170498071 [00:15<00:00, 12040688.94it/s]\n",
|
|
" 96%|█████████▌| 163026944/170498071 [00:15<00:00, 12066384.42it/s]\n",
|
|
" 96%|█████████▋| 164242432/170498071 [00:15<00:00, 12030570.11it/s]\n",
|
|
" 97%|█████████▋| 165451776/170498071 [00:15<00:00, 11715975.80it/s]\n",
|
|
" 98%|█████████▊| 166629376/170498071 [00:15<00:00, 11429772.28it/s]\n",
|
|
" 98%|█████████▊| 167777280/170498071 [00:15<00:00, 11396536.97it/s]\n",
|
|
" 99%|█████████▉| 168921088/170498071 [00:15<00:00, 11335778.16it/s]\n",
|
|
"170499072it [00:16, 10634117.63it/s] \n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m Extracting /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00000_0_batch_size=4,l1=128,l2=128,lr=0.0005_2022-07-22_16-38-57/data/cifar-10-python.tar.gz to /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00000_0_batch_size=4,l1=128,l2=128,lr=0.0005_2022-07-22_16-38-57/data\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m Files already downloaded and verified\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m /Users/kai/.pyenv/versions/3.7.7/lib/python3.7/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at ../c10/core/TensorImpl.h:1156.)\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00001_1_batch_size=4,l1=128,l2=64,lr=0.0099_2022-07-22_16-39-01/data/cifar-10-python.tar.gz\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 0%| | 0/170498071 [00:00<?, ?it/s]\n",
|
|
" 0%| | 33792/170498071 [00:00<13:49, 205600.99it/s]\n",
|
|
" 0%| | 197632/170498071 [00:00<03:15, 869741.20it/s]\n",
|
|
" 0%| | 443392/170498071 [00:00<02:17, 1233031.00it/s]\n",
|
|
" 1%| | 1868800/170498071 [00:00<00:37, 4499043.51it/s]\n",
|
|
" 2%|▏ | 2589696/170498071 [00:00<00:31, 5313052.46it/s]\n",
|
|
" 2%|▏ | 3671040/170498071 [00:00<00:23, 6978488.44it/s]\n",
|
|
" 3%|▎ | 4703232/170498071 [00:00<00:20, 7988630.70it/s]\n",
|
|
" 3%|▎ | 5817344/170498071 [00:01<00:18, 8937646.63it/s]\n",
|
|
" 4%|▍ | 6996992/170498071 [00:01<00:16, 9785571.02it/s]\n",
|
|
" 5%|▍ | 8225792/170498071 [00:01<00:15, 10363873.64it/s]\n",
|
|
" 5%|▌ | 9307136/170498071 [00:01<00:15, 10452563.74it/s]\n",
|
|
" 6%|▌ | 10361856/170498071 [00:01<00:15, 10414666.33it/s]\n",
|
|
" 7%|▋ | 11469824/170498071 [00:01<00:14, 10611373.09it/s]\n",
|
|
" 7%|▋ | 12600320/170498071 [00:01<00:14, 10817759.86it/s]\n",
|
|
" 8%|▊ | 13685760/170498071 [00:01<00:14, 10674349.48it/s]\n",
|
|
" 9%|▊ | 14779392/170498071 [00:01<00:14, 10735551.44it/s]\n",
|
|
" 9%|▉ | 15893504/170498071 [00:01<00:14, 10841588.52it/s]\n",
|
|
" 10%|▉ | 17024000/170498071 [00:02<00:14, 10935080.88it/s]\n",
|
|
" 11%|█ | 18118656/170498071 [00:02<00:14, 10734313.48it/s]\n",
|
|
" 11%|█▏ | 19193856/170498071 [00:02<00:14, 10736033.30it/s]\n",
|
|
" 12%|█▏ | 20284416/170498071 [00:02<00:13, 10784705.38it/s]\n",
|
|
" 13%|█▎ | 22594560/170498071 [00:02<00:13, 11197004.04it/s]\n",
|
|
" 14%|█▍ | 23774208/170498071 [00:02<00:12, 11327905.78it/s]\n",
|
|
" 15%|█▍ | 24953856/170498071 [00:02<00:12, 11441768.69it/s]\n",
|
|
" 15%|█▌ | 26098688/170498071 [00:02<00:12, 11317906.35it/s]\n",
|
|
" 16%|█▌ | 27231232/170498071 [00:02<00:12, 11304969.94it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [1, 2000] loss: 2.289\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 17%|█▋ | 28558336/170498071 [00:03<00:11, 11857850.10it/s]\n",
|
|
" 17%|█▋ | 29745152/170498071 [00:03<00:11, 11779914.21it/s]\n",
|
|
" 18%|█▊ | 30923776/170498071 [00:03<00:12, 11470109.27it/s]\n",
|
|
" 19%|█▉ | 32072704/170498071 [00:03<00:12, 10962954.99it/s]\n",
|
|
" 19%|█▉ | 33244160/170498071 [00:03<00:12, 11138489.87it/s]\n",
|
|
" 20%|██ | 34362368/170498071 [00:03<00:12, 11060657.86it/s]\n",
|
|
" 21%|██ | 35488768/170498071 [00:03<00:12, 11075482.88it/s]\n",
|
|
" 22%|██▏ | 36733952/170498071 [00:03<00:11, 11463576.76it/s]\n",
|
|
" 22%|██▏ | 37946368/170498071 [00:03<00:11, 11644667.40it/s]\n",
|
|
" 23%|██▎ | 39207936/170498071 [00:03<00:11, 11771113.78it/s]\n",
|
|
" 24%|██▍ | 40551424/170498071 [00:04<00:10, 12239670.49it/s]\n",
|
|
" 25%|██▍ | 41777152/170498071 [00:04<00:10, 11724623.32it/s]\n",
|
|
" 25%|██▌ | 42959872/170498071 [00:04<00:10, 11728894.89it/s]\n",
|
|
" 26%|██▌ | 44237824/170498071 [00:04<00:10, 11980491.97it/s]\n",
|
|
" 27%|██▋ | 45474816/170498071 [00:04<00:10, 12094090.27it/s]\n",
|
|
" 27%|██▋ | 46687232/170498071 [00:04<00:10, 11965519.76it/s]\n",
|
|
" 28%|██▊ | 47886336/170498071 [00:04<00:12, 10214803.94it/s]\n",
|
|
" 29%|██▉ | 49693696/170498071 [00:04<00:09, 12272562.75it/s]\n",
|
|
" 30%|██▉ | 50979840/170498071 [00:04<00:09, 12216219.96it/s]\n",
|
|
" 31%|███ | 52242432/170498071 [00:05<00:10, 11819987.87it/s]\n",
|
|
" 31%|███▏ | 53508096/170498071 [00:05<00:09, 12050298.93it/s]\n",
|
|
" 32%|███▏ | 54735872/170498071 [00:05<00:09, 12065940.19it/s]\n",
|
|
" 33%|███▎ | 55958528/170498071 [00:05<00:09, 12089312.70it/s]\n",
|
|
" 34%|███▎ | 57274368/170498071 [00:05<00:09, 12399347.53it/s]\n",
|
|
" 34%|███▍ | 58523648/170498071 [00:05<00:09, 12262574.22it/s]\n",
|
|
" 35%|███▌ | 59756544/170498071 [00:05<00:09, 12035557.70it/s]\n",
|
|
" 36%|███▌ | 60998656/170498071 [00:05<00:09, 12133520.71it/s]\n",
|
|
" 37%|███▋ | 62276608/170498071 [00:05<00:08, 12211085.29it/s]\n",
|
|
" 37%|███▋ | 63501312/170498071 [00:06<00:08, 12042366.84it/s]\n",
|
|
" 38%|███▊ | 64708608/170498071 [00:06<00:08, 12023498.31it/s]\n",
|
|
" 39%|███▊ | 65912832/170498071 [00:06<00:08, 11757085.89it/s]\n",
|
|
" 39%|███▉ | 67090432/170498071 [00:06<00:09, 11320601.68it/s]\n",
|
|
" 40%|████ | 68227072/170498071 [00:06<00:09, 11258567.04it/s]\n",
|
|
" 41%|████ | 69355520/170498071 [00:06<00:09, 11082937.77it/s]\n",
|
|
" 41%|████▏ | 70465536/170498071 [00:06<00:09, 10911735.04it/s]\n",
|
|
" 42%|████▏ | 71558144/170498071 [00:06<00:09, 10780589.37it/s]\n",
|
|
" 43%|████▎ | 72680448/170498071 [00:06<00:08, 10893260.16it/s]\n",
|
|
" 43%|████▎ | 73771008/170498071 [00:06<00:08, 10841439.34it/s]\n",
|
|
" 44%|████▍ | 74856448/170498071 [00:07<00:08, 10769785.94it/s]\n",
|
|
" 45%|████▍ | 75940864/170498071 [00:07<00:08, 10763959.14it/s]\n",
|
|
" 45%|████▌ | 77054976/170498071 [00:07<00:08, 10849984.90it/s]\n",
|
|
" 46%|████▌ | 78140416/170498071 [00:07<00:08, 10726097.11it/s]\n",
|
|
" 47%|████▋ | 79315968/170498071 [00:07<00:08, 11026350.29it/s]\n",
|
|
" 47%|████▋ | 80462848/170498071 [00:07<00:08, 11146851.17it/s]\n",
|
|
" 48%|████▊ | 81593344/170498071 [00:07<00:08, 11105620.54it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [1, 4000] loss: 1.058\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 49%|████▊ | 82854912/170498071 [00:07<00:07, 11527296.83it/s]\n",
|
|
" 49%|████▉ | 84008960/170498071 [00:07<00:07, 11414359.53it/s]\n",
|
|
" 50%|████▉ | 85151744/170498071 [00:07<00:07, 10991470.33it/s]\n",
|
|
" 51%|█████ | 86254592/170498071 [00:08<00:07, 10779941.74it/s]\n",
|
|
" 51%|█████▏ | 87426048/170498071 [00:08<00:07, 10916081.56it/s]\n",
|
|
" 52%|█████▏ | 88548352/170498071 [00:08<00:07, 11004500.00it/s]\n",
|
|
" 53%|█████▎ | 89670656/170498071 [00:08<00:07, 11052931.99it/s]\n",
|
|
" 53%|█████▎ | 90850304/170498071 [00:08<00:07, 11002613.99it/s]\n",
|
|
" 54%|█████▍ | 92144640/170498071 [00:08<00:06, 11551701.57it/s]\n",
|
|
" 55%|█████▍ | 93357056/170498071 [00:08<00:06, 11700840.36it/s]\n",
|
|
" 55%|█████▌ | 94553088/170498071 [00:08<00:06, 11639934.12it/s]\n",
|
|
" 56%|█████▌ | 95724544/170498071 [00:08<00:06, 11661673.96it/s]\n",
|
|
" 57%|█████▋ | 96891904/170498071 [00:09<00:06, 11214261.52it/s]\n",
|
|
" 57%|█████▋ | 98017280/170498071 [00:09<00:06, 10988710.06it/s]\n",
|
|
" 58%|█████▊ | 99120128/170498071 [00:09<00:06, 10959602.56it/s]\n",
|
|
" 59%|█████▉ | 100218880/170498071 [00:09<00:06, 10938597.56it/s]\n",
|
|
" 59%|█████▉ | 101314560/170498071 [00:09<00:06, 10739220.45it/s]\n",
|
|
" 60%|██████ | 102417408/170498071 [00:09<00:06, 10815208.28it/s]\n",
|
|
" 61%|██████ | 103500800/170498071 [00:09<00:06, 10820566.49it/s]\n",
|
|
" 61%|██████▏ | 104678400/170498071 [00:09<00:05, 11089700.09it/s]\n",
|
|
" 62%|██████▏ | 105907200/170498071 [00:09<00:05, 11414720.98it/s]\n",
|
|
" 64%|██████▎ | 108348416/170498071 [00:10<00:05, 11853907.96it/s]\n",
|
|
" 64%|██████▍ | 109593600/170498071 [00:10<00:05, 12026577.90it/s]\n",
|
|
" 65%|██████▍ | 110797824/170498071 [00:10<00:05, 11649481.70it/s]\n",
|
|
" 66%|██████▌ | 111966208/170498071 [00:10<00:05, 11295371.19it/s]\n",
|
|
" 67%|██████▋ | 114279424/170498071 [00:10<00:05, 11174140.17it/s]\n",
|
|
" 68%|██████▊ | 115491840/170498071 [00:10<00:04, 11428872.46it/s]\n",
|
|
" 68%|██████▊ | 116638720/170498071 [00:10<00:04, 11376576.33it/s]\n",
|
|
" 69%|██████▉ | 117779456/170498071 [00:10<00:04, 11128529.20it/s]\n",
|
|
" 70%|██████▉ | 118894592/170498071 [00:10<00:04, 11105995.24it/s]\n",
|
|
" 70%|███████ | 120046592/170498071 [00:11<00:04, 11194307.10it/s]\n",
|
|
" 71%|███████ | 121291776/170498071 [00:11<00:04, 11529028.42it/s]\n",
|
|
" 72%|███████▏ | 122504192/170498071 [00:11<00:04, 11678012.53it/s]\n",
|
|
" 73%|███████▎ | 123673600/170498071 [00:11<00:04, 11616160.53it/s]\n",
|
|
" 73%|███████▎ | 124896256/170498071 [00:11<00:03, 11792603.53it/s]\n",
|
|
" 74%|███████▍ | 126092288/170498071 [00:11<00:03, 11722249.72it/s]\n",
|
|
" 75%|███████▍ | 127265792/170498071 [00:11<00:03, 11438563.16it/s]\n",
|
|
" 75%|███████▌ | 128411648/170498071 [00:11<00:03, 11383743.46it/s]\n",
|
|
" 76%|███████▌ | 129582080/170498071 [00:11<00:03, 11459099.89it/s]\n",
|
|
" 77%|███████▋ | 130728960/170498071 [00:12<00:03, 11417116.03it/s]\n",
|
|
" 77%|███████▋ | 131924992/170498071 [00:12<00:03, 11562162.11it/s]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [1, 6000] loss: 0.633\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" 78%|███████▊ | 133082112/170498071 [00:12<00:04, 8762729.97it/s] \n",
|
|
" 79%|███████▊ | 134251520/170498071 [00:12<00:03, 9459387.31it/s]\n",
|
|
" 79%|███████▉ | 135414784/170498071 [00:12<00:03, 10010405.01it/s]\n",
|
|
" 80%|████████ | 136610816/170498071 [00:12<00:03, 10523298.83it/s]\n",
|
|
" 82%|████████▏ | 138980352/170498071 [00:12<00:02, 11012610.93it/s]\n",
|
|
" 82%|████████▏ | 140198912/170498071 [00:12<00:02, 11337292.82it/s]\n",
|
|
" 83%|████████▎ | 141378560/170498071 [00:13<00:02, 11433312.45it/s]\n",
|
|
" 84%|████████▎ | 142537728/170498071 [00:13<00:02, 11225954.39it/s]\n",
|
|
" 84%|████████▍ | 143672320/170498071 [00:13<00:02, 11106773.35it/s]\n",
|
|
" 85%|████████▍ | 144884736/170498071 [00:13<00:02, 11392243.15it/s]\n",
|
|
" 86%|████████▌ | 146064384/170498071 [00:13<00:02, 11461605.17it/s]\n",
|
|
" 86%|████████▋ | 147276800/170498071 [00:13<00:01, 11644469.12it/s]\n",
|
|
" 87%|████████▋ | 148587520/170498071 [00:13<00:01, 12032938.55it/s]\n",
|
|
" 88%|████████▊ | 149793792/170498071 [00:13<00:01, 11625996.36it/s]\n",
|
|
" 89%|████████▊ | 150961152/170498071 [00:13<00:01, 11353618.86it/s]\n",
|
|
" 89%|████████▉ | 152100864/170498071 [00:13<00:01, 11210110.17it/s]\n",
|
|
" 90%|████████▉ | 153225216/170498071 [00:14<00:01, 10989692.27it/s]\n",
|
|
" 91%|█████████ | 154327040/170498071 [00:14<00:02, 6395856.39it/s] \n",
|
|
" 92%|█████████▏| 157336576/170498071 [00:14<00:01, 10963246.92it/s]\n",
|
|
" 93%|█████████▎| 158843904/170498071 [00:14<00:01, 10672622.13it/s]\n",
|
|
" 94%|█████████▍| 160198656/170498071 [00:15<00:01, 7535629.34it/s] \n",
|
|
" 96%|█████████▌| 163070976/170498071 [00:15<00:00, 11093551.80it/s]\n",
|
|
" 97%|█████████▋| 164648960/170498071 [00:15<00:00, 11143733.74it/s]\n",
|
|
" 97%|█████████▋| 166092800/170498071 [00:15<00:00, 11190526.07it/s]\n",
|
|
" 98%|█████████▊| 167443456/170498071 [00:15<00:00, 11480616.98it/s]\n",
|
|
" 99%|█████████▉| 168762368/170498071 [00:15<00:00, 11429373.68it/s]\n",
|
|
"170499072it [00:15, 10815137.24it/s] \n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m Extracting /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00001_1_batch_size=4,l1=128,l2=64,lr=0.0099_2022-07-22_16-39-01/data/cifar-10-python.tar.gz to /Users/kai/ray_results/train_cifar_2022-07-22_16-38-50/train_cifar_66098_00001_1_batch_size=4,l1=128,l2=64,lr=0.0099_2022-07-22_16-39-01/data\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [1, 8000] loss: 0.434\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m Files already downloaded and verified\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m /Users/kai/.pyenv/versions/3.7.7/lib/python3.7/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at ../c10/core/TensorImpl.h:1156.)\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [1, 10000] loss: 0.325\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m [1, 2000] loss: 2.117\n",
|
|
"Result for train_cifar_66098_00000:\n",
|
|
" accuracy: 0.4004\n",
|
|
" date: 2022-07-22_16-39-47\n",
|
|
" done: false\n",
|
|
" experiment_id: 6512b700fdb64a458c3496f36ea1776c\n",
|
|
" hostname: Kais-MacBook-Pro.local\n",
|
|
" iterations_since_restore: 1\n",
|
|
" loss: 1.625945699906349\n",
|
|
" node_ip: 127.0.0.1\n",
|
|
" pid: 53065\n",
|
|
" should_checkpoint: true\n",
|
|
" time_since_restore: 45.849108934402466\n",
|
|
" time_this_iter_s: 45.849108934402466\n",
|
|
" time_total_s: 45.849108934402466\n",
|
|
" timestamp: 1658504387\n",
|
|
" timesteps_since_restore: 0\n",
|
|
" training_iteration: 1\n",
|
|
" trial_id: '66098_00000'\n",
|
|
" warmup_time: 0.003801107406616211\n",
|
|
" \n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m [1, 4000] loss: 0.983\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [2, 2000] loss: 1.582\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m [1, 6000] loss: 0.647\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [2, 4000] loss: 0.758\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m [1, 8000] loss: 0.489\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [2, 6000] loss: 0.499\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [2, 8000] loss: 0.365\n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53078)\u001b[0m [1, 10000] loss: 0.388\n",
|
|
"Result for train_cifar_66098_00001:\n",
|
|
" accuracy: 0.2915\n",
|
|
" date: 2022-07-22_16-40-09\n",
|
|
" done: true\n",
|
|
" experiment_id: 6410c16837024e5e903317c212a4af63\n",
|
|
" hostname: Kais-MacBook-Pro.local\n",
|
|
" iterations_since_restore: 1\n",
|
|
" loss: 1.9046219720602036\n",
|
|
" node_ip: 127.0.0.1\n",
|
|
" pid: 53078\n",
|
|
" should_checkpoint: true\n",
|
|
" time_since_restore: 64.97207283973694\n",
|
|
" time_this_iter_s: 64.97207283973694\n",
|
|
" time_total_s: 64.97207283973694\n",
|
|
" timestamp: 1658504409\n",
|
|
" timesteps_since_restore: 0\n",
|
|
" training_iteration: 1\n",
|
|
" trial_id: '66098_00001'\n",
|
|
" warmup_time: 0.0027120113372802734\n",
|
|
" \n",
|
|
"\u001b[2m\u001b[36m(train_cifar pid=53065)\u001b[0m [2, 10000] loss: 0.285\n",
|
|
"Result for train_cifar_66098_00000:\n",
|
|
" accuracy: 0.4877\n",
|
|
" date: 2022-07-22_16-40-13\n",
|
|
" done: true\n",
|
|
" experiment_id: 6512b700fdb64a458c3496f36ea1776c\n",
|
|
" hostname: Kais-MacBook-Pro.local\n",
|
|
" iterations_since_restore: 2\n",
|
|
" loss: 1.421571186053753\n",
|
|
" node_ip: 127.0.0.1\n",
|
|
" pid: 53065\n",
|
|
" should_checkpoint: true\n",
|
|
" time_since_restore: 72.61763620376587\n",
|
|
" time_this_iter_s: 26.768527269363403\n",
|
|
" time_total_s: 72.61763620376587\n",
|
|
" timestamp: 1658504413\n",
|
|
" timesteps_since_restore: 0\n",
|
|
" training_iteration: 2\n",
|
|
" trial_id: '66098_00000'\n",
|
|
" warmup_time: 0.003801107406616211\n",
|
|
" \n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2022-07-22 16:40:14,050\tINFO tune.py:738 -- Total run time: 77.27 seconds (76.42 seconds for the tuning loop).\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Best trial config: {'l1': 128, 'l2': 128, 'lr': 0.00046907397024184945, 'batch_size': 4}\n",
|
|
"Best trial final validation loss: 1.421571186053753\n",
|
|
"Best trial final validation accuracy: 0.4877\n",
|
|
"Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ./data/cifar-10-python.tar.gz\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "48688c4943794c738333408a117af6c7",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/170498071 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Extracting ./data/cifar-10-python.tar.gz to ./data\n",
|
|
"Files already downloaded and verified\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/Users/kai/.pyenv/versions/3.7.7/lib/python3.7/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at ../c10/core/TensorImpl.h:1156.)\n",
|
|
" return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Best trial test set accuracy: 0.4939\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"def main(num_samples=10, max_num_epochs=10, gpus_per_trial=2):\n",
|
|
" config = {\n",
|
|
" \"l1\": tune.sample_from(lambda _: 2 ** np.random.randint(2, 9)),\n",
|
|
" \"l2\": tune.sample_from(lambda _: 2 ** np.random.randint(2, 9)),\n",
|
|
" \"lr\": tune.loguniform(1e-4, 1e-1),\n",
|
|
" \"batch_size\": tune.choice([2, 4, 8, 16])\n",
|
|
" }\n",
|
|
" scheduler = ASHAScheduler(\n",
|
|
" max_t=max_num_epochs,\n",
|
|
" grace_period=1,\n",
|
|
" reduction_factor=2)\n",
|
|
" \n",
|
|
" tuner = tune.Tuner(\n",
|
|
" tune.with_resources(\n",
|
|
" tune.with_parameters(train_cifar),\n",
|
|
" resources={\"cpu\": 2, \"gpu\": gpus_per_trial}\n",
|
|
" ),\n",
|
|
" tune_config=tune.TuneConfig(\n",
|
|
" metric=\"loss\",\n",
|
|
" mode=\"min\",\n",
|
|
" scheduler=scheduler,\n",
|
|
" num_samples=num_samples,\n",
|
|
" ),\n",
|
|
" param_space=config,\n",
|
|
" )\n",
|
|
" results = tuner.fit()\n",
|
|
" \n",
|
|
" best_result = results.get_best_result(\"loss\", \"min\")\n",
|
|
"\n",
|
|
" print(\"Best trial config: {}\".format(best_result.config))\n",
|
|
" print(\"Best trial final validation loss: {}\".format(\n",
|
|
" best_result.metrics[\"loss\"]))\n",
|
|
" print(\"Best trial final validation accuracy: {}\".format(\n",
|
|
" best_result.metrics[\"accuracy\"]))\n",
|
|
"\n",
|
|
" test_best_model(best_result)\n",
|
|
"\n",
|
|
"main(num_samples=2, max_num_epochs=2, gpus_per_trial=0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b702b4ce",
|
|
"metadata": {},
|
|
"source": [
|
|
"If you run the code, an example output could look like this:\n",
|
|
"\n",
|
|
"```{code-block} bash\n",
|
|
":emphasize-lines: 7\n",
|
|
"\n",
|
|
" Number of trials: 10 (10 TERMINATED)\n",
|
|
" +-------------------------+------------+-------+------+------+-------------+--------------+---------+------------+----------------------+\n",
|
|
" | Trial name | status | loc | l1 | l2 | lr | batch_size | loss | accuracy | training_iteration |\n",
|
|
" |-------------------------+------------+-------+------+------+-------------+--------------+---------+------------+----------------------|\n",
|
|
" | train_cifar_87d1f_00000 | TERMINATED | | 64 | 4 | 0.00011629 | 2 | 1.87273 | 0.244 | 2 |\n",
|
|
" | train_cifar_87d1f_00001 | TERMINATED | | 32 | 64 | 0.000339763 | 8 | 1.23603 | 0.567 | 8 |\n",
|
|
" | train_cifar_87d1f_00002 | TERMINATED | | 8 | 16 | 0.00276249 | 16 | 1.1815 | 0.5836 | 10 |\n",
|
|
" | train_cifar_87d1f_00003 | TERMINATED | | 4 | 64 | 0.000648721 | 4 | 1.31131 | 0.5224 | 8 |\n",
|
|
" | train_cifar_87d1f_00004 | TERMINATED | | 32 | 16 | 0.000340753 | 8 | 1.26454 | 0.5444 | 8 |\n",
|
|
" | train_cifar_87d1f_00005 | TERMINATED | | 8 | 4 | 0.000699775 | 8 | 1.99594 | 0.1983 | 2 |\n",
|
|
" | train_cifar_87d1f_00006 | TERMINATED | | 256 | 8 | 0.0839654 | 16 | 2.3119 | 0.0993 | 1 |\n",
|
|
" | train_cifar_87d1f_00007 | TERMINATED | | 16 | 128 | 0.0758154 | 16 | 2.33575 | 0.1327 | 1 |\n",
|
|
" | train_cifar_87d1f_00008 | TERMINATED | | 16 | 8 | 0.0763312 | 16 | 2.31129 | 0.1042 | 4 |\n",
|
|
" | train_cifar_87d1f_00009 | TERMINATED | | 128 | 16 | 0.000124903 | 4 | 2.26917 | 0.1945 | 1 |\n",
|
|
" +-------------------------+------------+-------+------+------+-------------+--------------+---------+------------+----------------------+\n",
|
|
"\n",
|
|
"\n",
|
|
" Best trial config: {'l1': 8, 'l2': 16, 'lr': 0.0027624906698231976, 'batch_size': 16, 'data_dir': '...'}\n",
|
|
" Best trial final validation loss: 1.1815014744281769\n",
|
|
" Best trial final validation accuracy: 0.5836\n",
|
|
" Best trial test set accuracy: 0.5806\n",
|
|
"```\n",
|
|
"\n",
|
|
"As you can see, most trials have been stopped early in order to avoid wasting resources.\n",
|
|
"The best performing trial achieved a validation accuracy of about 58%, which could\n",
|
|
"be confirmed on the test set.\n",
|
|
"\n",
|
|
"So that's it! You can now tune the parameters of your PyTorch models.\n",
|
|
"\n",
|
|
"## See More PyTorch Examples\n",
|
|
"\n",
|
|
"- {doc}`/tune/examples/includes/mnist_pytorch`: Converts the PyTorch MNIST example to use Tune with the function-based API.\n",
|
|
" Also shows how to easily convert something relying on argparse to use Tune.\n",
|
|
"- {doc}`/tune/examples/includes/pbt_convnet_function_example`: Example training a ConvNet with checkpointing in function API.\n",
|
|
"- {doc}`/tune/examples/includes/mnist_pytorch_trainable`: Converts the PyTorch MNIST example to use Tune with Trainable API.\n",
|
|
" Also uses the HyperBandScheduler and checkpoints the model at the end."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.8.6"
|
|
},
|
|
"orphan": true
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|