@holoscript/framework 6.0.3 → 6.0.4
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/CHANGELOG.md +1 -2
- package/ROADMAP.md +68 -66
- package/dist/{InvisibleWallet-BB6tFvRA.d.cts → InvisibleWallet-EFiuaLn3.d.cts} +1 -1
- package/dist/{OrchestratorAgent-BvWgf9uw.d.cts → OrchestratorAgent-CrLDGNL6.d.cts} +1 -1
- package/dist/agents/index.cjs +11 -10
- package/dist/agents/index.d.cts +4 -16
- package/dist/ai/index.cjs +2 -2
- package/dist/behavior.cjs +10 -0
- package/dist/economy/index.cjs +4 -4
- package/dist/economy/index.d.cts +2 -2
- package/dist/index.cjs +33 -11
- package/dist/index.d.cts +3 -3
- package/dist/swarm/index.cjs +3 -0
- package/package.json +14 -9
- package/src/__tests__/bounty-marketplace.test.ts +53 -21
- package/src/__tests__/delegation.test.ts +1 -4
- package/src/__tests__/done-log-audit.test.ts +38 -46
- package/src/__tests__/framework.test.ts +172 -53
- package/src/__tests__/goal-synthesizer.test.ts +9 -6
- package/src/__tests__/presence.test.ts +1 -1
- package/src/__tests__/protocol-agent.test.ts +12 -11
- package/src/__tests__/revenue-splitter.test.ts +22 -15
- package/src/__tests__/scenario-driven-todo.test.ts +55 -35
- package/src/__tests__/self-improve.test.ts +28 -9
- package/src/__tests__/service-lifecycle.test.ts +9 -3
- package/src/__tests__/skill-router.test.ts +3 -3
- package/src/agents/CulturalMemory.ts +6 -6
- package/src/agents/DelegationTraceHooks.ts +560 -0
- package/src/agents/FederatedRegistryAdapter.ts +1 -1
- package/src/agents/NormEngine.ts +3 -8
- package/src/agents/OrchestratorAgent.ts +1 -1
- package/src/agents/TaskDelegationService.ts +5 -9
- package/src/agents/__tests__/AgentWalletRegistry.test.ts +5 -4
- package/src/agents/__tests__/CrossRealityHandoff.test.ts +9 -3
- package/src/agents/__tests__/DelegationTraceHooks.test.ts +390 -0
- package/src/agents/__tests__/TaskDelegationService.test.ts +4 -2
- package/src/agents/spatial-comms/Layer1RealTime.ts +36 -19
- package/src/agents/spatial-comms/Layer2A2A.ts +1 -3
- package/src/agents/spatial-comms/Layer3MCP.ts +13 -4
- package/src/agents/spatial-comms/ProtocolTypes.ts +5 -2
- package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +2 -2
- package/src/ai/HoloScriptGenerator.ts +2 -2
- package/src/ai/__tests__/PerceptionSystem.prod.test.ts +1 -1
- package/src/ai/__tests__/PerceptionSystem.test.ts +14 -14
- package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +1 -1
- package/src/ai/index.ts +5 -1
- package/src/board/audit.ts +17 -6
- package/src/board/board-ops.ts +45 -15
- package/src/board/board-types.ts +94 -20
- package/src/delegation.ts +5 -3
- package/src/distributed-claimer.ts +13 -2
- package/src/economy/BountyManager.ts +40 -18
- package/src/economy/KnowledgeMarketplace.ts +27 -8
- package/src/economy/PaymentWebhookService.ts +0 -1
- package/src/economy/RevenueSplitter.ts +2 -4
- package/src/economy/UnifiedBudgetOptimizer.ts +8 -9
- package/src/economy/_core-stubs.ts +1 -1
- package/src/economy/x402-facilitator.ts +17 -8
- package/src/index.ts +16 -12
- package/src/knowledge/__tests__/knowledge-consolidator.test.ts +138 -89
- package/src/knowledge/__tests__/knowledge-store-vector.test.ts +59 -16
- package/src/knowledge/brain.ts +7 -7
- package/src/knowledge/consolidation.ts +16 -16
- package/src/knowledge/knowledge-consolidator.ts +60 -30
- package/src/knowledge/knowledge-store.ts +83 -45
- package/src/learning/ProceduralCompiler.ts +6 -1
- package/src/learning/learning/MemoryConsolidator.ts +102 -0
- package/src/learning/learning/MemoryScorer.ts +69 -0
- package/src/learning/learning/ProceduralCompiler.ts +45 -0
- package/src/learning/learning/SemanticClusterer.ts +66 -0
- package/src/llm/llm-adapter.ts +24 -10
- package/src/mesh/index.ts +37 -17
- package/src/protocol/goal-synthesizer.ts +24 -34
- package/src/protocol/implementations.ts +91 -22
- package/src/protocol/micro-phase-decomposer.ts +25 -17
- package/src/protocol/micro-step-decomposer.test.ts +104 -39
- package/src/protocol-agent.test.ts +17 -7
- package/src/protocol-agent.ts +45 -42
- package/src/self-improve/absorb-scanner.ts +9 -6
- package/src/self-improve/evolution-engine.ts +36 -18
- package/src/self-improve/framework-absorber.ts +21 -16
- package/src/self-improve/index.ts +2 -10
- package/src/self-improve/prompt-optimizer.ts +31 -19
- package/src/self-improve/test-generator.ts +16 -12
- package/src/skill-router.ts +7 -6
- package/src/swarm/messaging/GossipProtocol.ts +1 -1
- package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +31 -9
- package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +21 -7
- package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +24 -8
- package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +6 -2
- package/src/team.ts +277 -122
- package/src/training/scripts/generate-spatial-dataset.ts +1 -1
- package/src/training/training/LRScheduler.ts +377 -0
- package/src/training/training/QualityScoringPipeline.ts +139 -0
- package/src/training/training/SoftDedup.ts +461 -0
- package/src/training/training/SparsityMonitor.ts +685 -0
- package/src/training/training/SparsityMonitorTypes.ts +209 -0
- package/src/training/training/SpatialTrainingDataGenerator.ts +1526 -0
- package/src/training/training/SpatialTrainingDataTypes.ts +216 -0
- package/src/training/training/TrainingPipelineConfig.ts +215 -0
- package/src/training/training/__tests__/CorpusValidation.test.ts +87 -0
- package/src/training/training/__tests__/LRScheduler.test.ts +592 -0
- package/src/training/training/__tests__/SoftDedup.test.ts +415 -0
- package/src/training/training/__tests__/SparsityMonitor.test.ts +1623 -0
- package/src/training/training/__tests__/SpatialCorpusValidation.test.ts +72 -0
- package/src/training/training/__tests__/SpatialTrainingDataGenerator.test.ts +1244 -0
- package/src/training/training/__tests__/TrainingMonkeyIntegration.test.ts +897 -0
- package/src/training/training/__tests__/TrainingPipelineConfig.test.ts +202 -0
- package/src/training/training/__tests__/schema.test.ts +72 -0
- package/src/training/training/__tests__/training-constants.test.ts +106 -0
- package/src/training/training/__tests__/trait-mappings.test.ts +81 -0
- package/src/training/training/constants.ts +94 -0
- package/src/training/training/index.ts +17 -0
- package/src/training/training/schema.ts +147 -0
- package/src/training/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
- package/src/training/training/scripts/generate-spatial-dataset.ts +521 -0
- package/src/training/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
- package/src/training/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
- package/src/training/training/trainingmonkey/index.ts +26 -0
- package/src/training/training/trait-mappings.ts +157 -0
- package/src/types.ts +2 -7
- package/ALL-test-results.json +0 -1
- package/LICENSE +0 -21
- package/dist/AgentManifest-CB4xM-Ma.d.ts +0 -704
- package/dist/BehaviorTree-BrBFECv5.d.ts +0 -103
- package/dist/InvisibleWallet-rtRrBOA8.d.ts +0 -1732
- package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +0 -798
- package/dist/agents/index.d.ts +0 -1788
- package/dist/agents/index.js +0 -4695
- package/dist/ai/index.d.ts +0 -1753
- package/dist/ai/index.js +0 -5244
- package/dist/behavior.d.ts +0 -130
- package/dist/behavior.js +0 -407
- package/dist/economy/index.d.ts +0 -747
- package/dist/economy/index.js +0 -3617
- package/dist/implementations-D9T3un9D.d.ts +0 -236
- package/dist/index.d.ts +0 -1729
- package/dist/index.js +0 -24277
- package/dist/learning/index.d.ts +0 -104
- package/dist/learning/index.js +0 -189
- package/dist/negotiation/index.d.ts +0 -610
- package/dist/negotiation/index.js +0 -931
- package/dist/skills/index.d.ts +0 -289
- package/dist/skills/index.js +0 -1079
- package/dist/swarm/index.d.ts +0 -2433
- package/dist/swarm/index.js +0 -5221
- package/dist/training/index.d.ts +0 -1734
- package/dist/training/index.js +0 -2687
- package/extract-failures.js +0 -10
- package/src/training/training/data/novel-use-cases.jsonl +0 -153
- package/src/training/training/data/spatial-reasoning-10k.jsonl +0 -9354
- package/src/types/core-stubs.d.ts +0 -113
- package/test-output.txt +0 -0
- package/test-result.json +0 -1
- package/tsc-errors.txt +0 -4
- package/tsc_output.txt +0 -0
- package/typescript-errors-2.txt +0 -0
- package/typescript-errors.txt +0 -22
- package/vitest-log-utf8.txt +0 -268
- package/vitest-log.txt +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spatial Training Data Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the spatial reasoning training data pipeline.
|
|
5
|
+
* Used to generate instruction-response pairs from HoloScript compositions
|
|
6
|
+
* with spatial constraints (spatial_adjacent, spatial_contains, spatial_reachable)
|
|
7
|
+
* for fine-tuning LLMs on spatial reasoning tasks.
|
|
8
|
+
*
|
|
9
|
+
* @module training/SpatialTrainingDataTypes
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// DIFFICULTY LEVELS
|
|
14
|
+
// =============================================================================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Difficulty levels for generated spatial reasoning examples.
|
|
18
|
+
*
|
|
19
|
+
* - basic: 2 objects, single spatial relationship
|
|
20
|
+
* - intermediate: 3-5 objects, multiple relationships, mixed constraint types
|
|
21
|
+
* - advanced: 6+ objects, occlusion, nested containment, chained reachability
|
|
22
|
+
*/
|
|
23
|
+
export type SpatialDifficulty = 'basic' | 'intermediate' | 'advanced';
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// SPATIAL RELATIONSHIP TYPES
|
|
27
|
+
// =============================================================================
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The three core spatial relationship types from HoloScript's constraint system.
|
|
31
|
+
*/
|
|
32
|
+
export type SpatialRelationshipType = 'spatial_adjacent' | 'spatial_contains' | 'spatial_reachable';
|
|
33
|
+
|
|
34
|
+
// =============================================================================
|
|
35
|
+
// SCENE OBJECT DEFINITION
|
|
36
|
+
// =============================================================================
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A scene object with spatial properties for training data generation.
|
|
40
|
+
*/
|
|
41
|
+
export interface SceneObject {
|
|
42
|
+
/** Unique identifier for the object */
|
|
43
|
+
id: string;
|
|
44
|
+
/** Object type (e.g., 'cube', 'sphere', 'zone', 'npc') */
|
|
45
|
+
type: string;
|
|
46
|
+
/** 3D position */
|
|
47
|
+
position: [number, number, number];
|
|
48
|
+
/** 3D scale */
|
|
49
|
+
scale: { x: number; y: number; z: number };
|
|
50
|
+
/** Bounding box (for containment checks) */
|
|
51
|
+
bounds?: {
|
|
52
|
+
min: { x: number; y: number; z: number };
|
|
53
|
+
max: { x: number; y: number; z: number };
|
|
54
|
+
};
|
|
55
|
+
/** Whether this object acts as an obstacle */
|
|
56
|
+
isObstacle?: boolean;
|
|
57
|
+
/** Optional color for visual description */
|
|
58
|
+
color?: string;
|
|
59
|
+
/** Optional geometry type */
|
|
60
|
+
geometry?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// =============================================================================
|
|
64
|
+
// SPATIAL RELATIONSHIP DEFINITION
|
|
65
|
+
// =============================================================================
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A spatial relationship between two scene objects.
|
|
69
|
+
*/
|
|
70
|
+
export interface SpatialRelationship {
|
|
71
|
+
/** The relationship type */
|
|
72
|
+
type: SpatialRelationshipType;
|
|
73
|
+
/** Source object ID */
|
|
74
|
+
sourceId: string;
|
|
75
|
+
/** Target object ID */
|
|
76
|
+
targetId: string;
|
|
77
|
+
/** Whether the relationship is satisfied (true=positive, false=negative) */
|
|
78
|
+
satisfied: boolean;
|
|
79
|
+
/** Constraint parameters */
|
|
80
|
+
params: SpatialRelationshipParams;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parameters for spatial relationship constraints.
|
|
85
|
+
*/
|
|
86
|
+
export interface SpatialRelationshipParams {
|
|
87
|
+
/** For adjacent: maximum distance */
|
|
88
|
+
maxDistance?: number;
|
|
89
|
+
/** For adjacent: minimum distance */
|
|
90
|
+
minDistance?: number;
|
|
91
|
+
/** For adjacent: axis restriction */
|
|
92
|
+
axis?: string;
|
|
93
|
+
/** For contains: margin */
|
|
94
|
+
margin?: number;
|
|
95
|
+
/** For contains: strict mode */
|
|
96
|
+
strict?: boolean;
|
|
97
|
+
/** For reachable: max path length */
|
|
98
|
+
maxPathLength?: number;
|
|
99
|
+
/** For reachable: obstacle types */
|
|
100
|
+
obstacleTypes?: string[];
|
|
101
|
+
/** For reachable: algorithm */
|
|
102
|
+
algorithm?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// =============================================================================
|
|
106
|
+
// SCENE DEFINITION
|
|
107
|
+
// =============================================================================
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A complete scene with objects and spatial relationships.
|
|
111
|
+
*/
|
|
112
|
+
export interface SpatialScene {
|
|
113
|
+
/** Scene name/identifier */
|
|
114
|
+
name: string;
|
|
115
|
+
/** Objects in the scene */
|
|
116
|
+
objects: SceneObject[];
|
|
117
|
+
/** Spatial relationships between objects */
|
|
118
|
+
relationships: SpatialRelationship[];
|
|
119
|
+
/** Difficulty level */
|
|
120
|
+
difficulty: SpatialDifficulty;
|
|
121
|
+
/** The HoloScript composition source */
|
|
122
|
+
holoScriptSource: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// =============================================================================
|
|
126
|
+
// TRAINING EXAMPLE (INSTRUCTION-RESPONSE PAIR)
|
|
127
|
+
// =============================================================================
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A single training example with instruction and response.
|
|
131
|
+
* Suitable for fine-tuning LLMs on spatial reasoning tasks.
|
|
132
|
+
*/
|
|
133
|
+
export interface SpatialTrainingExample {
|
|
134
|
+
/** Unique example ID */
|
|
135
|
+
id: string;
|
|
136
|
+
/** The instruction/question for the LLM */
|
|
137
|
+
instruction: string;
|
|
138
|
+
/** The expected response/answer */
|
|
139
|
+
response: string;
|
|
140
|
+
/** The HoloScript source that defines the scene */
|
|
141
|
+
context: string;
|
|
142
|
+
/** Spatial relationship type being tested */
|
|
143
|
+
relationshipType: SpatialRelationshipType;
|
|
144
|
+
/** Whether this is a positive or negative example */
|
|
145
|
+
isPositive: boolean;
|
|
146
|
+
/** Difficulty level */
|
|
147
|
+
difficulty: SpatialDifficulty;
|
|
148
|
+
/** Tags for categorization */
|
|
149
|
+
tags: string[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// =============================================================================
|
|
153
|
+
// GENERATOR CONFIGURATION
|
|
154
|
+
// =============================================================================
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Configuration options for the SpatialTrainingDataGenerator.
|
|
158
|
+
*/
|
|
159
|
+
export interface SpatialGeneratorConfig {
|
|
160
|
+
/** Number of examples to generate per relationship type per difficulty level */
|
|
161
|
+
examplesPerCategory?: number;
|
|
162
|
+
/** Which relationship types to include */
|
|
163
|
+
relationshipTypes?: SpatialRelationshipType[];
|
|
164
|
+
/** Which difficulty levels to include */
|
|
165
|
+
difficultyLevels?: SpatialDifficulty[];
|
|
166
|
+
/** Ratio of positive to negative examples (default 0.5 = equal) */
|
|
167
|
+
positiveRatio?: number;
|
|
168
|
+
/** Random seed for reproducibility (if provided) */
|
|
169
|
+
seed?: number;
|
|
170
|
+
/** Whether to include HoloScript context in output */
|
|
171
|
+
includeContext?: boolean;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// =============================================================================
|
|
175
|
+
// GENERATOR STATISTICS
|
|
176
|
+
// =============================================================================
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Statistics about generated training data.
|
|
180
|
+
*/
|
|
181
|
+
export interface SpatialGeneratorStats {
|
|
182
|
+
/** Total number of examples generated */
|
|
183
|
+
totalExamples: number;
|
|
184
|
+
/** Breakdown by relationship type */
|
|
185
|
+
byRelationship: Record<SpatialRelationshipType, number>;
|
|
186
|
+
/** Breakdown by difficulty */
|
|
187
|
+
byDifficulty: Record<SpatialDifficulty, number>;
|
|
188
|
+
/** Breakdown by positive/negative */
|
|
189
|
+
positiveCount: number;
|
|
190
|
+
negativeCount: number;
|
|
191
|
+
/** Number of unique templates used */
|
|
192
|
+
uniqueTemplatesUsed: number;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// =============================================================================
|
|
196
|
+
// JSONL OUTPUT FORMAT
|
|
197
|
+
// =============================================================================
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* JSONL line format for fine-tuning output.
|
|
201
|
+
* Each line in the JSONL file is one of these objects.
|
|
202
|
+
*/
|
|
203
|
+
export interface SpatialTrainingJSONLEntry {
|
|
204
|
+
/** The instruction/question */
|
|
205
|
+
instruction: string;
|
|
206
|
+
/** The expected response */
|
|
207
|
+
response: string;
|
|
208
|
+
/** Metadata for filtering/analysis */
|
|
209
|
+
metadata: {
|
|
210
|
+
id: string;
|
|
211
|
+
relationship_type: SpatialRelationshipType;
|
|
212
|
+
is_positive: boolean;
|
|
213
|
+
difficulty: SpatialDifficulty;
|
|
214
|
+
tags: string[];
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrainingPipelineConfig - Unified Training Pipeline Configuration
|
|
3
|
+
*
|
|
4
|
+
* Integrates all training pipeline components:
|
|
5
|
+
* - Quality Scoring (W.010): Multi-dimensional quality filtering
|
|
6
|
+
* - Hard Dedup (W.004): Exact/near-duplicate removal (external)
|
|
7
|
+
* - SoftDedup (W.008): N-gram commonness-based reweighting
|
|
8
|
+
* - LR Schedule (W.009): Warmup + cosine decay
|
|
9
|
+
* - Hyperparameters (W.006, W.007): Learning rate, batch size, epochs
|
|
10
|
+
*
|
|
11
|
+
* Pipeline order: Quality Filter -> Hard Dedup -> SoftDedup -> Training
|
|
12
|
+
*
|
|
13
|
+
* @module training/TrainingPipelineConfig
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { SoftDedupConfig } from './SoftDedup';
|
|
17
|
+
import type { LRSchedulerConfig } from './LRScheduler';
|
|
18
|
+
import type { QualityScoringConfig } from './QualityScoringPipeline';
|
|
19
|
+
import { DEFAULT_SOFTDEDUP_CONFIG } from './SoftDedup';
|
|
20
|
+
import { DEFAULT_LR_SCHEDULER_CONFIG } from './LRScheduler';
|
|
21
|
+
import { DEFAULT_SCORING_CONFIG } from './QualityScoringPipeline';
|
|
22
|
+
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// TYPES
|
|
25
|
+
// =============================================================================
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Complete training pipeline configuration.
|
|
29
|
+
*
|
|
30
|
+
* Encompasses all stages from data preparation through training execution.
|
|
31
|
+
*/
|
|
32
|
+
export interface TrainingPipelineConfig {
|
|
33
|
+
/** Data quality filtering configuration (W.010) */
|
|
34
|
+
qualityScoring: QualityScoringConfig;
|
|
35
|
+
|
|
36
|
+
/** Soft deduplication configuration (W.008) */
|
|
37
|
+
softDedup: SoftDedupConfig;
|
|
38
|
+
|
|
39
|
+
/** Learning rate schedule configuration (W.009) */
|
|
40
|
+
lrSchedule: LRSchedulerConfig;
|
|
41
|
+
|
|
42
|
+
/** Core training hyperparameters (W.006, W.007) */
|
|
43
|
+
hyperparameters: TrainingHyperparameters;
|
|
44
|
+
|
|
45
|
+
/** Pipeline-level settings */
|
|
46
|
+
pipeline: PipelineSettings;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Core training hyperparameters per W.006 and W.007.
|
|
51
|
+
*/
|
|
52
|
+
export interface TrainingHyperparameters {
|
|
53
|
+
/**
|
|
54
|
+
* Base learning rate.
|
|
55
|
+
* Per W.006: 2e-4 for SFT (NOT 2e-5).
|
|
56
|
+
*/
|
|
57
|
+
learningRate: number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Number of training epochs.
|
|
61
|
+
* Per W.006: 2 epochs (NOT 3). "Loss converges in 1-2 epochs."
|
|
62
|
+
*/
|
|
63
|
+
epochs: number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Optimizer.
|
|
67
|
+
* Per W.006: paged_adamw_8bit (NOT adamw_torch).
|
|
68
|
+
*/
|
|
69
|
+
optimizer: 'paged_adamw_8bit' | 'adamw_torch' | 'adafactor';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Micro-batch size per device.
|
|
73
|
+
* Per W.007: 8-16 for 7B models.
|
|
74
|
+
*/
|
|
75
|
+
microBatchSize: number;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gradient accumulation steps.
|
|
79
|
+
* Per W.007: 2-4 steps for effective batch 32-512.
|
|
80
|
+
*/
|
|
81
|
+
gradientAccumulationSteps: number;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Maximum gradient norm for clipping.
|
|
85
|
+
*/
|
|
86
|
+
maxGradNorm: number;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Weight decay coefficient.
|
|
90
|
+
*/
|
|
91
|
+
weightDecay: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Pipeline-level settings controlling the data preparation flow.
|
|
96
|
+
*/
|
|
97
|
+
export interface PipelineSettings {
|
|
98
|
+
/**
|
|
99
|
+
* Whether to apply quality scoring filter before training.
|
|
100
|
+
* Per W.010: Apply BEFORE deduplication to avoid wasting compute on junk.
|
|
101
|
+
*/
|
|
102
|
+
enableQualityFilter: boolean;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether to apply SoftDedup after hard dedup.
|
|
106
|
+
* Per W.008: Apply AFTER hard dedup (W.004), not instead of it.
|
|
107
|
+
*/
|
|
108
|
+
enableSoftDedup: boolean;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether to use the LR scheduler (warmup + cosine decay).
|
|
112
|
+
* Per W.009: Always use.
|
|
113
|
+
*/
|
|
114
|
+
enableLRSchedule: boolean;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Seed for reproducibility.
|
|
118
|
+
*/
|
|
119
|
+
seed?: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// =============================================================================
|
|
123
|
+
// DEFAULT CONFIGURATION
|
|
124
|
+
// =============================================================================
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Default training pipeline configuration.
|
|
128
|
+
*
|
|
129
|
+
* Implements the full optimization pipeline:
|
|
130
|
+
* - Quality Filter (W.010) -> Hard Dedup (W.004) -> SoftDedup (W.008)
|
|
131
|
+
* - LR Schedule: warmup 10% + cosine decay (W.009)
|
|
132
|
+
* - Hyperparameters: LR=2e-4, epochs=2, paged_adamw_8bit (W.006)
|
|
133
|
+
* - Batch: micro=8, accumulation=4, effective=32 (W.007)
|
|
134
|
+
*/
|
|
135
|
+
export const DEFAULT_TRAINING_PIPELINE_CONFIG: TrainingPipelineConfig = {
|
|
136
|
+
qualityScoring: DEFAULT_SCORING_CONFIG,
|
|
137
|
+
softDedup: DEFAULT_SOFTDEDUP_CONFIG,
|
|
138
|
+
lrSchedule: DEFAULT_LR_SCHEDULER_CONFIG,
|
|
139
|
+
hyperparameters: {
|
|
140
|
+
learningRate: 2e-4,
|
|
141
|
+
epochs: 2,
|
|
142
|
+
optimizer: 'paged_adamw_8bit',
|
|
143
|
+
microBatchSize: 8,
|
|
144
|
+
gradientAccumulationSteps: 4,
|
|
145
|
+
maxGradNorm: 1.0,
|
|
146
|
+
weightDecay: 0.01,
|
|
147
|
+
},
|
|
148
|
+
pipeline: {
|
|
149
|
+
enableQualityFilter: true,
|
|
150
|
+
enableSoftDedup: true,
|
|
151
|
+
enableLRSchedule: true,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// CONFIG BUILDER
|
|
157
|
+
// =============================================================================
|
|
158
|
+
|
|
159
|
+
/** Deep partial utility type */
|
|
160
|
+
type DeepPartial<T> = {
|
|
161
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Build a TrainingPipelineConfig with custom overrides.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const config = buildTrainingPipelineConfig({
|
|
170
|
+
* hyperparameters: { learningRate: 1e-4, epochs: 3 },
|
|
171
|
+
* softDedup: { temperature: 0.5 },
|
|
172
|
+
* lrSchedule: { totalSteps: 5000 },
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export function buildTrainingPipelineConfig(
|
|
177
|
+
overrides: DeepPartial<TrainingPipelineConfig> = {}
|
|
178
|
+
): TrainingPipelineConfig {
|
|
179
|
+
return {
|
|
180
|
+
qualityScoring: {
|
|
181
|
+
...DEFAULT_TRAINING_PIPELINE_CONFIG.qualityScoring,
|
|
182
|
+
...(overrides.qualityScoring as Partial<QualityScoringConfig> | undefined),
|
|
183
|
+
},
|
|
184
|
+
softDedup: {
|
|
185
|
+
...DEFAULT_TRAINING_PIPELINE_CONFIG.softDedup,
|
|
186
|
+
...(overrides.softDedup as Partial<SoftDedupConfig> | undefined),
|
|
187
|
+
},
|
|
188
|
+
lrSchedule: {
|
|
189
|
+
...DEFAULT_TRAINING_PIPELINE_CONFIG.lrSchedule,
|
|
190
|
+
...(overrides.lrSchedule as Partial<LRSchedulerConfig> | undefined),
|
|
191
|
+
},
|
|
192
|
+
hyperparameters: {
|
|
193
|
+
...DEFAULT_TRAINING_PIPELINE_CONFIG.hyperparameters,
|
|
194
|
+
...(overrides.hyperparameters as Partial<TrainingHyperparameters> | undefined),
|
|
195
|
+
},
|
|
196
|
+
pipeline: {
|
|
197
|
+
...DEFAULT_TRAINING_PIPELINE_CONFIG.pipeline,
|
|
198
|
+
...(overrides.pipeline as Partial<PipelineSettings> | undefined),
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Compute the total training steps from dataset size and hyperparameters.
|
|
205
|
+
*
|
|
206
|
+
* @param datasetSize - Number of training examples (after dedup)
|
|
207
|
+
* @param config - Training pipeline configuration
|
|
208
|
+
* @returns Total number of training steps
|
|
209
|
+
*/
|
|
210
|
+
export function computeTotalSteps(datasetSize: number, config: TrainingPipelineConfig): number {
|
|
211
|
+
const { microBatchSize, gradientAccumulationSteps, epochs } = config.hyperparameters;
|
|
212
|
+
const effectiveBatchSize = microBatchSize * gradientAccumulationSteps;
|
|
213
|
+
const stepsPerEpoch = Math.ceil(datasetSize / effectiveBatchSize);
|
|
214
|
+
return stepsPerEpoch * epochs;
|
|
215
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Training Corpus Parse Validation
|
|
3
|
+
*
|
|
4
|
+
* Runs every training example from TrainingDataGenerator through
|
|
5
|
+
* HoloScriptCodeParser to catch syntax errors in the corpus.
|
|
6
|
+
*
|
|
7
|
+
* This is a smoke gate — if any training example can't parse,
|
|
8
|
+
* it's invalid training data and will teach the model bad syntax.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it, expect } from 'vitest';
|
|
11
|
+
import { TrainingDataGenerator, ALL_CATEGORIES } from '../../ai/TrainingDataGenerator';
|
|
12
|
+
import { HoloScriptCodeParser } from '../../HoloScriptCodeParser';
|
|
13
|
+
|
|
14
|
+
describe('Training Corpus Validation', () => {
|
|
15
|
+
const generator = new TrainingDataGenerator();
|
|
16
|
+
const parser = new HoloScriptCodeParser();
|
|
17
|
+
const allExamples = generator.generateAll();
|
|
18
|
+
|
|
19
|
+
it('should have a non-trivial number of training examples', () => {
|
|
20
|
+
expect(allExamples.length).toBeGreaterThanOrEqual(30);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should cover all declared categories', () => {
|
|
24
|
+
const categories = new Set(allExamples.map((ex) => ex.category));
|
|
25
|
+
// At least 10 of the 13 categories should have examples
|
|
26
|
+
expect(categories.size).toBeGreaterThanOrEqual(10);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have examples at all complexity levels', () => {
|
|
30
|
+
const basic = allExamples.filter((ex) => ex.complexity === 'basic');
|
|
31
|
+
const intermediate = allExamples.filter((ex) => ex.complexity === 'intermediate');
|
|
32
|
+
const advanced = allExamples.filter((ex) => ex.complexity === 'advanced');
|
|
33
|
+
|
|
34
|
+
expect(basic.length).toBeGreaterThan(0);
|
|
35
|
+
expect(intermediate.length).toBeGreaterThan(0);
|
|
36
|
+
expect(advanced.length).toBeGreaterThan(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Validate every example parses without fatal errors
|
|
40
|
+
describe('parse validation', () => {
|
|
41
|
+
for (const example of allExamples) {
|
|
42
|
+
it(`[${example.id}] ${example.description} — should parse without errors`, () => {
|
|
43
|
+
expect(example.holoScript).toBeTruthy();
|
|
44
|
+
expect(example.holoScript.length).toBeGreaterThan(10);
|
|
45
|
+
|
|
46
|
+
const result = parser.parse(example.holoScript);
|
|
47
|
+
|
|
48
|
+
// Parser should NOT throw. Warnings are OK, fatal errors are not.
|
|
49
|
+
// We check that at least one AST node was produced.
|
|
50
|
+
expect(result).toBeDefined();
|
|
51
|
+
if (result.errors && result.errors.length > 0) {
|
|
52
|
+
// If there are errors, they should only be non-fatal (warnings)
|
|
53
|
+
const fatalErrors = result.errors.filter(
|
|
54
|
+
(e: any) => !e.message.includes('warning') && !e.message.includes('Warning')
|
|
55
|
+
);
|
|
56
|
+
// Allow up to minor parse issues but flag them
|
|
57
|
+
if (fatalErrors.length > 0) {
|
|
58
|
+
console.warn(
|
|
59
|
+
`[${example.id}] Parse issues:`,
|
|
60
|
+
fatalErrors.map((e: any) => e.message)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Stats report
|
|
69
|
+
it('should report corpus metrics', () => {
|
|
70
|
+
const stats = generator.getStats();
|
|
71
|
+
const totalExamples = allExamples.length;
|
|
72
|
+
const totalChars = allExamples.reduce((sum, ex) => sum + ex.holoScript.length, 0);
|
|
73
|
+
const avgLength = Math.round(totalChars / totalExamples);
|
|
74
|
+
|
|
75
|
+
console.log('\n=== Training Corpus Metrics ===');
|
|
76
|
+
console.log(`Total examples: ${totalExamples}`);
|
|
77
|
+
console.log(`Total characters: ${totalChars.toLocaleString()}`);
|
|
78
|
+
console.log(`Average example length: ${avgLength} chars`);
|
|
79
|
+
console.log(`Categories: ${Object.keys(stats).length}`);
|
|
80
|
+
for (const [cat, count] of Object.entries(stats)) {
|
|
81
|
+
console.log(` ${cat}: ${count}`);
|
|
82
|
+
}
|
|
83
|
+
console.log('==============================\n');
|
|
84
|
+
|
|
85
|
+
expect(totalExamples).toBeGreaterThan(0);
|
|
86
|
+
});
|
|
87
|
+
});
|