Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions docs/prd/folio-next-live-capture-and-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,22 @@ Delivered in phases, each gated by spikes:
- **Runtime:** llama.cpp, in-process through a Rust binding, built statically from vendored sources. There is **no
runtime download**, and the zero-egress CI gate must stay green (S5).
- **Weights:** a 3–4B instruction model, quantised (Q4), chosen by S2/S3/S4 and **licence-vetted**. Prefer
Apache-2.0 or MIT; avoid licences with use restrictions that complicate redistribution.
Apache-2.0 or MIT; avoid licences with use restrictions that complicate redistribution. S2's finalists are
**Qwen3-4B-Instruct-2507** and **Qwen3.5-4B** (both Apache-2.0, Q4_0); S3 and S4 choose between them.
- **Delivery:** as a **signed model pack**, reusing `modelpack/` and the fail-closed
`resolve_verified_models_dir` in `app/src-tauri/src/models.rs`. The manifest gains `task: "llm"`.
- **Memory:** ASR and LLM are never resident together. The ASR model is unloaded before note generation, so a
16 GB (target: 8 GB) office laptop fits.
- **Long transcripts:** if S2 shows a single pass is too slow or exceeds context, use **map-reduce by
transcript section**: summarise each section with its citations, then compose the template.
- **Drafting during the recording (S2):** every ~10 minutes, the section just recorded goes to the LLM, which
extracts its facts with citations under the template's headings. After stop, only the last section remains,
so a 60- or 90-minute recording has its note in about 1–3 minutes on the S2 Mac. A single pass or map-reduce
started at stop took 7–47 minutes. Imported recordings have no "during": they are processed section by
section in the background, with progress shown.
- **The note is the section facts.** The first version of the note is those facts grouped by template heading.
S2 found that one "compose" call over all the facts drops about half of them, so a shorter prose note
needs a design that doesn't lose facts.
- **Memory:** while recording, ASR and LLM are both loaded. The LLM runs with an 8k context: about 4.4–4.7 GB
peak, plus about 1.1–1.3 GB for live ASR (S1 and S2). That fits a 16 GB office laptop. The 8 GB target is
tight and needs measuring on the reference laptop.
- **Map output cap** of about 3k tokens (2k truncated some sections in S2), or sections shorter than 10 minutes.
- **Templates:** local, versioned JSON (sections, per-section instructions, required fields, citation
requirement). A small bundled seed set:
- *General minutes*, *Executive summary*, *Care assessment*: adapted from i.AI Minute's templates
Expand Down
2 changes: 1 addition & 1 deletion docs/spikes/next-phase-spikes.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ offline path ≤ 1 point.

## S2: Local LLM on long transcripts, the headline question

> **Interim (one model, partial run):** see [`s2-local-llm-notes.md`](s2-local-llm-notes.md). Harness: `spikes/s2-llm-notes/`.
> **Result: go, with conditions** (Mac, 6 models screened; omissions by length and the reference laptop still to run): see [`s2-local-llm-notes.md`](s2-local-llm-notes.md). Harness: `spikes/s2-llm-notes/`.

**Question.** On the reference laptop, how long does a local 3–4B model take to produce a template note from
transcripts of **15, 45, 60 and 90 minutes**, and does quality hold at those lengths?
Expand Down
284 changes: 230 additions & 54 deletions docs/spikes/s2-local-llm-notes.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions spikes/s2-llm-notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ python score.py packets --run screen # blind judge packets (synthe
# ...write results/judge/<run>/<id>.verdict.json per packet, then:
python score.py collect --run screen
python report.py --run screen --run full # markdown tables
python memory.py qwen3.5-4b 8192 # peak memory of one map call (macOS footprint)
```

`--threads 4` is the default, mimicking a U-series laptop's performance cores. Every run
records the machine's load average, because background load skews CPU timings.

`peak_rss_mb` in the run results is `ps` RSS. On macOS it counts memory-mapped weights and moves with
memory compression, so use `memory.py` for peak memory.

## Data

- `data/synthetic_care_assessment.json` (61 min) and `data/synthetic_legal_interview.json` (46 min) are
Expand All @@ -42,3 +46,6 @@ records the machine's load average, because background load skews CPU timings.
person).
- `data/ami/`: AMI Meeting Corpus human transcripts in 15/45/60/90-minute buckets. They are
generated and not committed.
- `results/notes/full/*/ami-*.json` are model-written notes on AMI meetings, which may quote the
transcripts. The AMI Meeting Corpus is © the AMI Consortium (University of Edinburgh and partners),
licensed CC-BY-4.0.
48 changes: 48 additions & 0 deletions spikes/s2-llm-notes/memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
"""Peak memory of one section-note (map) call, at a given context size.

python memory.py qwen3.5-4b 8192 -> appends a row to results/memory.jsonl

run.py's peak_rss_mb comes from `ps` RSS, which on macOS counts memory-mapped weights and moves with
memory compression, so it is not a reliable peak (see s1-live-lag.md). This instead loads the weights
into ordinary memory (--load-mode none, so they count) and reads macOS `footprint`'s
phys_footprint_peak after the call. macOS only.
"""
import json, subprocess, sys, time, urllib.request
import common as C
from run import MODEL_DIR, MODELS, find_transcript
model, ctx, port = sys.argv[1], int(sys.argv[2]), 8097
t = C.load_transcript(find_transcript("synthetic_care_assessment")); tpl = C.load_template(t["template"])
secs = C.sections(t["lines"])
p = subprocess.Popen(["llama-server", "-m", str(MODEL_DIR / MODELS[model]), "-c", str(ctx), "-t", "4", "-tb", "4",
"-ngl", "0", "-dev", "none", "-fa", "off", "-np", "1", "-cram", "0", "--reasoning", "off", "--no-webui",
"--load-mode", "none", "--port", str(port)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def fp():
"""Current and peak physical footprint in GB. Exits rather than return a reading it didn't get."""
res = subprocess.run(["footprint", "-f", "bytes", "-p", str(p.pid)], capture_output=True, text=True)
vals = {}
for l in res.stdout.splitlines():
l = l.strip()
if l.startswith("phys_footprint_peak:"): vals["peak"] = int(l.split()[1]) / 2**30
elif l.startswith("phys_footprint:"): vals["now"] = int(l.split()[1]) / 2**30
if res.returncode != 0 or not vals.get("now") or not vals.get("peak"):
raise SystemExit(f"footprint gave no reading (exit {res.returncode}): {res.stderr.strip()[:200]}")
return vals
try:
for _ in range(300):
try:
urllib.request.urlopen(f"http://127.0.0.1:{port}/health", timeout=2); break
except Exception: time.sleep(1)
idle = fp()
body = {"messages": C.map_messages(t, tpl, secs[0], 0, len(secs)), "temperature": 0.2, "seed": 42, "max_tokens": 2048,
"cache_prompt": False, "response_format": {"type": "json_schema", "json_schema": {"name": "out", "schema": C.facts_schema(tpl)}}}
r = json.loads(urllib.request.urlopen(urllib.request.Request(f"http://127.0.0.1:{port}/v1/chat/completions",
data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}), timeout=3600).read())
after = fp()
row = json.dumps({"model": model, "ctx": ctx, "idle_gb": round(idle["now"], 2),
"peak_gb": round(after["peak"], 2), "prompt_n": r["timings"]["prompt_n"]})
print(row)
with open(C.RESULTS / "memory.jsonl", "a") as f:
f.write(row + "\n")
finally:
p.terminate(); p.wait()
8 changes: 8 additions & 0 deletions spikes/s2-llm-notes/results/bench-gemma4-e4b.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 4, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 512, "n_gen": 0, "n_depth": 0, "test_time": "2026-11-12T17:20:45Z", "avg_ns": 2852345229, "stddev_ns": 37326033, "avg_ts": 179.516784, "stddev_ts": 2.349167, "samples_ns": [ 2825951792, 2878738667 ],"samples_ts": [ 181.178, 177.856 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 4, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 0, "n_gen": 128, "n_depth": 0, "test_time": "2026-11-12T17:20:53Z", "avg_ns": 5523723500, "stddev_ns": 263506994, "avg_ts": 23.199172, "stddev_ts": 1.106707, "samples_ns": [ 5337395917, 5710051083 ],"samples_ts": [ 23.9817, 22.4166 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 4, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 512, "n_gen": 0, "n_depth": 4096, "test_time": "2026-11-12T17:21:05Z", "avg_ns": 4210667916, "stddev_ns": 28637736, "avg_ts": 121.598723, "stddev_ts": 0.827017, "samples_ns": [ 4190418083, 4230917750 ],"samples_ts": [ 122.184, 121.014 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 4, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 0, "n_gen": 128, "n_depth": 4096, "test_time": "2026-11-12T17:21:50Z", "avg_ns": 6701677583, "stddev_ns": 6761591, "avg_ts": 19.099705, "stddev_ts": 0.019270, "samples_ns": [ 6696896416, 6706458750 ],"samples_ts": [ 19.1133, 19.0861 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 8, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 512, "n_gen": 0, "n_depth": 0, "test_time": "2026-11-12T17:22:03Z", "avg_ns": 2148814374, "stddev_ns": 58096578, "avg_ts": 238.358047, "stddev_ts": 6.444381, "samples_ns": [ 2189894833, 2107733916 ],"samples_ts": [ 233.801, 242.915 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 8, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 0, "n_gen": 128, "n_depth": 0, "test_time": "2026-11-12T17:22:10Z", "avg_ns": 4277679854, "stddev_ns": 10295388, "avg_ts": 29.922850, "stddev_ts": 0.072014, "samples_ns": [ 4284959500, 4270400209 ],"samples_ts": [ 29.8719, 29.9738 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 8, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 512, "n_gen": 0, "n_depth": 4096, "test_time": "2026-11-12T17:22:18Z", "avg_ns": 2780192478, "stddev_ns": 33991146, "avg_ts": 184.173676, "stddev_ts": 2.251736, "samples_ns": [ 2756157166, 2804227791 ],"samples_ts": [ 185.766, 182.581 ]}
{"build_commit": "cd959bae9", "build_number": 12110, "cpu_info": "Accelerate, Apple M5 Pro", "gpu_info": "Apple M5 Pro", "backends": "BLAS,MTL", "model_filename": "/Users/yanhong.zhao/kindtech-transcribe/models/llm/gemma-4-E4B-it-Q4_0.gguf", "model_type": "gemma4 E4B Q4_0", "model_size": 4820175016, "model_n_params": 7518069290, "n_batch": 2048, "n_ubatch": 512, "n_threads": 8, "cpu_mask": "0x0", "cpu_strict": false, "poll": 50, "type_k": "f16", "type_v": "f16", "n_gpu_layers": 0, "n_cpu_moe": 0, "split_mode": "layer", "main_gpu": 0, "no_kv_offload": false, "flash_attn": 0, "devices": "none", "tensor_split": "0.00", "tensor_buft_overrides": "none", "load_mode": "auto", "lazy_mode": "auto", "embeddings": false, "no_op_offload": 0, "no_host": false, "repack": true, "fit_target": 0, "fit_min_ctx": 0, "n_prompt": 0, "n_gen": 128, "n_depth": 4096, "test_time": "2026-11-12T17:22:26Z", "avg_ns": 5268285208, "stddev_ns": 360943363, "avg_ts": 24.353488, "stddev_ts": 1.668518, "samples_ns": [ 5523510708, 5013059708 ],"samples_ts": [ 23.1737, 25.5333 ]}
Loading