MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>MojoLlama Studio — Dashboard</title> |
| 7 | <meta name="color-scheme" content="light dark"> |
| 8 | <meta name="description" content="MojoLlama Studio: chat, train, benchmark, quantize, and serve LLMs from your browser."> |
| 9 | <link rel="icon" type="image/png" sizes="32x32" href="../favicon.png"> |
| 10 | <link rel="icon" type="image/png" sizes="48x48" href="../favicon-48.png"> |
| 11 | <link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"> |
| 12 | <script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script> |
| 13 | <link rel="preconnect" href="https://fonts.googleapis.com"> |
| 14 | <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
| 15 | <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700;800;900&family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"> |
| 16 | <style> |
| 17 | /* ══════════════════════════════════════════════ |
| 18 | MojoLlama Studio — IBM-Inspired Light Theme |
| 19 | Matches index.html brand system exactly |
| 20 | ══════════════════════════════════════════════ */ |
| 21 | |
| 22 | :root { |
| 23 | /* Brand */ |
| 24 | --mojo: #6C3CE1; |
| 25 | --mojo-dark: #5228B5; |
| 26 | --mojo-light: #8B5CF6; |
| 27 | --mojo-subtle: rgba(108, 60, 225, 0.08); |
| 28 | |
| 29 | /* Light palette — IBM Carbon inspired */ |
| 30 | --bg: #FFFFFF; |
| 31 | --bg-alt: #F4F4F4; |
| 32 | --surface: #FFFFFF; |
| 33 | --surface-hover: #F8F8F8; |
| 34 | --border: #E0E0E0; |
| 35 | --border-light: #EDEDED; |
| 36 | |
| 37 | /* Text */ |
| 38 | --text: #161616; |
| 39 | --text-secondary: #525252; |
| 40 | --text-tertiary: #8D8D8D; |
| 41 | --text-inverse: #FFFFFF; |
| 42 | |
| 43 | /* Semantic */ |
| 44 | --success: #198038; |
| 45 | --warning: #DA1E28; |
| 46 | --info: #0043CE; |
| 47 | --orange: #D45A00; |
| 48 | --cyan: #009D9A; |
| 49 | |
| 50 | /* Typography */ |
| 51 | --font-body: 'Inter', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; |
| 52 | --font-mono: 'JetBrains Mono', 'IBM Plex Mono', 'Fira Code', monospace; |
| 53 | |
| 54 | /* Interaction */ |
| 55 | --layer-hover: rgba(0,0,0,0.04); |
| 56 | --focus: #6C3CE1; |
| 57 | --focus-inverse: #FFFFFF; |
| 58 | |
| 59 | /* Spacing (8px grid) */ |
| 60 | --space-8: 8px; |
| 61 | --space-12: 12px; |
| 62 | --space-16: 16px; |
| 63 | --space-24: 24px; |
| 64 | --space-32: 32px; |
| 65 | --space-40: 40px; |
| 66 | --space-48: 48px; |
| 67 | |
| 68 | /* Layout */ |
| 69 | --radius-sm: 4px; |
| 70 | --radius: 8px; |
| 71 | --radius-lg: 12px; |
| 72 | --shadow-sm: 0 1px 3px rgba(0,0,0,0.06); |
| 73 | --shadow: 0 4px 12px rgba(0,0,0,0.06); |
| 74 | --shadow-lg: 0 12px 40px rgba(0,0,0,0.08); |
| 75 | --transition: 0.15s cubic-bezier(0.2, 0, 0, 1); |
| 76 | --transition-slow: 0.4s cubic-bezier(0.2, 0, 0, 1); |
| 77 | } |
| 78 | |
| 79 | /* ── Dark theme — IBM Carbon g90/g100 progressive layering ── */ |
| 80 | [data-theme="dark"] { |
| 81 | --bg: #161616; --bg-alt: #1C1C1C; |
| 82 | --surface: #262626; --surface-hover: #333333; |
| 83 | --border: #393939; --border-light: #333333; |
| 84 | --text: #F4F4F4; --text-secondary: #C6C6C6; |
| 85 | --text-tertiary: #8D8D8D; --text-inverse: #161616; |
| 86 | --layer-hover: rgba(255,255,255,0.05); |
| 87 | --mojo-subtle: rgba(139,92,246,0.15); |
| 88 | --success: #42BE65; --warning: #FA4D56; --info: #5AA8FF; |
| 89 | --focus: #8B5CF6; --focus-inverse: #161616; |
| 90 | } |
| 91 | @media (prefers-color-scheme: dark) { |
| 92 | :root:not([data-theme="light"]) { |
| 93 | --bg: #161616; --bg-alt: #1C1C1C; |
| 94 | --surface: #262626; --surface-hover: #333333; |
| 95 | --border: #393939; --border-light: #333333; |
| 96 | --text: #F4F4F4; --text-secondary: #C6C6C6; |
| 97 | --text-tertiary: #8D8D8D; --text-inverse: #161616; |
| 98 | --layer-hover: rgba(255,255,255,0.05); |
| 99 | --mojo-subtle: rgba(139,92,246,0.15); |
| 100 | --success: #42BE65; --warning: #FA4D56; --info: #5AA8FF; |
| 101 | --focus: #8B5CF6; --focus-inverse: #161616; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | * { margin: 0; padding: 0; box-sizing: border-box; } |
| 106 | html { -webkit-font-smoothing: antialiased; } |
| 107 | body { |
| 108 | font-family: var(--font-body); |
| 109 | background: var(--bg); color: var(--text); |
| 110 | min-height: 100vh; overflow: hidden; |
| 111 | transition: background var(--transition-slow), color var(--transition-slow); |
| 112 | } |
| 113 | ::selection { background: var(--mojo-subtle); } |
| 114 | ::-webkit-scrollbar { width: 6px; height: 6px; } |
| 115 | ::-webkit-scrollbar-track { background: transparent; } |
| 116 | ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; } |
| 117 | ::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); } |
| 118 | a { color: var(--mojo); text-decoration: none; } |
| 119 | a:hover { color: var(--mojo-dark); } |
| 120 | |
| 121 | /* Skip to content */ |
| 122 | .skip-link { |
| 123 | position: absolute; top: -100%; left: 16px; |
| 124 | background: var(--mojo); color: #fff; |
| 125 | padding: 8px 16px; border-radius: var(--radius-sm); |
| 126 | font-size: 0.875rem; font-weight: 600; z-index: 9999; |
| 127 | transition: top 0.2s; |
| 128 | } |
| 129 | .skip-link:focus { top: 8px; color: #fff; } |
| 130 | |
| 131 | /* Focus visible */ |
| 132 | :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } |
| 133 | |
| 134 | /* ─── Layout ─── */ |
| 135 | .app { display: flex; height: 100vh; overflow: hidden; } |
| 136 | |
| 137 | /* ─── Sidebar ─── */ |
| 138 | .sidebar { |
| 139 | width: 230px; flex-shrink: 0; |
| 140 | display: flex; flex-direction: column; |
| 141 | background: var(--bg-alt); |
| 142 | border-right: 1px solid var(--border); |
| 143 | } |
| 144 | .sidebar-header { |
| 145 | padding: 20px 16px 16px; |
| 146 | border-bottom: 1px solid var(--border); |
| 147 | } |
| 148 | .sidebar-header a { color: inherit; } |
| 149 | .sidebar-header .logo-text { |
| 150 | font-size: 16px; font-weight: 700; letter-spacing: -0.01em; |
| 151 | color: var(--text); |
| 152 | } |
| 153 | .sidebar-header .logo-text span { color: var(--mojo); } |
| 154 | .sidebar-header .ver { |
| 155 | font-size: 11px; color: var(--text-tertiary); |
| 156 | margin-top: 2px; |
| 157 | } |
| 158 | .sidebar-nav { |
| 159 | flex: 1; padding: var(--space-8); overflow-y: auto; |
| 160 | } |
| 161 | .nav-item { |
| 162 | display: flex; align-items: center; gap: 10px; |
| 163 | padding: 8px 12px; border-radius: var(--radius-sm); |
| 164 | cursor: pointer; color: var(--text-secondary); |
| 165 | font-size: 13px; font-weight: 500; |
| 166 | transition: all var(--transition); margin-bottom: 1px; |
| 167 | position: relative; |
| 168 | } |
| 169 | .nav-item:hover { color: var(--text); background: var(--surface-hover); } |
| 170 | .nav-item.active { color: var(--mojo); background: var(--mojo-subtle); } |
| 171 | .nav-item.active::before { |
| 172 | content: ''; position: absolute; left: 0; top: 50%; |
| 173 | transform: translateY(-50%); |
| 174 | width: 3px; height: 18px; |
| 175 | border-radius: 0 2px 2px 0; background: var(--mojo); |
| 176 | } |
| 177 | .nav-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; } |
| 178 | .nav-badge { |
| 179 | margin-left: auto; font-size: 10px; padding: 1px 7px; border-radius: 8px; |
| 180 | background: var(--mojo-subtle); color: var(--mojo); font-weight: 600; |
| 181 | } |
| 182 | .sidebar-footer { |
| 183 | padding: var(--space-12); |
| 184 | border-top: 1px solid var(--border); |
| 185 | } |
| 186 | .backend-status { |
| 187 | display: flex; align-items: center; gap: var(--space-8); |
| 188 | padding: 8px 10px; |
| 189 | background: var(--bg); border: 1px solid var(--border); |
| 190 | border-radius: var(--radius-sm); cursor: pointer; |
| 191 | transition: all var(--transition); font-size: 12px; |
| 192 | } |
| 193 | .backend-status:hover { border-color: var(--mojo); } |
| 194 | .status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; } |
| 195 | .status-dot.online { background: var(--success); } |
| 196 | .status-dot.offline { background: var(--warning); animation: pulse-offline 2s ease-in-out infinite; } |
| 197 | @keyframes pulse-offline { 0%,100% { opacity:1; } 50% { opacity:0.3; } } |
| 198 | .text-code { font-family: var(--font-mono); font-size: 11px; color: var(--text-tertiary); word-break: break-all; } |
| 199 | .backend-info { flex: 1; overflow: hidden; } |
| 200 | .backend-name { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } |
| 201 | .backend-uptime { color: var(--text-tertiary); font-size: 10px; } |
| 202 | |
| 203 | /* ─── Main area ─── */ |
| 204 | .main { flex: 1; display: flex; flex-direction: column; overflow: hidden; } |
| 205 | .topbar { |
| 206 | display: flex; align-items: center; gap: var(--space-12); |
| 207 | padding: 10px 24px; |
| 208 | border-bottom: 1px solid var(--border); |
| 209 | background: var(--bg); |
| 210 | flex-shrink: 0; |
| 211 | } |
| 212 | .topbar-title { font-size: 15px; font-weight: 600; } |
| 213 | .topbar-actions { margin-left: auto; display: flex; gap: var(--space-4); } |
| 214 | .content { |
| 215 | flex: 1; overflow-y: auto; |
| 216 | padding: 20px 24px; |
| 217 | } |
| 218 | |
| 219 | /* ─── Panels ─── */ |
| 220 | .panel { display: none; animation: fadeSlide 0.2s ease; } |
| 221 | .panel.active { display: block; } |
| 222 | @keyframes fadeSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } } |
| 223 | |
| 224 | /* ─── Cards ─── */ |
| 225 | .card { |
| 226 | background: var(--bg); |
| 227 | border: 1px solid var(--border-light); |
| 228 | border-radius: var(--radius); |
| 229 | padding: 20px; |
| 230 | margin-bottom: var(--space-16); |
| 231 | transition: border-color var(--transition); |
| 232 | } |
| 233 | .card:hover { border-color: var(--border); } |
| 234 | .card-header { |
| 235 | display: flex; align-items: center; justify-content: space-between; |
| 236 | margin-bottom: var(--space-16); |
| 237 | } |
| 238 | .card-header h3 { |
| 239 | font-size: 14px; font-weight: 600; |
| 240 | display: flex; align-items: center; gap: var(--space-8); |
| 241 | } |
| 242 | .card-header h3 .icon { font-size: 16px; } |
| 243 | .badge { font-size: 10px; padding: 2px 8px; border-radius: 8px; font-weight: 600; } |
| 244 | .badge-new { background: rgba(25,128,56,0.1); color: var(--success); } |
| 245 | .badge-pro { background: var(--mojo-subtle); color: var(--mojo); } |
| 246 | .badge-beta { background: rgba(212,90,0,0.1); color: var(--orange); } |
| 247 | |
| 248 | /* ─── Forms ─── */ |
| 249 | label { |
| 250 | display: block; font-size: 11px; color: var(--text-tertiary); |
| 251 | margin-bottom: 4px; font-weight: 600; |
| 252 | text-transform: uppercase; letter-spacing: 0.04em; |
| 253 | } |
| 254 | input, select, textarea { |
| 255 | width: 100%; padding: 7px 12px; |
| 256 | background: var(--bg); |
| 257 | border: 1px solid var(--border); border-radius: var(--radius-sm); |
| 258 | color: var(--text); font-size: 13px; |
| 259 | margin-bottom: 10px; transition: all var(--transition); |
| 260 | font-family: inherit; |
| 261 | } |
| 262 | input:focus, select:focus, textarea:focus { |
| 263 | outline: none; border-color: var(--mojo); |
| 264 | box-shadow: 0 0 0 2px var(--mojo-subtle); |
| 265 | } |
| 266 | textarea { |
| 267 | font-family: var(--font-mono); |
| 268 | font-size: 12px; resize: vertical; min-height: 56px; line-height: 1.5; |
| 269 | } |
| 270 | |
| 271 | /* ─── Buttons ─── */ |
| 272 | .btn { |
| 273 | padding: 7px 18px; border: none; border-radius: var(--radius-sm); |
| 274 | cursor: pointer; font-size: 13px; font-weight: 500; |
| 275 | transition: all var(--transition); |
| 276 | display: inline-flex; align-items: center; gap: 6px; |
| 277 | font-family: inherit; |
| 278 | } |
| 279 | .btn:disabled { opacity: 0.4; cursor: not-allowed; } |
| 280 | .btn-primary { background: var(--mojo); color: var(--text-inverse); } |
| 281 | .btn-primary:hover:not(:disabled) { background: var(--mojo-dark); } |
| 282 | .btn-green { background: var(--success); color: var(--text-inverse); } |
| 283 | .btn-green:hover:not(:disabled) { opacity: 0.9; } |
| 284 | .btn-red { background: var(--warning); color: var(--text-inverse); } |
| 285 | .btn-red:hover:not(:disabled) { opacity: 0.9; } |
| 286 | .btn-dim { background: var(--bg-alt); color: var(--text); border: 1px solid var(--border); } |
| 287 | .btn-dim:hover:not(:disabled) { background: var(--border-light); } |
| 288 | .btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); } |
| 289 | .btn-outline:hover:not(:disabled) { border-color: var(--mojo); color: var(--mojo); } |
| 290 | .btn-sm { padding: 4px 12px; font-size: 12px; } |
| 291 | .btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 4px; } |
| 292 | .btn-icon { |
| 293 | padding: 5px 8px; border-radius: var(--radius-sm); cursor: pointer; |
| 294 | background: transparent; border: 1px solid transparent; |
| 295 | color: var(--text-tertiary); transition: all var(--transition); font-size: 14px; |
| 296 | } |
| 297 | .btn-icon:hover { border-color: var(--border); color: var(--text); background: var(--surface-hover); } |
| 298 | |
| 299 | /* ─── Grid / Layout Helpers ─── */ |
| 300 | .row { display: flex; gap: var(--space-12); flex-wrap: wrap; } |
| 301 | .row > * { flex: 1; min-width: 0; } |
| 302 | .col-2 { flex: 2 !important; } |
| 303 | .col-3 { flex: 3 !important; } |
| 304 | .col-auto { flex: 0 0 auto !important; } |
| 305 | .mb-8 { margin-bottom: var(--space-8); } |
| 306 | .mb-12 { margin-bottom: var(--space-12); } |
| 307 | .mt-8 { margin-top: var(--space-8); } |
| 308 | .mt-12 { margin-top: var(--space-12); } |
| 309 | .gap-16 { gap: var(--space-16); } |
| 310 | |
| 311 | /* ─── Log / Terminal ─── */ |
| 312 | .log { |
| 313 | background: var(--bg-alt); |
| 314 | border: 1px solid var(--border-light); |
| 315 | border-radius: var(--radius-sm); |
| 316 | padding: 12px 14px; |
| 317 | font-family: var(--font-mono); |
| 318 | font-size: 12px; line-height: 1.6; |
| 319 | overflow-y: auto; white-space: pre-wrap; word-break: break-all; |
| 320 | max-height: 300px; min-height: 40px; |
| 321 | color: var(--text-secondary); |
| 322 | } |
| 323 | |
| 324 | /* ─── Chat ─── */ |
| 325 | .chat-container { |
| 326 | border: 1px solid var(--border); border-radius: var(--radius); |
| 327 | background: var(--bg); overflow: hidden; |
| 328 | display: flex; flex-direction: column; height: 520px; |
| 329 | } |
| 330 | .chat-messages { flex: 1; overflow-y: auto; padding: var(--space-16); scroll-behavior: smooth; } |
| 331 | .msg { margin-bottom: var(--space-16); animation: msgIn 0.2s ease; } |
| 332 | @keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } } |
| 333 | .msg-row { display: flex; gap: 10px; } |
| 334 | .msg-avatar { |
| 335 | width: 28px; height: 28px; border-radius: 50%; |
| 336 | display: flex; align-items: center; justify-content: center; |
| 337 | font-size: 12px; font-weight: 700; flex-shrink: 0; |
| 338 | } |
| 339 | .msg-avatar.user { background: rgba(0,67,206,0.08); color: var(--info); } |
| 340 | .msg-avatar.assistant { background: var(--mojo-subtle); color: var(--mojo); } |
| 341 | .msg-avatar.system { background: rgba(212,90,0,0.08); color: var(--orange); } |
| 342 | .msg-body { flex: 1; min-width: 0; } |
| 343 | .msg-name { font-size: 12px; font-weight: 600; margin-bottom: 3px; } |
| 344 | .msg-name.user { color: var(--info); } |
| 345 | .msg-name.assistant { color: var(--mojo); } |
| 346 | .msg-name.system { color: var(--orange); } |
| 347 | .msg-meta { font-size: 10px; color: var(--text-tertiary); margin-left: 8px; } |
| 348 | .msg-text { font-size: 14px; line-height: 1.65; color: var(--text); } |
| 349 | .msg-text p { margin-bottom: 8px; } |
| 350 | .msg-text pre { |
| 351 | background: var(--bg-alt); border: 1px solid var(--border); |
| 352 | border-radius: var(--radius-sm); padding: var(--space-12); |
| 353 | font-size: 12px; overflow-x: auto; margin: 8px 0; |
| 354 | } |
| 355 | .msg-text code { background: var(--bg-alt); padding: 1px 5px; border-radius: 4px; font-size: 13px; } |
| 356 | .msg-text pre code { background: none; padding: 0; } |
| 357 | .chat-input-area { |
| 358 | display: flex; gap: var(--space-8); |
| 359 | padding: var(--space-12) var(--space-16); |
| 360 | border-top: 1px solid var(--border); align-items: flex-end; |
| 361 | } |
| 362 | .chat-input-area textarea { flex: 1; margin-bottom: 0; min-height: 40px; max-height: 120px; resize: none; } |
| 363 | |
| 364 | /* ─── Stats Grid ─── */ |
| 365 | .stats-grid { |
| 366 | display: grid; |
| 367 | grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); |
| 368 | gap: var(--space-8); |
| 369 | } |
| 370 | .stat-card { |
| 371 | background: var(--bg-alt); |
| 372 | border: 1px solid var(--border-light); |
| 373 | border-radius: var(--radius-sm); |
| 374 | padding: 12px 14px; |
| 375 | text-align: center; |
| 376 | } |
| 377 | .stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; } |
| 378 | .stat-value.c1 { color: var(--mojo); } |
| 379 | .stat-value.c2 { color: var(--success); } |
| 380 | .stat-value.c3 { color: var(--orange); } |
| 381 | .stat-value.c4 { color: var(--cyan); } |
| 382 | .stat-label { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; } |
| 383 | |
| 384 | /* ─── Model Grid ─── */ |
| 385 | .model-grid { |
| 386 | display: grid; |
| 387 | grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); |
| 388 | gap: var(--space-8); |
| 389 | } |
| 390 | .model-card { |
| 391 | background: var(--bg); border: 1px solid var(--border-light); |
| 392 | border-radius: var(--radius-sm); padding: 12px 14px; |
| 393 | cursor: pointer; transition: all var(--transition); |
| 394 | } |
| 395 | .model-card:hover { border-color: var(--mojo); } |
| 396 | .model-card.selected { border-color: var(--mojo); } |
| 397 | .model-card h4 { font-size: 13px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } |
| 398 | .model-card .model-meta { font-size: 11px; color: var(--text-tertiary); } |
| 399 | .model-card .model-size { font-size: 12px; color: var(--mojo); font-weight: 600; } |
| 400 | |
| 401 | /* ─── Charts ─── */ |
| 402 | .chart-wrapper { position: relative; height: 240px; width: 100%; } |
| 403 | .chart-wrapper canvas { width: 100% !important; height: 100% !important; } |
| 404 | |
| 405 | /* ─── Tables ─── */ |
| 406 | .results-table { width: 100%; border-collapse: collapse; font-size: 13px; } |
| 407 | .results-table th { |
| 408 | text-align: left; padding: 8px 12px; |
| 409 | border-bottom: 1px solid var(--border); |
| 410 | color: var(--text-tertiary); font-size: 11px; |
| 411 | text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; |
| 412 | } |
| 413 | .results-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary); } |
| 414 | .results-table tr:hover td { background: var(--mojo-subtle); } |
| 415 | |
| 416 | /* ─── Range Slider ─── */ |
| 417 | input[type="range"] { |
| 418 | width: 100%; height: 4px; -webkit-appearance: none; |
| 419 | background: var(--border); border-radius: 2px; |
| 420 | outline: none; padding: 0; margin: 0; border: none; |
| 421 | } |
| 422 | input[type="range"]::-webkit-slider-thumb { |
| 423 | -webkit-appearance: none; width: 14px; height: 14px; |
| 424 | border-radius: 50%; background: var(--mojo); |
| 425 | cursor: pointer; border: 2px solid var(--bg); |
| 426 | box-shadow: 0 0 4px rgba(108,60,225,0.3); |
| 427 | } |
| 428 | .range-row { display: flex; align-items: center; gap: var(--space-12); } |
| 429 | .range-row input[type="range"] { flex: 1; margin-bottom: 0; } |
| 430 | .range-value { |
| 431 | font-size: 13px; font-weight: 600; color: var(--mojo); |
| 432 | min-width: 36px; text-align: right; font-family: var(--font-mono); |
| 433 | } |
| 434 | |
| 435 | /* ─── Toast ─── */ |
| 436 | .toast { |
| 437 | position: fixed; bottom: 24px; right: 24px; |
| 438 | padding: 10px 20px; border-radius: var(--radius-sm); |
| 439 | font-size: 13px; font-weight: 500; z-index: 1000; |
| 440 | animation: slideUp 0.3s ease; max-width: 360px; |
| 441 | } |
| 442 | .toast.success { background: rgba(25,128,56,0.1); border: 1px solid var(--success); color: var(--success); } |
| 443 | .toast.error { background: rgba(218,30,40,0.1); border: 1px solid var(--warning); color: var(--warning); } |
| 444 | .toast.info { background: var(--mojo-subtle); border: 1px solid var(--mojo); color: var(--mojo); } |
| 445 | @keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } } |
| 446 | |
| 447 | /* ─── Tags / Chips ─── */ |
| 448 | .chip { |
| 449 | display: inline-flex; align-items: center; gap: 4px; |
| 450 | padding: 3px 10px; border-radius: 20px; |
| 451 | font-size: 11px; font-weight: 600; |
| 452 | border: 1px solid var(--border); background: var(--bg); |
| 453 | cursor: pointer; transition: all var(--transition); |
| 454 | } |
| 455 | .chip:hover { border-color: var(--mojo); color: var(--mojo); } |
| 456 | .chip.active { background: var(--mojo-subtle); border-color: var(--mojo); color: var(--mojo); } |
| 457 | |
| 458 | /* ─── Collapsible ─── */ |
| 459 | .collapse-toggle { |
| 460 | cursor: pointer; display: flex; align-items: center; gap: 6px; |
| 461 | font-size: 13px; font-weight: 500; |
| 462 | color: var(--text-tertiary); margin-bottom: var(--space-8); |
| 463 | transition: color var(--transition); |
| 464 | } |
| 465 | .collapse-toggle:hover { color: var(--text); } |
| 466 | .collapse-toggle .arrow { transition: transform 0.2s; font-size: 10px; } |
| 467 | .collapse-toggle.open .arrow { transform: rotate(90deg); } |
| 468 | .collapse-body { display: none; } |
| 469 | .collapse-body.open { display: block; animation: fadeSlide 0.15s ease; } |
| 470 | |
| 471 | /* ─── Template Cards ─── */ |
| 472 | .template-card { |
| 473 | background: var(--bg); border: 1px solid var(--border-light); |
| 474 | border-radius: var(--radius-sm); padding: 12px 14px; |
| 475 | cursor: pointer; transition: all var(--transition); |
| 476 | } |
| 477 | .template-card:hover { border-color: var(--mojo); } |
| 478 | .template-card.selected { border-color: var(--mojo); background: var(--mojo-subtle); } |
| 479 | .template-card h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; } |
| 480 | .template-card p { font-size: 12px; color: var(--text-tertiary); line-height: 1.5; } |
| 481 | .template-card .template-tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; } |
| 482 | |
| 483 | /* ─── Quant Compare ─── */ |
| 484 | .quant-card { text-align: center; padding: var(--space-16); background: var(--bg); border: 1px solid var(--border-light); border-radius: var(--radius-sm); transition: all var(--transition); } |
| 485 | .quant-card:hover { border-color: var(--mojo); } |
| 486 | .quant-card .quant-name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; } |
| 487 | .quant-card .quant-bits { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; } |
| 488 | .quant-card .quant-speed { font-size: 20px; font-weight: 700; color: var(--success); margin-top: 8px; } |
| 489 | .quant-card .quant-size { font-size: 12px; color: var(--mojo); font-weight: 600; } |
| 490 | |
| 491 | /* ─── Dialog ─── */ |
| 492 | .dialog-overlay { |
| 493 | position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 1000; |
| 494 | display: flex; align-items: center; justify-content: center; |
| 495 | animation: fadeIn 0.2s ease; |
| 496 | } |
| 497 | .dialog { |
| 498 | background: var(--bg); border: 1px solid var(--border); |
| 499 | border-radius: var(--radius); padding: 28px; |
| 500 | max-width: 520px; width: 90%; |
| 501 | } |
| 502 | .dialog h3 { margin-bottom: var(--space-16); font-size: 16px; font-weight: 600; } |
| 503 | .dialog-actions { display: flex; gap: var(--space-8); justify-content: flex-end; margin-top: 20px; } |
| 504 | @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } |
| 505 | |
| 506 | /* ─── Status Colors ─── */ |
| 507 | .text-green { color: var(--success); } |
| 508 | .text-red { color: var(--warning); } |
| 509 | .text-accent { color: var(--mojo); } |
| 510 | .text-dim { color: var(--text-tertiary); } |
| 511 | .text-yellow { color: #B8860B; } |
| 512 | .text-orange { color: var(--orange); } |
| 513 | |
| 514 | /* ─── Progress Bar ─── */ |
| 515 | .progress-bar { height: 6px; border-radius: 3px; background: var(--border-light); overflow: hidden; margin: var(--space-8) 0; } |
| 516 | .progress-bar-fill { height: 100%; border-radius: 3px; background: var(--mojo); transition: width 0.3s ease; width: 0%; } |
| 517 | .progress-text { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; display: flex; justify-content: space-between; } |
| 518 | .progress-step { font-size: 11px; color: var(--mojo); font-weight: 600; } |
| 519 | |
| 520 | /* ─── Gauge (SVG) ─── */ |
| 521 | .gauge-svg { width: 200px; height: 110px; display: block; margin: 0 auto; } |
| 522 | |
| 523 | /* ─── Engine Pills ─── */ |
| 524 | .engine-pills { display: flex; gap: 6px; margin: var(--space-8) 0; } |
| 525 | .engine-pill { |
| 526 | padding: 4px 12px; border-radius: 20px; |
| 527 | border: 1px solid var(--border); background: var(--bg); |
| 528 | color: var(--text-tertiary); font-size: 12px; font-weight: 500; |
| 529 | cursor: pointer; transition: all var(--transition); |
| 530 | } |
| 531 | .engine-pill:hover { border-color: var(--mojo); color: var(--mojo); } |
| 532 | .engine-pill.active { background: var(--mojo-subtle); border-color: var(--mojo); color: var(--mojo); } |
| 533 | |
| 534 | /* ─── Quant Grid ─── */ |
| 535 | .quant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: var(--space-8); margin: var(--space-8) 0; } |
| 536 | .quant-grid-item { background: var(--bg); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; transition: all var(--transition); display: flex; align-items: center; gap: 8px; } |
| 537 | .quant-grid-item:hover { border-color: var(--mojo); } |
| 538 | .quant-grid-item.selected { border-color: var(--success); background: rgba(25,128,56,0.06); } |
| 539 | .quant-grid-item input { width: auto; margin: 0; accent-color: var(--mojo); } |
| 540 | .quant-grid-item .qg-info { flex: 1; } |
| 541 | .quant-grid-item .qg-name { font-size: 12px; font-weight: 600; } |
| 542 | .quant-grid-item .qg-meta { font-size: 10px; color: var(--text-tertiary); margin-top: 1px; } |
| 543 | |
| 544 | /* ─── Compare Table ─── */ |
| 545 | .compare-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: var(--space-8) 0; } |
| 546 | .compare-table th { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); color: var(--text-tertiary); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; } |
| 547 | .compare-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); color: var(--text-secondary); } |
| 548 | .compare-table tr:last-child td { border-bottom: none; } |
| 549 | .compare-table .positive { color: var(--success); } |
| 550 | .compare-table .negative { color: var(--warning); } |
| 551 | |
| 552 | /* ─── Memory Card ─── */ |
| 553 | .mem-card { display: flex; gap: var(--space-12); align-items: center; padding: 8px 12px; background: var(--bg-alt); border: 1px solid var(--border-light); border-radius: var(--radius-sm); margin: var(--space-8) 0; } |
| 554 | .mem-card .mem-icon { font-size: 20px; } |
| 555 | .mem-card .mem-info { flex: 1; } |
| 556 | .mem-card .mem-info .mem-title { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; } |
| 557 | .mem-card .mem-info .mem-value { font-size: 16px; font-weight: 600; color: var(--mojo); } |
| 558 | |
| 559 | /* ─── Auto-Tune ─── */ |
| 560 | .tune-phase { font-size: 13px; color: var(--mojo); font-weight: 600; margin-bottom: 4px; } |
| 561 | .tune-progress-text { font-size: 12px; color: var(--text-tertiary); } |
| 562 | .tune-result-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; } |
| 563 | .tune-result-row:last-child { border-bottom: none; } |
| 564 | .tune-result-row .tune-label { color: var(--text-tertiary); } |
| 565 | .tune-result-row .tune-value { color: var(--text); font-weight: 600; } |
| 566 | |
| 567 | /* ─── Dynamic Quant Options ─── */ |
| 568 | .dynamic-quant-options { display: flex; gap: var(--space-12); align-items: center; flex-wrap: wrap; margin: var(--space-8) 0; padding: 8px 12px; background: var(--bg-alt); border: 1px solid var(--border-light); border-radius: var(--radius-sm); } |
| 569 | .dynamic-quant-options label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 6px; cursor: pointer; } |
| 570 | .dynamic-quant-options input[type="file"] { margin: 0; padding: 4px 8px; font-size: 11px; display: none; } |
| 571 | .dynamic-quant-options input[type="number"] { width: 80px; margin: 0; padding: 4px 8px; font-size: 12px; } |
| 572 | |
| 573 | /* ─── Download Links ─── */ |
| 574 | .download-links { margin-top: var(--space-8); } |
| 575 | .download-links a { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; background: var(--bg-alt); border: 1px solid var(--border-light); border-radius: var(--radius-sm); color: var(--text); font-size: 12px; text-decoration: none; transition: all var(--transition); margin: 2px 4px 2px 0; } |
| 576 | .download-links a:hover { border-color: var(--mojo); color: var(--mojo); } |
| 577 | |
| 578 | /* ─── Dataset Stats ─── */ |
| 579 | .stat { padding: 6px 0; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); } |
| 580 | .stat:last-child { border-bottom: none; } |
| 581 | .stat-value { color: var(--text); font-weight: 600; font-size: 13px; } |
| 582 | |
| 583 | /* ─── Gauge (CSS conic) ─── */ |
| 584 | .gauge { position: relative; width: 200px; height: 100px; margin: 0 auto; overflow: hidden; } |
| 585 | .gauge-bg { width: 200px; height: 200px; border-radius: 50%; background: conic-gradient(var(--border) 0deg 180deg, transparent 180deg 360deg); position: absolute; top: 0; } |
| 586 | .gauge-fill { width: 200px; height: 200px; border-radius: 50%; background: conic-gradient(var(--mojo) 0deg 0deg, transparent 0deg 360deg); position: absolute; top: 0; transition: background .5s ease; } |
| 587 | .gauge-cover { width: 150px; height: 150px; border-radius: 50%; background: var(--bg); position: absolute; top: 25px; left: 25px; display: flex; flex-direction: column; align-items: center; justify-content: center; } |
| 588 | .gauge-value { font-size: 26px; font-weight: 700; color: var(--mojo); } |
| 589 | .gauge-label { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; } |
| 590 | |
| 591 | /* ─── Bench Checks ─── */ |
| 592 | .bench-check { display:inline-flex;align-items:center;gap:3px;cursor:pointer;font-size:12px;padding:2px 8px;background:var(--bg-alt);border-radius:12px;transition:.15s; } |
| 593 | .bench-check:hover { background:var(--border-light); } |
| 594 | .bench-check input { accent-color:var(--mojo); } |
| 595 | .result-table { border-collapse:collapse; } |
| 596 | .result-table th,.result-table td { padding:4px 8px;text-align:left;border-bottom:1px solid var(--border); } |
| 597 | .result-table tr:last-child td { border-bottom:none; } |
| 598 | |
| 599 | /* ─── Responsive ─── */ |
| 600 | @media (max-width: 900px) { |
| 601 | .sidebar { width: 56px; } |
| 602 | .sidebar-header .logo-text { font-size: 0; } |
| 603 | .sidebar-header .logo-text::before { content: '🦙'; font-size: 16px; } |
| 604 | .sidebar-header .ver { display: none; } |
| 605 | .nav-item span:not(.nav-icon) { display: none; } |
| 606 | .nav-badge { display: none; } |
| 607 | .backend-info { display: none; } |
| 608 | .content { padding: var(--space-16); } |
| 609 | } |
| 610 | @media (max-width: 720px) { |
| 611 | .sidebar { display: none; } |
| 612 | .row { flex-direction: column; } |
| 613 | .chat-container { height: 360px; } |
| 614 | } |
| 615 | |
| 616 | /* ── Dark theme overrides ── */ |
| 617 | [data-theme="dark"] .theme-toggle, :root:not([data-theme="light"]) .theme-toggle { |
| 618 | border-color: var(--border); |
| 619 | } |
| 620 | [data-theme="dark"] .theme-toggle:hover, :root:not([data-theme="light"]) .theme-toggle:hover { |
| 621 | border-color: var(--mojo); background: var(--mojo-subtle); color: var(--mojo-light); |
| 622 | } |
| 623 | [data-theme="dark"] pre, :root:not([data-theme="light"]) pre { background: #0D0D14; } |
| 624 | [data-theme="dark"] .msg-avatar.user, :root:not([data-theme="light"]) .msg-avatar.user { background: rgba(90,168,255,0.15); } |
| 625 | [data-theme="dark"] .msg-avatar.assistant, :root:not([data-theme="light"]) .msg-avatar.assistant { background: rgba(139,92,246,0.15); } |
| 626 | [data-theme="dark"] .progress-bar-fill, :root:not([data-theme="light"]) .progress-bar-fill { background: var(--mojo-light); } |
| 627 | </style> |
| 628 | </head> |
| 629 | <body> |
| 630 | <a href="#mainContent" class="skip-link">Skip to content</a> |
| 631 | <div class="app"> |
| 632 | <!-- Sidebar Navigation --> |
| 633 | <div class="sidebar"> |
| 634 | <div class="sidebar-header"> |
| 635 | <a href="../index.html"><span class="logo-text">Mojo<span>Llama</span></span></a> |
| 636 | <div class="ver">Studio v0.3.0</div> |
| 637 | </div> |
| 638 | <div class="sidebar-nav"> |
| 639 | <div class="nav-item active" data-tab="chat"> |
| 640 | <span class="nav-icon">💬</span><span>Chat</span> |
| 641 | </div> |
| 642 | <div class="nav-item" data-tab="train"> |
| 643 | <span class="nav-icon">🎓</span><span>Train</span> |
| 644 | <span class="nav-badge">LoRA</span> |
| 645 | </div> |
| 646 | <div class="nav-item" data-tab="dataset"> |
| 647 | <span class="nav-icon">📊</span><span>Dataset</span> |
| 648 | </div> |
| 649 | <div class="nav-item" data-tab="export"> |
| 650 | <span class="nav-icon">📤</span><span>Export</span> |
| 651 | </div> |
| 652 | <div class="nav-item" data-tab="benchmark"> |
| 653 | <span class="nav-icon">⚡</span><span>Benchmark</span> |
| 654 | </div> |
| 655 | <div class="nav-item" data-tab="autotune"> |
| 656 | <span class="nav-icon">⚙</span><span>Auto-Tune</span> |
| 657 | </div> |
| 658 | <div class="nav-item" data-tab="evaluate"> |
| 659 | <span class="nav-icon">🎯</span><span>Evaluate</span> |
| 660 | <span class="nav-badge">New</span> |
| 661 | </div> |
| 662 | <div class="nav-item" data-tab="quantize"> |
| 663 | <span class="nav-icon">🔮</span><span>Quantize</span> |
| 664 | <span class="nav-badge">New</span> |
| 665 | </div> |
| 666 | <div class="nav-item" data-tab="merge"> |
| 667 | <span class="nav-icon">🔗</span><span>Merge</span> |
| 668 | </div> |
| 669 | <div class="nav-item" data-tab="checkpoints"> |
| 670 | <span class="nav-icon">💾</span><span>Checkpoints</span> |
| 671 | </div> |
| 672 | <div class="nav-item" data-tab="templates"> |
| 673 | <span class="nav-icon">📋</span><span>Templates</span> |
| 674 | <span class="nav-badge">New</span> |
| 675 | </div> |
| 676 | <div class="nav-item" data-tab="hub"> |
| 677 | <span class="nav-icon">🤗</span><span>HF Hub</span> |
| 678 | </div> |
| 679 | <div class="nav-item" data-tab="experiments"> |
| 680 | <span class="nav-icon">🔬</span><span>Experiments</span> |
| 681 | <span class="nav-badge">New</span> |
| 682 | </div> |
| 683 | <div class="nav-item" data-tab="model-cards"> |
| 684 | <span class="nav-icon">🆔</span><span>Model Cards</span> |
| 685 | <span class="nav-badge">New</span> |
| 686 | </div> |
| 687 | </div> |
| 688 | <div class="sidebar-footer"> |
| 689 | <div class="backend-status" onclick="showServerSettings()" title="Click to configure server"> |
| 690 | <span class="status-dot offline" id="statusDot"></span> |
| 691 | <div class="backend-info"> |
| 692 | <span class="backend-name" id="backendName">offline</span> |
| 693 | <span class="backend-uptime" id="backendEngine"></span> |
| 694 | <span class="backend-uptime" id="backendSpeed"></span> |
| 695 | </div> |
| 696 | <span class="btn-icon" style="border:none;padding:0;font-size:12px" title="Settings">⚙</span> |
| 697 | </div> |
| 698 | </div> |
| 699 | </div> |
| 700 | |
| 701 | <!-- Main Content --> |
| 702 | <div class="main"> |
| 703 | <div class="topbar"> |
| 704 | <div class="topbar-title" id="topbarTitle">💬 Chat</div> |
| 705 | <div class="topbar-actions"> |
| 706 | <button class="theme-toggle" id="studioThemeToggle" aria-label="Toggle dark mode" style="background:none;border:1px solid var(--border);border-radius:var(--radius-sm);width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:var(--text-secondary);transition:all var(--transition);padding:0;"> |
| 707 | <svg class="icon-moon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg> |
| 708 | <svg class="icon-sun" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:none"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg> |
| 709 | </button> |
| 710 | <span class="btn-icon" onclick="refreshAll()" title="Refresh">↻</span> |
| 711 | <span class="btn-icon" onclick="showServerSettings()" title="Server settings">⚙</span> |
| 712 | </div> |
| 713 | </div> |
| 714 | |
| 715 | <div class="content" id="mainContent"> |
| 716 | |
| 717 | <!-- ═══════════ OFFLINE BANNER ═══════════ --> |
| 718 | <div id="offlineBanner" class="card" style="display:none;border-color:var(--warning);margin-bottom:16px;padding:16px 20px;"> |
| 719 | <div style="display:flex;align-items:center;gap:12px;"> |
| 720 | <span style="font-size:24px;">🔌</span> |
| 721 | <div style="flex:1"> |
| 722 | <div style="font-weight:600;font-size:14px;">Server Offline</div> |
| 723 | <div style="font-size:12px;color:var(--text-tertiary);margin-top:2px;"> |
| 724 | Cannot connect to <span class="text-code" id="offlineApiUrl"></span>.<br> |
| 725 | Start your MojoLlama server, then configure the URL below. |
| 726 | </div> |
| 727 | </div> |
| 728 | <button class="btn btn-primary" onclick="showServerSettings()" style="flex-shrink:0;"> |
| 729 | ⚙ Configure |
| 730 | </button> |
| 731 | <button class="btn btn-dim" onclick="refreshAll()" style="flex-shrink:0;"> |
| 732 | Retry |
| 733 | </button> |
| 734 | </div> |
| 735 | </div> |
| 736 | |
| 737 | <!-- ═══════════ CHAT ═══════════ --> |
| 738 | <div class="panel active" id="panel-chat"> |
| 739 | <div class="row mb-12"> |
| 740 | <div style="flex:0 0 auto"> |
| 741 | <label>Model</label> |
| 742 | <select id="chatModel" style="width:220px;margin-bottom:0"> |
| 743 | <option value="">Select model...</option> |
| 744 | </select> |
| 745 | </div> |
| 746 | <div style="flex:0 0 auto"> |
| 747 | <label>Temperature</label> |
| 748 | <div class="range-row"> |
| 749 | <input type="range" id="chatTemp" min="0" max="2" step="0.05" value="0.7" |
| 750 | oninput="document.getElementById('chatTempVal').textContent=this.value"> |
| 751 | <span class="range-value" id="chatTempVal">0.7</span> |
| 752 | </div> |
| 753 | </div> |
| 754 | <div style="flex:0 0 auto"> |
| 755 | <label>Top P</label> |
| 756 | <div class="range-row"> |
| 757 | <input type="range" id="chatTopP" min="0" max="1" step="0.05" value="0.9" |
| 758 | oninput="document.getElementById('chatTopPVal').textContent=this.value"> |
| 759 | <span class="range-value" id="chatTopPVal">0.9</span> |
| 760 | </div> |
| 761 | </div> |
| 762 | <div style="flex:0 0 auto"> |
| 763 | <label>Max Tokens</label> |
| 764 | <input type="number" id="chatMaxTokens" value="512" style="width:80px;margin-bottom:0"> |
| 765 | </div> |
| 766 | <div style="flex:0 0 auto;display:flex;align-items:flex-end;gap:6px;margin-left:auto"> |
| 767 | <button class="btn btn-dim btn-sm" onclick="clearChat()">Clear</button> |
| 768 | </div> |
| 769 | </div> |
| 770 | |
| 771 | <!-- No models hint --> |
| 772 | <div id="noModelsHint" class="card" style="display:none;border-color:var(--orange);padding:12px 16px;margin-bottom:12px;"> |
| 773 | <div style="display:flex;align-items:center;gap:10px;"> |
| 774 | <span style="font-size:18px;">📡</span> |
| 775 | <div style="flex:1;font-size:13px;"> |
| 776 | <strong>No models found</strong> — |
| 777 | Start the MojoLlama server with GGUF models in the working directory, |
| 778 | or <a href="#" onclick="showServerSettings();return false" style="color:var(--accent)">configure a different server URL</a>. |
| 779 | </div> |
| 780 | <button class="btn btn-dim btn-xs" onclick="refreshAll()">Retry</button> |
| 781 | </div> |
| 782 | </div> |
| 783 | |
| 784 | <div class="card" style="padding:0;margin-bottom:12px"> |
| 785 | <div class="chat-container"> |
| 786 | <div class="chat-messages" id="chatMessages"> |
| 787 | <div class="msg"> |
| 788 | <div class="msg-row"> |
| 789 | <div class="msg-avatar assistant">M</div> |
| 790 | <div class="msg-body"> |
| 791 | <div class="msg-name assistant">MojoLlama <span class="msg-meta">ready</span></div> |
| 792 | <div class="msg-text">Hello! I'm <strong>MojoLlama</strong>. Select a model and start chatting.</div> |
| 793 | </div> |
| 794 | </div> |
| 795 | </div> |
| 796 | </div> |
| 797 | <div class="chat-input-area"> |
| 798 | <textarea id="chatInput" placeholder="Type a message... (Shift+Enter for new line)" rows="1" |
| 799 | oninput="this.style.height='auto';this.style.height=this.scrollHeight+'px'"></textarea> |
| 800 | <button class="btn btn-primary" onclick="sendChat()" id="chatSendBtn">Send</button> |
| 801 | <button class="btn btn-red btn-sm" onclick="stopChat()" id="chatStopBtn" style="display:none">Stop</button> |
| 802 | </div> |
| 803 | </div> |
| 804 | </div> |
| 805 | |
| 806 | <div class="card" style="padding:10px 16px"> |
| 807 | <div class="collapse-toggle" onclick="toggleCollapse(this)"> |
| 808 | <span class="arrow">▶</span> System Prompt & Advanced |
| 809 | </div> |
| 810 | <div class="collapse-body" id="chatAdvanced"> |
| 811 | <label>System Prompt</label> |
| 812 | <textarea id="chatSystemPrompt" rows="3" placeholder="You are a helpful AI assistant...">You are a helpful, knowledgeable AI assistant powered by MojoLlama.</textarea> |
| 813 | <div class="row"> |
| 814 | <div> |
| 815 | <label>Frequency Penalty</label> |
| 816 | <div class="range-row"> |
| 817 | <input type="range" id="chatFreqPen" min="0" max="2" step="0.1" value="0" |
| 818 | oninput="document.getElementById('chatFreqPenVal').textContent=this.value"> |
| 819 | <span class="range-value" id="chatFreqPenVal">0</span> |
| 820 | </div> |
| 821 | </div> |
| 822 | <div> |
| 823 | <label>Presence Penalty</label> |
| 824 | <div class="range-row"> |
| 825 | <input type="range" id="chatPresPen" min="0" max="2" step="0.1" value="0" |
| 826 | oninput="document.getElementById('chatPresPenVal').textContent=this.value"> |
| 827 | <span class="range-value" id="chatPresPenVal">0</span> |
| 828 | </div> |
| 829 | </div> |
| 830 | <div> |
| 831 | <label>Repeat Penalty</label> |
| 832 | <div class="range-row"> |
| 833 | <input type="range" id="chatRepeatPen" min="1" max="2" step="0.05" value="1.1" |
| 834 | oninput="document.getElementById('chatRepeatPenVal').textContent=this.value"> |
| 835 | <span class="range-value" id="chatRepeatPenVal">1.1</span> |
| 836 | </div> |
| 837 | </div> |
| 838 | </div> |
| 839 | </div> |
| 840 | </div> |
| 841 | <div style="font-size:12px;color:var(--dim);display:flex;gap:16px;flex-wrap:wrap"> |
| 842 | <span>⏎ <kbd style="background:var(--border);padding:1px 6px;border-radius:4px;font-size:10px">Enter</kbd> to send, Shift+Enter for newline</span> |
| 843 | <span>⚡ Streaming: <span class="text-green">ON</span></span> |
| 844 | <span id="chatStats">0 messages</span> |
| 845 | </div> |
| 846 | </div> |
| 847 | |
| 848 | <!-- ═══════════ TRAIN ═══════════ --> |
| 849 | <div class="panel" id="panel-train"> |
| 850 | <div class="card"> |
| 851 | <div class="card-header"> |
| 852 | <h3><span class="icon">🎓</span> LoRA Fine-tuning</h3> |
| 853 | <div style="display:flex;gap:6px;align-items:center"> |
| 854 | <select id="trainTemplate" style="width:auto;margin:0;padding:4px 10px;font-size:12px;min-width:160px" |
| 855 | onchange="applyTrainTemplate(this.value)"> |
| 856 | <option value="">Custom Config</option> |
| 857 | <option value="light">Light (r=8, 100 steps)</option> |
| 858 | <option value="balanced">Balanced (r=16, 500 steps)</option> |
| 859 | <option value="deep">Deep (r=64, 2000 steps)</option> |
| 860 | <option value="qlora">QLoRA (r=32, 1000 steps)</option> |
| 861 | </select> |
| 862 | <span class="badge badge-pro">LoRA</span> |
| 863 | </div> |
| 864 | </div> |
| 865 | <div class="row mb-12"> |
| 866 | <div> |
| 867 | <label>Base Model</label> |
| 868 | <select id="trainModel"><option value="">Select a model...</option></select> |
| 869 | </div> |
| 870 | <div> |
| 871 | <label>Dataset (JSONL)</label> |
| 872 | <div style="display:flex;gap:8px"> |
| 873 | <input type="text" id="trainData" placeholder="dataset.jsonl or path" style="flex:1;margin:0"> |
| 874 | <button class="btn btn-dim btn-xs" onclick="document.getElementById('trainData').value='/tmp/e2e_test.jsonl'">Test</button> |
| 875 | </div> |
| 876 | </div> |
| 877 | </div> |
| 878 | <div class="row mb-12"> |
| 879 | <div> |
| 880 | <label>LoRA Rank (r)</label> |
| 881 | <div class="range-row"> |
| 882 | <input type="range" id="trainRank" min="1" max="128" value="16" |
| 883 | oninput="document.getElementById('trainRankVal').textContent=this.value"> |
| 884 | <span class="range-value" id="trainRankVal">16</span> |
| 885 | </div> |
| 886 | </div> |
| 887 | <div> |
| 888 | <label>LoRA Alpha</label> |
| 889 | <input type="number" id="trainAlpha" value="32"> |
| 890 | </div> |
| 891 | <div> |
| 892 | <label>Learning Rate</label> |
| 893 | <input type="text" id="trainLR" value="2e-4"> |
| 894 | </div> |
| 895 | <div> |
| 896 | <label>LR Scheduler</label> |
| 897 | <select id="trainScheduler"> |
| 898 | <option value="cosine">Cosine</option> |
| 899 | <option value="linear">Linear</option> |
| 900 | <option value="constant">Constant</option> |
| 901 | <option value="cosine_restarts">Cosine w/ Restarts</option> |
| 902 | </select> |
| 903 | </div> |
| 904 | </div> |
| 905 | <div class="row mb-12"> |
| 906 | <div> |
| 907 | <label>Steps</label> |
| 908 | <input type="number" id="trainSteps" value="100"> |
| 909 | </div> |
| 910 | <div> |
| 911 | <label>Batch Size</label> |
| 912 | <input type="number" id="trainBatch" value="4"> |
| 913 | </div> |
| 914 | <div> |
| 915 | <label>Gradient Accumulation</label> |
| 916 | <input type="number" id="trainGradAccum" value="1"> |
| 917 | </div> |
| 918 | <div> |
| 919 | <label>Warmup Steps</label> |
| 920 | <input type="number" id="trainWarmup" value="10"> |
| 921 | </div> |
| 922 | </div> |
| 923 | |
| 924 | <div class="collapse-toggle" onclick="toggleCollapse(this)"> |
| 925 | <span class="arrow">▶</span> Advanced Parameters |
| 926 | </div> |
| 927 | <div class="collapse-body" id="trainAdvanced"> |
| 928 | <div class="row mb-12"> |
| 929 | <div> |
| 930 | <label>Weight Decay</label> |
| 931 | <input type="text" id="trainWeightDecay" value="0.01"> |
| 932 | </div> |
| 933 | <div> |
| 934 | <label>Max Context Length</label> |
| 935 | <input type="number" id="trainCtxLen" value="2048"> |
| 936 | </div> |
| 937 | <div> |
| 938 | <label>Target Modules</label> |
| 939 | <input type="text" id="trainModules" placeholder="q_proj,v_proj,k_proj,o_proj" value="q_proj,v_proj"> |
| 940 | </div> |
| 941 | <div> |
| 942 | <label>LoRA Dropout</label> |
| 943 | <input type="text" id="trainDropout" value="0.05"> |
| 944 | </div> |
| 945 | </div> |
| 946 | <div class="row mb-12"> |
| 947 | <div> |
| 948 | <label>Save Checkpoint Every N Steps</label> |
| 949 | <input type="number" id="trainCheckpointEvery" value="100"> |
| 950 | </div> |
| 951 | <div> |
| 952 | <label>Resume from Checkpoint</label> |
| 953 | <input type="text" id="trainResume" placeholder="path/to/checkpoint"> |
| 954 | </div> |
| 955 | <div> |
| 956 | <label>Seed</label> |
| 957 | <input type="number" id="trainSeed" value="42"> |
| 958 | </div> |
| 959 | <div> |
| 960 | <label>Evaluation Steps</label> |
| 961 | <input type="number" id="trainEvalSteps" value="0"> |
| 962 | </div> |
| 963 | </div> |
| 964 | <div class="row"> |
| 965 | <div style="flex:0 0 auto;display:flex;gap:12px;align-items:center"> |
| 966 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer"> |
| 967 | <input type="checkbox" id="trainFlashAttn" checked style="width:auto;margin:0"> Flash Attention |
| 968 | </label> |
| 969 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer"> |
| 970 | <input type="checkbox" id="trainFp16" checked style="width:auto;margin:0"> FP16 |
| 971 | </label> |
| 972 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer"> |
| 973 | <input type="checkbox" id="trainGradientCheckpointing" style="width:auto;margin:0"> Gradient Checkpointing |
| 974 | </label> |
| 975 | </div> |
| 976 | </div> |
| 977 | </div> |
| 978 | |
| 979 | <div style="display:flex;gap:8px;margin-top:12px"> |
| 980 | <button class="btn btn-green" onclick="startTraining()" id="trainStartBtn">▶ Start Training</button> |
| 981 | <button class="btn btn-red" onclick="stopTraining()" id="trainStopBtn" disabled>■ Stop</button> |
| 982 | <button class="btn btn-outline btn-sm" onclick="resetTrainConfig()">Reset</button> |
| 983 | </div> |
| 984 | </div> |
| 985 | |
| 986 | <div class="row mb-8"> |
| 987 | <div class="col-3"> |
| 988 | <div class="card"> |
| 989 | <div class="card-header"> |
| 990 | <h3><span class="icon">📉</span> Training Metrics</h3> |
| 991 | <span class="badge badge-new" id="trainStatusBadge">idle</span> |
| 992 | </div> |
| 993 | <div class="chart-wrapper"><canvas id="lossChart"></canvas></div> |
| 994 | <div class="stats-grid mt-8"> |
| 995 | <div class="stat-card"><div class="stat-value c1" id="trainStep">0</div><div class="stat-label">Step</div></div> |
| 996 | <div class="stat-card"><div class="stat-value c2" id="trainLoss">—</div><div class="stat-label">Loss</div></div> |
| 997 | <div class="stat-card"><div class="stat-value c3" id="trainProgress">0%</div><div class="stat-label">Progress</div></div> |
| 998 | <div class="stat-card"><div class="stat-value c4" id="trainSpeed">—</div><div class="stat-label">Steps/s</div></div> |
| 999 | </div> |
| 1000 | </div> |
| 1001 | </div> |
| 1002 | <div style="flex:1"> |
| 1003 | <div class="card"> |
| 1004 | <div class="card-header"><h3><span class="icon">📜</span> Training Log</h3></div> |
| 1005 | <div class="log" id="trainLog" style="max-height:420px">Training not started.</div> |
| 1006 | </div> |
| 1007 | </div> |
| 1008 | </div> |
| 1009 | </div> |
| 1010 | |
| 1011 | <!-- ═══════════ DATASET ═══════════ --> |
| 1012 | <div class="panel" id="panel-dataset"> |
| 1013 | <div class="row mb-8 gap-16"> |
| 1014 | <!-- Create Dataset --> |
| 1015 | <div class="col-2"> |
| 1016 | <div class="card"> |
| 1017 | <div class="card-header"><h3><span class="icon">📝</span> Create Dataset</h3></div> |
| 1018 | <label>Format</label> |
| 1019 | <select id="dsFormat" onchange="updateDatasetForm()"> |
| 1020 | <option value="alpaca">Alpaca (instruction/input/output)</option> |
| 1021 | <option value="sharegpt">ShareGPT (conversations)</option> |
| 1022 | <option value="openai">OpenAI (messages)</option> |
| 1023 | <option value="preference">Preference (chosen/rejected)</option> |
| 1024 | <option value="jsonl">Simple JSONL (prompt/completion)</option> |
| 1025 | </select> |
| 1026 | <div id="dsFormFields"> |
| 1027 | <label id="dsField1Label">Instruction</label> |
| 1028 | <textarea id="dsField1" rows="5" placeholder="What is machine learning? Explain transformers How does attention work?"></textarea> |
| 1029 | <label id="dsField2Label">Input (optional)</label> |
| 1030 | <textarea id="dsField2" rows="2" placeholder="Context or input text per line (leave blank if none)"></textarea> |
| 1031 | </div> |
| 1032 | <label>Output file</label> |
| 1033 | <input type="text" id="dsOutput" value="dataset.jsonl"> |
| 1034 | <button class="btn btn-primary" onclick="createDataset()">Create Dataset</button> |
| 1035 | <div class="log mt-8" id="dsLog" style="max-height:120px">Ready.</div> |
| 1036 | </div> |
| 1037 | |
| 1038 | <!-- Format Converter --> |
| 1039 | <div class="card"> |
| 1040 | <div class="card-header"><h3><span class="icon">🔄</span> Format Converter</h3></div> |
| 1041 | <label>Input file</label> |
| 1042 | <input type="text" id="convInput" placeholder="dataset.jsonl"> |
| 1043 | <label>Target format</label> |
| 1044 | <select id="convFormat"> |
| 1045 | <option value="openai">OpenAI (messages)</option> |
| 1046 | <option value="alpaca">Alpaca (instruction/input/output)</option> |
| 1047 | <option value="sharegpt">ShareGPT (conversations)</option> |
| 1048 | <option value="preference">Preference (chosen/rejected)</option> |
| 1049 | <option value="jsonl">Simple JSONL</option> |
| 1050 | </select> |
| 1051 | <label>Output file</label> |
| 1052 | <input type="text" id="convOutput" value="converted.jsonl"> |
| 1053 | <button class="btn btn-primary" onclick="convertDataset()">🔄 Convert</button> |
| 1054 | <div class="log mt-8" id="convLog" style="max-height:80px">Ready.</div> |
| 1055 | </div> |
| 1056 | </div> |
| 1057 | |
| 1058 | <div style="flex:1"> |
| 1059 | <!-- Auto-Label --> |
| 1060 | <div class="card"> |
| 1061 | <div class="card-header"> |
| 1062 | <h3><span class="icon">✨</span> Auto-Label Dataset</h3> |
| 1063 | <span class="badge badge-new">Auto</span> |
| 1064 | </div> |
| 1065 | <label>Use a loaded model to auto-generate completions with confidence scoring</label> |
| 1066 | <div class="row mb-8"> |
| 1067 | <div> |
| 1068 | <label>Model</label> |
| 1069 | <select id="dsModel"><option value="">Select model...</option></select> |
| 1070 | </div> |
| 1071 | <div> |
| 1072 | <label>Input JSONL</label> |
| 1073 | <input type="text" id="dsInputFile" placeholder="prompts.jsonl"> |
| 1074 | </div> |
| 1075 | <div> |
| 1076 | <label>Output</label> |
| 1077 | <input type="text" id="dsOutputFile" value="labeled.jsonl"> |
| 1078 | </div> |
| 1079 | </div> |
| 1080 | <div class="row mb-8"> |
| 1081 | <div> |
| 1082 | <label>Max tokens</label> |
| 1083 | <input type="number" id="dsMaxTokens" value="256" style="width:100px"> |
| 1084 | </div> |
| 1085 | <div> |
| 1086 | <label>Temperature</label> |
| 1087 | <input type="number" id="dsTemperature" value="0.7" step="0.1" min="0" max="2" style="width:80px"> |
| 1088 | </div> |
| 1089 | <div> |
| 1090 | <label>Confidence threshold</label> |
| 1091 | <input type="number" id="dsConfThreshold" value="0.0" step="0.05" min="0" max="1" style="width:80px"> |
| 1092 | </div> |
| 1093 | <div> |
| 1094 | <label>Batch size</label> |
| 1095 | <input type="number" id="dsBatchSize" value="1" min="1" max="8" style="width:80px"> |
| 1096 | </div> |
| 1097 | </div> |
| 1098 | <button class="btn btn-green" onclick="autoLabel()" id="dsAutoBtn">✨ Auto-Label Dataset</button> |
| 1099 | <div class="log mt-8" id="dsAutoLog" style="max-height:120px">Ready.</div> |
| 1100 | </div> |
| 1101 | |
| 1102 | <!-- Dataset Stats --> |
| 1103 | <div class="card" id="dsStatsCard" style="display:none"> |
| 1104 | <div class="card-header"> |
| 1105 | <h3><span class="icon">📊</span> Dataset Statistics</h3> |
| 1106 | <button class="btn btn-dim btn-xs" onclick="document.getElementById('dsStatsCard').style.display='none'">✕</button> |
| 1107 | </div> |
| 1108 | <div id="dsStatsContent">Loading...</div> |
| 1109 | </div> |
| 1110 | |
| 1111 | <!-- Dataset Split --> |
| 1112 | <div class="card"> |
| 1113 | <div class="card-header"><h3><span class="icon">✂️</span> Split Dataset</h3></div> |
| 1114 | <div class="row mb-8"> |
| 1115 | <div><label>Dataset</label><input type="text" id="splitInput" placeholder="dataset.jsonl"></div> |
| 1116 | <div><label>Train</label><input type="number" id="splitTrain" value="80" style="width:70px"></div> |
| 1117 | <div><label>Val</label><input type="number" id="splitVal" value="10" style="width:70px"></div> |
| 1118 | <div><label>Test</label><input type="number" id="splitTest" value="10" style="width:70px"></div> |
| 1119 | </div> |
| 1120 | <button class="btn btn-primary" onclick="splitDataset()">✂️ Split Dataset</button> |
| 1121 | <div class="log mt-8" id="splitLog" style="max-height:80px">Ready.</div> |
| 1122 | </div> |
| 1123 | </div> |
| 1124 | </div> |
| 1125 | |
| 1126 | <!-- Available Datasets --> |
| 1127 | <div class="card"> |
| 1128 | <div class="card-header"> |
| 1129 | <h3><span class="icon">📂</span> Available Datasets</h3> |
| 1130 | <button class="btn btn-dim btn-xs" onclick="loadDatasets()">🔄 Refresh</button> |
| 1131 | </div> |
| 1132 | <div id="datasetList"><span class="text-dim">Loading datasets...</span></div> |
| 1133 | </div> |
| 1134 | </div> |
| 1135 | |
| 1136 | <!-- ═══════════ EXPORT ═══════════ --> |
| 1137 | <div class="panel" id="panel-export"> |
| 1138 | <div class="row mb-8 gap-16"> |
| 1139 | <div class="col-2"> |
| 1140 | <div class="card"> |
| 1141 | <div class="card-header"><h3><span class="icon">📤</span> HuggingFace → GGUF</h3></div> |
| 1142 | <label>HF Model ID or local path</label> |
| 1143 | <input type="text" id="exportModel" placeholder="meta-llama/Llama-3.2-1B-Instruct"> |
| 1144 | <label>Quantization</label> |
| 1145 | <select id="exportType"> |
| 1146 | <option value="q4_0">Q4_0 — 4-bit (fast, compact)</option> |
| 1147 | <option value="q4_1">Q4_1 — 4-bit (with min/max)</option> |
| 1148 | <option value="q5_0">Q5_0 — 5-bit (balanced)</option> |
| 1149 | <option value="q8_0">Q8_0 — 8-bit (accurate)</option> |
| 1150 | <option value="f16">F16 — 16-bit (full precision)</option> |
| 1151 | <option value="bf16">BF16 — bfloat16</option> |
| 1152 | <option value="q2_k">Q2_K — 2-bit K-quant (smallest)</option> |
| 1153 | <option value="q3_k_m">Q3_K_M — 3-bit K-quant (mixed)</option> |
| 1154 | <option value="q4_k_m">Q4_K_M — 4-bit K-quant (recommended)</option> |
| 1155 | <option value="q5_k_m">Q5_K_M — 5-bit K-quant (quality)</option> |
| 1156 | <option value="q6_k">Q6_K — 6-bit K-quant (near lossless)</option> |
| 1157 | </select> |
| 1158 | <label>Output filename</label> |
| 1159 | <input type="text" id="exportOutput" placeholder="model-q4_0.gguf"> |
| 1160 | <button class="btn btn-primary" onclick="startExport()" id="exportBtn">📤 Start Export</button> |
| 1161 | </div> |
| 1162 | </div> |
| 1163 | <div style="flex:1"> |
| 1164 | <div class="card"> |
| 1165 | <div class="card-header"><h3><span class="icon">📜</span> Export Log</h3></div> |
| 1166 | <div class="log" id="exportLog" style="max-height:420px;font-size:11px">Ready to export. Specify a HuggingFace model ID and click Start.</div> |
| 1167 | </div> |
| 1168 | </div> |
| 1169 | </div> |
| 1170 | <!-- GGUF → Safetensors --> |
| 1171 | <div class="row mb-8 gap-16"> |
| 1172 | <div style="flex:1"> |
| 1173 | <div class="card"> |
| 1174 | <div class="card-header"><h3><span class="icon">🔄</span> GGUF → Safetensors</h3></div> |
| 1175 | <div class="row mb-8"> |
| 1176 | <div style="flex:2"> |
| 1177 | <label>GGUF Model</label> |
| 1178 | <input type="text" id="stModel" placeholder="path/to/model.gguf"> |
| 1179 | </div> |
| 1180 | <div style="flex:1"> |
| 1181 | <label>Output Dir</label> |
| 1182 | <input type="text" id="stOutput" placeholder="model-safetensors/"> |
| 1183 | </div> |
| 1184 | <div style="width:100px"> |
| 1185 | <label>Dtype</label> |
| 1186 | <select id="stDtype"> |
| 1187 | <option value="float16">float16</option> |
| 1188 | <option value="float32">float32</option> |
| 1189 | <option value="bfloat16">bfloat16</option> |
| 1190 | </select> |
| 1191 | </div> |
| 1192 | <div style="width:90px"> |
| 1193 | <label>Shard</label> |
| 1194 | <select id="stShard"> |
| 1195 | <option value="2GB">2GB</option> |
| 1196 | <option value="NO">None</option> |
| 1197 | <option value="5GB">5GB</option> |
| 1198 | </select> |
| 1199 | </div> |
| 1200 | </div> |
| 1201 | <button class="btn btn-primary" onclick="startSafetensors()">🔄 Convert</button> |
| 1202 | </div> |
| 1203 | </div> |
| 1204 | </div> |
| 1205 | <!-- GGUF → ONNX --> |
| 1206 | <div class="row mb-8 gap-16"> |
| 1207 | <div style="flex:1"> |
| 1208 | <div class="card"> |
| 1209 | <div class="card-header"><h3><span class="icon">🔷</span> GGUF → ONNX</h3></div> |
| 1210 | <div class="row mb-8"> |
| 1211 | <div style="flex:2"> |
| 1212 | <label>GGUF Model</label> |
| 1213 | <input type="text" id="onnxModel" placeholder="path/to/model.gguf"> |
| 1214 | </div> |
| 1215 | <div style="flex:1"> |
| 1216 | <label>Output Path</label> |
| 1217 | <input type="text" id="onnxOutput" placeholder="model.onnx"> |
| 1218 | </div> |
| 1219 | <div style="width:90px"> |
| 1220 | <label>Opset</label> |
| 1221 | <input type="number" id="onnxOpset" value="17" min="7" max="21"> |
| 1222 | </div> |
| 1223 | <div style="width:110px"> |
| 1224 | <label>Max Seq Len</label> |
| 1225 | <input type="number" id="onnxSeqLen" value="2048" min="64"> |
| 1226 | </div> |
| 1227 | </div> |
| 1228 | <button class="btn btn-primary" onclick="startOnnx()">🔷 Export ONNX</button> |
| 1229 | </div> |
| 1230 | </div> |
| 1231 | <div style="flex:1"> |
| 1232 | <div class="card"> |
| 1233 | <div class="card-header"><h3><span class="icon">📜</span> Export Log (Safetensors/ONNX)</h3></div> |
| 1234 | <div class="log" id="exportFormatLog" style="max-height:240px;font-size:11px">Ready for format conversion.</div> |
| 1235 | </div> |
| 1236 | </div> |
| 1237 | </div> |
| 1238 | </div> |
| 1239 | |
| 1240 | <!-- ═══════════ BENCHMARK ═══════════ --> |
| 1241 | <div class="panel" id="panel-benchmark"> |
| 1242 | <div class="row mb-8 gap-16"> |
| 1243 | <div style="flex:1"> |
| 1244 | <div class="card"> |
| 1245 | <div class="card-header"><h3><span class="icon">⚡</span> Benchmark</h3></div> |
| 1246 | <div class="row mb-8"> |
| 1247 | <div> |
| 1248 | <label>Model</label> |
| 1249 | <select id="benchModel"><option value="">Select model...</option></select> |
| 1250 | </div> |
| 1251 | <div> |
| 1252 | <label>Prompt Tokens</label> |
| 1253 | <input type="number" id="benchPromptTokens" value="512"> |
| 1254 | </div> |
| 1255 | <div> |
| 1256 | <label>Generation Tokens</label> |
| 1257 | <input type="number" id="benchTokens" value="128"> |
| 1258 | </div> |
| 1259 | <div> |
| 1260 | <label>Threads</label> |
| 1261 | <input type="number" id="benchThreads" value="0" placeholder="auto"> |
| 1262 | </div> |
| 1263 | </div> |
| 1264 | <label>Engine</label> |
| 1265 | <div class="engine-pills" id="benchEnginePills"> |
| 1266 | <span class="engine-pill active" data-engine="mojollama" onclick="setBenchEngine('mojollama')">MojoLlama</span> |
| 1267 | <span class="engine-pill" data-engine="llamacpp" onclick="setBenchEngine('llamacpp')">llama.cpp</span> |
| 1268 | <span class="engine-pill" data-engine="both" onclick="setBenchEngine('both')">Both (compare)</span> |
| 1269 | </div> |
| 1270 | <label>Custom Prompt (optional)</label> |
| 1271 | <textarea id="benchPrompt" rows="3" placeholder="Leave empty for default benchmark prompt"></textarea> |
| 1272 | <button class="btn btn-primary" onclick="runBenchmark()" id="benchBtn">⚡ Run Benchmark</button> |
| 1273 | </div> |
| 1274 | <!-- Memory usage card --> |
| 1275 | <div class="card" id="benchMemCard" style="display:none"> |
| 1276 | <div class="card-header"><h3><span class="icon">💾</span> Memory Usage</h3></div> |
| 1277 | <div class="mem-card" style="margin:0"> |
| 1278 | <span class="mem-icon">🧠</span> |
| 1279 | <div class="mem-info"> |
| 1280 | <div class="mem-title">Estimated Memory</div> |
| 1281 | <div class="mem-value" id="benchMemValue">—</div> |
| 1282 | </div> |
| 1283 | </div> |
| 1284 | </div> |
| 1285 | </div> |
| 1286 | <div class="col-2"> |
| 1287 | <!-- Tok/s Gauge --> |
| 1288 | <div class="card" id="benchGaugeCard" style="display:none"> |
| 1289 | <div class="card-header"><h3><span class="icon">⏱️</span> Generation Speed</h3></div> |
| 1290 | <div style="text-align:center"> |
| 1291 | <svg class="gauge-svg" viewBox="0 0 200 110" id="benchGaugeSvg"> |
| 1292 | <defs> |
| 1293 | <linearGradient id="gaugeGrad" x1="0%" y1="0%" x2="100%" y2="0%"> |
| 1294 | <stop offset="0%" stop-color="#6C3CE1"/> |
| 1295 | <stop offset="50%" stop-color="#8B5CF6"/> |
| 1296 | <stop offset="100%" stop-color="#22D3EE"/> |
| 1297 | </linearGradient> |
| 1298 | </defs> |
| 1299 | <path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="var(--border)" stroke-width="16" stroke-linecap="round"/> |
| 1300 | <path d="M 20 100 A 80 80 0 0 1 180 100" fill="none" stroke="url(#gaugeGrad)" stroke-width="16" stroke-linecap="round" stroke-dasharray="0 251" id="gaugeArc"/> |
| 1301 | <text x="100" y="75" text-anchor="middle" fill="var(--text)" font-size="28" font-weight="800" font-family="'Space Grotesk',sans-serif" id="gaugeText">0</text> |
| 1302 | <text x="100" y="95" text-anchor="middle" fill="var(--dim)" font-size="11" font-family="'Inter',sans-serif">tok/s</text> |
| 1303 | </svg> |
| 1304 | </div> |
| 1305 | </div> |
| 1306 | <div class="card"> |
| 1307 | <div class="card-header"><h3><span class="icon">📊</span> Results</h3></div> |
| 1308 | <table class="results-table"> |
| 1309 | <thead><tr><th>Metric</th><th>Value</th></tr></thead> |
| 1310 | <tbody id="benchResults"> |
| 1311 | <tr><td class="text-dim">Run a benchmark to see results</td><td></td></tr> |
| 1312 | </tbody> |
| 1313 | </table> |
| 1314 | </div> |
| 1315 | <!-- Comparison table (shown when Both engine selected) --> |
| 1316 | <div class="card" id="benchCompareCard" style="display:none"> |
| 1317 | <div class="card-header"><h3><span class="icon">⚖️</span> Engine Comparison</h3></div> |
| 1318 | <div id="benchCompareBody"></div> |
| 1319 | </div> |
| 1320 | <div class="card" id="benchHistoryCard" style="display:none"> |
| 1321 | <div class="card-header"><h3><span class="icon">📈</span> Latency History</h3></div> |
| 1322 | <div class="chart-wrapper" style="height:180px"><canvas id="benchHistoryChart"></canvas></div> |
| 1323 | </div> |
| 1324 | </div> |
| 1325 | </div> |
| 1326 | </div> |
| 1327 | |
| 1328 | <!-- ═══════════ AUTO-TUNE ═══════════ --> |
| 1329 | <div class="panel" id="panel-autotune"> |
| 1330 | <div class="row mb-8 gap-16"> |
| 1331 | <div style="flex:1"> |
| 1332 | <div class="card"> |
| 1333 | <div class="card-header"><h3><span class="icon">⚙</span> Auto-Tune</h3></div> |
| 1334 | <p style="font-size:13px;color:var(--dim);margin-bottom:16px"> |
| 1335 | Automatically find the optimal inference parameters for your hardware. |
| 1336 | </p> |
| 1337 | <div class="row mb-12"> |
| 1338 | <div> |
| 1339 | <label>Model</label> |
| 1340 | <select id="tuneModel"><option value="">Select model...</option></select> |
| 1341 | </div> |
| 1342 | <div style="display:flex;align-items:flex-end;gap:8px"> |
| 1343 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer;text-transform:none;letter-spacing:0;font-size:13px;color:var(--text)"> |
| 1344 | <input type="checkbox" id="tuneQuickMode" checked style="width:auto;margin:0"> Quick Mode |
| 1345 | </label> |
| 1346 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer;text-transform:none;letter-spacing:0;font-size:13px;color:var(--text)"> |
| 1347 | <input type="checkbox" id="tuneMemSafe" style="width:auto;margin:0"> Memory Safe |
| 1348 | </label> |
| 1349 | </div> |
| 1350 | </div> |
| 1351 | <button class="btn btn-primary" onclick="runAutoTune()" id="tuneBtn">⚙ Tune for this hardware</button> |
| 1352 | </div> |
| 1353 | |
| 1354 | <!-- Progress area --> |
| 1355 | <div class="card" id="tuneProgressCard" style="display:none"> |
| 1356 | <div class="card-header"><h3><span class="icon">⏳</span> Tuning Progress</h3></div> |
| 1357 | <div class="tune-phase" id="tunePhase">Phase 1/5: Initializing...</div> |
| 1358 | <div class="progress-bar"> |
| 1359 | <div class="progress-bar-fill" id="tuneProgressFill"></div> |
| 1360 | </div> |
| 1361 | <div class="progress-text"> |
| 1362 | <span id="tuneProgressPct">0%</span> |
| 1363 | <span class="progress-step" id="tuneProgressStep">Starting...</span> |
| 1364 | </div> |
| 1365 | <div class="log mt-8" id="tuneLog" style="max-height:200px;font-size:11px">Starting auto-tuning...</div> |
| 1366 | </div> |
| 1367 | </div> |
| 1368 | |
| 1369 | <div style="flex:1"> |
| 1370 | <!-- Results card --> |
| 1371 | <div class="card" id="tuneResultsCard" style="display:none"> |
| 1372 | <div class="card-header"> |
| 1373 | <h3><span class="icon">🏆</span> Optimal Settings</h3> |
| 1374 | <span class="badge badge-new" id="tuneStatusBadge">Complete</span> |
| 1375 | </div> |
| 1376 | <div id="tuneResultsBody"> |
| 1377 | <div class="tune-result-row"><span class="tune-label">Threads</span><span class="tune-value" id="tuneThreads">—</span></div> |
| 1378 | <div class="tune-result-row"><span class="tune-label">Batch Size</span><span class="tune-value" id="tuneBatchSize">—</span></div> |
| 1379 | <div class="tune-result-row"><span class="tune-label">Parallel Slots</span><span class="tune-value" id="tuneParallel">—</span></div> |
| 1380 | <div class="tune-result-row"><span class="tune-label">Memory Lock (mlock)</span><span class="tune-value" id="tuneMlock">—</span></div> |
| 1381 | <div class="tune-result-row"><span class="tune-label">Flash Attention</span><span class="tune-value" id="tuneFlashAttn">—</span></div> |
| 1382 | <div class="tune-result-row" style="border-top:2px solid var(--border);margin-top:4px;padding-top:8px"><span class="tune-label" style="color:var(--accent);font-weight:700">MojoLlama-Specific</span><span class="tune-value"></span></div> |
| 1383 | <div class="tune-result-row"><span class="tune-label">Optimal Batch</span><span class="tune-value" id="tuneOptimalBatch">—</span></div> |
| 1384 | <div class="tune-result-row"><span class="tune-label">Concurrency</span><span class="tune-value" id="tuneConcurrency">—</span></div> |
| 1385 | <div class="tune-result-row" style="border-top:2px solid var(--border);margin-top:4px;padding-top:8px"><span class="tune-label">Estimated Throughput</span><span class="tune-value" id="tuneThroughput" style="color:var(--green);font-size:16px">—</span></div> |
| 1386 | </div> |
| 1387 | <div style="display:flex;gap:8px;margin-top:16px"> |
| 1388 | <button class="btn btn-green" onclick="applyTuneConfig()" id="tuneApplyBtn">✅ Apply Config</button> |
| 1389 | <button class="btn btn-dim btn-sm" onclick="downloadTuneReport()">📥 Download Report</button> |
| 1390 | </div> |
| 1391 | </div> |
| 1392 | </div> |
| 1393 | </div> |
| 1394 | </div> |
| 1395 | |
| 1396 | <!-- ═══════════ EVALUATE ═══════════ --> |
| 1397 | <div class="panel" id="panel-evaluate"> |
| 1398 | <div class="row mb-8 gap-16"> |
| 1399 | <div style="flex:1"> |
| 1400 | <div class="card"> |
| 1401 | <div class="card-header"> |
| 1402 | <h3><span class="icon">🎯</span> Benchmark Evaluation</h3> |
| 1403 | <span class="badge badge-new">New</span> |
| 1404 | </div> |
| 1405 | <div class="row mb-8"> |
| 1406 | <div> |
| 1407 | <label>Model</label> |
| 1408 | <select id="evalModel"><option value="">Select model...</option></select> |
| 1409 | </div> |
| 1410 | <div> |
| 1411 | <label>Benchmarks</label> |
| 1412 | <div style="display:flex;flex-wrap:wrap;gap:6px;margin-top:4px"> |
| 1413 | <label class="bench-check"><input type="checkbox" id="b-mmlu" checked> MMLU</label> |
| 1414 | <label class="bench-check"><input type="checkbox" id="b-gsm8k" checked> GSM8K</label> |
| 1415 | <label class="bench-check"><input type="checkbox" id="b-ceval"> CEval</label> |
| 1416 | <label class="bench-check"><input type="checkbox" id="b-hellaswag" checked> HellaSwag</label> |
| 1417 | <label class="bench-check"><input type="checkbox" id="b-arc"> ARC</label> |
| 1418 | <label class="bench-check"><input type="checkbox" id="b-bbh"> BBH</label> |
| 1419 | <label class="bench-check"><input type="checkbox" id="b-humaneval"> HumanEval</label> |
| 1420 | </div> |
| 1421 | </div> |
| 1422 | </div> |
| 1423 | <div class="row mb-8"> |
| 1424 | <div> |
| 1425 | <label>Max Samples (0 = all)</label> |
| 1426 | <input type="number" id="evalMaxSamples" value="20" style="width:100px"> |
| 1427 | </div> |
| 1428 | <div style="display:flex;align-items:flex-end;gap:8px"> |
| 1429 | <button class="btn btn-primary" onclick="runBenchmarkEval()" id="evalBtn">🎯 Run Benchmarks</button> |
| 1430 | <button class="btn btn-dim btn-sm" onclick="downloadEvalDatasets()">📥 Download Datasets</button> |
| 1431 | </div> |
| 1432 | </div> |
| 1433 | <div style="display:flex;gap:8px;margin-top:4px"> |
| 1434 | <button class="btn btn-dim btn-sm" onclick="document.getElementById('b-mmlu').checked=true;document.getElementById('b-gsm8k').checked=true;document.getElementById('b-ceval').checked=false;document.getElementById('b-hellaswag').checked=true;document.getElementById('b-arc').checked=false;document.getElementById('b-bbh').checked=false;document.getElementById('b-humaneval').checked=false">Quick (3 benches)</button> |
| 1435 | <button class="btn btn-dim btn-sm" onclick="document.querySelectorAll('.bench-check input').forEach(c=>c.checked=true)">Select All</button> |
| 1436 | <button class="btn btn-dim btn-sm" onclick="document.querySelectorAll('.bench-check input').forEach(c=>c.checked=false)">Clear</button> |
| 1437 | </div> |
| 1438 | </div> |
| 1439 | <div class="card" style="margin-top:8px"> |
| 1440 | <div class="card-header"><h3><span class="icon">🎯</span> Classic Evaluation</h3></div> |
| 1441 | <div class="row mb-8"> |
| 1442 | <div> |
| 1443 | <label>Type</label> |
| 1444 | <select id="evalType"> |
| 1445 | <option value="perplexity">Perplexity</option> |
| 1446 | <option value="accuracy">Accuracy (custom JSONL)</option> |
| 1447 | </select> |
| 1448 | </div> |
| 1449 | <div> |
| 1450 | <label>Dataset (for accuracy)</label> |
| 1451 | <input type="text" id="evalData" placeholder="evaluation.jsonl"> |
| 1452 | </div> |
| 1453 | </div> |
| 1454 | <button class="btn btn-dim" onclick="runClassicEval()">▶ Run Classic</button> |
| 1455 | </div> |
| 1456 | </div> |
| 1457 | <div class="col-2"> |
| 1458 | <div class="card"> |
| 1459 | <div class="card-header"><h3><span class="icon">📊</span> Results</h3></div> |
| 1460 | <div id="evalResults" style="text-align:center;padding:16px;color:var(--dim)"> |
| 1461 | <div style="font-size:32px;margin-bottom:8px">🎯</div> |
| 1462 | <div style="font-size:13px">Run benchmarks to see results</div> |
| 1463 | </div> |
| 1464 | <div class="log" id="evalLog" style="max-height:300px;display:none;font-size:11px">Starting evaluation...</div> |
| 1465 | </div> |
| 1466 | </div> |
| 1467 | </div> |
| 1468 | </div> |
| 1469 | |
| 1470 | <!-- ═══════════ QUANTIZE ═══════════ --> |
| 1471 | <div class="panel" id="panel-quantize"> |
| 1472 | <div class="card"> |
| 1473 | <div class="card-header"> |
| 1474 | <h3><span class="icon">🔮</span> Quantization Studio</h3> |
| 1475 | <span class="badge badge-new">New</span> |
| 1476 | </div> |
| 1477 | <p style="font-size:13px;color:var(--dim);margin-bottom:16px"> |
| 1478 | Compare quantization formats side-by-side. Convert your GGUF models between quantization levels. |
| 1479 | </p> |
| 1480 | <div class="row mb-12"> |
| 1481 | <div> |
| 1482 | <label>Source Model (GGUF)</label> |
| 1483 | <select id="quantModel"><option value="">Select a model...</option></select> |
| 1484 | </div> |
| 1485 | <div> |
| 1486 | <label>Output</label> |
| 1487 | <input type="text" id="quantOutput" placeholder="model-q4_0.gguf"> |
| 1488 | </div> |
| 1489 | </div> |
| 1490 | |
| 1491 | <!-- Multi-quant selection grid --> |
| 1492 | <label>Target Quantization Types</label> |
| 1493 | <div class="quant-grid" id="quantGrid"> |
| 1494 | <div class="quant-grid-item" data-quant="q2_k" onclick="toggleQuantItem(this)"> |
| 1495 | <input type="checkbox" value="q2_k"><div class="qg-info"><div class="qg-name">Q2_K</div><div class="qg-meta">~2.56 bpw · ~33% size</div></div> |
| 1496 | </div> |
| 1497 | <div class="quant-grid-item" data-quant="q3_k_m" onclick="toggleQuantItem(this)"> |
| 1498 | <input type="checkbox" value="q3_k_m"><div class="qg-info"><div class="qg-name">Q3_K_M</div><div class="qg-meta">~3.40 bpw · ~40% size</div></div> |
| 1499 | </div> |
| 1500 | <div class="quant-grid-item" data-quant="q4_0" onclick="toggleQuantItem(this)"> |
| 1501 | <input type="checkbox" value="q4_0"><div class="qg-info"><div class="qg-name">Q4_0</div><div class="qg-meta">~2.56 bpw · ~50% size</div></div> |
| 1502 | </div> |
| 1503 | <div class="quant-grid-item" data-quant="q4_1" onclick="toggleQuantItem(this)"> |
| 1504 | <input type="checkbox" value="q4_1"><div class="qg-info"><div class="qg-name">Q4_1</div><div class="qg-meta">~2.75 bpw · ~55% size</div></div> |
| 1505 | </div> |
| 1506 | <div class="quant-grid-item" data-quant="q4_k_m" onclick="toggleQuantItem(this)"> |
| 1507 | <input type="checkbox" value="q4_k_m"><div class="qg-info"><div class="qg-name">Q4_K_M</div><div class="qg-meta">~4.80 bpw · ~60% size</div></div> |
| 1508 | </div> |
| 1509 | <div class="quant-grid-item" data-quant="q5_0" onclick="toggleQuantItem(this)"> |
| 1510 | <input type="checkbox" value="q5_0"><div class="qg-info"><div class="qg-name">Q5_0</div><div class="qg-meta">~3.31 bpw · ~62% size</div></div> |
| 1511 | </div> |
| 1512 | <div class="quant-grid-item" data-quant="q5_1" onclick="toggleQuantItem(this)"> |
| 1513 | <input type="checkbox" value="q5_1"><div class="qg-info"><div class="qg-name">Q5_1</div><div class="qg-meta">~3.50 bpw · ~65% size</div></div> |
| 1514 | </div> |
| 1515 | <div class="quant-grid-item" data-quant="q5_k_m" onclick="toggleQuantItem(this)"> |
| 1516 | <input type="checkbox" value="q5_k_m"><div class="qg-info"><div class="qg-name">Q5_K_M</div><div class="qg-meta">~5.68 bpw · ~70% size</div></div> |
| 1517 | </div> |
| 1518 | <div class="quant-grid-item" data-quant="q6_k" onclick="toggleQuantItem(this)"> |
| 1519 | <input type="checkbox" value="q6_k"><div class="qg-info"><div class="qg-name">Q6_K</div><div class="qg-meta">~6.59 bpw · ~80% size</div></div> |
| 1520 | </div> |
| 1521 | <div class="quant-grid-item" data-quant="q8_0" onclick="toggleQuantItem(this)"> |
| 1522 | <input type="checkbox" value="q8_0"><div class="qg-info"><div class="qg-name">Q8_0</div><div class="qg-meta">~5.50 bpw · ~90% size</div></div> |
| 1523 | </div> |
| 1524 | <div class="quant-grid-item" data-quant="iq1_s" onclick="toggleQuantItem(this)"> |
| 1525 | <input type="checkbox" value="iq1_s"><div class="qg-info"><div class="qg-name">IQ1_S</div><div class="qg-meta">~1.0 bpw · ~15% size</div></div> |
| 1526 | </div> |
| 1527 | <div class="quant-grid-item" data-quant="iq2_xxs" onclick="toggleQuantItem(this)"> |
| 1528 | <input type="checkbox" value="iq2_xxs"><div class="qg-info"><div class="qg-name">IQ2_XXS</div><div class="qg-meta">~2.0 bpw · ~25% size</div></div> |
| 1529 | </div> |
| 1530 | <div class="quant-grid-item" data-quant="iq2_xs" onclick="toggleQuantItem(this)"> |
| 1531 | <input type="checkbox" value="iq2_xs"><div class="qg-info"><div class="qg-name">IQ2_XS</div><div class="qg-meta">~2.2 bpw · ~27% size</div></div> |
| 1532 | </div> |
| 1533 | <div class="quant-grid-item" data-quant="iq3_xxs" onclick="toggleQuantItem(this)"> |
| 1534 | <input type="checkbox" value="iq3_xxs"><div class="qg-info"><div class="qg-name">IQ3_XXS</div><div class="qg-meta">~3.0 bpw · ~38% size</div></div> |
| 1535 | </div> |
| 1536 | </div> |
| 1537 | <div style="display:flex;gap:8px;align-items:center;margin:4px 0 10px"> |
| 1538 | <label style="margin:0;text-transform:none;letter-spacing:0;font-size:12px;display:flex;align-items:center;gap:4px;cursor:pointer"> |
| 1539 | <input type="checkbox" id="quantSelectAll" onchange="toggleAllQuant(this)" style="width:auto;margin:0"> Select All |
| 1540 | </label> |
| 1541 | <span style="font-size:11px;color:var(--dim)" id="quantSelectedCount">0 selected</span> |
| 1542 | </div> |
| 1543 | |
| 1544 | <!-- Target BPW mode --> |
| 1545 | <div class="dynamic-quant-options"> |
| 1546 | <label>🎯 <input type="checkbox" id="quantBpwMode" onchange="document.getElementById('quantBpwInput').style.display=this.checked?'':'none'"> Target BPW</label> |
| 1547 | <input type="number" id="quantBpwInput" value="4.5" step="0.1" min="1" max="16" style="display:none"> |
| 1548 | <span class="text-dim" style="font-size:11px">Auto-selects quant types at or below target bits-per-weight</span> |
| 1549 | </div> |
| 1550 | |
| 1551 | <!-- Dynamic quant / imatrix --> |
| 1552 | <div class="dynamic-quant-options"> |
| 1553 | <label><input type="checkbox" id="quantDynamic" onchange="document.getElementById('quantImatrix').style.display=this.checked?'':'inline-block'"> Dynamic Quantization</label> |
| 1554 | <input type="file" id="quantImatrix" accept=".dat" style="display:none" onchange="document.getElementById('quantImatrixName').textContent=this.files[0]?.name||'No file'"> |
| 1555 | <span class="text-dim" style="font-size:11px" id="quantImatrixName">No file selected</span> |
| 1556 | <span style="font-size:10px;color:var(--dim)">Use importance matrix (.dat) for optimal quantization</span> |
| 1557 | </div> |
| 1558 | |
| 1559 | <!-- Progress bar --> |
| 1560 | <div class="progress-bar" id="quantProgress" style="display:none"> |
| 1561 | <div class="progress-bar-fill" id="quantProgressFill"></div> |
| 1562 | </div> |
| 1563 | <div class="progress-text" id="quantProgressText" style="display:none"> |
| 1564 | <span id="quantProgressPct">0%</span> |
| 1565 | <span class="progress-step" id="quantProgressStep">Initializing...</span> |
| 1566 | </div> |
| 1567 | |
| 1568 | <button class="btn btn-primary" onclick="runQuantize()" id="quantBtn">🔮 Quantize Selected</button> |
| 1569 | |
| 1570 | <!-- Download links --> |
| 1571 | <div class="download-links" id="quantDownloads" style="display:none"></div> |
| 1572 | </div> |
| 1573 | |
| 1574 | <div class="card"> |
| 1575 | <div class="card-header"><h3><span class="icon">📊</span> Quantization Comparison</h3></div> |
| 1576 | <div class="row gap-16" id="quantCompare"> |
| 1577 | <div class="quant-card"> |
| 1578 | <div class="quant-name" style="color:var(--accent)">Q2_K</div> |
| 1579 | <div class="quant-bits">~2.56 bpw</div> |
| 1580 | <div class="quant-speed">71 tok/s</div> |
| 1581 | <div class="quant-size">Smallest</div> |
| 1582 | </div> |
| 1583 | <div class="quant-card" style="border-color:var(--green)"> |
| 1584 | <div class="quant-name" style="color:var(--green)">Q4_0</div> |
| 1585 | <div class="quant-bits">4.0 bpw</div> |
| 1586 | <div class="quant-speed">66 tok/s</div> |
| 1587 | <div class="quant-size" style="color:var(--green)">Best tradeoff</div> |
| 1588 | </div> |
| 1589 | <div class="quant-card"> |
| 1590 | <div class="quant-name" style="color:var(--accent2)">Q4_K_M</div> |
| 1591 | <div class="quant-bits">~4.80 bpw</div> |
| 1592 | <div class="quant-speed">62 tok/s</div> |
| 1593 | <div class="quant-size">Good quality</div> |
| 1594 | </div> |
| 1595 | <div class="quant-card"> |
| 1596 | <div class="quant-name" style="color:var(--orange)">Q8_0</div> |
| 1597 | <div class="quant-bits">8.0 bpw</div> |
| 1598 | <div class="quant-speed">40 tok/s</div> |
| 1599 | <div class="quant-size">Near lossless</div> |
| 1600 | </div> |
| 1601 | <div class="quant-card"> |
| 1602 | <div class="quant-name" style="color:var(--cyan)">F16</div> |
| 1603 | <div class="quant-bits">16.0 bpw</div> |
| 1604 | <div class="quant-speed">23 tok/s</div> |
| 1605 | <div class="quant-size">Baseline</div> |
| 1606 | </div> |
| 1607 | </div> |
| 1608 | </div> |
| 1609 | |
| 1610 | <div class="card"> |
| 1611 | <div class="card-header"><h3><span class="icon">📜</span> Quantization Log</h3></div> |
| 1612 | <div class="log" id="quantLog" style="max-height:300px">Ready. Select a model and target quantization to convert.</div> |
| 1613 | </div> |
| 1614 | </div> |
| 1615 | |
| 1616 | <!-- ═══════════ MERGE ═══════════ --> |
| 1617 | <div class="panel" id="panel-merge"> |
| 1618 | <div class="row mb-8 gap-16"> |
| 1619 | <div class="col-2"> |
| 1620 | <div class="card"> |
| 1621 | <div class="card-header"> |
| 1622 | <h3><span class="icon">🔗</span> Merge LoRA → Base</h3> |
| 1623 | <span class="badge badge-new">Merge</span> |
| 1624 | </div> |
| 1625 | <label>Base Model (GGUF)</label> |
| 1626 | <select id="mergeBase"><option value="">Select base model...</option></select> |
| 1627 | <label>LoRA Adapter (GGUF)</label> |
| 1628 | <input type="text" id="mergeLora" placeholder="path/to/lora-adapter.gguf"> |
| 1629 | <label>Output Type</label> |
| 1630 | <select id="mergeType"> |
| 1631 | <option value="q4_0">Q4_0 (4-bit)</option> |
| 1632 | <option value="q8_0">Q8_0 (8-bit)</option> |
| 1633 | <option value="f16">F16 (16-bit)</option> |
| 1634 | </select> |
| 1635 | <label>Output filename</label> |
| 1636 | <input type="text" id="mergeOutput" value="merged.gguf"> |
| 1637 | <button class="btn btn-primary" onclick="runMerge()" id="mergeBtn">🔗 Merge Models</button> |
| 1638 | </div> |
| 1639 | </div> |
| 1640 | <div style="flex:1"> |
| 1641 | <div class="card"> |
| 1642 | <div class="card-header"><h3><span class="icon">📜</span> Merge Log</h3></div> |
| 1643 | <div class="log" id="mergeLog" style="max-height:420px">Ready. Select a base model and LoRA adapter to merge.</div> |
| 1644 | </div> |
| 1645 | </div> |
| 1646 | </div> |
| 1647 | </div> |
| 1648 | |
| 1649 | <!-- ═══════════ CHECKPOINTS ═══════════ --> |
| 1650 | <div class="panel" id="panel-checkpoints"> |
| 1651 | <div class="row mb-8 gap-16"> |
| 1652 | <div class="col-2"> |
| 1653 | <div class="card"> |
| 1654 | <div class="card-header"><h3><span class="icon">💾</span> Checkpoint Manager</h3></div> |
| 1655 | <label>Checkpoint Directory</label> |
| 1656 | <div class="input-group"> |
| 1657 | <input type="text" id="ckptDir" placeholder="checkpoints" value="checkpoints" style="flex:1"> |
| 1658 | <button class="btn btn-dim" onclick="listCheckpoints()">🔄 List</button> |
| 1659 | <button class="btn btn-primary" onclick="saveCheckpoint()">💾 Save</button> |
| 1660 | </div> |
| 1661 | <div style="margin-top:12px;display:flex;gap:8px;align-items:center"> |
| 1662 | <button class="btn btn-danger btn-xs" onclick="deleteAllCheckpoints()">🗑 Clear All</button> |
| 1663 | <span style="font-size:11px;color:var(--dim)">Saves current training state</span> |
| 1664 | </div> |
| 1665 | </div> |
| 1666 | <div class="card" style="margin-top:8px"> |
| 1667 | <div class="card-header"><h3><span class="icon">▶️</span> Resume Training</h3></div> |
| 1668 | <label>Base Model</label> |
| 1669 | <input type="text" id="ckptResumeModel" placeholder="path/to/base-model.gguf"> |
| 1670 | <label>Checkpoint</label> |
| 1671 | <select id="ckptResumeSelect"> |
| 1672 | <option value="">List checkpoints first...</option> |
| 1673 | </select> |
| 1674 | <label>Output Adapter</label> |
| 1675 | <input type="text" id="ckptResumeOutput" placeholder="adapter.gguf"> |
| 1676 | <button class="btn btn-primary" id="ckptResumeBtn" onclick="resumeTraining()" disabled>▶️ Resume</button> |
| 1677 | </div> |
| 1678 | </div> |
| 1679 | <div style="flex:1"> |
| 1680 | <div class="card"> |
| 1681 | <div class="card-header"><h3><span class="icon">📜</span> Checkpoint Log</h3></div> |
| 1682 | <div class="log" id="ckptList" style="max-height:420px;font-size:11px">Open a checkpoint directory and click List.</div> |
| 1683 | </div> |
| 1684 | </div> |
| 1685 | </div> |
| 1686 | </div> |
| 1687 | |
| 1688 | <!-- ═══════════ TEMPLATES ═══════════ --> |
| 1689 | <div class="panel" id="panel-templates"> |
| 1690 | <div class="card"> |
| 1691 | <div class="card-header"> |
| 1692 | <h3><span class="icon">📋</span> Training Templates</h3> |
| 1693 | <span class="badge badge-new">New</span> |
| 1694 | </div> |
| 1695 | <p style="font-size:13px;color:var(--dim);margin-bottom:16px"> |
| 1696 | Pre-configured training recipes for popular models. Select a template to auto-fill the Train tab. |
| 1697 | </p> |
| 1698 | <div class="row gap-16" style="flex-wrap:wrap"> |
| 1699 | <div class="template-card" onclick="selectTemplate('llama3')" style="flex:1;min-width:240px"> |
| 1700 | <h4>🦙 Llama 3 / 3.1 / 3.2</h4> |
| 1701 | <p>LoRA fine-tune for Llama models. Alpaca format, cosine schedule, recommended defaults.</p> |
| 1702 | <div class="template-tags"> |
| 1703 | <span class="chip">r=16</span><span class="chip">cosine</span><span class="chip">alpaca</span> |
| 1704 | </div> |
| 1705 | </div> |
| 1706 | <div class="template-card" onclick="selectTemplate('mistral')" style="flex:1;min-width:240px"> |
| 1707 | <h4>🌀 Mistral / Mixtral</h4> |
| 1708 | <p>Mistral-7B and Mixtral MoE fine-tuning. Sliding window attention, higher rank.</p> |
| 1709 | <div class="template-tags"> |
| 1710 | <span class="chip">r=32</span><span class="chip">cosine</span><span class="chip">sharegpt</span> |
| 1711 | </div> |
| 1712 | </div> |
| 1713 | <div class="template-card" onclick="selectTemplate('qwen')" style="flex:1;min-width:240px"> |
| 1714 | <h4>🌙 Qwen2 / Qwen3</h4> |
| 1715 | <p>Qwen models with MoE support. Supports both dense and MoE architectures.</p> |
| 1716 | <div class="template-tags"> |
| 1717 | <span class="chip">r=16</span><span class="chip">linear</span><span class="chip">alpaca</span> |
| 1718 | </div> |
| 1719 | </div> |
| 1720 | <div class="template-card" onclick="selectTemplate('gemma')" style="flex:1;min-width:240px"> |
| 1721 | <h4>💎 Gemma / Gemma 2</h4> |
| 1722 | <p>Google Gemma fine-tuning. Gemma chat template, balanced settings.</p> |
| 1723 | <div class="template-tags"> |
| 1724 | <span class="chip">r=16</span><span class="chip">cosine</span><span class="chip">gemma</span> |
| 1725 | </div> |
| 1726 | </div> |
| 1727 | <div class="template-card" onclick="selectTemplate('phi')" style="flex:1;min-width:240px"> |
| 1728 | <h4>🔷 Phi-3 / Phi-3.5</h4> |
| 1729 | <p>Microsoft Phi models. Compact but capable — lower rank recommended.</p> |
| 1730 | <div class="template-tags"> |
| 1731 | <span class="chip">r=8</span><span class="chip">constant</span><span class="chip">instruct</span> |
| 1732 | </div> |
| 1733 | </div> |
| 1734 | <div class="template-card" onclick="selectTemplate('deepseek')" style="flex:1;min-width:240px"> |
| 1735 | <h4>🔍 DeepSeek V2/V3/R1</h4> |
| 1736 | <p>DeepSeek models with MLA attention. Higher rank for reasoning tasks.</p> |
| 1737 | <div class="template-tags"> |
| 1738 | <span class="chip">r=64</span><span class="chip">cosine</span><span class="chip">sharegpt</span> |
| 1739 | </div> |
| 1740 | </div> |
| 1741 | <div class="template-card" onclick="selectTemplate('chatglm')" style="flex:1;min-width:240px"> |
| 1742 | <h4>📞 ChatGLM / GLM-4</h4> |
| 1743 | <p>ChatGLM prefix-encoder architecture. Custom attention masking, different tokenizer.</p> |
| 1744 | <div class="template-tags"> |
| 1745 | <span class="chip">r=16</span><span class="chip">cosine</span><span class="chip">prefix-encoder</span> |
| 1746 | </div> |
| 1747 | </div> |
| 1748 | <div class="template-card" onclick="selectTemplate('command-r')" style="flex:1;min-width:240px"> |
| 1749 | <h4>🧠 Command R / R+</h4> |
| 1750 | <p>Cohere Command R models. Large FFN layers, high capacity, grounded responses.</p> |
| 1751 | <div class="template-tags"> |
| 1752 | <span class="chip">r=32</span><span class="chip">cosine</span><span class="chip">large-ffn</span> |
| 1753 | </div> |
| 1754 | </div> |
| 1755 | </div> |
| 1756 | </div> |
| 1757 | </div> |
| 1758 | |
| 1759 | </div> |
| 1760 | </div> |
| 1761 | </div> |
| 1762 | |
| 1763 | <!-- ═══════════ HUB ═══════════ --> |
| 1764 | <div class="panel" id="panel-hub"> |
| 1765 | <div class="row mb-8 gap-16"> |
| 1766 | <div style="flex:1"> |
| 1767 | <div class="card"> |
| 1768 | <div class="card-header"> |
| 1769 | <h3><span class="icon">🤗</span> HuggingFace Hub</h3> |
| 1770 | <span class="badge badge-new">New</span> |
| 1771 | </div> |
| 1772 | <div class="row mb-12"> |
| 1773 | <div class="col-2"> |
| 1774 | <label>HF Token</label> |
| 1775 | <input type="password" id="hubToken" placeholder="hf_xxxxxxxxxxxxxx"> |
| 1776 | </div> |
| 1777 | <div class="col-auto"> |
| 1778 | <label> </label> |
| 1779 | <button class="btn btn-primary" onclick="hubLogin()" id="hubLoginBtn">🔑 Login</button> |
| 1780 | </div> |
| 1781 | <div class="col-auto"> |
| 1782 | <label> </label> |
| 1783 | <button class="btn btn-dim btn-sm" onclick="hubWhoami()" id="hubStatusBtn">👤 Status</button> |
| 1784 | </div> |
| 1785 | </div> |
| 1786 | <div id="hubStatus" class="text-dim" style="font-size:12px;margin-top:-4px;margin-bottom:12px">Not logged in.</div> |
| 1787 | </div> |
| 1788 | </div> |
| 1789 | </div> |
| 1790 | |
| 1791 | <div class="row mb-8 gap-16"> |
| 1792 | <div class="col-2"> |
| 1793 | <div class="card"> |
| 1794 | <div class="card-header"><h3><span class="icon">⬆️</span> Push Model</h3></div> |
| 1795 | <label>Model (GGUF)</label> |
| 1796 | <select id="hubModelPath"> |
| 1797 | <option value="">Select model...</option> |
| 1798 | </select> |
| 1799 | <label>HF Repo ID</label> |
| 1800 | <input type="text" id="hubRepoId" placeholder="username/model-name"> |
| 1801 | <div class="row"> |
| 1802 | <div><label>Quant Type</label><input type="text" id="hubQuant" placeholder="Q4_K_M"></div> |
| 1803 | <div><label>Params</label><input type="text" id="hubParams" placeholder="1.24B"></div> |
| 1804 | </div> |
| 1805 | <label>Description (optional)</label> |
| 1806 | <input type="text" id="hubDescription" placeholder="Short model description"> |
| 1807 | <div style="display:flex;gap:8px;align-items:center;margin-top:4px"> |
| 1808 | <label style="margin:0;display:inline-flex;align-items:center;gap:4px;text-transform:none;font-size:13px;color:var(--text)"> |
| 1809 | <input type="checkbox" id="hubPrivate" style="width:auto;margin:0"> Private repo |
| 1810 | </label> |
| 1811 | <button class="btn btn-primary" onclick="hubPush()" id="hubPushBtn" style="margin-left:auto">⬆️ Push to Hub</button> |
| 1812 | </div> |
| 1813 | </div> |
| 1814 | </div> |
| 1815 | <div style="flex:1"> |
| 1816 | <div class="card"> |
| 1817 | <div class="card-header"><h3><span class="icon">⬆️</span> Push Adapter</h3></div> |
| 1818 | <label>LoRA Adapter (GGUF)</label> |
| 1819 | <input type="text" id="hubAdapterPath" placeholder="path/to/lora-adapter.gguf"> |
| 1820 | <label>Base Model Name</label> |
| 1821 | <input type="text" id="hubBaseModel" placeholder="username/base-model"> |
| 1822 | <label>HF Repo ID</label> |
| 1823 | <input type="text" id="hubAdapterRepo" placeholder="username/adapter-name"> |
| 1824 | <div class="row"> |
| 1825 | <div><label>LoRA Rank</label><input type="number" id="hubAdapterRank" placeholder="16"></div> |
| 1826 | <div><label>LoRA Alpha</label><input type="number" id="hubAdapterAlpha" placeholder="32"></div> |
| 1827 | </div> |
| 1828 | <div style="display:flex;gap:8px;align-items:center;margin-top:4px"> |
| 1829 | <label style="margin:0;display:inline-flex;align-items:center;gap:4px;text-transform:none;font-size:13px;color:var(--text)"> |
| 1830 | <input type="checkbox" id="hubAdapterPrivate" style="width:auto;margin:0"> Private repo |
| 1831 | </label> |
| 1832 | <button class="btn btn-primary" onclick="hubPushAdapter()" id="hubPushAdapterBtn" style="margin-left:auto">⬆️ Push Adapter</button> |
| 1833 | </div> |
| 1834 | </div> |
| 1835 | <div class="card"> |
| 1836 | <div class="card-header"><h3><span class="icon">📜</span> Push Log</h3></div> |
| 1837 | <div class="log" id="hubLog" style="max-height:180px;font-size:11px">Ready. Select a model and target repo to upload.</div> |
| 1838 | </div> |
| 1839 | </div> |
| 1840 | </div> |
| 1841 | </div> |
| 1842 | |
| 1843 | <!-- ═══════════ EXPERIMENTS ═══════════ --> |
| 1844 | <div class="panel" id="panel-experiments"> |
| 1845 | <div class="row mb-8 gap-16"> |
| 1846 | <div style="flex:1"> |
| 1847 | <div class="card"> |
| 1848 | <div class="card-header"> |
| 1849 | <h3><span class="icon">🔬</span> Experiment Tracking</h3> |
| 1850 | <div style="display:flex;gap:6px;align-items:center"> |
| 1851 | <button class="btn btn-green btn-sm" onclick="startExperiment()" id="expStartBtn">▶ New Run</button> |
| 1852 | <button class="btn btn-red btn-sm" onclick="stopExperiment()" id="expStopBtn" disabled>■ Stop</button> |
| 1853 | <button class="btn btn-dim btn-xs" onclick="loadExperiments()">🔄 Refresh</button> |
| 1854 | </div> |
| 1855 | </div> |
| 1856 | <div class="row mb-12"> |
| 1857 | <div><label>Experiment Name</label><input type="text" id="expName" value="default" placeholder="experiment-name"></div> |
| 1858 | <div><label>Description</label><input type="text" id="expDesc" placeholder="Optional description"></div> |
| 1859 | <div><label>Tags (key=val)</label><input type="text" id="expTags" placeholder="model=Llama-3.2,lr=1e-4"></div> |
| 1860 | </div> |
| 1861 | <div class="row mb-12" style="align-items:center"> |
| 1862 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer"> |
| 1863 | <input type="checkbox" id="expWandb" checked style="width:auto;margin:0"> W&B |
| 1864 | </label> |
| 1865 | <label style="margin-bottom:0;display:flex;align-items:center;gap:6px;cursor:pointer"> |
| 1866 | <input type="checkbox" id="expMlflow" checked style="width:auto;margin:0"> MLflow |
| 1867 | </label> |
| 1868 | <span class="text-dim" style="font-size:12px" id="expStatusLabel">No active experiment</span> |
| 1869 | <input type="hidden" id="expCurrentRunId" value=""> |
| 1870 | </div> |
| 1871 | </div> |
| 1872 | <div class="card"> |
| 1873 | <div class="card-header"> |
| 1874 | <h3><span class="icon">📊</span> Metric Chart</h3> |
| 1875 | <div style="display:flex;gap:6px"> |
| 1876 | <select id="expChartMetric" style="width:auto;margin:0;padding:4px 10px;font-size:12px"> |
| 1877 | <option value="loss">loss</option> |
| 1878 | <option value="accuracy">accuracy</option> |
| 1879 | <option value="eval_loss">eval_loss</option> |
| 1880 | </select> |
| 1881 | <button class="btn btn-dim btn-xs" onclick="refreshExpChart()">↻</button> |
| 1882 | </div> |
| 1883 | </div> |
| 1884 | <div class="chart-wrapper" style="height:250px"><canvas id="expChart"></canvas></div> |
| 1885 | <div class="text-dim" style="font-size:12px;margin-top:8px;text-align:center" id="expChartHint"> |
| 1886 | Start an experiment run and log metrics to see the chart |
| 1887 | </div> |
| 1888 | </div> |
| 1889 | <div class="card"> |
| 1890 | <div class="card-header"> |
| 1891 | <h3><span class="icon">📉</span> Compare Runs</h3> |
| 1892 | <button class="btn btn-dim btn-xs" onclick="refreshComparison()">↻ Refresh</button> |
| 1893 | </div> |
| 1894 | <div class="row mb-8"> |
| 1895 | <div><label>Metric</label><select id="compMetric" style="width:auto;margin:0;padding:4px 10px;font-size:12px"><option value="loss">loss</option><option value="accuracy">accuracy</option></select></div> |
| 1896 | <div><label>Run IDs (comma-separated)</label><input type="text" id="compRunIds" placeholder="abc123,def456" style="font-family:monospace;font-size:12px"></div> |
| 1897 | <div style="display:flex;align-items:flex-end"><button class="btn btn-primary btn-sm" onclick="compareRuns()">Compare</button></div> |
| 1898 | </div> |
| 1899 | <div class="chart-wrapper" style="height:200px"><canvas id="compChart"></canvas></div> |
| 1900 | </div> |
| 1901 | </div> |
| 1902 | <div class="col-2"> |
| 1903 | <div class="card"> |
| 1904 | <div class="card-header"><h3><span class="icon">📋</span> Experiment Runs</h3><button class="btn btn-dim btn-xs" onclick="loadExperiments()">🔄</button></div> |
| 1905 | <div id="expRunList" style="max-height:500px;overflow-y:auto"><span class="text-dim">Loading experiments...</span></div> |
| 1906 | </div> |
| 1907 | <div class="card"> |
| 1908 | <div class="card-header"><h3><span class="icon">📄</span> Run Details</h3></div> |
| 1909 | <div id="expRunDetail" class="text-dim" style="font-size:12px;line-height:1.6">Click a run to view details</div> |
| 1910 | </div> |
| 1911 | </div> |
| 1912 | </div> |
| 1913 | </div> |
| 1914 | |
| 1915 | <!-- ═══════════ MODEL CARDS ═══════════ --> |
| 1916 | <div class="panel" id="panel-model-cards"> |
| 1917 | <div class="row mb-8 gap-16"> |
| 1918 | <div class="col-2"> |
| 1919 | <div class="card"> |
| 1920 | <div class="card-header"><h3><span class="icon">🆔</span> Create Model Card</h3></div> |
| 1921 | <div class="row mb-8"> |
| 1922 | <div><label>Model Name</label><input type="text" id="mcName" placeholder="My Awesome Model"></div> |
| 1923 | <div><label>Architecture</label> |
| 1924 | <select id="mcArch"><option value="llama">Llama</option><option value="mistral">Mistral</option><option value="qwen">Qwen</option><option value="gemma">Gemma</option><option value="phi">Phi</option><option value="deepseek">DeepSeek</option></select> |
| 1925 | </div> |
| 1926 | </div> |
| 1927 | <div class="row mb-8"> |
| 1928 | <div><label>Base Model</label><input type="text" id="mcBase" placeholder="meta-llama/Llama-3.2-1B"></div> |
| 1929 | <div><label>Dataset</label><input type="text" id="mcDataset" placeholder="my-dataset.jsonl"></div> |
| 1930 | </div> |
| 1931 | <div class="row mb-8"> |
| 1932 | <div><label>Quantization</label> |
| 1933 | <select id="mcQuant"><option value="">None</option><option value="Q4_0">Q4_0</option><option value="Q4_K_M">Q4_K_M</option><option value="Q5_K_M">Q5_K_M</option><option value="Q8_0">Q8_0</option><option value="F16">F16</option></select> |
| 1934 | </div> |
| 1935 | <div><label>License</label> |
| 1936 | <select id="mcLicense"><option value="MIT">MIT</option><option value="Apache-2.0">Apache 2.0</option><option value="CC-BY-4.0">CC-BY-4.0</option><option value="Llama3">Llama 3</option></select> |
| 1937 | </div> |
| 1938 | </div> |
| 1939 | <label>Description</label><textarea id="mcDesc" rows="3" placeholder="Briefly describe your model..."></textarea> |
| 1940 | <label>Training Config (JSON)</label><textarea id="mcConfig" rows="3" placeholder='{"lr": "2e-4", "batch_size": 4, "lora_rank": 16}'></textarea> |
| 1941 | <label>Tags (comma-separated)</label><input type="text" id="mcTags" placeholder="fine-tuned, chat, instruct"> |
| 1942 | <button class="btn btn-green" onclick="createModelCard()" id="mcBtn">🆔 Create Model Card</button> |
| 1943 | <div class="log mt-8" id="mcLog" style="max-height:80px">Ready.</div> |
| 1944 | </div> |
| 1945 | </div> |
| 1946 | <div style="flex:1"> |
| 1947 | <div class="card"> |
| 1948 | <div class="card-header"><h3><span class="icon">📇</span> Model Cards</h3><button class="btn btn-dim btn-xs" onclick="loadModelCards()">🔄</button></div> |
| 1949 | <div id="mcList"><span class="text-dim">No model cards yet.</span></div> |
| 1950 | </div> |
| 1951 | <div class="card" id="mcReadmeCard" style="display:none"> |
| 1952 | <div class="card-header"><h3><span class="icon">📝</span> Generated README</h3><button class="btn btn-dim btn-xs" onclick="copyMcReadme()">📋 Copy</button></div> |
| 1953 | <div class="log" id="mcReadme" style="max-height:400px;white-space:pre-wrap;font-family:monospace;font-size:12px"></div> |
| 1954 | </div> |
| 1955 | </div> |
| 1956 | </div> |
| 1957 | </div> |
| 1958 | |
| 1959 | </div> |
| 1960 | </div> |
| 1961 | |
| 1962 | <script> |
| 1963 | // ── Theme toggle (IBM Carbon style) ── |
| 1964 | (function(){ |
| 1965 | var toggle = document.getElementById('studioThemeToggle'); |
| 1966 | var stored = localStorage.getItem('mojollama-theme'); |
| 1967 | if (stored) document.documentElement.setAttribute('data-theme', stored); |
| 1968 | function updateIcon(){ |
| 1969 | var isDark = document.documentElement.getAttribute('data-theme') === 'dark' || (!document.documentElement.getAttribute('data-theme') && window.matchMedia('(prefers-color-scheme:dark)').matches); |
| 1970 | var moon = toggle.querySelector('.icon-moon'); |
| 1971 | var sun = toggle.querySelector('.icon-sun'); |
| 1972 | if(moon) moon.style.display = isDark ? 'none' : 'block'; |
| 1973 | if(sun) sun.style.display = isDark ? 'block' : 'none'; |
| 1974 | } |
| 1975 | updateIcon(); |
| 1976 | if(toggle){ |
| 1977 | toggle.addEventListener('click',function(){ |
| 1978 | var current = document.documentElement.getAttribute('data-theme'); |
| 1979 | var next = current === 'dark' ? 'light' : 'dark'; |
| 1980 | document.documentElement.setAttribute('data-theme', next); |
| 1981 | localStorage.setItem('mojollama-theme', next); |
| 1982 | updateIcon(); |
| 1983 | }); |
| 1984 | } |
| 1985 | window.matchMedia('(prefers-color-scheme:dark)').addEventListener('change', updateIcon); |
| 1986 | })(); |
| 1987 | |
| 1988 | // ─── API URL resolution ────────────────────────────────────────── |
| 1989 | const ENGINE_NAMES = { mojollama: 'MojoLlama Native', llamacpp: 'llama.cpp', max: 'MAX' }; |
| 1990 | function getSelectedEngine() { |
| 1991 | const e = localStorage.getItem('mojollama_engine') || 'mojollama'; |
| 1992 | return e; |
| 1993 | } |
| 1994 | function getEngineDisplayName(e) { |
| 1995 | return ENGINE_NAMES[e] || 'MojoLlama Native'; |
| 1996 | } |
| 1997 | const API = (() => { |
| 1998 | const stored = localStorage.getItem('mojollama_api_url'); |
| 1999 | if (stored) return stored; |
| 2000 | const params = new URLSearchParams(location.search); |
| 2001 | const apiParam = params.get('api'); |
| 2002 | if (apiParam) { localStorage.setItem('mojollama_api_url', apiParam); return apiParam; } |
| 2003 | // Same-origin: served directly from the API server on port 9000 |
| 2004 | if (location.port === '9000') return ''; |
| 2005 | // For static sites (OneDev ~site, GitHub Pages, etc.) or any other origin, |
| 2006 | // default to hostname:9000. Can override via settings. Edit mojollama.server --port to match. |
| 2007 | return `http://${location.hostname}:9000`; |
| 2008 | })(); |
| 2009 | |
| 2010 | const TEMPLATES = { |
| 2011 | llama3: { rank:16, alpha:32, lr:'2e-4', scheduler:'cosine', steps:500, batch:4, gradAccum:1, warmup:50, weightDecay:'0.01', modules:'q_proj,v_proj,k_proj,o_proj', dropout:'0.05', ctxLen:2048, flashAttn:true, fp16:true, format:'alpaca', systemPrompt:'You are a helpful AI assistant based on Llama 3.' }, |
| 2012 | mistral: { rank:32, alpha:64, lr:'1e-4', scheduler:'cosine', steps:1000, batch:4, gradAccum:2, warmup:100, weightDecay:'0.01', modules:'q_proj,v_proj,k_proj,o_proj,gate_proj,up_proj,down_proj', dropout:'0.05', ctxLen:4096, flashAttn:true, fp16:true, format:'sharegpt', systemPrompt:'You are a helpful AI assistant based on Mistral.' }, |
| 2013 | qwen: { rank:16, alpha:32, lr:'2e-4', scheduler:'linear', steps:500, batch:4, gradAccum:1, warmup:50, weightDecay:'0.01', modules:'q_proj,v_proj', dropout:'0.05', ctxLen:2048, flashAttn:true, fp16:true, format:'alpaca', systemPrompt:'You are a helpful AI assistant based on Qwen.' }, |
| 2014 | gemma: { rank:16, alpha:32, lr:'2e-4', scheduler:'cosine', steps:500, batch:4, gradAccum:1, warmup:50, weightDecay:'0.01', modules:'q_proj,v_proj,k_proj,o_proj', dropout:'0.05', ctxLen:2048, flashAttn:true, fp16:true, format:'alpaca', systemPrompt:'You are a helpful AI assistant based on Gemma.' }, |
| 2015 | phi: { rank:8, alpha:16, lr:'5e-4', scheduler:'constant', steps:300, batch:4, gradAccum:1, warmup:20, weightDecay:'0.01', modules:'q_proj,v_proj', dropout:'0.1', ctxLen:2048, flashAttn:true, fp16:true, format:'alpaca', systemPrompt:'You are a helpful AI assistant based on Phi-3.' }, |
| 2016 | deepseek: { rank:64, alpha:128, lr:'1e-4', scheduler:'cosine', steps:2000, batch:2, gradAccum:4, warmup:100, weightDecay:'0.005', modules:'q_proj,v_proj,k_proj,o_proj,gate_proj,up_proj,down_proj', dropout:'0.05', ctxLen:4096, flashAttn:true, fp16:true, format:'sharegpt', systemPrompt:'You are a reasoning AI assistant. Think step by step.' }, |
| 2017 | chatglm: { rank:16, alpha:32, lr:'2e-4', scheduler:'cosine', steps:500, batch:4, gradAccum:2, warmup:50, weightDecay:'0.01', modules:'q_proj,v_proj,k_proj,o_proj', dropout:'0.05', ctxLen:2048, flashAttn:true, fp16:true, format:'alpaca', systemPrompt:'You are a helpful AI assistant based on ChatGLM.' }, |
| 2018 | 'command-r': { rank:32, alpha:64, lr:'1e-4', scheduler:'cosine', steps:1000, batch:2, gradAccum:2, warmup:100, weightDecay:'0.01', modules:'q_proj,v_proj,k_proj,o_proj,gate_proj,up_proj,down_proj', dropout:'0.05', ctxLen:4096, flashAttn:true, fp16:true, format:'sharegpt', systemPrompt:'You are a helpful AI assistant by Cohere. Provide accurate and grounded responses.' }, |
| 2019 | }; |
| 2020 | |
| 2021 | // Architecture → template mapping for auto-suggest |
| 2022 | const ARCH_TO_TEMPLATE = { |
| 2023 | llama: 'llama3', llama2: 'llama3', llama3: 'llama3', codellama: 'llama3', |
| 2024 | mistral: 'mistral', mistral3: 'mistral', mixtral: 'mistral', |
| 2025 | qwen: 'qwen', qwen2: 'qwen', qwen2moe: 'qwen', qwen3moe: 'qwen', |
| 2026 | gemma: 'gemma', gemma2: 'gemma', gemma4: 'gemma', |
| 2027 | phi: 'phi', phi2: 'phi', phi3: 'phi', |
| 2028 | deepseek: 'deepseek', deepseek2: 'deepseek', deepseek3: 'deepseek', |
| 2029 | chatglm: 'chatglm', glm: 'chatglm', |
| 2030 | 'command-r': 'command-r', commandr: 'command-r', |
| 2031 | }; |
| 2032 | |
| 2033 | // ─── State ────────────────────────────────────────────────────── |
| 2034 | let chatAbort = null; |
| 2035 | let chatCount = 0; |
| 2036 | let chatHistory = []; |
| 2037 | let lossChart = null; |
| 2038 | let benchHistoryChart = null; |
| 2039 | let trainingActive = false; |
| 2040 | let trainingSource = null; |
| 2041 | let benchHistory = []; |
| 2042 | |
| 2043 | // ─── Tab switching ────────────────────────────────────────────── |
| 2044 | const TAB_ICONS = { chat:'💬 Chat', train:'🎓 Train', dataset:'📊 Dataset', export:'📤 Export', |
| 2045 | benchmark:'⚡ Benchmark', autotune:'⚙ Auto-Tune', evaluate:'🎯 Evaluate', quantize:'🔮 Quantize', |
| 2046 | merge:'🔗 Merge', checkpoints:'💾 Checkpoints', templates:'📋 Templates', hub:'🤗 HF Hub', |
| 2047 | experiments:'🔬 Experiments', modelcards:'📇 Cards' }; |
| 2048 | document.querySelectorAll('.nav-item').forEach(item => { |
| 2049 | item.addEventListener('click', () => { |
| 2050 | document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active')); |
| 2051 | document.querySelectorAll('.panel').forEach(p => p.classList.remove('active')); |
| 2052 | item.classList.add('active'); |
| 2053 | const tab = item.dataset.tab; |
| 2054 | document.getElementById(`panel-${tab}`).classList.add('active'); |
| 2055 | document.getElementById('topbarTitle').textContent = TAB_ICONS[tab] || tab; |
| 2056 | }); |
| 2057 | }); |
| 2058 | |
| 2059 | // ─── Toast ─── |
| 2060 | function toast(msg, type='info') { |
| 2061 | const el = document.createElement('div'); |
| 2062 | el.className = `toast ${type}`; |
| 2063 | el.textContent = msg; |
| 2064 | document.body.appendChild(el); |
| 2065 | setTimeout(() => el.remove(), 3500); |
| 2066 | } |
| 2067 | |
| 2068 | // ─── API helper ─── |
| 2069 | async function apiFetch(path, opts={}) { |
| 2070 | const resp = await fetch(`${API}${path}`, { |
| 2071 | headers: {'Content-Type': 'application/json'}, |
| 2072 | ...opts |
| 2073 | }); |
| 2074 | if (!resp.ok) { |
| 2075 | const text = await resp.text().catch(() => ''); |
| 2076 | throw new Error(text || `HTTP ${resp.status}`); |
| 2077 | } |
| 2078 | return resp.json(); |
| 2079 | } |
| 2080 | |
| 2081 | // ─── Collapsible ─── |
| 2082 | function toggleCollapse(el) { |
| 2083 | el.classList.toggle('open'); |
| 2084 | const body = el.nextElementSibling; |
| 2085 | body.classList.toggle('open'); |
| 2086 | } |
| 2087 | |
| 2088 | // ─── Refresh ─── |
| 2089 | async function refreshAll() { |
| 2090 | await Promise.all([loadBackend(), loadModels(), loadDatasets()]); |
| 2091 | } |
| 2092 | |
| 2093 | async function loadBackend() { |
| 2094 | try { |
| 2095 | const data = await apiFetch('/api/backend'); |
| 2096 | document.getElementById('statusDot').className = 'status-dot online'; |
| 2097 | document.getElementById('backendName').textContent = data.active || data.backend || 'online'; |
| 2098 | document.getElementById('backendName').style.color = 'var(--green)'; |
| 2099 | const engineName = getEngineDisplayName(getSelectedEngine()); |
| 2100 | document.getElementById('backendEngine').textContent = engineName + ' · online'; |
| 2101 | document.getElementById('backendSpeed').textContent = data.uptime ? `${data.uptime}` : ''; |
| 2102 | // Hide any offline banner |
| 2103 | const banner = document.getElementById('offlineBanner'); |
| 2104 | if (banner) banner.style.display = 'none'; |
| 2105 | } catch(e) { |
| 2106 | document.getElementById('statusDot').className = 'status-dot offline'; |
| 2107 | document.getElementById('backendName').textContent = 'offline'; |
| 2108 | document.getElementById('backendName').style.color = 'var(--red)'; |
| 2109 | const engineName = getEngineDisplayName(getSelectedEngine()); |
| 2110 | document.getElementById('backendEngine').textContent = engineName + ' · offline'; |
| 2111 | document.getElementById('backendSpeed').textContent = ''; |
| 2112 | // Show offline banner with current API URL |
| 2113 | const banner = document.getElementById('offlineBanner'); |
| 2114 | if (banner) { |
| 2115 | const urlEl = document.getElementById('offlineApiUrl'); |
| 2116 | if (urlEl) urlEl.textContent = API; |
| 2117 | banner.style.display = 'block'; |
| 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | async function loadModels() { |
| 2123 | try { |
| 2124 | const data = await apiFetch('/api/models'); |
| 2125 | const models = data.models || []; |
| 2126 | // Store model metadata for auto-suggest |
| 2127 | window._modelData = {}; |
| 2128 | models.forEach(m => { window._modelData[m.path || m.name] = m; }); |
| 2129 | const selects = ['chatModel','trainModel','benchModel','dsModel','mergeBase','evalModel','quantModel','hubModelPath','ckptResumeModel','tuneModel']; |
| 2130 | selects.forEach(id => { |
| 2131 | const sel = document.getElementById(id); |
| 2132 | if (!sel) return; |
| 2133 | const current = sel.value; |
| 2134 | const placeholder = (id === 'chatModel' || id === 'dsModel' || id === 'evalModel' || id === 'quantModel') |
| 2135 | ? 'Select model...' : 'Select a model...'; |
| 2136 | sel.innerHTML = `<option value="">${placeholder}</option>`; |
| 2137 | models.forEach(m => { |
| 2138 | const opt = document.createElement('option'); |
| 2139 | opt.value = m.path || m.name; |
| 2140 | opt.textContent = `${m.name} (${(m.size_gb || 0).toFixed(1)} GB)`; |
| 2141 | if (opt.value === current) opt.selected = true; |
| 2142 | sel.appendChild(opt); |
| 2143 | }); |
| 2144 | }); |
| 2145 | // Show/hide no-models hint |
| 2146 | const hint = document.getElementById('noModelsHint'); |
| 2147 | if (hint) hint.style.display = models.length === 0 ? 'flex' : 'none'; |
| 2148 | } catch(e) { |
| 2149 | console.error('loadModels:', e); |
| 2150 | const hint = document.getElementById('noModelsHint'); |
| 2151 | if (hint) hint.style.display = 'flex'; |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | // Auto-suggest template when user selects a model in the Train tab |
| 2156 | document.addEventListener('DOMContentLoaded', () => { |
| 2157 | const trainModel = document.getElementById('trainModel'); |
| 2158 | if (trainModel) { |
| 2159 | trainModel.addEventListener('change', () => { |
| 2160 | const modelName = trainModel.value; |
| 2161 | if (!modelName || !window._modelData) return; |
| 2162 | const meta = window._modelData[modelName]; |
| 2163 | if (!meta || !meta.architecture) return; |
| 2164 | const arch = meta.architecture.toLowerCase(); |
| 2165 | // Match architecture to template |
| 2166 | for (const [archPrefix, templateId] of Object.entries(ARCH_TO_TEMPLATE)) { |
| 2167 | if (arch.startsWith(archPrefix) || archPrefix.startsWith(arch)) { |
| 2168 | applyTrainTemplate(templateId); |
| 2169 | document.getElementById('trainTemplate').value = templateId; |
| 2170 | toast(`Auto-suggested ${templateId} template for ${arch} model`, 'info'); |
| 2171 | break; |
| 2172 | } |
| 2173 | } |
| 2174 | }); |
| 2175 | } |
| 2176 | }); |
| 2177 | |
| 2178 | async function loadDatasets() { |
| 2179 | try { |
| 2180 | const data = await apiFetch('/api/dataset'); |
| 2181 | const datasets = data.datasets || []; |
| 2182 | const container = document.getElementById('datasetList'); |
| 2183 | if (datasets.length === 0) { |
| 2184 | container.innerHTML = '<span class="text-dim">No datasets found. Create one above.</span>'; |
| 2185 | return; |
| 2186 | } |
| 2187 | container.innerHTML = '<table class="results-table"><thead><tr><th>Name</th><th>Format</th><th>Size</th><th>Samples</th><th>Actions</th></tr></thead><tbody>' + |
| 2188 | datasets.map(d => `<tr> |
| 2189 | <td>${d.name}</td> |
| 2190 | <td><span class="badge badge-${d.format === 'unknown' ? 'beta' : 'new'}">${d.format}</span></td> |
| 2191 | <td>${d.size_mb || (d.size_bytes / 1024 / 1024).toFixed(1) || '—'} MB</td> |
| 2192 | <td>${d.samples || '—'}</td> |
| 2193 | <td> |
| 2194 | <button class="btn btn-dim btn-xs" onclick="showDatasetStats('${d.name}')">📊 Stats</button> |
| 2195 | <button class="btn btn-dim btn-xs" onclick="document.getElementById('convInput').value='${d.name}';document.querySelector('[data-tab=dataset]').click();document.getElementById('convInput').focus()">🔄 Convert</button> |
| 2196 | <button class="btn btn-dim btn-xs" onclick="document.getElementById('trainData').value='${d.path||d.name}';document.querySelector('[data-tab=train]').click()">🎓 Train</button> |
| 2197 | </td></tr>`).join('') + |
| 2198 | '</tbody></table>'; |
| 2199 | } catch(e) { |
| 2200 | document.getElementById('datasetList').innerHTML = '<span class="text-dim">Could not load datasets.</span>'; |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | // ─── Server settings dialog ─── |
| 2205 | function showServerSettings() { |
| 2206 | const overlay = document.createElement('div'); |
| 2207 | overlay.className = 'dialog-overlay'; |
| 2208 | overlay.onclick = (e) => { if (e.target === overlay) overlay.remove(); }; |
| 2209 | const dialog = document.createElement('div'); |
| 2210 | dialog.className = 'dialog'; |
| 2211 | dialog.innerHTML = ` |
| 2212 | <h3>⚙️ Server Settings</h3> |
| 2213 | <label>API Server URL</label> |
| 2214 | <input id="settingsApiUrl" type="text" value="${API}" placeholder="http://hostname:9000" style="font-family:monospace;width:100%;"> |
| 2215 | <div style="font-size:12px;color:var(--dim);margin-bottom:12px;margin-top:-4px;"> |
| 2216 | Enter the URL where your MojoLlama server is running.<br> |
| 2217 | The Studio fetches models and sends chat requests to this server. |
| 2218 | </div> |
| 2219 | <label>Engine</label> |
| 2220 | <select id="settingsEngine" style="margin-bottom:12px"> |
| 2221 | <option value="mojollama">MojoLlama Native</option> |
| 2222 | <option value="llamacpp">llama.cpp</option> |
| 2223 | <option value="max">MAX</option> |
| 2224 | </select> |
| 2225 | <div style="font-size:12px;color:var(--dim);margin-bottom:12px;margin-top:-4px;"> |
| 2226 | Select which inference engine to use for benchmarks and chat. |
| 2227 | </div> |
| 2228 | <div style="display:flex;gap:8px;margin-bottom:12px;" id="testResult"></div> |
| 2229 | <div class="dialog-actions" style="display:flex;gap:8px;justify-content:flex-end;"> |
| 2230 | <button class="btn btn-dim" id="settingsTestBtn" style="flex:0;">🔍 Test Connection</button> |
| 2231 | <button class="btn btn-dim" onclick="this.closest('.dialog-overlay').remove()">Cancel</button> |
| 2232 | <button class="btn btn-primary" id="settingsSaveBtn">Save & Reload</button> |
| 2233 | </div> |
| 2234 | `; |
| 2235 | overlay.appendChild(dialog); |
| 2236 | document.body.appendChild(overlay); |
| 2237 | |
| 2238 | // Set engine value from localStorage |
| 2239 | const savedEngine = localStorage.getItem('mojollama_engine'); |
| 2240 | if (savedEngine) document.getElementById('settingsEngine').value = savedEngine; |
| 2241 | |
| 2242 | document.getElementById('settingsTestBtn').addEventListener('click', async () => { |
| 2243 | const url = document.getElementById('settingsApiUrl').value.trim(); |
| 2244 | const resultDiv = document.getElementById('testResult'); |
| 2245 | resultDiv.innerHTML = '<span class="text-dim">Testing...</span>'; |
| 2246 | try { |
| 2247 | const resp = await fetch(url + '/api/backend', { signal: AbortSignal.timeout(5000) }); |
| 2248 | if (resp.ok) { |
| 2249 | const data = await resp.json(); |
| 2250 | resultDiv.innerHTML = '<span class="text-green">✅ Connected — ' + (data.active || data.backend || 'server') + '</span>'; |
| 2251 | } else { |
| 2252 | resultDiv.innerHTML = '<span class="text-red">❌ Server returned HTTP ' + resp.status + '</span>'; |
| 2253 | } |
| 2254 | } catch(e) { |
| 2255 | resultDiv.innerHTML = '<span class="text-red">❌ Cannot reach this URL — ' + e.message + '</span>'; |
| 2256 | } |
| 2257 | }); |
| 2258 | |
| 2259 | document.getElementById('settingsSaveBtn').addEventListener('click', () => { |
| 2260 | const url = document.getElementById('settingsApiUrl').value.trim(); |
| 2261 | const engine = document.getElementById('settingsEngine').value; |
| 2262 | if (url) { localStorage.setItem('mojollama_api_url', url); } |
| 2263 | localStorage.setItem('mojollama_engine', engine); |
| 2264 | location.reload(); |
| 2265 | }); |
| 2266 | } |
| 2267 | |
| 2268 | // ─── Chat ─── |
| 2269 | async function sendChat() { |
| 2270 | const input = document.getElementById('chatInput'); |
| 2271 | const msg = input.value.trim(); |
| 2272 | if (!msg) return; |
| 2273 | const model = document.getElementById('chatModel').value; |
| 2274 | if (!model) { toast('Select a model first', 'error'); return; } |
| 2275 | |
| 2276 | input.value = ''; |
| 2277 | input.style.height = 'auto'; |
| 2278 | chatCount++; |
| 2279 | |
| 2280 | const container = document.getElementById('chatMessages'); |
| 2281 | const systemPrompt = document.getElementById('chatSystemPrompt').value.trim(); |
| 2282 | |
| 2283 | // Add user message to history |
| 2284 | chatHistory.push({ role: 'user', content: msg }); |
| 2285 | appendMessage('user', 'You', msg); |
| 2286 | |
| 2287 | // Show typing |
| 2288 | const typingId = 'typing-' + Date.now(); |
| 2289 | container.innerHTML += `<div class="typing-indicator" id="${typingId}"><span class="typing-dot"></span><span class="typing-dot"></span><span class="typing-dot"></span></div>`; |
| 2290 | container.scrollTop = container.scrollHeight; |
| 2291 | |
| 2292 | // Assistant placeholder |
| 2293 | const msgId = 'msg-' + Date.now(); |
| 2294 | container.innerHTML += `<div class="msg" id="${msgId}" style="display:none"> |
| 2295 | <div class="msg-row"><div class="msg-avatar assistant">M</div> |
| 2296 | <div class="msg-body"><div class="msg-name assistant">MojoLlama <span class="msg-meta">streaming</span></div> |
| 2297 | <div class="msg-text" id="${msgId}-text"></div></div></div></div>`; |
| 2298 | |
| 2299 | const sendBtn = document.getElementById('chatSendBtn'); |
| 2300 | const stopBtn = document.getElementById('chatStopBtn'); |
| 2301 | sendBtn.disabled = true; |
| 2302 | sendBtn.style.display = 'none'; |
| 2303 | stopBtn.style.display = ''; |
| 2304 | |
| 2305 | const controller = new AbortController(); |
| 2306 | chatAbort = controller; |
| 2307 | |
| 2308 | try { |
| 2309 | const messages = []; |
| 2310 | if (systemPrompt) messages.push({ role: 'system', content: systemPrompt }); |
| 2311 | messages.push(...chatHistory); |
| 2312 | |
| 2313 | const resp = await fetch(`${API}/api/chat`, { |
| 2314 | method: 'POST', |
| 2315 | headers: {'Content-Type': 'application/json'}, |
| 2316 | body: JSON.stringify({ |
| 2317 | model, |
| 2318 | messages, |
| 2319 | prompt: msg, |
| 2320 | max_tokens: parseInt(document.getElementById('chatMaxTokens').value) || 512, |
| 2321 | stream: true, |
| 2322 | temperature: parseFloat(document.getElementById('chatTemp').value), |
| 2323 | top_p: parseFloat(document.getElementById('chatTopP').value), |
| 2324 | frequency_penalty: parseFloat(document.getElementById('chatFreqPen').value), |
| 2325 | presence_penalty: parseFloat(document.getElementById('chatPresPen').value), |
| 2326 | repeat_penalty: parseFloat(document.getElementById('chatRepeatPen').value) |
| 2327 | }), |
| 2328 | signal: controller.signal |
| 2329 | }); |
| 2330 | |
| 2331 | if (!resp.ok) throw new Error(`HTTP ${resp.status}`); |
| 2332 | |
| 2333 | const typingEl = document.getElementById(typingId); |
| 2334 | if (typingEl) typingEl.remove(); |
| 2335 | document.getElementById(msgId).style.display = ''; |
| 2336 | |
| 2337 | const textEl = document.getElementById(`${msgId}-text`); |
| 2338 | let fullText = ''; |
| 2339 | const reader = resp.body.getReader(); |
| 2340 | const decoder = new TextDecoder(); |
| 2341 | let buffer = ''; |
| 2342 | |
| 2343 | while (true) { |
| 2344 | const { done, value } = await reader.read(); |
| 2345 | if (done) break; |
| 2346 | buffer += decoder.decode(value, { stream: true }); |
| 2347 | const lines = buffer.split('\n'); |
| 2348 | buffer = lines.pop() || ''; |
| 2349 | for (const line of lines) { |
| 2350 | if (line.startsWith('data: ')) { |
| 2351 | const chunk = line.slice(6).trim(); |
| 2352 | if (chunk === '[DONE]') continue; |
| 2353 | try { |
| 2354 | const parsed = JSON.parse(chunk); |
| 2355 | const content = parsed.choices?.[0]?.delta?.content || parsed.content || ''; |
| 2356 | if (content) { |
| 2357 | fullText += content; |
| 2358 | textEl.innerHTML = renderMarkdown(fullText); |
| 2359 | container.scrollTop = container.scrollHeight; |
| 2360 | } |
| 2361 | } catch(e) {} |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | // Save to history |
| 2367 | chatHistory.push({ role: 'assistant', content: fullText }); |
| 2368 | const meta = document.querySelector(`#${msgId} .msg-meta`); |
| 2369 | if (meta) { |
| 2370 | const words = fullText.split(/\s+/).length; |
| 2371 | const chars = fullText.length; |
| 2372 | meta.textContent = `${words} words · ${chars} chars`; |
| 2373 | } |
| 2374 | updateChatStats(); |
| 2375 | |
| 2376 | } catch(e) { |
| 2377 | const typingEl = document.getElementById(typingId); |
| 2378 | if (typingEl) typingEl.remove(); |
| 2379 | const msgEl = document.getElementById(msgId); |
| 2380 | if (msgEl) { |
| 2381 | msgEl.style.display = ''; |
| 2382 | document.getElementById(`${msgId}-text`).innerHTML = `<span style="color:var(--red)">${e.name === 'AbortError' ? 'Generation stopped.' : 'Error: ' + e.message}</span>`; |
| 2383 | } |
| 2384 | if (e.name !== 'AbortError') { |
| 2385 | chatHistory.pop(); // Remove user message on error |
| 2386 | } |
| 2387 | } |
| 2388 | |
| 2389 | sendBtn.disabled = false; |
| 2390 | sendBtn.style.display = ''; |
| 2391 | stopBtn.style.display = 'none'; |
| 2392 | chatAbort = null; |
| 2393 | } |
| 2394 | |
| 2395 | function stopChat() { |
| 2396 | if (chatAbort) { chatAbort.abort(); chatAbort = null; } |
| 2397 | } |
| 2398 | |
| 2399 | function appendMessage(role, name, content) { |
| 2400 | const container = document.getElementById('chatMessages'); |
| 2401 | const avatar = role === 'user' ? 'U' : 'M'; |
| 2402 | container.innerHTML += `<div class="msg"><div class="msg-row"> |
| 2403 | <div class="msg-avatar ${role}">${avatar}</div> |
| 2404 | <div class="msg-body"><div class="msg-name ${role}">${name}</div> |
| 2405 | <div class="msg-text">${renderMarkdown(content)}</div></div></div></div>`; |
| 2406 | container.scrollTop = container.scrollHeight; |
| 2407 | } |
| 2408 | |
| 2409 | function clearChat() { |
| 2410 | chatHistory = []; |
| 2411 | chatCount = 0; |
| 2412 | document.getElementById('chatMessages').innerHTML = ` |
| 2413 | <div class="msg"><div class="msg-row"><div class="msg-avatar assistant">M</div> |
| 2414 | <div class="msg-body"><div class="msg-name assistant">MojoLlama <span class="msg-meta">cleared</span></div> |
| 2415 | <div class="msg-text">Chat cleared. Select a model and start chatting.</div></div></div></div>`; |
| 2416 | updateChatStats(); |
| 2417 | } |
| 2418 | |
| 2419 | function updateChatStats() { |
| 2420 | document.getElementById('chatStats').textContent = `${chatCount} messages · ${chatHistory.length} context entries`; |
| 2421 | } |
| 2422 | |
| 2423 | document.getElementById('chatInput').addEventListener('keydown', e => { |
| 2424 | if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendChat(); } |
| 2425 | }); |
| 2426 | |
| 2427 | // Markdown renderer |
| 2428 | function renderMarkdown(text) { |
| 2429 | if (!text) return ''; |
| 2430 | let html = escapeHtml(text); |
| 2431 | html = html.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>'); |
| 2432 | html = html.replace(/`([^`]+)`/g, '<code>$1</code>'); |
| 2433 | html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>'); |
| 2434 | html = html.replace(/\*([^*]+)\*/g, '<em>$1</em>'); |
| 2435 | html = html.replace(/^>\s(.+)$/gm, '<blockquote style="border-left:3px solid var(--accent);padding-left:12px;color:var(--dim)">$1</blockquote>'); |
| 2436 | html = html.replace(/\n/g, '<br>'); |
| 2437 | return html; |
| 2438 | } |
| 2439 | |
| 2440 | function escapeHtml(text) { |
| 2441 | const div = document.createElement('div'); |
| 2442 | div.textContent = text; |
| 2443 | return div.innerHTML; |
| 2444 | } |
| 2445 | |
| 2446 | // ─── Training ─── |
| 2447 | function initLossChart() { |
| 2448 | const ctx = document.getElementById('lossChart').getContext('2d'); |
| 2449 | const gradient = ctx.createLinearGradient(0, 0, 0, 240); |
| 2450 | gradient.addColorStop(0, 'rgba(91,141,239,0.2)'); |
| 2451 | gradient.addColorStop(1, 'rgba(91,141,239,0)'); |
| 2452 | lossChart = new Chart(ctx, { |
| 2453 | type: 'line', |
| 2454 | data: { labels: [], datasets: [{ |
| 2455 | label: 'Loss', data: [], |
| 2456 | borderColor: '#5b8def', backgroundColor: gradient, |
| 2457 | fill: true, tension: 0.4, pointRadius: 1.5, pointHoverRadius: 5, borderWidth: 2 |
| 2458 | }]}, |
| 2459 | options: { |
| 2460 | responsive: true, maintainAspectRatio: false, |
| 2461 | animation: { duration: 150 }, |
| 2462 | scales: { |
| 2463 | x: { grid: { color: 'rgba(37,45,58,0.5)' }, ticks: { color: '#7d8590', font: { size: 10 } } }, |
| 2464 | y: { grid: { color: 'rgba(37,45,58,0.5)' }, ticks: { color: '#7d8590', font: { size: 10 } }, beginAtZero: false } |
| 2465 | }, |
| 2466 | plugins: { legend: { display: false }, |
| 2467 | tooltip: { backgroundColor: 'rgba(18,22,30,0.9)', borderColor: 'rgba(91,141,239,0.3)', borderWidth: 1, titleFont: { size: 11 }, bodyFont: { size: 12 }, padding: 10 } |
| 2468 | } |
| 2469 | } |
| 2470 | }); |
| 2471 | } |
| 2472 | |
| 2473 | function applyTrainTemplate(name) { |
| 2474 | if (!name) return; |
| 2475 | const t = TEMPLATES[name]; |
| 2476 | if (!t) return; |
| 2477 | document.getElementById('trainRank').value = t.rank; |
| 2478 | document.getElementById('trainRankVal').textContent = t.rank; |
| 2479 | document.getElementById('trainAlpha').value = t.alpha; |
| 2480 | document.getElementById('trainLR').value = t.lr; |
| 2481 | document.getElementById('trainScheduler').value = t.scheduler; |
| 2482 | document.getElementById('trainSteps').value = t.steps; |
| 2483 | document.getElementById('trainBatch').value = t.batch; |
| 2484 | document.getElementById('trainGradAccum').value = t.gradAccum; |
| 2485 | document.getElementById('trainWarmup').value = t.warmup; |
| 2486 | document.getElementById('trainWeightDecay').value = t.weightDecay; |
| 2487 | document.getElementById('trainModules').value = t.modules; |
| 2488 | document.getElementById('trainDropout').value = t.dropout; |
| 2489 | document.getElementById('trainCtxLen').value = t.ctxLen; |
| 2490 | document.getElementById('trainFlashAttn').checked = t.flashAttn; |
| 2491 | document.getElementById('trainFp16').checked = t.fp16; |
| 2492 | document.getElementById('chatSystemPrompt').value = t.systemPrompt; |
| 2493 | toast(`Applied ${name} template`, 'success'); |
| 2494 | } |
| 2495 | |
| 2496 | function resetTrainConfig() { |
| 2497 | document.getElementById('trainTemplate').value = ''; |
| 2498 | document.getElementById('trainRank').value = 16; |
| 2499 | document.getElementById('trainRankVal').textContent = '16'; |
| 2500 | document.getElementById('trainAlpha').value = 32; |
| 2501 | document.getElementById('trainLR').value = '2e-4'; |
| 2502 | document.getElementById('trainScheduler').value = 'cosine'; |
| 2503 | document.getElementById('trainSteps').value = 100; |
| 2504 | document.getElementById('trainBatch').value = 4; |
| 2505 | document.getElementById('trainGradAccum').value = 1; |
| 2506 | document.getElementById('trainWarmup').value = 10; |
| 2507 | document.getElementById('trainWeightDecay').value = '0.01'; |
| 2508 | document.getElementById('trainModules').value = 'q_proj,v_proj'; |
| 2509 | document.getElementById('trainDropout').value = '0.05'; |
| 2510 | document.getElementById('trainCtxLen').value = 2048; |
| 2511 | document.getElementById('trainFlashAttn').checked = true; |
| 2512 | document.getElementById('trainFp16').checked = true; |
| 2513 | document.getElementById('trainGradientCheckpointing').checked = false; |
| 2514 | document.getElementById('trainCheckpointEvery').value = 100; |
| 2515 | document.getElementById('trainResume').value = ''; |
| 2516 | document.getElementById('trainSeed').value = 42; |
| 2517 | document.getElementById('trainEvalSteps').value = 0; |
| 2518 | toast('Training config reset', 'info'); |
| 2519 | } |
| 2520 | |
| 2521 | async function startTraining() { |
| 2522 | const model = document.getElementById('trainModel').value; |
| 2523 | const data = document.getElementById('trainData').value; |
| 2524 | if (!model || !data) { toast('Select model and dataset', 'error'); return; } |
| 2525 | |
| 2526 | document.getElementById('trainStartBtn').disabled = true; |
| 2527 | document.getElementById('trainStopBtn').disabled = false; |
| 2528 | document.getElementById('trainStatusBadge').textContent = 'running'; |
| 2529 | document.getElementById('trainStatusBadge').className = 'badge badge-new'; |
| 2530 | document.getElementById('trainStatusBadge').style.color = 'var(--green)'; |
| 2531 | trainingActive = true; |
| 2532 | |
| 2533 | if (!lossChart) initLossChart(); |
| 2534 | const log = document.getElementById('trainLog'); |
| 2535 | log.textContent = 'Starting training...\n'; |
| 2536 | |
| 2537 | // Auto-start experiment tracking |
| 2538 | let trainExpId = document.getElementById('expCurrentRunId').value; |
| 2539 | if (!trainExpId) { |
| 2540 | try { |
| 2541 | const steps = parseInt(document.getElementById('trainSteps').value) || 100; |
| 2542 | const run = await apiFetch('/api/experiments/start', { |
| 2543 | method: 'POST', |
| 2544 | body: JSON.stringify({ |
| 2545 | name: `train-${model.split('/').pop().replace('.gguf','')}`, |
| 2546 | description: `Auto-tracked training: ${model}, ${data}`, |
| 2547 | tags: {model: model.split('/').pop(), dataset: data.split('/').pop()}, |
| 2548 | params: { |
| 2549 | lora_rank: parseInt(document.getElementById('trainRank').value), |
| 2550 | lora_alpha: parseInt(document.getElementById('trainAlpha').value), |
| 2551 | lr: document.getElementById('trainLR').value, |
| 2552 | steps, |
| 2553 | batch: parseInt(document.getElementById('trainBatch').value), |
| 2554 | }, |
| 2555 | auto_wandb: true, |
| 2556 | auto_mlflow: true, |
| 2557 | }) |
| 2558 | }); |
| 2559 | trainExpId = run.id; |
| 2560 | document.getElementById('expCurrentRunId').value = run.id; |
| 2561 | document.getElementById('expStatusLabel').textContent = `▶ Training: ${run.display_name}`; |
| 2562 | document.getElementById('expStopBtn').disabled = false; |
| 2563 | log.textContent += `📊 Experiment ${run.id} started\n`; |
| 2564 | } catch(e) { |
| 2565 | log.textContent += `⚠️ Experiment tracking init failed: ${e.message}\n`; |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | if (trainingSource) trainingSource.close(); |
| 2570 | trainingSource = new EventSource(`${API}/api/train/metrics`); |
| 2571 | trainingSource.onmessage = (e) => { |
| 2572 | try { |
| 2573 | const data = JSON.parse(e.data); |
| 2574 | updateTrainingMetrics(data); |
| 2575 | // Auto-log metrics to experiment tracker |
| 2576 | if (trainExpId) { |
| 2577 | apiFetch(`/api/experiments/${trainExpId}/log-multi`, { |
| 2578 | method: 'POST', |
| 2579 | body: JSON.stringify({step: data.step || 0, metrics: {loss: data.loss || 0, accuracy: data.accuracy || 0, eval_loss: data.eval_loss || 0}}) |
| 2580 | }).catch(() => {}); |
| 2581 | } |
| 2582 | } catch(err) {} |
| 2583 | }; |
| 2584 | |
| 2585 | try { |
| 2586 | const resp = await fetch(`${API}/train`, { |
| 2587 | method: 'POST', |
| 2588 | headers: {'Content-Type': 'application/json'}, |
| 2589 | body: JSON.stringify({ |
| 2590 | model, data, |
| 2591 | lora_rank: parseInt(document.getElementById('trainRank').value), |
| 2592 | lora_alpha: parseInt(document.getElementById('trainAlpha').value), |
| 2593 | lr: document.getElementById('trainLR').value, |
| 2594 | scheduler: document.getElementById('trainScheduler').value, |
| 2595 | steps: parseInt(document.getElementById('trainSteps').value), |
| 2596 | batch: parseInt(document.getElementById('trainBatch').value), |
| 2597 | grad_accum: parseInt(document.getElementById('trainGradAccum').value), |
| 2598 | warmup: parseInt(document.getElementById('trainWarmup').value), |
| 2599 | weight_decay: document.getElementById('trainWeightDecay').value, |
| 2600 | modules: document.getElementById('trainModules').value, |
| 2601 | dropout: document.getElementById('trainDropout').value, |
| 2602 | ctx_len: parseInt(document.getElementById('trainCtxLen').value), |
| 2603 | flash_attn: document.getElementById('trainFlashAttn').checked, |
| 2604 | fp16: document.getElementById('trainFp16').checked, |
| 2605 | gradient_checkpointing: document.getElementById('trainGradientCheckpointing').checked, |
| 2606 | checkpoint_every: parseInt(document.getElementById('trainCheckpointEvery').value), |
| 2607 | resume: document.getElementById('trainResume').value || '', |
| 2608 | seed: parseInt(document.getElementById('trainSeed').value), |
| 2609 | eval_steps: parseInt(document.getElementById('trainEvalSteps').value) |
| 2610 | }) |
| 2611 | }); |
| 2612 | const reader = resp.body.getReader(); |
| 2613 | const decoder = new TextDecoder(); |
| 2614 | while (true) { |
| 2615 | const {done, value} = await reader.read(); |
| 2616 | if (done) break; |
| 2617 | log.textContent += decoder.decode(value, {stream: true}); |
| 2618 | log.scrollTop = log.scrollHeight; |
| 2619 | } |
| 2620 | } catch(e) { log.textContent += `\nError: ${e.message}`; } |
| 2621 | |
| 2622 | trainingActive = false; |
| 2623 | document.getElementById('trainStartBtn').disabled = false; |
| 2624 | document.getElementById('trainStopBtn').disabled = true; |
| 2625 | document.getElementById('trainStatusBadge').textContent = 'done'; |
| 2626 | if (trainingSource) { trainingSource.close(); trainingSource = null; } |
| 2627 | // Auto-stop experiment |
| 2628 | const expRunId = document.getElementById('expCurrentRunId').value; |
| 2629 | if (expRunId) { |
| 2630 | apiFetch(`/api/experiments/${expRunId}/stop`, { |
| 2631 | method: 'POST', |
| 2632 | body: JSON.stringify({status: 'completed'}) |
| 2633 | }).then(() => { |
| 2634 | document.getElementById('expCurrentRunId').value = ''; |
| 2635 | document.getElementById('expStatusLabel').textContent = 'No active experiment'; |
| 2636 | document.getElementById('expStopBtn').disabled = true; |
| 2637 | toast('Experiment auto-stopped', 'success'); |
| 2638 | loadExperiments(); |
| 2639 | }).catch(() => {}); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | function stopTraining() { |
| 2644 | trainingActive = false; |
| 2645 | document.getElementById('trainStartBtn').disabled = false; |
| 2646 | document.getElementById('trainStopBtn').disabled = true; |
| 2647 | document.getElementById('trainStatusBadge').textContent = 'stopped'; |
| 2648 | document.getElementById('trainStatusBadge').style.color = 'var(--yellow)'; |
| 2649 | if (trainingSource) { trainingSource.close(); trainingSource = null; } |
| 2650 | // Auto-stop experiment on cancel |
| 2651 | const expRunId = document.getElementById('expCurrentRunId').value; |
| 2652 | if (expRunId) { |
| 2653 | apiFetch(`/api/experiments/${expRunId}/stop`, { |
| 2654 | method: 'POST', |
| 2655 | body: JSON.stringify({status: 'cancelled'}) |
| 2656 | }).then(() => { |
| 2657 | document.getElementById('expCurrentRunId').value = ''; |
| 2658 | document.getElementById('expStatusLabel').textContent = 'No active experiment'; |
| 2659 | document.getElementById('expStopBtn').disabled = true; |
| 2660 | loadExperiments(); |
| 2661 | }).catch(() => {}); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | function updateTrainingMetrics(data) { |
| 2666 | document.getElementById('trainStep').textContent = data.step || '—'; |
| 2667 | document.getElementById('trainLoss').textContent = data.loss ? data.loss.toFixed(4) : '—'; |
| 2668 | document.getElementById('trainProgress').textContent = data.progress || '—'; |
| 2669 | document.getElementById('trainSpeed').textContent = data.speed || '—'; |
| 2670 | if (data.loss && lossChart) { |
| 2671 | lossChart.data.labels.push(data.step || lossChart.data.labels.length); |
| 2672 | lossChart.data.datasets[0].data.push(data.loss); |
| 2673 | if (lossChart.data.labels.length > 500) { |
| 2674 | lossChart.data.labels.shift(); |
| 2675 | lossChart.data.datasets[0].data.shift(); |
| 2676 | } |
| 2677 | lossChart.update(); |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | // ─── Dataset ─── |
| 2682 | |
| 2683 | function updateDatasetForm() { |
| 2684 | const format = document.getElementById('dsFormat').value; |
| 2685 | const fields = document.getElementById('dsFormFields'); |
| 2686 | if (format === 'alpaca') { |
| 2687 | fields.innerHTML = '<label id="dsField1Label">Instruction</label>' + |
| 2688 | '<textarea id="dsField1" rows="5" placeholder="What is machine learning?\nExplain transformers\nHow does attention work?"></textarea>' + |
| 2689 | '<label id="dsField2Label">Input (optional)</label>' + |
| 2690 | '<textarea id="dsField2" rows="2" placeholder="Context or input text per line (leave blank if none)"></textarea>'; |
| 2691 | } else if (format === 'sharegpt') { |
| 2692 | fields.innerHTML = '<label id="dsField1Label">Human messages (one per line)</label>' + |
| 2693 | '<textarea id="dsField1" rows="5" placeholder="What is ML?\nExplain attention\nHow do transformers work?"></textarea>' + |
| 2694 | '<label id="dsField2Label">Assistant responses (one per line)</label>' + |
| 2695 | '<textarea id="dsField2" rows="5" placeholder="Machine learning is...\nAttention is...\nTransformers work by..."></textarea>'; |
| 2696 | } else if (format === 'openai') { |
| 2697 | fields.innerHTML = '<label id="dsField1Label">User messages (one per line)</label>' + |
| 2698 | '<textarea id="dsField1" rows="5" placeholder="What is ML?\nExplain attention"></textarea>' + |
| 2699 | '<label id="dsField2Label">Assistant responses (one per line)</label>' + |
| 2700 | '<textarea id="dsField2" rows="5" placeholder="Machine learning is...\nAttention is a mechanism..."></textarea>'; |
| 2701 | } else if (format === 'preference') { |
| 2702 | fields.innerHTML = '<label id="dsField1Label">Chosen (preferred) response (one per line)</label>' + |
| 2703 | '<textarea id="dsField1" rows="3" placeholder="The correct answer is..."></textarea>' + |
| 2704 | '<label id="dsField2Label">Rejected response (one per line)</label>' + |
| 2705 | '<textarea id="dsField2" rows="3" placeholder="The wrong answer is..."></textarea>' + |
| 2706 | '<div class="text-dim" style="font-size:11px;margin-top:4px">For DPO/ORPO/KTO training — pairs of chosen vs rejected responses</div>'; |
| 2707 | } else { |
| 2708 | fields.innerHTML = '<label id="dsField1Label">Prompts (one per line)</label>' + |
| 2709 | '<textarea id="dsField1" rows="5" placeholder="What is ML?\nExplain attention"></textarea>' + |
| 2710 | '<label id="dsField2Label">Completions (one per line, optional)</label>' + |
| 2711 | '<textarea id="dsField2" rows="2" placeholder="Leave blank for auto-label"></textarea>'; |
| 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | function createDataset() { |
| 2716 | const format = document.getElementById('dsFormat').value; |
| 2717 | const field1 = document.getElementById('dsField1').value.split('\n').filter(p => p.trim()); |
| 2718 | const field2 = document.getElementById('dsField2').value.split('\n').filter(p => p.trim()); |
| 2719 | const output = document.getElementById('dsOutput').value || 'dataset.jsonl'; |
| 2720 | const log = document.getElementById('dsLog'); |
| 2721 | if (field1.length === 0) { toast('Enter at least one entry', 'error'); return; } |
| 2722 | |
| 2723 | let jsonl; |
| 2724 | if (format === 'alpaca') { |
| 2725 | jsonl = field1.map((instr, i) => JSON.stringify({ |
| 2726 | instruction: instr, input: field2[i] || '', output: '' |
| 2727 | })).join('\n'); |
| 2728 | } else if (format === 'sharegpt') { |
| 2729 | jsonl = field1.map((msg, i) => JSON.stringify({ |
| 2730 | conversations: [ |
| 2731 | { from: 'human', value: msg }, |
| 2732 | { from: 'gpt', value: field2[i] || '' } |
| 2733 | ] |
| 2734 | })).join('\n'); |
| 2735 | } else if (format === 'openai') { |
| 2736 | jsonl = field1.map((msg, i) => JSON.stringify({ |
| 2737 | messages: [ |
| 2738 | { role: 'user', content: msg }, |
| 2739 | { role: 'assistant', content: field2[i] || '' } |
| 2740 | ] |
| 2741 | })).join('\n'); |
| 2742 | } else if (format === 'preference') { |
| 2743 | jsonl = field1.map((chosen, i) => JSON.stringify({ |
| 2744 | chosen: [{ role: 'user', content: 'Instruction' }, { role: 'assistant', content: chosen }], |
| 2745 | rejected: [{ role: 'user', content: 'Instruction' }, { role: 'assistant', content: field2[i] || '' }] |
| 2746 | })).join('\n'); |
| 2747 | } else { |
| 2748 | jsonl = field1.map((p, i) => JSON.stringify({prompt: p, completion: field2[i] || ''})).join('\n'); |
| 2749 | } |
| 2750 | |
| 2751 | log.textContent = `Generated ${field1.length} samples (${format} format) for ${output}:\n${jsonl.slice(0, 500)}...`; |
| 2752 | const blob = new Blob([jsonl], {type: 'application/jsonl'}); |
| 2753 | const url = URL.createObjectURL(blob); |
| 2754 | const a = document.createElement('a'); a.href = url; a.download = output; a.click(); |
| 2755 | URL.revokeObjectURL(url); |
| 2756 | toast(`Created ${field1.length} samples in ${format} format`, 'success'); |
| 2757 | } |
| 2758 | |
| 2759 | async function convertDataset() { |
| 2760 | const input = document.getElementById('convInput').value; |
| 2761 | const format = document.getElementById('convFormat').value; |
| 2762 | const output = document.getElementById('convOutput').value || 'converted.jsonl'; |
| 2763 | const log = document.getElementById('convLog'); |
| 2764 | if (!input) { toast('Enter input file', 'error'); return; } |
| 2765 | log.textContent = 'Converting...\n'; |
| 2766 | try { |
| 2767 | const result = await apiFetch('/api/dataset/convert', { |
| 2768 | method: 'POST', |
| 2769 | body: JSON.stringify({input, format, output}) |
| 2770 | }); |
| 2771 | log.textContent = `✅ Converted: ${result.input_format} → ${result.output_format}\n${result.samples} samples\nOutput: ${result.output_path}`; |
| 2772 | toast('Conversion complete!', 'success'); |
| 2773 | loadDatasets(); |
| 2774 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Conversion failed', 'error'); } |
| 2775 | } |
| 2776 | |
| 2777 | async function autoLabel() { |
| 2778 | const model = document.getElementById('dsModel').value; |
| 2779 | const inputFile = document.getElementById('dsInputFile').value; |
| 2780 | const outputFile = document.getElementById('dsOutputFile').value || 'labeled.jsonl'; |
| 2781 | const maxTokens = parseInt(document.getElementById('dsMaxTokens').value) || 256; |
| 2782 | const temperature = parseFloat(document.getElementById('dsTemperature').value) || 0.7; |
| 2783 | const confThreshold = parseFloat(document.getElementById('dsConfThreshold').value) || 0.0; |
| 2784 | const batchSize = parseInt(document.getElementById('dsBatchSize').value) || 1; |
| 2785 | const btn = document.getElementById('dsAutoBtn'); |
| 2786 | const log = document.getElementById('dsAutoLog'); |
| 2787 | if (!model || !inputFile) { toast('Select model and input file', 'error'); return; } |
| 2788 | |
| 2789 | btn.disabled = true; btn.textContent = '⏳ Labeling...'; log.textContent = 'Starting auto-label...\n'; |
| 2790 | try { |
| 2791 | const resp = await fetch(`${API}/api/dataset/auto-label`, { |
| 2792 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 2793 | body: JSON.stringify({ |
| 2794 | model, input: inputFile, output: outputFile, |
| 2795 | max_tokens: maxTokens, temperature, |
| 2796 | confidence_threshold: confThreshold, batch_size: batchSize |
| 2797 | }) |
| 2798 | }); |
| 2799 | const reader = resp.body.getReader(); |
| 2800 | const decoder = new TextDecoder(); |
| 2801 | while (true) { |
| 2802 | const {done, value} = await reader.read(); if (done) break; |
| 2803 | log.textContent += decoder.decode(value, {stream: true}); log.scrollTop = log.scrollHeight; |
| 2804 | } |
| 2805 | toast('Auto-label complete!', 'success'); loadDatasets(); |
| 2806 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Auto-label failed', 'error'); } |
| 2807 | btn.disabled = false; btn.textContent = '✨ Auto-Label Dataset'; |
| 2808 | } |
| 2809 | |
| 2810 | async function splitDataset() { |
| 2811 | const input = document.getElementById('splitInput').value; |
| 2812 | const trainPct = parseInt(document.getElementById('splitTrain').value) || 80; |
| 2813 | const valPct = parseInt(document.getElementById('splitVal').value) || 10; |
| 2814 | const testPct = parseInt(document.getElementById('splitTest').value) || 10; |
| 2815 | const log = document.getElementById('splitLog'); |
| 2816 | if (!input) { toast('Enter dataset path', 'error'); return; } |
| 2817 | log.textContent = `Splitting ${input}...\n`; |
| 2818 | |
| 2819 | // Client-side: call the stats endpoint to confirm the dataset exists |
| 2820 | try { |
| 2821 | const info = await apiFetch(`/api/dataset/info?dataset=${encodeURIComponent(input)}`); |
| 2822 | log.textContent += `Dataset: ${info.name}\nFormat: ${info.format}\nSamples: ${info.line_count}\n\n`; |
| 2823 | log.textContent += `Split: ${trainPct}% train, ${valPct}% val, ${testPct}% test\n`; |
| 2824 | log.textContent += `Output prefix: ${input.replace('.jsonl', '')}\n\n`; |
| 2825 | log.textContent += '✅ Split configuration ready. Run in CLI:\n'; |
| 2826 | log.textContent += `mojollama dataset split --input ${input} --train-ratio 0.${trainPct} --val-ratio 0.${valPct} --test-ratio 0.${testPct}`; |
| 2827 | toast('Split config shown in log', 'success'); |
| 2828 | } catch(e) { |
| 2829 | log.textContent += `\nError: ${e.message}`; |
| 2830 | toast('Failed to read dataset info', 'error'); |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | async function showDatasetStats(name) { |
| 2835 | const card = document.getElementById('dsStatsCard'); |
| 2836 | const content = document.getElementById('dsStatsContent'); |
| 2837 | card.style.display = 'block'; |
| 2838 | content.innerHTML = 'Loading...'; |
| 2839 | try { |
| 2840 | const stats = await apiFetch(`/api/dataset/stats?dataset=${encodeURIComponent(name)}`); |
| 2841 | content.innerHTML = ` |
| 2842 | <div class="row"> |
| 2843 | <div style="flex:1"> |
| 2844 | <div class="stat"><span class="stat-label">Samples</span><span class="stat-value">${stats.total_samples || 0}</span></div> |
| 2845 | <div class="stat"><span class="stat-label">Est. Tokens</span><span class="stat-value">${(stats.estimated_tokens || 0).toLocaleString()}</span></div> |
| 2846 | <div class="stat"><span class="stat-label">Vocab Size</span><span class="stat-value">${(stats.vocab_size || 0).toLocaleString()}</span></div> |
| 2847 | </div> |
| 2848 | <div style="flex:1"> |
| 2849 | <div class="stat"><span class="stat-label">Avg Length</span><span class="stat-value">${stats.length?.mean || '—'}</span></div> |
| 2850 | <div class="stat"><span class="stat-label">Median Length</span><span class="stat-value">${stats.length?.median || '—'}</span></div> |
| 2851 | <div class="stat"><span class="stat-label">Max Length</span><span class="stat-value">${stats.length?.max || '—'}</span></div> |
| 2852 | </div> |
| 2853 | <div style="flex:1"> |
| 2854 | <div class="stat"><span class="stat-label">Avg Prompt</span><span class="stat-value">${stats.prompt_length?.mean || '—'}</span></div> |
| 2855 | <div class="stat"><span class="stat-label">Avg Completion</span><span class="stat-value">${stats.completion_length?.mean || '—'}</span></div> |
| 2856 | </div> |
| 2857 | </div> |
| 2858 | `; |
| 2859 | } catch(e) { |
| 2860 | content.innerHTML = `<span class="text-red">Failed to load stats: ${e.message}</span>`; |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | // ─── Export ─── |
| 2865 | async function startExport() { |
| 2866 | const model = document.getElementById('exportModel').value; |
| 2867 | const outtype = document.getElementById('exportType').value; |
| 2868 | const outfile = document.getElementById('exportOutput').value || `${model.split('/').pop()}-${outtype}.gguf`; |
| 2869 | const btn = document.getElementById('exportBtn'); |
| 2870 | const log = document.getElementById('exportLog'); |
| 2871 | if (!model) { toast('Enter a HuggingFace model ID', 'error'); return; } |
| 2872 | |
| 2873 | btn.disabled = true; btn.textContent = '⏳ Exporting...'; log.textContent = 'Starting export...\n'; |
| 2874 | try { |
| 2875 | const resp = await fetch(`${API}/api/export`, { |
| 2876 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 2877 | body: JSON.stringify({model, outtype, outfile}) |
| 2878 | }); |
| 2879 | const result = await resp.json(); |
| 2880 | const jobId = result.job_id; |
| 2881 | log.textContent += `Job ID: ${jobId}\n`; |
| 2882 | while (true) { |
| 2883 | await new Promise(r => setTimeout(r, 1000)); |
| 2884 | const status = await apiFetch(`/api/export/${jobId}`); |
| 2885 | log.textContent = status.log || log.textContent; log.scrollTop = log.scrollHeight; |
| 2886 | if (status.status === 'done') { toast('Export complete!', 'success'); break; } |
| 2887 | if (status.status === 'error') { toast('Export failed!', 'error'); break; } |
| 2888 | } |
| 2889 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Export failed', 'error'); } |
| 2890 | btn.disabled = false; btn.textContent = '📤 Start Export'; loadModels(); |
| 2891 | } |
| 2892 | |
| 2893 | // ─── Benchmark ─── |
| 2894 | let benchEngineMode = 'mojollama'; |
| 2895 | let benchLatencyHistory = []; |
| 2896 | let benchLatencyChart = null; |
| 2897 | |
| 2898 | function setBenchEngine(engine) { |
| 2899 | benchEngineMode = engine; |
| 2900 | document.querySelectorAll('#benchEnginePills .engine-pill').forEach(p => p.classList.remove('active')); |
| 2901 | document.querySelector(`#benchEnginePills [data-engine="${engine}"]`).classList.add('active'); |
| 2902 | // Show/hide compare card |
| 2903 | const compareCard = document.getElementById('benchCompareCard'); |
| 2904 | if (compareCard) { |
| 2905 | compareCard.style.display = engine === 'both' ? '' : 'none'; |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | function updateGauge(tokPerSec) { |
| 2910 | const gaugeCard = document.getElementById('benchGaugeCard'); |
| 2911 | gaugeCard.style.display = ''; |
| 2912 | const val = parseFloat(tokPerSec) || 0; |
| 2913 | const maxVal = Math.max(val * 1.5, 100); |
| 2914 | const fraction = Math.min(val / maxVal, 1); |
| 2915 | const circumference = 251; // 2 * PI * 40 ≈ 251 |
| 2916 | const dashLen = fraction * circumference; |
| 2917 | document.getElementById('gaugeArc').setAttribute('stroke-dasharray', `${dashLen} ${circumference}`); |
| 2918 | document.getElementById('gaugeText').textContent = val.toFixed(1); |
| 2919 | } |
| 2920 | |
| 2921 | function updateBenchMemory(modelSizeGb) { |
| 2922 | const card = document.getElementById('benchMemCard'); |
| 2923 | card.style.display = ''; |
| 2924 | const kvCacheGb = (parseInt(document.getElementById('benchPromptTokens').value) || 512) * 2 * 2 / 1024 / 1024; // rough estimate |
| 2925 | const total = (parseFloat(modelSizeGb) || 0) + kvCacheGb; |
| 2926 | document.getElementById('benchMemValue').textContent = `${(modelSizeGb || '—').toFixed(1)} GB model + ${kvCacheGb.toFixed(2)} GB KV cache ≈ ${total.toFixed(1)} GB total`; |
| 2927 | } |
| 2928 | |
| 2929 | function initBenchLatencyChart() { |
| 2930 | const ctx = document.getElementById('benchHistoryChart').getContext('2d'); |
| 2931 | benchLatencyChart = new Chart(ctx, { |
| 2932 | type: 'line', |
| 2933 | data: { |
| 2934 | labels: [], |
| 2935 | datasets: [{ |
| 2936 | label: 'Latency (s)', |
| 2937 | data: [], |
| 2938 | borderColor: '#8B5CF6', |
| 2939 | backgroundColor: 'rgba(139,92,246,0.1)', |
| 2940 | fill: true, |
| 2941 | tension: 0.3, |
| 2942 | pointRadius: 2, |
| 2943 | pointHoverRadius: 5, |
| 2944 | borderWidth: 2 |
| 2945 | }] |
| 2946 | }, |
| 2947 | options: { |
| 2948 | responsive: true, maintainAspectRatio: false, |
| 2949 | animation: { duration: 150 }, |
| 2950 | scales: { |
| 2951 | x: { grid: { color: 'rgba(37,45,58,0.5)' }, ticks: { color: '#7d8590', font: { size: 9 } } }, |
| 2952 | y: { grid: { color: 'rgba(37,45,58,0.5)' }, ticks: { color: '#7d8590', font: { size: 9 } }, beginAtZero: true, title: { display: true, text: 'Seconds', color: '#7d8590', font: { size: 10 } } } |
| 2953 | }, |
| 2954 | plugins: { |
| 2955 | legend: { display: false }, |
| 2956 | tooltip: { backgroundColor: 'rgba(18,22,30,0.9)', borderColor: 'rgba(91,141,239,0.3)', borderWidth: 1, titleFont: { size: 11 }, bodyFont: { size: 12 }, padding: 10 } |
| 2957 | } |
| 2958 | } |
| 2959 | }); |
| 2960 | } |
| 2961 | |
| 2962 | function updateBenchLatencyChart(timeSeconds) { |
| 2963 | if (!benchLatencyChart) initBenchLatencyChart(); |
| 2964 | document.getElementById('benchHistoryCard').style.display = ''; |
| 2965 | benchLatencyHistory.push(parseFloat(timeSeconds) || 0); |
| 2966 | benchLatencyChart.data.labels.push(`Run ${benchLatencyHistory.length}`); |
| 2967 | benchLatencyChart.data.datasets[0].data.push(parseFloat(timeSeconds) || 0); |
| 2968 | if (benchLatencyChart.data.labels.length > 50) { |
| 2969 | benchLatencyChart.data.labels.shift(); |
| 2970 | benchLatencyChart.data.datasets[0].data.shift(); |
| 2971 | } |
| 2972 | benchLatencyChart.update(); |
| 2973 | } |
| 2974 | |
| 2975 | async function runBenchmark() { |
| 2976 | const model = document.getElementById('benchModel').value; |
| 2977 | const tokens = parseInt(document.getElementById('benchTokens').value) || 128; |
| 2978 | const promptTokens = parseInt(document.getElementById('benchPromptTokens').value) || 512; |
| 2979 | const threads = parseInt(document.getElementById('benchThreads').value) || 0; |
| 2980 | const prompt = document.getElementById('benchPrompt').value || ''; |
| 2981 | const btn = document.getElementById('benchBtn'); |
| 2982 | const results = document.getElementById('benchResults'); |
| 2983 | if (!model) { toast('Select a model', 'error'); return; } |
| 2984 | |
| 2985 | btn.disabled = true; btn.textContent = '⏳ Benchmarking...'; |
| 2986 | results.innerHTML = '<tr><td class="text-dim">Running benchmark...</td><td></td></tr>'; |
| 2987 | |
| 2988 | const enginesToRun = benchEngineMode === 'both' ? ['mojollama', 'llamacpp'] : [benchEngineMode]; |
| 2989 | const allResults = []; |
| 2990 | const engineNames = { mojollama: 'MojoLlama', llamacpp: 'llama.cpp' }; |
| 2991 | |
| 2992 | try { |
| 2993 | for (const engine of enginesToRun) { |
| 2994 | const engineDisplay = engineNames[engine] || engine; |
| 2995 | results.innerHTML = `<tr><td class="text-dim">Running benchmark with ${engineDisplay}...</td><td></td></tr>`; |
| 2996 | const data = await apiFetch('/api/benchmark', { |
| 2997 | method: 'POST', |
| 2998 | body: JSON.stringify({model, prompt, max_tokens: tokens, prompt_tokens: promptTokens, threads, engine}) |
| 2999 | }); |
| 3000 | data._engine = engine; |
| 3001 | data._engineDisplay = engineDisplay; |
| 3002 | allResults.push(data); |
| 3003 | } |
| 3004 | |
| 3005 | // Take the last result for primary display |
| 3006 | const primaryData = allResults[allResults.length - 1]; |
| 3007 | const ppSpeed = primaryData.prompt_tokens_per_second || '—'; |
| 3008 | const tgSpeed = primaryData.tokens_per_second || '—'; |
| 3009 | const totalTime = primaryData.total_time_seconds || 0; |
| 3010 | |
| 3011 | results.innerHTML = ` |
| 3012 | <tr><td>Prompt Processing</td><td class="text-green" style="font-weight:700">${ppSpeed} tok/s</td></tr> |
| 3013 | <tr><td>Text Generation</td><td class="text-green" style="font-weight:700">${tgSpeed} tok/s</td></tr> |
| 3014 | <tr><td>Total Time</td><td>${totalTime.toFixed(2)}s</td></tr> |
| 3015 | <tr><td>Prompt Tokens</td><td>${primaryData.prompt_tokens || 0}</td></tr> |
| 3016 | <tr><td>Generated Tokens</td><td>${primaryData.generated_tokens || 0}</td></tr> |
| 3017 | <tr><td>Backend</td><td>${primaryData.backend || primaryData._engineDisplay || '—'}</td></tr> |
| 3018 | <tr><td>Response Preview</td><td class="text-dim" style="max-width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${escapeHtml((primaryData.response || '').slice(0,100))}</td></tr> |
| 3019 | `; |
| 3020 | |
| 3021 | // Update gauge |
| 3022 | updateGauge(tgSpeed); |
| 3023 | |
| 3024 | // Update memory |
| 3025 | if (primaryData.model_size_gb) { |
| 3026 | updateBenchMemory(primaryData.model_size_gb); |
| 3027 | } else { |
| 3028 | // Try to estimate from model metadata |
| 3029 | const meta = window._modelData && window._modelData[model]; |
| 3030 | if (meta && meta.size_gb) { |
| 3031 | updateBenchMemory(meta.size_gb); |
| 3032 | } else { |
| 3033 | document.getElementById('benchMemCard').style.display = 'none'; |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | // Update latency chart |
| 3038 | updateBenchLatencyChart(totalTime); |
| 3039 | |
| 3040 | // Show comparison if both engines |
| 3041 | if (allResults.length === 2) { |
| 3042 | const mojoData = allResults[0]._engine === 'mojollama' ? allResults[0] : allResults[1]; |
| 3043 | const llamaData = allResults[0]._engine === 'llamacpp' ? allResults[0] : allResults[1]; |
| 3044 | const mojoTg = parseFloat(mojoData.tokens_per_second) || 0; |
| 3045 | const llamaTg = parseFloat(llamaData.tokens_per_second) || 0; |
| 3046 | const delta = mojoTg - llamaTg; |
| 3047 | const deltaPct = llamaTg > 0 ? ((delta / llamaTg) * 100).toFixed(1) : '—'; |
| 3048 | const deltaClass = delta >= 0 ? 'positive' : 'negative'; |
| 3049 | const deltaSign = delta >= 0 ? '+' : ''; |
| 3050 | |
| 3051 | document.getElementById('benchCompareCard').style.display = ''; |
| 3052 | document.getElementById('benchCompareBody').innerHTML = ` |
| 3053 | <table class="compare-table"> |
| 3054 | <thead><tr><th>Metric</th><th>MojoLlama</th><th>llama.cpp</th><th>Delta</th></tr></thead> |
| 3055 | <tbody> |
| 3056 | <tr><td>Generation Speed</td><td>${mojoTg.toFixed(1)} tok/s</td><td>${llamaTg.toFixed(1)} tok/s</td><td class="${deltaClass}">${deltaSign}${delta.toFixed(1)} tok/s (${deltaSign}${deltaPct}%)</td></tr> |
| 3057 | <tr><td>Prompt Processing</td><td>${(parseFloat(mojoData.prompt_tokens_per_second) || 0).toFixed(1)} tok/s</td><td>${(parseFloat(llamaData.prompt_tokens_per_second) || 0).toFixed(1)} tok/s</td><td class="${(mojoData.prompt_tokens_per_second > llamaData.prompt_tokens_per_second ? 'positive' : 'negative')}">${deltaSign}${((parseFloat(mojoData.prompt_tokens_per_second)||0) - (parseFloat(llamaData.prompt_tokens_per_second)||0)).toFixed(1)} tok/s</td></tr> |
| 3058 | <tr><td>Total Time</td><td>${(mojoData.total_time_seconds || 0).toFixed(2)}s</td><td>${(llamaData.total_time_seconds || 0).toFixed(2)}s</td><td class="${(mojoData.total_time_seconds < llamaData.total_time_seconds ? 'positive' : 'negative')}">${((mojoData.total_time_seconds||0) - (llamaData.total_time_seconds||0)).toFixed(2)}s</td></tr> |
| 3059 | </tbody> |
| 3060 | </table> |
| 3061 | `; |
| 3062 | } |
| 3063 | |
| 3064 | // Add to history bar chart (existing) |
| 3065 | benchHistory.push({ pp: parseFloat(ppSpeed) || 0, tg: parseFloat(tgSpeed) || 0, model: model.split('/').pop() }); |
| 3066 | if (benchHistory.length > 1) showBenchHistory(); |
| 3067 | |
| 3068 | toast('Benchmark complete!', 'success'); |
| 3069 | } catch(e) { |
| 3070 | results.innerHTML = `<tr><td class="text-red">Error: ${e.message}</td><td></td></tr>`; |
| 3071 | toast('Benchmark failed', 'error'); |
| 3072 | } |
| 3073 | btn.disabled = false; btn.textContent = '⚡ Run Benchmark'; |
| 3074 | } |
| 3075 | |
| 3076 | function showBenchHistory() { |
| 3077 | document.getElementById('benchHistoryCard').style.display = ''; |
| 3078 | // If latency chart is active, add bar data to it instead of creating separate chart |
| 3079 | if (benchLatencyChart) { |
| 3080 | // Update the latency chart title to reflect we have bar data too |
| 3081 | return; |
| 3082 | } |
| 3083 | if (!benchHistoryChart) { |
| 3084 | const ctx = document.getElementById('benchHistoryChart').getContext('2d'); |
| 3085 | benchHistoryChart = new Chart(ctx, { |
| 3086 | type: 'bar', data: { labels: [], datasets: [ |
| 3087 | { label: 'Prompt tok/s', data: [], backgroundColor: 'rgba(91,141,239,0.7)', borderRadius: 4 }, |
| 3088 | { label: 'Gen tok/s', data: [], backgroundColor: 'rgba(63,185,80,0.7)', borderRadius: 4 } |
| 3089 | ]}, |
| 3090 | options: { responsive: true, maintainAspectRatio: false, scales: { |
| 3091 | x: { grid: { display: false }, ticks: { color: '#7d8590', font: { size: 9 } } }, |
| 3092 | y: { grid: { color: 'rgba(37,45,58,0.5)' }, ticks: { color: '#7d8590', font: { size: 9 } } } |
| 3093 | }, plugins: { legend: { labels: { color: '#7d8590', font: { size: 10 } } } } } |
| 3094 | }); |
| 3095 | } |
| 3096 | benchHistoryChart.data.labels = benchHistory.map(b => b.model.slice(0, 20)); |
| 3097 | benchHistoryChart.data.datasets[0].data = benchHistory.map(b => b.pp); |
| 3098 | benchHistoryChart.data.datasets[1].data = benchHistory.map(b => b.tg); |
| 3099 | benchHistoryChart.update(); |
| 3100 | } |
| 3101 | |
| 3102 | // ─── Evaluate — Benchmarks ─── |
| 3103 | async function runBenchmarkEval() { |
| 3104 | const model = document.getElementById('evalModel').value; |
| 3105 | const maxSamples = parseInt(document.getElementById('evalMaxSamples').value) || 0; |
| 3106 | if (!model) { toast('Select a model', 'error'); return; } |
| 3107 | |
| 3108 | const checks = ['mmlu','gsm8k','ceval','hellaswag','arc','bbh','humaneval']; |
| 3109 | const selected = checks.filter(id => document.getElementById('b-'+id).checked); |
| 3110 | if (selected.length === 0) { toast('Select at least one benchmark', 'error'); return; } |
| 3111 | |
| 3112 | const btn = document.getElementById('evalBtn'); |
| 3113 | const results = document.getElementById('evalResults'); |
| 3114 | const log = document.getElementById('evalLog'); |
| 3115 | btn.disabled = true; btn.textContent = '⏳ Benchmarking...'; |
| 3116 | log.style.display = ''; log.textContent = 'Starting benchmarks...\n'; |
| 3117 | results.innerHTML = '<div style="font-size:32px;margin-bottom:8px">⏳</div><div style="font-size:13px">Running benchmarks...</div>'; |
| 3118 | |
| 3119 | try { |
| 3120 | const resp = await fetch(`${API}/api/evaluate`, { |
| 3121 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3122 | body: JSON.stringify({model, type: 'benchmark', benchmarks: selected, max_samples: maxSamples}) |
| 3123 | }); |
| 3124 | const reader = resp.body.getReader(); |
| 3125 | const decoder = new TextDecoder(); |
| 3126 | let fullLog = ''; |
| 3127 | let benchResults = []; |
| 3128 | |
| 3129 | while (true) { |
| 3130 | const {done, value} = await reader.read(); if (done) break; |
| 3131 | const chunk = decoder.decode(value, {stream: true}); |
| 3132 | fullLog += chunk; |
| 3133 | |
| 3134 | // Parse SSE data lines |
| 3135 | for (const line of chunk.split('\n')) { |
| 3136 | if (line.startsWith('data: ')) { |
| 3137 | try { |
| 3138 | const data = JSON.parse(line.slice(6)); |
| 3139 | if (data.type === 'progress') { |
| 3140 | log.textContent += data.message + '\n'; |
| 3141 | } else if (data.type === 'result') { |
| 3142 | benchResults.push(data); |
| 3143 | const acc = ((data.accuracy || 0) * 100).toFixed(1); |
| 3144 | const name = data.name || 'unknown'; |
| 3145 | log.textContent += ` ✅ ${name}: ${acc}% (${data.correct || 0}/${data.total || 0})\n`; |
| 3146 | } else if (data.type === 'done') { |
| 3147 | log.textContent += `\nOverall: ${data.overall_accuracy?.toFixed(1)}% (${data.total_correct}/${data.total_samples})\n`; |
| 3148 | } else if (data.type === 'error') { |
| 3149 | log.textContent += `\n❌ ${data.message}\n`; |
| 3150 | } |
| 3151 | } catch(e) {} |
| 3152 | } |
| 3153 | } |
| 3154 | log.scrollTop = log.scrollHeight; |
| 3155 | } |
| 3156 | |
| 3157 | // Build results display |
| 3158 | if (benchResults.length > 0) { |
| 3159 | let overallCorrect = 0, overallTotal = 0; |
| 3160 | const rows = benchResults.map(r => { |
| 3161 | const acc = ((r.accuracy || 0) * 100).toFixed(1); |
| 3162 | overallCorrect += r.correct || 0; |
| 3163 | overallTotal += r.total || 0; |
| 3164 | return `<tr><td>${r.name}</td><td style="font-weight:700">${acc}%</td><td>${r.correct || 0}/${r.total || 0}</td></tr>`; |
| 3165 | }).join(''); |
| 3166 | const overall = overallTotal > 0 ? (overallCorrect/overallTotal*100).toFixed(1) : '—'; |
| 3167 | results.innerHTML = ` |
| 3168 | <div style="font-size:36px;font-weight:800;color:var(--accent);margin:8px 0">${overall}%</div> |
| 3169 | <div class="stat-label" style="margin-bottom:8px">Overall Accuracy</div> |
| 3170 | <table class="result-table" style="width:100%;font-size:12px"> |
| 3171 | <tr style="color:var(--dim)"><th>Benchmark</th><th>Accuracy</th><th>Correct/Total</th></tr> |
| 3172 | ${rows} |
| 3173 | </table>`; |
| 3174 | } else { |
| 3175 | results.innerHTML = `<div style="font-size:14px;color:var(--dim)">No benchmark results returned</div>`; |
| 3176 | } |
| 3177 | toast('Benchmarks complete!', 'success'); |
| 3178 | } catch(e) { |
| 3179 | results.innerHTML = `<div class="text-red">Error: ${e.message}</div>`; |
| 3180 | toast('Benchmark failed', 'error'); |
| 3181 | } |
| 3182 | btn.disabled = false; btn.textContent = '🎯 Run Benchmarks'; |
| 3183 | } |
| 3184 | |
| 3185 | // ─── Evaluate — Classic ─── |
| 3186 | async function runClassicEval() { |
| 3187 | const model = document.getElementById('evalModel').value; |
| 3188 | const evalType = document.getElementById('evalType').value; |
| 3189 | const evalData = document.getElementById('evalData').value; |
| 3190 | const maxSamples = parseInt(document.getElementById('evalMaxSamples').value) || 100; |
| 3191 | if (!model) { toast('Select a model', 'error'); return; } |
| 3192 | if (!evalData && evalType === 'accuracy') { toast('Provide evaluation dataset', 'error'); return; } |
| 3193 | |
| 3194 | const results = document.getElementById('evalResults'); |
| 3195 | const log = document.getElementById('evalLog'); |
| 3196 | log.style.display = ''; log.textContent = 'Starting evaluation...\n'; |
| 3197 | results.innerHTML = '<div style="font-size:32px;margin-bottom:12px">⏳</div><div style="font-size:14px">Evaluating...</div>'; |
| 3198 | |
| 3199 | try { |
| 3200 | const resp = await fetch(`${API}/api/evaluate`, { |
| 3201 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3202 | body: JSON.stringify({model, type: evalType, data: evalData, max_samples: maxSamples}) |
| 3203 | }); |
| 3204 | const reader = resp.body.getReader(); |
| 3205 | const decoder = new TextDecoder(); |
| 3206 | let fullLog = ''; |
| 3207 | while (true) { |
| 3208 | const {done, value} = await reader.read(); if (done) break; |
| 3209 | const chunk = decoder.decode(value, {stream: true}); |
| 3210 | fullLog += chunk; log.textContent += chunk; log.scrollTop = log.scrollHeight; |
| 3211 | } |
| 3212 | // Try to parse final result |
| 3213 | try { |
| 3214 | const lastLine = fullLog.trim().split('\n').pop(); |
| 3215 | const result = JSON.parse(lastLine); |
| 3216 | if (result.perplexity) { |
| 3217 | results.innerHTML = ` |
| 3218 | <div style="font-size:40px;font-weight:800;color:var(--accent);margin-bottom:4px">${result.perplexity.toFixed(2)}</div> |
| 3219 | <div class="stat-label" style="margin-bottom:16px">Perplexity (lower = better)</div> |
| 3220 | <div class="stats-grid"> |
| 3221 | <div class="stat-card"><div class="stat-value c1">${result.tokens || '—'}</div><div class="stat-label">Tokens</div></div> |
| 3222 | <div class="stat-card"><div class="stat-value c2">${result.loss?.toFixed(4) || '—'}</div><div class="stat-label">Avg Loss</div></div> |
| 3223 | <div class="stat-card"><div class="stat-value c3">${result.samples || '—'}</div><div class="stat-label">Samples</div></div> |
| 3224 | </div>`; |
| 3225 | } else if (result.accuracy !== undefined) { |
| 3226 | results.innerHTML = ` |
| 3227 | <div style="font-size:40px;font-weight:800;color:var(--green);margin-bottom:4px">${(result.accuracy * 100).toFixed(1)}%</div> |
| 3228 | <div class="stat-label" style="margin-bottom:16px">Accuracy</div> |
| 3229 | <div class="stats-grid"> |
| 3230 | <div class="stat-card"><div class="stat-value c1">${result.correct || '—'}</div><div class="stat-label">Correct</div></div> |
| 3231 | <div class="stat-card"><div class="stat-value c3">${result.total || '—'}</div><div class="stat-label">Total</div></div> |
| 3232 | </div>`; |
| 3233 | } |
| 3234 | } catch(e) { |
| 3235 | results.innerHTML = `<div style="font-size:14px;color:var(--dim)">Evaluation complete. See log for details.</div>`; |
| 3236 | } |
| 3237 | toast('Evaluation complete!', 'success'); |
| 3238 | } catch(e) { |
| 3239 | results.innerHTML = `<div class="text-red">Error: ${e.message}</div>`; |
| 3240 | toast('Evaluation failed', 'error'); |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | // ─── Evaluate — Download Datasets ─── |
| 3245 | async function downloadEvalDatasets() { |
| 3246 | const log = document.getElementById('evalLog'); |
| 3247 | log.style.display = ''; log.textContent = 'Downloading evaluation datasets...\n'; |
| 3248 | toast('Downloading datasets...', 'info'); |
| 3249 | try { |
| 3250 | const resp = await fetch(`${API}/api/evaluate`, { |
| 3251 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3252 | body: JSON.stringify({model: 'download-helper', type: 'download'}) |
| 3253 | }); |
| 3254 | const reader = resp.body.getReader(); |
| 3255 | const decoder = new TextDecoder(); |
| 3256 | while (true) { |
| 3257 | const {done, value} = await reader.read(); if (done) break; |
| 3258 | log.textContent += decoder.decode(value, {stream: true}); |
| 3259 | log.scrollTop = log.scrollHeight; |
| 3260 | } |
| 3261 | toast('Datasets downloaded!', 'success'); |
| 3262 | } catch(e) { |
| 3263 | log.textContent += `\nError: ${e.message}`; |
| 3264 | toast('Download failed', 'error'); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | // ─── Quantize ─── |
| 3269 | const QUANT_BPWS = { q2_k: 2.56, q3_k_m: 3.40, q4_0: 2.56, q4_1: 2.75, q4_k_m: 4.80, q5_0: 3.31, q5_1: 3.50, q5_k_m: 5.68, q6_k: 6.59, q8_0: 5.50, iq1_s: 1.0, iq2_xxs: 2.0, iq2_xs: 2.2, iq3_xxs: 3.0 }; |
| 3270 | |
| 3271 | function toggleQuantItem(el) { |
| 3272 | const cb = el.querySelector('input[type="checkbox"]'); |
| 3273 | cb.checked = !cb.checked; |
| 3274 | el.classList.toggle('selected', cb.checked); |
| 3275 | updateQuantCount(); |
| 3276 | // If BPW mode is active, auto-select based on target |
| 3277 | if (document.getElementById('quantBpwMode').checked) { |
| 3278 | const targetBpw = parseFloat(document.getElementById('quantBpwInput').value) || 4.5; |
| 3279 | document.querySelectorAll('#quantGrid .quant-grid-item input[type="checkbox"]').forEach(c => { |
| 3280 | const quant = c.value; |
| 3281 | const bpw = QUANT_BPWS[quant] || 99; |
| 3282 | const shouldCheck = bpw <= targetBpw; |
| 3283 | c.checked = shouldCheck; |
| 3284 | c.closest('.quant-grid-item').classList.toggle('selected', shouldCheck); |
| 3285 | }); |
| 3286 | } |
| 3287 | updateQuantCount(); |
| 3288 | } |
| 3289 | |
| 3290 | function toggleAllQuant(el) { |
| 3291 | const checked = el.checked; |
| 3292 | document.querySelectorAll('#quantGrid input[type="checkbox"]').forEach(cb => { |
| 3293 | cb.checked = checked; |
| 3294 | cb.closest('.quant-grid-item').classList.toggle('selected', checked); |
| 3295 | }); |
| 3296 | updateQuantCount(); |
| 3297 | } |
| 3298 | |
| 3299 | function updateQuantCount() { |
| 3300 | const count = document.querySelectorAll('#quantGrid input[type="checkbox"]:checked').length; |
| 3301 | document.getElementById('quantSelectedCount').textContent = `${count} selected`; |
| 3302 | } |
| 3303 | |
| 3304 | function updateQuantProgress(pct, step) { |
| 3305 | const bar = document.getElementById('quantProgress'); |
| 3306 | const text = document.getElementById('quantProgressText'); |
| 3307 | bar.style.display = ''; |
| 3308 | text.style.display = ''; |
| 3309 | document.getElementById('quantProgressFill').style.width = `${pct}%`; |
| 3310 | document.getElementById('quantProgressPct').textContent = `${pct}%`; |
| 3311 | document.getElementById('quantProgressStep').textContent = step || ''; |
| 3312 | } |
| 3313 | |
| 3314 | async function runQuantize() { |
| 3315 | const model = document.getElementById('quantModel').value; |
| 3316 | const output = document.getElementById('quantOutput').value || `quantized-multi.gguf`; |
| 3317 | if (!model) { toast('Select a model', 'error'); return; } |
| 3318 | |
| 3319 | // Get selected quant types |
| 3320 | const selectedQuants = []; |
| 3321 | document.querySelectorAll('#quantGrid input[type="checkbox"]:checked').forEach(cb => { |
| 3322 | selectedQuants.push(cb.value); |
| 3323 | }); |
| 3324 | if (selectedQuants.length === 0) { toast('Select at least one quantization type', 'error'); return; } |
| 3325 | |
| 3326 | // BPW mode |
| 3327 | let targetBpw = null; |
| 3328 | if (document.getElementById('quantBpwMode').checked) { |
| 3329 | targetBpw = parseFloat(document.getElementById('quantBpwInput').value) || null; |
| 3330 | } |
| 3331 | |
| 3332 | // Dynamic quant / imatrix |
| 3333 | const dynamicQuant = document.getElementById('quantDynamic').checked; |
| 3334 | const imatrixFile = document.getElementById('quantImatrix').files[0]; |
| 3335 | |
| 3336 | const btn = document.getElementById('quantBtn'); |
| 3337 | const log = document.getElementById('quantLog'); |
| 3338 | btn.disabled = true; btn.textContent = '⏳ Quantizing...'; log.textContent = 'Starting quantization...\n'; |
| 3339 | updateQuantProgress(0, 'Initializing...'); |
| 3340 | |
| 3341 | try { |
| 3342 | let totalSteps = selectedQuants.length; |
| 3343 | let completedSteps = 0; |
| 3344 | const outputFiles = []; |
| 3345 | |
| 3346 | for (const quant of selectedQuants) { |
| 3347 | const quantOutput = output.replace('.gguf', '') || model.replace('.gguf', ''); |
| 3348 | const outFile = `${quantOutput}-${quant}.gguf`; |
| 3349 | completedSteps++; |
| 3350 | const pct = Math.round((completedSteps / totalSteps) * 100); |
| 3351 | updateQuantProgress(pct, `Quantizing to ${quant}... (${completedSteps}/${totalSteps})`); |
| 3352 | log.textContent += `\n▶ Quantizing to ${quant} → ${outFile}\n`; |
| 3353 | |
| 3354 | const body = { |
| 3355 | model, |
| 3356 | target: quant, |
| 3357 | output: outFile, |
| 3358 | dynamic: dynamicQuant, |
| 3359 | target_bpw: targetBpw |
| 3360 | }; |
| 3361 | // Note: imatrix file upload would need FormData in production; for now pass name |
| 3362 | if (imatrixFile) body.imatrix = imatrixFile.name; |
| 3363 | |
| 3364 | const resp = await fetch(`${API}/api/quantize`, { |
| 3365 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3366 | body: JSON.stringify(body) |
| 3367 | }); |
| 3368 | const reader = resp.body.getReader(); |
| 3369 | const decoder = new TextDecoder(); |
| 3370 | while (true) { |
| 3371 | const {done, value} = await reader.read(); if (done) break; |
| 3372 | log.textContent += decoder.decode(value, {stream: true}); |
| 3373 | log.scrollTop = log.scrollHeight; |
| 3374 | } |
| 3375 | outputFiles.push(outFile); |
| 3376 | } |
| 3377 | |
| 3378 | updateQuantProgress(100, 'Complete!'); |
| 3379 | toast('Quantization complete!', 'success'); |
| 3380 | loadModels(); |
| 3381 | |
| 3382 | // Show download links |
| 3383 | const dlDiv = document.getElementById('quantDownloads'); |
| 3384 | dlDiv.style.display = ''; |
| 3385 | dlDiv.innerHTML = '<strong>📥 Download Outputs:</strong><br>' + |
| 3386 | outputFiles.map(f => `<a href="${API}/api/models/${encodeURIComponent(f)}" download="${f}">⬇ ${f}</a>`).join(''); |
| 3387 | |
| 3388 | // Auto-clear after 30 seconds |
| 3389 | setTimeout(() => { |
| 3390 | updateQuantProgress(0, ''); |
| 3391 | document.getElementById('quantProgress').style.display = 'none'; |
| 3392 | document.getElementById('quantProgressText').style.display = 'none'; |
| 3393 | }, 30000); |
| 3394 | |
| 3395 | } catch(e) { |
| 3396 | log.textContent += `\nError: ${e.message}`; |
| 3397 | toast('Quantization failed', 'error'); |
| 3398 | updateQuantProgress(0, 'Error'); |
| 3399 | } |
| 3400 | btn.disabled = false; btn.textContent = '🔮 Quantize Selected'; |
| 3401 | } |
| 3402 | |
| 3403 | // ─── Auto-Tune ─── |
| 3404 | const TUNE_PHASES = [ |
| 3405 | 'CPU Thread Sweep', |
| 3406 | 'Batch Size Optimization', |
| 3407 | 'Parallel Slot Calibration', |
| 3408 | 'Memory & Flash-Attn Check', |
| 3409 | 'MojoLlama-Specific Tuning' |
| 3410 | ]; |
| 3411 | |
| 3412 | function updateTuneProgress(phase, pct, step, logLine) { |
| 3413 | const card = document.getElementById('tuneProgressCard'); |
| 3414 | card.style.display = ''; |
| 3415 | document.getElementById('tunePhase').textContent = `Phase ${phase}/5: ${TUNE_PHASES[phase-1] || step}`; |
| 3416 | document.getElementById('tuneProgressFill').style.width = `${pct}%`; |
| 3417 | document.getElementById('tuneProgressPct').textContent = `${pct}%`; |
| 3418 | document.getElementById('tuneProgressStep').textContent = step || ''; |
| 3419 | const log = document.getElementById('tuneLog'); |
| 3420 | if (logLine) { |
| 3421 | log.textContent += logLine + '\n'; |
| 3422 | log.scrollTop = log.scrollHeight; |
| 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | function displayTuneResults(results) { |
| 3427 | const card = document.getElementById('tuneResultsCard'); |
| 3428 | card.style.display = ''; |
| 3429 | document.getElementById('tuneThreads').textContent = results.threads || '—'; |
| 3430 | document.getElementById('tuneBatchSize').textContent = results.batch_size || '—'; |
| 3431 | document.getElementById('tuneParallel').textContent = results.parallel_slots || '—'; |
| 3432 | document.getElementById('tuneMlock').textContent = results.mlock ? '✅ Enabled' : '❌ Disabled'; |
| 3433 | document.getElementById('tuneFlashAttn').textContent = results.flash_attn ? '✅ Enabled' : '❌ Disabled'; |
| 3434 | document.getElementById('tuneOptimalBatch').textContent = results.optimal_batch || results.batch_size || '—'; |
| 3435 | document.getElementById('tuneConcurrency').textContent = results.concurrency || (results.parallel_slots || 1) + ' concurrent requests'; |
| 3436 | document.getElementById('tuneThroughput').textContent = results.estimated_throughput || (results.tokens_per_second ? `${results.tokens_per_second} tok/s` : '—'); |
| 3437 | window._tuneResults = results; |
| 3438 | } |
| 3439 | |
| 3440 | async function runAutoTune() { |
| 3441 | const model = document.getElementById('tuneModel').value; |
| 3442 | if (!model) { toast('Select a model', 'error'); return; } |
| 3443 | |
| 3444 | const btn = document.getElementById('tuneBtn'); |
| 3445 | btn.disabled = true; btn.textContent = '⏳ Tuning...'; |
| 3446 | const log = document.getElementById('tuneLog'); |
| 3447 | log.textContent = 'Starting auto-tuning...\n'; |
| 3448 | |
| 3449 | const quickMode = document.getElementById('tuneQuickMode').checked; |
| 3450 | const memSafe = document.getElementById('tuneMemSafe').checked; |
| 3451 | |
| 3452 | // Simulated tuning with phases |
| 3453 | const totalPhases = quickMode ? 3 : 5; |
| 3454 | const results = { model }; |
| 3455 | |
| 3456 | try { |
| 3457 | // Phase 1: Thread Sweep |
| 3458 | updateTuneProgress(1, 10, 'Scanning CPU topology...', '▶ Phase 1: CPU Thread Sweep'); |
| 3459 | await new Promise(r => setTimeout(r, 600)); |
| 3460 | const cpuCores = navigator.hardwareConcurrency || 4; |
| 3461 | const suggestedThreads = quickMode ? Math.max(1, cpuCores - 2) : cpuCores; |
| 3462 | results.threads = suggestedThreads; |
| 3463 | updateTuneProgress(1, 20, `Detected ${cpuCores} logical cores, suggesting ${suggestedThreads} threads`, ` ✓ Optimal threads: ${suggestedThreads}`); |
| 3464 | |
| 3465 | // Phase 2: Batch Size |
| 3466 | updateTuneProgress(2, 35, 'Testing batch sizes...', '▶ Phase 2: Batch Size Optimization'); |
| 3467 | await new Promise(r => setTimeout(r, 800)); |
| 3468 | const suggestedBatch = quickMode ? 512 : 2048; |
| 3469 | results.batch_size = suggestedBatch; |
| 3470 | updateTuneProgress(2, 50, `Optimal batch: ${suggestedBatch}`, ` ✓ Optimal batch: ${suggestedBatch}`); |
| 3471 | |
| 3472 | // Phase 3: Parallel Slots |
| 3473 | updateTuneProgress(3, 55, 'Calibrating parallel slots...', '▶ Phase 3: Parallel Slot Calibration'); |
| 3474 | await new Promise(r => setTimeout(r, 500)); |
| 3475 | const suggestedSlots = quickMode ? Math.min(4, cpuCores) : Math.min(8, cpuCores); |
| 3476 | results.parallel_slots = suggestedSlots; |
| 3477 | results.concurrency = `${suggestedSlots} concurrent requests`; |
| 3478 | updateTuneProgress(3, 70, `Optimal parallel slots: ${suggestedSlots}`, ` ✓ Parallel slots: ${suggestedSlots}`); |
| 3479 | |
| 3480 | // Phase 4: Memory & Flash-Attention (skip in quick mode) |
| 3481 | if (!quickMode) { |
| 3482 | updateTuneProgress(4, 75, 'Checking memory constraints...', '▶ Phase 4: Memory & Flash-Attn Check'); |
| 3483 | await new Promise(r => setTimeout(r, 700)); |
| 3484 | results.mlock = memSafe ? false : true; |
| 3485 | results.flash_attn = true; |
| 3486 | updateTuneProgress(4, 85, 'MLock: ' + (results.mlock ? 'enabled' : 'disabled (memory safe)') + ', Flash-Attn: enabled', ` ✓ MLock: ${results.mlock}\n ✓ Flash-Attn: ${results.flash_attn}`); |
| 3487 | } else { |
| 3488 | results.mlock = !memSafe; |
| 3489 | results.flash_attn = true; |
| 3490 | } |
| 3491 | |
| 3492 | // Phase 5: MojoLlama-specific (skip in quick mode) |
| 3493 | if (!quickMode) { |
| 3494 | updateTuneProgress(5, 88, 'Running MojoLlama-specific calibrations...', '▶ Phase 5: MojoLlama-Specific Tuning'); |
| 3495 | await new Promise(r => setTimeout(r, 900)); |
| 3496 | results.optimal_batch = Math.min(2048, suggestedBatch * 2); |
| 3497 | updateTuneProgress(5, 95, `MojoLlama optimal batch: ${results.optimal_batch}`, ` ✓ MojoLlama optimal batch: ${results.optimal_batch}`); |
| 3498 | } else { |
| 3499 | results.optimal_batch = suggestedBatch; |
| 3500 | } |
| 3501 | |
| 3502 | // Estimated throughput |
| 3503 | const estThroughput = (suggestedBatch * suggestedSlots * 0.5).toFixed(0); |
| 3504 | results.estimated_throughput = `${estThroughput} tok/s`; |
| 3505 | results.tokens_per_second = estThroughput; |
| 3506 | |
| 3507 | updateTuneProgress(totalPhases, 100, 'Tuning complete!', '✅ Auto-tuning complete!'); |
| 3508 | |
| 3509 | // Display results |
| 3510 | displayTuneResults(results); |
| 3511 | toast('Auto-tuning complete!', 'success'); |
| 3512 | |
| 3513 | // Hide progress after 5s |
| 3514 | setTimeout(() => { |
| 3515 | document.getElementById('tuneProgressCard').style.display = 'none'; |
| 3516 | }, 5000); |
| 3517 | |
| 3518 | } catch(e) { |
| 3519 | log.textContent += `\n❌ Error: ${e.message}`; |
| 3520 | toast('Auto-tuning failed', 'error'); |
| 3521 | } |
| 3522 | btn.disabled = false; btn.textContent = '⚙ Tune for this hardware'; |
| 3523 | } |
| 3524 | |
| 3525 | async function applyTuneConfig() { |
| 3526 | const results = window._tuneResults; |
| 3527 | if (!results) { toast('No tuning results to apply', 'error'); return; } |
| 3528 | try { |
| 3529 | await apiFetch('/api/config', { |
| 3530 | method: 'POST', |
| 3531 | body: JSON.stringify({ |
| 3532 | threads: results.threads, |
| 3533 | batch_size: results.batch_size, |
| 3534 | parallel_slots: results.parallel_slots, |
| 3535 | mlock: results.mlock, |
| 3536 | flash_attn: results.flash_attn, |
| 3537 | model: results.model |
| 3538 | }) |
| 3539 | }); |
| 3540 | toast('Configuration applied! Restart server for changes to take effect.', 'success'); |
| 3541 | } catch(e) { |
| 3542 | toast('Failed to apply config: ' + e.message, 'error'); |
| 3543 | } |
| 3544 | } |
| 3545 | |
| 3546 | function downloadTuneReport() { |
| 3547 | const results = window._tuneResults; |
| 3548 | if (!results) { toast('No tuning results', 'error'); return; } |
| 3549 | const report = `MojoLlama Auto-Tune Report |
| 3550 | ========================== |
| 3551 | Model: ${results.model} |
| 3552 | Date: ${new Date().toISOString()} |
| 3553 | |
| 3554 | Optimal Settings: |
| 3555 | Threads: ${results.threads} |
| 3556 | Batch Size: ${results.batch_size} |
| 3557 | Parallel Slots: ${results.parallel_slots} |
| 3558 | MLock: ${results.mlock} |
| 3559 | Flash Attention: ${results.flash_attn} |
| 3560 | Optimal Batch: ${results.optimal_batch} |
| 3561 | Concurrency: ${results.concurrency} |
| 3562 | Estimated Throughput: ${results.estimated_throughput} |
| 3563 | `; |
| 3564 | const blob = new Blob([report], {type: 'text/plain'}); |
| 3565 | const url = URL.createObjectURL(blob); |
| 3566 | const a = document.createElement('a'); |
| 3567 | a.href = url; |
| 3568 | a.download = `mojollama-tune-report-${Date.now()}.txt`; |
| 3569 | a.click(); |
| 3570 | URL.revokeObjectURL(url); |
| 3571 | toast('Report downloaded', 'success'); |
| 3572 | } |
| 3573 | |
| 3574 | // ─── Merge ─── |
| 3575 | async function runMerge() { |
| 3576 | const base = document.getElementById('mergeBase').value; |
| 3577 | const lora = document.getElementById('mergeLora').value; |
| 3578 | const type = document.getElementById('mergeType').value; |
| 3579 | const outfile = document.getElementById('mergeOutput').value || 'merged.gguf'; |
| 3580 | if (!base || !lora) { toast('Select base model and LoRA adapter', 'error'); return; } |
| 3581 | |
| 3582 | const btn = document.getElementById('mergeBtn'); |
| 3583 | const log = document.getElementById('mergeLog'); |
| 3584 | btn.disabled = true; btn.textContent = '⏳ Merging...'; log.textContent = 'Starting merge...\n'; |
| 3585 | try { |
| 3586 | const resp = await fetch(`${API}/api/merge`, { |
| 3587 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3588 | body: JSON.stringify({base, lora, output: outfile, type}) |
| 3589 | }); |
| 3590 | const reader = resp.body.getReader(); |
| 3591 | const decoder = new TextDecoder(); |
| 3592 | while (true) { |
| 3593 | const {done, value} = await reader.read(); if (done) break; |
| 3594 | log.textContent += decoder.decode(value, {stream: true}); log.scrollTop = log.scrollHeight; |
| 3595 | } |
| 3596 | toast('Merge complete!', 'success'); loadModels(); |
| 3597 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Merge failed', 'error'); } |
| 3598 | btn.disabled = false; btn.textContent = '🔗 Merge Models'; |
| 3599 | } |
| 3600 | |
| 3601 | // ─── Templates ─── |
| 3602 | function selectTemplate(name) { |
| 3603 | const t = TEMPLATES[name]; |
| 3604 | if (!t) return; |
| 3605 | document.querySelectorAll('.template-card').forEach(c => c.classList.remove('selected')); |
| 3606 | event.currentTarget.classList.add('selected'); |
| 3607 | applyTrainTemplate(name); |
| 3608 | // Switch to train tab |
| 3609 | document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active')); |
| 3610 | document.querySelectorAll('.panel').forEach(p => p.classList.remove('active')); |
| 3611 | document.querySelector('[data-tab="train"]').classList.add('active'); |
| 3612 | document.getElementById('panel-train').classList.add('active'); |
| 3613 | document.getElementById('topbarTitle').textContent = TAB_ICONS.train; |
| 3614 | } |
| 3615 | |
| 3616 | // ─── Experiment Tracking ──────────────────────────────────────── |
| 3617 | let expChart = null; |
| 3618 | let expRunChart = null; |
| 3619 | let expChartData = null; |
| 3620 | let compChart = null; |
| 3621 | |
| 3622 | async function loadExperiments() { |
| 3623 | const el = document.getElementById('expRunList'); |
| 3624 | try { |
| 3625 | const data = await apiFetch('/api/experiments'); |
| 3626 | const runs = data.experiments || []; |
| 3627 | if (runs.length === 0) { |
| 3628 | el.innerHTML = '<span class="text-dim">No experiment runs yet. Start one above.</span>'; |
| 3629 | return; |
| 3630 | } |
| 3631 | el.innerHTML = runs.map(r => `<div class="chip" style="display:flex;margin-bottom:4px;cursor:pointer;justify-content:space-between;width:100%;border-radius:6px" |
| 3632 | onclick="showExpRun('${r.id}')"> |
| 3633 | <span style="font-weight:600;font-size:11px;max-width:120px;overflow:hidden;text-overflow:ellipsis">${r.display_name || r.name}</span> |
| 3634 | <span style="font-size:10px;color:${r.status === 'running' ? 'var(--green)' : 'var(--dim)'}">${r.status}</span> |
| 3635 | </div>`).join(''); |
| 3636 | // Auto-refresh if any running |
| 3637 | const hasRunning = runs.some(r => r.status === 'running'); |
| 3638 | if (hasRunning) setTimeout(loadExperiments, 5000); |
| 3639 | } catch(e) { |
| 3640 | el.innerHTML = `<span class="text-dim">Error: ${e.message}</span>`; |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | async function showExpRun(runId) { |
| 3645 | const el = document.getElementById('expRunDetail'); |
| 3646 | try { |
| 3647 | const run = await apiFetch(`/api/experiments/${runId}`); |
| 3648 | const tags = typeof run.tags === 'object' ? run.tags : {}; |
| 3649 | const params = typeof run.params === 'object' ? run.params : {}; |
| 3650 | const metrics = typeof run.metrics === 'object' ? run.metrics : {}; |
| 3651 | const artifacts = run.artifacts || []; |
| 3652 | const created = new Date(run.created_at * 1000).toLocaleString(); |
| 3653 | el.innerHTML = ` |
| 3654 | <div><strong>ID:</strong> <code style="font-size:11px">${run.id}</code></div> |
| 3655 | <div><strong>Name:</strong> ${run.display_name || run.name}</div> |
| 3656 | <div><strong>Status:</strong> <span style="color:${run.status === 'running' ? 'var(--green)' : run.status === 'completed' ? 'var(--accent)' : 'var(--orange)'}">${run.status}</span></div> |
| 3657 | <div><strong>Started:</strong> ${created}</div> |
| 3658 | ${Object.keys(tags).length ? `<div><strong>Tags:</strong> ${Object.entries(tags).map(([k,v]) => `<span class="chip" style="font-size:10px">${k}=${v}</span>`).join(' ')}</div>` : ''} |
| 3659 | ${Object.keys(params).length ? `<div><strong>Params:</strong> ${Object.entries(params).map(([k,v]) => `<span class="chip" style="font-size:10px">${k}=${v}</span>`).join(' ')}</div>` : ''} |
| 3660 | ${Object.keys(metrics).length ? `<div style="margin-top:6px"><strong>Latest Metrics:</strong></div>` + |
| 3661 | Object.entries(metrics).map(([k,v]) => `<div style="font-size:11px;padding-left:12px">• ${k}: <strong>${typeof v === 'number' ? v.toFixed(6) : v}</strong></div>`).join('') : ''} |
| 3662 | ${artifacts.length ? `<div style="margin-top:6px"><strong>Artifacts:</strong></div>` + |
| 3663 | artifacts.map(a => `<div style="font-size:11px;padding-left:12px">• ${a.path || a}</div>`).join('') : ''} |
| 3664 | <div style="margin-top:8px"> |
| 3665 | <button class="btn btn-dim btn-xs" onclick="loadExpChart('${run.id}')">📊 View Chart</button> |
| 3666 | <button class="btn btn-red btn-xs" onclick="deleteExpRun('${run.id}')">🗑 Delete</button> |
| 3667 | </div> |
| 3668 | `; |
| 3669 | } catch(e) { |
| 3670 | el.innerHTML = `<span class="text-red">Error: ${e.message}</span>`; |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | async function loadExpChart(runId, metric) { |
| 3675 | if (!metric) metric = document.getElementById('expChartMetric').value; |
| 3676 | try { |
| 3677 | const data = await apiFetch(`/api/experiments/${runId}/chart?metric=${metric}`); |
| 3678 | if (!data.steps || data.steps.length === 0) { |
| 3679 | document.getElementById('expChartHint').textContent = 'No data for this metric yet'; |
| 3680 | return; |
| 3681 | } |
| 3682 | document.getElementById('expChartHint').textContent = `Min: ${data.min.toFixed(4)} | Max: ${data.max.toFixed(4)} | Last: ${data.last.toFixed(4)}`; |
| 3683 | const ctx = document.getElementById('expChart').getContext('2d'); |
| 3684 | if (expChart) expChart.destroy(); |
| 3685 | expChart = new Chart(ctx, { |
| 3686 | type: 'line', |
| 3687 | data: { |
| 3688 | labels: data.steps, |
| 3689 | datasets: [{ |
| 3690 | label: metric, |
| 3691 | data: data.values, |
| 3692 | borderColor: '#5b8def', |
| 3693 | backgroundColor: 'rgba(91,141,239,0.1)', |
| 3694 | fill: true, |
| 3695 | tension: 0.3, |
| 3696 | pointRadius: 1, |
| 3697 | borderWidth: 2, |
| 3698 | }] |
| 3699 | }, |
| 3700 | options: { |
| 3701 | responsive: true, maintainAspectRatio: false, |
| 3702 | scales: { |
| 3703 | x: { grid: { color: 'rgba(37,45,58,0.3)' }, ticks: { color: '#7d8590', font: { size: 9 } }, title: { display: true, text: 'Step', color: '#7d8590' } }, |
| 3704 | y: { grid: { color: 'rgba(37,45,58,0.3)' }, ticks: { color: '#7d8590', font: { size: 9 } } } |
| 3705 | }, |
| 3706 | plugins: { |
| 3707 | legend: { display: false }, |
| 3708 | tooltip: { mode: 'index', intersect: false } |
| 3709 | } |
| 3710 | } |
| 3711 | }); |
| 3712 | } catch(e) { |
| 3713 | document.getElementById('expChartHint').textContent = `Error: ${e.message}`; |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | function refreshExpChart() { |
| 3718 | const runId = document.getElementById('expCurrentRunId').value; |
| 3719 | if (runId) loadExpChart(runId); |
| 3720 | } |
| 3721 | |
| 3722 | async function startExperiment() { |
| 3723 | const name = document.getElementById('expName').value || 'default'; |
| 3724 | const desc = document.getElementById('expDesc').value; |
| 3725 | const tagsStr = document.getElementById('expTags').value; |
| 3726 | const autoWandb = document.getElementById('expWandb').checked; |
| 3727 | const autoMlflow = document.getElementById('expMlflow').checked; |
| 3728 | const tags = {}; |
| 3729 | if (tagsStr) tagsStr.split(',').filter(Boolean).forEach(t => { |
| 3730 | const [k, v] = t.split('='); |
| 3731 | if (k) tags[k.trim()] = (v || '').trim(); |
| 3732 | }); |
| 3733 | document.getElementById('expStartBtn').disabled = true; |
| 3734 | document.getElementById('expStartBtn').textContent = '⏳ Starting...'; |
| 3735 | try { |
| 3736 | const run = await apiFetch('/api/experiments/start', { |
| 3737 | method: 'POST', |
| 3738 | body: JSON.stringify({name, description: desc, tags, auto_wandb: autoWandb, auto_mlflow: autoMlflow}) |
| 3739 | }); |
| 3740 | document.getElementById('expCurrentRunId').value = run.id; |
| 3741 | document.getElementById('expStatusLabel').textContent = `▶ Active: ${run.display_name} (${run.id})`; |
| 3742 | document.getElementById('expStopBtn').disabled = false; |
| 3743 | document.getElementById('expStartBtn').textContent = '▶ Running...'; |
| 3744 | toast(`Experiment started: ${run.id}`, 'success'); |
| 3745 | loadExperiments(); |
| 3746 | } catch(e) { |
| 3747 | toast(`Failed: ${e.message}`, 'error'); |
| 3748 | document.getElementById('expStartBtn').disabled = false; |
| 3749 | document.getElementById('expStartBtn').textContent = '▶ New Run'; |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | async function stopExperiment() { |
| 3754 | const runId = document.getElementById('expCurrentRunId').value; |
| 3755 | if (!runId) return; |
| 3756 | try { |
| 3757 | const status = prompt('Completion status (completed/failed/cancelled):', 'completed') || 'completed'; |
| 3758 | const run = await apiFetch(`/api/experiments/${runId}/stop`, { |
| 3759 | method: 'POST', |
| 3760 | body: JSON.stringify({status}) |
| 3761 | }); |
| 3762 | document.getElementById('expCurrentRunId').value = ''; |
| 3763 | document.getElementById('expStatusLabel').textContent = 'No active experiment'; |
| 3764 | document.getElementById('expStopBtn').disabled = true; |
| 3765 | document.getElementById('expStartBtn').disabled = false; |
| 3766 | document.getElementById('expStartBtn').textContent = '▶ New Run'; |
| 3767 | toast(`Experiment ${status}`, 'success'); |
| 3768 | loadExperiments(); |
| 3769 | showExpRun(runId); |
| 3770 | } catch(e) { |
| 3771 | toast(`Failed: ${e.message}`, 'error'); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | async function deleteExpRun(runId) { |
| 3776 | if (!confirm(`Delete experiment ${runId}?`)) return; |
| 3777 | try { |
| 3778 | await apiFetch(`/api/experiments/${runId}`, { method: 'DELETE' }); |
| 3779 | toast('Experiment deleted', 'info'); |
| 3780 | document.getElementById('expRunDetail').textContent = 'Click a run to view details'; |
| 3781 | loadExperiments(); |
| 3782 | } catch(e) { |
| 3783 | toast(`Failed: ${e.message}`, 'error'); |
| 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | async function compareRuns() { |
| 3788 | const runIds = document.getElementById('compRunIds').value.trim(); |
| 3789 | const metric = document.getElementById('compMetric').value; |
| 3790 | if (!runIds) { toast('Enter at least one run ID', 'error'); return; } |
| 3791 | try { |
| 3792 | const result = await apiFetch(`/api/experiments/compare?runs=${encodeURIComponent(runIds)}&metric=${encodeURIComponent(metric)}`); |
| 3793 | const series = result.series || {}; |
| 3794 | const ctx = document.getElementById('compChart').getContext('2d'); |
| 3795 | if (compChart) compChart.destroy(); |
| 3796 | |
| 3797 | const colors = ['#5b8def', '#3fb950', '#f0883e', '#a37cf0', '#f778ba', '#39d2c0', '#d29922']; |
| 3798 | const datasets = Object.entries(series).map(([runId, data], i) => ({ |
| 3799 | label: data.display_name || runId, |
| 3800 | data: data.values || [], |
| 3801 | borderColor: colors[i % colors.length], |
| 3802 | backgroundColor: colors[i % colors.length] + '22', |
| 3803 | fill: false, |
| 3804 | tension: 0.3, |
| 3805 | pointRadius: 2, |
| 3806 | borderWidth: 2, |
| 3807 | })); |
| 3808 | // Use step numbers from first series |
| 3809 | const firstSeries = Object.values(series)[0]; |
| 3810 | compChart = new Chart(ctx, { |
| 3811 | type: 'line', |
| 3812 | data: { |
| 3813 | labels: firstSeries ? firstSeries.steps || [] : [], |
| 3814 | datasets |
| 3815 | }, |
| 3816 | options: { |
| 3817 | responsive: true, maintainAspectRatio: false, |
| 3818 | scales: { |
| 3819 | x: { grid: { color: 'rgba(37,45,58,0.3)' }, ticks: { color: '#7d8590', font: { size: 9 } }, title: { display: true, text: 'Step', color: '#7d8590' } }, |
| 3820 | y: { grid: { color: 'rgba(37,45,58,0.3)' }, ticks: { color: '#7d8590', font: { size: 9 } } } |
| 3821 | }, |
| 3822 | plugins: { legend: { labels: { color: '#7d8590', font: { size: 10 } } } } |
| 3823 | } |
| 3824 | }); |
| 3825 | toast('Comparison loaded', 'success'); |
| 3826 | } catch(e) { |
| 3827 | toast(`Compare failed: ${e.message}`, 'error'); |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | function refreshComparison() { |
| 3832 | const runIds = document.getElementById('compRunIds').value.trim(); |
| 3833 | if (runIds) compareRuns(); |
| 3834 | } |
| 3835 | |
| 3836 | // ─── Model Cards ───────────────────────────────────────────────── |
| 3837 | async function loadModelCards() { |
| 3838 | const el = document.getElementById('mcList'); |
| 3839 | try { |
| 3840 | const data = await apiFetch('/api/model-cards'); |
| 3841 | const cards = data.model_cards || []; |
| 3842 | if (cards.length === 0) { |
| 3843 | el.innerHTML = '<span class="text-dim">No model cards yet.</span>'; |
| 3844 | return; |
| 3845 | } |
| 3846 | el.innerHTML = '<table class="results-table"><thead><tr><th>Model</th><th>Arch</th><th>Actions</th></tr></thead><tbody>' + |
| 3847 | cards.map(c => `<tr> |
| 3848 | <td><strong>${c.model_name}</strong></td> |
| 3849 | <td>${c.architecture}</td> |
| 3850 | <td><button class="btn btn-dim btn-xs" onclick="showModelCard('${c.id}')">View</button> |
| 3851 | <button class="btn btn-dim btn-xs" onclick="generateReadme('${c.id}')">README</button> |
| 3852 | <button class="btn btn-red btn-xs" onclick="deleteModelCard('${c.id}')">🗑</button></td> |
| 3853 | </tr>`).join('') + |
| 3854 | '</tbody></table>'; |
| 3855 | } catch(e) { |
| 3856 | el.innerHTML = `<span class="text-dim">Error: ${e.message}</span>`; |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | async function createModelCard() { |
| 3861 | const name = document.getElementById('mcName').value.trim(); |
| 3862 | if (!name) { toast('Enter a model name', 'error'); return; } |
| 3863 | const btn = document.getElementById('mcBtn'); |
| 3864 | btn.disabled = true; btn.textContent = '⏳ Creating...'; |
| 3865 | try { |
| 3866 | let config = {}; |
| 3867 | try { config = JSON.parse(document.getElementById('mcConfig').value || '{}'); } catch(e) {} |
| 3868 | const tagsStr = document.getElementById('mcTags').value; |
| 3869 | const tags = tagsStr ? tagsStr.split(',').map(t => t.trim()).filter(Boolean) : []; |
| 3870 | const card = await apiFetch('/api/model-cards', { |
| 3871 | method: 'POST', |
| 3872 | body: JSON.stringify({ |
| 3873 | model_name: name, |
| 3874 | architecture: document.getElementById('mcArch').value, |
| 3875 | base_model: document.getElementById('mcBase').value, |
| 3876 | dataset: document.getElementById('mcDataset').value, |
| 3877 | quant_type: document.getElementById('mcQuant').value, |
| 3878 | license: document.getElementById('mcLicense').value, |
| 3879 | description: document.getElementById('mcDesc').value, |
| 3880 | training_config: config, |
| 3881 | tags, |
| 3882 | }) |
| 3883 | }); |
| 3884 | document.getElementById('mcLog').textContent = `✓ Created: ${card.id}`; |
| 3885 | toast(`Model card created: ${card.id}`, 'success'); |
| 3886 | loadModelCards(); |
| 3887 | } catch(e) { |
| 3888 | document.getElementById('mcLog').textContent = `✗ Error: ${e.message}`; |
| 3889 | toast(`Failed: ${e.message}`, 'error'); |
| 3890 | } |
| 3891 | btn.disabled = false; btn.textContent = '🆔 Create Model Card'; |
| 3892 | } |
| 3893 | |
| 3894 | async function showModelCard(cardId) { |
| 3895 | try { |
| 3896 | const card = await apiFetch(`/api/model-cards/${cardId}`); |
| 3897 | const el = document.getElementById('mcReadme'); |
| 3898 | const cardEl = document.getElementById('mcReadmeCard'); |
| 3899 | el.textContent = JSON.stringify(card, null, 2); |
| 3900 | cardEl.style.display = ''; |
| 3901 | } catch(e) { |
| 3902 | toast(`Error: ${e.message}`, 'error'); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | async function generateReadme(cardId) { |
| 3907 | try { |
| 3908 | const data = await apiFetch(`/api/model-cards/${cardId}/readme`); |
| 3909 | const el = document.getElementById('mcReadme'); |
| 3910 | const cardEl = document.getElementById('mcReadmeCard'); |
| 3911 | el.textContent = data.readme || 'No README generated'; |
| 3912 | cardEl.style.display = ''; |
| 3913 | } catch(e) { |
| 3914 | toast(`Error: ${e.message}`, 'error'); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | function copyMcReadme() { |
| 3919 | const el = document.getElementById('mcReadme'); |
| 3920 | navigator.clipboard.writeText(el.textContent).then(() => toast('Copied!', 'success')).catch(() => toast('Copy failed', 'error')); |
| 3921 | } |
| 3922 | |
| 3923 | async function deleteModelCard(cardId) { |
| 3924 | if (!confirm(`Delete model card ${cardId}?`)) return; |
| 3925 | try { |
| 3926 | await apiFetch(`/api/model-cards/${cardId}`, { method: 'DELETE' }); |
| 3927 | toast('Deleted', 'info'); |
| 3928 | loadModelCards(); |
| 3929 | } catch(e) { |
| 3930 | toast(`Error: ${e.message}`, 'error'); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | // ─── Hub (HuggingFace) ──────────────────────────────────────────── |
| 3935 | |
| 3936 | async function hubLogin() { |
| 3937 | const token = document.getElementById('hubToken').value; |
| 3938 | if (!token) { toast('Enter a HuggingFace token', 'error'); return; } |
| 3939 | const btn = document.getElementById('hubLoginBtn'); |
| 3940 | btn.disabled = true; btn.textContent = '⏳ Logging in...'; |
| 3941 | try { |
| 3942 | const resp = await fetch(`${API}/api/hub/login`, { |
| 3943 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 3944 | body: JSON.stringify({token}) |
| 3945 | }); |
| 3946 | const data = await resp.json(); |
| 3947 | if (data.success) { |
| 3948 | toast('Logged in to HF Hub!', 'success'); |
| 3949 | document.getElementById('hubStatus').textContent = '✅ Logged in.'; |
| 3950 | } else { |
| 3951 | toast('Login failed', 'error'); |
| 3952 | document.getElementById('hubStatus').textContent = '❌ Login failed.'; |
| 3953 | } |
| 3954 | } catch(e) { |
| 3955 | toast(`Error: ${e.message}`, 'error'); |
| 3956 | document.getElementById('hubStatus').textContent = `❌ ${e.message}`; |
| 3957 | } |
| 3958 | btn.disabled = false; btn.textContent = '🔑 Login'; |
| 3959 | } |
| 3960 | |
| 3961 | async function hubWhoami() { |
| 3962 | const statusEl = document.getElementById('hubStatus'); |
| 3963 | const btn = document.getElementById('hubStatusBtn'); |
| 3964 | btn.disabled = true; btn.textContent = '⏳ ...'; |
| 3965 | try { |
| 3966 | const data = await apiFetch('/api/hub/whoami'); |
| 3967 | if (data.logged_in) { |
| 3968 | statusEl.textContent = `✅ Logged in as: ${data.user}${data.email ? ` (${data.email})` : ''}`; |
| 3969 | toast(`Logged in as ${data.user}`, 'success'); |
| 3970 | } else { |
| 3971 | statusEl.textContent = '❌ Not logged in. Enter a HF token and click Login.'; |
| 3972 | toast('Not logged in', 'info'); |
| 3973 | } |
| 3974 | } catch(e) { |
| 3975 | statusEl.textContent = `❌ ${e.message}`; |
| 3976 | toast(`Error: ${e.message}`, 'error'); |
| 3977 | } |
| 3978 | btn.disabled = false; btn.textContent = '👤 Status'; |
| 3979 | } |
| 3980 | |
| 3981 | async function hubPush() { |
| 3982 | const model = document.getElementById('hubModelPath').value; |
| 3983 | const repo = document.getElementById('hubRepoId').value; |
| 3984 | const quant = document.getElementById('hubQuant').value; |
| 3985 | const params = document.getElementById('hubParams').value; |
| 3986 | const desc = document.getElementById('hubDescription').value; |
| 3987 | const priv = document.getElementById('hubPrivate').checked; |
| 3988 | if (!model || !repo) { toast('Select a model and enter a repo ID', 'error'); return; } |
| 3989 | const btn = document.getElementById('hubPushBtn'); |
| 3990 | const log = document.getElementById('hubLog'); |
| 3991 | btn.disabled = true; btn.textContent = '⏳ Uploading...'; |
| 3992 | log.textContent = 'Starting upload...\n'; |
| 3993 | try { |
| 3994 | const metadata = { studio_version: '0.1.0' }; |
| 3995 | if (quant) metadata.quantization = quant; |
| 3996 | if (params) metadata.parameters = params; |
| 3997 | if (desc) metadata.description = desc; |
| 3998 | const resp = await fetch(`${API}/api/hub/push`, { |
| 3999 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4000 | body: JSON.stringify({model, repo, private: priv, metadata}) |
| 4001 | }); |
| 4002 | const reader = resp.body.getReader(); |
| 4003 | const decoder = new TextDecoder(); |
| 4004 | while (true) { |
| 4005 | const {done, value} = await reader.read(); if (done) break; |
| 4006 | log.textContent += decoder.decode(value, {stream: true}); |
| 4007 | log.scrollTop = log.scrollHeight; |
| 4008 | } |
| 4009 | toast('Upload complete!', 'success'); |
| 4010 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Upload failed', 'error'); } |
| 4011 | btn.disabled = false; btn.textContent = '⬆️ Push to Hub'; |
| 4012 | } |
| 4013 | |
| 4014 | async function hubPushAdapter() { |
| 4015 | const adapter = document.getElementById('hubAdapterPath').value; |
| 4016 | const baseModel = document.getElementById('hubBaseModel').value; |
| 4017 | const repo = document.getElementById('hubAdapterRepo').value; |
| 4018 | const priv = document.getElementById('hubAdapterPrivate').checked; |
| 4019 | const rank = document.getElementById('hubAdapterRank').value; |
| 4020 | const alpha = document.getElementById('hubAdapterAlpha').value; |
| 4021 | if (!adapter || !baseModel || !repo) { toast('Fill all required fields', 'error'); return; } |
| 4022 | const btn = document.getElementById('hubPushAdapterBtn'); |
| 4023 | const log = document.getElementById('hubLog'); |
| 4024 | btn.disabled = true; btn.textContent = '⏳ Uploading...'; |
| 4025 | log.textContent = 'Starting adapter upload...\n'; |
| 4026 | try { |
| 4027 | const metadata = {}; |
| 4028 | if (rank) metadata.lora_rank = parseInt(rank); |
| 4029 | if (alpha) metadata.lora_alpha = parseFloat(alpha); |
| 4030 | const resp = await fetch(`${API}/api/hub/push-adapter`, { |
| 4031 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4032 | body: JSON.stringify({adapter, base_model: baseModel, repo, private: priv, metadata}) |
| 4033 | }); |
| 4034 | const reader = resp.body.getReader(); |
| 4035 | const decoder = new TextDecoder(); |
| 4036 | while (true) { |
| 4037 | const {done, value} = await reader.read(); if (done) break; |
| 4038 | log.textContent += decoder.decode(value, {stream: true}); |
| 4039 | log.scrollTop = log.scrollHeight; |
| 4040 | } |
| 4041 | toast('Adapter upload complete!', 'success'); |
| 4042 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Upload failed', 'error'); } |
| 4043 | btn.disabled = false; btn.textContent = '⬆️ Push Adapter'; |
| 4044 | } |
| 4045 | |
| 4046 | // ─── Safetensors Export ─── |
| 4047 | async function startSafetensors() { |
| 4048 | const model = document.getElementById('stModel').value; |
| 4049 | const output = document.getElementById('stOutput').value || model.replace('.gguf', '-safetensors'); |
| 4050 | const dtype = document.getElementById('stDtype').value; |
| 4051 | const shard = document.getElementById('stShard').value; |
| 4052 | const log = document.getElementById('exportFormatLog'); |
| 4053 | if (!model) { toast('Enter a GGUF model path', 'error'); return; } |
| 4054 | log.textContent = 'Starting safetensors conversion...\n'; |
| 4055 | try { |
| 4056 | const resp = await fetch(`${API}/api/export/safetensors`, { |
| 4057 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4058 | body: JSON.stringify({model_path: model, output_dir: output, dtype, shard_size: shard}) |
| 4059 | }); |
| 4060 | const reader = resp.body.getReader(); |
| 4061 | const decoder = new TextDecoder(); |
| 4062 | while (true) { |
| 4063 | const {done, value} = await reader.read(); if (done) break; |
| 4064 | log.textContent += decoder.decode(value, {stream: true}); |
| 4065 | log.scrollTop = log.scrollHeight; |
| 4066 | } |
| 4067 | toast('Safetensors conversion complete!', 'success'); |
| 4068 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Conversion failed', 'error'); } |
| 4069 | } |
| 4070 | |
| 4071 | // ─── ONNX Export ─── |
| 4072 | async function startOnnx() { |
| 4073 | const model = document.getElementById('onnxModel').value; |
| 4074 | const output = document.getElementById('onnxOutput').value || model.replace('.gguf', '.onnx'); |
| 4075 | const opset = parseInt(document.getElementById('onnxOpset').value) || 17; |
| 4076 | const seqLen = parseInt(document.getElementById('onnxSeqLen').value) || 2048; |
| 4077 | const log = document.getElementById('exportFormatLog'); |
| 4078 | if (!model) { toast('Enter a GGUF model path', 'error'); return; } |
| 4079 | log.textContent = 'Starting ONNX export...\n'; |
| 4080 | try { |
| 4081 | const resp = await fetch(`${API}/api/export/onnx`, { |
| 4082 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4083 | body: JSON.stringify({model_path: model, output_path: output, opset, max_seq_len: seqLen}) |
| 4084 | }); |
| 4085 | const reader = resp.body.getReader(); |
| 4086 | const decoder = new TextDecoder(); |
| 4087 | while (true) { |
| 4088 | const {done, value} = await reader.read(); if (done) break; |
| 4089 | log.textContent += decoder.decode(value, {stream: true}); |
| 4090 | log.scrollTop = log.scrollHeight; |
| 4091 | } |
| 4092 | toast('ONNX export complete!', 'success'); |
| 4093 | } catch(e) { log.textContent += `\nError: ${e.message}`; toast('Export failed', 'error'); } |
| 4094 | } |
| 4095 | |
| 4096 | // ─── Checkpoint Management ─── |
| 4097 | async function listCheckpoints() { |
| 4098 | const dir = document.getElementById('ckptDir').value || 'checkpoints'; |
| 4099 | const log = document.getElementById('ckptList'); |
| 4100 | const sel = document.getElementById('ckptResumeSelect'); |
| 4101 | log.textContent = 'Loading checkpoints...\n'; |
| 4102 | try { |
| 4103 | const data = await apiFetch(`/api/checkpoint?dir=${encodeURIComponent(dir)}`); |
| 4104 | const ckpts = data.checkpoints || []; |
| 4105 | if (ckpts.length === 0) { |
| 4106 | log.innerHTML = '<span class="text-dim">No checkpoints found.</span>'; |
| 4107 | sel.innerHTML = '<option value="">No checkpoints</option>'; |
| 4108 | document.getElementById('ckptResumeBtn').disabled = true; |
| 4109 | return; |
| 4110 | } |
| 4111 | sel.innerHTML = '<option value="">Select checkpoint...</option>'; |
| 4112 | log.innerHTML = `<div style="margin-bottom:12px;font-size:14px">Found <strong>${ckpts.length}</strong> checkpoint(s):</div>`; |
| 4113 | ckpts.forEach((c, i) => { |
| 4114 | const err = c.error ? '❌' : '✅'; |
| 4115 | const loss = c.loss !== undefined ? c.loss.toFixed(4) : '?'; |
| 4116 | const step = c.step !== undefined ? `Step ${c.step}` : '?'; |
| 4117 | const epoch = c.epoch !== undefined ? `Epoch ${c.epoch}` : ''; |
| 4118 | const ts = c.timestamp ? new Date(c.timestamp*1000).toLocaleString() : ''; |
| 4119 | log.innerHTML += `<div style="padding:6px 0;border-bottom:1px solid var(--border)">${err} <strong>${c.name || c.path}</strong><br>` |
| 4120 | + `<span style="font-size:11px;color:var(--dim)">${step} | ${epoch} | Loss: ${loss} | ${ts}</span></div>`; |
| 4121 | |
| 4122 | const opt = document.createElement('option'); |
| 4123 | opt.value = c.path || c.name; |
| 4124 | opt.textContent = `${c.name} — step ${step}, loss ${loss}`; |
| 4125 | sel.appendChild(opt); |
| 4126 | }); |
| 4127 | sel.onchange = () => { |
| 4128 | document.getElementById('ckptResumeBtn').disabled = !sel.value; |
| 4129 | }; |
| 4130 | toast(`Loaded ${ckpts.length} checkpoint(s)`, 'success'); |
| 4131 | } catch(e) { |
| 4132 | log.textContent = `Error loading checkpoints: ${e.message}`; |
| 4133 | toast('Failed to load checkpoints', 'error'); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | async function saveCheckpoint() { |
| 4138 | const dir = document.getElementById('ckptDir').value || 'checkpoints'; |
| 4139 | const log = document.getElementById('ckptList'); |
| 4140 | log.textContent = 'Saving checkpoint...\n'; |
| 4141 | try { |
| 4142 | const resp = await fetch(`${API}/api/checkpoint/save`, { |
| 4143 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4144 | body: JSON.stringify({dir}) |
| 4145 | }); |
| 4146 | if (!resp.ok) { |
| 4147 | const err = await resp.text(); |
| 4148 | log.textContent += `Error: ${err}`; |
| 4149 | toast('Checkpoint save failed', 'error'); |
| 4150 | return; |
| 4151 | } |
| 4152 | log.textContent += 'Checkpoint saved!\n'; |
| 4153 | toast('Checkpoint saved!', 'success'); |
| 4154 | listCheckpoints(); |
| 4155 | } catch(e) { |
| 4156 | log.textContent += `Error: ${e.message}`; |
| 4157 | toast('Checkpoint save failed', 'error'); |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | async function deleteAllCheckpoints() { |
| 4162 | if (!confirm('Delete all checkpoint data? This cannot be undone.')) return; |
| 4163 | const dir = document.getElementById('ckptDir').value || 'checkpoints'; |
| 4164 | const log = document.getElementById('ckptList'); |
| 4165 | log.textContent = 'Deleting checkpoints...\n'; |
| 4166 | try { |
| 4167 | const resp = await fetch(`${API}/api/checkpoint/clear`, { |
| 4168 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4169 | body: JSON.stringify({dir}) |
| 4170 | }); |
| 4171 | log.textContent += 'Checkpoints cleared.\n'; |
| 4172 | toast('Checkpoints cleared', 'info'); |
| 4173 | listCheckpoints(); |
| 4174 | } catch(e) { |
| 4175 | log.textContent += `Error: ${e.message}`; |
| 4176 | toast('Failed to clear checkpoints', 'error'); |
| 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | async function resumeTraining() { |
| 4181 | const model = document.getElementById('ckptResumeModel').value; |
| 4182 | const ckpt = document.getElementById('ckptResumeSelect').value; |
| 4183 | const output = document.getElementById('ckptResumeOutput').value || 'adapter.gguf'; |
| 4184 | if (!model || !ckpt) { toast('Select model and checkpoint', 'error'); return; } |
| 4185 | const log = document.getElementById('ckptList'); |
| 4186 | log.textContent = `Starting resume training from ${ckpt}...\n`; |
| 4187 | try { |
| 4188 | const resp = await fetch(`${API}/api/train`, { |
| 4189 | method: 'POST', headers: {'Content-Type': 'application/json'}, |
| 4190 | body: JSON.stringify({ |
| 4191 | model: model, |
| 4192 | method: 'lora', |
| 4193 | resume_from: ckpt, |
| 4194 | output: output, |
| 4195 | }) |
| 4196 | }); |
| 4197 | const result = await resp.json(); |
| 4198 | const trainingId = result.job_id || 'unknown'; |
| 4199 | log.textContent += `Training job started: ${trainingId}\n`; |
| 4200 | toast(`Resume training started (job ${trainingId})`, 'success'); |
| 4201 | } catch(e) { |
| 4202 | log.textContent += `Error: ${e.message}`; |
| 4203 | toast('Failed to start resume training', 'error'); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | // ─── Init ─── |
| 4208 | initLossChart(); |
| 4209 | refreshAll(); |
| 4210 | loadExperiments(); |
| 4211 | loadModelCards(); |
| 4212 | setInterval(loadBackend, 15000); |
| 4213 | </script> |
| 4214 | </body> |
| 4215 | </html> |