mlx-bun 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1453 -88
- package/THIRD_PARTY_NOTICES.md +882 -0
- package/bin/mlx-bun.convert.mjs +4 -0
- package/bin/mlx-bun.fuse.mjs +4 -0
- package/bin/mlx-bun.generate.mjs +4 -0
- package/bin/mlx-bun.lora.mjs +4 -0
- package/bin/mlx-bun.mjs +13 -21
- package/bin/mlx-bun.server.mjs +4 -0
- package/bin/mlx-bun.upload.mjs +4 -0
- package/dist/web/app.js +9584 -0
- package/package.json +50 -53
- package/src/cli/ane-install.ts +76 -0
- package/src/cli/args.ts +179 -0
- package/src/cli/engine-entry.ts +68 -0
- package/src/cli/inference.ts +214 -0
- package/src/cli/job-entry.ts +97 -0
- package/src/cli/library-host.ts +117 -0
- package/src/cli/main.ts +57 -0
- package/src/cli/memory-engine.ts +163 -0
- package/src/cli/memory.ts +36 -0
- package/src/cli/mlx-lm-aliases.ts +309 -0
- package/src/cli/model-choice.ts +33 -0
- package/src/cli/model-selection.ts +84 -0
- package/src/cli/module-host.ts +11 -0
- package/src/cli/module-verbs.ts +50 -0
- package/src/cli/numerical-policy.ts +12 -0
- package/src/cli/perplexity.ts +89 -0
- package/src/cli/serve-host.ts +423 -0
- package/src/cli/serve-isolated.ts +217 -0
- package/src/cli/serve-options.ts +106 -0
- package/src/cli/serve-state.ts +205 -0
- package/src/cli/serve.ts +500 -0
- package/src/cli/served-model-host.ts +102 -0
- package/src/cli/server-entry.ts +148 -0
- package/src/cli/serving-unit.ts +177 -0
- package/src/{tui.ts → cli/terminal.ts} +13 -8
- package/src/cli/worker-adapters.ts +34 -0
- package/src/cli/worker-entry.ts +272 -0
- package/src/cli/worker-unit.ts +179 -0
- package/src/engine/adapter-operation.ts +26 -0
- package/src/engine/cache-services.ts +114 -0
- package/src/engine/completion.ts +39 -0
- package/src/engine/generation-gateway.ts +358 -0
- package/src/engine/index.ts +59 -0
- package/src/engine/kv-budget.ts +120 -0
- package/src/engine/media-preparation.ts +232 -0
- package/src/engine/model-binding.ts +24 -0
- package/src/engine/model-host.ts +513 -0
- package/src/engine/model-serving.ts +89 -0
- package/src/{serve → engine}/preparation.ts +10 -8
- package/src/{serve → engine}/session-completion-engine.ts +6 -6
- package/src/engine/telemetry.ts +109 -0
- package/src/hub/downloads.ts +116 -0
- package/src/jobs/db.ts +16 -7
- package/src/jobs/events.ts +29 -0
- package/src/jobs/executable.ts +5 -0
- package/src/jobs/host.ts +51 -0
- package/src/jobs/in-process.ts +55 -0
- package/src/{contracts/jobs.ts → jobs/protocol.ts} +7 -9
- package/src/jobs/runner.ts +150 -231
- package/src/jobs/service.ts +75 -0
- package/src/jobs/sse.ts +59 -23
- package/src/jobs/worker-memory.ts +46 -0
- package/src/jobs/worker-process.ts +163 -0
- package/src/jobs/worker-supervisor.ts +258 -0
- package/src/modules.ts +58 -0
- package/src/publishing/catalog-hub.ts +18 -0
- package/src/publishing/credentials.ts +31 -0
- package/src/publishing/upload.ts +37 -0
- package/src/residency/leased-adapters.ts +21 -0
- package/src/residency/local-records.ts +16 -0
- package/src/residency/model-residency.ts +405 -0
- package/src/residency/record-index.ts +28 -0
- package/src/residency/resident-estimate.ts +50 -0
- package/src/{anthropic.ts → server/anthropic.ts} +3 -81
- package/src/server/cache-routes.ts +36 -0
- package/src/{serve → server}/chat-request.ts +12 -10
- package/src/{serve → server}/chat-stage.ts +27 -22
- package/src/{client.ts → server/client.ts} +28 -2
- package/src/{serve → server}/completion-executor.ts +42 -42
- package/src/server/decision-body.ts +55 -0
- package/src/server/decision-routes.ts +134 -0
- package/src/server/decision-wire.ts +228 -0
- package/src/{serve → server}/discovery-routes.ts +42 -83
- package/src/server/generated-token-history.ts +57 -0
- package/src/{serve → server}/http.ts +25 -13
- package/src/{serve → server}/inference-request.ts +5 -5
- package/src/server/job-routes.ts +20 -0
- package/src/server/media-prompt.ts +63 -0
- package/src/server/memory-completion-client.ts +46 -0
- package/src/server/model-routes.ts +192 -0
- package/src/{serve → server}/openai-wire.ts +3 -2
- package/src/{serve → server}/pipeline.ts +1 -1
- package/src/server/prompt-builder.ts +13 -0
- package/src/server/prompt-contracts.ts +17 -0
- package/src/server/proxy-routes.ts +187 -0
- package/src/server/publishing-routes.ts +41 -0
- package/src/{serve → server}/request-plan.ts +8 -8
- package/src/{serve → server}/request-prep.ts +82 -68
- package/src/{serve → server}/responses-client.ts +30 -13
- package/src/{responses.ts → server/responses.ts} +12 -93
- package/src/server/routes.ts +205 -0
- package/src/server/start.ts +72 -0
- package/src/server/status-routes.ts +108 -0
- package/src/{serve → server}/text-completion-stage.ts +25 -4
- package/src/server/text-prompt.ts +12 -0
- package/src/{serve → server}/token-streams.ts +36 -38
- package/src/server/worker-routes.ts +311 -0
- package/src/storage/paths.ts +61 -0
- package/src/web/assets.ts +37 -0
- package/src/web/{src → browser}/api.ts +5 -23
- package/src/web/browser/chat-host.ts +17 -0
- package/src/web/browser/installed-panels.ts +6 -0
- package/src/web/browser/main.ts +55 -0
- package/src/web/browser/markdown.ts +279 -0
- package/src/web/browser/memory-panel.ts +9 -0
- package/src/web/browser/palette.ts +64 -0
- package/src/web/browser/protocol.ts +13 -0
- package/src/web/browser/shell.ts +467 -0
- package/src/web/{src → browser}/status.ts +32 -36
- package/src/web/build.ts +51 -0
- package/src/web/public/app.html +1054 -0
- package/src/web/{sw.js → public/sw.js} +4 -3
- package/src/web/{vendor → public/vendor}/hljs-theme.css +2 -2
- package/src/web/{vendor → public/vendor}/hljs.js +2 -2
- package/THIRD_PARTY_LICENSES.md +0 -51
- package/docs/README.md +0 -94
- package/docs/archive/hlg-sampling.md +0 -350
- package/docs/archive/investigations/audio-input-plan.md +0 -356
- package/docs/archive/investigations/chunk-finetune-experiment.md +0 -84
- package/docs/archive/investigations/colibri-glm52-port.md +0 -1486
- package/docs/archive/investigations/colibri-oracle-pin.md +0 -1284
- package/docs/archive/investigations/curve-bisector-routing.md +0 -123
- package/docs/archive/investigations/decode-roofline-lookagain.md +0 -348
- package/docs/archive/investigations/diffusion-gemma-port.md +0 -602
- package/docs/archive/investigations/dspark-handoff.md +0 -224
- package/docs/archive/investigations/expert-offload-single-user-moe.md +0 -292
- package/docs/archive/investigations/faithful-l1-consolidation.md +0 -310
- package/docs/archive/investigations/hlg-sampling-investigation.md +0 -970
- package/docs/archive/investigations/indexshare-performance-spike.md +0 -357
- package/docs/archive/investigations/kernel-perf-review-2026-07.md +0 -171
- package/docs/archive/investigations/lab-build-journal.md +0 -157
- package/docs/archive/investigations/minicpm5-decode-megakernel.md +0 -489
- package/docs/archive/investigations/openjarvis-fit.md +0 -198
- package/docs/archive/investigations/openwiki-evaluation.md +0 -249
- package/docs/archive/investigations/optimization_plan.md +0 -346
- package/docs/archive/investigations/orpo-base-uf-experiment-and-directions.md +0 -120
- package/docs/archive/investigations/orpo-flash-cce-pin-leak.md +0 -167
- package/docs/archive/investigations/orpo-uf-testing-handoff.md +0 -126
- package/docs/archive/investigations/pareto-specialized-runtime-findings.md +0 -92
- package/docs/archive/investigations/pi-builtin-investigation.md +0 -308
- package/docs/archive/investigations/pre-colibri-stabilization.md +0 -329
- package/docs/archive/investigations/qwen38-27b-campaign-log.md +0 -1092
- package/docs/archive/investigations/segmented-backward-handoff.md +0 -148
- package/docs/archive/investigations/starter-model-port-handoff.md +0 -342
- package/docs/archive/investigations/steel-flash-cce-handoff.md +0 -489
- package/docs/archive/investigations/the-dreaming-handoff.md +0 -141
- package/docs/archive/investigations/trainer-validation-experiment.md +0 -173
- package/docs/archive/planning/chat-ui-vision-memory-first.md +0 -199
- package/docs/archive/planning/chat-ui-vision.md +0 -50
- package/docs/archive/planning/chunk-task-roadmap.md +0 -77
- package/docs/archive/planning/curve-sampler-research-plan.md +0 -331
- package/docs/archive/planning/journal.md +0 -316
- package/docs/archive/planning/memory-docs-and-dag-plan.md +0 -194
- package/docs/archive/planning/pi-integration-review.md +0 -178
- package/docs/archive/planning/release-notes-v0.0.10.md +0 -57
- package/docs/archive/planning/release-notes-v0.0.11.md +0 -239
- package/docs/archive/planning/release-notes-v0.0.12.md +0 -80
- package/docs/archive/planning/release-notes-v0.0.13.md +0 -77
- package/docs/archive/planning/release-notes-v0.0.9.md +0 -122
- package/docs/archive/planning/release-notes-v0.2.0.md +0 -49
- package/docs/archive/planning/release-notes-v0.3.0.md +0 -35
- package/docs/archive/planning/web-ui-pass-plan.md +0 -213
- package/docs/archive/planning/website-readme-pass-plan.md +0 -224
- package/docs/design/batching.md +0 -1841
- package/docs/design/decode-speed-program.md +0 -2349
- package/docs/design/dreaming-nightly-pipeline.md +0 -684
- package/docs/design/generic-model-support.md +0 -705
- package/docs/design/kv-cache.md +0 -824
- package/docs/design/orpo-training.md +0 -680
- package/docs/design/speculative-decoding.md +0 -1990
- package/docs/design/turboquant.md +0 -2212
- package/docs/design/unified-engine-frontier-plan.md +0 -1880
- package/docs/design/web-chat-redesign.md +0 -695
- package/docs/planning/PRODUCT_ROADMAP.md +0 -594
- package/docs/planning/ResearchTopics.md +0 -119
- package/docs/planning/release-notes-v0.4.0.md +0 -45
- package/docs/planning/video-series.md +0 -421
- package/docs/reference/benchmarks.md +0 -3613
- package/docs/reference/cli.md +0 -585
- package/docs/reference/distribution.md +0 -355
- package/docs/reference/environment.md +0 -398
- package/docs/reference/glossary.md +0 -39
- package/docs/reference/library-api.md +0 -674
- package/docs/reference/memory.md +0 -260
- package/docs/reference/models.md +0 -334
- package/docs/reference/server-api.md +0 -1775
- package/docs/reference/server-config.md +0 -846
- package/docs/reference/training.md +0 -462
- package/docs/reference/troubleshooting.md +0 -158
- package/src/admission-plan.ts +0 -18
- package/src/audio/conformer.ts +0 -647
- package/src/audio/decode.ts +0 -133
- package/src/audio/features.ts +0 -202
- package/src/audio/transcode.ts +0 -67
- package/src/backends/mlx/assistant-target.ts +0 -46
- package/src/backends/mlx/autoregressive-draft-rows.ts +0 -120
- package/src/backends/mlx/autoregressive.ts +0 -108
- package/src/backends/mlx/batch-group.ts +0 -1790
- package/src/backends/mlx/cache-attachment.ts +0 -67
- package/src/backends/mlx/cache-layout.ts +0 -31
- package/src/backends/mlx/checkpoint-state.ts +0 -53
- package/src/backends/mlx/continuation-persistence.ts +0 -106
- package/src/backends/mlx/continuation-request.ts +0 -43
- package/src/backends/mlx/continuation.ts +0 -77
- package/src/backends/mlx/diffusion.ts +0 -39
- package/src/backends/mlx/draft-target.ts +0 -32
- package/src/backends/mlx/evaluation.ts +0 -105
- package/src/backends/mlx/fill-append.ts +0 -45
- package/src/backends/mlx/full-kv-row-append.ts +0 -32
- package/src/backends/mlx/full-kv-row-donor.ts +0 -54
- package/src/backends/mlx/full-transitioning-kv-rows.ts +0 -65
- package/src/backends/mlx/gateway-binding.ts +0 -130
- package/src/backends/mlx/graph.ts +0 -38
- package/src/backends/mlx/kv-codec.ts +0 -9
- package/src/backends/mlx/kv-maintenance.ts +0 -133
- package/src/backends/mlx/kv-tensor-rows.ts +0 -212
- package/src/backends/mlx/memory-client.ts +0 -189
- package/src/backends/mlx/methods.ts +0 -90
- package/src/backends/mlx/model-prompt.ts +0 -164
- package/src/backends/mlx/model-serving.ts +0 -79
- package/src/backends/mlx/prefill-cohort.ts +0 -89
- package/src/backends/mlx/prefill-rows.ts +0 -200
- package/src/backends/mlx/prefill.ts +0 -33
- package/src/backends/mlx/projected-context-rows.ts +0 -72
- package/src/backends/mlx/request-policy.ts +0 -20
- package/src/backends/mlx/request-state-policy.ts +0 -41
- package/src/backends/mlx/rollback.ts +0 -89
- package/src/backends/mlx/row-sampling.ts +0 -49
- package/src/backends/mlx/serial-executor.ts +0 -242
- package/src/backends/mlx/speculative-group.ts +0 -359
- package/src/backends/mlx/speculative-round.ts +0 -161
- package/src/backends/mlx/speculative.ts +0 -114
- package/src/backends/mlx/state-rows.ts +0 -104
- package/src/backends/mlx/state-views.ts +0 -46
- package/src/backends/mlx/target-layout-capability.ts +0 -35
- package/src/backends/mlx/text-engine.ts +0 -73
- package/src/backends/mlx/transitioning-kv-rows.ts +0 -165
- package/src/chat-template.ts +0 -382
- package/src/cli.ts +0 -3168
- package/src/config.ts +0 -399
- package/src/contracts/completion.ts +0 -16
- package/src/contracts/execution.ts +0 -60
- package/src/contracts/generation.ts +0 -103
- package/src/contracts/host.ts +0 -7
- package/src/contracts/pi-provider.ts +0 -30
- package/src/contracts/pi.ts +0 -259
- package/src/contracts/prefix-cache.ts +0 -23
- package/src/contracts/resources.ts +0 -25
- package/src/contracts/sampling.ts +0 -23
- package/src/contracts/scheduling.ts +0 -45
- package/src/contracts/tsconfig.json +0 -14
- package/src/dataset/generators.ts +0 -1087
- package/src/dataset/index.ts +0 -12
- package/src/dataset/job.ts +0 -81
- package/src/dataset/llm.ts +0 -71
- package/src/dataset/registry.ts +0 -528
- package/src/diffusion/diffusion-generate.ts +0 -507
- package/src/download.ts +0 -505
- package/src/embed.ts +0 -77
- package/src/engine/admission.ts +0 -59
- package/src/engine/cancellation.ts +0 -38
- package/src/engine/engine.ts +0 -56
- package/src/engine/execution-coordinator.ts +0 -70
- package/src/engine/execution-plan.ts +0 -53
- package/src/engine/resources.ts +0 -53
- package/src/engine/scheduler.ts +0 -72
- package/src/engine/session.ts +0 -247
- package/src/eval/README.md +0 -130
- package/src/eval/ifeval.ts +0 -81
- package/src/eval/kl-prompts.ts +0 -29
- package/src/eval/kl.ts +0 -590
- package/src/eval/perplexity.ts +0 -164
- package/src/eval/quality-db.ts +0 -92
- package/src/eval/reference-logits.ts +0 -207
- package/src/eval/runner.ts +0 -124
- package/src/eval/score.ts +0 -49
- package/src/eval/tasks/bfcl.ts +0 -535
- package/src/eval/tasks/gsm8k.ts +0 -98
- package/src/eval/tasks/hashhop.ts +0 -139
- package/src/eval/tasks/humaneval.ts +0 -275
- package/src/eval/tasks/ifeval.ts +0 -525
- package/src/eval/tasks/mmlu.ts +0 -157
- package/src/eval/ultrafeedback.ts +0 -60
- package/src/evaldb.ts +0 -199
- package/src/expert-io.ts +0 -393
- package/src/expert-offload-build.ts +0 -77
- package/src/expert-offload.ts +0 -76
- package/src/expert-residency.ts +0 -1134
- package/src/expert-usage.ts +0 -415
- package/src/fill/echo-index.ts +0 -188
- package/src/fill/fill-session.ts +0 -452
- package/src/fill/proposal.ts +0 -68
- package/src/fill/schema-rows.ts +0 -506
- package/src/fill/tool-boundary.ts +0 -103
- package/src/fit.ts +0 -249
- package/src/generate.ts +0 -1346
- package/src/grammar.ts +0 -591
- package/src/harness-pi.ts +0 -184
- package/src/hf-push.ts +0 -628
- package/src/hub-rest.ts +0 -242
- package/src/index.ts +0 -63
- package/src/inference/denoising.ts +0 -17
- package/src/inference/draft-acceptance.ts +0 -41
- package/src/inference/draft-output.ts +0 -49
- package/src/inference/graph.ts +0 -33
- package/src/inference/prefill.ts +0 -39
- package/src/inference/rollback.ts +0 -7
- package/src/jobs/index.ts +0 -31
- package/src/jobs/job-entry.ts +0 -107
- package/src/jobs/task-client.ts +0 -19
- package/src/jobs/types.ts +0 -2
- package/src/kv-scheme.ts +0 -257
- package/src/kv-store.ts +0 -1099
- package/src/lab/README.md +0 -18
- package/src/lab/curve/curve-designer.html +0 -303
- package/src/lab/curve/curve-sampler.ts +0 -122
- package/src/lab/expert-trace/expert-trace.ts +0 -69
- package/src/lab/paged-kv/paged-kv-rows.ts +0 -83
- package/src/lab/paged-kv/paged-kv.ts +0 -270
- package/src/library.ts +0 -40
- package/src/lora.ts +0 -408
- package/src/md-modules.d.ts +0 -49
- package/src/media-fetch.ts +0 -442
- package/src/memory/article.ts +0 -558
- package/src/memory/chunk-validation.ts +0 -150
- package/src/memory/chunk.ts +0 -318
- package/src/memory/cluster.ts +0 -351
- package/src/memory/coverage.ts +0 -134
- package/src/memory/crosslink.ts +0 -0
- package/src/memory/db.ts +0 -253
- package/src/memory/entity.ts +0 -203
- package/src/memory/gate.ts +0 -187
- package/src/memory/history.ts +0 -152
- package/src/memory/ingest.ts +0 -335
- package/src/memory/model.ts +0 -183
- package/src/memory/normalize.ts +0 -671
- package/src/memory/parse.ts +0 -22
- package/src/memory/pipeline.ts +0 -275
- package/src/memory/prompts.ts +0 -65
- package/src/memory/query.ts +0 -334
- package/src/memory/reconcile.ts +0 -734
- package/src/memory/redirect.ts +0 -108
- package/src/memory/reindex.ts +0 -325
- package/src/memory/resolve.ts +0 -307
- package/src/memory/rest.ts +0 -245
- package/src/memory/route.ts +0 -272
- package/src/memory/schedule.ts +0 -165
- package/src/memory/stages.ts +0 -777
- package/src/memory/synthesize.ts +0 -1638
- package/src/memory/tools.ts +0 -749
- package/src/memory/vault.ts +0 -1194
- package/src/memory/wikify.ts +0 -1064
- package/src/mlx/array.ts +0 -388
- package/src/mlx/autograd.ts +0 -304
- package/src/mlx/checkpoint.ts +0 -149
- package/src/mlx/compile.ts +0 -168
- package/src/mlx/custom-vjp.ts +0 -188
- package/src/mlx/ffi.ts +0 -512
- package/src/mlx/materialize.ts +0 -23
- package/src/mlx/metal-kernel.ts +0 -159
- package/src/mlx/ops.ts +0 -1021
- package/src/mlx/quantized-rows.ts +0 -36
- package/src/mlx/token-bitmask.ts +0 -52
- package/src/mlx/turboquant-kv-decode.ts +0 -82
- package/src/mlx/turboquant-kv-inverse.ts +0 -122
- package/src/mlx/turboquant-ops.ts +0 -861
- package/src/mlx/turboquant-tables.ts +0 -237
- package/src/mmap.ts +0 -90
- package/src/model/artifact-identity.ts +0 -73
- package/src/model/batched-kv.ts +0 -235
- package/src/model/batched-mask.ts +0 -279
- package/src/model/batched-quant.ts +0 -212
- package/src/model/batched-quantized-kv.ts +0 -144
- package/src/model/batched-rotating-quant.ts +0 -353
- package/src/model/batched-rotating-state.ts +0 -149
- package/src/model/batched-rotating.ts +0 -338
- package/src/model/batched-row-storage.ts +0 -179
- package/src/model/batched-ssm.ts +0 -52
- package/src/model/batched-turboquant-kv.ts +0 -93
- package/src/model/compiled-decode.ts +0 -712
- package/src/model/decoded-kv-donor.ts +0 -12
- package/src/model/delayed-quantized-kv.ts +0 -72
- package/src/model/delayed-rotating-quantized-kv.ts +0 -93
- package/src/model/delayed-turboquant-kv.ts +0 -55
- package/src/model/diffusion-gemma.ts +0 -1026
- package/src/model/factory.ts +0 -189
- package/src/model/fingerprint.ts +0 -33
- package/src/model/flash-attention.ts +0 -694
- package/src/model/full-prefill-padding.ts +0 -56
- package/src/model/full-prefill-row.ts +0 -105
- package/src/model/gemma4-base.ts +0 -2351
- package/src/model/gemma4.ts +0 -1315
- package/src/model/generated/gemma4-12b.ts +0 -429
- package/src/model/generated/gemma4-26b.ts +0 -448
- package/src/model/generated/gemma4-e4b.ts +0 -717
- package/src/model/generated/index.ts +0 -18
- package/src/model/glm52-atlas.ts +0 -511
- package/src/model/glm52-cache.ts +0 -792
- package/src/model/glm52-config.ts +0 -262
- package/src/model/glm52-container.ts +0 -305
- package/src/model/glm52-coupling.ts +0 -388
- package/src/model/glm52-dsa.ts +0 -606
- package/src/model/glm52-expert-layout.ts +0 -253
- package/src/model/glm52-layout.ts +0 -152
- package/src/model/glm52-memory.ts +0 -500
- package/src/model/glm52-mla.ts +0 -792
- package/src/model/glm52-moe.ts +0 -223
- package/src/model/glm52-pilot.ts +0 -537
- package/src/model/glm52-reference.ts +0 -445
- package/src/model/glm52-residency.ts +0 -557
- package/src/model/glm52-resident-weights.ts +0 -135
- package/src/model/glm52-streamed-experts.ts +0 -453
- package/src/model/glm52-streamed-metal.ts +0 -610
- package/src/model/glm52-weights.ts +0 -503
- package/src/model/glm52.ts +0 -1132
- package/src/model/implementation.ts +0 -69
- package/src/model/kv-attention-view.ts +0 -67
- package/src/model/minicpm5.ts +0 -376
- package/src/model/profile.ts +0 -443
- package/src/model/qwen-append.ts +0 -12
- package/src/model/qwen-conv.ts +0 -52
- package/src/model/qwen3-delta-state.ts +0 -74
- package/src/model/qwen3-delta.ts +0 -451
- package/src/model/qwen3-moe.ts +0 -404
- package/src/model/qwen3-mrope.ts +0 -252
- package/src/model/qwen3.ts +0 -277
- package/src/model/qwen3_5-checkpoint.ts +0 -164
- package/src/model/qwen3_5.ts +0 -819
- package/src/model/rotating-kv-donor.ts +0 -35
- package/src/model/rotating-kv-layout.ts +0 -262
- package/src/model/rotating-row-transaction.ts +0 -35
- package/src/model/speculative-rotating-kv.ts +0 -101
- package/src/model/ssm-prefill-padding.ts +0 -39
- package/src/model/support.ts +0 -102
- package/src/model/trellis-balanced-scatter.ts +0 -51
- package/src/model/trellis-linear.ts +0 -672
- package/src/model/trellis-shared-m.ts +0 -151
- package/src/model/trellis-shared-scatter.ts +0 -144
- package/src/model/trellis-splitk-prefill.ts +0 -158
- package/src/model/trellis-tiled-prefill.ts +0 -136
- package/src/model/trellis-vector-expand.ts +0 -62
- package/src/model/trellis-wide-prefill.ts +0 -94
- package/src/model/turboquant-codec.ts +0 -83
- package/src/model/universal/archs.ts +0 -332
- package/src/model/universal/dense.ts +0 -612
- package/src/model/universal/modules.ts +0 -170
- package/src/model/universal/rope.ts +0 -381
- package/src/native/expert_io.c +0 -523
- package/src/native/frame_extract.swift +0 -140
- package/src/native-pack.ts +0 -162
- package/src/pi-provider.ts +0 -53
- package/src/pi-session.ts +0 -81
- package/src/pi-terminal.ts +0 -274
- package/src/pi-web.ts +0 -1932
- package/src/preflight.ts +0 -158
- package/src/prompt-cache.ts +0 -460
- package/src/quantize/allocator.ts +0 -627
- package/src/quantize/atomic-output.ts +0 -38
- package/src/quantize/calibration.ts +0 -181
- package/src/quantize/config-writer.ts +0 -145
- package/src/quantize/index.ts +0 -84
- package/src/quantize/job.ts +0 -162
- package/src/quantize/quantizer.ts +0 -666
- package/src/quantize/rotate.ts +0 -603
- package/src/quantize/safetensors-writer.ts +0 -249
- package/src/quantize/sensitivity.ts +0 -216
- package/src/quantize/trellis.ts +0 -586
- package/src/quantize/weight-transform.ts +0 -292
- package/src/registry.ts +0 -602
- package/src/runtime-config.ts +0 -81
- package/src/safetensors.ts +0 -158
- package/src/sampler.ts +0 -1011
- package/src/serve/admin-routes.ts +0 -184
- package/src/serve/assets/curve-terrain.html +0 -105
- package/src/serve/assets/training-inference-map.html +0 -575
- package/src/serve/aux-routes.ts +0 -132
- package/src/serve/batch-scheduler.ts +0 -8
- package/src/serve/checkpoint-identity.ts +0 -64
- package/src/serve/generation-gateway.ts +0 -496
- package/src/serve/isolate.ts +0 -609
- package/src/serve/kv-budget.ts +0 -14
- package/src/serve/lab-routes.ts +0 -341
- package/src/serve/lane-registry.ts +0 -45
- package/src/serve/model-admin-routes.ts +0 -155
- package/src/serve/model-binding.ts +0 -43
- package/src/serve/model-host.ts +0 -511
- package/src/serve/parent-application.ts +0 -56
- package/src/serve/prompt-response-trace.ts +0 -147
- package/src/serve/response-lease.ts +0 -24
- package/src/serve/session-search.ts +0 -326
- package/src/serve/static-routes.ts +0 -101
- package/src/server.ts +0 -1314
- package/src/spec/assistant-rows.ts +0 -92
- package/src/spec/assistant-source.ts +0 -126
- package/src/spec/cache-identity.ts +0 -22
- package/src/spec/deepspec-rows.ts +0 -29
- package/src/spec/deepspec-source.ts +0 -145
- package/src/spec/dflash-source.ts +0 -149
- package/src/spec/drafter.ts +0 -304
- package/src/spec/dspark/ab-stats.ts +0 -136
- package/src/spec/dspark/calibration.ts +0 -112
- package/src/spec/dspark/data-dflash.ts +0 -156
- package/src/spec/dspark/data.ts +0 -201
- package/src/spec/dspark/deepspec-module.ts +0 -776
- package/src/spec/dspark/generate-dflash.ts +0 -245
- package/src/spec/dspark/generate.ts +0 -290
- package/src/spec/dspark/loader.ts +0 -23
- package/src/spec/dspark/loss.ts +0 -213
- package/src/spec/dspark/module-dflash.ts +0 -560
- package/src/spec/dspark/module.ts +0 -540
- package/src/spec/dspark/quantize-drafter.ts +0 -91
- package/src/spec/dspark/sample.ts +0 -112
- package/src/spec/generate.ts +0 -276
- package/src/spec/glm52-mtp-graph.ts +0 -29
- package/src/spec/glm52-mtp-rows.ts +0 -132
- package/src/spec/glm52-mtp-source.ts +0 -317
- package/src/spec/glm52-mtp-state.ts +0 -33
- package/src/spec/ngram-source.ts +0 -204
- package/src/spec/projected-draft-rows.ts +0 -73
- package/src/spec/qwen-mtp-module.ts +0 -171
- package/src/spec/qwen-mtp-rows.ts +0 -219
- package/src/spec/qwen-mtp-source.ts +0 -383
- package/src/spec/qwen-mtp-state.ts +0 -30
- package/src/spec/serve-loop.ts +0 -585
- package/src/spec/source.ts +0 -215
- package/src/spec/two-model-rows.ts +0 -61
- package/src/spec/two-model.ts +0 -113
- package/src/ssd-cache.ts +0 -372
- package/src/ssd-durability.ts +0 -211
- package/src/tokenizer.ts +0 -335
- package/src/tool-approvals.ts +0 -131
- package/src/tool-call.ts +0 -695
- package/src/train/dataset.ts +0 -484
- package/src/train/diffusion-lora.ts +0 -216
- package/src/train/export.ts +0 -32
- package/src/train/flash-cce.ts +0 -1234
- package/src/train/forward.ts +0 -266
- package/src/train/fuse.ts +0 -243
- package/src/train/index.ts +0 -46
- package/src/train/job.ts +0 -205
- package/src/train/lora-params.ts +0 -254
- package/src/train/loss.ts +0 -1591
- package/src/train/merge.ts +0 -195
- package/src/train/optimizer.ts +0 -183
- package/src/train/prefix-shared.ts +0 -490
- package/src/train/rank.ts +0 -137
- package/src/train/segmented.ts +0 -1828
- package/src/train/steel-qmm-header.ts +0 -1461
- package/src/train/trainer.ts +0 -1221
- package/src/train/watch.ts +0 -542
- package/src/vision/diffusion-vision.ts +0 -620
- package/src/vision/embedder.ts +0 -168
- package/src/vision/preprocess.ts +0 -247
- package/src/vision/prompt.ts +0 -373
- package/src/vision/qwen3vl-preprocess.ts +0 -409
- package/src/vision/qwen3vl-prompt.ts +0 -196
- package/src/vision/qwen3vl-tower.ts +0 -555
- package/src/vision/siglip.ts +0 -599
- package/src/vision/video-frames.ts +0 -148
- package/src/web/app.html +0 -2143
- package/src/web/app.js +0 -5703
- package/src/web/skills/memory/SKILL.md +0 -120
- package/src/web/skills/web-research/SKILL.md +0 -46
- package/src/web/skills.ts +0 -97
- package/src/web/src/adapters-panel.ts +0 -288
- package/src/web/src/assistant.ts +0 -451
- package/src/web/src/chat.ts +0 -1057
- package/src/web/src/composer.ts +0 -959
- package/src/web/src/dataset.ts +0 -132
- package/src/web/src/finetune.ts +0 -267
- package/src/web/src/hub.ts +0 -428
- package/src/web/src/main.ts +0 -98
- package/src/web/src/markdown.ts +0 -0
- package/src/web/src/memory-panel.ts +0 -572
- package/src/web/src/model-picker.ts +0 -159
- package/src/web/src/palette.ts +0 -346
- package/src/web/src/protocol.ts +0 -26
- package/src/web/src/quantize.ts +0 -167
- package/src/web/src/rag.ts +0 -274
- package/src/web/src/sessions.ts +0 -469
- package/src/web/src/shell.ts +0 -804
- package/src/web/src/ui-catalog.ts +0 -78
- package/src/web/vendor/README.md +0 -61
- package/src/web-assets.ts +0 -47
- package/src/web-tools.ts +0 -478
- package/src/weights.ts +0 -255
- /package/src/{serve → server}/completion-sink.ts +0 -0
- /package/src/web/{icon.svg → public/icon.svg} +0 -0
- /package/src/web/{manifest.webmanifest → public/manifest.webmanifest} +0 -0
- /package/src/web/{vendor → public/vendor}/hljs-LICENSE +0 -0
|
@@ -1,575 +0,0 @@
|
|
|
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" />
|
|
6
|
-
<title>mlx-bun · control-flow DAG (MiniCPM5-1B)</title>
|
|
7
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.28.1/cytoscape.min.js"></script>
|
|
8
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/dagre/0.8.5/dagre.min.js"></script>
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/cytoscape-dagre@2.5.0/cytoscape-dagre.min.js"></script>
|
|
10
|
-
<style>
|
|
11
|
-
:root{--bg:#0b0f14;--panel:#11161d;--line:#243040;--txt:#cdd9e5;--dim:#7d8aa0;--cond:#39c5cf;}
|
|
12
|
-
*{box-sizing:border-box;}
|
|
13
|
-
html,body{margin:0;height:100%;background:var(--bg);color:var(--txt);font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;}
|
|
14
|
-
#top{display:flex;align-items:center;gap:12px;padding:8px 14px;flex-wrap:wrap;border-bottom:1px solid var(--line);background:var(--panel);}
|
|
15
|
-
#top b{color:#fff;font-size:14px;}
|
|
16
|
-
.seg{display:flex;gap:2px;background:#0b0f14;border:1px solid var(--line);border-radius:6px;}
|
|
17
|
-
.seg button,.btn{background:transparent;color:var(--dim);border:0;padding:5px 11px;cursor:pointer;font:inherit;border-radius:5px;}
|
|
18
|
-
.seg button.on{background:#388bfd;color:#fff;}
|
|
19
|
-
.btn{border:1px solid var(--line);}
|
|
20
|
-
.legend{margin-left:auto;display:flex;gap:11px;color:var(--dim);align-items:center;flex-wrap:wrap;font-size:11px;}
|
|
21
|
-
.legend span{display:flex;align-items:center;gap:5px;}
|
|
22
|
-
.dot{width:9px;height:9px;border-radius:50%;display:inline-block;}
|
|
23
|
-
.dash{width:15px;border-top:2px dashed var(--cond);display:inline-block;}
|
|
24
|
-
#wrap{display:flex;height:calc(100% - 46px);}
|
|
25
|
-
#cy{flex:1;height:100%;}
|
|
26
|
-
#side{width:340px;border-left:1px solid var(--line);background:var(--panel);padding:14px;overflow:auto;}
|
|
27
|
-
#side h2{margin:0 0 4px;font-size:14px;color:#fff;}
|
|
28
|
-
#side .file{color:#388bfd;font-size:12px;word-break:break-all;margin-bottom:8px;}
|
|
29
|
-
#side .k{color:var(--dim);text-transform:uppercase;font-size:10.5px;letter-spacing:.06em;margin-top:10px;}
|
|
30
|
-
#side .v{white-space:pre-wrap;}
|
|
31
|
-
.hint{color:var(--dim);font-size:12px;margin-top:6px;}
|
|
32
|
-
code{color:#e3b341;}
|
|
33
|
-
</style>
|
|
34
|
-
</head>
|
|
35
|
-
<body>
|
|
36
|
-
<div id="top">
|
|
37
|
-
<b>mlx-bun control-flow DAG</b><span style="color:var(--dim);font-size:11px">MiniCPM5-1B</span>
|
|
38
|
-
<div class="seg" id="graph">
|
|
39
|
-
<button data-g="infer" class="on">inference</button>
|
|
40
|
-
<button data-g="train">training</button>
|
|
41
|
-
</div>
|
|
42
|
-
<button class="btn" id="fit">⤢ fit</button>
|
|
43
|
-
<div class="legend" id="legend"></div>
|
|
44
|
-
</div>
|
|
45
|
-
<div id="wrap">
|
|
46
|
-
<div id="cy"></div>
|
|
47
|
-
<div id="side">
|
|
48
|
-
<h2 id="s-title">Click a step</h2>
|
|
49
|
-
<div class="file" id="s-file"></div>
|
|
50
|
-
<div class="hint" id="hint">Every node = one actual step the code runs. Solid arrows = the next step in execution order. <b style="color:var(--cond)">Dashed labelled arrows</b> = a branch: the code can go several ways, and the label is the exact condition (flag / variable / check) that takes that edge. Loops are back-edges. Scroll to zoom, drag to pan. Colour = subsystem (legend). Traced from the actual source — file:line on each node.</div>
|
|
51
|
-
<div id="s-body" style="display:none">
|
|
52
|
-
<div class="k">file</div><div class="v" id="s-fileb"></div>
|
|
53
|
-
<div class="k">subsystem</div><div class="v" id="s-grp"></div>
|
|
54
|
-
<div class="k">outgoing</div><div class="v" id="s-out"></div>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
<script>
|
|
59
|
-
// node = [id, label, group, file]. edge = [from, to, condition('' = unconditional)].
|
|
60
|
-
// A node with several edges of different conditions IS a branch point.
|
|
61
|
-
const GRP={ // subsystem → colour
|
|
62
|
-
drive:'#388bfd', fwd:'#2ea043', layer:'#3fb950', attn:'#d29922', sdpa:'#a371f7',
|
|
63
|
-
unfused:'#6e7b91', tiled:'#39c5cf', mlp:'#56d364', kv:'#f0883e', samp:'#db61a2',
|
|
64
|
-
setup:'#6e7b91', loss:'#d29922', seg:'#a371f7', accum:'#388bfd', bwd:'#f85149',
|
|
65
|
-
norm:'#39c5cf', opt:'#f0883e', metrics:'#db61a2' };
|
|
66
|
-
|
|
67
|
-
const INFER={ n:[
|
|
68
|
-
['n1','generate() entry','drive','generate.ts:168'],
|
|
69
|
-
['n2','generateInner() entry','drive','generate.ts:208'],
|
|
70
|
-
['n3','? wired-scope: FORCE_WIRE ∨ weights>thresh','drive','generate.ts:175'],
|
|
71
|
-
['n4','enter wired scope','drive','generate.ts:200'],
|
|
72
|
-
['n5','? adapters?.length','drive','generate.ts:174'],
|
|
73
|
-
['n6','set loraState.active','drive','generate.ts:187'],
|
|
74
|
-
['n7','makeCache/Sampler/LogitsProcessors','drive','generate.ts:218'],
|
|
75
|
-
['n8','maybeQuantizeKv (prefill)','drive','generate.ts:281'],
|
|
76
|
-
['n9','? prompt-pos > prefillChunkSize','drive','generate.ts:298'],
|
|
77
|
-
['n10','chunked prefill: loop chunk','drive','generate.ts:299'],
|
|
78
|
-
['n11','forwardHidden(chunk, cache)','drive','generate.ts:301'],
|
|
79
|
-
['n12','evalAll(cache) after chunk','drive','generate.ts:304'],
|
|
80
|
-
['n13','clearCache() after chunk','drive','generate.ts:312'],
|
|
81
|
-
['n14','? options.promptEmbeddings','drive','generate.ts:284'],
|
|
82
|
-
['n15','forwardEmbeddings(...)','drive','generate.ts:292'],
|
|
83
|
-
['n16','forwardHidden(lastChunk, cache)','drive','generate.ts:320'],
|
|
84
|
-
['n17','? needsTokenHistory init','drive','generate.ts:315'],
|
|
85
|
-
['n18','slice last position h0[:,L-1]','drive','generate.ts:324'],
|
|
86
|
-
['n19','logitsFromHidden(hLast)','drive','generate.ts:326'],
|
|
87
|
-
['n20','sampleStep(logits0, 0)','drive','generate.ts:328'],
|
|
88
|
-
['n21','asyncEvalAll([pending])','drive','generate.ts:338'],
|
|
89
|
-
['n22','? CompiledDecode.for (env·adapters·gemma4)','drive','generate.ts:352'],
|
|
90
|
-
['n23','decode loop: while !stop','drive','generate.ts:360'],
|
|
91
|
-
['n24','? generated+1 < maxTokens','drive','generate.ts:364'],
|
|
92
|
-
['n25','maybeQuantizeKv (decode)','drive','generate.ts:365'],
|
|
93
|
-
['n26','pushHistory(cur)','drive','generate.ts:366'],
|
|
94
|
-
['n27','? compiled && supports(cache)','drive','generate.ts:369'],
|
|
95
|
-
['n28','compiled.step(cur, cache)','drive','generate.ts:371'],
|
|
96
|
-
['n29','catch → compiled=null (fallback)','drive','generate.ts:374'],
|
|
97
|
-
['n30','forwardHidden(ids, cache)','drive','generate.ts:383'],
|
|
98
|
-
['n31','logitsFromHidden(h)','drive','generate.ts:385'],
|
|
99
|
-
['n32','sampleStep(logits, n+1)','drive','generate.ts:388'],
|
|
100
|
-
['n33','asyncEvalAll([nextPending,…])','drive','generate.ts:390'],
|
|
101
|
-
['n34','itemUint32(cur) sync-read token','drive','generate.ts:394'],
|
|
102
|
-
['n35','? first token: prefillMs/tDecode','drive','generate.ts:399'],
|
|
103
|
-
['n36','cur.dispose; generated++','drive','generate.ts:402'],
|
|
104
|
-
['n37','? nextPending !== null','drive','generate.ts:406'],
|
|
105
|
-
['n38','? eosTokenIds.includes(token)','drive','generate.ts:408'],
|
|
106
|
-
['n39','yield {token, index}','drive','generate.ts:413'],
|
|
107
|
-
['n40','? clearCache every 256','drive','generate.ts:416'],
|
|
108
|
-
['n42','stop = true (no next)','drive','generate.ts:418'],
|
|
109
|
-
['n43','pending = nextPending','drive','generate.ts:420'],
|
|
110
|
-
['n44','stop = true (EOS / done)','drive','generate.ts:411'],
|
|
111
|
-
['n45','decodeMs','drive','generate.ts:425'],
|
|
112
|
-
['n46','return makeStats()','drive','generate.ts:427'],
|
|
113
|
-
['n47','finally: dispose pending/cache/history','drive','generate.ts:432'],
|
|
114
|
-
['n49','loraState.active=[] (scope exit)','drive','generate.ts:191'],
|
|
115
|
-
['n50','exitWiredScope()','drive','generate.ts:204'],
|
|
116
|
-
// model forward
|
|
117
|
-
['n51','embed.encode(ids)','fwd','minicpm5.ts:250'],
|
|
118
|
-
['n52','forwardLayers(h, cache)','fwd','minicpm5.ts:258'],
|
|
119
|
-
['n53','runLayerRange(h,0,N,cache)','fwd','minicpm5.ts:259'],
|
|
120
|
-
['n54','? makeMask(L) (N==1? offset==0?)','fwd','minicpm5.ts:275'],
|
|
121
|
-
['n55','for i in [0,N): layers','fwd','minicpm5.ts:277'],
|
|
122
|
-
['n56','layers[i].forward(cur,mask,cache[i])','fwd','minicpm5.ts:278'],
|
|
123
|
-
['n57','? dispose(cur) if i>0','fwd','minicpm5.ts:279'],
|
|
124
|
-
['n58','mask.arr?.dispose()','fwd','minicpm5.ts:282'],
|
|
125
|
-
['n59','finalNorm.forward(h)','fwd','minicpm5.ts:261'],
|
|
126
|
-
['n60','lmHead.forward(h) → logits','fwd','minicpm5.ts:287'],
|
|
127
|
-
// layer
|
|
128
|
-
['n61','inputNorm RMSNorm','layer','minicpm5.ts:189'],
|
|
129
|
-
['n62','attn.forward(xn,mask,cache)','layer','minicpm5.ts:190'],
|
|
130
|
-
['n63','add(x, attnOut) residual','layer','minicpm5.ts:192'],
|
|
131
|
-
['n64','postAttnNorm RMSNorm','layer','minicpm5.ts:194'],
|
|
132
|
-
['n65','mlp.forward(hn)','layer','minicpm5.ts:195'],
|
|
133
|
-
['n66','add(h, mlpOut) residual','layer','minicpm5.ts:197'],
|
|
134
|
-
// attention
|
|
135
|
-
['n67','q_proj quantized_matmul','attn','minicpm5.ts:89'],
|
|
136
|
-
['n68','k_proj quantized_matmul','attn','minicpm5.ts:90'],
|
|
137
|
-
['n69','v_proj quantized_matmul','attn','minicpm5.ts:91'],
|
|
138
|
-
['n70','reshape q [B,L,H,D]','attn','minicpm5.ts:93'],
|
|
139
|
-
['n71','reshape k [B,L,Kv,D]','attn','minicpm5.ts:94'],
|
|
140
|
-
['n72','reshape v [B,L,Kv,D]','attn','minicpm5.ts:95'],
|
|
141
|
-
['n73','transpose q →[B,H,L,D]','attn','minicpm5.ts:97'],
|
|
142
|
-
['n74','transpose k','attn','minicpm5.ts:98'],
|
|
143
|
-
['n75','transpose v','attn','minicpm5.ts:99'],
|
|
144
|
-
['n76','? rope: prefixPlan / offsetArr / static','attn','minicpm5.ts:106'],
|
|
145
|
-
['n77','ropeBlocks(q) (prefix)','attn','minicpm5.ts:108'],
|
|
146
|
-
['n78','ropeDynamic(q) (offsetArr)','attn','minicpm5.ts:110'],
|
|
147
|
-
['n79','rope(q, cache.offset)','attn','minicpm5.ts:111'],
|
|
148
|
-
['n80','rope k (same offset)','attn','minicpm5.ts:113'],
|
|
149
|
-
['n81','? cache instanceof QuantizedKVCache','attn','minicpm5.ts:115'],
|
|
150
|
-
['n82','updateAndFetchQuantized(k,v)','attn','minicpm5.ts:116'],
|
|
151
|
-
['n83','quantizedSdpa(q,kq,vq,…)','attn','minicpm5.ts:119'],
|
|
152
|
-
['n84','updateAndFetch(k,v) bf16','attn','minicpm5.ts:123'],
|
|
153
|
-
['n85','? getTrainingAttn()=="flash"','attn','minicpm5.ts:128'],
|
|
154
|
-
['n86','flashAttention(...)','attn','minicpm5.ts:130'],
|
|
155
|
-
['n87','ops.sdpa(q,keys,values,…)','attn','minicpm5.ts:132'],
|
|
156
|
-
['n88','transpose attn →[B,L,H,D]','attn','minicpm5.ts:138'],
|
|
157
|
-
['n89','reshape merged [B,L,H*D]','attn','minicpm5.ts:140'],
|
|
158
|
-
['n90','o_proj quantized_matmul','attn','minicpm5.ts:142'],
|
|
159
|
-
// sdpa dispatch
|
|
160
|
-
['n91','? mask=="" && scale==1.0','sdpa','gemma4-base.ts:1514'],
|
|
161
|
-
['n92','? perfKernelEnabled()','sdpa','fused-decode-kernel.ts:36'],
|
|
162
|
-
['n93','? !isCompiledTrace()','sdpa','gemma4-base.ts:1515'],
|
|
163
|
-
['n94','? fusedDecodeKernelSupported','sdpa','gemma4-base.ts:1515'],
|
|
164
|
-
['n95','⚙ fusedDecodeSdpa (L=1)','sdpa','gemma4-base.ts:1517'],
|
|
165
|
-
['n96','? tile: L>1 ∨ FUSED_DECODE','sdpa','gemma4-base.ts:1518'],
|
|
166
|
-
['n97','? fusedSdpaSupported','sdpa','gemma4-base.ts:1519'],
|
|
167
|
-
['n98','⚙ quantizedSdpaTiled','sdpa','gemma4-base.ts:1520'],
|
|
168
|
-
['n99','quantizedSdpaUnfused','sdpa','gemma4-base.ts:1521'],
|
|
169
|
-
// unfused internals
|
|
170
|
-
['n100','dims [B,H,L,D,KV,nRep,N]','unfused','gemma4-base.ts:1221'],
|
|
171
|
-
['n101','? scale !== 1.0','unfused','gemma4-base.ts:1229'],
|
|
172
|
-
['n102','mulScalar(q, scale)','unfused','gemma4-base.ts:1229'],
|
|
173
|
-
['n103','? nRep > 1 (GQA)','unfused','gemma4-base.ts:1233'],
|
|
174
|
-
['n104','reshape q [B,KV,nRep,L,D]','unfused','gemma4-base.ts:1234'],
|
|
175
|
-
['n105','expandDims(k.packed,-3)','unfused','gemma4-base.ts:1245'],
|
|
176
|
-
['n106','quantizedMatmulQT(q,kᵀ) → scores','unfused','gemma4-base.ts:1251'],
|
|
177
|
-
['n107','? mask.mode=="causal"','unfused','gemma4-base.ts:1256'],
|
|
178
|
-
['n108','greaterEqual → causal mask','unfused','gemma4-base.ts:1261'],
|
|
179
|
-
['n109','? mask.mode=="array"','unfused','gemma4-base.ts:1264'],
|
|
180
|
-
['n110','where(mask, scores, -inf)','unfused','gemma4-base.ts:1269'],
|
|
181
|
-
['n111','softmaxAxis(scores,-1)','unfused','gemma4-base.ts:1276'],
|
|
182
|
-
['n112','quantizedMatmulQT(probs,vᵀ) → out','unfused','gemma4-base.ts:1278'],
|
|
183
|
-
['n113','? nRep > 1','unfused','gemma4-base.ts:1279'],
|
|
184
|
-
['n114','reshape out [B,H,L,D]','unfused','gemma4-base.ts:1280'],
|
|
185
|
-
// tiled internals
|
|
186
|
-
['n115','dims [B,H,L,D,KV,nRep,N]','tiled','gemma4-base.ts:1304'],
|
|
187
|
-
['n116','? scale !== 1.0','tiled','gemma4-base.ts:1312'],
|
|
188
|
-
['n117','mulScalar(q, scale)','tiled','gemma4-base.ts:1312'],
|
|
189
|
-
['n118','? nRep > 1 (GQA)','tiled','gemma4-base.ts:1317'],
|
|
190
|
-
['n119','reshape q [B,KV,nRep,L,D]','tiled','gemma4-base.ts:1318'],
|
|
191
|
-
['n120','expandDims(k.packed,-3)','tiled','gemma4-base.ts:1324'],
|
|
192
|
-
['n121','? mask.mode=="causal"','tiled','gemma4-base.ts:1340'],
|
|
193
|
-
['n122','greaterEqual → causal mask','tiled','gemma4-base.ts:1345'],
|
|
194
|
-
['n123','? mask.mode=="array"','tiled','gemma4-base.ts:1348'],
|
|
195
|
-
['n124','for n0=0..N step 512 (KV chunks)','tiled','gemma4-base.ts:1378'],
|
|
196
|
-
['n125','slice kᵀ.packed chunk','tiled','gemma4-base.ts:1381'],
|
|
197
|
-
['n126','slice kᵀ.scales chunk','tiled','gemma4-base.ts:1382'],
|
|
198
|
-
['n127','slice kᵀ.biases chunk','tiled','gemma4-base.ts:1383'],
|
|
199
|
-
['n128','slice vᵀ.packed chunk','tiled','gemma4-base.ts:1386'],
|
|
200
|
-
['n129','quantizedMatmulQT(q,kChunk) → scores','tiled','gemma4-base.ts:1391'],
|
|
201
|
-
['n130','? maskChunk dtype bool','tiled','gemma4-base.ts:1397'],
|
|
202
|
-
['n131','where(mask, scores, -inf)','tiled','gemma4-base.ts:1399'],
|
|
203
|
-
['n132','add(scores, maskChunk) float','tiled','gemma4-base.ts:1402'],
|
|
204
|
-
['n133','maxAxis(scores) → chunkMax','tiled','gemma4-base.ts:1409'],
|
|
205
|
-
['n134','? oAcc===null (first tile)','tiled','gemma4-base.ts:1410'],
|
|
206
|
-
['n135','init rowMax/rowSum/oAcc','tiled','gemma4-base.ts:1411'],
|
|
207
|
-
['n136','maximum(rowMax,chunkMax)=newMax','tiled','gemma4-base.ts:1419'],
|
|
208
|
-
['n137','exp(rowMax-newMax)=factor','tiled','gemma4-base.ts:1422'],
|
|
209
|
-
['n138','exp(scores-newMax)=exps','tiled','gemma4-base.ts:1425'],
|
|
210
|
-
['n139','newSum = factor·rowSum + Σexps','tiled','gemma4-base.ts:1428'],
|
|
211
|
-
['n140','nextAcc = oAcc·factor + exps·vChunk','tiled','gemma4-base.ts:1436'],
|
|
212
|
-
['n141','rowMax/rowSum = new','tiled','gemma4-base.ts:1443'],
|
|
213
|
-
['n142','div(oAcc, rowSum) → out','tiled','gemma4-base.ts:1452'],
|
|
214
|
-
['n143','? nRep > 1','tiled','gemma4-base.ts:1459'],
|
|
215
|
-
['n144','reshape out [B,H,L,D]','tiled','gemma4-base.ts:1460'],
|
|
216
|
-
// mlp
|
|
217
|
-
['n145','gate_proj quantized_matmul','mlp','minicpm5.ts:160'],
|
|
218
|
-
['n146','up_proj quantized_matmul','mlp','minicpm5.ts:161'],
|
|
219
|
-
['n147','sigmoid(gate)','mlp','minicpm5.ts:162'],
|
|
220
|
-
['n148','mul → SiLU (gate·σ(gate))','mlp','minicpm5.ts:163'],
|
|
221
|
-
['n149','mul(silu, up)','mlp','minicpm5.ts:166'],
|
|
222
|
-
['n150','down_proj quantized_matmul','mlp','minicpm5.ts:169'],
|
|
223
|
-
// KV bf16
|
|
224
|
-
['n151','offset=prev, L=k.shape[2]','kv','gemma4-base.ts:252'],
|
|
225
|
-
['n152','? capacity: !keys ∨ prev+L>cap','kv','gemma4-base.ts:254'],
|
|
226
|
-
['n153','alloc newK/newV zeros','kv','gemma4-base.ts:257'],
|
|
227
|
-
['n154','? cache exists','kv','gemma4-base.ts:260'],
|
|
228
|
-
['n155','? prev%STEP!=0 (trim)','kv','gemma4-base.ts:263'],
|
|
229
|
-
['n156','slice old, dispose','kv','gemma4-base.ts:264'],
|
|
230
|
-
['n157','concat([old,new]) grow','kv','gemma4-base.ts:271'],
|
|
231
|
-
['n158','sliceUpdate keys←k','kv','gemma4-base.ts:283'],
|
|
232
|
-
['n159','sliceUpdate values←v','kv','gemma4-base.ts:284'],
|
|
233
|
-
['n160','slice fetch keys','kv','gemma4-base.ts:290'],
|
|
234
|
-
['n161','slice fetch values','kv','gemma4-base.ts:291'],
|
|
235
|
-
// KV quantized
|
|
236
|
-
['n162','prev/L/elPerInt','kv','gemma4-base.ts:443'],
|
|
237
|
-
['n163','? capacity (packed)','kv','gemma4-base.ts:446'],
|
|
238
|
-
['n164','grow cache (6 comps)','kv','gemma4-base.ts:447'],
|
|
239
|
-
['n165','? prev%STEP!=0 (trim)','kv','gemma4-base.ts:448'],
|
|
240
|
-
['n166','trimTo (slice 6)','kv','gemma4-base.ts:449'],
|
|
241
|
-
['n167','quantize(k) → kq','kv','gemma4-base.ts:467'],
|
|
242
|
-
['n168','quantize(v) → vq','kv','gemma4-base.ts:468'],
|
|
243
|
-
['n169','write k packed/scales/biases','kv','gemma4-base.ts:479'],
|
|
244
|
-
['n175','fetch keys (3 comps)','kv','gemma4-base.ts:488'],
|
|
245
|
-
['n176','fetch values (3 comps)','kv','gemma4-base.ts:488'],
|
|
246
|
-
// sampler
|
|
247
|
-
['n177','? curve sampler active','samp','sampler.ts:418'],
|
|
248
|
-
['n178','applyCurve(lp, curve)','samp','sampler.ts:420'],
|
|
249
|
-
['n179','randomCategorical (curve)','samp','sampler.ts:421'],
|
|
250
|
-
['n180','? temperature === 0','samp','sampler.ts:429'],
|
|
251
|
-
['n181','argmaxAxis(lp) greedy','samp','sampler.ts:430'],
|
|
252
|
-
['n182','? hlg?.enabled','samp','sampler.ts:437'],
|
|
253
|
-
['n183','applyHlgShaper','samp','sampler.ts:453'],
|
|
254
|
-
['n184','applyHlgPipeline','samp','sampler.ts:454'],
|
|
255
|
-
['n185','applyHlgEotf','samp','sampler.ts:454'],
|
|
256
|
-
['n186','applyHlgOetf','samp','sampler.ts:455'],
|
|
257
|
-
['n187','applyHlg (parametric)','samp','sampler.ts:455'],
|
|
258
|
-
['n188','randomCategorical (HLG)','samp','sampler.ts:457'],
|
|
259
|
-
['n189','? topP in (0,1)','samp','sampler.ts:467'],
|
|
260
|
-
['n190','applyTopP(lp, topP)','samp','sampler.ts:467'],
|
|
261
|
-
['n191','? topK > 0','samp','sampler.ts:468'],
|
|
262
|
-
['n192','applyTopK(lp, topK)','samp','sampler.ts:468'],
|
|
263
|
-
['n193','mulScalar(lp, 1/temp)','samp','sampler.ts:469'],
|
|
264
|
-
['n194','randomCategorical (temp)','samp','sampler.ts:471'],
|
|
265
|
-
],e:[
|
|
266
|
-
['n1','n2',''],['n2','n3',''],
|
|
267
|
-
['n3','n4','FORCE_WIRE ∨ weights>thresh'],['n3','n5','else'],
|
|
268
|
-
['n4','n5',''],
|
|
269
|
-
['n5','n6','adapters?.length'],['n5','n7','else'],
|
|
270
|
-
['n6','n7',''],['n7','n8',''],['n8','n9',''],
|
|
271
|
-
['n9','n10','pos > prefillChunkSize'],['n9','n14','else (one-shot)'],
|
|
272
|
-
['n10','n11',''],['n11','n51','call forward'],['n11','n12',''],['n12','n13',''],
|
|
273
|
-
['n13','n10','more chunks'],['n13','n14','done'],
|
|
274
|
-
['n14','n15','promptEmbeddings'],['n14','n16','else'],
|
|
275
|
-
['n15','n17',''],['n16','n51','call forward'],['n16','n17',''],
|
|
276
|
-
['n17','n18',''],['n18','n19',''],['n19','n60','call lmHead'],['n19','n20',''],['n20','n21',''],['n21','n22',''],['n22','n23',''],
|
|
277
|
-
['n23','n24',''],
|
|
278
|
-
['n24','n25','generated+1<maxTokens'],['n24','n34','else'],
|
|
279
|
-
['n25','n26',''],['n26','n27',''],
|
|
280
|
-
['n27','n28','compiled && supports'],['n27','n30','else (uncompiled)'],
|
|
281
|
-
['n28','n29','throws'],['n28','n31','ok'],['n29','n30',''],
|
|
282
|
-
['n30','n51','call forward'],['n30','n31',''],['n31','n60','call lmHead'],['n31','n32',''],['n32','n33',''],['n33','n34',''],
|
|
283
|
-
['n34','n35','first token'],['n34','n36','else'],['n35','n36',''],['n36','n37',''],
|
|
284
|
-
['n37','n38','nextPending!=null'],['n37','n42','else'],
|
|
285
|
-
['n38','n39','!EOS'],['n38','n44','EOS'],
|
|
286
|
-
['n39','n40',''],['n40','n43','nextPending'],['n40','n42','none'],
|
|
287
|
-
['n42','n44',''],['n43','n23','loop'],
|
|
288
|
-
['n44','n45',''],['n45','n46',''],['n46','n47',''],['n47','n49',''],['n49','n50',''],
|
|
289
|
-
// forward
|
|
290
|
-
['n51','n52',''],['n52','n53',''],['n53','n54',''],['n54','n55',''],
|
|
291
|
-
['n55','n56','i<N'],['n56','n57',''],['n57','n55','i++'],['n57','n58','done'],
|
|
292
|
-
['n58','n59',''],['n59','n12','return (prefill)'],['n59','n17','return (prefill)'],['n59','n31','return (decode)'],
|
|
293
|
-
// layer (called by n56)
|
|
294
|
-
['n56','n61','call layer'],
|
|
295
|
-
['n61','n62',''],['n62','n63',''],['n63','n64',''],['n64','n65',''],['n65','n66',''],
|
|
296
|
-
// attention (called by n62)
|
|
297
|
-
['n62','n67','call attn'],
|
|
298
|
-
['n67','n68',''],['n68','n69',''],['n69','n70',''],['n70','n71',''],['n71','n72',''],['n72','n73',''],['n73','n74',''],['n74','n75',''],['n75','n76',''],
|
|
299
|
-
['n76','n77','_prefixPlan'],['n76','n78','offsetArr'],['n76','n79','else (static)'],
|
|
300
|
-
['n77','n80',''],['n78','n80',''],['n79','n80',''],['n80','n81',''],
|
|
301
|
-
['n81','n82','QuantizedKVCache'],['n81','n84','else (bf16)'],
|
|
302
|
-
['n82','n83',''],['n83','n88',''],
|
|
303
|
-
['n84','n85',''],
|
|
304
|
-
['n85','n86','flash & supported'],['n85','n87','else'],
|
|
305
|
-
['n86','n88',''],['n87','n88',''],['n88','n89',''],['n89','n90',''],
|
|
306
|
-
// sdpa dispatch (called by n83)
|
|
307
|
-
['n83','n91','call quantizedSdpa'],
|
|
308
|
-
['n91','n92','mask=="" & scale==1'],['n91','n96','else'],
|
|
309
|
-
['n92','n93','perfKernel'],['n92','n96','else'],
|
|
310
|
-
['n93','n94','!compiledTrace'],['n93','n96','else'],
|
|
311
|
-
['n94','n95','supported'],['n94','n96','else'],
|
|
312
|
-
['n96','n97','tile (L>1 ∨ FUSED_DECODE)'],['n96','n99','else'],
|
|
313
|
-
['n97','n98','fusedSdpaSupported'],['n97','n99','else'],
|
|
314
|
-
// unfused (n99)
|
|
315
|
-
['n99','n100','call'],['n100','n101',''],
|
|
316
|
-
['n101','n102','scale!=1'],['n101','n103','else'],['n102','n103',''],
|
|
317
|
-
['n103','n104','nRep>1'],['n103','n106','else'],['n104','n105',''],['n105','n106',''],
|
|
318
|
-
['n106','n107',''],['n107','n108','causal'],['n107','n109','else'],
|
|
319
|
-
['n108','n110',''],['n109','n110','array'],['n109','n111','none'],['n110','n111',''],
|
|
320
|
-
['n111','n112',''],['n112','n113',''],['n113','n114','nRep>1'],
|
|
321
|
-
// tiled (n98)
|
|
322
|
-
['n98','n115','call'],['n115','n116',''],
|
|
323
|
-
['n116','n117','scale!=1'],['n116','n118','else'],['n117','n118',''],
|
|
324
|
-
['n118','n119','nRep>1'],['n118','n121','else'],['n119','n120',''],['n120','n121',''],
|
|
325
|
-
['n121','n122','causal'],['n121','n123','else'],['n122','n124',''],['n123','n124',''],
|
|
326
|
-
['n124','n125','n0<N'],['n125','n126',''],['n126','n127',''],['n127','n128',''],['n128','n129',''],
|
|
327
|
-
['n129','n130',''],['n130','n131','bool'],['n130','n132','float'],['n131','n133',''],['n132','n133',''],
|
|
328
|
-
['n133','n134',''],['n134','n135','first'],['n134','n136','else'],
|
|
329
|
-
['n135','n124','next chunk'],
|
|
330
|
-
['n136','n137',''],['n137','n138',''],['n138','n139',''],['n139','n140',''],['n140','n141',''],['n141','n124','next chunk'],
|
|
331
|
-
['n124','n142','n0>=N'],['n142','n143',''],['n143','n144','nRep>1'],
|
|
332
|
-
// mlp (called by n65)
|
|
333
|
-
['n65','n145','call mlp'],
|
|
334
|
-
['n145','n146',''],['n146','n147',''],['n147','n148',''],['n148','n149',''],['n149','n150',''],
|
|
335
|
-
// KV bf16 (called by n84)
|
|
336
|
-
['n84','n151','call updateAndFetch'],
|
|
337
|
-
['n151','n152',''],['n152','n153','grow'],['n152','n158','fits'],
|
|
338
|
-
['n153','n154',''],['n154','n155','exists'],['n154','n157','first'],
|
|
339
|
-
['n155','n156','prev%STEP!=0'],['n155','n157','aligned'],['n156','n157',''],['n157','n158',''],
|
|
340
|
-
['n158','n159',''],['n159','n160',''],['n160','n161',''],
|
|
341
|
-
// KV quant (called by n82)
|
|
342
|
-
['n82','n162','call updateAndFetchQuantized'],
|
|
343
|
-
['n162','n163',''],['n163','n164','grow'],['n163','n167','fits'],
|
|
344
|
-
['n164','n165',''],['n165','n166','prev%STEP!=0'],['n165','n167','aligned'],['n166','n167',''],
|
|
345
|
-
['n167','n168',''],['n168','n169',''],['n169','n175',''],['n175','n176',''],
|
|
346
|
-
// sampler (called by n20, n32)
|
|
347
|
-
['n20','n177','call sampleStep'],['n32','n177','call sampleStep'],
|
|
348
|
-
['n177','n178','curve'],['n177','n180','else'],['n178','n179',''],
|
|
349
|
-
['n180','n181','temp==0'],['n180','n182','else'],
|
|
350
|
-
['n182','n183','shaper'],['n182','n184','pipeline'],['n182','n185','eotf'],['n182','n186','oetf'],['n182','n187','parametric'],['n182','n189','hlg off'],
|
|
351
|
-
['n183','n188',''],['n184','n188',''],['n185','n188',''],['n186','n188',''],['n187','n188',''],
|
|
352
|
-
['n189','n190','topP'],['n189','n191','else'],['n190','n191',''],
|
|
353
|
-
['n191','n192','topK'],['n191','n193','else'],['n192','n193',''],['n193','n194',''],
|
|
354
|
-
]};
|
|
355
|
-
|
|
356
|
-
const TRAIN={ n:[
|
|
357
|
-
['t1','step loop begins','setup','trainer.ts:479'],
|
|
358
|
-
['t2','per-step dropout seed','setup','trainer.ts:876'],
|
|
359
|
-
['t3','enter accumulation loop','accum','trainer.ts:487'],
|
|
360
|
-
['t4','fetch micro-batch','accum','trainer.ts:490'],
|
|
361
|
-
['t5','? segmentSize > 0','setup','trainer.ts:409'],
|
|
362
|
-
['t6','segmented forward start','seg','segmented.ts:196'],
|
|
363
|
-
['t7','embed.encode(ids)','seg','segmented.ts:196'],
|
|
364
|
-
['t8','detach embedding boundary','seg','segmented.ts:196'],
|
|
365
|
-
['t9','for segment k=0..nSeg','seg','segmented.ts:197'],
|
|
366
|
-
['t10','runLayerRange[lo:hi] (swap LoRA)','seg','segmented.ts:199'],
|
|
367
|
-
['t11','detach output boundary k','seg','segmented.ts:199'],
|
|
368
|
-
['t12','? ORPO prefix-shared & segmented','seg','trainer.ts:880'],
|
|
369
|
-
['t13','splitPrefixBatch','seg','trainer.ts:881'],
|
|
370
|
-
['t14','single forward [P;C;R] block-mask','seg','prefix-shared.ts:159'],
|
|
371
|
-
['t15','prefix fallback (two-forward)','seg','trainer.ts:884'],
|
|
372
|
-
['t16','non-segmented forward start','accum','trainer.ts:492'],
|
|
373
|
-
['t17','value_and_grad: swap primals','accum','trainer.ts:432'],
|
|
374
|
-
['t18','? B==1 response-only vs full','loss','loss.ts:123'],
|
|
375
|
-
['t19','forwardHidden → [B,T,hid]','fwd','forward.ts:72'],
|
|
376
|
-
['t20','embedding forward','fwd','forward.ts:92'],
|
|
377
|
-
['t21','layer-stack forward','fwd','forward.ts:92'],
|
|
378
|
-
['t22','? MLX_BUN_TRAIN_ATTN=="flash"','fwd','trainer.ts:469'],
|
|
379
|
-
['t23','sdpa attention (O(L²) bwd)','fwd','loss.ts:131'],
|
|
380
|
-
['t24','flash attention (O(L) bwd)','fwd','trainer.ts:469'],
|
|
381
|
-
['t25','final norm','fwd','forward.ts:113'],
|
|
382
|
-
['t26','lm-head → logits','fwd','loss.ts:131'],
|
|
383
|
-
['t27','? B==1 responseCe vs B>1 maskedCe','loss','loss.ts:123'],
|
|
384
|
-
['t28','slice hidden to response span','loss','loss.ts:160'],
|
|
385
|
-
['t29','head at response positions','loss','loss.ts:161'],
|
|
386
|
-
['t30','gather target logits','loss','loss.ts:170'],
|
|
387
|
-
['t31','logsumexp vocab','loss','loss.ts:169'],
|
|
388
|
-
['t32','CE = lse - target','loss','loss.ts:172'],
|
|
389
|
-
['t33','sum/normalize response CE','loss','loss.ts:174'],
|
|
390
|
-
['t34','build response mask [B,T]','loss','loss.ts:233'],
|
|
391
|
-
['t35','reshape logits [B*T,V]','loss','loss.ts:251'],
|
|
392
|
-
['t36','gather targets','loss','loss.ts:252'],
|
|
393
|
-
['t37','logsumexp','loss','loss.ts:256'],
|
|
394
|
-
['t38','CE * mask','loss','loss.ts:262'],
|
|
395
|
-
['t39','sum masked CE / norm','loss','loss.ts:264'],
|
|
396
|
-
['t40','DPO ref logps (scale=0, detach)','loss','loss.ts:361'],
|
|
397
|
-
['t41','DPO policy logps','loss','loss.ts:389'],
|
|
398
|
-
['t42','logr_c = piC - refC','loss','loss.ts:392'],
|
|
399
|
-
['t43','logr_r = piR - refR','loss','loss.ts:393'],
|
|
400
|
-
['t44','adv = β(logr_c - logr_r)','loss','loss.ts:394'],
|
|
401
|
-
['t45','-logσ(adv) = softplus; mean','loss','loss.ts:399'],
|
|
402
|
-
['t46','ORPO chosen logp','loss','loss.ts:1242'],
|
|
403
|
-
['t47','? orpoChunkSize > 0','loss','loss.ts:481'],
|
|
404
|
-
['t48','? orpoFusedCe ∨ orpoFlashCe','loss','loss.ts:482'],
|
|
405
|
-
['t49','chunked head (Checkpoint)','loss','loss.ts:567'],
|
|
406
|
-
['t50','fused linear-CE head (CustomVjp)','loss','loss.ts:726'],
|
|
407
|
-
['t51','vocab-blocked head','loss','loss.ts:822'],
|
|
408
|
-
['t52','flash-CCE Metal head','loss','loss.ts:1009'],
|
|
409
|
-
['t53','whole-vocab head (oracle)','loss','loss.ts:1087'],
|
|
410
|
-
['t54','ORPO rejected logp','loss','loss.ts:1243'],
|
|
411
|
-
['t55','NLL = mean(-ℓw)','loss','loss.ts:1225'],
|
|
412
|
-
['t56','log_odds calc','loss','loss.ts:1207'],
|
|
413
|
-
['t57','OR = mean softplus(-log_odds)','loss','loss.ts:1228'],
|
|
414
|
-
['t58','L = NLL + λ·OR','loss','loss.ts:1231'],
|
|
415
|
-
['t59','seg loss-head VJP (cot=1)','seg','segmented.ts:141'],
|
|
416
|
-
['t60','seg loss scalar (detached)','seg','segmented.ts:204'],
|
|
417
|
-
['t61','seg dh_out = dLoss/dhidden','seg','segmented.ts:205'],
|
|
418
|
-
['t62','evalAll([loss, …grads])','accum','trainer.ts:1027'],
|
|
419
|
-
['t63','loss scalar toFloat32','accum','trainer.ts:1028'],
|
|
420
|
-
['t64','scale grad by 1/accum','accum','trainer.ts:1042'],
|
|
421
|
-
['t65','accumulate grad','accum','trainer.ts:1048'],
|
|
422
|
-
['t66','dispose checkpoint closures','accum','trainer.ts:496'],
|
|
423
|
-
['t67','sum micro losses','accum','trainer.ts:1061'],
|
|
424
|
-
['t69','value_and_grad backward','bwd','trainer.ts:492'],
|
|
425
|
-
['t70','MLX reverse-mode AD','bwd','trainer.ts:492'],
|
|
426
|
-
['t71','restore LoRA leaves','bwd','trainer.ts:436'],
|
|
427
|
-
['t72','seg backward: k=nSeg-1..0','bwd','segmented.ts:210'],
|
|
428
|
-
['t73','vjp segment k (cot=dh_out)','bwd','segmented.ts:215'],
|
|
429
|
-
['t74','scatter per-seg LoRA grads','bwd','segmented.ts:220'],
|
|
430
|
-
['t75','dh_in → cotangent for k-1','bwd','segmented.ts:225'],
|
|
431
|
-
['t76','dispose boundary k','bwd','segmented.ts:226'],
|
|
432
|
-
['t80','globalNorm(grads)','norm','trainer.ts:1076'],
|
|
433
|
-
['t81','square each grad','norm','trainer.ts:1078'],
|
|
434
|
-
['t82','sum squares, sqrt','norm','trainer.ts:1086'],
|
|
435
|
-
['t83','? ‖g‖ > maxNorm','norm','trainer.ts:1099'],
|
|
436
|
-
['t84','scale g *= max/‖g‖','norm','trainer.ts:1103'],
|
|
437
|
-
['t85','AdamW.step(grads)','opt','trainer.ts:504'],
|
|
438
|
-
['t86','t++ step counter','opt','optimizer.ts:84'],
|
|
439
|
-
['t87','bias-correct β1^t','opt','optimizer.ts:85'],
|
|
440
|
-
['t88','bias-correct β2^t','opt','optimizer.ts:86'],
|
|
441
|
-
['t89','for each param i (A,B)','opt','optimizer.ts:88'],
|
|
442
|
-
['t90','grad → float32','opt','optimizer.ts:92'],
|
|
443
|
-
['t91','m ← β1·m + (1-β1)g','opt','optimizer.ts:95'],
|
|
444
|
-
['t92','v ← β2·v + (1-β2)g²','opt','optimizer.ts:105'],
|
|
445
|
-
['t93','? weight decay','opt','optimizer.ts:119'],
|
|
446
|
-
['t94','m̂ = m/(1-β1^t)','opt','optimizer.ts:125'],
|
|
447
|
-
['t95','v̂ = v/(1-β2^t)','opt','optimizer.ts:126'],
|
|
448
|
-
['t96','√v̂ + ε','opt','optimizer.ts:127'],
|
|
449
|
-
['t97','m̂/(√v̂+ε)','opt','optimizer.ts:130'],
|
|
450
|
-
['t98','scale by lr (LoRA+ per-param)','opt','optimizer.ts:131'],
|
|
451
|
-
['t99','p = p - lr·update','opt','optimizer.ts:132'],
|
|
452
|
-
['t100','writeParam → swap into LoRA','opt','trainer.ts:402'],
|
|
453
|
-
['t101','opt.evalState()','opt','trainer.ts:505'],
|
|
454
|
-
['t102','clearCache()','metrics','trainer.ts:511'],
|
|
455
|
-
['t103','emit step metrics','metrics','trainer.ts:516'],
|
|
456
|
-
['t104','? step%report==0 ∨ step==1','metrics','trainer.ts:514'],
|
|
457
|
-
['t105','recompute dpo/orpo metrics','metrics','trainer.ts:900'],
|
|
458
|
-
['t106','? step%eval==0 & valid>0','metrics','trainer.ts:529'],
|
|
459
|
-
['t107','disable grad-ckpt for eval','metrics','trainer.ts:532'],
|
|
460
|
-
['t108','loop validation examples','metrics','trainer.ts:554'],
|
|
461
|
-
['t109','eval loss per example','metrics','trainer.ts:564'],
|
|
462
|
-
['t110','reduce eval (mean/acc/margin)','metrics','trainer.ts:684'],
|
|
463
|
-
['t111','re-enable grad-ckpt','metrics','trainer.ts:534'],
|
|
464
|
-
['t112','step iteration completes','setup','trainer.ts:538'],
|
|
465
|
-
],e:[
|
|
466
|
-
['t1','t2',''],['t2','t3',''],['t3','t4',''],['t4','t5',''],
|
|
467
|
-
['t5','t6','segmentSize>0'],['t5','t16','else'],
|
|
468
|
-
['t6','t7',''],['t7','t8',''],['t8','t9',''],
|
|
469
|
-
['t9','t10','k<nSeg'],['t10','t11',''],['t11','t9','k++'],
|
|
470
|
-
['t11','t12','done (ORPO)'],['t11','t59','done (SFT seg)'],
|
|
471
|
-
['t12','t13','prefixShared & segmented'],['t12','t59','else'],
|
|
472
|
-
['t13','t14','split non-null'],['t13','t15','null (mismatch)'],
|
|
473
|
-
['t14','t59',''],['t15','t72',''],
|
|
474
|
-
['t16','t17',''],['t17','t18',''],
|
|
475
|
-
['t18','t19','B==1'],['t18','t20','full-logits'],
|
|
476
|
-
['t19','t20',''],['t20','t21',''],['t21','t22',''],
|
|
477
|
-
['t22','t24','flash'],['t22','t23','else'],
|
|
478
|
-
['t23','t25',''],['t24','t25',''],['t25','t26',''],
|
|
479
|
-
['t19','t27','SFT B==1'],['t26','t27','SFT B>1'],
|
|
480
|
-
['t27','t28','B==1'],['t27','t34','B>1'],
|
|
481
|
-
['t28','t29',''],['t29','t30',''],['t30','t31',''],['t31','t32',''],['t32','t33',''],
|
|
482
|
-
['t34','t35',''],['t35','t36',''],['t36','t37',''],['t37','t38',''],['t38','t39',''],
|
|
483
|
-
// DPO
|
|
484
|
-
['t4','t40','method==dpo'],['t40','t41',''],['t41','t42',''],['t42','t43',''],['t43','t44',''],['t44','t45',''],
|
|
485
|
-
// ORPO
|
|
486
|
-
['t4','t12','method==orpo & prefixShared'],['t12','t46','else'],['t13','t46','null → two-forward'],
|
|
487
|
-
['t46','t47',''],
|
|
488
|
-
['t47','t48','chunkSize>0'],['t47','t54','batched'],
|
|
489
|
-
['t48','t49','neither'],['t48','t50','fused'],['t48','t52','flash'],
|
|
490
|
-
['t50','t51','vocabBlock>0'],['t50','t53','else'],
|
|
491
|
-
['t49','t54',''],['t51','t54',''],['t52','t54',''],['t53','t54',''],
|
|
492
|
-
['t14','t55','prefix-shared done'],['t54','t55',''],
|
|
493
|
-
['t55','t56',''],['t56','t57',''],['t57','t58',''],
|
|
494
|
-
// seg head
|
|
495
|
-
['t59','t60',''],['t60','t61',''],
|
|
496
|
-
// accumulation
|
|
497
|
-
['t33','t62','SFT B==1'],['t39','t62','SFT B>1'],['t45','t62','DPO'],['t58','t62','ORPO'],['t60','t62','seg'],
|
|
498
|
-
['t62','t63',''],
|
|
499
|
-
['t63','t64','accum>1'],['t63','t66','else'],
|
|
500
|
-
['t64','t65',''],['t65','t66',''],
|
|
501
|
-
['t66','t64','next micro'],['t66','t67','last micro'],
|
|
502
|
-
// backward
|
|
503
|
-
['t62','t69','non-seg'],['t69','t70',''],['t70','t71',''],
|
|
504
|
-
['t61','t72','seg'],['t72','t73','k>=0'],['t73','t74',''],['t74','t75',''],['t75','t76',''],['t76','t72','k--'],
|
|
505
|
-
// norm/clip
|
|
506
|
-
['t71','t80',''],['t72','t80','seg done'],['t67','t80','accum done'],
|
|
507
|
-
['t80','t81',''],['t81','t82',''],['t82','t83',''],
|
|
508
|
-
['t83','t84','‖g‖>max'],['t83','t85','else'],['t84','t85',''],
|
|
509
|
-
// optimizer
|
|
510
|
-
['t85','t86',''],['t86','t87',''],['t87','t88',''],['t88','t89',''],
|
|
511
|
-
['t89','t90','i<len'],['t90','t91',''],['t91','t92',''],['t92','t93',''],
|
|
512
|
-
['t93','t94','wd>0 / else'],['t94','t95',''],['t95','t96',''],['t96','t97',''],['t97','t98',''],['t98','t99',''],['t99','t100',''],['t100','t89','i++'],
|
|
513
|
-
['t89','t101','done'],
|
|
514
|
-
// metrics
|
|
515
|
-
['t101','t102',''],['t102','t103',''],['t103','t104',''],
|
|
516
|
-
['t104','t105','report'],['t104','t106','skip'],['t105','t106',''],
|
|
517
|
-
['t106','t107','eval'],['t106','t112','skip'],
|
|
518
|
-
['t107','t108',''],['t108','t109','ex'],['t109','t108','next'],['t108','t110','done'],['t110','t111',''],['t111','t112',''],
|
|
519
|
-
['t112','t1','step++'],
|
|
520
|
-
]};
|
|
521
|
-
|
|
522
|
-
let MODE_G='infer';
|
|
523
|
-
const cy=cytoscape({container:document.getElementById('cy'),minZoom:0.06,maxZoom:3,wheelSensitivity:0.25,
|
|
524
|
-
autoungrabify:true, boxSelectionEnabled:false, selectionType:'single',
|
|
525
|
-
style:[
|
|
526
|
-
{selector:'node',style:{'background-color':d=>GRP[d.data('grp')]||'#6e7b91','label':'data(label)',
|
|
527
|
-
'color':'#0b0f14','font-family':'ui-monospace, Menlo, monospace','font-size':'11px','font-weight':'600',
|
|
528
|
-
'text-valign':'center','text-halign':'center','shape':'round-rectangle','width':'label','height':22,
|
|
529
|
-
'padding':'7px','text-wrap':'wrap','text-max-width':'210px','border-width':1,'border-color':'#0b0f14'}},
|
|
530
|
-
{selector:'node[branch]',style:{'border-width':2.5,'border-color':'#39c5cf'}},
|
|
531
|
-
{selector:'node:selected',style:{'border-width':3,'border-color':'#fff'}},
|
|
532
|
-
{selector:'edge',style:{'width':1.6,'line-color':'#3a4760','target-arrow-color':'#3a4760',
|
|
533
|
-
'target-arrow-shape':'triangle','curve-style':'bezier','arrow-scale':0.8}},
|
|
534
|
-
{selector:'edge[cond]',style:{'line-color':'#39c5cf','target-arrow-color':'#39c5cf','line-style':'dashed',
|
|
535
|
-
'label':'data(cond)','font-size':'8px','font-family':'ui-monospace, Menlo, monospace','color':'#39c5cf',
|
|
536
|
-
'text-background-color':'#0b0f14','text-background-opacity':0.85,'text-background-padding':'1px','text-rotation':'autorotate'}},
|
|
537
|
-
]});
|
|
538
|
-
|
|
539
|
-
function build(g){
|
|
540
|
-
// count outgoing per node to mark branch points (>1 distinct outgoing edge)
|
|
541
|
-
const out={}; g.e.forEach(([a])=>out[a]=(out[a]||0)+1);
|
|
542
|
-
const nodes=g.n.map(([id,label,grp,file])=>({data:{id,label,grp,file,branch:out[id]>1?1:undefined}}));
|
|
543
|
-
const edges=g.e.map(([a,b,c])=>({data:{id:a+'>'+b+(c||''),source:a,target:b,...(c?{cond:c}:{})}}));
|
|
544
|
-
return {nodes,edges};
|
|
545
|
-
}
|
|
546
|
-
function load(g){const el=build(g);cy.elements().remove();cy.add(el.nodes);cy.add(el.edges);
|
|
547
|
-
cy.layout({name:'dagre',rankDir:'TB',nodeSep:18,rankSep:30,padding:30}).run();}
|
|
548
|
-
|
|
549
|
-
function show(d){
|
|
550
|
-
document.getElementById('s-title').textContent=d.label;
|
|
551
|
-
document.getElementById('s-file').textContent=d.file||'';
|
|
552
|
-
document.getElementById('hint').style.display='none';
|
|
553
|
-
document.getElementById('s-body').style.display='block';
|
|
554
|
-
document.getElementById('s-fileb').textContent=d.file||'';
|
|
555
|
-
document.getElementById('s-grp').textContent=d.grp||'';
|
|
556
|
-
const outs=cy.getElementById(d.id).outgoers('edge').map(e=>{
|
|
557
|
-
const t=e.target().data('label'); const c=e.data('cond'); return c?`• [${c}] → ${t}`:`• → ${t}`;}).join('\n');
|
|
558
|
-
document.getElementById('s-out').textContent=outs||'(terminal)';
|
|
559
|
-
}
|
|
560
|
-
cy.on('tap','node',e=>show(e.target.data()));
|
|
561
|
-
document.getElementById('fit').onclick=()=>cy.fit(undefined,40);
|
|
562
|
-
const LABELS={drive:'generate',fwd:'forward',layer:'layer',attn:'attention',sdpa:'sdpa dispatch',unfused:'unfused sdpa',tiled:'tiled sdpa',mlp:'mlp',kv:'kv cache',samp:'sampler',
|
|
563
|
-
setup:'setup/loop',loss:'loss head',seg:'segmented',accum:'accum',bwd:'backward',norm:'grad norm/clip',opt:'optimizer',metrics:'metrics/eval'};
|
|
564
|
-
function legend(){
|
|
565
|
-
const groups = MODE_G==='infer' ? ['drive','fwd','attn','sdpa','tiled','unfused','mlp','kv','samp'] : ['setup','fwd','loss','seg','accum','bwd','norm','opt','metrics'];
|
|
566
|
-
document.getElementById('legend').innerHTML='<span><i class="dash"></i>branch (condition)</span>'+
|
|
567
|
-
groups.map(g=>`<span><i class="dot" style="background:${GRP[g]}"></i>${LABELS[g]}</span>`).join('');
|
|
568
|
-
}
|
|
569
|
-
document.querySelectorAll('#graph button').forEach(b=>b.onclick=()=>{
|
|
570
|
-
document.querySelectorAll('#graph button').forEach(x=>x.classList.remove('on'));b.classList.add('on');
|
|
571
|
-
MODE_G=b.dataset.g;load(MODE_G==='infer'?INFER:TRAIN);legend();});
|
|
572
|
-
legend();load(INFER);
|
|
573
|
-
</script>
|
|
574
|
-
</body>
|
|
575
|
-
</html>
|