Skip to content

Commit 09d2d42

Browse files
authored
Merge pull request #6 from dAppCore/dev
Model Engine with restore KV
2 parents c1014bd + d260e56 commit 09d2d42

2,161 files changed

Lines changed: 608105 additions & 1008 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.forgejo/workflows/security-scan.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.forgejo/workflows/test.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Build the sovereign `lem` binary for every target and ship the zips.
2+
# One binary named `lem` per platform (the GPU backend — metal/rocm/cuda — loads
3+
# its kernel sidecar at runtime); targets are separated by build folder, not by
4+
# binary name. Zips flow to a rolling `dev` prerelease.
5+
name: Build
6+
7+
on:
8+
push:
9+
branches: [dev, main]
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
name: lem · ${{ matrix.goos }}/${{ matrix.goarch }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- { os: macos-latest, goos: darwin, goarch: arm64, metal: true }
24+
- { os: ubuntu-latest, goos: linux, goarch: amd64 }
25+
- { os: ubuntu-24.04-arm, goos: linux, goarch: arm64 }
26+
- { os: windows-latest, goos: windows, goarch: amd64 }
27+
env:
28+
CGO_ENABLED: "1"
29+
GOWORK: "off"
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
submodules: recursive # metal needs external/mlx
34+
35+
- uses: actions/setup-go@v5
36+
with:
37+
go-version: "1.26"
38+
39+
- name: Install Task
40+
run: go install github.com/go-task/task/v3/cmd/task@latest
41+
42+
- name: Build lem
43+
shell: bash
44+
env:
45+
METAL: ${{ matrix.metal }}
46+
run: |
47+
set -e
48+
if [ "$METAL" = "true" ]; then
49+
task metallib && task build:embed # self-contained metal lem
50+
else
51+
task build:native # plain lem (GPU sidecar loads at runtime)
52+
fi
53+
54+
- name: Assemble build folder (build/dist/<target>/lem)
55+
shell: bash
56+
env:
57+
TARGET: ${{ matrix.goos }}-${{ matrix.goarch }}
58+
run: |
59+
set -e
60+
mkdir -p "build/dist/$TARGET"
61+
cp bin/lem* "build/dist/$TARGET/"
62+
63+
- uses: actions/upload-artifact@v4
64+
with:
65+
name: lem-${{ matrix.goos }}-${{ matrix.goarch }}
66+
path: build/dist/${{ matrix.goos }}-${{ matrix.goarch }}/
67+
68+
release:
69+
name: Zip + rolling dev prerelease
70+
needs: build
71+
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
72+
runs-on: ubuntu-latest
73+
permissions:
74+
contents: write
75+
steps:
76+
- uses: actions/download-artifact@v4
77+
with:
78+
path: dist # one subfolder per target (lem-<goos>-<goarch>/lem)
79+
80+
- name: Zip each target
81+
run: |
82+
set -e
83+
cd dist
84+
for d in */; do (cd "$d" && zip -r "../${d%/}.zip" .); done
85+
ls -la *.zip
86+
87+
- name: Publish rolling dev prerelease
88+
uses: softprops/action-gh-release@v2
89+
with:
90+
tag_name: dev
91+
name: dev (rolling)
92+
prerelease: true
93+
files: dist/*.zip
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
97+
sdk:
98+
name: SDK clients (OpenAPI)
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/checkout@v4
102+
- uses: actions/setup-go@v5
103+
with:
104+
go-version: "1.26"
105+
- uses: actions/setup-node@v4
106+
with:
107+
node-version: "20"
108+
- uses: actions/setup-java@v4 # openapi-generator runs on the JVM
109+
with:
110+
distribution: temurin
111+
java-version: "21"
112+
- name: Install generators
113+
run: |
114+
npm install -g @openapitools/openapi-generator-cli@7.22.0
115+
go install github.com/go-task/task/v3/cmd/task@latest
116+
- name: Generate SDKs (lem spec -> OpenAPI 3.1 -> typed clients)
117+
run: task sdk
118+
- uses: actions/upload-artifact@v4
119+
with:
120+
name: lem-sdks
121+
path: build/sdk/
122+
if-no-files-found: warn

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Portable CI for go-inference — the default-tag (no-GPU) test + coverage lane.
2+
# go-inference is a Metal/CGO project; the FULL lem build (engine/metal, the
3+
# metallibs) needs macOS 26 / Metal 4 and lives in build.yml on a self-hosted
4+
# runner. This lane runs the portable suite (Taskfile `test`/`cover`) on any OS.
5+
name: CI
6+
7+
on:
8+
push:
9+
branches: [dev, main]
10+
pull_request:
11+
branches: [dev, main]
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
name: Portable test + coverage
19+
runs-on: ubuntu-latest
20+
env:
21+
GOWORK: "off" # resolve deps from go/go.mod tags, not the workspace
22+
CGO_ENABLED: "1" # go/ links duckdb (go-duckdb/v2 ships prebuilt linux libs)
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: actions/setup-go@v5
27+
with:
28+
go-version: "1.26"
29+
30+
- name: Portable tests + coverage (default tags — engine/metal excluded)
31+
working-directory: go
32+
run: go test -count=1 -covermode=atomic -coverprofile=coverage.out ./...
33+
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v5
36+
with:
37+
files: go/coverage.out
38+
flags: portable
39+
fail_ci_if_error: false

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@
22
.core/
33
.idea/
44
.vscode/
5+
# build / test artefacts
6+
*.test
7+
*.out
8+
.DS_Store
9+
*.bak
10+
go.work.sum
11+
/build/
12+
*.air
13+
cmd/lem/*.metallib.gz
14+
15+
# compiled lem binary (build artefact — built via Taskfile/go build)
16+
go/lem

.gitmodules

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
[submodule "external/go"]
2-
path = external/go
3-
url = https://github.com/dappcore/go.git
4-
branch = dev
1+
[submodule "external/mlx"]
2+
path = external/mlx
3+
url = https://github.com/ml-explore/mlx.git
4+
[submodule "external/rocm-hip"]
5+
path = external/rocm-hip
6+
url = https://github.com/ROCm/HIP.git
7+
branch = release/rocm-rel-7.2
8+
[submodule "external/rocm-clr"]
9+
path = external/rocm-clr
10+
url = https://github.com/ROCm/clr.git
11+
branch = release/rocm-rel-7.2
12+
[submodule "external/rocr-runtime"]
13+
path = external/rocr-runtime
14+
url = https://github.com/ROCm/ROCR-Runtime.git
15+
branch = release/rocm-rel-7.2

.woodpecker.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

AGENTS.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,73 @@ assert behavior directly against the symbol named by the test. A triplet named
3939
`TestOptions_WithMaxTokens_Bad` must invoke `WithMaxTokens` in its own body,
4040
not route through a dispatcher helper.
4141

42+
## Writing Tests, Examples & Benchmarks
43+
44+
Every source file ships three siblings — extend them, never create monolithic
45+
compliance files, versioned test files (`_v2`), or `ax7*` files:
46+
47+
| Sibling of `foo.go` | Holds | Verified by |
48+
|---------------------|-------|-------------|
49+
| `foo_test.go` | one `Test<Symbol>_<Case>` per exported symbol per variant | `task test` |
50+
| `foo_example_test.go` | one `Example<Symbol>` per symbol, with an `// Output:` block | `task test` (runs + diffs the output) |
51+
| `foo_bench_test.go` | one `Benchmark<Symbol>` per hot symbol | `task bench` |
52+
53+
**Tests — name the symbol, exercise it directly.** A test asserts against the
54+
symbol its name claims: `TestOptions_WithMaxTokens_Bad` must call
55+
`WithMaxTokens` in its own body, not route through a dispatcher/table helper.
56+
A test that never names its symbol is fake coverage the audit flags. Write the
57+
AX-7 triplet for each symbol — `_Good` (valid input, happy path), `_Bad`
58+
(invalid input is rejected), `_Ugly` (malformed / boundary / empty). Production
59+
functions that can fail return `core.Result`: the `_Good` test asserts `r.OK`
60+
then reads `r.Value`; the `_Bad`/`_Ugly` tests assert `!r.OK`.
61+
62+
**Examples are compiled documentation.** `func ExampleWithMaxTokens()` ends with
63+
a `// Output:` block so `go test` runs and diffs it — a stale example fails the
64+
build. Print with `Println` from `dappco.re/go`, never `fmt.Println`.
65+
66+
**Benchmarks measure the load path.** Shape:
67+
68+
```go
69+
var sinkResult core.Result // package sink — stops the compiler eliding the call
70+
71+
func BenchmarkDiscover(b *testing.B) {
72+
dir := writeFixtureModel(b) // setup OUTSIDE the timed loop
73+
b.ReportAllocs()
74+
b.ResetTimer() // discount the setup
75+
for i := 0; i < b.N; i++ {
76+
sinkResult = Discover(dir) // assign to the sink so it can't be optimised away
77+
}
78+
}
79+
```
80+
81+
Read **B/op as hard as allocs/op** — the biggest wins (whole-slice clones,
82+
full-file reads) leave allocs/op flat while B/op screams. allocs/op is only
83+
trustworthy at steady state, so `task bench` runs `-benchtime=20x`; a cold
84+
3-iteration number is inflated by setup.
85+
4286
## Working Locally
4387

44-
Use the same commands as the compliance brief before handing work back:
88+
Run the Taskfile gates before handing work back (portable lanes need no GPU;
89+
`*:metal` lanes need `task metallib` first):
90+
91+
```sh
92+
task qa # gofmt check + go vet + portable tests — the pre-handback gate
93+
task test # portable suite (default tags, runs anywhere)
94+
task test:metal # engine/metal suite (-tags metal_runtime; needs task metallib)
95+
task cover # coverage.out + total — must clear the 95% codecov target
96+
task bench # every benchmark with -benchmem (allocation regressions)
97+
```
98+
99+
`codecov.yml` enforces **95%** on both the project and each patch, measured on
100+
the portable `task cover` profile (the surface a Linux CI compiles; engine/metal
101+
is Darwin-only and covered by `task test:metal`).
102+
103+
For core/go idiom compliance specifically, the audit script is the work
104+
provider — a change is not complete until it reports `verdict: COMPLIANT` with
105+
every counter at zero:
45106

46107
```sh
47108
GOWORK=off go mod tidy
48-
GOWORK=off go vet ./...
49-
GOWORK=off go test -count=1 ./...
50109
gofmt -l .
51110
bash /Users/snider/Code/core/go/tests/cli/v090-upgrade/audit.sh .
52111
```
53-
54-
The audit script is the work provider for compliance tasks. A change is not
55-
complete until it reports `verdict: COMPLIANT` with every counter at zero.

0 commit comments

Comments
 (0)