Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
626 changes: 626 additions & 0 deletions build_flu_age_training_datasets.ipynb

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions emily_train.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4f2d8f69",
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import sys\n",
"import os\n",
"from torch.utils.data import DataLoader"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "99c59435",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Environment: Mac\n",
"Project root: /Users/emprzy/Documents/work/influpaint\n",
"Data path: /Users/emprzy/Documents/work/miscellaneous/influpaint_data/TS_30S70M_2025-07-17.nc\n"
]
}
],
"source": [
"if os.path.exists(\"/nas/longleaf/home/emprzy\"):\n",
" project_root = \"/nas/longleaf/home/emprzy/influpaint\"\n",
" # This matches the directory you just created\n",
" data_path = os.path.join(project_root, \"training_datasets/TS_30S70M_2025-07-17.nc\")\n",
"else:\n",
" project_root = \"/Users/emprzy/Documents/work/influpaint\"\n",
" data_path = \"/Users/emprzy/Documents/work/miscellaneous/influpaint_data/TS_30S70M_2025-07-17.nc\"\n",
"\n",
"if project_root not in sys.path:\n",
" sys.path.insert(0, project_root)\n",
"\n",
"# Point to the specific CoPaint folder\n",
"copaint_path = os.path.join(project_root, \"influpaint/batch/CoPaint4influpaint\")\n",
"if copaint_path not in sys.path:\n",
" sys.path.insert(0, copaint_path)\n",
"\n",
"print(f\"Environment: {'Longleaf' if 'nas' in project_root else 'Mac'}\")\n",
"print(f\"Project root: {project_root}\")\n",
"print(f\"Data path: {data_path}\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4e9a67a1",
"metadata": {},
"outputs": [],
"source": [
"from influpaint.batch.scenarios import get_training_scenario, create_scenario_objects, print_available_scenarios\n",
"from influpaint.batch.config import transform_library\n",
"from influpaint.datasets import loaders as training_datasets"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "df346a15",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using device: cpu\n"
]
}
],
"source": [
"# season_setup = SeasonAxis.for_flusight(remove_us=True, remove_territories=True) \n",
"image_size = 64\n",
"channels = 6\n",
"batch_size=512\n",
"epochs=3000\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"print(f\"Using device: {device}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7472d8a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"created dataset with max [188028. 109653.8 109653.8 109653.8 109653.8 109653.8], full dataset has shape (10000, 6, 64, 64)\n",
"test passed: back and forth transformation are ok ✅\n"
]
}
],
"source": [
"scn_id = 868 # i868::m_U500cRx1224::ds_30S70M::tr_Sqrt::ri_No\n",
"experiment_name = \"emily_first_train\" # MLflow experiment name\n",
"scenario_spec = get_training_scenario(scn_id)\n",
"ddpm, dataset, transform, enrich, scaling_per_channel, data_mean, data_sd = create_scenario_objects(\n",
" scenario_spec, image_size, channels, batch_size, epochs, device) # PATCH: removed season_setup param (don't need it b/c it is only used for `datasets`, which i will set explicitly)\n",
"# dataset = training_datasets.FluDataset.from_xarray(\"/Users/emprzy/Documents/work/miscellaneous/influpaint_data/TS_30S70M_2025-07-17.nc\",channels=channels,)\n",
"# don't need ^this^ line because i modified create_scenario_objects()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edf53cb8",
"metadata": {},
"outputs": [],
"source": [
"dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=True, drop_last=True)\n",
"losses = ddpm.train(dataloader, mlflow_logging=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.13.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
30 changes: 23 additions & 7 deletions influpaint/batch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,62 @@
}

def unet_library(image_size, channels):
unet_spec = { "Rx124":
# unet_library() logic has been patched
base_width = image_size

unet_spec = {
"Rx124":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 4,),
resnet_block_groups=1,
use_convnext=False
),
"Cx124":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 4,),
resnet_block_groups=1,
use_convnext=True
),
"Rx1224":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 2, 4,),
resnet_block_groups=1,
use_convnext=False
),
"Cx1224":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 2, 4,),
resnet_block_groups=1,
use_convnext=True
),
"Rx12448":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 4, 4, 8,),
resnet_block_groups=1,
use_convnext=False
),
"Cx12448":
nn_blocks.Unet(
dim=image_size,
dim=base_width,
init_dim=base_width,
channels=channels,
dim_mults=(1, 2, 4, 4, 8,),
resnet_block_groups=1,
use_convnext=True
),
}
Expand Down
13 changes: 9 additions & 4 deletions influpaint/batch/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import itertools
from .config import AVAILABLE_DDPMS,AVAILABLE_UNETS, AVAILABLE_DATASETS, AVAILABLE_TRANSFORMS, AVAILABLE_ENRICHMENTS, AVAILABLE_COPAINT_CONFIGS
from .config import CONFIG_BASELINE
from ..datasets import loaders as training_datasets


@dataclass(frozen=True)
Expand Down Expand Up @@ -164,8 +165,10 @@ def get_inpainting_scenario(scenario_id: int) -> InpaintingScenario:
return scenarios[scenario_id]


# Simple helper for research use
def create_scenario_objects(scenario_spec: TrainingScenario, season_setup, image_size=64, channels=1, batch_size=512, epochs=800, device="cuda"):
# --- PATCH ---
# REMOVED season_axis as a required param (don't need it b/c i will overwrite `dataset` manually)
# PATCH cascades into `config.py::get_dataset()` and `config.py::dataset_library()`
def create_scenario_objects(scenario_spec: TrainingScenario, season_setup=None, image_size=64, channels=1, batch_size=512, epochs=800, device="cuda"):
"""Create actual objects from scenario spec - one function does everything"""
from .config import ddpm_library, unet_library, get_dataset, transform_library
import numpy as np
Expand All @@ -176,7 +179,8 @@ def create_scenario_objects(scenario_spec: TrainingScenario, season_setup, image
ddpm_spec = ddpm_library(image_size, channels, epochs, device, batch_size, unet=unet)
ddpm = ddpm_spec[scenario_spec.ddpm_name]

dataset = get_dataset(scenario_spec.dataset_name, season_setup, channels)
# PATCH to avoid original dataset init
dataset = training_datasets.FluDataset.from_xarray("/Users/emprzy/Documents/work/miscellaneous/influpaint_data/TS_30S70M_2025-07-17.nc",channels=channels,)

# Create transforms
# scaling_per_channel = np.array(max(dataset.max_per_feature, gt1.gt_xarr.max(dim=["date", "place"])))
Expand All @@ -191,14 +195,15 @@ def create_scenario_objects(scenario_spec: TrainingScenario, season_setup, image
enrich = transform_enrich[scenario_spec.enrich_name]

# Configure dataset
dataset.add_transform(
dataset.add_transform( # had to PATCH transforms.py to make this work
transform=transform["reg"],
transform_inv=transform["inv"],
transform_enrich=enrich,
bypass_test=False
)

return ddpm, dataset, transform, enrich, scaling_per_channel, data_mean, data_std
# --- END PATCH ---


def print_available_scenarios():
Expand Down
Loading