dacorvo's picture
dacorvo HF Staff
Upload folder using huggingface_hub
507abef verified
Raw History Blame Contribute Delete
28.6 kB
// Lists the support results of the aws-neuron/torch-neuronx-model-support
// dataset, one tab per library, 100 models per page: for the models the latest
// sweep selected, or for the Hub's models by trending score or downloads. A last
// tab shows the status of the sweep of each pod to the members of aws-neuron who
// sign in.
import { parquetReadObjects } from "https://cdn.jsdelivr.net/npm/hyparquet@1.31.2/src/index.js";
const HUB = "https://huggingface.co";
// ?branch=<name> shows what a checkout of that branch of the sweep publishes:
// the branch of that name in the test dataset. main is the public dataset.
const BRANCH = new URLSearchParams(location.search).get("branch") ?? "main";
const DATASET = BRANCH === "main" ? "aws-neuron/torch-neuronx-model-support"
: "optimum-internal-testing/torch-neuronx-model-support";
const NEFF_CACHE = "hf://buckets/aws-neuron/torch-neuronx-neff-cache";
const LIBRARIES = ["transformers", "diffusers", "sentence-transformers"];
const VIEWS = { selected: "Selected", trending: "Trending", downloads: "Downloads" };
// The task Trending and Downloads open on, by library: all tasks would open on models the sweep never tests.
const DEFAULT_TASKS = { transformers: "text-generation", diffusers: "text-to-image" };
// The Hub's sort, and model field, of each view but "selected".
const HUB_SORTS = { trending: "trendingScore", downloads: "downloads" };
const PAGE = 100;
// The test instances: 4 devices of their target, with the HBM of one device.
const DEVICES = 4;
const TARGETS = {
trn2: { name: "Trainium2", deviceHbm: 96 * 1024 ** 3 },
trn3: { name: "Trainium3", deviceHbm: 144 * 1024 ** 3 },
};
const COLUMNS = ["model_id", "cores", "result", "Memory (GB)", "notes"];
const TOOLTIPS = {
"Memory (GB)": "The run's peak device memory (HBM), summed over its NeuronCores,"
+ " out of the HBM of those NeuronCores, in GiB",
};
// The status of the sweep of each pod, which it writes every minute to a private
// bucket of aws-neuron, one file per host: only the members of the organization
// can read it, once signed in.
const STATUS_TAB = "Sweep status";
const STATUS_BUCKET = "aws-neuron/torch-neuronx-sweep-status";
const AWS_NEURON_ID = "6438282a1ee0e43f14d82144";
const HUB_JS = "https://cdn.jsdelivr.net/npm/@huggingface/hub@2.17.10/+esm";
const SIGN_IN = "sweep-status:sign-in";
const STATUS_REFRESH = 60 * 1000;
// A scheduled sweep whose status is older stopped writing it.
const STALE = 5 * 60 * 1000;
// A pod that has not written its status for longer is gone, or paused that long.
const GONE = 24 * 60 * 60 * 1000;
// An element with attributes and children. Strings become text nodes, never HTML.
function h(tag, attrs = {}, ...children) {
const el = document.createElement(tag);
for (const [key, value] of Object.entries(attrs)) {
if (key.startsWith("on")) el.addEventListener(key.slice(2), value);
else if (value === true) el.setAttribute(key, "");
else if (value !== false && value != null) el.setAttribute(key, value);
}
el.append(...children.flat(Infinity).filter((c) => c != null && c !== false));
return el;
}
const encodePath = (path) => path.split("/").map(encodeURIComponent).join("/");
async function fetchOk(url, options) {
const response = await fetch(url, options);
if (!response.ok) throw new Error(`${url}: HTTP ${response.status}`);
return response;
}
// Promises by key, dropped on failure so that the next render retries.
const cache = new Map();
function cached(key, load) {
if (!cache.has(key)) cache.set(key, load().catch((e) => { cache.delete(key); throw e; }));
return cache.get(key);
}
// The files of the dataset's branch at its latest commit: one per target and
// (neuronx-cc, library version) pair. The file of a library other than
// transformers also names the transformers version its runs pin. A file
// directly under data/ predates the target level and holds trn2 runs.
async function loadIndex() {
const info = await (await fetchOk(`${HUB}/api/datasets/${DATASET}/revision/${encodeURIComponent(BRANCH)}`)).json();
const pairs = [];
for (const { rfilename: path } of info.siblings) {
const pair = path.match(/^data\/(?:([^/]+)\/)?neuronxcc-([^/]+)\/(.+?)-([^-/]+)(?:-transformers-([^-/]+))?\.parquet$/);
if (pair) {
pairs.push({ target: pair[1] ?? "trn2", sdk: pair[2], library: pair[3], version: pair[4], transformers: pair[5], path });
}
}
return { sha: info.sha, pairs };
}
const index = await loadIndex().catch((e) => e);
const fileUrl = (path) => `${HUB}/datasets/${DATASET}/resolve/${index.sha}/${encodePath(path)}`;
// A pair's rows: its runs, the models its sweep left out, and each model's rank
// in the selection of its last sweep, best-ranked first.
const loadRows = (path) => cached(path, async () => {
// The images are bytes: only the columns the file declares as strings decode as text.
const rows = await parquetReadObjects({ file: await (await fetchOk(fileUrl(path))).arrayBuffer(), utf8: false });
const ranked = rows.filter((row) => row.selection_rank != null)
.sort((a, b) => a.selection_rank - b.selection_rank);
return {
runs: rows.filter((row) => row.result !== "EXCLUDED"),
exclusions: new Map(rows.filter((row) => row.result === "EXCLUDED").map((row) => [row.model_id, row])),
selection: new Map(ranked.map((row) => [row.model_id, row.selection_rank])),
};
});
// A model's task on the Hub, or "unknown" if the Hub no longer has it.
const loadTask = (id) => cached(`task:${id}`, async () => {
const query = new URLSearchParams({ "expand[]": "pipeline_tag" });
const response = await fetch(`${HUB}/api/models/${encodePath(id)}?${query}`);
if (response.status === 404) return "unknown";
if (!response.ok) throw new Error(`${id}: HTTP ${response.status}`);
return (await response.json()).pipeline_tag ?? "unknown";
}).catch(() => "unknown");
// The models of a library, of a task unless it is null, and whose id contains
// `name` unless it is empty, in the order of the Hub's model list, with their
// parameter count when the Hub knows it: at least `count` of them, or all if it
// has fewer. `next` is the Hub's link to the models after them, if any. The list
// grows one Hub page at a time, as deep as it was asked for.
const hubLists = new Map();
function hubList(library, task, name, view, count) {
const key = `${library}:${task}:${name}:${view}`;
const sort = HUB_SORTS[view];
if (!hubLists.has(key)) {
// The Hub's model list ignores library=. filter= lists the models with the library's tag.
const query = new URLSearchParams({ filter: library, sort, direction: "-1", limit: PAGE });
if (task) query.set("pipeline_tag", task);
if (name) query.set("search", name);
for (const field of [sort, "safetensors", "library_name"]) query.append("expand[]", field);
hubLists.set(key, { models: [], next: `${HUB}/api/models?${query}`, growing: Promise.resolve() });
}
const list = hubLists.get(key);
list.growing = list.growing.catch(() => {}).then(async () => {
while (list.models.length < count && list.next) {
const response = await fetchOk(list.next);
list.models.push(...(await response.json())
// The Hub's library filter matches a tag that models of other libraries
// carry too, such as diffusers' FLUX or sentence-transformers' MiniLM.
.filter((model) => model.library_name === library)
.map((model) => ({ id: model.id, score: model[sort] ?? 0, params: model.safetensors?.total })));
list.next = response.headers.get("Link")?.match(/<([^>]+)>;\s*rel="next"/)?.[1];
}
});
return list.growing.then(() => list);
}
// Newest first. A version that is not a release, such as a git commit pin,
// comes before the releases.
function newestFirst(a, b) {
const release = (v) => v.match(/^\d+(?:\.\d+)+/)?.[0].split(".").map(Number);
const [ra, rb] = [release(a), release(b)];
if (!ra || !rb) return Boolean(ra) - Boolean(rb) || a.localeCompare(b);
for (let i = 0; i < Math.max(ra.length, rb.length); i++) {
const d = (rb[i] ?? 0) - (ra[i] ?? 0);
if (d) return d;
}
// A pre-release, such as 5.21.0rc1, is older than its release.
const pre = (v) => /^\d+(?:\.\d+)+(?:a|b|rc|\.?dev)/.test(v);
return pre(a) - pre(b);
}
const badge = (result) => `${result === "PASS" ? "✅" : "❌"} ${result}`;
const memory = (run) => run.hbm_peak_gb == null ? ""
: `${run.hbm_peak_gb.toFixed(2)} / ${Number(run.hbm_capacity_gb.toFixed(1))}`;
const day = (date) => new Date(date).toISOString().slice(0, 10);
const tabs = document.getElementById("tabs");
const panel = document.getElementById("panel");
const dialog = document.getElementById("run");
const state = new Map(LIBRARIES.map((library) =>
[library, { view: "selected", target: null, sdk: null, version: null, tasks: {}, names: {}, page: 1 }]));
let active = LIBRARIES[0];
let rendering = 0;
// The pending list render of the name being typed.
let typing;
function renderTabs() {
tabs.replaceChildren(...[...LIBRARIES, STATUS_TAB].map((tab) => h("button", {
role: "tab",
"aria-selected": String(tab === active),
onclick: () => { active = tab; renderTabs(); renderPanel(); },
}, tab)));
}
async function renderPanel() {
const render = ++rendering;
clearTimeout(typing);
if (active === STATUS_TAB) {
renderStatus(render);
return;
}
if (index instanceof Error) {
panel.replaceChildren(h("p", { class: "status" }, `Could not read the dataset: ${index.message}`));
return;
}
const all = index.pairs.filter((p) => p.library === active);
if (!all.length) {
panel.replaceChildren(h("p", { class: "status" }, "No records yet."));
return;
}
const s = state.get(active);
// Each target has its own sweeps, so its own selection, compilers and library versions.
const targets = [...new Set(all.map((p) => p.target))].sort();
if (!targets.includes(s.target)) s.target = targets[0];
const pairs = all.filter((p) => p.target === s.target);
const sdks = [...new Set(pairs.map((p) => p.sdk))].sort(newestFirst);
const versionLabel = (p) => p.transformers ? `${p.version} · transformers ${p.transformers}` : p.version;
const versionsOf = (sdk) => pairs.filter((p) => p.sdk === sdk)
.sort((a, b) => newestFirst(a.version, b.version) || newestFirst(a.transformers ?? "", b.transformers ?? ""))
.map(versionLabel);
// The latest selection was swept with the newest library version of the newest compiler.
const latest = { sdk: sdks[0], version: versionsOf(sdks[0])[0] };
if (!sdks.includes(s.sdk)) s.sdk = latest.sdk;
if (!versionsOf(s.sdk).includes(s.version)) s.version = versionsOf(s.sdk)[0];
const selected = s.view === "selected";
const shown = selected ? latest : { sdk: s.sdk, version: s.version };
const pathOf = ({ sdk, version }) => pairs.find((p) => p.sdk === sdk && versionLabel(p) === version).path;
const select = (label, key, options, onchange) => h("label", {}, label, h("select", {
onchange: (e) => { s[key] = e.target.value; s.page = 1; onchange?.(); renderPanel(); },
}, options.map((o) => h("option", { value: o, selected: o === s[key] }, o))));
const tasks = h("div", { class: "tasks", role: "group", "aria-label": "Task" }, h("span", {}, "Task"));
const results = h("div", { class: "results" }, h("p", { class: "status" }, "Loading…"));
// Typing renders the list again, not the panel, which would take the focus away.
let renderResults;
const nameField = h("label", {}, "Name", h("input", {
type: "search",
placeholder: "Filter by name",
value: s.names[s.view] ?? "",
oninput: (e) => {
s.names[s.view] = e.target.value.trim();
s.page = 1;
clearTimeout(typing);
typing = setTimeout(() => renderResults?.(), 300);
},
}));
const instance = select("Instance", "target", targets, () => { s.sdk = null; s.version = null; });
panel.replaceChildren(
h("div", { class: "views", role: "tablist" }, Object.entries(VIEWS).map(([view, label]) => h("button", {
role: "tab",
"aria-selected": String(view === s.view),
onclick: () => { s.view = view; s.page = 1; renderPanel(); },
}, label))),
selected
? h("div", { class: "controls" }, instance)
: h("div", { class: "controls" },
instance,
select("SDK (neuronx-cc)", "sdk", sdks, () => { s.version = null; }),
select(active, "version", versionsOf(s.sdk)),
nameField),
...(selected ? [h("p", { class: "pair" }, `neuronx-cc ${latest.sdk} · ${active} ${latest.version}`)] : [tasks]),
results);
let runs, rank, exclusions, taskList;
try {
let latestRows;
[{ runs, exclusions }, latestRows] = await Promise.all([loadRows(pathOf(shown)), loadRows(pathOf(latest))]);
rank = latestRows.selection;
if (!selected) {
// The tasks the sweep covers: those of the latest pair's and the selection's models.
const covered = new Set([...latestRows.runs.map((run) => run.model_id), ...rank.keys()]);
taskList = [...new Set(await Promise.all([...covered].map(loadTask)))].sort();
}
} catch (e) {
if (render === rendering) results.replaceChildren(h("p", { class: "status" }, `Could not load the results: ${e.message}`));
return;
}
if (render !== rendering) return;
const runsOf = new Map();
for (const run of runs) runsOf.set(run.model_id, [...(runsOf.get(run.model_id) ?? []), run]);
// The task Trending or Downloads shows, or null for all of them.
if (!selected && !(s.view in s.tasks)) {
s.tasks[s.view] = taskList.includes(DEFAULT_TASKS[active]) ? DEFAULT_TASKS[active] : null;
}
const task = s.tasks[s.view] ?? null;
// The current page of the selection, or of the Hub's list of the chosen task or
// of all tasks: its models, each with its runs on the shown pair, the position
// of the first, and whether more follow.
async function listed() {
const start = (s.page - 1) * PAGE;
const end = start + PAGE;
let models, more;
if (selected) {
const ids = [...rank.keys()];
models = ids.slice(start, end).map((id) => ({ id }));
more = ids.length > end;
} else {
const list = await hubList(active, task, s.names[s.view] ?? "", s.view, end);
models = list.models.slice(start, end);
more = list.models.length > end || Boolean(list.next);
}
return { start, more, models: models.map((model) => ({ ...model, runs: runsOf.get(model.id) ?? [] })) };
}
// Why a model was not tested: weights larger than the test instance's HBM, or
// the reason the sweep's selection left it out.
function untestedReason({ id, params }) {
const device = TARGETS[s.target];
if (device && params * 2 > DEVICES * device.deviceHbm) return `Requires more than ${DEVICES} ${device.name} devices`;
return exclusions.get(id)?.notes ?? "";
}
renderResults = async () => {
const render = ++rendering;
let page;
try {
page = await listed();
} catch (e) {
if (render === rendering) results.replaceChildren(h("p", { class: "status" }, `Could not load the Hub's list: ${e.message}`));
return;
}
if (render !== rendering) return;
if (!page.models.length) {
const name = s.names[s.view];
results.replaceChildren(h("p", { class: "status" }, selected ? "No selection yet."
: `No model of ${task ?? "any task"}${name ? ` matching "${name}"` : ""} is listed.`));
return;
}
// A model passes if one of its runs passed.
const passed = page.models.filter((m) => m.runs.some((run) => run.result === "PASS")).length;
const untested = page.models.filter((m) => !m.runs.length).length;
const go = async (pages) => {
s.page += pages;
await renderResults();
if (results.getBoundingClientRect().top < 0) results.scrollIntoView();
};
const pager = () => h("div", { class: "pager" },
h("button", { disabled: s.page === 1, onclick: () => go(-1) }, "‹ Previous"),
h("button", { disabled: !page.more, onclick: () => go(1) }, "Next ›"));
results.replaceChildren(
h("div", { class: "summary" },
h("p", {}, h("strong", {}, `${page.start + 1}-${page.start + page.models.length}`),
` · ✅ Pass ${passed} · ❌ Fail ${page.models.length - passed - untested} · Untested ${untested}`),
pager()),
h("div", { class: "scroll" }, h("table", {},
h("thead", {}, h("tr", {}, COLUMNS.map((c) => h("th", { title: TOOLTIPS[c] }, c)))),
h("tbody", {}, page.models.map((model) => model.runs.length ? model.runs.map((run) => h("tr", {
tabindex: 0,
onclick: () => showRun(run),
onkeydown: (e) => { if (e.key === "Enter") showRun(run); },
},
h("td", {}, h("code", {}, model.id)),
h("td", { class: "num" }, run.neuron_cores),
h("td", { class: "result" }, badge(run.result)),
h("td", { class: "num" }, memory(run)),
h("td", { class: "notes" }, thumbnail(run), run.notes ?? "")))
: h("tr", { class: "untested" },
h("td", {}, h("code", {}, model.id)), h("td"), h("td", { class: "result" }, "not tested"),
h("td"), h("td", { class: "notes" }, untestedReason(model))))))),
pager());
};
// One task at a time, as on the Hub: clicking the chosen task again shows all of them.
if (!selected) {
tasks.append(...[null, ...taskList].map((t) => h("button", {
"aria-pressed": String(task === t),
onclick: () => { s.tasks[s.view] = task === t ? null : t; s.page = 1; renderPanel(); },
}, t ?? "All")));
}
renderResults();
}
// The URLs of what a pipeline generated on Neuron and on CPU, made once per run:
// the rows of a file stay cached.
const imageUrls = new WeakMap();
function images(run) {
if (!run.image) return null;
if (!imageUrls.has(run)) {
const url = (image) => image && URL.createObjectURL(new Blob([image.bytes], { type: "image/webp" }));
imageUrls.set(run, { neuron: url(run.image), cpu: url(run.cpu_image) });
}
return imageUrls.get(run);
}
// The Neuron and CPU outputs side by side, next to the thumbnail under the
// pointer. Outside the table, which would clip it.
const preview = h("div", { class: "preview", hidden: true });
document.body.append(preview);
function showPreview(thumb, urls) {
preview.replaceChildren(...[["Neuron", urls.neuron], ["CPU", urls.cpu]].filter(([, url]) => url)
.map(([label, url]) => h("figure", {}, h("img", { src: url, alt: `${label} output` }), h("figcaption", {}, label))));
preview.hidden = false;
const box = thumb.getBoundingClientRect();
const { width, height } = preview.getBoundingClientRect();
preview.style.left = `${Math.max(8, box.left - width - 8)}px`;
preview.style.top = `${Math.max(8, Math.min(box.top + (box.height - height) / 2, innerHeight - height - 8))}px`;
}
// A thumbnail of what a pipeline generated on Neuron, or null for other models.
function thumbnail(run) {
const urls = images(run);
return urls && h("img", {
class: "thumb",
src: urls.neuron,
alt: "Neuron output",
onmouseenter: (e) => showPreview(e.currentTarget, urls),
onmouseleave: () => { preview.hidden = true; },
});
}
let scriptUrl;
function showRun(run) {
URL.revokeObjectURL(scriptUrl);
scriptUrl = URL.createObjectURL(new Blob([run.run_py], { type: "text/x-python" }));
const pip = run.run_py.match(/^# (pip install .*)$/m)?.[1];
// The rows of the files from before the target level ran on trn2.
const target = run.target ?? "trn2";
const stack = [
["neuronx-cc", run.neuronx_cc], ["torch-neuronx", run.torch_neuronx], ["torch", run.torch],
["nki", run.nki], ["Python", run.python], ["Neuron driver", run.neuron_driver],
].filter(([, version]) => version);
dialog.replaceChildren(h("div", { class: "dialog" },
h("form", { method: "dialog" }, h("button", { class: "close", "aria-label": "Close" }, "×")),
h("h2", {}, h("a", { href: `${HUB}/${run.model_id}`, target: "_blank", rel: "noopener" }, run.model_id)),
h("p", {}, `${badge(run.result)} · ${run.neuron_cores} NeuronCore${run.neuron_cores > 1 ? "s" : ""}`
+ ` · ${run.runner} · ${run.library} ${run.library_version}`
+ (run.library === "transformers" ? "" : ` · transformers ${run.transformers}`)
+ ` · tested ${day(run.tested_at)}`),
h("h3", {}, "Run it"),
h("p", {}, `On a ${TARGETS[target]?.name ?? target} (${target}) instance with this Neuron stack,`
+ " for example in the AWS Neuron Deep Learning Container:"),
h("dl", {}, stack.map(([name, version]) => [h("dt", {}, name), h("dd", {}, h("code", {}, version))])),
h("ol", {},
pip && h("li", {}, "Install the packages the script adds:", h("pre", {}, pip)),
h("li", {}, "Optionally, skip compilation with the graphs this compiler already built:",
h("pre", {}, `hf buckets sync ${NEFF_CACHE}/${target}/neuronxcc-${run.neuronx_cc} /tmp/neff_cache`)),
h("li", {}, "Download ", h("a", { href: scriptUrl, download: "run.py" }, "run.py"), " and run it",
run.neuron_cores > 1 ? ". It launches its own torch.distributed ranks:" : ":",
h("pre", {}, "python3 run.py"))),
run.error && [h("h3", {}, "Error"), h("pre", { class: "error" }, run.error)],
h("details", {}, h("summary", {}, "run.py"), h("pre", {}, run.run_py))));
dialog.showModal();
}
dialog.addEventListener("click", (e) => { if (e.target === dialog) dialog.close(); });
// The visitor's sign-in, until its token expires, or null.
function signedIn() {
try {
const saved = JSON.parse(localStorage.getItem(SIGN_IN));
if (saved && new Date(saved.expires) > new Date()) return saved;
} catch {
// Without storage, such as in some private windows, the visitor is signed out.
}
return null;
}
let signInError;
async function signIn() {
try {
const { oauthLoginUrl } = await import(HUB_JS);
// The token reads the private bucket of aws-neuron only if the visitor grants it access to the organization.
location.href = `${await oauthLoginUrl()}&orgIds=${AWS_NEURON_ID}`;
} catch (e) {
signInError = e.message;
renderPanel();
}
}
function signOut() {
try {
localStorage.removeItem(SIGN_IN);
} catch {
// Nothing was saved.
}
renderPanel();
}
// Back from the sign-in, the page's URL holds its code or its error, which a reload must not use again.
async function finishSignIn() {
const query = new URLSearchParams(location.search);
if (!query.has("code") && !query.has("error")) return;
active = STATUS_TAB;
try {
const { oauthHandleRedirectIfPresent } = await import(HUB_JS);
const result = await oauthHandleRedirectIfPresent();
if (result) {
localStorage.setItem(SIGN_IN, JSON.stringify({
token: result.accessToken, expires: result.accessTokenExpiresAt, name: result.userInfo.preferred_username,
}));
}
} catch (e) {
signInError = e.message;
}
for (const key of ["code", "state", "error", "error_description"]) query.delete(key);
const rest = query.toString();
history.replaceState(null, "", `${location.pathname}${rest ? `?${rest}` : ""}`);
}
// The status of each pod that wrote one in the last day, with its host, by target and host.
async function loadStatus(token) {
const options = { headers: { Authorization: `Bearer ${token}` }, cache: "no-store" };
const files = await (await fetchOk(`${HUB}/api/buckets/${STATUS_BUCKET}/tree`, options)).json();
const pods = await Promise.all(files
.filter((file) => file.type === "file" && file.path.endsWith(".json") && Date.now() - new Date(file.uploadedAt) < GONE)
.map(async (file) => ({
host: file.path.slice(0, -".json".length),
...await (await fetchOk(`${HUB}/buckets/${STATUS_BUCKET}/resolve/${encodePath(file.path)}`, options)).json(),
})));
return pods.sort((a, b) => a.target.localeCompare(b.target) || a.host.localeCompare(b.host));
}
// A time as the logs of the sweep write it, in UTC.
const clock = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
function duration(ms) {
const minutes = Math.floor(ms / 60000);
if (minutes < 1) return `${Math.round(ms / 1000)} s`;
if (minutes < 60) return `${minutes} min`;
const hours = Math.floor(minutes / 60);
if (hours < 24) return `${hours} h ${minutes % 60} min`;
return `${Math.floor(hours / 24)} d ${hours % 24} h`;
}
const since = (iso) => duration(Date.now() - new Date(iso));
// A run directory's version of its library, and of the transformers its runs pin: a release or a commit.
const short = (version) => /^[0-9a-f]{40}$/.test(version) ? version.slice(0, 7) : version;
const versions = ({ library, pins }) => library === "transformers" ? short(pins.transformers)
: `${short(pins[library])} · transformers ${short(pins.transformers)}`;
const table = (columns, rows) => h("div", { class: "scroll" }, h("table", {},
h("thead", {}, h("tr", {}, columns.map((column) => h("th", {}, column)))),
h("tbody", {}, rows.map((cells) => h("tr", {}, cells.map((cell) => h("td", {}, cell)))))));
function renderPod(pod) {
const stale = pod.scheduled && Date.now() - new Date(pod.updated) > STALE;
const runs = (key) => pod.libraries.flatMap((l) => l[key].map((run) => ({ ...run, library: l.library })));
const running = runs("running").sort((a, b) => a.started.localeCompare(b.started));
const latest = runs("latest").sort((a, b) => b.ended.localeCompare(a.ended));
return h("section", { class: "pod" },
h("h2", {}, `${TARGETS[pod.target]?.name ?? pod.target} (${pod.target}) · ${pod.host}`),
h("p", { class: stale ? "pair stale" : "pair" },
`${pod.deployed} · ${pod.scheduled ? "scheduled" : "paused"} · updated ${clock(pod.updated)}, ${since(pod.updated)} ago`,
stale ? ": the pod stopped writing its status" : ""),
table(["Library", "Version", "neuronx-cc", "Position in its list", "Pipeline"], pod.libraries.map((l) => [
l.library,
versions(l),
l.neuronx_cc ?? "",
l.position && [h("progress", { value: l.position[0], max: l.position[1] }), ` ${l.position[0]} / ${l.position[1]}`],
l.pipeline_started ? `running for ${since(l.pipeline_started)}` : "",
])),
running.length > 0 && [h("h3", {}, "Running"), table(["Model", "Library", "Cores", "Runner", "Started", "For"],
running.map((run) => [h("code", {}, run.model_id), run.library, run.neuron_cores, run.runner,
clock(run.started), since(run.started)]))],
latest.length > 0 && [h("h3", {}, "Latest results"),
table(["Ended", "Model", "Library", "Cores", "Result", "Wall", "Notes"],
latest.map((run) => [clock(run.ended), h("code", {}, run.model_id), run.library, run.neuron_cores,
badge(run.result), run.wall_s == null ? "" : duration(run.wall_s * 1000), run.notes]))],
h("details", {}, h("summary", {}, "scheduler.log"), h("pre", {}, pod.log.join("\n"))));
}
// The status of each pod, which refreshes every minute while its tab shows.
async function renderStatus(render) {
const auth = signedIn();
const signInButton = (label) => h("button", { onclick: signIn }, label);
if (!auth) {
panel.replaceChildren(h("div", { class: "signin" },
h("p", {}, "Members of the aws-neuron organization can sign in to see the status of the sweep of each pod:"
+ " where it is in the list of each library, the models it runs and its latest results."),
signInError && h("p", { class: "error" }, `Could not sign in: ${signInError}`),
signInButton("Sign in with Hugging Face")));
return;
}
if (!panel.querySelector(".pod")) panel.replaceChildren(h("p", { class: "status" }, "Loading…"));
let pods;
try {
pods = await loadStatus(auth.token);
} catch (e) {
if (render === rendering) {
panel.replaceChildren(h("div", { class: "signin" },
h("p", { class: "error" }, `Could not read the status: ${e.message}`),
h("p", {}, "Only the members of aws-neuron who give this Space access to the organization when they sign in"
+ " can read it."),
signInButton("Sign in again"), " ", h("button", { onclick: signOut }, "Sign out")));
}
return;
}
if (render !== rendering) return;
panel.replaceChildren(
h("p", { class: "pair" }, `Signed in as ${auth.name} · `, h("button", { class: "link", onclick: signOut }, "Sign out")),
pods.length ? pods.map(renderPod) : h("p", { class: "status" }, "No pod has written its status in the last day."));
setTimeout(() => { if (render === rendering) renderPanel(); }, STATUS_REFRESH);
}
await finishSignIn();
renderTabs();
renderPanel();