Add training scripts for all-future and next-step supervision with DeepHealth
- Implement `train_all_future.py` for training with query-conditioned all-future supervision. - Implement `train_next_step.py` for training with next-token/next-time-point supervision. - Introduce `train_util.py` for shared utility functions including logging, dataset splitting, and model checkpointing. - Enhance argument parsing for both training scripts to accommodate new parameters. - Update loss functions and model configurations to support the new training paradigms.
This commit is contained in:
@@ -18,7 +18,7 @@ Efficiency notes:
|
||||
avoiding repeated pickling of arrays for every disease.
|
||||
|
||||
Run from the DeepHealth code directory containing dataset.py, models.py,
|
||||
readouts.py, and train.py-compatible checkpoints/configs.
|
||||
readouts.py, and train_config.json-compatible checkpoints/configs.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -38,7 +38,8 @@ import torch
|
||||
from torch.utils.data import DataLoader, Subset
|
||||
from tqdm.auto import tqdm
|
||||
|
||||
from dataset import HealthDataset, collate_fn
|
||||
from dataset import HealthDataset
|
||||
from eval_data import load_sequence_eval_dataset, sequence_eval_collate_fn
|
||||
from models import DeepHealth
|
||||
from readouts import build_readout
|
||||
from targets import PAD_IDX, CHECKUP_IDX, NO_EVENT_IDX
|
||||
@@ -1330,11 +1331,14 @@ def main() -> None:
|
||||
torch.backends.cudnn.benchmark = True
|
||||
|
||||
print("Loading dataset...")
|
||||
dataset = HealthDataset(
|
||||
dataset = load_sequence_eval_dataset(
|
||||
model_target_mode=model_target_mode,
|
||||
data_prefix=data_prefix,
|
||||
labels_file=labels_file,
|
||||
no_event_interval_years=no_event_interval_years,
|
||||
include_no_event_in_uts_target=include_no_event,
|
||||
min_history_events=int(cfg.get("all_future_min_history_events", 1)),
|
||||
min_future_events=int(cfg.get("all_future_min_future_events", 1)),
|
||||
extra_info_types=parse_int_list(cfg.get("extra_info_types", None)),
|
||||
)
|
||||
validate_dataset_metadata(dataset, cfg)
|
||||
@@ -1346,7 +1350,7 @@ def main() -> None:
|
||||
subset,
|
||||
batch_size=int(cfg_get(args, cfg, "batch_size", 128)),
|
||||
shuffle=False,
|
||||
collate_fn=collate_fn,
|
||||
collate_fn=sequence_eval_collate_fn,
|
||||
num_workers=int(cfg_get(args, cfg, "num_workers", 4)),
|
||||
pin_memory=device.type == "cuda",
|
||||
persistent_workers=int(cfg_get(args, cfg, "num_workers", 4)) > 0,
|
||||
|
||||
Reference in New Issue
Block a user