| """Modal GPU reproduction of DropoutTS (arXiv:2601.21726) claims. |
| |
| Trains the Informer backbone on the self-generating SyntheticTS benchmark, |
| baseline vs +DropoutTS, and captures test MSE/MAE + training wall-clock. |
| |
| Usage: |
| modal run modal_repro.py::smoke # 2-epoch smoke, one condition |
| modal run modal_repro.py::claim1 # full Synth noise sweep |
| """ |
| import modal |
|
|
| REPO = "DropoutTS" |
| IMAGE = ( |
| modal.Image.debian_slim(python_version="3.10") |
| .pip_install( |
| "torch", "numpy==1.24.4", "easy-torch==1.3.3", "easydict", "packaging", |
| "setproctitle", "pandas", "scikit-learn", "tables", "sympy", "openpyxl", |
| "setuptools==59.5.0", "tqdm==4.67.1", "tensorboard==2.18.0", |
| "transformers==4.40.1", "matplotlib", |
| ) |
| .add_local_dir(REPO, f"/root/{REPO}", copy=True) |
| ) |
| app = modal.App("dropoutts-repro", image=IMAGE) |
|
|
|
|
| def _run_training(model_name, dataset_name, noise_level, input_len, output_len, |
| use_dropout, num_epochs, seed=42, init_sensitivity=5.0): |
| """Runs inside the container: generate data, train one condition, return metrics.""" |
| import os, sys, glob, json, time, importlib |
| os.chdir(f"/root/{REPO}") |
| sys.path.insert(0, f"/root/{REPO}/src") |
| sys.path.insert(0, f"/root/{REPO}") |
|
|
| |
| gen = importlib.import_module("scripts.data_preparation.SyntheticTS.generate_training_data") |
| out_dir = f"/root/{REPO}/datasets/{dataset_name}" |
| if not os.path.exists(os.path.join(out_dir, "train_data.npy")): |
| suffix = f"_noise{noise_level:.1f}" |
| gen.generate_single_dataset(noise_level, 100, 336, 1, suffix, |
| base_dir_local=f"/root/{REPO}") |
|
|
| |
| from basicts.models.Informer import Informer, InformerConfig |
| from basicts.configs import BasicTSForecastingConfig |
| from basicts.runners.callback import EarlyStopping, DropoutTSCallback |
| from basicts import BasicTSLauncher |
|
|
| ts_sizes = [96, 7, 31, 366] |
| model_cfg = InformerConfig( |
| input_len=input_len, output_len=output_len, label_len=output_len // 2, |
| num_features=1, use_timestamps=True, timestamp_sizes=ts_sizes, |
| ) |
| callbacks = [EarlyStopping(patience=10)] |
| if use_dropout: |
| callbacks.insert(0, DropoutTSCallback( |
| p_min=0.05, p_max=0.5, init_alpha=10.0, init_sensitivity=init_sensitivity, |
| enable_visualization=False, enable_statistics=False, |
| )) |
|
|
| cfg = BasicTSForecastingConfig( |
| model=Informer, model_config=model_cfg, |
| dataset_name=dataset_name, input_len=input_len, output_len=output_len, |
| use_timestamps=True, use_clean_targets=True, |
| gpus="0", num_epochs=num_epochs, batch_size=64, callbacks=callbacks, seed=seed, |
| train_data_num_workers=2, val_data_num_workers=2, test_data_num_workers=2, |
| train_data_pin_memory=True, val_data_pin_memory=True, test_data_pin_memory=True, |
| ) |
|
|
| |
| t0 = time.time() |
| BasicTSLauncher.launch_training(cfg) |
| train_seconds = time.time() - t0 |
|
|
| |
| hits = sorted(glob.glob(f"/root/{REPO}/**/test_metrics.json", recursive=True), |
| key=os.path.getmtime) |
| metrics = json.load(open(hits[-1])) if hits else None |
|
|
| |
| epochs_run = None |
| logs = sorted(glob.glob(f"/root/{REPO}/**/training_log*.log", recursive=True), |
| key=os.path.getmtime) |
| if logs: |
| txt = open(logs[-1], errors="ignore").read() |
| import re |
| ep = re.findall(r"[Ee]poch\s*[:\s]\s*(\d+)\s*/\s*\d+", txt) |
| if ep: |
| epochs_run = max(int(e) for e in ep) |
|
|
| return { |
| "model": model_name, "dataset": dataset_name, "noise": noise_level, |
| "input_len": input_len, "output_len": output_len, |
| "dropout": use_dropout, "num_epochs_cap": num_epochs, |
| "epochs_run": epochs_run, "train_seconds": round(train_seconds, 1), |
| "init_sensitivity": init_sensitivity if use_dropout else None, |
| "metrics": metrics, |
| } |
|
|
|
|
| @app.function(gpu="A10G", timeout=3600) |
| def train_condition(**kw): |
| return _run_training(**kw) |
|
|
|
|
| def _run_training_ett(dataset_name, input_len, output_len, use_dropout, num_epochs, seed=42): |
| """Claim 2: real ETT dataset. Downloads CSV, preps, trains Informer +/- DropoutTS.""" |
| import os, sys, glob, json, time, subprocess, urllib.request, re |
| os.chdir(f"/root/{REPO}") |
| sys.path.insert(0, f"/root/{REPO}/src"); sys.path.insert(0, f"/root/{REPO}") |
|
|
| |
| raw_dir = f"/root/{REPO}/datasets/raw_data/{dataset_name}" |
| os.makedirs(raw_dir, exist_ok=True) |
| csv = f"{raw_dir}/{dataset_name}.csv" |
| if not os.path.exists(csv): |
| url = f"https://raw.githubusercontent.com/zhouhaoyi/ETDataset/main/ETT-small/{dataset_name}.csv" |
| urllib.request.urlretrieve(url, csv) |
| if not os.path.exists(f"/root/{REPO}/datasets/{dataset_name}/train_data.npy"): |
| subprocess.run([sys.executable, f"scripts/data_preparation/{dataset_name}/generate_training_data.py"], |
| check=True, cwd=f"/root/{REPO}") |
|
|
| |
| from basicts.models.Informer import Informer, InformerConfig |
| from basicts.configs import BasicTSForecastingConfig |
| from basicts.runners.callback import EarlyStopping, DropoutTSCallback |
| from basicts import BasicTSLauncher |
|
|
| model_cfg = InformerConfig( |
| input_len=input_len, output_len=output_len, label_len=output_len // 2, |
| num_features=7, use_timestamps=True, timestamp_sizes=[24, 7, 31, 366], |
| ) |
| callbacks = [EarlyStopping(patience=10)] |
| if use_dropout: |
| callbacks.insert(0, DropoutTSCallback( |
| p_min=0.05, p_max=0.5, init_alpha=10.0, init_sensitivity=5.0, |
| enable_visualization=False, enable_statistics=False, |
| )) |
| cfg = BasicTSForecastingConfig( |
| model=Informer, model_config=model_cfg, |
| dataset_name=dataset_name, input_len=input_len, output_len=output_len, |
| use_timestamps=True, use_clean_targets=False, |
| gpus="0", num_epochs=num_epochs, batch_size=64, callbacks=callbacks, seed=seed, |
| train_data_num_workers=2, val_data_num_workers=2, test_data_num_workers=2, |
| train_data_pin_memory=True, val_data_pin_memory=True, test_data_pin_memory=True, |
| ) |
|
|
| t0 = time.time() |
| BasicTSLauncher.launch_training(cfg) |
| train_seconds = time.time() - t0 |
|
|
| hits = sorted(glob.glob(f"/root/{REPO}/**/test_metrics.json", recursive=True), key=os.path.getmtime) |
| metrics = json.load(open(hits[-1])) if hits else None |
| epochs_run = None |
| logs = sorted(glob.glob(f"/root/{REPO}/**/training_log*.log", recursive=True), key=os.path.getmtime) |
| if logs: |
| ep = re.findall(r"[Ee]poch\s*[:\s]\s*(\d+)\s*/\s*\d+", open(logs[-1], errors="ignore").read()) |
| if ep: |
| epochs_run = max(int(e) for e in ep) |
| return { |
| "model": "Informer", "dataset": dataset_name, "noise": None, |
| "input_len": input_len, "output_len": output_len, "dropout": use_dropout, |
| "num_epochs_cap": num_epochs, "epochs_run": epochs_run, |
| "train_seconds": round(train_seconds, 1), "metrics": metrics, |
| } |
|
|
|
|
| @app.function(gpu="A10G", timeout=3600) |
| def train_ett(**kw): |
| return _run_training_ett(**kw) |
|
|
|
|
| def _run_training_c5(strategy, dataset_name, noise_level, input_len, output_len, num_epochs, seed=42): |
| """Claim 5: orthogonal compatibility. strategy in {baseline, sl, dropout_sl}.""" |
| import os, sys, glob, json, time, importlib, re |
| os.chdir(f"/root/{REPO}") |
| sys.path.insert(0, f"/root/{REPO}/src"); sys.path.insert(0, f"/root/{REPO}") |
|
|
| gen = importlib.import_module("scripts.data_preparation.SyntheticTS.generate_training_data") |
| if not os.path.exists(f"/root/{REPO}/datasets/{dataset_name}/train_data.npy"): |
| gen.generate_single_dataset(noise_level, 100, 336, 1, f"_noise{noise_level:.1f}", |
| base_dir_local=f"/root/{REPO}") |
|
|
| from basicts.models.Informer import Informer, InformerConfig |
| from basicts.configs import BasicTSForecastingConfig |
| from basicts.runners.callback import EarlyStopping, DropoutTSCallback, SelectiveLearning |
| from basicts import BasicTSLauncher |
|
|
| model_cfg = InformerConfig( |
| input_len=input_len, output_len=output_len, label_len=output_len // 2, |
| num_features=1, use_timestamps=True, timestamp_sizes=[96, 7, 31, 366], |
| ) |
| dts = lambda: DropoutTSCallback(p_min=0.05, p_max=0.5, init_alpha=10.0, |
| init_sensitivity=5.0, enable_visualization=False, |
| enable_statistics=False) |
| sl = lambda: SelectiveLearning(r_u=0.1) |
| callbacks = { |
| "baseline": [EarlyStopping(patience=10)], |
| "sl": [sl(), EarlyStopping(patience=10)], |
| "dropout_sl": [dts(), sl(), EarlyStopping(patience=10)], |
| }[strategy] |
|
|
| cfg = BasicTSForecastingConfig( |
| model=Informer, model_config=model_cfg, |
| dataset_name=dataset_name, input_len=input_len, output_len=output_len, |
| use_timestamps=True, use_clean_targets=True, |
| gpus="0", num_epochs=num_epochs, batch_size=64, callbacks=callbacks, seed=seed, |
| train_data_num_workers=2, val_data_num_workers=2, test_data_num_workers=2, |
| train_data_pin_memory=True, val_data_pin_memory=True, test_data_pin_memory=True, |
| ) |
| t0 = time.time() |
| BasicTSLauncher.launch_training(cfg) |
| train_seconds = time.time() - t0 |
| hits = sorted(glob.glob(f"/root/{REPO}/**/test_metrics.json", recursive=True), key=os.path.getmtime) |
| metrics = json.load(open(hits[-1])) if hits else None |
| return {"strategy": strategy, "dataset": dataset_name, "noise": noise_level, |
| "output_len": output_len, "train_seconds": round(train_seconds, 1), "metrics": metrics} |
|
|
|
|
| @app.function(gpu="A10G", timeout=3600) |
| def train_c5(**kw): |
| return _run_training_c5(**kw) |
|
|
|
|
| @app.local_entrypoint() |
| def claim5(): |
| """Claim 5: baseline vs SL-alone vs DropoutTS+SL (orthogonal compatibility).""" |
| import json |
| jobs = {s: train_c5.spawn(strategy=s, dataset_name="SyntheticTS_noise0.3", noise_level=0.3, |
| input_len=96, output_len=96, num_epochs=100) |
| for s in ("baseline", "sl", "dropout_sl")} |
| results = {} |
| for s, j in jobs.items(): |
| try: |
| results[s] = j.get() |
| except Exception as e: |
| print(s, "failed:", repr(e)) |
| print(json.dumps(results, indent=2)) |
| with open("claim5_results.json", "w") as f: |
| json.dump(results, f, indent=2) |
|
|
|
|
| @app.local_entrypoint() |
| def claim1_sweep(): |
| """Issue fix: sweep sensitivity {1,5,10} at sigma=0.3 across horizons (baselines already in claim1).""" |
| import json |
| jobs = [] |
| for sens in (1.0, 5.0, 10.0): |
| for h in (96, 192, 336, 720): |
| jobs.append(train_condition.spawn( |
| model_name="Informer", dataset_name="SyntheticTS_noise0.3", noise_level=0.3, |
| input_len=96, output_len=h, use_dropout=True, num_epochs=100, |
| init_sensitivity=sens, |
| )) |
| results = [] |
| for j in jobs: |
| try: |
| results.append(j.get()) |
| except Exception as e: |
| print("job failed:", repr(e)) |
| print(json.dumps(results, indent=2)) |
| with open("claim1_sweep_results.json", "w") as f: |
| json.dump(results, f, indent=2) |
|
|
|
|
| @app.local_entrypoint() |
| def claim2(): |
| """Claim 2: Informer +/- DropoutTS on ETTh2, all horizons (paper: up to 47.6% MSE).""" |
| import json |
| jobs = [] |
| for h in (96, 192, 336, 720): |
| for drop in (False, True): |
| jobs.append(train_ett.spawn( |
| dataset_name="ETTh2", input_len=96, output_len=h, |
| use_dropout=drop, num_epochs=100, |
| )) |
| results = [] |
| for j in jobs: |
| try: |
| results.append(j.get()) |
| except Exception as e: |
| print("job failed:", repr(e)) |
| print(json.dumps(results, indent=2)) |
| with open("claim2_ETTh2_results.json", "w") as f: |
| json.dump(results, f, indent=2) |
|
|
|
|
| @app.local_entrypoint() |
| def smoke(): |
| """Minimal end-to-end de-risk: 2 epochs, Informer, Synth noise0.3, H=96, baseline only.""" |
| r = train_condition.remote( |
| model_name="Informer", dataset_name="SyntheticTS_noise0.3", noise_level=0.3, |
| input_len=96, output_len=96, use_dropout=False, num_epochs=2, |
| ) |
| import json |
| print("SMOKE RESULT:\n", json.dumps(r, indent=2)) |
|
|
|
|
| @app.local_entrypoint() |
| def claim1(): |
| """Claim 1: Informer +/- DropoutTS across noise levels, horizon 96 (extend later).""" |
| import json |
| noise_levels = [0.1, 0.3, 0.5, 0.7, 0.9] |
| horizons = [96, 192, 336, 720] |
| jobs = [] |
| for nl in noise_levels: |
| ds = f"SyntheticTS_noise{nl:.1f}" |
| for h in horizons: |
| for drop in (False, True): |
| jobs.append(train_condition.spawn( |
| model_name="Informer", dataset_name=ds, noise_level=nl, |
| input_len=96, output_len=h, use_dropout=drop, num_epochs=100, |
| )) |
| results = [j.get() for j in jobs] |
| print(json.dumps(results, indent=2)) |
| with open("claim1_results.json", "w") as f: |
| json.dump(results, f, indent=2) |
|
|