captainspock commited on
Commit
e695b00
·
verified ·
1 Parent(s): c38043a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -19
index.html CHANGED
@@ -219,7 +219,7 @@
219
  </div>
220
  <div class="grid grid-cols-3 gap-2 text-[10px] font-mono">
221
  <div class="bg-white p-1 border border-black">
222
- <div class="text-gray-500 uppercase">Model Load</div>
223
  <div class="font-bold" id="metric-compilation">-</div>
224
  </div>
225
  <div class="bg-white p-1 border border-black">
@@ -1087,8 +1087,7 @@
1087
  const TOOL_SCHEMA = [{"type": "function", "function": {"name": "add", "description": "Add a shape into the game scene.", "parameters": {"type": "object", "properties": {"shape": {"type": "string", "enum": ["circle", "square", "triangle", "star", "rectangle", "line", "ellipse"], "description": "The kind shape to add. Required."}, "location": {"type": "string", "description": "The [x, y] coordinates where the shape will be placed or a descriptive string. Required."}, "size": {"type": "number", "description": "The size of the object (between 0.1 and 10.0). Default is 1.0."}, "rotation": {"type": "integer", "description": "The initial clockwise rotation of the object in degrees (0-360). Default is 0."}, "friction": {"type": "number", "description": "The friction of the object (between 0.0 and 1.0). Default is 0.0."}, "restitution": {"type": "number", "description": "The bounciness of the object (between 0.0 and 1.0). Default is 0.0."}, "mass": {"type": "number", "description": "The mass of the object (between 1.0 and 10.0). Default is 1.0."}, "delay": {"type": "number", "description": "The time in seconds to wait before the object appears in the scene. Default is 0.0."}, "static": {"type": "boolean", "description": "Whether the object is static (immovable) or dynamic. Default is False."}, "velocity": {"type": "array", "items": {"type": "number"}, "description": "The initial [vx, vy] velocity vector of the object (values between -10.0 and 10.0). Default is [0.0, 0.0]."}, "color": {"type": "string", "description": "The color of the object as a string or hex code (e.g., \"red\", \"blue\", \"#FF00FF\"). Default is \"red\"."}}, "required": ["shape", "location"]}, "return": {"type": "string", "description": "A unique identifier for the added shape."}}}];
1088
  async function initModel() {
1089
  try {
1090
- const loadStart = performance.now();
1091
- console.log("⏱️ Starting model load...");
1092
 
1093
  tokenizer = await AutoTokenizer.from_pretrained(MODEL_ID);
1094
  model = await AutoModelForCausalLM.from_pretrained(MODEL_ID, {
@@ -1096,9 +1095,16 @@
1096
  dtype: "q4",
1097
  });
1098
 
1099
- const loadEnd = performance.now();
1100
- STATE.modelCompilationTime = loadEnd - loadStart;
1101
- console.log(`✅ Model loaded in ${STATE.modelCompilationTime.toFixed(2)}ms (${(STATE.modelCompilationTime / 1000).toFixed(2)}s)`);
 
 
 
 
 
 
 
1102
 
1103
  // Update UI
1104
  document.getElementById("metric-compilation").innerText = `${(STATE.modelCompilationTime / 1000).toFixed(2)}s`;
@@ -1137,37 +1143,34 @@
1137
 
1138
  // 4. Generate with performance tracking
1139
  const generationStart = performance.now();
1140
- let ttftRecorded = false;
1141
  let ttft = 0;
1142
- let callbackCount = 0;
1143
 
1144
  const output = await model.generate({
1145
  ...inputs,
1146
  max_new_tokens: 128,
1147
  do_sample: false,
1148
  callback_function: (tokens) => {
1149
- callbackCount++;
1150
- console.log(`🔍 Callback #${callbackCount}, tokens:`, tokens);
1151
- // Record TTFT on first callback (first token generated)
1152
- if (!ttftRecorded) {
1153
  ttft = performance.now() - generationStart;
1154
- ttftRecorded = true;
1155
- console.log(`⚡ Time to First Token (TTFT): ${ttft.toFixed(2)}ms`);
 
 
 
1156
  }
1157
  }
1158
  });
1159
 
1160
  const generationEnd = performance.now();
1161
  const totalTime = generationEnd - generationStart;
1162
- const inputTokenCount = inputs.input_ids.dims[1];
1163
- const totalTokenCount = output.dims ? output.dims[1] : output.size;
1164
- const outputTokenCount = Math.max(0, totalTokenCount - inputTokenCount);
1165
- const tps = outputTokenCount / (totalTime / 1000);
1166
 
1167
  // Store and display metrics
1168
  STATE.lastTTFT = ttft;
1169
  STATE.lastTPS = tps;
1170
- console.log(`📊 Performance: TTFT=${ttft.toFixed(0)}ms, TPS=${tps.toFixed(1)} tok/s`);
1171
  document.getElementById("metric-ttft").innerText = `${ttft.toFixed(0)}ms`;
1172
  document.getElementById("metric-tps").innerText = `${tps.toFixed(1)} t/s`;
1173
 
 
219
  </div>
220
  <div class="grid grid-cols-3 gap-2 text-[10px] font-mono">
221
  <div class="bg-white p-1 border border-black">
222
+ <div class="text-gray-500 uppercase">Compilation</div>
223
  <div class="font-bold" id="metric-compilation">-</div>
224
  </div>
225
  <div class="bg-white p-1 border border-black">
 
1087
  const TOOL_SCHEMA = [{"type": "function", "function": {"name": "add", "description": "Add a shape into the game scene.", "parameters": {"type": "object", "properties": {"shape": {"type": "string", "enum": ["circle", "square", "triangle", "star", "rectangle", "line", "ellipse"], "description": "The kind shape to add. Required."}, "location": {"type": "string", "description": "The [x, y] coordinates where the shape will be placed or a descriptive string. Required."}, "size": {"type": "number", "description": "The size of the object (between 0.1 and 10.0). Default is 1.0."}, "rotation": {"type": "integer", "description": "The initial clockwise rotation of the object in degrees (0-360). Default is 0."}, "friction": {"type": "number", "description": "The friction of the object (between 0.0 and 1.0). Default is 0.0."}, "restitution": {"type": "number", "description": "The bounciness of the object (between 0.0 and 1.0). Default is 0.0."}, "mass": {"type": "number", "description": "The mass of the object (between 1.0 and 10.0). Default is 1.0."}, "delay": {"type": "number", "description": "The time in seconds to wait before the object appears in the scene. Default is 0.0."}, "static": {"type": "boolean", "description": "Whether the object is static (immovable) or dynamic. Default is False."}, "velocity": {"type": "array", "items": {"type": "number"}, "description": "The initial [vx, vy] velocity vector of the object (values between -10.0 and 10.0). Default is [0.0, 0.0]."}, "color": {"type": "string", "description": "The color of the object as a string or hex code (e.g., \"red\", \"blue\", \"#FF00FF\"). Default is \"red\"."}}, "required": ["shape", "location"]}, "return": {"type": "string", "description": "A unique identifier for the added shape."}}}];
1088
  async function initModel() {
1089
  try {
1090
+ console.log("⏱️ Loading model...");
 
1091
 
1092
  tokenizer = await AutoTokenizer.from_pretrained(MODEL_ID);
1093
  model = await AutoModelForCausalLM.from_pretrained(MODEL_ID, {
 
1095
  dtype: "q4",
1096
  });
1097
 
1098
+ console.log("✅ Model loaded, starting compilation warmup...");
1099
+
1100
+ // Compilation warmup
1101
+ const compileStart = performance.now();
1102
+ const inputs = tokenizer("test");
1103
+ await model.generate({ ...inputs, max_new_tokens: 1 });
1104
+ const compileEnd = performance.now();
1105
+
1106
+ STATE.modelCompilationTime = compileEnd - compileStart;
1107
+ console.log(`✅ Compilation complete in ${STATE.modelCompilationTime.toFixed(2)}ms (${(STATE.modelCompilationTime / 1000).toFixed(2)}s)`);
1108
 
1109
  // Update UI
1110
  document.getElementById("metric-compilation").innerText = `${(STATE.modelCompilationTime / 1000).toFixed(2)}s`;
 
1143
 
1144
  // 4. Generate with performance tracking
1145
  const generationStart = performance.now();
1146
+ let numTokens = 0;
1147
  let ttft = 0;
1148
+ let tps = 0;
1149
 
1150
  const output = await model.generate({
1151
  ...inputs,
1152
  max_new_tokens: 128,
1153
  do_sample: false,
1154
  callback_function: (tokens) => {
1155
+ // Record TTFT on first token (before incrementing counter)
1156
+ if (numTokens === 0) {
 
 
1157
  ttft = performance.now() - generationStart;
1158
+ }
1159
+ numTokens++;
1160
+ // Calculate TPS after incrementing
1161
+ if (numTokens > 0) {
1162
+ tps = (numTokens / (performance.now() - generationStart)) * 1000;
1163
  }
1164
  }
1165
  });
1166
 
1167
  const generationEnd = performance.now();
1168
  const totalTime = generationEnd - generationStart;
 
 
 
 
1169
 
1170
  // Store and display metrics
1171
  STATE.lastTTFT = ttft;
1172
  STATE.lastTPS = tps;
1173
+ console.log(`📊 Performance: TTFT=${ttft.toFixed(0)}ms, TPS=${tps.toFixed(1)} tok/s, Tokens=${numTokens}`);
1174
  document.getElementById("metric-ttft").innerText = `${ttft.toFixed(0)}ms`;
1175
  document.getElementById("metric-tps").innerText = `${tps.toFixed(1)} t/s`;
1176