@elizaos/training 2.0.0-alpha.13 → 2.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/research-output/training-runs/training-run-1773726941205.json +38 -0
- package/scripts/rank_trajectories.ts +0 -1
- package/scripts/run_task_benchmark.ts +4 -11
- package/src/adapter.ts +96 -49
- package/src/archetypes/ArchetypeConfigService.ts +188 -185
- package/src/archetypes/derive-archetype.ts +47 -47
- package/src/archetypes/index.ts +2 -2
- package/src/benchmark/ArchetypeMatchupBenchmark.ts +70 -70
- package/src/benchmark/BenchmarkChartGenerator.ts +70 -69
- package/src/benchmark/BenchmarkDataGenerator.ts +136 -136
- package/src/benchmark/BenchmarkDataViewer.ts +32 -30
- package/src/benchmark/BenchmarkHistoryService.ts +13 -12
- package/src/benchmark/BenchmarkRunner.ts +87 -83
- package/src/benchmark/BenchmarkValidator.ts +48 -46
- package/src/benchmark/FastEvalRunner.ts +17 -16
- package/src/benchmark/MetricsValidator.ts +20 -21
- package/src/benchmark/MetricsVisualizer.ts +92 -85
- package/src/benchmark/ModelBenchmarkService.ts +90 -82
- package/src/benchmark/ModelRegistry.ts +44 -44
- package/src/benchmark/RulerBenchmarkIntegration.ts +24 -24
- package/src/benchmark/SimulationA2AInterface.ts +118 -118
- package/src/benchmark/SimulationEngine.ts +51 -51
- package/src/benchmark/TaskRunner.ts +87 -79
- package/src/benchmark/__tests__/BenchmarkRunner.test.ts +80 -80
- package/src/benchmark/__tests__/HeadToHead.test.ts +26 -26
- package/src/benchmark/index.ts +27 -27
- package/src/benchmark/parseSimulationMetrics.ts +32 -32
- package/src/benchmark/simulation-types.ts +10 -10
- package/src/dependencies.ts +34 -34
- package/src/generation/TrajectoryGenerator.ts +39 -37
- package/src/generation/index.ts +1 -1
- package/src/huggingface/HuggingFaceDatasetUploader.ts +72 -72
- package/src/huggingface/HuggingFaceIntegrationService.ts +59 -53
- package/src/huggingface/HuggingFaceModelUploader.ts +60 -59
- package/src/huggingface/index.ts +6 -6
- package/src/huggingface/shared/HuggingFaceUploadUtil.ts +32 -32
- package/src/index.ts +27 -27
- package/src/init-training.ts +6 -6
- package/src/metrics/TrajectoryMetricsExtractor.ts +70 -71
- package/src/metrics/__tests__/TrajectoryMetricsExtractor.test.ts +182 -182
- package/src/metrics/index.ts +2 -2
- package/src/rubrics/__tests__/index.test.ts +73 -73
- package/src/rubrics/ass-kisser.ts +6 -6
- package/src/rubrics/degen.ts +6 -6
- package/src/rubrics/goody-twoshoes.ts +6 -6
- package/src/rubrics/index.ts +50 -50
- package/src/rubrics/information-trader.ts +6 -6
- package/src/rubrics/infosec.ts +6 -6
- package/src/rubrics/liar.ts +6 -6
- package/src/rubrics/perps-trader.ts +6 -6
- package/src/rubrics/researcher.ts +6 -6
- package/src/rubrics/scammer.ts +6 -6
- package/src/rubrics/social-butterfly.ts +7 -7
- package/src/rubrics/super-predictor.ts +6 -6
- package/src/rubrics/trader.ts +5 -5
- package/src/scoring/ArchetypeScoringService.ts +56 -54
- package/src/scoring/JudgePromptBuilder.ts +96 -96
- package/src/scoring/LLMJudgeCache.ts +26 -23
- package/src/scoring/index.ts +3 -3
- package/src/training/AutomationPipeline.ts +149 -140
- package/src/training/BenchmarkService.ts +49 -45
- package/src/training/ConfigValidator.ts +38 -32
- package/src/training/MarketOutcomesTracker.ts +22 -12
- package/src/training/ModelDeployer.ts +15 -15
- package/src/training/ModelFetcher.ts +7 -7
- package/src/training/ModelSelectionService.ts +32 -32
- package/src/training/ModelUsageVerifier.ts +31 -24
- package/src/training/MultiModelOrchestrator.ts +44 -44
- package/src/training/RLModelConfig.ts +57 -57
- package/src/training/RewardBackpropagationService.ts +18 -17
- package/src/training/RulerScoringService.ts +73 -72
- package/src/training/TrainingMonitor.ts +29 -29
- package/src/training/TrajectoryRecorder.ts +25 -27
- package/src/training/__tests__/TrajectoryRecorder.test.ts +105 -105
- package/src/training/index.ts +36 -36
- package/src/training/logRLConfig.ts +7 -7
- package/src/training/pipeline.ts +13 -16
- package/src/training/storage/ModelStorageService.ts +32 -32
- package/src/training/storage/TrainingDataArchiver.ts +21 -21
- package/src/training/storage/index.ts +2 -2
- package/src/training/types.ts +6 -6
- package/src/training/window-utils.ts +14 -14
- package/src/utils/index.ts +7 -7
- package/src/utils/logger.ts +5 -5
- package/src/utils/snowflake.ts +1 -1
- package/src/utils/synthetic-detector.ts +7 -7
package/src/training/index.ts
CHANGED
|
@@ -4,38 +4,49 @@
|
|
|
4
4
|
* Core training pipeline services for RL model development.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export type { AutomationConfig } from
|
|
8
|
-
export { AutomationPipeline, automationPipeline } from
|
|
9
|
-
export type { BenchmarkResults, ComparisonResults } from
|
|
10
|
-
export { BenchmarkService, benchmarkService } from
|
|
7
|
+
export type { AutomationConfig } from "./AutomationPipeline";
|
|
8
|
+
export { AutomationPipeline, automationPipeline } from "./AutomationPipeline";
|
|
9
|
+
export type { BenchmarkResults, ComparisonResults } from "./BenchmarkService";
|
|
10
|
+
export { BenchmarkService, benchmarkService } from "./BenchmarkService";
|
|
11
11
|
|
|
12
|
-
export { ConfigValidator } from
|
|
13
|
-
export { logRLConfigOnStartup } from
|
|
14
|
-
export { MarketOutcomesTracker } from
|
|
15
|
-
export type { DeploymentOptions, DeploymentResult } from
|
|
16
|
-
export { ModelDeployer, modelDeployer } from
|
|
17
|
-
export type { ModelArtifact } from
|
|
12
|
+
export { ConfigValidator } from "./ConfigValidator";
|
|
13
|
+
export { logRLConfigOnStartup } from "./logRLConfig";
|
|
14
|
+
export { MarketOutcomesTracker } from "./MarketOutcomesTracker";
|
|
15
|
+
export type { DeploymentOptions, DeploymentResult } from "./ModelDeployer";
|
|
16
|
+
export { ModelDeployer, modelDeployer } from "./ModelDeployer";
|
|
17
|
+
export type { ModelArtifact } from "./ModelFetcher";
|
|
18
18
|
// Model fetching
|
|
19
|
-
export { getLatestRLModel } from
|
|
19
|
+
export { getLatestRLModel } from "./ModelFetcher";
|
|
20
20
|
export {
|
|
21
21
|
ModelSelectionService,
|
|
22
22
|
modelSelectionService,
|
|
23
|
-
} from
|
|
24
|
-
export { ModelUsageVerifier } from
|
|
23
|
+
} from "./ModelSelectionService";
|
|
24
|
+
export { ModelUsageVerifier } from "./ModelUsageVerifier";
|
|
25
25
|
// Multi-model orchestration for efficient archetype model management
|
|
26
26
|
export type {
|
|
27
27
|
ModelInferenceRequest,
|
|
28
28
|
ModelInferenceResult,
|
|
29
29
|
OrchestratorConfig,
|
|
30
|
-
} from
|
|
30
|
+
} from "./MultiModelOrchestrator";
|
|
31
31
|
export {
|
|
32
32
|
createMultiModelOrchestrator,
|
|
33
33
|
MultiModelOrchestrator,
|
|
34
|
-
} from
|
|
34
|
+
} from "./MultiModelOrchestrator";
|
|
35
|
+
export type { NextTrainingModelSelection } from "./pipeline";
|
|
36
|
+
export {
|
|
37
|
+
benchmarkAndMaybeDeployModel,
|
|
38
|
+
checkTrainingReadiness,
|
|
39
|
+
deployModelVersion,
|
|
40
|
+
getAutomationPipelineStatus,
|
|
41
|
+
getNextTrainingModelSelection,
|
|
42
|
+
monitorTrainingJob,
|
|
43
|
+
rollbackModelVersion,
|
|
44
|
+
triggerTraining,
|
|
45
|
+
} from "./pipeline";
|
|
35
46
|
export {
|
|
36
47
|
RewardBackpropagationService,
|
|
37
48
|
rewardBackpropagationService,
|
|
38
|
-
} from
|
|
49
|
+
} from "./RewardBackpropagationService";
|
|
39
50
|
export type {
|
|
40
51
|
ArchetypeModelConfig,
|
|
41
52
|
ModelTier,
|
|
@@ -43,7 +54,7 @@ export type {
|
|
|
43
54
|
MultiModelConfig,
|
|
44
55
|
QuantizationMode,
|
|
45
56
|
RLModelConfig,
|
|
46
|
-
} from
|
|
57
|
+
} from "./RLModelConfig";
|
|
47
58
|
export {
|
|
48
59
|
clearArchetypeModels,
|
|
49
60
|
getAllArchetypeModels,
|
|
@@ -62,30 +73,19 @@ export {
|
|
|
62
73
|
MODEL_TIERS,
|
|
63
74
|
// Archetype model management
|
|
64
75
|
registerArchetypeModel,
|
|
65
|
-
} from
|
|
66
|
-
export type { MarketOutcomes, RulerScore } from
|
|
76
|
+
} from "./RLModelConfig";
|
|
77
|
+
export type { MarketOutcomes, RulerScore } from "./RulerScoringService";
|
|
67
78
|
export {
|
|
68
79
|
RulerScoringService,
|
|
69
80
|
rulerScoringService,
|
|
70
|
-
} from
|
|
71
|
-
export type { NextTrainingModelSelection } from './pipeline';
|
|
72
|
-
export {
|
|
73
|
-
benchmarkAndMaybeDeployModel,
|
|
74
|
-
checkTrainingReadiness,
|
|
75
|
-
deployModelVersion,
|
|
76
|
-
getAutomationPipelineStatus,
|
|
77
|
-
getNextTrainingModelSelection,
|
|
78
|
-
monitorTrainingJob,
|
|
79
|
-
rollbackModelVersion,
|
|
80
|
-
triggerTraining,
|
|
81
|
-
} from './pipeline';
|
|
81
|
+
} from "./RulerScoringService";
|
|
82
82
|
// Storage services
|
|
83
|
-
export * from
|
|
84
|
-
export { TrainingMonitor, trainingMonitor } from
|
|
85
|
-
export { TrajectoryRecorder, trajectoryRecorder } from
|
|
83
|
+
export * from "./storage";
|
|
84
|
+
export { TrainingMonitor, trainingMonitor } from "./TrainingMonitor";
|
|
85
|
+
export { TrajectoryRecorder, trajectoryRecorder } from "./TrajectoryRecorder";
|
|
86
86
|
|
|
87
87
|
// Types
|
|
88
|
-
export * from
|
|
88
|
+
export * from "./types";
|
|
89
89
|
|
|
90
90
|
// Window utilities
|
|
91
91
|
export {
|
|
@@ -97,4 +97,4 @@ export {
|
|
|
97
97
|
isTimestampInWindow,
|
|
98
98
|
isWindowComplete,
|
|
99
99
|
parseWindowId,
|
|
100
|
-
} from
|
|
100
|
+
} from "./window-utils";
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Used for diagnostics and verification during deployment.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { isRLModelAvailable, logRLModelConfig } from
|
|
8
|
+
import { isRLModelAvailable, logRLModelConfig } from "./RLModelConfig";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Log RL model configuration and verify setup
|
|
@@ -14,9 +14,9 @@ import { isRLModelAvailable, logRLModelConfig } from './RLModelConfig';
|
|
|
14
14
|
* and verify that the RL training system is properly configured.
|
|
15
15
|
*/
|
|
16
16
|
export async function logRLConfigOnStartup(): Promise<void> {
|
|
17
|
-
console.log(
|
|
18
|
-
console.log(
|
|
19
|
-
console.log(
|
|
17
|
+
console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
18
|
+
console.log("🚀 RL Training System Configuration");
|
|
19
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
20
20
|
|
|
21
21
|
// Log RL configuration
|
|
22
22
|
logRLModelConfig();
|
|
@@ -25,10 +25,10 @@ export async function logRLConfigOnStartup(): Promise<void> {
|
|
|
25
25
|
const available = isRLModelAvailable();
|
|
26
26
|
|
|
27
27
|
if (available) {
|
|
28
|
-
console.log(
|
|
28
|
+
console.log("\n✅ RL Model system available");
|
|
29
29
|
} else {
|
|
30
|
-
console.log(
|
|
30
|
+
console.log("\nℹ️ RL models not available - using base model");
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
console.log(
|
|
33
|
+
console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
34
34
|
}
|
package/src/training/pipeline.ts
CHANGED
|
@@ -7,21 +7,18 @@
|
|
|
7
7
|
* "@elizaos/training" without side-effects.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type { AutomationPipeline } from "./AutomationPipeline";
|
|
11
|
+
import type { DeploymentOptions, DeploymentResult } from "./ModelDeployer";
|
|
10
12
|
import type {
|
|
11
13
|
AutomationStatus,
|
|
12
14
|
TrainingMonitoringStatus,
|
|
13
15
|
TrainingReadinessResult,
|
|
14
16
|
TrainingTriggerOptions,
|
|
15
17
|
TrainingTriggerResult,
|
|
16
|
-
} from
|
|
17
|
-
import type {
|
|
18
|
-
DeploymentOptions,
|
|
19
|
-
DeploymentResult,
|
|
20
|
-
} from './ModelDeployer';
|
|
21
|
-
import type { AutomationPipeline } from './AutomationPipeline';
|
|
18
|
+
} from "./types";
|
|
22
19
|
|
|
23
20
|
export type NextTrainingModelSelection = Awaited<
|
|
24
|
-
ReturnType<AutomationPipeline[
|
|
21
|
+
ReturnType<AutomationPipeline["getModelSelectionInfo"]>
|
|
25
22
|
>;
|
|
26
23
|
|
|
27
24
|
// ---------------------------------------------------------------------------
|
|
@@ -33,14 +30,14 @@ let _pipeline: AutomationPipeline | null = null;
|
|
|
33
30
|
|
|
34
31
|
async function getPipeline(): Promise<AutomationPipeline> {
|
|
35
32
|
if (!_pipeline) {
|
|
36
|
-
const mod = await import(
|
|
33
|
+
const mod = await import("./AutomationPipeline");
|
|
37
34
|
_pipeline = mod.automationPipeline;
|
|
38
35
|
}
|
|
39
36
|
return _pipeline;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
async function getDeployer() {
|
|
43
|
-
const mod = await import(
|
|
40
|
+
const mod = await import("./ModelDeployer");
|
|
44
41
|
return mod.modelDeployer;
|
|
45
42
|
}
|
|
46
43
|
|
|
@@ -56,7 +53,7 @@ export async function checkTrainingReadiness(): Promise<TrainingReadinessResult>
|
|
|
56
53
|
* Trigger a new training job.
|
|
57
54
|
*/
|
|
58
55
|
export async function triggerTraining(
|
|
59
|
-
options: TrainingTriggerOptions = {}
|
|
56
|
+
options: TrainingTriggerOptions = {},
|
|
60
57
|
): Promise<TrainingTriggerResult> {
|
|
61
58
|
const pipeline = await getPipeline();
|
|
62
59
|
return pipeline.triggerTraining(options);
|
|
@@ -66,7 +63,7 @@ export async function triggerTraining(
|
|
|
66
63
|
* Monitor a training batch by its batch id.
|
|
67
64
|
*/
|
|
68
65
|
export async function monitorTrainingJob(
|
|
69
|
-
batchId: string
|
|
66
|
+
batchId: string,
|
|
70
67
|
): Promise<TrainingMonitoringStatus> {
|
|
71
68
|
const pipeline = await getPipeline();
|
|
72
69
|
return pipeline.monitorTraining(batchId);
|
|
@@ -85,8 +82,8 @@ export async function getAutomationPipelineStatus(): Promise<AutomationStatus> {
|
|
|
85
82
|
*/
|
|
86
83
|
export async function getNextTrainingModelSelection(): Promise<{
|
|
87
84
|
success: boolean;
|
|
88
|
-
selection: NextTrainingModelSelection[
|
|
89
|
-
summary: NextTrainingModelSelection[
|
|
85
|
+
selection: NextTrainingModelSelection["selection"];
|
|
86
|
+
summary: NextTrainingModelSelection["summary"];
|
|
90
87
|
}> {
|
|
91
88
|
const pipeline = await getPipeline();
|
|
92
89
|
return pipeline.getModelSelectionInfo();
|
|
@@ -97,7 +94,7 @@ export async function getNextTrainingModelSelection(): Promise<{
|
|
|
97
94
|
*/
|
|
98
95
|
export async function benchmarkAndMaybeDeployModel(
|
|
99
96
|
batchId: string,
|
|
100
|
-
autoDeploy = true
|
|
97
|
+
autoDeploy = true,
|
|
101
98
|
): Promise<{
|
|
102
99
|
benchmarked: boolean;
|
|
103
100
|
deployed: boolean;
|
|
@@ -111,7 +108,7 @@ export async function benchmarkAndMaybeDeployModel(
|
|
|
111
108
|
* Deploy a specific model version using the deployment strategy options.
|
|
112
109
|
*/
|
|
113
110
|
export async function deployModelVersion(
|
|
114
|
-
options: DeploymentOptions
|
|
111
|
+
options: DeploymentOptions,
|
|
115
112
|
): Promise<DeploymentResult> {
|
|
116
113
|
const deployer = await getDeployer();
|
|
117
114
|
return deployer.deploy(options);
|
|
@@ -122,7 +119,7 @@ export async function deployModelVersion(
|
|
|
122
119
|
*/
|
|
123
120
|
export async function rollbackModelVersion(
|
|
124
121
|
currentVersion: string,
|
|
125
|
-
targetVersion: string
|
|
122
|
+
targetVersion: string,
|
|
126
123
|
): Promise<DeploymentResult> {
|
|
127
124
|
const deployer = await getDeployer();
|
|
128
125
|
return deployer.rollback(currentVersion, targetVersion);
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* Stores trained models with metadata for easy deployment.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { del, list, put } from
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { logger } from
|
|
8
|
+
import fs from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { del, list, put } from "@vercel/blob";
|
|
11
|
+
import type { JsonValue } from "../../adapter";
|
|
12
|
+
import { getTrainingDataAdapter } from "../../adapter";
|
|
13
|
+
import { logger } from "../../utils/logger";
|
|
14
14
|
|
|
15
15
|
export interface ModelMetadata {
|
|
16
16
|
trainingBatch?: string;
|
|
@@ -30,7 +30,7 @@ export interface ModelVersion {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export class ModelStorageService {
|
|
33
|
-
private readonly blobPrefix =
|
|
33
|
+
private readonly blobPrefix = "models/";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Upload trained model to Vercel Blob
|
|
@@ -39,9 +39,9 @@ export class ModelStorageService {
|
|
|
39
39
|
version: string;
|
|
40
40
|
modelPath: string;
|
|
41
41
|
modelIdPrefix?: string;
|
|
42
|
-
metadata?: ModelVersion[
|
|
42
|
+
metadata?: ModelVersion["metadata"];
|
|
43
43
|
}): Promise<ModelVersion> {
|
|
44
|
-
logger.info(
|
|
44
|
+
logger.info("Uploading model to Vercel Blob", {
|
|
45
45
|
version: options.version,
|
|
46
46
|
path: options.modelPath,
|
|
47
47
|
});
|
|
@@ -55,9 +55,9 @@ export class ModelStorageService {
|
|
|
55
55
|
`${this.blobPrefix}${options.version}/${fileName}`,
|
|
56
56
|
modelData,
|
|
57
57
|
{
|
|
58
|
-
access:
|
|
58
|
+
access: "public", // Models can be publicly downloaded
|
|
59
59
|
addRandomSuffix: false,
|
|
60
|
-
}
|
|
60
|
+
},
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
// Upload metadata
|
|
@@ -65,26 +65,26 @@ export class ModelStorageService {
|
|
|
65
65
|
`${this.blobPrefix}${options.version}/metadata.json`,
|
|
66
66
|
JSON.stringify(options.metadata || {}, null, 2),
|
|
67
67
|
{
|
|
68
|
-
access:
|
|
68
|
+
access: "public",
|
|
69
69
|
addRandomSuffix: false,
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
logger.info(
|
|
73
|
+
logger.info("Model uploaded to Vercel Blob", {
|
|
74
74
|
version: options.version,
|
|
75
75
|
url: blob.url,
|
|
76
76
|
size: (blob as { size?: number }).size || 0,
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
const metadataModelIdPrefix =
|
|
80
|
-
typeof options.metadata?.modelIdPrefix ===
|
|
80
|
+
typeof options.metadata?.modelIdPrefix === "string"
|
|
81
81
|
? options.metadata.modelIdPrefix
|
|
82
82
|
: undefined;
|
|
83
83
|
const modelIdPrefix =
|
|
84
84
|
options.modelIdPrefix ||
|
|
85
85
|
metadataModelIdPrefix ||
|
|
86
86
|
process.env.TRAINING_MODEL_ID_PREFIX ||
|
|
87
|
-
|
|
87
|
+
"eliza-agent";
|
|
88
88
|
|
|
89
89
|
// Save to database via adapter
|
|
90
90
|
const adapter = getTrainingDataAdapter();
|
|
@@ -93,9 +93,9 @@ export class ModelStorageService {
|
|
|
93
93
|
modelId: `${modelIdPrefix}-${options.version}`,
|
|
94
94
|
version: options.version,
|
|
95
95
|
baseModel:
|
|
96
|
-
(options.metadata?.baseModel as string) ||
|
|
96
|
+
(options.metadata?.baseModel as string) || "unsloth/Qwen3-4B-128K",
|
|
97
97
|
trainingBatch: (options.metadata?.trainingBatch as string) || null,
|
|
98
|
-
status:
|
|
98
|
+
status: "ready",
|
|
99
99
|
deployedAt: null,
|
|
100
100
|
archivedAt: null,
|
|
101
101
|
storagePath: blob.url,
|
|
@@ -116,7 +116,7 @@ export class ModelStorageService {
|
|
|
116
116
|
return {
|
|
117
117
|
version: options.version,
|
|
118
118
|
baseModel:
|
|
119
|
-
(options.metadata?.baseModel as string) ||
|
|
119
|
+
(options.metadata?.baseModel as string) || "unsloth/Qwen3-4B-128K",
|
|
120
120
|
blobUrl: blob.url,
|
|
121
121
|
size: (blob as { size?: number }).size || 0,
|
|
122
122
|
uploadedAt: new Date(),
|
|
@@ -129,7 +129,7 @@ export class ModelStorageService {
|
|
|
129
129
|
*/
|
|
130
130
|
async downloadModel(version: string): Promise<{
|
|
131
131
|
modelData: Buffer;
|
|
132
|
-
metadata: ModelVersion[
|
|
132
|
+
metadata: ModelVersion["metadata"];
|
|
133
133
|
}> {
|
|
134
134
|
const adapter = getTrainingDataAdapter();
|
|
135
135
|
const model = await adapter.getModelByVersion(version);
|
|
@@ -143,10 +143,10 @@ export class ModelStorageService {
|
|
|
143
143
|
const modelData = Buffer.from(await modelResponse.arrayBuffer());
|
|
144
144
|
|
|
145
145
|
// Download metadata
|
|
146
|
-
const metadataUrl = model.storagePath.replace(/\/[^/]+$/,
|
|
146
|
+
const metadataUrl = model.storagePath.replace(/\/[^/]+$/, "/metadata.json");
|
|
147
147
|
const metadataResponse = await fetch(metadataUrl);
|
|
148
148
|
const metadata =
|
|
149
|
-
(await metadataResponse.json()) as ModelVersion[
|
|
149
|
+
(await metadataResponse.json()) as ModelVersion["metadata"];
|
|
150
150
|
|
|
151
151
|
return {
|
|
152
152
|
modelData,
|
|
@@ -178,7 +178,7 @@ export class ModelStorageService {
|
|
|
178
178
|
const versions = new Map<string, VersionData>();
|
|
179
179
|
|
|
180
180
|
for (const blob of blobs) {
|
|
181
|
-
const parts = blob.pathname.split(
|
|
181
|
+
const parts = blob.pathname.split("/");
|
|
182
182
|
const version = parts[1];
|
|
183
183
|
if (!version) continue;
|
|
184
184
|
|
|
@@ -196,7 +196,7 @@ export class ModelStorageService {
|
|
|
196
196
|
? blob.uploadedAt.toISOString()
|
|
197
197
|
: blob.uploadedAt,
|
|
198
198
|
};
|
|
199
|
-
versions.get(version)
|
|
199
|
+
versions.get(version)?.blobs.push(blobInfo);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
// Get metadata for each version
|
|
@@ -205,19 +205,19 @@ export class ModelStorageService {
|
|
|
205
205
|
for (const [version, data] of versions) {
|
|
206
206
|
const modelBlob = data.blobs.find(
|
|
207
207
|
(b: BlobInfo) =>
|
|
208
|
-
b.pathname.endsWith(
|
|
208
|
+
b.pathname.endsWith(".safetensors") || b.pathname.endsWith(".bin"),
|
|
209
209
|
);
|
|
210
210
|
|
|
211
211
|
if (modelBlob) {
|
|
212
212
|
// Try to get metadata
|
|
213
|
-
let metadata: ModelVersion[
|
|
213
|
+
let metadata: ModelVersion["metadata"] = {};
|
|
214
214
|
try {
|
|
215
215
|
const metadataBlob = data.blobs.find((b: BlobInfo) =>
|
|
216
|
-
b.pathname.endsWith(
|
|
216
|
+
b.pathname.endsWith("metadata.json"),
|
|
217
217
|
);
|
|
218
218
|
if (metadataBlob) {
|
|
219
219
|
const response = await fetch(metadataBlob.url);
|
|
220
|
-
metadata = (await response.json()) as ModelVersion[
|
|
220
|
+
metadata = (await response.json()) as ModelVersion["metadata"];
|
|
221
221
|
}
|
|
222
222
|
} catch {
|
|
223
223
|
// No metadata, use defaults
|
|
@@ -225,7 +225,7 @@ export class ModelStorageService {
|
|
|
225
225
|
|
|
226
226
|
models.push({
|
|
227
227
|
version,
|
|
228
|
-
baseModel: metadata.baseModel ||
|
|
228
|
+
baseModel: metadata.baseModel || "unknown",
|
|
229
229
|
blobUrl: modelBlob.url,
|
|
230
230
|
size: modelBlob.size,
|
|
231
231
|
uploadedAt:
|
|
@@ -238,7 +238,7 @@ export class ModelStorageService {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
return models.sort(
|
|
241
|
-
(a, b) => b.uploadedAt.getTime() - a.uploadedAt.getTime()
|
|
241
|
+
(a, b) => b.uploadedAt.getTime() - a.uploadedAt.getTime(),
|
|
242
242
|
);
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -258,12 +258,12 @@ export class ModelStorageService {
|
|
|
258
258
|
const adapter = getTrainingDataAdapter();
|
|
259
259
|
const model = await adapter.getModelByVersion(version);
|
|
260
260
|
if (model) {
|
|
261
|
-
await adapter.updateModelStatus(model.modelId,
|
|
261
|
+
await adapter.updateModelStatus(model.modelId, "archived", {
|
|
262
262
|
archivedAt: new Date(),
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
logger.info(
|
|
266
|
+
logger.info("Model deleted from Vercel Blob", { version });
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
/**
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* for long-term storage and reproducibility.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { logger } from
|
|
8
|
+
import fs from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { del, list, put } from "@vercel/blob";
|
|
11
|
+
import type { JsonValue } from "../../adapter";
|
|
12
|
+
import { logger } from "../../utils/logger";
|
|
13
13
|
|
|
14
14
|
export interface ArchivedWindow {
|
|
15
15
|
windowId: string;
|
|
@@ -25,7 +25,7 @@ export interface ArchivedWindow {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class TrainingDataArchiver {
|
|
28
|
-
private readonly blobPrefix =
|
|
28
|
+
private readonly blobPrefix = "training-data/";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Archive training data for a window
|
|
@@ -37,7 +37,7 @@ export class TrainingDataArchiver {
|
|
|
37
37
|
rulerScoresPath?: string;
|
|
38
38
|
metadata?: Record<string, unknown>;
|
|
39
39
|
}): Promise<ArchivedWindow> {
|
|
40
|
-
logger.info(
|
|
40
|
+
logger.info("Archiving training data", { windowId: options.windowId });
|
|
41
41
|
|
|
42
42
|
const prefix = `${this.blobPrefix}${options.windowId}/`;
|
|
43
43
|
interface BlobUrls {
|
|
@@ -47,15 +47,15 @@ export class TrainingDataArchiver {
|
|
|
47
47
|
metadata: string;
|
|
48
48
|
}
|
|
49
49
|
const urls: BlobUrls = {
|
|
50
|
-
trajectories:
|
|
51
|
-
metadata:
|
|
50
|
+
trajectories: "",
|
|
51
|
+
metadata: "",
|
|
52
52
|
};
|
|
53
53
|
let totalSize = 0;
|
|
54
54
|
|
|
55
55
|
// Upload trajectories
|
|
56
56
|
const trajData = await fs.readFile(options.trajectoriesPath);
|
|
57
57
|
const trajBlob = await put(`${prefix}trajectories.jsonl`, trajData, {
|
|
58
|
-
access:
|
|
58
|
+
access: "public",
|
|
59
59
|
addRandomSuffix: false,
|
|
60
60
|
});
|
|
61
61
|
urls.trajectories = trajBlob.url;
|
|
@@ -65,7 +65,7 @@ export class TrainingDataArchiver {
|
|
|
65
65
|
if (options.groupsPath) {
|
|
66
66
|
const groupsData = await fs.readFile(options.groupsPath);
|
|
67
67
|
const groupsBlob = await put(`${prefix}groups.jsonl`, groupsData, {
|
|
68
|
-
access:
|
|
68
|
+
access: "public",
|
|
69
69
|
addRandomSuffix: false,
|
|
70
70
|
});
|
|
71
71
|
urls.groups = groupsBlob.url;
|
|
@@ -76,7 +76,7 @@ export class TrainingDataArchiver {
|
|
|
76
76
|
if (options.rulerScoresPath) {
|
|
77
77
|
const scoresData = await fs.readFile(options.rulerScoresPath);
|
|
78
78
|
const scoresBlob = await put(`${prefix}ruler_scores.json`, scoresData, {
|
|
79
|
-
access:
|
|
79
|
+
access: "public",
|
|
80
80
|
addRandomSuffix: false,
|
|
81
81
|
});
|
|
82
82
|
urls.rulerScores = scoresBlob.url;
|
|
@@ -86,13 +86,13 @@ export class TrainingDataArchiver {
|
|
|
86
86
|
// Upload metadata
|
|
87
87
|
const metadataJson = JSON.stringify(options.metadata || {}, null, 2);
|
|
88
88
|
const metadataBlob = await put(`${prefix}metadata.json`, metadataJson, {
|
|
89
|
-
access:
|
|
89
|
+
access: "public",
|
|
90
90
|
addRandomSuffix: false,
|
|
91
91
|
});
|
|
92
92
|
urls.metadata = metadataBlob.url;
|
|
93
|
-
totalSize += Buffer.byteLength(metadataJson,
|
|
93
|
+
totalSize += Buffer.byteLength(metadataJson, "utf8");
|
|
94
94
|
|
|
95
|
-
logger.info(
|
|
95
|
+
logger.info("Training data archived", {
|
|
96
96
|
windowId: options.windowId,
|
|
97
97
|
size: totalSize,
|
|
98
98
|
});
|
|
@@ -134,16 +134,16 @@ export class TrainingDataArchiver {
|
|
|
134
134
|
const response = await fetch(blob.url);
|
|
135
135
|
const filename = path.basename(blob.pathname);
|
|
136
136
|
|
|
137
|
-
if (filename ===
|
|
137
|
+
if (filename === "trajectories.jsonl") {
|
|
138
138
|
result.trajectories = await response.text();
|
|
139
|
-
} else if (filename ===
|
|
139
|
+
} else if (filename === "groups.jsonl") {
|
|
140
140
|
result.groups = await response.text();
|
|
141
|
-
} else if (filename ===
|
|
141
|
+
} else if (filename === "ruler_scores.json") {
|
|
142
142
|
result.rulerScores = (await response.json()) as Record<
|
|
143
143
|
string,
|
|
144
144
|
JsonValue
|
|
145
145
|
>;
|
|
146
|
-
} else if (filename ===
|
|
146
|
+
} else if (filename === "metadata.json") {
|
|
147
147
|
result.metadata = (await response.json()) as Record<string, JsonValue>;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -169,7 +169,7 @@ export class TrainingDataArchiver {
|
|
|
169
169
|
|
|
170
170
|
const windows = new Set<string>();
|
|
171
171
|
for (const blob of blobs) {
|
|
172
|
-
const parts = blob.pathname.split(
|
|
172
|
+
const parts = blob.pathname.split("/");
|
|
173
173
|
if (parts[1]) {
|
|
174
174
|
windows.add(parts[1]);
|
|
175
175
|
}
|
|
@@ -189,7 +189,7 @@ export class TrainingDataArchiver {
|
|
|
189
189
|
await del(blob.url);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
logger.info(
|
|
192
|
+
logger.info("Deleted archived window", { windowId });
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
@@ -8,10 +8,10 @@ export {
|
|
|
8
8
|
ModelStorageService,
|
|
9
9
|
type ModelVersion,
|
|
10
10
|
modelStorage,
|
|
11
|
-
} from
|
|
11
|
+
} from "./ModelStorageService";
|
|
12
12
|
|
|
13
13
|
export {
|
|
14
14
|
type ArchivedWindow,
|
|
15
15
|
TrainingDataArchiver,
|
|
16
16
|
trainingDataArchiver,
|
|
17
|
-
} from
|
|
17
|
+
} from "./TrainingDataArchiver";
|
package/src/training/types.ts
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
JsonValue,
|
|
9
|
-
|
|
9
|
+
LlmCallLogRecord,
|
|
10
10
|
TrainedModelRecord,
|
|
11
11
|
TrainingBatchRecord,
|
|
12
|
-
|
|
13
|
-
} from
|
|
12
|
+
TrajectoryRecord,
|
|
13
|
+
} from "../adapter";
|
|
14
14
|
|
|
15
15
|
// Re-export adapter record types under the old names for backward compatibility
|
|
16
16
|
export type Trajectory = TrajectoryRecord;
|
|
@@ -57,7 +57,7 @@ export interface LLMCall {
|
|
|
57
57
|
temperature: number;
|
|
58
58
|
maxTokens: number;
|
|
59
59
|
latencyMs?: number;
|
|
60
|
-
purpose:
|
|
60
|
+
purpose: "action" | "reasoning" | "evaluation" | "response";
|
|
61
61
|
actionType?: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -79,7 +79,7 @@ export interface Action {
|
|
|
79
79
|
perpCorrect?: boolean; // Was the perp trade correct?
|
|
80
80
|
sentimentAtTrade?: number; // Sentiment at time of trade (-1 to 1)
|
|
81
81
|
priceChange?: number; // Actual price change after trade
|
|
82
|
-
expectedDirection?:
|
|
82
|
+
expectedDirection?: "up" | "down"; // Expected direction based on sentiment
|
|
83
83
|
|
|
84
84
|
// Sentiment analysis accuracy
|
|
85
85
|
sentimentAccuracy?: number; // How accurate was sentiment reading (0-1)
|
|
@@ -196,7 +196,7 @@ export interface AutomationConfig {
|
|
|
196
196
|
pythonProjectRoot?: string;
|
|
197
197
|
trainerScriptPath?: string;
|
|
198
198
|
trainerPythonExecutable?: string;
|
|
199
|
-
trainingMode?:
|
|
199
|
+
trainingMode?: "atropos" | "tinker";
|
|
200
200
|
atroposApiUrl?: string;
|
|
201
201
|
vllmPort?: number;
|
|
202
202
|
}
|