From 5117a0e33834561deb20fd568fcead5b5449c3d6 Mon Sep 17 00:00:00 2001 From: misha-chertushkin Date: Mon, 17 Feb 2025 11:51:20 +0000 Subject: [PATCH] Fix the data function --- notebooks/finetuning_torch.ipynb | 234 +++++++++++++++++++++++++++++-- 1 file changed, 225 insertions(+), 9 deletions(-) diff --git a/notebooks/finetuning_torch.ipynb b/notebooks/finetuning_torch.ipynb index 545822a..970fd51 100644 --- a/notebooks/finetuning_torch.ipynb +++ b/notebooks/finetuning_torch.ipynb @@ -20,9 +20,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "TimesFM v1.2.0. See https://github.com/google-research/timesfm/blob/master/README.md for updated APIs.\n", + "Loaded Jax TimesFM.\n", + "Loaded PyTorch TimesFM.\n" + ] + } + ], "source": [ "from os import path\n", "from typing import Optional, Tuple\n", @@ -139,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -168,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -252,10 +262,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ + "def get_data(context_len: int,\n", + " horizon_len: int,\n", + " freq_type: int = 0) -> Tuple[Dataset, Dataset]:\n", + " df = yf.download(\"AAPL\", start=\"2010-01-01\", end=\"2019-01-01\")\n", + " time_series = df[\"Close\"].values\n", + "\n", + " train_dataset, val_dataset = prepare_datasets(\n", + " series=time_series,\n", + " context_length=context_len,\n", + " horizon_length=horizon_len,\n", + " freq_type=freq_type,\n", + " train_split=0.8,\n", + " )\n", + "\n", + " print(f\"Created datasets:\")\n", + " print(f\"- Training samples: {len(train_dataset)}\")\n", + " print(f\"- Validation samples: {len(val_dataset)}\")\n", + " print(f\"- Using frequency type: {freq_type}\")\n", + " return train_dataset, val_dataset\n", + "\n", + "\n", "\n", "def single_gpu_example():\n", " \"\"\"Basic example of finetuning TimesFM on stock data.\"\"\"\n", @@ -290,17 +321,202 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ac84aeda3a1749ae8f30b06859067bb1", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Fetching 3 files: 0%| | 0/3 [00:00" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "Run data is saved locally in /home/chertushkin/forks/timesfm/notebooks/wandb/run-20250217_114343-tjs63ml2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "Syncing run chocolate-eon-50 to Weights & Biases (docs)
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + " View project at https://wandb.ai/mishacamry/timesfm-finetuning" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + " View run at https://wandb.ai/mishacamry/timesfm-finetuning/runs/tjs63ml2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Starting finetuning...\n" + ] + }, + { + "data": { + "text/html": [], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

Run history:


epoch▁▃▅▆█
learning_rate▁▁▁▁▁
train_loss█▃▂▁▁
val_loss█▁▄▁▂

Run summary:


epoch5
learning_rate0.0001
train_loss2.85423
val_loss26.7628

" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + " View run chocolate-eon-50 at: https://wandb.ai/mishacamry/timesfm-finetuning/runs/tjs63ml2
View project at: https://wandb.ai/mishacamry/timesfm-finetuning
Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "Find logs at: ./wandb/run-20250217_114343-tjs63ml2/logs" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Finetuning completed!\n", + "Training history: 5 epochs\n", + "Plot saved to timesfm_predictions.png\n" + ] + } + ], "source": [ "single_gpu_example()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "timesfm-311", + "display_name": "timesfm-DnAbSweh-py3.11", "language": "python", "name": "python3" }, @@ -314,7 +530,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.11" + "version": "3.11.10" } }, "nbformat": 4,