Spaces:
Running
Running
P2SAMAPA commited on
Update train_and_push.yml
Browse files
.github/workflows/train_and_push.yml
CHANGED
|
@@ -8,8 +8,10 @@ name: Daily TFT Training
|
|
| 8 |
|
| 9 |
on:
|
| 10 |
schedule:
|
| 11 |
-
- cron: "0 12 * * 1-5" # 12:00 UTC = 7am EST Mon-Fri
|
| 12 |
- cron: "0 5 * * *" # 05:00 UTC = midnight EST daily cleanup
|
|
|
|
|
|
|
| 13 |
workflow_dispatch:
|
| 14 |
inputs:
|
| 15 |
start_year:
|
|
@@ -30,7 +32,47 @@ on:
|
|
| 30 |
|
| 31 |
jobs:
|
| 32 |
|
| 33 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
cleanup:
|
| 35 |
if: >
|
| 36 |
github.event_name == 'schedule' &&
|
|
@@ -43,7 +85,7 @@ jobs:
|
|
| 43 |
- name: Wipe single-year outputs (preserve sweep cache)
|
| 44 |
run: |
|
| 45 |
pip install huggingface_hub -q
|
| 46 |
-
|
| 47 |
import os
|
| 48 |
from huggingface_hub import HfApi
|
| 49 |
api = HfApi()
|
|
@@ -51,18 +93,14 @@ jobs:
|
|
| 51 |
repo_id = "P2SAMAPA/p2-etf-tft-outputs"
|
| 52 |
for filename in ["model_outputs.npz", "signals.json", "training_meta.json"]:
|
| 53 |
try:
|
| 54 |
-
api.delete_file(
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
repo_type="dataset",
|
| 58 |
-
token=token,
|
| 59 |
-
commit_message=f"Midnight cleanup: {filename}"
|
| 60 |
-
)
|
| 61 |
print(f"Deleted {filename}")
|
| 62 |
except Exception as e:
|
| 63 |
-
print(f"{filename} not found
|
| 64 |
-
print("Cleanup done
|
| 65 |
-
|
| 66 |
|
| 67 |
# ββ Single-year train β daily default + manual (no sweep_mode) ββββββββββββββ
|
| 68 |
train:
|
|
@@ -103,8 +141,8 @@ jobs:
|
|
| 103 |
# ββ Sweep 2008 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 104 |
sweep_2008:
|
| 105 |
if: >
|
| 106 |
-
github.event_name == '
|
| 107 |
-
contains(github.event.inputs.sweep_mode, '2008')
|
| 108 |
runs-on: ubuntu-latest
|
| 109 |
timeout-minutes: 180
|
| 110 |
env:
|
|
@@ -117,7 +155,7 @@ jobs:
|
|
| 117 |
python-version: "3.11"
|
| 118 |
cache: "pip"
|
| 119 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 120 |
-
- run: python train_pipeline.py --start-year 2008
|
| 121 |
- if: always()
|
| 122 |
uses: actions/upload-artifact@v4
|
| 123 |
with:
|
|
@@ -128,8 +166,8 @@ jobs:
|
|
| 128 |
# ββ Sweep 2014 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 129 |
sweep_2014:
|
| 130 |
if: >
|
| 131 |
-
github.event_name == '
|
| 132 |
-
contains(github.event.inputs.sweep_mode, '2014')
|
| 133 |
runs-on: ubuntu-latest
|
| 134 |
timeout-minutes: 180
|
| 135 |
env:
|
|
@@ -142,7 +180,7 @@ jobs:
|
|
| 142 |
python-version: "3.11"
|
| 143 |
cache: "pip"
|
| 144 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 145 |
-
- run: python train_pipeline.py --start-year 2014
|
| 146 |
- if: always()
|
| 147 |
uses: actions/upload-artifact@v4
|
| 148 |
with:
|
|
@@ -153,8 +191,8 @@ jobs:
|
|
| 153 |
# ββ Sweep 2016 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 154 |
sweep_2016:
|
| 155 |
if: >
|
| 156 |
-
github.event_name == '
|
| 157 |
-
contains(github.event.inputs.sweep_mode, '2016')
|
| 158 |
runs-on: ubuntu-latest
|
| 159 |
timeout-minutes: 180
|
| 160 |
env:
|
|
@@ -167,7 +205,7 @@ jobs:
|
|
| 167 |
python-version: "3.11"
|
| 168 |
cache: "pip"
|
| 169 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 170 |
-
- run: python train_pipeline.py --start-year 2016
|
| 171 |
- if: always()
|
| 172 |
uses: actions/upload-artifact@v4
|
| 173 |
with:
|
|
@@ -178,8 +216,8 @@ jobs:
|
|
| 178 |
# ββ Sweep 2019 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 179 |
sweep_2019:
|
| 180 |
if: >
|
| 181 |
-
github.event_name == '
|
| 182 |
-
contains(github.event.inputs.sweep_mode, '2019')
|
| 183 |
runs-on: ubuntu-latest
|
| 184 |
timeout-minutes: 180
|
| 185 |
env:
|
|
@@ -192,7 +230,7 @@ jobs:
|
|
| 192 |
python-version: "3.11"
|
| 193 |
cache: "pip"
|
| 194 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 195 |
-
- run: python train_pipeline.py --start-year 2019
|
| 196 |
- if: always()
|
| 197 |
uses: actions/upload-artifact@v4
|
| 198 |
with:
|
|
@@ -203,8 +241,8 @@ jobs:
|
|
| 203 |
# ββ Sweep 2021 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 204 |
sweep_2021:
|
| 205 |
if: >
|
| 206 |
-
github.event_name == '
|
| 207 |
-
contains(github.event.inputs.sweep_mode, '2021')
|
| 208 |
runs-on: ubuntu-latest
|
| 209 |
timeout-minutes: 180
|
| 210 |
env:
|
|
@@ -217,7 +255,7 @@ jobs:
|
|
| 217 |
python-version: "3.11"
|
| 218 |
cache: "pip"
|
| 219 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 220 |
-
- run: python train_pipeline.py --start-year 2021
|
| 221 |
- if: always()
|
| 222 |
uses: actions/upload-artifact@v4
|
| 223 |
with:
|
|
|
|
| 8 |
|
| 9 |
on:
|
| 10 |
schedule:
|
| 11 |
+
- cron: "0 12 * * 1-5" # 12:00 UTC = 7am EST Mon-Fri (single-year default)
|
| 12 |
- cron: "0 5 * * *" # 05:00 UTC = midnight EST daily cleanup
|
| 13 |
+
- cron: "0 1 * * 2-6" # 01:00 UTC = 8pm EST Mon-Fri (daily consensus sweep)
|
| 14 |
+
- cron: "0 0 * * 2-6" # 00:00 UTC = 7pm EST Mon-Fri (wipe previous day's sweep)
|
| 15 |
workflow_dispatch:
|
| 16 |
inputs:
|
| 17 |
start_year:
|
|
|
|
| 32 |
|
| 33 |
jobs:
|
| 34 |
|
| 35 |
+
# ββ 7pm EST: wipe previous day sweep cache from HF dataset βββββββββββββββββ
|
| 36 |
+
wipe_sweep_cache:
|
| 37 |
+
if: >
|
| 38 |
+
github.event_name == 'schedule' &&
|
| 39 |
+
github.event.schedule == '0 0 * * 2-6'
|
| 40 |
+
runs-on: ubuntu-latest
|
| 41 |
+
timeout-minutes: 10
|
| 42 |
+
env:
|
| 43 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 44 |
+
steps:
|
| 45 |
+
- name: Delete stale dated sweep files from HF dataset
|
| 46 |
+
run: |
|
| 47 |
+
pip install huggingface_hub -q
|
| 48 |
+
python3 - <<'PYEOF'
|
| 49 |
+
import os
|
| 50 |
+
from datetime import datetime, timezone, timedelta
|
| 51 |
+
from huggingface_hub import HfApi
|
| 52 |
+
api = HfApi()
|
| 53 |
+
token = os.environ["HF_TOKEN"]
|
| 54 |
+
repo = "P2SAMAPA/p2-etf-tft-outputs"
|
| 55 |
+
today = (datetime.now(timezone.utc) - timedelta(hours=5)).strftime("%Y%m%d")
|
| 56 |
+
try:
|
| 57 |
+
files = api.list_repo_files(repo_id=repo, repo_type="dataset", token=token)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"Could not list files: {e}"); files = []
|
| 60 |
+
deleted = 0
|
| 61 |
+
for f in files:
|
| 62 |
+
if f.startswith("signals_") and f.endswith(".json") and "_" in f[9:]:
|
| 63 |
+
parts = f.replace(".json","").split("_")
|
| 64 |
+
if len(parts) == 3 and parts[2] != today:
|
| 65 |
+
try:
|
| 66 |
+
api.delete_file(path_in_repo=f, repo_id=repo,
|
| 67 |
+
repo_type="dataset", token=token,
|
| 68 |
+
commit_message=f"Wipe stale sweep: {f}")
|
| 69 |
+
print(f"Deleted {f}"); deleted += 1
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Could not delete {f}: {e}")
|
| 72 |
+
print(f"Wiped {deleted} stale sweep files")
|
| 73 |
+
PYEOF
|
| 74 |
+
|
| 75 |
+
# ββ Midnight cleanup β wipes single-year outputs only ββββββββββββββββββββββββ
|
| 76 |
cleanup:
|
| 77 |
if: >
|
| 78 |
github.event_name == 'schedule' &&
|
|
|
|
| 85 |
- name: Wipe single-year outputs (preserve sweep cache)
|
| 86 |
run: |
|
| 87 |
pip install huggingface_hub -q
|
| 88 |
+
python3 - <<'PYEOF'
|
| 89 |
import os
|
| 90 |
from huggingface_hub import HfApi
|
| 91 |
api = HfApi()
|
|
|
|
| 93 |
repo_id = "P2SAMAPA/p2-etf-tft-outputs"
|
| 94 |
for filename in ["model_outputs.npz", "signals.json", "training_meta.json"]:
|
| 95 |
try:
|
| 96 |
+
api.delete_file(path_in_repo=filename, repo_id=repo_id,
|
| 97 |
+
repo_type="dataset", token=token,
|
| 98 |
+
commit_message=f"Midnight cleanup: {filename}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
print(f"Deleted {filename}")
|
| 100 |
except Exception as e:
|
| 101 |
+
print(f"{filename} not found: {e}")
|
| 102 |
+
print("Cleanup done")
|
| 103 |
+
PYEOF
|
| 104 |
|
| 105 |
# ββ Single-year train β daily default + manual (no sweep_mode) ββββββββββββββ
|
| 106 |
train:
|
|
|
|
| 141 |
# ββ Sweep 2008 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 142 |
sweep_2008:
|
| 143 |
if: >
|
| 144 |
+
(github.event_name == 'schedule' && github.event.schedule == '0 1 * * 2-6') ||
|
| 145 |
+
(github.event_name == 'workflow_dispatch' && contains(github.event.inputs.sweep_mode, '2008'))
|
| 146 |
runs-on: ubuntu-latest
|
| 147 |
timeout-minutes: 180
|
| 148 |
env:
|
|
|
|
| 155 |
python-version: "3.11"
|
| 156 |
cache: "pip"
|
| 157 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 158 |
+
- run: python train_pipeline.py --start-year 2008 --sweep-date $(date -u -d "-5 hours" +%Y%m%d 2>/dev/null || date -u +%Y%m%d)
|
| 159 |
- if: always()
|
| 160 |
uses: actions/upload-artifact@v4
|
| 161 |
with:
|
|
|
|
| 166 |
# ββ Sweep 2014 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 167 |
sweep_2014:
|
| 168 |
if: >
|
| 169 |
+
(github.event_name == 'schedule' && github.event.schedule == '0 1 * * 2-6') ||
|
| 170 |
+
(github.event_name == 'workflow_dispatch' && contains(github.event.inputs.sweep_mode, '2014'))
|
| 171 |
runs-on: ubuntu-latest
|
| 172 |
timeout-minutes: 180
|
| 173 |
env:
|
|
|
|
| 180 |
python-version: "3.11"
|
| 181 |
cache: "pip"
|
| 182 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 183 |
+
- run: python train_pipeline.py --start-year 2014 --sweep-date $(date -u -d "-5 hours" +%Y%m%d 2>/dev/null || date -u +%Y%m%d)
|
| 184 |
- if: always()
|
| 185 |
uses: actions/upload-artifact@v4
|
| 186 |
with:
|
|
|
|
| 191 |
# ββ Sweep 2016 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
sweep_2016:
|
| 193 |
if: >
|
| 194 |
+
(github.event_name == 'schedule' && github.event.schedule == '0 1 * * 2-6') ||
|
| 195 |
+
(github.event_name == 'workflow_dispatch' && contains(github.event.inputs.sweep_mode, '2016'))
|
| 196 |
runs-on: ubuntu-latest
|
| 197 |
timeout-minutes: 180
|
| 198 |
env:
|
|
|
|
| 205 |
python-version: "3.11"
|
| 206 |
cache: "pip"
|
| 207 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 208 |
+
- run: python train_pipeline.py --start-year 2016 --sweep-date $(date -u -d "-5 hours" +%Y%m%d 2>/dev/null || date -u +%Y%m%d)
|
| 209 |
- if: always()
|
| 210 |
uses: actions/upload-artifact@v4
|
| 211 |
with:
|
|
|
|
| 216 |
# ββ Sweep 2019 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 217 |
sweep_2019:
|
| 218 |
if: >
|
| 219 |
+
(github.event_name == 'schedule' && github.event.schedule == '0 1 * * 2-6') ||
|
| 220 |
+
(github.event_name == 'workflow_dispatch' && contains(github.event.inputs.sweep_mode, '2019'))
|
| 221 |
runs-on: ubuntu-latest
|
| 222 |
timeout-minutes: 180
|
| 223 |
env:
|
|
|
|
| 230 |
python-version: "3.11"
|
| 231 |
cache: "pip"
|
| 232 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 233 |
+
- run: python train_pipeline.py --start-year 2019 --sweep-date $(date -u -d "-5 hours" +%Y%m%d 2>/dev/null || date -u +%Y%m%d)
|
| 234 |
- if: always()
|
| 235 |
uses: actions/upload-artifact@v4
|
| 236 |
with:
|
|
|
|
| 241 |
# ββ Sweep 2021 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 242 |
sweep_2021:
|
| 243 |
if: >
|
| 244 |
+
(github.event_name == 'schedule' && github.event.schedule == '0 1 * * 2-6') ||
|
| 245 |
+
(github.event_name == 'workflow_dispatch' && contains(github.event.inputs.sweep_mode, '2021'))
|
| 246 |
runs-on: ubuntu-latest
|
| 247 |
timeout-minutes: 180
|
| 248 |
env:
|
|
|
|
| 255 |
python-version: "3.11"
|
| 256 |
cache: "pip"
|
| 257 |
- run: pip install --no-cache-dir -r requirements.txt
|
| 258 |
+
- run: python train_pipeline.py --start-year 2021 --sweep-date $(date -u -d "-5 hours" +%Y%m%d 2>/dev/null || date -u +%Y%m%d)
|
| 259 |
- if: always()
|
| 260 |
uses: actions/upload-artifact@v4
|
| 261 |
with:
|