P2SAMAPA commited on
Commit
7a2d2f4
Β·
unverified Β·
1 Parent(s): 6af882b

Update train_and_push.yml

Browse files
Files changed (1) hide show
  1. .github/workflows/train_and_push.yml +156 -36
.github/workflows/train_and_push.yml CHANGED
@@ -1,21 +1,27 @@
1
  # .github/workflows/train_and_push.yml
2
- # Two jobs:
3
- # 1. train β€” daily 7am EST default (start_year=2016) + manual trigger with custom start_year
4
- # 2. cleanup β€” daily midnight EST wipes p2-etf-tft-outputs dataset clean
 
5
 
6
  name: Daily TFT Training
7
 
8
  on:
9
  schedule:
10
- - cron: "0 12 * * 1-5" # 12:00 UTC = 7:00am EST, Mon-Fri (default training)
11
- - cron: "0 5 * * *" # 05:00 UTC = midnight EST, daily (cleanup)
12
  workflow_dispatch:
13
  inputs:
14
  start_year:
15
- description: "Start year for training data"
16
  required: false
17
  default: "2016"
18
  type: string
 
 
 
 
 
19
  force_refresh:
20
  description: "Force full dataset rebuild"
21
  required: false
@@ -23,16 +29,18 @@ on:
23
  type: boolean
24
 
25
  jobs:
26
- # ── Cleanup job β€” runs at midnight EST, wipes output dataset ────────────────
 
27
  cleanup:
28
  if: >
29
- github.event_name == 'schedule' && github.event.schedule == '0 5 * * *'
 
30
  runs-on: ubuntu-latest
31
  timeout-minutes: 10
32
  env:
33
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
34
  steps:
35
- - name: Wipe p2-etf-tft-outputs dataset
36
  run: |
37
  pip install huggingface_hub -q
38
  python - <<'EOF'
@@ -41,7 +49,6 @@ jobs:
41
  api = HfApi()
42
  token = os.environ["HF_TOKEN"]
43
  repo_id = "P2SAMAPA/p2-etf-tft-outputs"
44
- # Delete each output file if it exists
45
  for filename in ["model_outputs.npz", "signals.json", "training_meta.json"]:
46
  try:
47
  api.delete_file(
@@ -49,58 +56,171 @@ jobs:
49
  repo_id=repo_id,
50
  repo_type="dataset",
51
  token=token,
52
- commit_message=f"Midnight cleanup: remove {filename}"
53
  )
54
- print(f"βœ… Deleted {filename}")
55
  except Exception as e:
56
- print(f"ℹ️ {filename} not found or already deleted: {e}")
57
- print("βœ… Cleanup complete")
58
  EOF
59
 
60
- # ── Training job β€” runs at 7am EST daily + manual triggers ─────────────────
61
  train:
62
  if: >
63
- github.event_name == 'workflow_dispatch' ||
64
- (github.event_name == 'schedule' && github.event.schedule == '0 12 * * 1-5')
 
 
65
  runs-on: ubuntu-latest
66
  timeout-minutes: 180
67
-
68
  env:
69
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
70
  FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
71
-
72
  steps:
73
- - name: Checkout code
74
- uses: actions/checkout@v4
75
-
76
- - name: Set up Python 3.11
77
- uses: actions/setup-python@v5
78
  with:
79
  python-version: "3.11"
80
  cache: "pip"
81
-
82
  - name: Install dependencies
 
 
83
  run: |
84
- pip install --no-cache-dir -r requirements.txt
85
-
86
- - name: Train TFT models and push outputs
87
- run: |
88
- # Use workflow input start_year if manual trigger, else default 2016
89
  START_YEAR="${{ github.event.inputs.start_year }}"
90
  START_YEAR="${START_YEAR:-2016}"
91
-
92
  ARGS="--start-year $START_YEAR"
93
  if [ "${{ github.event.inputs.force_refresh }}" = "true" ]; then
94
  ARGS="$ARGS --force-refresh"
95
  fi
96
-
97
- echo "Running: python train_pipeline.py $ARGS"
98
  python train_pipeline.py $ARGS
 
 
 
 
 
 
99
 
100
- - name: Upload training logs
101
- if: always()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  uses: actions/upload-artifact@v4
103
  with:
104
- name: training-logs-${{ github.run_id }}
105
  path: "*.log"
106
  retention-days: 7
 
1
  # .github/workflows/train_and_push.yml
2
+ # Three triggers:
3
+ # 1. train β€” daily 7am EST (start_year=2016) + manual single-year
4
+ # 2. sweep_YYYY β€” manual consensus sweep (parallel jobs, missing years only)
5
+ # 3. cleanup β€” daily midnight EST, wipes single-year outputs only
6
 
7
  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:
16
+ description: "Start year for single-year run"
17
  required: false
18
  default: "2016"
19
  type: string
20
+ sweep_mode:
21
+ description: "Comma-separated sweep years e.g. 2008,2014,2016,2019,2021 (leave blank for single-year)"
22
+ required: false
23
+ default: ""
24
+ type: string
25
  force_refresh:
26
  description: "Force full dataset rebuild"
27
  required: false
 
29
  type: boolean
30
 
31
  jobs:
32
+
33
+ # ── Midnight cleanup β€” wipes single-year outputs, keeps sweep cache ─────────
34
  cleanup:
35
  if: >
36
+ github.event_name == 'schedule' &&
37
+ github.event.schedule == '0 5 * * *'
38
  runs-on: ubuntu-latest
39
  timeout-minutes: 10
40
  env:
41
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
42
  steps:
43
+ - name: Wipe single-year outputs (preserve sweep cache)
44
  run: |
45
  pip install huggingface_hub -q
46
  python - <<'EOF'
 
49
  api = HfApi()
50
  token = os.environ["HF_TOKEN"]
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(
 
56
  repo_id=repo_id,
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 or already gone: {e}")
64
+ print("Cleanup done β€” sweep cache preserved")
65
  EOF
66
 
67
+ # ── Single-year train β€” daily default + manual (no sweep_mode) ──────────────
68
  train:
69
  if: >
70
+ (github.event_name == 'schedule' &&
71
+ github.event.schedule == '0 12 * * 1-5') ||
72
+ (github.event_name == 'workflow_dispatch' &&
73
+ (github.event.inputs.sweep_mode == '' || github.event.inputs.sweep_mode == null))
74
  runs-on: ubuntu-latest
75
  timeout-minutes: 180
 
76
  env:
77
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
78
  FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
 
79
  steps:
80
+ - uses: actions/checkout@v4
81
+ - uses: actions/setup-python@v5
 
 
 
82
  with:
83
  python-version: "3.11"
84
  cache: "pip"
 
85
  - name: Install dependencies
86
+ run: pip install --no-cache-dir -r requirements.txt
87
+ - name: Train
88
  run: |
 
 
 
 
 
89
  START_YEAR="${{ github.event.inputs.start_year }}"
90
  START_YEAR="${START_YEAR:-2016}"
 
91
  ARGS="--start-year $START_YEAR"
92
  if [ "${{ github.event.inputs.force_refresh }}" = "true" ]; then
93
  ARGS="$ARGS --force-refresh"
94
  fi
 
 
95
  python train_pipeline.py $ARGS
96
+ - if: always()
97
+ uses: actions/upload-artifact@v4
98
+ with:
99
+ name: logs-single-${{ github.run_id }}
100
+ path: "*.log"
101
+ retention-days: 7
102
 
103
+ # ── Sweep 2008 ───────────────────────────────────────────────────────────────
104
+ sweep_2008:
105
+ if: >
106
+ github.event_name == 'workflow_dispatch' &&
107
+ contains(github.event.inputs.sweep_mode, '2008')
108
+ runs-on: ubuntu-latest
109
+ timeout-minutes: 180
110
+ env:
111
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
112
+ FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
113
+ steps:
114
+ - uses: actions/checkout@v4
115
+ - uses: actions/setup-python@v5
116
+ with:
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:
124
+ name: logs-sweep-2008-${{ github.run_id }}
125
+ path: "*.log"
126
+ retention-days: 7
127
+
128
+ # ── Sweep 2014 ───────────────────────────────────────────────────────────────
129
+ sweep_2014:
130
+ if: >
131
+ github.event_name == 'workflow_dispatch' &&
132
+ contains(github.event.inputs.sweep_mode, '2014')
133
+ runs-on: ubuntu-latest
134
+ timeout-minutes: 180
135
+ env:
136
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
137
+ FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
138
+ steps:
139
+ - uses: actions/checkout@v4
140
+ - uses: actions/setup-python@v5
141
+ with:
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:
149
+ name: logs-sweep-2014-${{ github.run_id }}
150
+ path: "*.log"
151
+ retention-days: 7
152
+
153
+ # ── Sweep 2016 ───────────────────────────────────────────────────────────────
154
+ sweep_2016:
155
+ if: >
156
+ github.event_name == 'workflow_dispatch' &&
157
+ contains(github.event.inputs.sweep_mode, '2016')
158
+ runs-on: ubuntu-latest
159
+ timeout-minutes: 180
160
+ env:
161
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
162
+ FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
163
+ steps:
164
+ - uses: actions/checkout@v4
165
+ - uses: actions/setup-python@v5
166
+ with:
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:
174
+ name: logs-sweep-2016-${{ github.run_id }}
175
+ path: "*.log"
176
+ retention-days: 7
177
+
178
+ # ── Sweep 2019 ───────────────────────────────────────────────────────────────
179
+ sweep_2019:
180
+ if: >
181
+ github.event_name == 'workflow_dispatch' &&
182
+ contains(github.event.inputs.sweep_mode, '2019')
183
+ runs-on: ubuntu-latest
184
+ timeout-minutes: 180
185
+ env:
186
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
187
+ FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
188
+ steps:
189
+ - uses: actions/checkout@v4
190
+ - uses: actions/setup-python@v5
191
+ with:
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:
199
+ name: logs-sweep-2019-${{ github.run_id }}
200
+ path: "*.log"
201
+ retention-days: 7
202
+
203
+ # ── Sweep 2021 ───────────────────────────────────────────────────────────────
204
+ sweep_2021:
205
+ if: >
206
+ github.event_name == 'workflow_dispatch' &&
207
+ contains(github.event.inputs.sweep_mode, '2021')
208
+ runs-on: ubuntu-latest
209
+ timeout-minutes: 180
210
+ env:
211
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
212
+ FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
213
+ steps:
214
+ - uses: actions/checkout@v4
215
+ - uses: actions/setup-python@v5
216
+ with:
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:
224
+ name: logs-sweep-2021-${{ github.run_id }}
225
  path: "*.log"
226
  retention-days: 7