Repository navigation
Expand file tree
/
Copy pathkernel_workflow_bmk.js
More file actions
64 lines (59 loc) · 3.09 KB
/
Copy pathkernel_workflow_bmk.js
File metadata and controls
64 lines (59 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Orchestrator: run kernel_workflow.js on a LIST of kernels sequentially, all pinned to ONE GPU.
// Launch one of these per GPU (4 total) for 4-way parallelism. Each kernel's kernel_workflow runs
// as a nested child workflow (its agents are subagents). Output goes to <exp_base>/<kernel_name>.
//
// args = {
// workflow_dir: "<abs path to kernel_workflow/>", // holds kernel_workflow.js + roles/ + knowledge/
// exp_base: "<abs shared exp dir>", // all kernels share this; each writes a <name>/ subdir
// gpu: "0", // single GPU id this batch is pinned to
// budget: 6, // per-kernel optimization budget
// kernels: ["/abs/kernel_dir", ...] // kernel dirs to process on this GPU, in order
// }
export const meta = {
name: 'team-workflow-bmk-batch',
description: 'Run kernel_workflow on a list of kernels sequentially on one GPU (one batch per GPU).',
phases: [{ title: 'Optimize', detail: 'nested kernel_workflow per kernel, sequential on one GPU' }],
};
const A = args || {};
const WF = String(A.workflow_dir || '').replace(/\/+$/, '');
if (!WF) throw new Error('args.workflow_dir is required');
const EXP_BASE = String(A.exp_base || '').replace(/\/+$/, '');
if (!EXP_BASE) throw new Error('args.exp_base is required');
const GPU = String(A.gpu != null ? A.gpu : '0');
const BUDGET = parseInt(A.budget != null ? A.budget : 6, 10);
const TASK = A.task != null ? String(A.task) : '';
const KERNELS = Array.isArray(A.kernels) ? A.kernels : [];
if (!KERNELS.length) throw new Error('args.kernels must be a non-empty array');
// Call the single-language WORKER lane directly. kernel_workflow.js is now a dispatcher that itself
// nests into the worker; this batch orchestrator is already a top-level workflow, so routing through the
// dispatcher would be bmk -> dispatcher -> worker = 3 levels (forbidden). kernel_lane.js is the worker.
const TEAM = WF + '/kernel_lane.js';
phase('Optimize');
log(`[gpu ${GPU}] ${KERNELS.length} kernels: ${KERNELS.map(k => k.split('/').pop()).join(', ')}`);
const results = [];
for (let i = 0; i < KERNELS.length; i++) {
const k = String(KERNELS[i]).replace(/\/+$/, '');
const name = k.split('/').pop();
log(`[gpu ${GPU}] (${i + 1}/${KERNELS.length}) START ${name}`);
let res = null;
try {
res = await workflow({ scriptPath: TEAM }, {
kernel_path: k,
workflow_dir: WF,
budget: BUDGET,
gpu_ids: GPU,
eval_dir: EXP_BASE + '/' + name,
apply_to_original: 'false',
// Forward the KB switch. This arg object is explicit, so an omitted key silently takes the
// lane's ON default and a batch asked to run KB-off ran KB-on with no error.
use_learned_kb: A.use_learned_kb != null ? String(A.use_learned_kb) : 'true',
task: TASK,
});
} catch (e) {
res = { error: String(e && e.message || e) };
log(`[gpu ${GPU}] ERROR ${name}: ${res.error}`);
}
results.push({ name, eval_dir: EXP_BASE + '/' + name, result: res });
log(`[gpu ${GPU}] (${i + 1}/${KERNELS.length}) DONE ${name}`);
}
return { gpu: GPU, count: KERNELS.length, results };