import React from "react"; function isNumberString(value) { return typeof value === "string" && /^[0-9]+$/.test(value); } function LayerNode({ node, nodeKey, last, depth = 0 }) { if (!node) return null; const name = node.class_name || node.name || ""; const shape = node.params?.weight?.shape || []; // Normalize children: object map let children = []; let keys = []; if (node.children && typeof node.children === "object") { children = Object.values(node.children); keys = Object.keys(node.children); } // choose background by depth for subtle alternation const bgByDepth = ["bg-slate-50", "bg-slate-100", "bg-slate-200", "bg-slate-50"]; const bgClass = bgByDepth[depth % bgByDepth.length]; const isEmbed = String(name).toLowerCase().includes("embed"); const embedStyle = isEmbed ? { backgroundColor: "#fbdfe2" } : undefined; const isAttn = String(name).toLowerCase().includes("attention") || String(name).toLowerCase().includes("attn"); const attnStyle = isAttn ? { backgroundColor: "#fddfba" } : undefined; const isFFN = String(name).toLowerCase().includes("ffn") || String(name).toLowerCase().includes("mlp"); const ffnStyle = isFFN ? { backgroundColor: "#c2e6f8" } : undefined; const isNorm = String(name).toLowerCase().includes("norm"); const normStyle = isNorm ? { backgroundColor: "#f3f7c3" } : undefined; const isLastNorm = last && isNorm; const lastNormStyle = isLastNorm ? { backgroundColor: "#DEDFF1" } : undefined; return (
{name}
{nodeKey && !isNumberString(nodeKey) &&
({nodeKey})
}
{shape.join(" x ")}
{node.num_repeats && x {node.num_repeats}}
{children.length > 0 && (
{children.map((child, idx) => ( ))}
)}
); } export default function ModelLayersCard({ layers = {}, name = "" }) { let rootNodes = []; let rootKeys = []; if (layers && typeof layers === "object") { if (layers.children && typeof layers.children === "object") { rootNodes = Object.values(layers.children); rootKeys = Object.keys(layers.children); } else { // Fallback: convert the top-level keyed object into an array rootNodes = Object.values(layers); rootKeys = Object.keys(layers); } } if (!rootNodes || rootNodes.length === 0) { return null; } return (

{name}

{rootNodes.map((node, idx) => ( ))}
); }