Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37b029b
docs: add DSpark exactness investigation context
Aug 7, 2026
e2ef36b
docs: add Codex P2 C0 static audit
raveonetter Aug 7, 2026
2596a70
probe: add GPU-independent exact float comparator
raveonetter Aug 7, 2026
97362ef
docs: freeze DSpark exactness phase gates for agents
raveonetter Aug 7, 2026
dfc3305
probe: add inline F32 copy candidate; Metal validation pending
raveonetter Aug 7, 2026
34f858f
test: satisfy Metal logging stub for C2a regression
raveonetter Aug 7, 2026
ac20431
docs: freeze first-divergence experiment v1
raveonetter Aug 7, 2026
804ecaa
docs: add Codex C2b implementation handoff
raveonetter Aug 7, 2026
6cfd8d7
probe: add first-divergence capture layer
raveonetter Aug 7, 2026
c11ac46
test: run forced-token pass pair
raveonetter Aug 7, 2026
0b41145
probe: emit first-divergence report
raveonetter Aug 7, 2026
7f68d7f
probe: integrate real C2b verifier gate
raveonetter Aug 7, 2026
36550e3
probe: add canonical C4 C5 divergence run
raveonetter Aug 8, 2026
c47273e
probe: localize first Q-projection divergence
raveonetter Aug 8, 2026
80854f9
probe: isolate generic vs sequential QA numerics
raveonetter Aug 8, 2026
b958093
probe: canonicalize QA for divergence diagnosis
raveonetter Aug 8, 2026
613654b
probe: add composable canonicalization sweep controls
raveonetter Aug 8, 2026
1479320
probe: canonicalize KV for divergence diagnosis
raveonetter Aug 8, 2026
ab3bf45
probe: subdivide CP4 divergence interval
raveonetter Aug 8, 2026
f5e2764
probe: canonicalize Q-B for divergence diagnosis
raveonetter Aug 8, 2026
29f20f0
probe: localize and canonicalize raw attention drift
raveonetter Aug 8, 2026
812ab24
probe: isolate and canonicalize CP4 tail
raveonetter Aug 8, 2026
e9d7f99
probe: execute CP4 tail input clones
raveonetter Aug 8, 2026
0598657
probe: fix CP4 tail Metal fallback
raveonetter Aug 8, 2026
085c79f
probe: align CP4 tail fixture with verified fallback
raveonetter Aug 8, 2026
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
56 changes: 56 additions & 0 deletions .claude/AGENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Agent Notes

`ds4.c` is a DeepSeek V4 Flash specific inference engine. It is not a generic
GGUF runner. The goal is a small, readable, high-performance C codebase with
Objective-C only where Metal requires it and Metal kernels under `metal/`.

## Goals

- Keep the production path as whole-model Metal graph inference.
- Always make sure that the SSD streaming, CUDA, distributed inference, Metal default inference are not affected by fixes to other parts of the code.
- Keep model loading mmap-backed for the Metal default case; do not eagerly copy the full GGUF. Keep the model loading for SSD streaming of routed experts explicit: allocated buffers, fast reads from disk, always try to hide loading of missing routed experts by loading them while performing the inference of the shared expert and routed experts already in RAM. Always try to hide loading of layers for prefill in SSD streaming mode using the inference time of the current layer as the next one is loaded.
- Keep the CPU backend CPU-only and use it only as reference/debug code.
- Preserve correctness before speed. Do not keep a faster path with unexplained attention, KV cache, or logits drift.
- Make long local agent sessions practical through live KV reuse and disk KV checkpoints.

## Quality Rules

- Keep the implementation small, sharp, easy to understand. Try to write elegant code in a state of grace. Don't settle for the first thing that comes to mind, try to find the most minimal and better working design. Don't introduce slop: very fragile code that just patches specific cases, dead code, useless code and code ways more complicated of how it should be.
- Comment important inference code where the model mechanics, cache lifetime, memory policy, or API orchestration are not obvious from the local code.
- Prefer comments beside the implementation over separate design documents.
- Keep comments instructive and compact: explain why a shape, ordering, cache boundary, or memory choice exists.
- Keep public APIs narrow. CLI/server code should not know tensor internals.
- Do not add permanent semantic variants behind flags. Diagnostic switches are fine when they validate the one release path.
- Do not introduce C++.

## Safety

- Avoid large CPU inference runs on macOS; the CPU path has previously exposed kernel VM failures with very large mappings.
- Do not run multiple huge model processes concurrently. The instance lock is intentional.

## Layout

- `ds4.c`: model loading, tokenizer, CPU reference code, Metal graph scheduling,
sessions, disk-cache payload serialization.
- `ds4_cli.c`: command line, linenoise REPL, interactive transcript handling.
- `ds4_server.c`: OpenAI/Anthropic compatible HTTP API, worker queue, streaming,
tool-call mapping, disk KV cache policy.
- `ds4_metal.m`: Objective-C Metal runtime and kernel wrappers.
- `metal/*.metal`: compute kernels.
- `tests/`: unit and live integration tests.
- `misc/`: ignored notes, experiments, and old planning material.

This list is not complete, check the files for more info.

## Testing

Use `make` for build validation. Use `make test` for unit/regression tests when a
model and Metal are available. Use live server tests only when intentionally
testing the API surface.

At every major change where one of the following could be affected, make sure to:

1. Test the normal Metal path and that speed is still at the level it was.
2. Test the SSD streaming path.
3. Test the distributed inference if it could be affected, but ask the user before doing so.
4. Check if CUDA could be broken after the change, and ask the user to give you access to the CUDA machine to actually test if everything is still fine.
Loading