Keep bot operational when forecast model is unavailable

This commit is contained in:
Курнат Андрей
2026-07-13 11:57:25 +03:00
parent da53483164
commit 668e606ee2
22 changed files with 706 additions and 73 deletions
+23 -3
View File
@@ -23,7 +23,9 @@ ALLOWED_TRAINING_ARTIFACTS = {
RUNNING_TIMEOUT = timedelta(hours=12)
ONLINE_WINDOW = timedelta(minutes=3)
MAX_ARTIFACT_CHUNK_BYTES = 1024 * 1024
MAX_ARTIFACT_BYTES = 64 * 1024 * 1024
# Independent per-symbol ensembles are intentionally larger than pooled models.
# Keep a bounded limit, but leave enough room for the supported 12-symbol bundle.
MAX_ARTIFACT_BYTES = 256 * 1024 * 1024
MAX_ARTIFACT_CHUNKS = 1024
REQUIRED_MODEL_BUNDLE = set(ALLOWED_TRAINING_ARTIFACTS)
@@ -378,13 +380,19 @@ def _safe_parameters(value: Any) -> dict[str, Any]:
"dropouts",
"epochs",
"holdout_window",
"ensemble_seeds",
"selection_folds",
"learning_rate",
"weight_decay",
"pooled",
"resume_candidate",
}
result = {key: value[key] for key in allowed if key in value}
for key, low, high in (
("limit", 500, 5000),
("limit", 500, 20000),
("epochs", 1, 200),
("holdout_window", 64, 1000),
("selection_folds", 1, 12),
):
if key not in result:
continue
@@ -406,9 +414,21 @@ def _safe_parameters(value: Any) -> dict[str, Any]:
if item.strip().lower() in {"lstm", "gru"}
]
result["architectures"] = ",".join(architectures) or "lstm,gru"
for key in ("lookbacks", "hidden_sizes", "layers", "dropouts"):
for key in ("lookbacks", "hidden_sizes", "layers", "dropouts", "ensemble_seeds"):
if key in result:
result[key] = str(result[key])[:200]
for key, low, high in (
("learning_rate", 0.00001, 0.1),
("weight_decay", 0.0, 0.1),
):
if key not in result:
continue
try:
result[key] = max(low, min(high, float(result[key])))
except (TypeError, ValueError):
result.pop(key, None)
if "pooled" in result:
result["pooled"] = result["pooled"] is True
if "resume_candidate" in result:
result["resume_candidate"] = result["resume_candidate"] is True
return result