textopt 0.0.0 → 0.2.0
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/README.md +65 -25
- package/dist/bootstrap-search/index.cjs +159 -73
- package/dist/bootstrap-search/index.d.cts +32 -10
- package/dist/bootstrap-search/index.d.mts +32 -10
- package/dist/bootstrap-search/index.mjs +150 -66
- package/dist/demos-9v5ts7F3.cjs +244 -0
- package/dist/{demos-B0pVQjYC.d.mts → demos-ASsSXYXA.d.mts} +10 -3
- package/dist/demos-Brobjfuc.mjs +215 -0
- package/dist/{demos-BTuzFNsp.d.cts → demos-ByaLZy-Z.d.cts} +10 -3
- package/dist/file-cache.cjs +27 -8
- package/dist/file-cache.d.cts +13 -0
- package/dist/file-cache.d.mts +13 -0
- package/dist/file-cache.mjs +27 -8
- package/dist/gepa/index.cjs +128 -80
- package/dist/gepa/index.d.cts +15 -7
- package/dist/gepa/index.d.mts +15 -7
- package/dist/gepa/index.mjs +101 -55
- package/dist/index.cjs +157 -30
- package/dist/index.d.cts +177 -7
- package/dist/index.d.mts +177 -7
- package/dist/index.mjs +139 -18
- package/dist/{math-COOofUyv.cjs → math-BhlziRPc.cjs} +60 -9
- package/dist/math-Dqme4rYz.mjs +123 -0
- package/dist/mipro/index.cjs +104 -70
- package/dist/mipro/index.d.cts +17 -14
- package/dist/mipro/index.d.mts +17 -14
- package/dist/mipro/index.mjs +90 -58
- package/dist/opro/index.cjs +136 -51
- package/dist/opro/index.d.cts +17 -9
- package/dist/opro/index.d.mts +17 -9
- package/dist/opro/index.mjs +121 -38
- package/dist/{optimizer-B7SpRwl7.d.cts → optimizer-4Zv-Zt2t.d.cts} +90 -5
- package/dist/{optimizer-DqCoth_w.d.mts → optimizer-Ds5mzYjz.d.mts} +90 -5
- package/dist/random-search/index.cjs +99 -49
- package/dist/random-search/index.d.cts +15 -13
- package/dist/random-search/index.d.mts +15 -13
- package/dist/random-search/index.mjs +89 -41
- package/dist/{reflection-Cr_upzU0.d.mts → reflection-CMezGu6u.d.mts} +38 -14
- package/dist/{reflection-CQToe-5B.d.cts → reflection-D0A7eahD.d.cts} +38 -14
- package/dist/reporting-bq007_2z.d.cts +294 -0
- package/dist/reporting-bq007_2z.d.mts +294 -0
- package/dist/simba/index.cjs +216 -83
- package/dist/simba/index.d.cts +53 -13
- package/dist/simba/index.d.mts +53 -13
- package/dist/simba/index.mjs +206 -75
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +5 -3
- package/dist/testing.d.mts +5 -3
- package/dist/testing.mjs +1 -1
- package/dist/{evaluation-OZOp6TB7.cjs → warnings-CWRJF-jA.cjs} +228 -5
- package/dist/{evaluation-BV0nSZVx.mjs → warnings-OxvDi9kN.mjs} +175 -6
- package/docs/adapters.md +169 -0
- package/docs/benchmark.md +90 -0
- package/docs/data-prep.md +113 -0
- package/docs/distillation.md +128 -0
- package/docs/evaluation.md +87 -0
- package/docs/metric-preflight.md +132 -0
- package/docs/optimizers.md +293 -0
- package/docs/tuning.md +130 -0
- package/package.json +6 -4
- package/dist/demos-B9BJiNKz.cjs +0 -143
- package/dist/demos-Degx6UmP.mjs +0 -126
- package/dist/math-DhrDmpFS.mjs +0 -78
- package/dist/types-CWv4IQFF.d.cts +0 -129
- package/dist/types-CWv4IQFF.d.mts +0 -129
package/dist/mipro/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_warnings = require("../warnings-CWRJF-jA.cjs");
|
|
3
3
|
const require_concurrency = require("../concurrency-C-cFzWW2.cjs");
|
|
4
|
-
const require_math = require("../math-
|
|
5
|
-
const require_demos = require("../demos-
|
|
4
|
+
const require_math = require("../math-BhlziRPc.cjs");
|
|
5
|
+
const require_demos = require("../demos-9v5ts7F3.cjs");
|
|
6
6
|
const require_text = require("../text-CK_HB3su.cjs");
|
|
7
7
|
const require_rng = require("../rng-DbA_rPIo.cjs");
|
|
8
8
|
const require_sampling = require("../sampling-Dars7ctR.cjs");
|
|
@@ -212,10 +212,14 @@ var MiproOptimizer = class {
|
|
|
212
212
|
this.#config = config;
|
|
213
213
|
}
|
|
214
214
|
async optimize(task) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
try {
|
|
216
|
+
return await runMipro({
|
|
217
|
+
config: this.#config,
|
|
218
|
+
task
|
|
219
|
+
});
|
|
220
|
+
} finally {
|
|
221
|
+
await require_warnings.flushReporters(task.reporters ?? []);
|
|
222
|
+
}
|
|
219
223
|
}
|
|
220
224
|
};
|
|
221
225
|
function buildMiproPrompt(args) {
|
|
@@ -274,9 +278,14 @@ function buildDatasetSummaryPrompt(examples) {
|
|
|
274
278
|
async function runMipro(args) {
|
|
275
279
|
const { config, task } = args;
|
|
276
280
|
const { instructionsPerComponent = DEFAULT_INSTRUCTIONS, minibatchSize = DEFAULT_MINIBATCH_SIZE, maxTrials = DEFAULT_MAX_TRIALS, startupTrials, gamma, surrogateSamples, multivariate, fullEvalInterval = DEFAULT_FULL_EVAL_INTERVAL, demoSets = DEFAULT_DEMO_SETS, maxDemos = DEFAULT_MAX_DEMOS, demoMinScore, exemplars = DEFAULT_EXEMPLARS, datasetSummary = true, summaryExamples = DEFAULT_SUMMARY_EXAMPLES, concurrency = 1, seed = 0, buildPrompt = buildMiproPrompt, tips = DEFAULT_TIPS, trackBestOutputs = false, checkpointCache = true } = config;
|
|
277
|
-
const { seedCandidate, trainingSet, validationSet
|
|
278
|
-
const
|
|
279
|
-
|
|
281
|
+
const { seedCandidate, trainingSet, validationSet: requestedValidationSet, testSet, adapter, reflect, componentOptions, demoComponents, renderDemo, goldOutput, maxMetricCalls, renderDatum = renderDefault, batchSampler = require_sampling.createEpochShuffledSampler({ minibatchSize }), cache, cacheNamespace, retry, maxCostUsd, maxWallClockMs, instanceId = require_warnings.defaultInstanceId, reporters = [], onCheckpoint, resumeFrom, signal } = task;
|
|
282
|
+
const { validationSet, warnings } = require_warnings.resolveValidationSet({
|
|
283
|
+
validationSet: requestedValidationSet,
|
|
284
|
+
trainingSet
|
|
285
|
+
});
|
|
286
|
+
const emit = require_warnings.createEmitter(reporters);
|
|
287
|
+
const deadline = require_warnings.createDeadline({ maxWallClockMs });
|
|
288
|
+
const components = require_warnings.componentNames(seedCandidate);
|
|
280
289
|
if (trainingSet.length === 0) throw new Error("optimize requires a non-empty trainingSet");
|
|
281
290
|
if (validationSet.length === 0) throw new Error("optimize requires a non-empty validationSet");
|
|
282
291
|
if (components.length === 0) throw new Error("optimize requires a seed candidate with at least one component");
|
|
@@ -294,24 +303,24 @@ async function runMipro(args) {
|
|
|
294
303
|
datum,
|
|
295
304
|
index
|
|
296
305
|
})) ?? [];
|
|
297
|
-
const fingerprint =
|
|
306
|
+
const fingerprint = require_warnings.runFingerprint({
|
|
298
307
|
seedCandidate,
|
|
299
308
|
trainingIds,
|
|
300
309
|
validationIds,
|
|
301
310
|
seed,
|
|
302
311
|
...cacheNamespace === void 0 ? {} : { cacheNamespace }
|
|
303
312
|
});
|
|
304
|
-
|
|
313
|
+
require_warnings.assertResumable({
|
|
305
314
|
fingerprint,
|
|
306
315
|
...resumeFrom === void 0 ? {} : { snapshot: resumeFrom }
|
|
307
316
|
});
|
|
308
317
|
const rng = require_rng.createSeededRng(seed, resumeFrom?.rngState);
|
|
309
|
-
const budget =
|
|
318
|
+
const budget = require_warnings.createBudget({
|
|
310
319
|
maxMetricCalls,
|
|
311
320
|
spent: resumeFrom?.metricCalls ?? 0
|
|
312
321
|
});
|
|
313
|
-
const evaluationCache = cache === false ? void 0 : cache ??
|
|
314
|
-
const evaluator =
|
|
322
|
+
const evaluationCache = cache === false ? void 0 : cache ?? require_warnings.createMemoryCache();
|
|
323
|
+
const evaluator = require_warnings.createEvaluator({
|
|
315
324
|
adapter,
|
|
316
325
|
budget,
|
|
317
326
|
...retry === void 0 ? {} : { retry },
|
|
@@ -319,15 +328,16 @@ async function runMipro(args) {
|
|
|
319
328
|
...evaluationCache === void 0 ? {} : { cache: evaluationCache },
|
|
320
329
|
trackOutputs: trackBestOutputs,
|
|
321
330
|
cacheHits: resumeFrom?.cacheHits ?? 0,
|
|
331
|
+
...resumeFrom?.usage === void 0 ? {} : { usage: resumeFrom.usage },
|
|
322
332
|
...signal === void 0 ? {} : { signal },
|
|
323
|
-
onEvaluation: (event) =>
|
|
333
|
+
onEvaluation: (event) => emit({
|
|
324
334
|
type: "evaluation",
|
|
325
335
|
...event
|
|
326
336
|
})
|
|
327
337
|
});
|
|
328
338
|
evaluator.restore(resumeFrom?.cache ?? []);
|
|
329
339
|
if (resumeFrom?.sampler !== void 0) batchSampler.restore?.(resumeFrom.sampler);
|
|
330
|
-
|
|
340
|
+
emit({
|
|
331
341
|
type: "start",
|
|
332
342
|
components,
|
|
333
343
|
validationSetSize: validationSet.length
|
|
@@ -374,20 +384,26 @@ async function runMipro(args) {
|
|
|
374
384
|
for (let index = 0; index < demoSets; index += 1) {
|
|
375
385
|
const affordable = Math.min(trainingSet.length, budget.remaining() - validationSet.length);
|
|
376
386
|
if (affordable < 1) break;
|
|
387
|
+
if (require_warnings.costExhausted({
|
|
388
|
+
usage: evaluator.usage(),
|
|
389
|
+
maxCostUsd
|
|
390
|
+
})) break;
|
|
377
391
|
const requested = demoSets === 1 ? maxDemos : Math.round(1 + index * (maxDemos - 1) / (demoSets - 1));
|
|
378
|
-
const harvest = await require_demos.
|
|
392
|
+
const harvest = await require_demos.harvestFewShotExamples({
|
|
379
393
|
adapter,
|
|
380
394
|
candidate: seedCandidate,
|
|
381
395
|
trainingSet,
|
|
382
396
|
...demoMinScore === void 0 ? {} : { minScore: demoMinScore },
|
|
383
397
|
maxDemos: requested,
|
|
384
398
|
maxMetricCalls: affordable,
|
|
399
|
+
...maxCostUsd === void 0 ? {} : { maxCostUsd: maxCostUsd - evaluator.usage().costUsd },
|
|
385
400
|
rng,
|
|
386
401
|
...renderDemo === void 0 ? {} : { renderDemo },
|
|
387
402
|
...signal === void 0 ? {} : { signal }
|
|
388
403
|
});
|
|
389
404
|
bootstrapMetricCalls += harvest.metricCalls;
|
|
390
405
|
budget.reserve(harvest.metricCalls);
|
|
406
|
+
evaluator.absorbUsage(harvest.usage);
|
|
391
407
|
if (harvest.demos.length > 0) blocks.push(require_demos.formatDemos(harvest.demos, renderDemo === void 0 ? {} : { render: renderDemo }));
|
|
392
408
|
}
|
|
393
409
|
return [.../* @__PURE__ */ new Set([
|
|
@@ -432,7 +448,7 @@ async function runMipro(args) {
|
|
|
432
448
|
});
|
|
433
449
|
menu[name] = [seedCandidate[name], ...drawn.filter((text) => text.length > 0)];
|
|
434
450
|
}
|
|
435
|
-
|
|
451
|
+
emit({
|
|
436
452
|
type: "menu",
|
|
437
453
|
menu,
|
|
438
454
|
reflectionCalls
|
|
@@ -462,11 +478,20 @@ async function runMipro(args) {
|
|
|
462
478
|
});
|
|
463
479
|
}
|
|
464
480
|
const seedEvaluation = resumeFrom === void 0 ? await fullSweep(seedCandidate, "seed") : void 0;
|
|
465
|
-
const seedScore = seedEvaluation === void 0 ? resumeFrom.seedScore :
|
|
481
|
+
const seedScore = seedEvaluation === void 0 ? resumeFrom.seedScore : require_warnings.requireMeasuredMean({
|
|
466
482
|
batch: seedEvaluation,
|
|
467
483
|
phase: "seed"
|
|
468
484
|
});
|
|
469
485
|
if (seedEvaluation !== void 0) fullEvaluations += 1;
|
|
486
|
+
if (seedEvaluation !== void 0) emit({
|
|
487
|
+
type: "candidateAccepted",
|
|
488
|
+
trial: 0,
|
|
489
|
+
candidateId: 0,
|
|
490
|
+
candidate: seedCandidate,
|
|
491
|
+
aggregateScore: seedScore,
|
|
492
|
+
instanceScores: require_warnings.instanceRow(seedEvaluation),
|
|
493
|
+
...trackBestOutputs ? { outputs: seedEvaluation.outputs } : {}
|
|
494
|
+
});
|
|
470
495
|
if (resumeFrom === void 0) surrogateInput.push({
|
|
471
496
|
choices: menuSizes.map(() => 0),
|
|
472
497
|
score: seedScore
|
|
@@ -474,6 +499,7 @@ async function runMipro(args) {
|
|
|
474
499
|
let best = resumeFrom?.best ?? seedCandidate;
|
|
475
500
|
let bestScore = resumeFrom?.bestScore ?? seedScore;
|
|
476
501
|
/** Absent on a resumed run until a sweep wins: outputs are not checkpointed. */
|
|
502
|
+
let acceptedCandidates = resumeFrom?.acceptedCandidates ?? 0;
|
|
477
503
|
let bestOutputs = seedEvaluation?.outputs;
|
|
478
504
|
const readings = new Map(resumeFrom?.readings ?? []);
|
|
479
505
|
const swept = new Set(resumeFrom?.swept ?? []);
|
|
@@ -493,6 +519,8 @@ async function runMipro(args) {
|
|
|
493
519
|
bootstrapMetricCalls,
|
|
494
520
|
metricCalls: budget.spent(),
|
|
495
521
|
cacheHits: evaluator.cacheHits(),
|
|
522
|
+
usage: evaluator.usage(),
|
|
523
|
+
acceptedCandidates,
|
|
496
524
|
rngState: rng.state(),
|
|
497
525
|
observations: [...observations],
|
|
498
526
|
surrogateInput: surrogateInput.map((entry) => ({
|
|
@@ -535,12 +563,12 @@ async function runMipro(args) {
|
|
|
535
563
|
try {
|
|
536
564
|
evaluation = await fullSweep(candidate, "validation");
|
|
537
565
|
} catch (err) {
|
|
538
|
-
if (err instanceof
|
|
566
|
+
if (err instanceof require_warnings.BudgetExhausted) return "budgetExhausted";
|
|
539
567
|
if (signal?.aborted) return "aborted";
|
|
540
568
|
throw err;
|
|
541
569
|
}
|
|
542
570
|
fullEvaluations += 1;
|
|
543
|
-
const score =
|
|
571
|
+
const score = require_warnings.measuredMean(evaluation);
|
|
544
572
|
if (score === void 0) return "swept";
|
|
545
573
|
surrogateInput.push({
|
|
546
574
|
choices,
|
|
@@ -554,11 +582,15 @@ async function runMipro(args) {
|
|
|
554
582
|
best = candidate;
|
|
555
583
|
bestScore = score;
|
|
556
584
|
bestOutputs = evaluation.outputs;
|
|
557
|
-
|
|
558
|
-
|
|
585
|
+
acceptedCandidates += 1;
|
|
586
|
+
emit({
|
|
587
|
+
type: "candidateAccepted",
|
|
559
588
|
trial,
|
|
560
|
-
|
|
561
|
-
|
|
589
|
+
candidateId: acceptedCandidates,
|
|
590
|
+
candidate,
|
|
591
|
+
aggregateScore: score,
|
|
592
|
+
instanceScores: require_warnings.instanceRow(evaluation),
|
|
593
|
+
...trackBestOutputs ? { outputs: evaluation.outputs } : {}
|
|
562
594
|
});
|
|
563
595
|
}
|
|
564
596
|
return "swept";
|
|
@@ -568,7 +600,7 @@ async function runMipro(args) {
|
|
|
568
600
|
stopReason = "aborted";
|
|
569
601
|
break;
|
|
570
602
|
}
|
|
571
|
-
if (
|
|
603
|
+
if (require_warnings.costExhausted({
|
|
572
604
|
usage: evaluator.usage(),
|
|
573
605
|
maxCostUsd
|
|
574
606
|
})) {
|
|
@@ -613,9 +645,9 @@ async function runMipro(args) {
|
|
|
613
645
|
candidateId: null,
|
|
614
646
|
iteration: trial
|
|
615
647
|
});
|
|
616
|
-
minibatchScore =
|
|
648
|
+
minibatchScore = require_warnings.measuredMean(evaluation);
|
|
617
649
|
} catch (err) {
|
|
618
|
-
if (err instanceof
|
|
650
|
+
if (err instanceof require_warnings.BudgetExhausted) {
|
|
619
651
|
stopReason = "budgetExhausted";
|
|
620
652
|
break;
|
|
621
653
|
}
|
|
@@ -625,47 +657,44 @@ async function runMipro(args) {
|
|
|
625
657
|
}
|
|
626
658
|
throw err;
|
|
627
659
|
}
|
|
628
|
-
if (minibatchScore
|
|
629
|
-
|
|
630
|
-
|
|
660
|
+
if (minibatchScore !== void 0) {
|
|
661
|
+
surrogateInput.push({
|
|
662
|
+
choices,
|
|
663
|
+
score: minibatchScore
|
|
664
|
+
});
|
|
665
|
+
const key = choices.join(",");
|
|
666
|
+
readings.set(key, [...readings.get(key) ?? [], minibatchScore]);
|
|
667
|
+
const observation = {
|
|
668
|
+
trial,
|
|
669
|
+
choices,
|
|
670
|
+
minibatchScore,
|
|
671
|
+
promoted: false
|
|
672
|
+
};
|
|
673
|
+
observations.push(observation);
|
|
674
|
+
emit({
|
|
675
|
+
type: "trial",
|
|
676
|
+
trial,
|
|
677
|
+
choices,
|
|
678
|
+
minibatchScore,
|
|
679
|
+
promoted: false
|
|
680
|
+
});
|
|
631
681
|
}
|
|
632
|
-
surrogateInput.push({
|
|
633
|
-
choices,
|
|
634
|
-
score: minibatchScore
|
|
635
|
-
});
|
|
636
|
-
const key = choices.join(",");
|
|
637
|
-
readings.set(key, [...readings.get(key) ?? [], minibatchScore]);
|
|
638
|
-
const observation = {
|
|
639
|
-
trial,
|
|
640
|
-
choices,
|
|
641
|
-
minibatchScore,
|
|
642
|
-
promoted: false
|
|
643
|
-
};
|
|
644
|
-
observations.push(observation);
|
|
645
|
-
onEvent?.({
|
|
646
|
-
type: "trial",
|
|
647
|
-
trial,
|
|
648
|
-
choices,
|
|
649
|
-
minibatchScore,
|
|
650
|
-
promoted: false
|
|
651
|
-
});
|
|
652
682
|
trial += 1;
|
|
653
|
-
|
|
683
|
+
let cadenceStop;
|
|
654
684
|
if (trial % fullEvalInterval === 0) {
|
|
655
685
|
const outcome = await sweepBestUnswept();
|
|
656
|
-
if (outcome === "budgetExhausted" || outcome === "aborted")
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
686
|
+
if (outcome === "budgetExhausted" || outcome === "aborted") cadenceStop = outcome;
|
|
687
|
+
if (outcome === "unaffordable") cadenceStop = "budgetExhausted";
|
|
688
|
+
}
|
|
689
|
+
await checkpoint();
|
|
690
|
+
if (cadenceStop !== void 0) {
|
|
691
|
+
stopReason = cadenceStop;
|
|
692
|
+
break;
|
|
664
693
|
}
|
|
665
694
|
}
|
|
666
695
|
if (stopReason === "maxTrials" && !signal?.aborted) await sweepBestUnswept();
|
|
667
696
|
if (signal?.aborted) stopReason = "aborted";
|
|
668
|
-
const
|
|
697
|
+
const heldOut = testSet === void 0 ? void 0 : await evaluator.evaluate({
|
|
669
698
|
candidate: best,
|
|
670
699
|
batch: testSet,
|
|
671
700
|
ids: testIds,
|
|
@@ -674,13 +703,18 @@ async function runMipro(args) {
|
|
|
674
703
|
candidateId: null,
|
|
675
704
|
iteration: trial,
|
|
676
705
|
charge: false
|
|
677
|
-
})
|
|
678
|
-
|
|
706
|
+
});
|
|
707
|
+
const testScore = heldOut === void 0 ? void 0 : require_warnings.measuredMean(heldOut);
|
|
708
|
+
emit({
|
|
679
709
|
type: "finish",
|
|
680
710
|
reason: stopReason,
|
|
711
|
+
warnings,
|
|
712
|
+
bestCandidateId: acceptedCandidates,
|
|
681
713
|
bestScore,
|
|
682
714
|
metricCalls: budget.spent(),
|
|
683
|
-
...testScore === void 0 ? {} : { testScore }
|
|
715
|
+
...testScore === void 0 ? {} : { testScore },
|
|
716
|
+
...heldOut === void 0 ? {} : { testInstanceScores: require_warnings.instanceRow(heldOut) },
|
|
717
|
+
...heldOut === void 0 || !trackBestOutputs ? {} : { testOutputs: heldOut.outputs }
|
|
684
718
|
});
|
|
685
719
|
return {
|
|
686
720
|
snapshot: takeSnapshot(),
|
|
@@ -691,7 +725,8 @@ async function runMipro(args) {
|
|
|
691
725
|
...trackBestOutputs ? { bestOutputs } : {},
|
|
692
726
|
...testScore === void 0 ? {} : {
|
|
693
727
|
testScore,
|
|
694
|
-
testMetricCalls: evaluator.unchargedCalls()
|
|
728
|
+
testMetricCalls: evaluator.unchargedCalls(),
|
|
729
|
+
testUsage: evaluator.unchargedUsage()
|
|
695
730
|
},
|
|
696
731
|
trials: trial,
|
|
697
732
|
menu,
|
|
@@ -701,6 +736,7 @@ async function runMipro(args) {
|
|
|
701
736
|
metricCalls: budget.spent(),
|
|
702
737
|
reflectionCalls,
|
|
703
738
|
cacheHits: evaluator.cacheHits(),
|
|
739
|
+
warnings,
|
|
704
740
|
stopReason
|
|
705
741
|
};
|
|
706
742
|
}
|
|
@@ -729,11 +765,9 @@ function assertConfig(config) {
|
|
|
729
765
|
if (config.gamma !== void 0 && (!Number.isFinite(config.gamma) || config.gamma <= 0 || config.gamma > 1)) throw new Error(`gamma must be within (0, 1], received ${config.gamma}`);
|
|
730
766
|
if (config.tips !== void 0 && config.tips.length === 0) throw new Error("tips must not be empty");
|
|
731
767
|
}
|
|
732
|
-
function defaultInstanceId(args) {
|
|
733
|
-
const hash = require_evaluation.stableHash(args.datum);
|
|
734
|
-
return hash === "" ? String(args.index) : hash;
|
|
735
|
-
}
|
|
736
768
|
//#endregion
|
|
737
769
|
exports.MiproOptimizer = MiproOptimizer;
|
|
738
770
|
exports.buildMiproPrompt = buildMiproPrompt;
|
|
771
|
+
exports.isCandidateAccepted = require_warnings.isCandidateAccepted;
|
|
772
|
+
exports.isRunFinished = require_warnings.isRunFinished;
|
|
739
773
|
exports.proposeConfiguration = proposeConfiguration;
|
package/dist/mipro/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as Candidate, t as
|
|
1
|
+
import { S as UsageTotals, a as RunFinished, f as Adapter, i as Reporter, n as OptimizerEvent, o as isCandidateAccepted, p as Candidate, r as ReportableEvent, s as isRunFinished, t as CandidateAccepted, x as TextModel } from "../reporting-bq007_2z.cjs";
|
|
2
2
|
import { n as EvaluationCache, t as CachedScore } from "../cache-CuSo0NJ8.cjs";
|
|
3
3
|
import { t as Rng } from "../rng-BR5MOedA.cjs";
|
|
4
|
-
import { r as DemoRenderer } from "../demos-
|
|
5
|
-
import { n as OptimizerResult, r as OptimizerTask, s as EvaluationEvent, t as Optimizer } from "../optimizer-
|
|
4
|
+
import { r as DemoRenderer } from "../demos-ByaLZy-Z.cjs";
|
|
5
|
+
import { n as OptimizerResult, r as OptimizerTask, s as EvaluationEvent, t as Optimizer } from "../optimizer-4Zv-Zt2t.cjs";
|
|
6
6
|
import { t as BatchSampler } from "../sampling-axOwfZf5.cjs";
|
|
7
7
|
//#region src/mipro/optimize.d.ts
|
|
8
8
|
type MiproPromptBuilder = (args: {
|
|
@@ -131,6 +131,13 @@ interface MiproSnapshot {
|
|
|
131
131
|
bootstrapMetricCalls: number;
|
|
132
132
|
metricCalls: number;
|
|
133
133
|
cacheHits: number;
|
|
134
|
+
/** Usage already spent, so a resumed run reports totals and honours ceilings. */
|
|
135
|
+
usage?: UsageTotals;
|
|
136
|
+
/**
|
|
137
|
+
* Candidates accepted so far. Reporters key rows by this id, so restarting it
|
|
138
|
+
* at zero makes a resumed run collide with the run it continues.
|
|
139
|
+
*/
|
|
140
|
+
acceptedCandidates?: number;
|
|
134
141
|
rngState: number;
|
|
135
142
|
observations: MiproObservation[];
|
|
136
143
|
/** What the surrogate was fitted on: one entry per measured trial. */
|
|
@@ -187,7 +194,8 @@ interface MiproTask<Datum, Trajectory = unknown, Output = unknown, K extends str
|
|
|
187
194
|
}) => string;
|
|
188
195
|
/** Pass `false` to disable caching entirely. */
|
|
189
196
|
cache?: EvaluationCache | false;
|
|
190
|
-
|
|
197
|
+
/** Observers of the run. Every one sees every event; none can fail it. */
|
|
198
|
+
reporters?: readonly Reporter<MiproEvent<NoInfer<K>>>[];
|
|
191
199
|
/**
|
|
192
200
|
* Called with a resumable snapshot once the menus are built and after every
|
|
193
201
|
* trial. Persist it and a killed run costs the last trial, not the menus.
|
|
@@ -214,18 +222,13 @@ type MiproEvent<K extends string = string> = {
|
|
|
214
222
|
minibatchScore: number;
|
|
215
223
|
/** True when the trial earned a full validation sweep. */
|
|
216
224
|
promoted: boolean;
|
|
217
|
-
} | {
|
|
218
|
-
type: "
|
|
225
|
+
} | ({
|
|
226
|
+
type: "candidateAccepted";
|
|
219
227
|
trial: number;
|
|
220
|
-
|
|
221
|
-
score: number;
|
|
222
|
-
} | {
|
|
228
|
+
} & CandidateAccepted<K>) | ({
|
|
223
229
|
type: "finish";
|
|
224
230
|
reason: MiproStopReason;
|
|
225
|
-
|
|
226
|
-
metricCalls: number;
|
|
227
|
-
testScore?: number;
|
|
228
|
-
};
|
|
231
|
+
} & RunFinished);
|
|
229
232
|
interface MiproObservation {
|
|
230
233
|
trial: number;
|
|
231
234
|
choices: number[];
|
|
@@ -369,4 +372,4 @@ declare function proposeConfiguration(args: {
|
|
|
369
372
|
rng: Rng;
|
|
370
373
|
}): number[];
|
|
371
374
|
//#endregion
|
|
372
|
-
export { type MiproConfig, type MiproEvent, type MiproObservation, MiproOptimizer, type MiproPromptBuilder, type MiproResult, type MiproSnapshot, type MiproStopReason, type MiproTask, type Observation, buildMiproPrompt, proposeConfiguration };
|
|
375
|
+
export { type CandidateAccepted, type MiproConfig, type MiproEvent, type MiproObservation, MiproOptimizer, type MiproPromptBuilder, type MiproResult, type MiproSnapshot, type MiproStopReason, type MiproTask, type Observation, type OptimizerEvent, type ReportableEvent, type Reporter, type RunFinished, buildMiproPrompt, isCandidateAccepted, isRunFinished, proposeConfiguration };
|
package/dist/mipro/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as Candidate, t as
|
|
1
|
+
import { S as UsageTotals, a as RunFinished, f as Adapter, i as Reporter, n as OptimizerEvent, o as isCandidateAccepted, p as Candidate, r as ReportableEvent, s as isRunFinished, t as CandidateAccepted, x as TextModel } from "../reporting-bq007_2z.mjs";
|
|
2
2
|
import { n as EvaluationCache, t as CachedScore } from "../cache-CuSo0NJ8.mjs";
|
|
3
3
|
import { t as Rng } from "../rng-BR5MOedA.mjs";
|
|
4
|
-
import { r as DemoRenderer } from "../demos-
|
|
5
|
-
import { n as OptimizerResult, r as OptimizerTask, s as EvaluationEvent, t as Optimizer } from "../optimizer-
|
|
4
|
+
import { r as DemoRenderer } from "../demos-ASsSXYXA.mjs";
|
|
5
|
+
import { n as OptimizerResult, r as OptimizerTask, s as EvaluationEvent, t as Optimizer } from "../optimizer-Ds5mzYjz.mjs";
|
|
6
6
|
import { t as BatchSampler } from "../sampling-DFo_7RNJ.mjs";
|
|
7
7
|
//#region src/mipro/optimize.d.ts
|
|
8
8
|
type MiproPromptBuilder = (args: {
|
|
@@ -131,6 +131,13 @@ interface MiproSnapshot {
|
|
|
131
131
|
bootstrapMetricCalls: number;
|
|
132
132
|
metricCalls: number;
|
|
133
133
|
cacheHits: number;
|
|
134
|
+
/** Usage already spent, so a resumed run reports totals and honours ceilings. */
|
|
135
|
+
usage?: UsageTotals;
|
|
136
|
+
/**
|
|
137
|
+
* Candidates accepted so far. Reporters key rows by this id, so restarting it
|
|
138
|
+
* at zero makes a resumed run collide with the run it continues.
|
|
139
|
+
*/
|
|
140
|
+
acceptedCandidates?: number;
|
|
134
141
|
rngState: number;
|
|
135
142
|
observations: MiproObservation[];
|
|
136
143
|
/** What the surrogate was fitted on: one entry per measured trial. */
|
|
@@ -187,7 +194,8 @@ interface MiproTask<Datum, Trajectory = unknown, Output = unknown, K extends str
|
|
|
187
194
|
}) => string;
|
|
188
195
|
/** Pass `false` to disable caching entirely. */
|
|
189
196
|
cache?: EvaluationCache | false;
|
|
190
|
-
|
|
197
|
+
/** Observers of the run. Every one sees every event; none can fail it. */
|
|
198
|
+
reporters?: readonly Reporter<MiproEvent<NoInfer<K>>>[];
|
|
191
199
|
/**
|
|
192
200
|
* Called with a resumable snapshot once the menus are built and after every
|
|
193
201
|
* trial. Persist it and a killed run costs the last trial, not the menus.
|
|
@@ -214,18 +222,13 @@ type MiproEvent<K extends string = string> = {
|
|
|
214
222
|
minibatchScore: number;
|
|
215
223
|
/** True when the trial earned a full validation sweep. */
|
|
216
224
|
promoted: boolean;
|
|
217
|
-
} | {
|
|
218
|
-
type: "
|
|
225
|
+
} | ({
|
|
226
|
+
type: "candidateAccepted";
|
|
219
227
|
trial: number;
|
|
220
|
-
|
|
221
|
-
score: number;
|
|
222
|
-
} | {
|
|
228
|
+
} & CandidateAccepted<K>) | ({
|
|
223
229
|
type: "finish";
|
|
224
230
|
reason: MiproStopReason;
|
|
225
|
-
|
|
226
|
-
metricCalls: number;
|
|
227
|
-
testScore?: number;
|
|
228
|
-
};
|
|
231
|
+
} & RunFinished);
|
|
229
232
|
interface MiproObservation {
|
|
230
233
|
trial: number;
|
|
231
234
|
choices: number[];
|
|
@@ -369,4 +372,4 @@ declare function proposeConfiguration(args: {
|
|
|
369
372
|
rng: Rng;
|
|
370
373
|
}): number[];
|
|
371
374
|
//#endregion
|
|
372
|
-
export { type MiproConfig, type MiproEvent, type MiproObservation, MiproOptimizer, type MiproPromptBuilder, type MiproResult, type MiproSnapshot, type MiproStopReason, type MiproTask, type Observation, buildMiproPrompt, proposeConfiguration };
|
|
375
|
+
export { type CandidateAccepted, type MiproConfig, type MiproEvent, type MiproObservation, MiproOptimizer, type MiproPromptBuilder, type MiproResult, type MiproSnapshot, type MiproStopReason, type MiproTask, type Observation, type OptimizerEvent, type ReportableEvent, type Reporter, type RunFinished, buildMiproPrompt, isCandidateAccepted, isRunFinished, proposeConfiguration };
|