MCPcopy
hub / github.com/bbycroft/llm-viz / drawModelCard

Function drawModelCard

src/llm/components/ModelCard.ts:16–100  ·  view source on GitHub ↗
(state: IProgramState, layout: IGptModelLayout, title: string, offset: Vec3)

Source from the content-addressed store, hash-verified

14import { clamp } from "@/src/utils/data";
15
16export function drawModelCard(state: IProgramState, layout: IGptModelLayout, title: string, offset: Vec3) {
17 let { render } = state;
18 let { camPos } = cameraToMatrixView(state.camera);
19 let dist = camPos.dist(new Vec3(0, 0, -30)); //.add(offset));
20
21 let scale = clamp(dist / 500.0, 1.0, 800.0);
22
23 let pinY = -60;
24 let mtx = Mat4f.fromScaleTranslation(new Vec3(scale, scale, scale), new Vec3(0, pinY, 0).add(offset))
25 .mul(Mat4f.fromTranslation(new Vec3(0, -pinY, 0)));
26
27 let thick = 1.0 / 10.0 * scale;
28 let borderColor = Vec4.fromHexColor("#555599", 0.8);
29 let backgroundColor = Vec4.fromHexColor("#93c5fd", 0.3);
30 let titleColor = Vec4.fromHexColor("#000000", 1.0);
31 let n = new Vec3(0, 0, 1);
32
33 let lineOpts: ILineOpts = { color: borderColor, mtx, thick, n };
34
35 let tl = new Vec3(-45, -97, 0);
36 let br = new Vec3( 45, -70, 0);
37 drawLineRect(render, tl, br, lineOpts);
38
39 addQuad(render.triRender, new Vec3(tl.x, tl.y, -0.1), new Vec3(br.x, br.y, -0.1), backgroundColor, mtx);
40
41 // let w = measureTextWidth(state.modelFontBuf, title, .0);
42 let { B, C, T, A, nBlocks, nHeads, vocabSize } = layout.shape;
43
44 let midX = (tl.x + br.x) / 2;
45 let paramLeft = br.x - 50;
46 let paramOff = tl.y + 2;
47
48 let paramLineHeight = 1.3;
49 let paramFontScale = 4;
50 let numWidth = paramFontScale * 0.6;
51 let allNums = [B, C, T, A, nBlocks, nHeads];
52 let maxLen = Math.max(...allNums.map(n => n.toString().length));
53 let paramHeight = 2 + paramLineHeight * paramFontScale * 3 + 1;
54
55 let titleFontScale = 13;
56 let titleW = measureTextWidth(render.modelFontBuf, title, titleFontScale);
57 let titleHeight = titleFontScale * paramLineHeight;
58 writeTextToBuffer(render.modelFontBuf, title, titleColor, midX - titleW / 2, tl.y + 2, titleFontScale, mtx);
59
60 // layout.weightCount = 150000000000;
61
62 let nParamsText = `n_params = `;
63 let weightCountText = numberToCommaSep(layout.weightCount);
64
65 let weightSize = 8;
66 let weightTitleW = measureTextWidth(render.modelFontBuf, nParamsText, paramFontScale);
67 let weightCountW = measureTextWidth(render.modelFontBuf, weightCountText, weightSize);
68 // let infoText = "goal: sort 6 letters from { A, B, C } into ascending order";
69 // writeTextToBuffer(render.modelFontBuf, infoText, titleColor, tl.x + 2, tl.y + paramHeight + 2, 4, mtx);
70
71 paramOff = tl.y + titleHeight + 4;
72 let weightX = midX - (weightCountW + weightTitleW) / 2;
73

Callers 1

runProgramFunction · 0.90

Calls 15

toStringMethod · 0.95
cameraToMatrixViewFunction · 0.90
clampFunction · 0.90
addQuadFunction · 0.90
measureTextWidthFunction · 0.90
writeTextToBufferFunction · 0.90
drawLineRectFunction · 0.85
numberToCommaSepFunction · 0.85
renderOutputAtBottomFunction · 0.85
renderInputAtTopFunction · 0.85
fromScaleTranslationMethod · 0.80
fromTranslationMethod · 0.80

Tested by

no test coverage detected